1 use crate::cdsl::settings::{SettingGroup, SettingGroupBuilder};
2 
define() -> SettingGroup3 pub fn define() -> SettingGroup {
4     let mut settings = SettingGroupBuilder::new("shared");
5 
6     settings.add_enum(
7         "opt_level",
8         r#"
9         Optimization level:
10 
11         - none: Minimise compile time by disabling most optimizations.
12         - speed: Generate the fastest possible code
13         - speed_and_size: like "speed", but also perform transformations
14           aimed at reducing code size.
15         "#,
16         vec!["none", "speed", "speed_and_size"],
17     );
18 
19     settings.add_bool(
20         "enable_verifier",
21         r#"
22         Run the Cranelift IR verifier at strategic times during compilation.
23 
24         This makes compilation slower but catches many bugs. The verifier is
25         disabled by default, except when reading Cranelift IR from a text file.
26         "#,
27         true,
28     );
29 
30     // Note that Cranelift doesn't currently need an is_pie flag, because PIE is
31     // just PIC where symbols can't be pre-empted, which can be expressed with the
32     // `colocated` flag on external functions and global values.
33     settings.add_bool(
34         "is_pic",
35         "Enable Position-Independent Code generation",
36         false,
37     );
38 
39     settings.add_bool(
40         "colocated_libcalls",
41         r#"
42             Use colocated libcalls.
43 
44             Generate code that assumes that libcalls can be declared "colocated",
45             meaning they will be defined along with the current function, such that
46             they can use more efficient addressing.
47             "#,
48         false,
49     );
50 
51     settings.add_bool(
52         "avoid_div_traps",
53         r#"
54             Generate explicit checks around native division instructions to avoid
55             their trapping.
56 
57             This is primarily used by SpiderMonkey which doesn't install a signal
58             handler for SIGFPE, but expects a SIGILL trap for division by zero.
59 
60             On ISAs like ARM where the native division instructions don't trap,
61             this setting has no effect - explicit checks are always inserted.
62             "#,
63         false,
64     );
65 
66     settings.add_bool(
67         "enable_float",
68         r#"
69             Enable the use of floating-point instructions
70 
71             Disabling use of floating-point instructions is not yet implemented.
72             "#,
73         true,
74     );
75 
76     settings.add_bool(
77         "enable_nan_canonicalization",
78         r#"
79             Enable NaN canonicalization
80 
81             This replaces NaNs with a single canonical value, for users requiring
82             entirely deterministic WebAssembly computation. This is not required
83             by the WebAssembly spec, so it is not enabled by default.
84             "#,
85         false,
86     );
87 
88     settings.add_bool(
89         "enable_pinned_reg",
90         r#"Enable the use of the pinned register.
91 
92         This register is excluded from register allocation, and is completely under the control of
93         the end-user. It is possible to read it via the get_pinned_reg instruction, and to set it
94         with the set_pinned_reg instruction.
95         "#,
96         false,
97     );
98 
99     settings.add_bool(
100         "use_pinned_reg_as_heap_base",
101         r#"Use the pinned register as the heap base.
102 
103         Enabling this requires the enable_pinned_reg setting to be set to true. It enables a custom
104         legalization of the `heap_addr` instruction so it will use the pinned register as the heap
105         base, instead of fetching it from a global value.
106 
107         Warning! Enabling this means that the pinned register *must* be maintained to contain the
108         heap base address at all times, during the lifetime of a function. Using the pinned
109         register for other purposes when this is set is very likely to cause crashes.
110         "#,
111         false,
112     );
113 
114     settings.add_bool("enable_simd", "Enable the use of SIMD instructions.", false);
115 
116     settings.add_bool(
117         "enable_atomics",
118         "Enable the use of atomic instructions",
119         true,
120     );
121 
122     settings.add_bool(
123         "enable_safepoints",
124         r#"
125             Enable safepoint instruction insertions.
126 
127             This will allow the emit_stackmaps() function to insert the safepoint
128             instruction on top of calls and interrupt traps in order to display the
129             live reference values at that point in the program.
130             "#,
131         false,
132     );
133 
134     // Settings specific to the `baldrdash` calling convention.
135 
136     settings.add_enum(
137         "libcall_call_conv",
138         r#"
139             Defines the calling convention to use for LibCalls call expansion,
140             since it may be different from the ISA default calling convention.
141 
142             The default value is to use the same calling convention as the ISA
143             default calling convention.
144 
145             This list should be kept in sync with the list of calling
146             conventions available in isa/call_conv.rs.
147         "#,
148         vec![
149             "isa_default",
150             "fast",
151             "cold",
152             "system_v",
153             "windows_fastcall",
154             "baldrdash_system_v",
155             "baldrdash_windows",
156             "probestack",
157         ],
158     );
159 
160     settings.add_num(
161         "baldrdash_prologue_words",
162         r#"
163             Number of pointer-sized words pushed by the baldrdash prologue.
164 
165             Functions with the `baldrdash` calling convention don't generate their
166             own prologue and epilogue. They depend on externally generated code
167             that pushes a fixed number of words in the prologue and restores them
168             in the epilogue.
169 
170             This setting configures the number of pointer-sized words pushed on the
171             stack when the Cranelift-generated code is entered. This includes the
172             pushed return address on x86.
173             "#,
174         0,
175     );
176 
177     // BaldrMonkey requires that not-yet-relocated function addresses be encoded
178     // as all-ones bitpatterns.
179     settings.add_bool(
180         "allones_funcaddrs",
181         "Emit not-yet-relocated function addresses as all-ones bit patterns.",
182         false,
183     );
184 
185     // Stack probing options.
186 
187     settings.add_bool(
188         "probestack_enabled",
189         r#"
190             Enable the use of stack probes, for calling conventions which support this
191             functionality.
192             "#,
193         true,
194     );
195 
196     settings.add_bool(
197         "probestack_func_adjusts_sp",
198         r#"
199             Set this to true of the stack probe function modifies the stack pointer
200             itself.
201             "#,
202         false,
203     );
204 
205     settings.add_num(
206         "probestack_size_log2",
207         r#"
208             The log2 of the size of the stack guard region.
209 
210             Stack frames larger than this size will have stack overflow checked
211             by calling the probestack function.
212 
213             The default is 12, which translates to a size of 4096.
214             "#,
215         12,
216     );
217 
218     // Jump table options.
219 
220     settings.add_bool(
221         "jump_tables_enabled",
222         "Enable the use of jump tables in generated machine code.",
223         true,
224     );
225 
226     settings.build()
227 }
228