celox_backend_cranelift/
cranelift_options.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
5pub enum CraneliftOptLevel {
6 None,
8 #[default]
10 Speed,
11 SpeedAndSize,
13}
14
15impl CraneliftOptLevel {
16 pub fn as_cranelift_str(self) -> &'static str {
18 match self {
19 CraneliftOptLevel::None => "none",
20 CraneliftOptLevel::Speed => "speed",
21 CraneliftOptLevel::SpeedAndSize => "speed_and_size",
22 }
23 }
24}
25
26#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
28pub enum RegallocAlgorithm {
29 #[default]
32 Backtracking,
33 SinglePass,
36}
37
38impl RegallocAlgorithm {
39 pub fn as_cranelift_str(self) -> &'static str {
41 match self {
42 RegallocAlgorithm::Backtracking => "backtracking",
43 RegallocAlgorithm::SinglePass => "single_pass",
44 }
45 }
46}
47
48#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
50pub struct CraneliftDiagnostics {
51 pub pass_timing: bool,
52}
53
54#[derive(Debug, Clone, Copy)]
56pub struct CraneliftOptions {
57 pub opt_level: CraneliftOptLevel,
59 pub regalloc_algorithm: RegallocAlgorithm,
61 pub enable_alias_analysis: bool,
64 pub enable_verifier: bool,
67 pub tail_call_split: bool,
69 pub diagnostics: CraneliftDiagnostics,
70}
71
72impl Default for CraneliftOptions {
73 fn default() -> Self {
74 Self {
75 opt_level: CraneliftOptLevel::default(),
76 regalloc_algorithm: RegallocAlgorithm::default(),
77 enable_alias_analysis: true,
78 enable_verifier: true,
79 tail_call_split: true,
80 diagnostics: CraneliftDiagnostics::default(),
81 }
82 }
83}
84
85impl CraneliftOptions {
86 pub fn fast_compile() -> Self {
88 Self {
89 opt_level: CraneliftOptLevel::None,
90 regalloc_algorithm: RegallocAlgorithm::SinglePass,
91 enable_alias_analysis: false,
92 enable_verifier: false,
93 tail_call_split: true,
94 diagnostics: CraneliftDiagnostics::default(),
95 }
96 }
97
98 pub fn for_speed_optimization(enabled: bool) -> Self {
100 if enabled {
101 Self::default()
102 } else {
103 Self::fast_compile()
104 }
105 }
106}