cranelift_codegen_meta/
isle.rs

1/// A list of compilations (transformations from ISLE source to
2/// generated Rust source) that exist in the repository.
3///
4/// This list is used either to regenerate the Rust source in-tree (if
5/// the `rebuild-isle` feature is enabled), or to verify that the ISLE
6/// source in-tree corresponds to the ISLE source that was last used
7/// to rebuild the Rust source (if the `rebuild-isle` feature is not
8/// enabled).
9#[derive(Clone, Debug)]
10pub struct IsleCompilations {
11    pub items: Vec<IsleCompilation>,
12}
13
14impl IsleCompilations {
15    pub fn lookup(&self, name: &str) -> Option<&IsleCompilation> {
16        for compilation in &self.items {
17            if compilation.name == name {
18                return Some(compilation);
19            }
20        }
21        None
22    }
23}
24
25#[derive(Clone, Debug)]
26pub struct IsleCompilation {
27    pub name: String,
28    pub output: std::path::PathBuf,
29    pub inputs: Vec<std::path::PathBuf>,
30    pub untracked_inputs: Vec<std::path::PathBuf>,
31}
32
33impl IsleCompilation {
34    pub fn inputs(&self) -> Vec<std::path::PathBuf> {
35        self.inputs
36            .iter()
37            .chain(self.untracked_inputs.iter())
38            .cloned()
39            .collect()
40    }
41}
42
43pub fn shared_isle_lower_paths(codegen_crate_dir: &std::path::Path) -> Vec<std::path::PathBuf> {
44    let inst_specs_isle = codegen_crate_dir.join("src").join("inst_specs.isle");
45    let prelude_isle = codegen_crate_dir.join("src").join("prelude.isle");
46    let prelude_lower_isle = codegen_crate_dir.join("src").join("prelude_lower.isle");
47    // The shared instruction selector logic.
48    vec![
49        inst_specs_isle.clone(),
50        prelude_isle.clone(),
51        prelude_lower_isle.clone(),
52    ]
53}
54
55/// Construct the list of compilations (transformations from ISLE
56/// source to generated Rust source) that exist in the repository.
57pub fn get_isle_compilations(
58    codegen_crate_dir: &std::path::Path,
59    gen_dir: &std::path::Path,
60) -> IsleCompilations {
61    // Preludes.
62    let numerics_isle = gen_dir.join("numerics.isle");
63    let clif_lower_isle = gen_dir.join("clif_lower.isle");
64    let clif_opt_isle = gen_dir.join("clif_opt.isle");
65    let prelude_isle = codegen_crate_dir.join("src").join("prelude.isle");
66    let prelude_opt_isle = codegen_crate_dir.join("src").join("prelude_opt.isle");
67    let prelude_lower_isle = codegen_crate_dir.join("src").join("prelude_lower.isle");
68    #[cfg(feature = "pulley")]
69    let pulley_gen = gen_dir.join("pulley_gen.isle");
70
71    // Directory for mid-end optimizations.
72    let src_opts = codegen_crate_dir.join("src").join("opts");
73
74    // Directories for lowering backends.
75    let src_isa_x64 = codegen_crate_dir.join("src").join("isa").join("x64");
76    let src_isa_aarch64 = codegen_crate_dir.join("src").join("isa").join("aarch64");
77    let src_isa_s390x = codegen_crate_dir.join("src").join("isa").join("s390x");
78    let src_isa_risc_v = codegen_crate_dir.join("src").join("isa").join("riscv64");
79    #[cfg(feature = "pulley")]
80    let src_isa_pulley_shared = codegen_crate_dir
81        .join("src")
82        .join("isa")
83        .join("pulley_shared");
84
85    // This is a set of ISLE compilation units.
86    //
87    // The format of each entry is:
88    //
89    //     (output Rust code file, input ISLE source files)
90    //
91    // There should be one entry for each backend that uses ISLE for lowering,
92    // and if/when we replace our peephole optimization passes with ISLE, there
93    // should be an entry for each of those as well.
94    //
95    // N.B.: add any new compilation outputs to
96    // `scripts/force-rebuild-isle.sh` if they do not fit the pattern
97    // `cranelift/codegen/src/isa/*/lower/isle/generated_code.rs`!
98    IsleCompilations {
99        items: vec![
100            // The mid-end optimization rules.
101            IsleCompilation {
102                name: "opt".to_string(),
103                output: gen_dir.join("isle_opt.rs"),
104                inputs: vec![
105                    prelude_isle.clone(),
106                    prelude_opt_isle,
107                    src_opts.join("arithmetic.isle"),
108                    src_opts.join("bitops.isle"),
109                    src_opts.join("cprop.isle"),
110                    src_opts.join("extends.isle"),
111                    src_opts.join("icmp.isle"),
112                    src_opts.join("remat.isle"),
113                    src_opts.join("selects.isle"),
114                    src_opts.join("shifts.isle"),
115                    src_opts.join("skeleton.isle"),
116                    src_opts.join("spaceship.isle"),
117                    src_opts.join("spectre.isle"),
118                    src_opts.join("vector.isle"),
119                ],
120                untracked_inputs: vec![numerics_isle.clone(), clif_opt_isle],
121            },
122            // The x86-64 instruction selector.
123            IsleCompilation {
124                name: "x64".to_string(),
125                output: gen_dir.join("isle_x64.rs"),
126                inputs: vec![
127                    prelude_isle.clone(),
128                    prelude_lower_isle.clone(),
129                    src_isa_x64.join("inst.isle"),
130                    src_isa_x64.join("lower.isle"),
131                ],
132                untracked_inputs: vec![
133                    numerics_isle.clone(),
134                    clif_lower_isle.clone(),
135                    gen_dir.join("assembler.isle"),
136                ],
137            },
138            // The aarch64 instruction selector.
139            IsleCompilation {
140                name: "aarch64".to_string(),
141                output: gen_dir.join("isle_aarch64.rs"),
142                inputs: vec![
143                    prelude_isle.clone(),
144                    prelude_lower_isle.clone(),
145                    src_isa_aarch64.join("inst.isle"),
146                    src_isa_aarch64.join("inst_neon.isle"),
147                    src_isa_aarch64.join("lower.isle"),
148                    src_isa_aarch64.join("lower_dynamic_neon.isle"),
149                ],
150                untracked_inputs: vec![numerics_isle.clone(), clif_lower_isle.clone()],
151            },
152            // The s390x instruction selector.
153            IsleCompilation {
154                name: "s390x".to_string(),
155                output: gen_dir.join("isle_s390x.rs"),
156                inputs: vec![
157                    prelude_isle.clone(),
158                    prelude_lower_isle.clone(),
159                    src_isa_s390x.join("inst.isle"),
160                    src_isa_s390x.join("lower.isle"),
161                ],
162                untracked_inputs: vec![numerics_isle.clone(), clif_lower_isle.clone()],
163            },
164            // The risc-v instruction selector.
165            IsleCompilation {
166                name: "riscv64".to_string(),
167                output: gen_dir.join("isle_riscv64.rs"),
168                inputs: vec![
169                    prelude_isle.clone(),
170                    prelude_lower_isle.clone(),
171                    src_isa_risc_v.join("inst.isle"),
172                    src_isa_risc_v.join("inst_vector.isle"),
173                    src_isa_risc_v.join("lower.isle"),
174                ],
175                untracked_inputs: vec![numerics_isle.clone(), clif_lower_isle.clone()],
176            },
177            // The Pulley instruction selector.
178            #[cfg(feature = "pulley")]
179            IsleCompilation {
180                name: "pulley".to_string(),
181                output: gen_dir.join("isle_pulley_shared.rs"),
182                inputs: vec![
183                    prelude_isle.clone(),
184                    prelude_lower_isle.clone(),
185                    src_isa_pulley_shared.join("inst.isle"),
186                    src_isa_pulley_shared.join("lower.isle"),
187                ],
188                untracked_inputs: vec![
189                    numerics_isle.clone(),
190                    pulley_gen.clone(),
191                    clif_lower_isle.clone(),
192                ],
193            },
194        ],
195    }
196}