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
14#[derive(Clone, Debug)]
15pub struct IsleCompilation {
16    pub output: std::path::PathBuf,
17    pub inputs: Vec<std::path::PathBuf>,
18    pub untracked_inputs: Vec<std::path::PathBuf>,
19}
20
21/// Construct the list of compilations (transformations from ISLE
22/// source to generated Rust source) that exist in the repository.
23pub fn get_isle_compilations(
24    codegen_crate_dir: &std::path::Path,
25    gen_dir: &std::path::Path,
26) -> IsleCompilations {
27    // Preludes.
28    let clif_lower_isle = gen_dir.join("clif_lower.isle");
29    let clif_opt_isle = gen_dir.join("clif_opt.isle");
30    let prelude_isle = codegen_crate_dir.join("src").join("prelude.isle");
31    let prelude_opt_isle = codegen_crate_dir.join("src").join("prelude_opt.isle");
32    let prelude_lower_isle = codegen_crate_dir.join("src").join("prelude_lower.isle");
33
34    // Directory for mid-end optimizations.
35    let src_opts = codegen_crate_dir.join("src").join("opts");
36    // Directories for lowering backends.
37    let src_isa_x64 = codegen_crate_dir.join("src").join("isa").join("x64");
38    let src_isa_aarch64 = codegen_crate_dir.join("src").join("isa").join("aarch64");
39    let src_isa_s390x = codegen_crate_dir.join("src").join("isa").join("s390x");
40
41    let src_isa_risc_v = codegen_crate_dir.join("src").join("isa").join("riscv64");
42    // This is a set of ISLE compilation units.
43    //
44    // The format of each entry is:
45    //
46    //     (output Rust code file, input ISLE source files)
47    //
48    // There should be one entry for each backend that uses ISLE for lowering,
49    // and if/when we replace our peephole optimization passes with ISLE, there
50    // should be an entry for each of those as well.
51    //
52    // N.B.: add any new compilation outputs to
53    // `scripts/force-rebuild-isle.sh` if they do not fit the pattern
54    // `cranelift/codegen/src/isa/*/lower/isle/generated_code.rs`!
55    IsleCompilations {
56        items: vec![
57            // The mid-end optimization rules.
58            IsleCompilation {
59                output: gen_dir.join("isle_opt.rs"),
60                inputs: vec![
61                    prelude_isle.clone(),
62                    prelude_opt_isle,
63                    src_opts.join("arithmetic.isle"),
64                    src_opts.join("bitops.isle"),
65                    src_opts.join("cprop.isle"),
66                    src_opts.join("extends.isle"),
67                    src_opts.join("icmp.isle"),
68                    src_opts.join("remat.isle"),
69                    src_opts.join("selects.isle"),
70                    src_opts.join("shifts.isle"),
71                    src_opts.join("spaceship.isle"),
72                    src_opts.join("spectre.isle"),
73                    src_opts.join("vector.isle"),
74                ],
75                untracked_inputs: vec![clif_opt_isle],
76            },
77            // The x86-64 instruction selector.
78            IsleCompilation {
79                output: gen_dir.join("isle_x64.rs"),
80                inputs: vec![
81                    prelude_isle.clone(),
82                    prelude_lower_isle.clone(),
83                    src_isa_x64.join("inst.isle"),
84                    src_isa_x64.join("lower.isle"),
85                ],
86                untracked_inputs: vec![clif_lower_isle.clone()],
87            },
88            // The aarch64 instruction selector.
89            IsleCompilation {
90                output: gen_dir.join("isle_aarch64.rs"),
91                inputs: vec![
92                    prelude_isle.clone(),
93                    prelude_lower_isle.clone(),
94                    src_isa_aarch64.join("inst.isle"),
95                    src_isa_aarch64.join("inst_neon.isle"),
96                    src_isa_aarch64.join("lower.isle"),
97                    src_isa_aarch64.join("lower_dynamic_neon.isle"),
98                ],
99                untracked_inputs: vec![clif_lower_isle.clone()],
100            },
101            // The s390x instruction selector.
102            IsleCompilation {
103                output: gen_dir.join("isle_s390x.rs"),
104                inputs: vec![
105                    prelude_isle.clone(),
106                    prelude_lower_isle.clone(),
107                    src_isa_s390x.join("inst.isle"),
108                    src_isa_s390x.join("lower.isle"),
109                ],
110                untracked_inputs: vec![clif_lower_isle.clone()],
111            },
112            // The risc-v instruction selector.
113            IsleCompilation {
114                output: gen_dir.join("isle_riscv64.rs"),
115                inputs: vec![
116                    prelude_isle.clone(),
117                    prelude_lower_isle.clone(),
118                    src_isa_risc_v.join("inst.isle"),
119                    src_isa_risc_v.join("inst_vector.isle"),
120                    src_isa_risc_v.join("lower.isle"),
121                ],
122                untracked_inputs: vec![clif_lower_isle.clone()],
123            },
124        ],
125    }
126}