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