Skip to main content

cranelift_codegen_meta/shared/
settings.rs

1use crate::cdsl::settings::{SettingGroup, SettingGroupBuilder};
2
3pub(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        "regalloc_algorithm",
35        "Algorithm to use in register allocator.",
36        r#"
37            Supported options:
38
39            - `backtracking`: A backtracking allocator with range splitting; more expensive
40                              but generates better code.
41            - `single_pass`: A single-pass algorithm that yields quick compilation but
42                             results in code with more register spills and moves.
43        "#,
44        vec!["backtracking", "single_pass"],
45    );
46
47    settings.add_enum(
48        "opt_level",
49        "Optimization level for generated code.",
50        r#"
51            Supported levels:
52
53            - `none`: Minimise compile time by disabling most optimizations.
54            - `speed`: Generate the fastest possible code
55            - `speed_and_size`: like "speed", but also perform transformations aimed at reducing code size.
56        "#,
57        vec!["none", "speed", "speed_and_size"],
58    );
59
60    settings.add_bool(
61        "enable_alias_analysis",
62        "Do redundant-load optimizations with alias analysis.",
63        r#"
64            This enables the use of a simple alias analysis to optimize away redundant loads.
65            Only effective when `opt_level` is `speed` or `speed_and_size`.
66        "#,
67        true,
68    );
69
70    settings.add_bool(
71        "enable_verifier",
72        "Run the Cranelift IR verifier at strategic times during compilation.",
73        r#"
74            This makes compilation slower but catches many bugs. The verifier is always enabled by
75            default, which is useful during development.
76        "#,
77        true,
78    );
79
80    // Note that Cranelift doesn't currently need an is_pie flag, because PIE is
81    // just PIC where symbols can't be preempted, which can be expressed with the
82    // `colocated` flag on external functions and global values.
83    settings.add_bool(
84        "is_pic",
85        "Enable Position-Independent Code generation.",
86        "",
87        false,
88    );
89
90    settings.add_bool(
91        "use_colocated_libcalls",
92        "Use colocated libcalls.",
93        r#"
94            Generate code that assumes that libcalls can be declared "colocated",
95            meaning they will be defined along with the current function, such that
96            they can use more efficient addressing.
97        "#,
98        false,
99    );
100
101    settings.add_bool(
102        "enable_nan_canonicalization",
103        "Enable NaN canonicalization.",
104        r#"
105            This replaces NaNs with a single canonical value, for users requiring
106            entirely deterministic WebAssembly computation. This is not required
107            by the WebAssembly spec, so it is not enabled by default.
108        "#,
109        false,
110    );
111
112    settings.add_bool(
113        "enable_pinned_reg",
114        "Enable the use of the pinned register.",
115        r#"
116            This register is excluded from register allocation, and is completely under the control of
117            the end-user. It is possible to read it via the get_pinned_reg instruction, and to set it
118            with the set_pinned_reg instruction.
119        "#,
120        false,
121    );
122
123    settings.add_enum(
124        "tls_model",
125        "Defines the model used to perform TLS accesses.",
126        "",
127        vec!["none", "elf_gd", "macho", "coff"],
128    );
129
130    settings.add_enum(
131        "stack_switch_model",
132        "Defines the model used to performing stack switching.",
133        r#"
134           This determines the compilation of `stack_switch` instructions. If
135           set to `basic`, we simply save all registers, update stack pointer
136           and frame pointer (if needed), and jump to the target IP.
137           If set to `update_windows_tib`, we *additionally* update information
138           about the active stack in Windows' Thread Information Block.
139        "#,
140        vec!["none", "basic", "update_windows_tib"],
141    );
142
143    settings.add_enum(
144        "libcall_call_conv",
145        "Defines the calling convention to use for LibCalls call expansion.",
146        r#"
147            This may be different from the ISA default calling convention.
148
149            The default value is to use the same calling convention as the ISA
150            default calling convention.
151
152            This list should be kept in sync with the list of calling
153            conventions available in isa/call_conv.rs.
154        "#,
155        vec![
156            "isa_default",
157            "fast",
158            "system_v",
159            "windows_fastcall",
160            "apple_aarch64",
161            "probestack",
162            "preserve_all",
163        ],
164    );
165
166    settings.add_bool(
167        "separate_constant_pool",
168        "Emit a function's constants into a separate buffer instead of its code.",
169        r#"
170            The constants are in `CompiledCode::constants`. The embedder places
171            the constants and resolves the relocations that refer to them.
172
173            `cranelift-jit` and `cranelift-object` return an error for a
174            function that has constants. Jump tables stay in the code.
175        "#,
176        false,
177    );
178
179    settings.add_bool(
180        "enable_llvm_abi_extensions",
181        "Enable various ABI extensions defined by LLVM's behavior.",
182        r#"
183            In some cases, LLVM's implementation of an ABI (calling convention)
184            goes beyond a standard and supports additional argument types or
185            behavior. This option instructs Cranelift codegen to follow LLVM's
186            behavior where applicable.
187
188            Currently, this applies only to Windows Fastcall on x86-64, and
189            allows an `i128` argument to be spread across two 64-bit integer
190            registers. The Fastcall implementation otherwise does not support
191            `i128` arguments, and will panic if they are present and this
192            option is not set.
193        "#,
194        false,
195    );
196
197    settings.add_bool(
198        "enable_multi_ret_implicit_sret",
199        "Enable support for sret arg introduction when there are too many ret vals.",
200        r#"
201            When there are more returns than available return registers, the
202            return value has to be returned through the introduction of a
203            return area pointer. Normally this return area pointer has to be
204            introduced as `ArgumentPurpose::StructReturn` parameter, but for
205            backward compatibility reasons Cranelift also supports implicitly
206            introducing this parameter and writing the return values through it.
207
208            **This option currently does not conform to platform ABIs and the
209            used ABI should not be assumed to remain the same between Cranelift
210            versions.**
211
212            This option is **deprecated** and will be removed in the future.
213
214            Because of the above issues, and complexities of native ABI support
215            for the concept in general, Cranelift's support for multiple return
216            values may also be removed in the future (#9510). For the most
217            robust solution, it is recommended to build a convention on top of
218            Cranelift's primitives for passing multiple return values, for
219            example by allocating a stackslot in the caller, passing it as an
220            explicit StructReturn argument, storing return values in the callee,
221            and loading results in the caller.
222        "#,
223        false,
224    );
225
226    settings.add_bool(
227        "unwind_info",
228        "Generate unwind information.",
229        r#"
230            This increases metadata size and compile time, but allows for the
231            debugger to trace frames, is needed for GC tracing that relies on
232            libunwind (such as in Wasmtime), and is unconditionally needed on
233            certain platforms (such as Windows) that must always be able to unwind.
234          "#,
235        true,
236    );
237
238    settings.add_bool(
239        "preserve_frame_pointers",
240        "Preserve frame pointers",
241        r#"
242            Preserving frame pointers -- even inside leaf functions -- makes it
243            easy to capture the stack of a running program, without requiring any
244            side tables or metadata (like `.eh_frame` sections). Many sampling
245            profilers and similar tools walk frame pointers to capture stacks.
246            Enabling this option will play nice with those tools.
247        "#,
248        false,
249    );
250
251    settings.add_bool(
252        "machine_code_cfg_info",
253        "Generate CFG metadata for machine code.",
254        r#"
255            This increases metadata size and compile time, but allows for the
256            embedder to more easily post-process or analyze the generated
257            machine code. It provides code offsets for the start of each
258            basic block in the generated machine code, and a list of CFG
259            edges (with blocks identified by start offsets) between them.
260            This is useful for, e.g., machine-code analyses that verify certain
261            properties of the generated code.
262        "#,
263        false,
264    );
265
266    // Stack probing options.
267
268    settings.add_bool(
269        "enable_probestack",
270        "Enable the use of stack probes for supported calling conventions.",
271        "",
272        false,
273    );
274
275    settings.add_num(
276        "probestack_size_log2",
277        "The log2 of the size of the stack guard region.",
278        r#"
279            Stack frames larger than this size will have stack overflow checked
280            by calling the probestack function.
281
282            The default is 12, which translates to a size of 4096.
283        "#,
284        12,
285    );
286
287    settings.add_enum(
288        "probestack_strategy",
289        "Controls what kinds of stack probes are emitted.",
290        r#"
291            Supported strategies:
292
293            - `outline`: Always emits stack probes as calls to a probe stack function.
294            - `inline`: Always emits inline stack probes.
295        "#,
296        vec!["outline", "inline"],
297    );
298
299    // Spectre options. (Only read by wasmtime-cranelift)
300    // FIXME move configuration out of Cranelift into Wasmtime
301
302    settings.add_bool(
303        "enable_heap_access_spectre_mitigation",
304        "Enable Spectre mitigation on heap bounds checks.",
305        r#"
306            This is a no-op for any heap that needs no bounds checks; e.g.,
307            if the limit is static and the guard region is large enough that
308            the index cannot reach past it.
309
310            This option is enabled by default because it is highly
311            recommended for secure sandboxing. The embedder should consider
312            the security implications carefully before disabling this option.
313        "#,
314        true,
315    );
316
317    settings.add_bool(
318        "enable_table_access_spectre_mitigation",
319        "Enable Spectre mitigation on table bounds checks.",
320        r#"
321            This option uses a conditional move to ensure that when a table
322            access index is bounds-checked and a conditional branch is used
323            for the out-of-bounds case, a misspeculation of that conditional
324            branch (falsely predicted in-bounds) will select an in-bounds
325            index to load on the speculative path.
326
327            This option is enabled by default because it is highly
328            recommended for secure sandboxing. The embedder should consider
329            the security implications carefully before disabling this option.
330        "#,
331        true,
332    );
333
334    settings.add_bool(
335        "enable_incremental_compilation_cache_checks",
336        "Enable additional checks for debugging the incremental compilation cache.",
337        r#"
338            Enables additional checks that are useful during development of the incremental
339            compilation cache. This should be mostly useful for Cranelift hackers, as well as for
340            helping to debug false incremental cache positives for embedders.
341
342            This option is disabled by default and requires enabling the "incremental-cache" Cargo
343            feature in cranelift-codegen.
344        "#,
345        false,
346    );
347
348    settings.add_num(
349        "bb_padding_log2_minus_one",
350        "The log2 of the size to insert dummy padding between basic blocks",
351        r#"
352            This is a debugging option for stressing various cases during code
353            generation without requiring large functions. This will insert
354            0-byte padding between basic blocks of the specified size.
355
356            The amount of padding inserted two raised to the power of this value
357            minus one. If this value is 0 then no padding is inserted.
358
359            The default for this option is 0 to insert no padding as it's only
360            intended for testing and development.
361        "#,
362        0,
363    );
364
365    settings.add_num(
366        "log2_min_function_alignment",
367        "The log2 of the minimum alignment of functions",
368        "The bigger of this value and the default alignment will be used as actual alignment.",
369        0,
370    );
371
372    settings.add_bool(
373        "enable_compact_unwind_abi",
374        "Enable Mach-O compact unwind compatible code emission.",
375        r#"
376            This constrains function prologues and epilogues to the ABI shape
377            that Mach-O compact unwind can encode. Unwind instructions describe
378            which pairs of callee-save registers are saved and restored, but the
379            canonical stack frame layout is still expected: nonvolatile registers
380            must be placed near the top of the frame, immediately below the
381            return address.
382
383            The unwind encoding only supports register pairs emitted with `stp`;
384            it cannot encode individual registers. This may result in slightly
385            larger stack frames.
386        "#,
387        false,
388    );
389
390    // When adding new settings please check if they can also be added
391    // in cranelift/fuzzgen/src/lib.rs for fuzzing.
392    settings.build()
393}