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)]
10 pub struct IsleCompilations {
11     pub items: Vec<IsleCompilation>,
12 }
13 
14 impl 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)]
26 pub 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 
33 impl 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 
43 pub 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.
57 pub 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("spaceship.isle"),
115                     src_opts.join("spectre.isle"),
116                     src_opts.join("vector.isle"),
117                 ],
118                 untracked_inputs: vec![clif_opt_isle],
119             },
120             // The x86-64 instruction selector.
121             IsleCompilation {
122                 name: "x64".to_string(),
123                 output: gen_dir.join("isle_x64.rs"),
124                 inputs: vec![
125                     prelude_isle.clone(),
126                     prelude_lower_isle.clone(),
127                     src_isa_x64.join("inst.isle"),
128                     src_isa_x64.join("lower.isle"),
129                 ],
130                 untracked_inputs: vec![clif_lower_isle.clone(), gen_dir.join("assembler.isle")],
131             },
132             // The aarch64 instruction selector.
133             IsleCompilation {
134                 name: "aarch64".to_string(),
135                 output: gen_dir.join("isle_aarch64.rs"),
136                 inputs: vec![
137                     prelude_isle.clone(),
138                     prelude_lower_isle.clone(),
139                     src_isa_aarch64.join("inst.isle"),
140                     src_isa_aarch64.join("inst_neon.isle"),
141                     src_isa_aarch64.join("lower.isle"),
142                     src_isa_aarch64.join("lower_dynamic_neon.isle"),
143                 ],
144                 untracked_inputs: vec![clif_lower_isle.clone()],
145             },
146             // The s390x instruction selector.
147             IsleCompilation {
148                 name: "s390x".to_string(),
149                 output: gen_dir.join("isle_s390x.rs"),
150                 inputs: vec![
151                     prelude_isle.clone(),
152                     prelude_lower_isle.clone(),
153                     src_isa_s390x.join("inst.isle"),
154                     src_isa_s390x.join("lower.isle"),
155                 ],
156                 untracked_inputs: vec![clif_lower_isle.clone()],
157             },
158             // The risc-v instruction selector.
159             IsleCompilation {
160                 name: "riscv64".to_string(),
161                 output: gen_dir.join("isle_riscv64.rs"),
162                 inputs: vec![
163                     prelude_isle.clone(),
164                     prelude_lower_isle.clone(),
165                     src_isa_risc_v.join("inst.isle"),
166                     src_isa_risc_v.join("inst_vector.isle"),
167                     src_isa_risc_v.join("lower.isle"),
168                 ],
169                 untracked_inputs: vec![clif_lower_isle.clone()],
170             },
171             // The Pulley instruction selector.
172             #[cfg(feature = "pulley")]
173             IsleCompilation {
174                 name: "pulley".to_string(),
175                 output: gen_dir.join("isle_pulley_shared.rs"),
176                 inputs: vec![
177                     prelude_isle.clone(),
178                     prelude_lower_isle.clone(),
179                     src_isa_pulley_shared.join("inst.isle"),
180                     src_isa_pulley_shared.join("lower.isle"),
181                 ],
182                 untracked_inputs: vec![pulley_gen.clone(), clif_lower_isle.clone()],
183             },
184         ],
185     }
186 }
187