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 can result in 62 better optimization, but is currently considered experimental. 63 "#, 64 false, 65 ); 66 67 settings.add_bool( 68 "enable_verifier", 69 "Run the Cranelift IR verifier at strategic times during compilation.", 70 r#" 71 This makes compilation slower but catches many bugs. The verifier is always enabled by 72 default, which is useful during development. 73 "#, 74 true, 75 ); 76 77 // Note that Cranelift doesn't currently need an is_pie flag, because PIE is 78 // just PIC where symbols can't be pre-empted, which can be expressed with the 79 // `colocated` flag on external functions and global values. 80 settings.add_bool( 81 "is_pic", 82 "Enable Position-Independent Code generation.", 83 "", 84 false, 85 ); 86 87 settings.add_bool( 88 "use_colocated_libcalls", 89 "Use colocated libcalls.", 90 r#" 91 Generate code that assumes that libcalls can be declared "colocated", 92 meaning they will be defined along with the current function, such that 93 they can use more efficient addressing. 94 "#, 95 false, 96 ); 97 98 settings.add_bool( 99 "avoid_div_traps", 100 "Generate explicit checks around native division instructions to avoid their trapping.", 101 r#" 102 Generate explicit checks around native division instructions to 103 avoid their trapping. 104 105 On ISAs like ARM where the native division instructions don't trap, 106 this setting has no effect - explicit checks are always inserted. 107 "#, 108 false, 109 ); 110 111 settings.add_bool( 112 "enable_float", 113 "Enable the use of floating-point instructions.", 114 r#" 115 Disabling use of floating-point instructions is not yet implemented. 116 "#, 117 true, 118 ); 119 120 settings.add_bool( 121 "enable_nan_canonicalization", 122 "Enable NaN canonicalization.", 123 r#" 124 This replaces NaNs with a single canonical value, for users requiring 125 entirely deterministic WebAssembly computation. This is not required 126 by the WebAssembly spec, so it is not enabled by default. 127 "#, 128 false, 129 ); 130 131 settings.add_bool( 132 "enable_pinned_reg", 133 "Enable the use of the pinned register.", 134 r#" 135 This register is excluded from register allocation, and is completely under the control of 136 the end-user. It is possible to read it via the get_pinned_reg instruction, and to set it 137 with the set_pinned_reg instruction. 138 "#, 139 false, 140 ); 141 142 settings.add_bool( 143 "enable_simd", 144 "Enable the use of SIMD instructions.", 145 "", 146 false, 147 ); 148 149 settings.add_bool( 150 "enable_atomics", 151 "Enable the use of atomic instructions", 152 "", 153 true, 154 ); 155 156 settings.add_bool( 157 "enable_safepoints", 158 "Enable safepoint instruction insertions.", 159 r#" 160 This will allow the emit_stack_maps() function to insert the safepoint 161 instruction on top of calls and interrupt traps in order to display the 162 live reference values at that point in the program. 163 "#, 164 false, 165 ); 166 167 settings.add_enum( 168 "tls_model", 169 "Defines the model used to perform TLS accesses.", 170 "", 171 vec!["none", "elf_gd", "macho", "coff"], 172 ); 173 174 settings.add_enum( 175 "libcall_call_conv", 176 "Defines the calling convention to use for LibCalls call expansion.", 177 r#" 178 This may be different from the ISA default calling convention. 179 180 The default value is to use the same calling convention as the ISA 181 default calling convention. 182 183 This list should be kept in sync with the list of calling 184 conventions available in isa/call_conv.rs. 185 "#, 186 vec![ 187 "isa_default", 188 "fast", 189 "cold", 190 "system_v", 191 "windows_fastcall", 192 "apple_aarch64", 193 "probestack", 194 ], 195 ); 196 197 settings.add_bool( 198 "enable_llvm_abi_extensions", 199 "Enable various ABI extensions defined by LLVM's behavior.", 200 r#" 201 In some cases, LLVM's implementation of an ABI (calling convention) 202 goes beyond a standard and supports additional argument types or 203 behavior. This option instructs Cranelift codegen to follow LLVM's 204 behavior where applicable. 205 206 Currently, this applies only to Windows Fastcall on x86-64, and 207 allows an `i128` argument to be spread across two 64-bit integer 208 registers. The Fastcall implementation otherwise does not support 209 `i128` arguments, and will panic if they are present and this 210 option is not set. 211 "#, 212 false, 213 ); 214 215 settings.add_bool( 216 "unwind_info", 217 "Generate unwind information.", 218 r#" 219 This increases metadata size and compile time, but allows for the 220 debugger to trace frames, is needed for GC tracing that relies on 221 libunwind (such as in Wasmtime), and is unconditionally needed on 222 certain platforms (such as Windows) that must always be able to unwind. 223 "#, 224 true, 225 ); 226 227 settings.add_bool( 228 "preserve_frame_pointers", 229 "Preserve frame pointers", 230 r#" 231 Preserving frame pointers -- even inside leaf functions -- makes it 232 easy to capture the stack of a running program, without requiring any 233 side tables or metadata (like `.eh_frame` sections). Many sampling 234 profilers and similar tools walk frame pointers to capture stacks. 235 Enabling this option will play nice with those tools. 236 "#, 237 false, 238 ); 239 240 settings.add_bool( 241 "machine_code_cfg_info", 242 "Generate CFG metadata for machine code.", 243 r#" 244 This increases metadata size and compile time, but allows for the 245 embedder to more easily post-process or analyze the generated 246 machine code. It provides code offsets for the start of each 247 basic block in the generated machine code, and a list of CFG 248 edges (with blocks identified by start offsets) between them. 249 This is useful for, e.g., machine-code analyses that verify certain 250 properties of the generated code. 251 "#, 252 false, 253 ); 254 255 // Stack probing options. 256 257 settings.add_bool( 258 "enable_probestack", 259 "Enable the use of stack probes for supported calling conventions.", 260 "", 261 false, 262 ); 263 264 settings.add_bool( 265 "probestack_func_adjusts_sp", 266 "Enable if the stack probe adjusts the stack pointer.", 267 "", 268 false, 269 ); 270 271 settings.add_num( 272 "probestack_size_log2", 273 "The log2 of the size of the stack guard region.", 274 r#" 275 Stack frames larger than this size will have stack overflow checked 276 by calling the probestack function. 277 278 The default is 12, which translates to a size of 4096. 279 "#, 280 12, 281 ); 282 283 settings.add_enum( 284 "probestack_strategy", 285 "Controls what kinds of stack probes are emitted.", 286 r#" 287 Supported strategies: 288 289 - `outline`: Always emits stack probes as calls to a probe stack function. 290 - `inline`: Always emits inline stack probes. 291 "#, 292 vec!["outline", "inline"], 293 ); 294 295 // Jump table options. 296 297 settings.add_bool( 298 "enable_jump_tables", 299 "Enable the use of jump tables in generated machine code.", 300 "", 301 true, 302 ); 303 304 // Spectre options. 305 306 settings.add_bool( 307 "enable_heap_access_spectre_mitigation", 308 "Enable Spectre mitigation on heap bounds checks.", 309 r#" 310 This is a no-op for any heap that needs no bounds checks; e.g., 311 if the limit is static and the guard region is large enough that 312 the index cannot reach past it. 313 314 This option is enabled by default because it is highly 315 recommended for secure sandboxing. The embedder should consider 316 the security implications carefully before disabling this option. 317 "#, 318 true, 319 ); 320 321 settings.add_bool( 322 "enable_table_access_spectre_mitigation", 323 "Enable Spectre mitigation on table bounds checks.", 324 r#" 325 This option uses a conditional move to ensure that when a table 326 access index is bounds-checked and a conditional branch is used 327 for the out-of-bounds case, a misspeculation of that conditional 328 branch (falsely predicted in-bounds) will select an in-bounds 329 index to load on the speculative path. 330 331 This option is enabled by default because it is highly 332 recommended for secure sandboxing. The embedder should consider 333 the security implications carefully before disabling this option. 334 "#, 335 true, 336 ); 337 338 settings.add_bool( 339 "enable_incremental_compilation_cache_checks", 340 "Enable additional checks for debugging the incremental compilation cache.", 341 r#" 342 Enables additional checks that are useful during development of the incremental 343 compilation cache. This should be mostly useful for Cranelift hackers, as well as for 344 helping to debug false incremental cache positives for embedders. 345 346 This option is disabled by default and requires enabling the "incremental-cache" Cargo 347 feature in cranelift-codegen. 348 "#, 349 false, 350 ); 351 352 // When adding new settings please check if they can also be added 353 // in cranelift/fuzzgen/src/lib.rs for fuzzing. 354 settings.build() 355 } 356