[meta] Rename base/ to shared/ in the Rust meta crate;
This commit is contained in:
committed by
Dan Gohman
parent
25fdda6134
commit
f78a61b998
4
cranelift/codegen/meta/src/shared/mod.rs
Normal file
4
cranelift/codegen/meta/src/shared/mod.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
//! Shared definitions for the Cranelift intermediate language.
|
||||
|
||||
pub mod settings;
|
||||
pub mod types;
|
||||
164
cranelift/codegen/meta/src/shared/settings.rs
Normal file
164
cranelift/codegen/meta/src/shared/settings.rs
Normal file
@@ -0,0 +1,164 @@
|
||||
use crate::cdsl::settings::{SettingGroup, SettingGroupBuilder};
|
||||
|
||||
pub fn generate() -> SettingGroup {
|
||||
let mut settings = SettingGroupBuilder::new("shared");
|
||||
|
||||
settings.add_enum(
|
||||
"opt_level",
|
||||
r#"
|
||||
Optimization level:
|
||||
|
||||
- default: Very profitable optimizations enabled, none slow.
|
||||
- best: Enable all optimizations
|
||||
- fastest: Optimize for compile time by disabling most optimizations.
|
||||
"#,
|
||||
vec!["default", "best", "fastest"],
|
||||
);
|
||||
|
||||
settings.add_bool(
|
||||
"enable_verifier",
|
||||
r#"
|
||||
Run the Cranelift IR verifier at strategic times during compilation.
|
||||
|
||||
This makes compilation slower but catches many bugs. The verifier is
|
||||
disabled by default, except when reading Cranelift IR from a text file.
|
||||
"#,
|
||||
true,
|
||||
);
|
||||
|
||||
// Note that Cranelift doesn't currently need an is_pie flag, because PIE is
|
||||
// just PIC where symbols can't be pre-empted, which can be expressed with the
|
||||
// `colocated` flag on external functions and global values.
|
||||
settings.add_bool(
|
||||
"is_pic",
|
||||
"Enable Position-Independent Code generation",
|
||||
false,
|
||||
);
|
||||
|
||||
settings.add_bool(
|
||||
"colocated_libcalls",
|
||||
r#"
|
||||
Use colocated libcalls.
|
||||
|
||||
Generate code that assumes that libcalls can be declared "colocated",
|
||||
meaning they will be defined along with the current function, such that
|
||||
they can use more efficient addressing.
|
||||
"#,
|
||||
false,
|
||||
);
|
||||
|
||||
settings.add_bool(
|
||||
"avoid_div_traps",
|
||||
r#"
|
||||
Generate explicit checks around native division instructions to avoid
|
||||
their trapping.
|
||||
|
||||
This is primarily used by SpiderMonkey which doesn't install a signal
|
||||
handler for SIGFPE, but expects a SIGILL trap for division by zero.
|
||||
|
||||
On ISAs like ARM where the native division instructions don't trap,
|
||||
this setting has no effect - explicit checks are always inserted.
|
||||
"#,
|
||||
false,
|
||||
);
|
||||
|
||||
settings.add_bool(
|
||||
"enable_float",
|
||||
r#"
|
||||
Enable the use of floating-point instructions
|
||||
|
||||
Disabling use of floating-point instructions is not yet implemented.
|
||||
"#,
|
||||
true,
|
||||
);
|
||||
|
||||
settings.add_bool(
|
||||
"enable_nan_canonicalization",
|
||||
r#"
|
||||
Enable NaN canonicalization
|
||||
|
||||
This replaces NaNs with a single canonical value, for users requiring
|
||||
entirely deterministic WebAssembly computation. This is not required
|
||||
by the WebAssembly spec, so it is not enabled by default.
|
||||
"#,
|
||||
false,
|
||||
);
|
||||
|
||||
settings.add_bool("enable_simd", "Enable the use of SIMD instructions.", true);
|
||||
|
||||
settings.add_bool(
|
||||
"enable_atomics",
|
||||
"Enable the use of atomic instructions",
|
||||
true,
|
||||
);
|
||||
|
||||
// Settings specific to the `baldrdash` calling convention.
|
||||
|
||||
settings.add_num(
|
||||
"baldrdash_prologue_words",
|
||||
r#"
|
||||
Number of pointer-sized words pushed by the baldrdash prologue.
|
||||
|
||||
Functions with the `baldrdash` calling convention don't generate their
|
||||
own prologue and epilogue. They depend on externally generated code
|
||||
that pushes a fixed number of words in the prologue and restores them
|
||||
in the epilogue.
|
||||
|
||||
This setting configures the number of pointer-sized words pushed on the
|
||||
stack when the Cranelift-generated code is entered. This includes the
|
||||
pushed return address on x86.
|
||||
"#,
|
||||
0,
|
||||
);
|
||||
|
||||
// BaldrMonkey requires that not-yet-relocated function addresses be encoded
|
||||
// as all-ones bitpatterns.
|
||||
settings.add_bool(
|
||||
"allones_funcaddrs",
|
||||
"Emit not-yet-relocated function addresses as all-ones bit patterns.",
|
||||
false,
|
||||
);
|
||||
|
||||
// Stack probing options.
|
||||
|
||||
settings.add_bool(
|
||||
"probestack_enabled",
|
||||
r#"
|
||||
Enable the use of stack probes, for calling conventions which support this
|
||||
functionality.
|
||||
"#,
|
||||
true,
|
||||
);
|
||||
|
||||
settings.add_bool(
|
||||
"probestack_func_adjusts_sp",
|
||||
r#"
|
||||
Set this to true of the stack probe function modifies the stack pointer
|
||||
itself.
|
||||
"#,
|
||||
false,
|
||||
);
|
||||
|
||||
settings.add_num(
|
||||
"probestack_size_log2",
|
||||
r#"
|
||||
The log2 of the size of the stack guard region.
|
||||
|
||||
Stack frames larger than this size will have stack overflow checked
|
||||
by calling the probestack function.
|
||||
|
||||
The default is 12, which translates to a size of 4096.
|
||||
"#,
|
||||
12,
|
||||
);
|
||||
|
||||
// Jump table options.
|
||||
|
||||
settings.add_bool(
|
||||
"jump_tables_enabled",
|
||||
"Enable the use of jump tables in generated machine code.",
|
||||
true,
|
||||
);
|
||||
|
||||
settings.finish()
|
||||
}
|
||||
188
cranelift/codegen/meta/src/shared/types.rs
Normal file
188
cranelift/codegen/meta/src/shared/types.rs
Normal file
@@ -0,0 +1,188 @@
|
||||
//! This module predefines all the Cranelift scalar types.
|
||||
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
pub enum Bool {
|
||||
/// 1-bit bool.
|
||||
B1 = 1,
|
||||
/// 8-bit bool.
|
||||
B8 = 8,
|
||||
/// 16-bit bool.
|
||||
B16 = 16,
|
||||
/// 32-bit bool.
|
||||
B32 = 32,
|
||||
/// 64-bit bool.
|
||||
B64 = 64,
|
||||
}
|
||||
|
||||
/// This provides an iterator through all of the supported bool variants.
|
||||
pub struct BoolIterator {
|
||||
index: u8,
|
||||
}
|
||||
|
||||
impl BoolIterator {
|
||||
pub fn new() -> Self {
|
||||
Self { index: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for BoolIterator {
|
||||
type Item = Bool;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let res = match self.index {
|
||||
0 => Some(Bool::B1),
|
||||
1 => Some(Bool::B8),
|
||||
2 => Some(Bool::B16),
|
||||
3 => Some(Bool::B32),
|
||||
4 => Some(Bool::B64),
|
||||
_ => return None,
|
||||
};
|
||||
self.index += 1;
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
pub enum Int {
|
||||
/// 8-bit int.
|
||||
I8 = 8,
|
||||
/// 16-bit int.
|
||||
I16 = 16,
|
||||
/// 32-bit int.
|
||||
I32 = 32,
|
||||
/// 64-bit int.
|
||||
I64 = 64,
|
||||
}
|
||||
|
||||
/// This provides an iterator through all of the supported int variants.
|
||||
pub struct IntIterator {
|
||||
index: u8,
|
||||
}
|
||||
|
||||
impl IntIterator {
|
||||
pub fn new() -> Self {
|
||||
Self { index: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for IntIterator {
|
||||
type Item = Int;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let res = match self.index {
|
||||
0 => Some(Int::I8),
|
||||
1 => Some(Int::I16),
|
||||
2 => Some(Int::I32),
|
||||
3 => Some(Int::I64),
|
||||
_ => return None,
|
||||
};
|
||||
self.index += 1;
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
pub enum Float {
|
||||
F32 = 32,
|
||||
F64 = 64,
|
||||
}
|
||||
|
||||
/// Iterator through the variants of the Float enum.
|
||||
pub struct FloatIterator {
|
||||
index: u8,
|
||||
}
|
||||
|
||||
impl FloatIterator {
|
||||
pub fn new() -> Self {
|
||||
Self { index: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
/// This provides an iterator through all of the supported float variants.
|
||||
impl Iterator for FloatIterator {
|
||||
type Item = Float;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let res = match self.index {
|
||||
0 => Some(Float::F32),
|
||||
1 => Some(Float::F64),
|
||||
_ => return None,
|
||||
};
|
||||
self.index += 1;
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
/// A type representing CPU flags.
|
||||
///
|
||||
/// Flags can't be stored in memory.
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
pub enum Flag {
|
||||
/// CPU flags from an integer comparison.
|
||||
IFlags,
|
||||
/// CPU flags from a floating point comparison.
|
||||
FFlags,
|
||||
}
|
||||
|
||||
/// Iterator through the variants of the Flag enum.
|
||||
pub struct FlagIterator {
|
||||
index: u8,
|
||||
}
|
||||
|
||||
impl FlagIterator {
|
||||
pub fn new() -> Self {
|
||||
Self { index: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for FlagIterator {
|
||||
type Item = Flag;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let res = match self.index {
|
||||
0 => Some(Flag::IFlags),
|
||||
1 => Some(Flag::FFlags),
|
||||
_ => return None,
|
||||
};
|
||||
self.index += 1;
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod iter_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn bool_iter_works() {
|
||||
let mut bool_iter = BoolIterator::new();
|
||||
assert_eq!(bool_iter.next(), Some(Bool::B1));
|
||||
assert_eq!(bool_iter.next(), Some(Bool::B8));
|
||||
assert_eq!(bool_iter.next(), Some(Bool::B16));
|
||||
assert_eq!(bool_iter.next(), Some(Bool::B32));
|
||||
assert_eq!(bool_iter.next(), Some(Bool::B64));
|
||||
assert_eq!(bool_iter.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn int_iter_works() {
|
||||
let mut int_iter = IntIterator::new();
|
||||
assert_eq!(int_iter.next(), Some(Int::I8));
|
||||
assert_eq!(int_iter.next(), Some(Int::I16));
|
||||
assert_eq!(int_iter.next(), Some(Int::I32));
|
||||
assert_eq!(int_iter.next(), Some(Int::I64));
|
||||
assert_eq!(int_iter.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn float_iter_works() {
|
||||
let mut float_iter = FloatIterator::new();
|
||||
assert_eq!(float_iter.next(), Some(Float::F32));
|
||||
assert_eq!(float_iter.next(), Some(Float::F64));
|
||||
assert_eq!(float_iter.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flag_iter_works() {
|
||||
let mut flag_iter = FlagIterator::new();
|
||||
assert_eq!(flag_iter.next(), Some(Flag::IFlags));
|
||||
assert_eq!(flag_iter.next(), Some(Flag::FFlags));
|
||||
assert_eq!(flag_iter.next(), None);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user