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 clif_lower_isle = gen_dir.join("clif_lower.isle");
63    let clif_opt_isle = gen_dir.join("clif_opt.isle");
64    let prelude_isle = codegen_crate_dir.join("src").join("prelude.isle");
65    let prelude_opt_isle = codegen_crate_dir.join("src").join("prelude_opt.isle");
66    let prelude_lower_isle = codegen_crate_dir.join("src").join("prelude_lower.isle");
67    #[cfg(feature = "pulley")]
68    let pulley_gen = gen_dir.join("pulley_gen.isle");
69
70    // Directory for mid-end optimizations.
71    let src_opts = codegen_crate_dir.join("src").join("opts");
72
73    // Directories for lowering backends.
74    let src_isa_x64 = codegen_crate_dir.join("src").join("isa").join("x64");
75    let src_isa_aarch64 = codegen_crate_dir.join("src").join("isa").join("aarch64");
76    let src_isa_s390x = codegen_crate_dir.join("src").join("isa").join("s390x");
77    let src_isa_risc_v = codegen_crate_dir.join("src").join("isa").join("riscv64");
78    #[cfg(feature = "pulley")]
79    let src_isa_pulley_shared = codegen_crate_dir
80        .join("src")
81        .join("isa")
82        .join("pulley_shared");
83
84    // Assembler definitions.
85    let asm_isle_definitions = cranelift_assembler_x64::generated_files()
86        .into_iter()
87        .filter(|p| p.extension() == Some(std::ffi::OsStr::new("isle")))
88        .next()
89        .unwrap();
90
91    // This is a set of ISLE compilation units.
92    //
93    // The format of each entry is:
94    //
95    //     (output Rust code file, input ISLE source files)
96    //
97    // There should be one entry for each backend that uses ISLE for lowering,
98    // and if/when we replace our peephole optimization passes with ISLE, there
99    // should be an entry for each of those as well.
100    //
101    // N.B.: add any new compilation outputs to
102    // `scripts/force-rebuild-isle.sh` if they do not fit the pattern
103    // `cranelift/codegen/src/isa/*/lower/isle/generated_code.rs`!
104    IsleCompilations {
105        items: vec![
106            // The mid-end optimization rules.
107            IsleCompilation {
108                name: "opt".to_string(),
109                output: gen_dir.join("isle_opt.rs"),
110                inputs: vec![
111                    prelude_isle.clone(),
112                    prelude_opt_isle,
113                    src_opts.join("arithmetic.isle"),
114                    src_opts.join("bitops.isle"),
115                    src_opts.join("cprop.isle"),
116                    src_opts.join("extends.isle"),
117                    src_opts.join("icmp.isle"),
118                    src_opts.join("remat.isle"),
119                    src_opts.join("selects.isle"),
120                    src_opts.join("shifts.isle"),
121                    src_opts.join("spaceship.isle"),
122                    src_opts.join("spectre.isle"),
123                    src_opts.join("vector.isle"),
124                ],
125                untracked_inputs: vec![clif_opt_isle],
126            },
127            // The x86-64 instruction selector.
128            IsleCompilation {
129                name: "x64".to_string(),
130                output: gen_dir.join("isle_x64.rs"),
131                inputs: vec![
132                    prelude_isle.clone(),
133                    prelude_lower_isle.clone(),
134                    src_isa_x64.join("inst.isle"),
135                    src_isa_x64.join("lower.isle"),
136                    asm_isle_definitions.clone(),
137                ],
138                untracked_inputs: vec![clif_lower_isle.clone()],
139            },
140            // The aarch64 instruction selector.
141            IsleCompilation {
142                name: "aarch64".to_string(),
143                output: gen_dir.join("isle_aarch64.rs"),
144                inputs: vec![
145                    prelude_isle.clone(),
146                    prelude_lower_isle.clone(),
147                    src_isa_aarch64.join("inst.isle"),
148                    src_isa_aarch64.join("inst_neon.isle"),
149                    src_isa_aarch64.join("lower.isle"),
150                    src_isa_aarch64.join("lower_dynamic_neon.isle"),
151                ],
152                untracked_inputs: vec![clif_lower_isle.clone()],
153            },
154            // The s390x instruction selector.
155            IsleCompilation {
156                name: "s390x".to_string(),
157                output: gen_dir.join("isle_s390x.rs"),
158                inputs: vec![
159                    prelude_isle.clone(),
160                    prelude_lower_isle.clone(),
161                    src_isa_s390x.join("inst.isle"),
162                    src_isa_s390x.join("lower.isle"),
163                ],
164                untracked_inputs: vec![clif_lower_isle.clone()],
165            },
166            // The risc-v instruction selector.
167            IsleCompilation {
168                name: "riscv64".to_string(),
169                output: gen_dir.join("isle_riscv64.rs"),
170                inputs: vec![
171                    prelude_isle.clone(),
172                    prelude_lower_isle.clone(),
173                    src_isa_risc_v.join("inst.isle"),
174                    src_isa_risc_v.join("inst_vector.isle"),
175                    src_isa_risc_v.join("lower.isle"),
176                ],
177                untracked_inputs: vec![clif_lower_isle.clone()],
178            },
179            // The Pulley instruction selector.
180            #[cfg(feature = "pulley")]
181            IsleCompilation {
182                name: "pulley".to_string(),
183                output: gen_dir.join("isle_pulley_shared.rs"),
184                inputs: vec![
185                    prelude_isle.clone(),
186                    prelude_lower_isle.clone(),
187                    src_isa_pulley_shared.join("inst.isle"),
188                    src_isa_pulley_shared.join("lower.isle"),
189                ],
190                untracked_inputs: vec![pulley_gen.clone(), clif_lower_isle.clone()],
191            },
192        ],
193    }
194}