1 use crate::cdsl::settings::{SettingGroup, SettingGroupBuilder};
2 
3 pub(crate) fn define() -> SettingGroup {
4     let mut settings = SettingGroupBuilder::new("shared");
5 
6     settings.add_bool(
7         "regalloc_checker",
8         "Enable the symbolic checker for register allocation.",
9         r#"
10             This performs a verification that the register allocator preserves
11             equivalent dataflow with respect to the original (pre-regalloc)
12             program. This analysis is somewhat expensive. However, if it succeeds,
13             it provides independent evidence (by a carefully-reviewed, from-first-principles
14             analysis) that no regalloc bugs were triggered for the particular compilations
15             performed. This is a valuable assurance to have as regalloc bugs can be
16             very dangerous and difficult to debug.
17         "#,
18         false,
19     );
20 
21     settings.add_bool(
22         "regalloc_verbose_logs",
23         "Enable verbose debug logs for regalloc2.",
24         r#"
25             This adds extra logging for regalloc2 output, that is quite valuable to understand
26             decisions taken by the register allocator as well as debugging it. It is disabled by
27             default, as it can cause many log calls which can slow down compilation by a large
28             amount.
29         "#,
30         false,
31     );
32 
33     settings.add_enum(
34         "opt_level",
35         "Optimization level for generated code.",
36         r#"
37             Supported levels:
38 
39             - `none`: Minimise compile time by disabling most optimizations.
40             - `speed`: Generate the fastest possible code
41             - `speed_and_size`: like "speed", but also perform transformations aimed at reducing code size.
42         "#,
43         vec!["none", "speed", "speed_and_size"],
44     );
45 
46     settings.add_bool(
47         "enable_alias_analysis",
48         "Do redundant-load optimizations with alias analysis.",
49         r#"
50             This enables the use of a simple alias analysis to optimize away redundant loads.
51             Only effective when `opt_level` is `speed` or `speed_and_size`.
52         "#,
53         true,
54     );
55 
56     settings.add_bool(
57         "use_egraphs",
58         "Enable egraph-based optimization.",
59         r#"
60             This enables an optimization phase that converts CLIF to an egraph (equivalence graph)
61             representation, performs various rewrites, and then converts it back. This should result in
62             better optimization, but the traditional optimization pass structure is also still
63             available by setting this to `false`. The `false` setting will eventually be
64             deprecated and removed.
65         "#,
66         true,
67     );
68 
69     settings.add_bool(
70         "enable_verifier",
71         "Run the Cranelift IR verifier at strategic times during compilation.",
72         r#"
73             This makes compilation slower but catches many bugs. The verifier is always enabled by
74             default, which is useful during development.
75         "#,
76         true,
77     );
78 
79     // Note that Cranelift doesn't currently need an is_pie flag, because PIE is
80     // just PIC where symbols can't be pre-empted, which can be expressed with the
81     // `colocated` flag on external functions and global values.
82     settings.add_bool(
83         "is_pic",
84         "Enable Position-Independent Code generation.",
85         "",
86         false,
87     );
88 
89     settings.add_bool(
90         "use_colocated_libcalls",
91         "Use colocated libcalls.",
92         r#"
93             Generate code that assumes that libcalls can be declared "colocated",
94             meaning they will be defined along with the current function, such that
95             they can use more efficient addressing.
96         "#,
97         false,
98     );
99 
100     settings.add_bool(
101         "enable_float",
102         "Enable the use of floating-point instructions.",
103         r#"
104             Disabling use of floating-point instructions is not yet implemented.
105         "#,
106         true,
107     );
108 
109     settings.add_bool(
110         "enable_nan_canonicalization",
111         "Enable NaN canonicalization.",
112         r#"
113             This replaces NaNs with a single canonical value, for users requiring
114             entirely deterministic WebAssembly computation. This is not required
115             by the WebAssembly spec, so it is not enabled by default.
116         "#,
117         false,
118     );
119 
120     settings.add_bool(
121         "enable_pinned_reg",
122         "Enable the use of the pinned register.",
123         r#"
124             This register is excluded from register allocation, and is completely under the control of
125             the end-user. It is possible to read it via the get_pinned_reg instruction, and to set it
126             with the set_pinned_reg instruction.
127         "#,
128         false,
129     );
130 
131     settings.add_bool(
132         "enable_simd",
133         "Enable the use of SIMD instructions.",
134         "",
135         false,
136     );
137 
138     settings.add_bool(
139         "enable_atomics",
140         "Enable the use of atomic instructions",
141         "",
142         true,
143     );
144 
145     settings.add_bool(
146         "enable_safepoints",
147         "Enable safepoint instruction insertions.",
148         r#"
149             This will allow the emit_stack_maps() function to insert the safepoint
150             instruction on top of calls and interrupt traps in order to display the
151             live reference values at that point in the program.
152         "#,
153         false,
154     );
155 
156     settings.add_enum(
157         "tls_model",
158         "Defines the model used to perform TLS accesses.",
159         "",
160         vec!["none", "elf_gd", "macho", "coff"],
161     );
162 
163     settings.add_enum(
164         "libcall_call_conv",
165         "Defines the calling convention to use for LibCalls call expansion.",
166         r#"
167             This may be different from the ISA default calling convention.
168 
169             The default value is to use the same calling convention as the ISA
170             default calling convention.
171 
172             This list should be kept in sync with the list of calling
173             conventions available in isa/call_conv.rs.
174         "#,
175         vec![
176             "isa_default",
177             "fast",
178             "cold",
179             "system_v",
180             "windows_fastcall",
181             "apple_aarch64",
182             "probestack",
183         ],
184     );
185 
186     settings.add_bool(
187         "enable_llvm_abi_extensions",
188         "Enable various ABI extensions defined by LLVM's behavior.",
189         r#"
190             In some cases, LLVM's implementation of an ABI (calling convention)
191             goes beyond a standard and supports additional argument types or
192             behavior. This option instructs Cranelift codegen to follow LLVM's
193             behavior where applicable.
194 
195             Currently, this applies only to Windows Fastcall on x86-64, and
196             allows an `i128` argument to be spread across two 64-bit integer
197             registers. The Fastcall implementation otherwise does not support
198             `i128` arguments, and will panic if they are present and this
199             option is not set.
200         "#,
201         false,
202     );
203 
204     settings.add_bool(
205         "unwind_info",
206         "Generate unwind information.",
207         r#"
208             This increases metadata size and compile time, but allows for the
209             debugger to trace frames, is needed for GC tracing that relies on
210             libunwind (such as in Wasmtime), and is unconditionally needed on
211             certain platforms (such as Windows) that must always be able to unwind.
212           "#,
213         true,
214     );
215 
216     settings.add_bool(
217         "preserve_frame_pointers",
218         "Preserve frame pointers",
219         r#"
220             Preserving frame pointers -- even inside leaf functions -- makes it
221             easy to capture the stack of a running program, without requiring any
222             side tables or metadata (like `.eh_frame` sections). Many sampling
223             profilers and similar tools walk frame pointers to capture stacks.
224             Enabling this option will play nice with those tools.
225         "#,
226         false,
227     );
228 
229     settings.add_bool(
230         "machine_code_cfg_info",
231         "Generate CFG metadata for machine code.",
232         r#"
233             This increases metadata size and compile time, but allows for the
234             embedder to more easily post-process or analyze the generated
235             machine code. It provides code offsets for the start of each
236             basic block in the generated machine code, and a list of CFG
237             edges (with blocks identified by start offsets) between them.
238             This is useful for, e.g., machine-code analyses that verify certain
239             properties of the generated code.
240         "#,
241         false,
242     );
243 
244     // Stack probing options.
245 
246     settings.add_bool(
247         "enable_probestack",
248         "Enable the use of stack probes for supported calling conventions.",
249         "",
250         false,
251     );
252 
253     settings.add_bool(
254         "probestack_func_adjusts_sp",
255         "Enable if the stack probe adjusts the stack pointer.",
256         "",
257         false,
258     );
259 
260     settings.add_num(
261         "probestack_size_log2",
262         "The log2 of the size of the stack guard region.",
263         r#"
264             Stack frames larger than this size will have stack overflow checked
265             by calling the probestack function.
266 
267             The default is 12, which translates to a size of 4096.
268         "#,
269         12,
270     );
271 
272     settings.add_enum(
273         "probestack_strategy",
274         "Controls what kinds of stack probes are emitted.",
275         r#"
276             Supported strategies:
277 
278             - `outline`: Always emits stack probes as calls to a probe stack function.
279             - `inline`: Always emits inline stack probes.
280         "#,
281         vec!["outline", "inline"],
282     );
283 
284     // Jump table options.
285 
286     settings.add_bool(
287         "enable_jump_tables",
288         "Enable the use of jump tables in generated machine code.",
289         "",
290         true,
291     );
292 
293     // Spectre options.
294 
295     settings.add_bool(
296         "enable_heap_access_spectre_mitigation",
297         "Enable Spectre mitigation on heap bounds checks.",
298         r#"
299             This is a no-op for any heap that needs no bounds checks; e.g.,
300             if the limit is static and the guard region is large enough that
301             the index cannot reach past it.
302 
303             This option is enabled by default because it is highly
304             recommended for secure sandboxing. The embedder should consider
305             the security implications carefully before disabling this option.
306         "#,
307         true,
308     );
309 
310     settings.add_bool(
311         "enable_table_access_spectre_mitigation",
312         "Enable Spectre mitigation on table bounds checks.",
313         r#"
314             This option uses a conditional move to ensure that when a table
315             access index is bounds-checked and a conditional branch is used
316             for the out-of-bounds case, a misspeculation of that conditional
317             branch (falsely predicted in-bounds) will select an in-bounds
318             index to load on the speculative path.
319 
320             This option is enabled by default because it is highly
321             recommended for secure sandboxing. The embedder should consider
322             the security implications carefully before disabling this option.
323         "#,
324         true,
325     );
326 
327     settings.add_bool(
328         "enable_incremental_compilation_cache_checks",
329         "Enable additional checks for debugging the incremental compilation cache.",
330         r#"
331             Enables additional checks that are useful during development of the incremental
332             compilation cache. This should be mostly useful for Cranelift hackers, as well as for
333             helping to debug false incremental cache positives for embedders.
334 
335             This option is disabled by default and requires enabling the "incremental-cache" Cargo
336             feature in cranelift-codegen.
337         "#,
338         false,
339     );
340 
341     // When adding new settings please check if they can also be added
342     // in cranelift/fuzzgen/src/lib.rs for fuzzing.
343     settings.build()
344 }
345