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