Update no_std support for Rust 2018 Edition.
With Rust 2018 Edition, the `mod std` trick to alias `core` names to `std` no longer works, so switch to just having the code use `core` explicitly. So instead, switch to just using `core::*` for things that in core. This is more consistent with other Rust no_std code. And it allows us to enable `no_std` mode unconditionally in the crates that support it, which makes testing a little easier. There actually three cases: - For things in std and also in core, like `cmp`: Just use them via `core::*`. - For things in std and also in alloc, like `Vec`: Import alloc as std, as use them from std. This allows them to work on both stable (which doesn't provide alloc, but we don't support no_std mode anyway) and nightly. - For HashMap and similar which are not in core or alloc, import them in the top-level lib.rs files from either std or the third-party hashmap_core crate, and then have the code use super::hashmap_core. Also, no_std support continues to be "best effort" at this time and not something most people need to be testing.
This commit is contained in:
@@ -94,7 +94,7 @@ The following crates support \`no\_std\`, although they do depend on liballoc:
|
||||
- cranelift-native
|
||||
- cranelift-wasm
|
||||
- cranelift-module
|
||||
- cranelift-simplejit
|
||||
- cranelift-preopt
|
||||
- cranelift
|
||||
|
||||
To use no\_std mode, disable the std feature and enable the core
|
||||
|
||||
@@ -3,6 +3,7 @@ name = "clif-wasm-fuzz"
|
||||
version = "0.0.1"
|
||||
authors = ["foote@fastly.com"]
|
||||
publish = false
|
||||
edition = "2018"
|
||||
|
||||
[package.metadata]
|
||||
cargo-fuzz = true
|
||||
|
||||
@@ -13,7 +13,7 @@ function banner {
|
||||
}
|
||||
|
||||
# Test those packages which have no_std support.
|
||||
LIBS="codegen frontend wasm native preopt module simplejit umbrella"
|
||||
LIBS="codegen frontend wasm native preopt module entity bforest umbrella"
|
||||
for LIB in $LIBS; do
|
||||
banner "Rust unit tests in $LIB"
|
||||
pushd "lib/$LIB" >/dev/null
|
||||
|
||||
@@ -17,6 +17,7 @@ cranelift-entity = { path = "../entity", version = "0.26.0", default-features =
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = ["cranelift-entity/std"]
|
||||
core = []
|
||||
|
||||
[badges]
|
||||
maintenance = { status = "experimental" }
|
||||
|
||||
@@ -31,24 +31,24 @@
|
||||
clippy::use_self
|
||||
)
|
||||
)]
|
||||
// Turns on no_std and alloc features if std is not available.
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![no_std]
|
||||
#![cfg_attr(not(feature = "std"), feature(alloc))]
|
||||
|
||||
/// This replaces `std` in builds with `core`.
|
||||
#[cfg(test)]
|
||||
#[cfg(not(feature = "std"))]
|
||||
mod std {
|
||||
extern crate alloc;
|
||||
pub use self::alloc::{boxed, string, vec};
|
||||
pub use core::*;
|
||||
}
|
||||
#[macro_use]
|
||||
extern crate alloc as std;
|
||||
#[cfg(test)]
|
||||
#[cfg(feature = "std")]
|
||||
#[macro_use]
|
||||
extern crate std;
|
||||
|
||||
#[macro_use]
|
||||
extern crate cranelift_entity as entity;
|
||||
use crate::entity::packed_option;
|
||||
|
||||
use std::borrow::BorrowMut;
|
||||
use std::cmp::Ordering;
|
||||
use core::borrow::BorrowMut;
|
||||
use core::cmp::Ordering;
|
||||
|
||||
mod map;
|
||||
mod node;
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
use super::{Comparator, Forest, Node, NodeData, NodePool, Path, INNER_SIZE};
|
||||
use crate::packed_option::PackedOption;
|
||||
#[cfg(test)]
|
||||
use std::fmt;
|
||||
use std::marker::PhantomData;
|
||||
use core::fmt;
|
||||
use core::marker::PhantomData;
|
||||
#[cfg(test)]
|
||||
use std::string::String;
|
||||
|
||||
@@ -429,7 +429,7 @@ where
|
||||
mod tests {
|
||||
use super::super::NodeData;
|
||||
use super::*;
|
||||
use std::mem;
|
||||
use core::mem;
|
||||
use std::vec::Vec;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//! B+-tree nodes.
|
||||
|
||||
use super::{slice_insert, slice_shift, Forest, Node, SetValue, INNER_SIZE};
|
||||
use std::borrow::{Borrow, BorrowMut};
|
||||
use std::fmt;
|
||||
use core::borrow::{Borrow, BorrowMut};
|
||||
use core::fmt;
|
||||
|
||||
/// B+-tree node.
|
||||
///
|
||||
@@ -584,7 +584,7 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::mem;
|
||||
use core::mem;
|
||||
use std::string::ToString;
|
||||
|
||||
// Forest impl for a set implementation.
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
use super::node::Removed;
|
||||
use super::{slice_insert, slice_shift, Comparator, Forest, Node, NodeData, NodePool, MAX_PATH};
|
||||
use std::borrow::Borrow;
|
||||
use std::marker::PhantomData;
|
||||
use core::borrow::Borrow;
|
||||
use core::marker::PhantomData;
|
||||
|
||||
#[cfg(test)]
|
||||
use std::fmt;
|
||||
use core::fmt;
|
||||
|
||||
pub(super) struct Path<F: Forest> {
|
||||
/// Number of path entries including the root and leaf nodes.
|
||||
@@ -706,7 +706,7 @@ impl<F: Forest> fmt::Display for Path<F> {
|
||||
mod tests {
|
||||
use super::super::{Forest, NodeData, NodePool};
|
||||
use super::*;
|
||||
use std::cmp::Ordering;
|
||||
use core::cmp::Ordering;
|
||||
|
||||
struct TC();
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ use super::Comparator;
|
||||
use super::{Forest, Node, NodeData};
|
||||
use crate::entity::PrimaryMap;
|
||||
#[cfg(test)]
|
||||
use std::fmt;
|
||||
use std::ops::{Index, IndexMut};
|
||||
use core::fmt;
|
||||
use core::ops::{Index, IndexMut};
|
||||
|
||||
/// A pool of nodes, including a free list.
|
||||
pub(super) struct NodePool<F: Forest> {
|
||||
@@ -84,8 +84,8 @@ impl<F: Forest> NodePool<F> {
|
||||
F::Key: fmt::Display,
|
||||
{
|
||||
use crate::entity::SparseSet;
|
||||
use std::borrow::Borrow;
|
||||
use std::cmp::Ordering;
|
||||
use core::borrow::Borrow;
|
||||
use core::cmp::Ordering;
|
||||
use std::vec::Vec;
|
||||
|
||||
// The root node can't be an inner node with just a single sub-tree. It should have been
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
use super::{Comparator, Forest, Node, NodeData, NodePool, Path, SetValue, INNER_SIZE};
|
||||
use crate::packed_option::PackedOption;
|
||||
#[cfg(test)]
|
||||
use std::fmt;
|
||||
use std::marker::PhantomData;
|
||||
use core::fmt;
|
||||
use core::marker::PhantomData;
|
||||
#[cfg(test)]
|
||||
use std::string::String;
|
||||
|
||||
@@ -357,7 +357,7 @@ where
|
||||
mod tests {
|
||||
use super::super::NodeData;
|
||||
use super::*;
|
||||
use std::mem;
|
||||
use core::mem;
|
||||
use std::vec::Vec;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -257,8 +257,8 @@ def gen_instruction_data_impl(fmt):
|
||||
'pub fn eq(&self, other: &Self, pool: &ir::ValueListPool)'
|
||||
' -> bool {',
|
||||
'}'):
|
||||
with fmt.indented('if ::std::mem::discriminant(self) != '
|
||||
'::std::mem::discriminant(other) {', '}'):
|
||||
with fmt.indented('if ::core::mem::discriminant(self) != '
|
||||
'::core::mem::discriminant(other) {', '}'):
|
||||
fmt.line('return false;')
|
||||
with fmt.indented('match (self, other) {', '}'):
|
||||
for f in InstructionFormat.all_formats:
|
||||
@@ -301,7 +301,7 @@ def gen_instruction_data_impl(fmt):
|
||||
hash the contents of any `ValueLists`.
|
||||
""")
|
||||
with fmt.indented(
|
||||
'pub fn hash<H: ::std::hash::Hasher>'
|
||||
'pub fn hash<H: ::core::hash::Hasher>'
|
||||
'(&self, state: &mut H, pool: &ir::ValueListPool) {',
|
||||
'}'):
|
||||
with fmt.indented('match *self {', '}'):
|
||||
@@ -323,13 +323,13 @@ def gen_instruction_data_impl(fmt):
|
||||
members.append(field.member)
|
||||
pat = n + ' { ' + ', '.join(members) + ' }'
|
||||
with fmt.indented(pat + ' => {', '}'):
|
||||
fmt.line('::std::hash::Hash::hash( '
|
||||
'&::std::mem::discriminant(self), state);')
|
||||
fmt.line('::std::hash::Hash::hash(&opcode, state);')
|
||||
fmt.line('::core::hash::Hash::hash( '
|
||||
'&::core::mem::discriminant(self), state);')
|
||||
fmt.line('::core::hash::Hash::hash(&opcode, state);')
|
||||
for field in f.imm_fields:
|
||||
fmt.line('::std::hash::Hash::hash(&{}, state);'
|
||||
fmt.line('::core::hash::Hash::hash(&{}, state);'
|
||||
.format(field.member))
|
||||
fmt.line('::std::hash::Hash::hash({}, state);'
|
||||
fmt.line('::core::hash::Hash::hash({}, state);'
|
||||
.format(args))
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//! `TargetIsa::legalize_signature()` method.
|
||||
|
||||
use crate::ir::{AbiParam, ArgumentExtension, ArgumentLoc, Type};
|
||||
use std::cmp::Ordering;
|
||||
use core::cmp::Ordering;
|
||||
use std::vec::Vec;
|
||||
|
||||
/// Legalization action to perform on a single argument or return value when converting a
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
use super::{Addend, CodeOffset, CodeSink, Reloc};
|
||||
use crate::ir::{ExternalName, JumpTable, SourceLoc, TrapCode};
|
||||
use std::ptr::write_unaligned;
|
||||
use core::ptr::write_unaligned;
|
||||
|
||||
/// A `CodeSink` that writes binary machine code directly into memory.
|
||||
///
|
||||
|
||||
@@ -13,7 +13,7 @@ pub use self::shrink::shrink_instructions;
|
||||
pub use crate::regalloc::RegDiversions;
|
||||
|
||||
use crate::ir::{ExternalName, Function, Inst, JumpTable, SourceLoc, TrapCode};
|
||||
use std::fmt;
|
||||
use core::fmt;
|
||||
|
||||
/// Offset in bytes from the beginning of the function.
|
||||
///
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
//!
|
||||
//! If you would like to add support for larger bitsets in the future, you need to change the trait
|
||||
//! bound Into<u32> and the u32 in the implementation of `max_bits()`.
|
||||
use std::convert::{From, Into};
|
||||
use std::mem::size_of;
|
||||
use std::ops::{Add, BitOr, Shl, Sub};
|
||||
use core::convert::{From, Into};
|
||||
use core::mem::size_of;
|
||||
use core::ops::{Add, BitOr, Shl, Sub};
|
||||
|
||||
/// A small bitset built on a single primitive integer type
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! The `CFGPrinter` utility.
|
||||
|
||||
use std::fmt::{Display, Formatter, Result, Write};
|
||||
use core::fmt::{Display, Formatter, Result, Write};
|
||||
|
||||
use crate::flowgraph::{BasicBlock, ControlFlowGraph};
|
||||
use crate::ir::instructions::BranchInfo;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Debug tracing helpers.
|
||||
use std::fmt;
|
||||
use core::fmt;
|
||||
|
||||
/// Prefix added to the log file names, just before the thread name or id.
|
||||
pub static LOG_FILENAME_PREFIX: &str = "cranelift.dbg.";
|
||||
|
||||
@@ -6,9 +6,9 @@ use crate::ir::instructions::BranchInfo;
|
||||
use crate::ir::{Ebb, ExpandedProgramPoint, Function, Inst, Layout, ProgramOrder, Value};
|
||||
use crate::packed_option::PackedOption;
|
||||
use crate::timing;
|
||||
use std::cmp;
|
||||
use std::cmp::Ordering;
|
||||
use std::mem;
|
||||
use core::cmp;
|
||||
use core::cmp::Ordering;
|
||||
use core::mem;
|
||||
use std::vec::Vec;
|
||||
|
||||
/// RPO numbers are not first assigned in a contiguous way but as multiples of STRIDE, to leave
|
||||
|
||||
@@ -28,7 +28,7 @@ use crate::entity::SecondaryMap;
|
||||
use crate::ir::instructions::BranchInfo;
|
||||
use crate::ir::{Ebb, Function, Inst};
|
||||
use crate::timing;
|
||||
use std::mem;
|
||||
use core::mem;
|
||||
|
||||
/// A basic block denoted by its enclosing Ebb and last instruction.
|
||||
#[derive(PartialEq, Eq)]
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::default::Default;
|
||||
use std::hash::{BuildHasherDefault, Hash, Hasher};
|
||||
use std::ops::BitXor;
|
||||
use super::{HashMap, HashSet};
|
||||
use core::default::Default;
|
||||
use core::hash::{BuildHasherDefault, Hash, Hasher};
|
||||
use core::ops::BitXor;
|
||||
|
||||
pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
|
||||
pub type FxHashSet<V> = HashSet<V, BuildHasherDefault<FxHasher>>;
|
||||
|
||||
@@ -59,7 +59,7 @@ pub trait InstInserterBase<'f>: Sized {
|
||||
fn insert_built_inst(self, inst: Inst, ctrl_typevar: Type) -> &'f mut DataFlowGraph;
|
||||
}
|
||||
|
||||
use std::marker::PhantomData;
|
||||
use core::marker::PhantomData;
|
||||
|
||||
/// Builder that inserts an instruction at the current position.
|
||||
///
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
//! are different rules for comparing integers and floating point numbers, so they use different
|
||||
//! condition codes.
|
||||
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::str::FromStr;
|
||||
use core::fmt::{self, Display, Formatter};
|
||||
use core::str::FromStr;
|
||||
|
||||
/// Common traits of condition codes.
|
||||
pub trait CondCode: Copy {
|
||||
|
||||
@@ -10,11 +10,11 @@ use crate::ir::{Ebb, FuncRef, Inst, SigRef, Signature, Type, Value, ValueList, V
|
||||
use crate::isa::TargetIsa;
|
||||
use crate::packed_option::ReservedValue;
|
||||
use crate::write::write_operands;
|
||||
use std::fmt;
|
||||
use std::iter;
|
||||
use std::mem;
|
||||
use std::ops::{Index, IndexMut};
|
||||
use std::u16;
|
||||
use core::fmt;
|
||||
use core::iter;
|
||||
use core::mem;
|
||||
use core::ops::{Index, IndexMut};
|
||||
use core::u16;
|
||||
|
||||
/// A data flow graph defines all instructions and extended basic blocks in a function as well as
|
||||
/// the data flow dependencies between them. The DFG also tracks values which can be either
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
//! format.
|
||||
|
||||
use crate::entity::entity_impl;
|
||||
use std::fmt;
|
||||
use std::u32;
|
||||
use core::fmt;
|
||||
use core::u32;
|
||||
|
||||
/// An opaque reference to an extended basic block in a function.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
@@ -305,8 +305,8 @@ impl From<Table> for AnyEntity {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use core::u32;
|
||||
use std::string::ToString;
|
||||
use std::u32;
|
||||
|
||||
#[test]
|
||||
fn value_with_number() {
|
||||
@@ -320,7 +320,7 @@ mod tests {
|
||||
#[test]
|
||||
fn memory() {
|
||||
use crate::packed_option::PackedOption;
|
||||
use std::mem;
|
||||
use core::mem;
|
||||
// This is the whole point of `PackedOption`.
|
||||
assert_eq!(
|
||||
mem::size_of::<Value>(),
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
use crate::ir::{ArgumentLoc, ExternalName, SigRef, Type};
|
||||
use crate::isa::{CallConv, RegInfo, RegUnit};
|
||||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
use core::fmt;
|
||||
use core::str::FromStr;
|
||||
use std::vec::Vec;
|
||||
|
||||
/// Function signature.
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
//! Cranelift, which compiles functions independently.
|
||||
|
||||
use crate::ir::LibCall;
|
||||
use std::cmp;
|
||||
use std::fmt::{self, Write};
|
||||
use std::str::FromStr;
|
||||
use core::cmp;
|
||||
use core::fmt::{self, Write};
|
||||
use core::str::FromStr;
|
||||
|
||||
const TESTCASE_NAME_LENGTH: usize = 16;
|
||||
|
||||
@@ -120,8 +120,8 @@ impl FromStr for ExternalName {
|
||||
mod tests {
|
||||
use super::ExternalName;
|
||||
use crate::ir::LibCall;
|
||||
use core::u32;
|
||||
use std::string::ToString;
|
||||
use std::u32;
|
||||
|
||||
#[test]
|
||||
fn display_testcase() {
|
||||
|
||||
@@ -16,7 +16,7 @@ use crate::ir::{JumpTableOffsets, JumpTables};
|
||||
use crate::isa::{CallConv, EncInfo, Encoding, Legalize, TargetIsa};
|
||||
use crate::regalloc::RegDiversions;
|
||||
use crate::write::write_function;
|
||||
use std::fmt;
|
||||
use core::fmt;
|
||||
|
||||
/// A function.
|
||||
///
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use crate::ir::immediates::{Imm64, Offset32};
|
||||
use crate::ir::{ExternalName, GlobalValue, Type};
|
||||
use crate::isa::TargetIsa;
|
||||
use std::fmt;
|
||||
use core::fmt;
|
||||
|
||||
/// Information about a global value declaration.
|
||||
#[derive(Clone)]
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use crate::ir::immediates::Uimm64;
|
||||
use crate::ir::{GlobalValue, Type};
|
||||
use std::fmt;
|
||||
use core::fmt;
|
||||
|
||||
/// Information about a heap declaration.
|
||||
#[derive(Clone)]
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
//! Each type here should have a corresponding definition in the `cranelift.immediates` Python
|
||||
//! module in the meta language.
|
||||
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::mem;
|
||||
use std::str::FromStr;
|
||||
use std::{i32, u32};
|
||||
use core::fmt::{self, Display, Formatter};
|
||||
use core::mem;
|
||||
use core::str::FromStr;
|
||||
use core::{i32, u32};
|
||||
|
||||
/// 64-bit immediate signed integer operand.
|
||||
///
|
||||
@@ -729,10 +729,10 @@ impl FromStr for Ieee64 {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::fmt::Display;
|
||||
use std::str::FromStr;
|
||||
use core::fmt::Display;
|
||||
use core::str::FromStr;
|
||||
use core::{f32, f64};
|
||||
use std::string::ToString;
|
||||
use std::{f32, f64};
|
||||
|
||||
#[test]
|
||||
fn format_imm64() {
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
//! A large part of this module is auto-generated from the instruction descriptions in the meta
|
||||
//! directory.
|
||||
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::str::FromStr;
|
||||
use core::fmt::{self, Display, Formatter};
|
||||
use core::ops::{Deref, DerefMut};
|
||||
use core::str::FromStr;
|
||||
use std::vec::Vec;
|
||||
|
||||
use crate::ir;
|
||||
@@ -561,7 +561,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn opcodes() {
|
||||
use std::mem;
|
||||
use core::mem;
|
||||
|
||||
let x = Opcode::Iadd;
|
||||
let mut y = Opcode::Isub;
|
||||
@@ -590,7 +590,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn instruction_data() {
|
||||
use std::mem;
|
||||
use core::mem;
|
||||
// The size of the `InstructionData` enum is important for performance. It should not
|
||||
// exceed 16 bytes. Use `Box<FooData>` out-of-line payloads for instruction formats that
|
||||
// require more space than that. It would be fine with a data structure smaller than 16
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
//! The actual table of destinations is stored in a `JumpTableData` struct defined in this module.
|
||||
|
||||
use crate::ir::entities::Ebb;
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::slice::{Iter, IterMut};
|
||||
use core::fmt::{self, Display, Formatter};
|
||||
use core::slice::{Iter, IterMut};
|
||||
use std::vec::Vec;
|
||||
|
||||
/// Contents of a jump table.
|
||||
|
||||
@@ -8,9 +8,9 @@ use crate::ir::progpoint::{ExpandedProgramPoint, ProgramOrder};
|
||||
use crate::ir::{Ebb, Inst};
|
||||
use crate::packed_option::PackedOption;
|
||||
use crate::timing;
|
||||
use core::cmp;
|
||||
use core::iter::{IntoIterator, Iterator};
|
||||
use log::debug;
|
||||
use std::cmp;
|
||||
use std::iter::{IntoIterator, Iterator};
|
||||
|
||||
/// The `Layout` struct determines the layout of EBBs and instructions in a function. It does not
|
||||
/// contain definitions of instructions or EBBs, but depends on `Inst` and `Ebb` entity references
|
||||
@@ -745,7 +745,7 @@ mod tests {
|
||||
use crate::cursor::{Cursor, CursorPosition};
|
||||
use crate::entity::EntityRef;
|
||||
use crate::ir::{Ebb, Inst, ProgramOrder, SourceLoc};
|
||||
use std::cmp::Ordering;
|
||||
use core::cmp::Ordering;
|
||||
use std::vec::Vec;
|
||||
|
||||
struct LayoutCursor<'f> {
|
||||
|
||||
@@ -5,8 +5,8 @@ use crate::ir::{
|
||||
Signature, Type,
|
||||
};
|
||||
use crate::isa::{CallConv, RegUnit, TargetIsa};
|
||||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
use core::fmt;
|
||||
use core::str::FromStr;
|
||||
|
||||
/// The name of a runtime library routine.
|
||||
///
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Memory operation flags.
|
||||
|
||||
use std::fmt;
|
||||
use core::fmt;
|
||||
|
||||
enum FlagBit {
|
||||
Notrap,
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
use crate::entity::EntityRef;
|
||||
use crate::ir::{Ebb, Inst, ValueDef};
|
||||
use std::cmp;
|
||||
use std::fmt;
|
||||
use std::u32;
|
||||
use core::cmp;
|
||||
use core::fmt;
|
||||
use core::u32;
|
||||
|
||||
/// A `ProgramPoint` represents a position in a function where the live range of an SSA value can
|
||||
/// begin or end. It can be either:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//! Cranelift tracks the original source location of each instruction, and preserves the source
|
||||
//! location when instructions are transformed.
|
||||
|
||||
use std::fmt;
|
||||
use core::fmt;
|
||||
|
||||
/// A source location.
|
||||
///
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
use crate::entity::{Iter, IterMut, Keys, PrimaryMap};
|
||||
use crate::ir::{StackSlot, Type};
|
||||
use crate::packed_option::PackedOption;
|
||||
use std::cmp;
|
||||
use std::fmt;
|
||||
use std::ops::{Index, IndexMut};
|
||||
use std::slice;
|
||||
use std::str::FromStr;
|
||||
use core::cmp;
|
||||
use core::fmt;
|
||||
use core::ops::{Index, IndexMut};
|
||||
use core::slice;
|
||||
use core::str::FromStr;
|
||||
use std::vec::Vec;
|
||||
|
||||
/// The size of an object on the stack, or the size of a stack frame.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use crate::ir::immediates::Uimm64;
|
||||
use crate::ir::{GlobalValue, Type};
|
||||
use std::fmt;
|
||||
use core::fmt;
|
||||
|
||||
/// Information about a table declaration.
|
||||
#[derive(Clone)]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Trap codes describing the reason for a trap.
|
||||
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::str::FromStr;
|
||||
use core::fmt::{self, Display, Formatter};
|
||||
use core::str::FromStr;
|
||||
|
||||
/// A trap code describing the reason for a trap.
|
||||
///
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Common types for the Cranelift code generator.
|
||||
|
||||
use std::default::Default;
|
||||
use std::fmt::{self, Debug, Display, Formatter};
|
||||
use core::default::Default;
|
||||
use core::fmt::{self, Debug, Display, Formatter};
|
||||
use target_lexicon::{PointerWidth, Triple};
|
||||
|
||||
/// The type of an SSA value.
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
use crate::ir::StackSlot;
|
||||
use crate::isa::{RegInfo, RegUnit};
|
||||
use std::fmt;
|
||||
use core::fmt;
|
||||
|
||||
/// Value location.
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
|
||||
@@ -15,8 +15,8 @@ use crate::isa::enc_tables::{self as shared_enc_tables, lookup_enclist, Encoding
|
||||
use crate::isa::Builder as IsaBuilder;
|
||||
use crate::isa::{EncInfo, RegClass, RegInfo, TargetIsa};
|
||||
use crate::regalloc;
|
||||
use core::fmt;
|
||||
use std::boxed::Box;
|
||||
use std::fmt;
|
||||
use target_lexicon::{Architecture, Triple};
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! ARM32 Settings.
|
||||
|
||||
use crate::settings::{self, detail, Builder};
|
||||
use std::fmt;
|
||||
use core::fmt;
|
||||
|
||||
// Include code generated by `lib/codegen/meta-python/gen_settings.py`. This file contains a public
|
||||
// `Flags` struct with an impl for all of the settings defined in
|
||||
|
||||
@@ -15,8 +15,8 @@ use crate::isa::enc_tables::{lookup_enclist, Encodings};
|
||||
use crate::isa::Builder as IsaBuilder;
|
||||
use crate::isa::{EncInfo, RegClass, RegInfo, TargetIsa};
|
||||
use crate::regalloc;
|
||||
use core::fmt;
|
||||
use std::boxed::Box;
|
||||
use std::fmt;
|
||||
use target_lexicon::Triple;
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! ARM64 Settings.
|
||||
|
||||
use crate::settings::{self, detail, Builder};
|
||||
use std::fmt;
|
||||
use core::fmt;
|
||||
|
||||
// Include code generated by `lib/codegen/meta-python/gen_settings.py`. This file contains a public
|
||||
// `Flags` struct with an impl for all of the settings defined in
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::fmt;
|
||||
use std::str;
|
||||
use core::fmt;
|
||||
use core::str;
|
||||
use target_lexicon::{CallingConvention, Triple};
|
||||
|
||||
/// Calling convention identifiers.
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::constant_hash::{probe, Table};
|
||||
use crate::ir::{Function, InstructionData, Opcode, Type};
|
||||
use crate::isa::{Encoding, Legalize};
|
||||
use crate::settings::PredicateView;
|
||||
use std::ops::Range;
|
||||
use core::ops::Range;
|
||||
|
||||
/// A recipe predicate.
|
||||
///
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::binemit::CodeOffset;
|
||||
use crate::ir::{Function, Inst};
|
||||
use crate::isa::constraints::{BranchRange, RecipeConstraints};
|
||||
use crate::regalloc::RegDiversions;
|
||||
use std::fmt;
|
||||
use core::fmt;
|
||||
|
||||
/// Bits needed to encode an instruction as binary machine code.
|
||||
///
|
||||
|
||||
@@ -63,9 +63,9 @@ use crate::result::CodegenResult;
|
||||
use crate::settings;
|
||||
use crate::settings::SetResult;
|
||||
use crate::timing;
|
||||
use core::fmt;
|
||||
use failure_derive::Fail;
|
||||
use std::boxed::Box;
|
||||
use std::fmt;
|
||||
use target_lexicon::{Architecture, PointerWidth, Triple};
|
||||
|
||||
#[cfg(build_riscv)]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Data structures describing the registers in an ISA.
|
||||
|
||||
use crate::entity::EntityRef;
|
||||
use std::fmt;
|
||||
use core::fmt;
|
||||
|
||||
/// Register units are the smallest units of register allocation.
|
||||
///
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::abi::{legalize_args, ArgAction, ArgAssigner, ValueConversion};
|
||||
use crate::ir::{self, AbiParam, ArgumentExtension, ArgumentLoc, ArgumentPurpose, Type};
|
||||
use crate::isa::RegClass;
|
||||
use crate::regalloc::RegisterSet;
|
||||
use std::i32;
|
||||
use core::i32;
|
||||
use target_lexicon::Triple;
|
||||
|
||||
struct Args {
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::ir::{Function, Inst, InstructionData};
|
||||
use crate::isa::{RegUnit, StackBaseMask, StackRef};
|
||||
use crate::predicates::is_signed_int;
|
||||
use crate::regalloc::RegDiversions;
|
||||
use std::u32;
|
||||
use core::u32;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/binemit-riscv.rs"));
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ use crate::isa::enc_tables::{self as shared_enc_tables, lookup_enclist, Encoding
|
||||
use crate::isa::Builder as IsaBuilder;
|
||||
use crate::isa::{EncInfo, RegClass, RegInfo, TargetIsa};
|
||||
use crate::regalloc;
|
||||
use core::fmt;
|
||||
use std::boxed::Box;
|
||||
use std::fmt;
|
||||
use target_lexicon::{PointerWidth, Triple};
|
||||
|
||||
#[allow(dead_code)]
|
||||
@@ -129,7 +129,7 @@ mod tests {
|
||||
use crate::ir::{Function, InstructionData, Opcode};
|
||||
use crate::isa;
|
||||
use crate::settings::{self, Configurable};
|
||||
use std::str::FromStr;
|
||||
use core::str::FromStr;
|
||||
use std::string::{String, ToString};
|
||||
use target_lexicon::triple;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! RISC-V Settings.
|
||||
|
||||
use crate::settings::{self, detail, Builder};
|
||||
use std::fmt;
|
||||
use core::fmt;
|
||||
|
||||
// Include code generated by `lib/codegen/meta-python/gen_settings.py`. This file contains a public
|
||||
// `Flags` struct with an impl for all of the settings defined in
|
||||
|
||||
@@ -14,7 +14,7 @@ use crate::isa::{CallConv, RegClass, RegUnit, TargetIsa};
|
||||
use crate::regalloc::RegisterSet;
|
||||
use crate::result::CodegenResult;
|
||||
use crate::stack_layout::layout_stack;
|
||||
use std::i32;
|
||||
use core::i32;
|
||||
use target_lexicon::{PointerWidth, Triple};
|
||||
|
||||
/// Argument registers for x86-64
|
||||
|
||||
@@ -17,8 +17,8 @@ use crate::isa::{EncInfo, RegClass, RegInfo, TargetIsa};
|
||||
use crate::regalloc;
|
||||
use crate::result::CodegenResult;
|
||||
use crate::timing;
|
||||
use core::fmt;
|
||||
use std::boxed::Box;
|
||||
use std::fmt;
|
||||
use target_lexicon::{PointerWidth, Triple};
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! x86 Settings.
|
||||
|
||||
use crate::settings::{self, detail, Builder};
|
||||
use std::fmt;
|
||||
use core::fmt;
|
||||
|
||||
// Include code generated by `lib/codegen/meta-python/gen_settings.py`. This file contains a public
|
||||
// `Flags` struct with an impl for all of the settings defined in
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
use crate::cursor::{Cursor, CursorPosition, FuncCursor};
|
||||
use crate::flowgraph::{BasicBlock, ControlFlowGraph};
|
||||
use crate::ir::{self, Ebb, Inst, InstBuilder, InstructionData, Opcode, Type, Value, ValueDef};
|
||||
use std::iter;
|
||||
use core::iter;
|
||||
use std::vec::Vec;
|
||||
|
||||
/// Split `value` into two values using the `isplit` semantics. Do this by reusing existing values
|
||||
|
||||
@@ -40,15 +40,20 @@
|
||||
clippy::use_self
|
||||
)
|
||||
)]
|
||||
// Turns on no_std and alloc features if std is not available.
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![no_std]
|
||||
#![cfg_attr(not(feature = "std"), feature(alloc))]
|
||||
// TODO: Remove this workaround once https://github.com/rust-lang/rust/issues/27747 is done.
|
||||
#![cfg_attr(not(feature = "std"), feature(slice_concat_ext))]
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
#[macro_use]
|
||||
extern crate alloc;
|
||||
extern crate alloc as std;
|
||||
#[cfg(feature = "std")]
|
||||
#[macro_use]
|
||||
extern crate std;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use hashmap_core::{map as hash_map, HashMap, HashSet};
|
||||
#[cfg(feature = "std")]
|
||||
use std::collections::{hash_map, HashMap, HashSet};
|
||||
|
||||
pub use crate::context::Context;
|
||||
pub use crate::legalizer::legalize_function;
|
||||
@@ -101,20 +106,5 @@ mod unreachable_code;
|
||||
|
||||
pub use crate::result::{CodegenError, CodegenResult};
|
||||
|
||||
/// This replaces `std` in builds with `core`.
|
||||
#[cfg(not(feature = "std"))]
|
||||
mod std {
|
||||
pub use alloc::{boxed, slice, string, vec};
|
||||
pub use core::*;
|
||||
pub mod collections {
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate hashmap_core;
|
||||
|
||||
pub use self::hashmap_core::map as hash_map;
|
||||
pub use self::hashmap_core::{HashMap, HashSet};
|
||||
pub use alloc::collections::BTreeSet;
|
||||
}
|
||||
}
|
||||
|
||||
/// Version number of this crate.
|
||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Rearrange the elements in a slice according to a predicate.
|
||||
|
||||
use std::mem;
|
||||
use core::mem;
|
||||
|
||||
/// Rearrange the elements of the mutable slice `s` such that elements where `p(t)` is true precede
|
||||
/// the elements where `p(t)` is false.
|
||||
|
||||
@@ -8,9 +8,9 @@ use crate::isa::TargetIsa;
|
||||
use crate::result::CodegenError;
|
||||
use crate::verifier::{VerifierError, VerifierErrors};
|
||||
use crate::write::{decorate_function, FuncWriter, PlainWriter};
|
||||
use core::fmt;
|
||||
use core::fmt::Write;
|
||||
use std::boxed::Box;
|
||||
use std::fmt;
|
||||
use std::fmt::Write;
|
||||
use std::string::{String, ToString};
|
||||
use std::vec::Vec;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
//!
|
||||
//! Despite their using an unsafe block, these functions are completely safe.
|
||||
|
||||
use std::slice;
|
||||
use core::slice;
|
||||
|
||||
pub fn ref_slice<T>(s: &T) -> &[T] {
|
||||
unsafe { slice::from_raw_parts(s, 1) }
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
use crate::ir::{AbiParam, ArgumentLoc};
|
||||
use crate::isa::{ConstraintKind, OperandConstraint, RegClassIndex, RegInfo, TargetIsa};
|
||||
use std::fmt;
|
||||
use core::fmt;
|
||||
|
||||
/// Preferred register allocation for an SSA value.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
|
||||
@@ -17,11 +17,11 @@ use crate::regalloc::affinity::Affinity;
|
||||
use crate::regalloc::liveness::Liveness;
|
||||
use crate::regalloc::virtregs::{VirtReg, VirtRegs};
|
||||
use crate::timing;
|
||||
use core::cmp;
|
||||
use core::fmt;
|
||||
use core::iter;
|
||||
use core::slice;
|
||||
use log::debug;
|
||||
use std::cmp;
|
||||
use std::fmt;
|
||||
use std::iter;
|
||||
use std::slice;
|
||||
use std::vec::Vec;
|
||||
|
||||
// # Implementation
|
||||
|
||||
@@ -57,8 +57,8 @@ use crate::regalloc::register_set::RegisterSet;
|
||||
use crate::regalloc::solver::{Solver, SolverError};
|
||||
use crate::regalloc::RegDiversions;
|
||||
use crate::timing;
|
||||
use core::mem;
|
||||
use log::debug;
|
||||
use std::mem;
|
||||
|
||||
/// Data structures for the coloring pass.
|
||||
///
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
//! EBB.
|
||||
|
||||
use crate::fx::FxHashMap;
|
||||
use crate::hash_map::{Entry, Iter};
|
||||
use crate::ir::{InstructionData, Opcode};
|
||||
use crate::ir::{StackSlot, Value, ValueLoc, ValueLocations};
|
||||
use crate::isa::{RegInfo, RegUnit};
|
||||
use std::collections::hash_map::{Entry, Iter};
|
||||
use std::fmt;
|
||||
use core::fmt;
|
||||
|
||||
/// A diversion of a value from its original location to a new register or stack location.
|
||||
///
|
||||
|
||||
@@ -183,8 +183,8 @@ use crate::isa::{EncInfo, OperandConstraint, TargetIsa};
|
||||
use crate::regalloc::affinity::Affinity;
|
||||
use crate::regalloc::liverange::{LiveRange, LiveRangeContext, LiveRangeForest};
|
||||
use crate::timing;
|
||||
use std::mem;
|
||||
use std::ops::Index;
|
||||
use core::mem;
|
||||
use core::ops::Index;
|
||||
use std::vec::Vec;
|
||||
|
||||
/// A set of live ranges, indexed by value number.
|
||||
|
||||
@@ -111,8 +111,8 @@ use crate::bforest;
|
||||
use crate::entity::SparseMapValue;
|
||||
use crate::ir::{Ebb, ExpandedProgramPoint, Inst, Layout, ProgramOrder, ProgramPoint, Value};
|
||||
use crate::regalloc::affinity::Affinity;
|
||||
use std::cmp::Ordering;
|
||||
use std::marker::PhantomData;
|
||||
use core::cmp::Ordering;
|
||||
use core::marker::PhantomData;
|
||||
|
||||
/// Global live range of a single SSA value.
|
||||
///
|
||||
@@ -461,7 +461,7 @@ mod tests {
|
||||
use crate::entity::EntityRef;
|
||||
use crate::ir::{Ebb, Inst, Value};
|
||||
use crate::ir::{ExpandedProgramPoint, ProgramOrder};
|
||||
use std::cmp::Ordering;
|
||||
use core::cmp::Ordering;
|
||||
use std::vec::Vec;
|
||||
|
||||
// Dummy program order which simply compares indexes.
|
||||
|
||||
@@ -38,9 +38,9 @@
|
||||
|
||||
use crate::isa::registers::{RegClass, RegClassMask, RegInfo, MAX_TRACKED_TOPRCS};
|
||||
use crate::regalloc::RegisterSet;
|
||||
use std::cmp::min;
|
||||
use std::fmt;
|
||||
use std::iter::ExactSizeIterator;
|
||||
use core::cmp::min;
|
||||
use core::fmt;
|
||||
use core::iter::ExactSizeIterator;
|
||||
|
||||
/// Information per top-level register class.
|
||||
///
|
||||
@@ -275,9 +275,9 @@ mod tests {
|
||||
use super::Pressure;
|
||||
use crate::isa::{RegClass, TargetIsa};
|
||||
use crate::regalloc::RegisterSet;
|
||||
use std::borrow::Borrow;
|
||||
use core::borrow::Borrow;
|
||||
use core::str::FromStr;
|
||||
use std::boxed::Box;
|
||||
use std::str::FromStr;
|
||||
use target_lexicon::triple;
|
||||
|
||||
// Make an arm32 `TargetIsa`, if possible.
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
//! share a register unit can't be in use at the same time.
|
||||
|
||||
use crate::isa::registers::{RegClass, RegInfo, RegUnit, RegUnitMask};
|
||||
use std::char;
|
||||
use std::fmt;
|
||||
use std::iter::ExactSizeIterator;
|
||||
use std::mem::size_of_val;
|
||||
use core::char;
|
||||
use core::fmt;
|
||||
use core::iter::ExactSizeIterator;
|
||||
use core::mem::size_of_val;
|
||||
|
||||
/// Set of registers available for allocation.
|
||||
#[derive(Clone)]
|
||||
|
||||
@@ -104,11 +104,11 @@ use crate::entity::{SparseMap, SparseMapValue};
|
||||
use crate::ir::Value;
|
||||
use crate::isa::{RegClass, RegUnit};
|
||||
use crate::regalloc::register_set::RegSetIter;
|
||||
use core::cmp;
|
||||
use core::fmt;
|
||||
use core::mem;
|
||||
use core::u16;
|
||||
use log::debug;
|
||||
use std::cmp;
|
||||
use std::fmt;
|
||||
use std::mem;
|
||||
use std::u16;
|
||||
use std::vec::Vec;
|
||||
|
||||
/// A variable in the constraint problem.
|
||||
@@ -1134,8 +1134,8 @@ mod tests {
|
||||
use crate::ir::Value;
|
||||
use crate::isa::{RegClass, RegInfo, RegUnit, TargetIsa};
|
||||
use crate::regalloc::RegisterSet;
|
||||
use core::str::FromStr;
|
||||
use std::boxed::Box;
|
||||
use std::str::FromStr;
|
||||
use target_lexicon::triple;
|
||||
|
||||
// Make an arm32 `TargetIsa`, if possible.
|
||||
|
||||
@@ -27,8 +27,8 @@ use crate::regalloc::pressure::Pressure;
|
||||
use crate::regalloc::virtregs::VirtRegs;
|
||||
use crate::timing;
|
||||
use crate::topo_order::TopoOrder;
|
||||
use core::fmt;
|
||||
use log::debug;
|
||||
use std::fmt;
|
||||
use std::vec::Vec;
|
||||
|
||||
/// Return a top-level register class which contains `unit`.
|
||||
|
||||
@@ -19,8 +19,8 @@ use crate::entity::{Keys, PrimaryMap, SecondaryMap};
|
||||
use crate::ir::{Function, Value};
|
||||
use crate::packed_option::PackedOption;
|
||||
use crate::ref_slice::ref_slice;
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt;
|
||||
use core::cmp::Ordering;
|
||||
use core::fmt;
|
||||
use std::vec::Vec;
|
||||
|
||||
/// A virtual register reference.
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
//! `ScopedHashMap`
|
||||
//!
|
||||
//! This module defines a struct `ScopedHashMap<K, V>` which defines a `HashMap`-like
|
||||
//! This module defines a struct `ScopedHashMap<K, V>` which defines a `FxHashMap`-like
|
||||
//! container that has a concept of scopes that can be entered and exited, such that
|
||||
//! values inserted while inside a scope aren't visible outside the scope.
|
||||
|
||||
use crate::fx::FxHashMap;
|
||||
use std::collections::hash_map;
|
||||
use std::hash::Hash;
|
||||
use std::mem;
|
||||
use core::hash::Hash;
|
||||
use core::mem;
|
||||
|
||||
struct Val<K, V> {
|
||||
value: V,
|
||||
@@ -17,7 +16,7 @@ struct Val<K, V> {
|
||||
|
||||
/// A view into an occupied entry in a `ScopedHashMap`. It is part of the `Entry` enum.
|
||||
pub struct OccupiedEntry<'a, K: 'a, V: 'a> {
|
||||
entry: hash_map::OccupiedEntry<'a, K, Val<K, V>>,
|
||||
entry: super::hash_map::OccupiedEntry<'a, K, Val<K, V>>,
|
||||
}
|
||||
|
||||
impl<'a, K, V> OccupiedEntry<'a, K, V> {
|
||||
@@ -29,7 +28,7 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
|
||||
|
||||
/// A view into a vacant entry in a `ScopedHashMap`. It is part of the `Entry` enum.
|
||||
pub struct VacantEntry<'a, K: 'a, V: 'a> {
|
||||
entry: hash_map::VacantEntry<'a, K, Val<K, V>>,
|
||||
entry: super::hash_map::VacantEntry<'a, K, Val<K, V>>,
|
||||
next_key: Option<K>,
|
||||
depth: usize,
|
||||
}
|
||||
@@ -53,7 +52,7 @@ pub enum Entry<'a, K: 'a, V: 'a> {
|
||||
Vacant(VacantEntry<'a, K, V>),
|
||||
}
|
||||
|
||||
/// A wrapper around a `HashMap` which adds the concept of scopes. Items inserted
|
||||
/// A wrapper around a `FxHashMap` which adds the concept of scopes. Items inserted
|
||||
/// within a scope are removed when the scope is exited.
|
||||
///
|
||||
/// Shadowing, where one scope has entries with the same keys as a containing scope,
|
||||
@@ -77,10 +76,10 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Similar to `HashMap::entry`, gets the given key's corresponding entry in the map for
|
||||
/// Similar to `FxHashMap::entry`, gets the given key's corresponding entry in the map for
|
||||
/// in-place manipulation.
|
||||
pub fn entry(&mut self, key: K) -> Entry<K, V> {
|
||||
use self::hash_map::Entry::*;
|
||||
use super::hash_map::Entry::*;
|
||||
match self.map.entry(key) {
|
||||
Occupied(entry) => Entry::Occupied(OccupiedEntry { entry }),
|
||||
Vacant(entry) => {
|
||||
@@ -104,7 +103,7 @@ where
|
||||
pub fn decrement_depth(&mut self) {
|
||||
// Remove all elements inserted at the current depth.
|
||||
while let Some(key) = self.last_insert.clone() {
|
||||
use self::hash_map::Entry::*;
|
||||
use crate::hash_map::Entry::*;
|
||||
match self.map.entry(key) {
|
||||
Occupied(entry) => {
|
||||
if entry.get().depth != self.current_depth {
|
||||
|
||||
@@ -22,16 +22,12 @@
|
||||
|
||||
use crate::constant_hash::{probe, simple_hash};
|
||||
use crate::isa::TargetIsa;
|
||||
use core::fmt;
|
||||
use core::str;
|
||||
use failure_derive::Fail;
|
||||
use std::boxed::Box;
|
||||
use std::fmt;
|
||||
use std::str;
|
||||
use std::string::{String, ToString};
|
||||
|
||||
// TODO: Remove this workaround once https://github.com/rust-lang/rust/issues/27747 is done.
|
||||
#[cfg(not(feature = "std"))]
|
||||
use std::slice::SliceConcatExt;
|
||||
|
||||
/// A string-based configurator for settings groups.
|
||||
///
|
||||
/// The `Configurable` protocol allows settings to be modified by name before a finished `Flags`
|
||||
@@ -111,10 +107,21 @@ fn parse_bool_value(value: &str) -> SetResult<bool> {
|
||||
fn parse_enum_value(value: &str, choices: &[&str]) -> SetResult<u8> {
|
||||
match choices.iter().position(|&tag| tag == value) {
|
||||
Some(idx) => Ok(idx as u8),
|
||||
None => Err(SetError::BadValue(format!(
|
||||
"any among {}",
|
||||
choices.join(", ")
|
||||
))),
|
||||
None => {
|
||||
// TODO: Use `join` instead of this code, once
|
||||
// https://github.com/rust-lang/rust/issues/27747 is resolved.
|
||||
let mut all_choices = String::new();
|
||||
let mut first = true;
|
||||
for choice in choices {
|
||||
if first {
|
||||
first = false
|
||||
} else {
|
||||
all_choices += ", ";
|
||||
}
|
||||
all_choices += choice;
|
||||
}
|
||||
Err(SetError::BadValue(format!("any among {}", all_choices)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +211,7 @@ impl<'a> PredicateView<'a> {
|
||||
/// code in other modules.
|
||||
pub mod detail {
|
||||
use crate::constant_hash;
|
||||
use std::fmt;
|
||||
use core::fmt;
|
||||
|
||||
/// An instruction group template.
|
||||
pub struct Template {
|
||||
|
||||
@@ -5,8 +5,8 @@ use crate::dominator_tree::DominatorTree;
|
||||
use crate::ir::{Function, Inst, InstructionData, Opcode, Type};
|
||||
use crate::scoped_hash_map::ScopedHashMap;
|
||||
use crate::timing;
|
||||
use std::cell::{Ref, RefCell};
|
||||
use std::hash::{Hash, Hasher};
|
||||
use core::cell::{Ref, RefCell};
|
||||
use core::hash::{Hash, Hasher};
|
||||
use std::vec::Vec;
|
||||
|
||||
/// Test whether the given opcode is unsafe to even consider for GVN.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use crate::ir::stackslot::{StackOffset, StackSize, StackSlotKind};
|
||||
use crate::ir::StackSlots;
|
||||
use crate::result::{CodegenError, CodegenResult};
|
||||
use std::cmp::{max, min};
|
||||
use core::cmp::{max, min};
|
||||
|
||||
/// Compute the stack frame layout.
|
||||
///
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//!
|
||||
//! This modules provides facilities for timing the execution of individual compilation passes.
|
||||
|
||||
use std::fmt;
|
||||
use core::fmt;
|
||||
|
||||
pub use self::details::{add_to_current, take_current, PassTimes, TimingToken};
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ mod tests {
|
||||
use crate::dominator_tree::DominatorTree;
|
||||
use crate::flowgraph::ControlFlowGraph;
|
||||
use crate::ir::{Function, InstBuilder};
|
||||
use std::iter;
|
||||
use core::iter;
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::regalloc::liveness::Liveness;
|
||||
use crate::regalloc::liverange::LiveRange;
|
||||
use crate::timing;
|
||||
use crate::verifier::{VerifierErrors, VerifierStepResult};
|
||||
use std::cmp::Ordering;
|
||||
use core::cmp::Ordering;
|
||||
|
||||
/// Verify liveness information for `func`.
|
||||
///
|
||||
|
||||
@@ -72,10 +72,10 @@ use crate::isa::TargetIsa;
|
||||
use crate::iterators::IteratorExtras;
|
||||
use crate::settings::FlagsOrIsa;
|
||||
use crate::timing;
|
||||
use core::cmp::Ordering;
|
||||
use core::fmt::{self, Display, Formatter, Write};
|
||||
use failure_derive::Fail;
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::BTreeSet;
|
||||
use std::fmt::{self, Display, Formatter, Write};
|
||||
use std::string::String;
|
||||
use std::vec::Vec;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::ir::entities::AnyEntity;
|
||||
use crate::ir::{DataFlowGraph, Ebb, Function, Inst, SigRef, Type, Value, ValueDef};
|
||||
use crate::isa::{RegInfo, TargetIsa};
|
||||
use crate::packed_option::ReservedValue;
|
||||
use std::fmt::{self, Write};
|
||||
use core::fmt::{self, Write};
|
||||
use std::string::String;
|
||||
use std::vec::Vec;
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ edition = "2018"
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = []
|
||||
core = []
|
||||
|
||||
[badges]
|
||||
maintenance = { status = "experimental" }
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
use crate::iter::{Iter, IterMut};
|
||||
use crate::keys::Keys;
|
||||
use crate::EntityRef;
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::{Index, IndexMut};
|
||||
use std::slice;
|
||||
use core::marker::PhantomData;
|
||||
use core::ops::{Index, IndexMut};
|
||||
use core::slice;
|
||||
use std::boxed::Box;
|
||||
|
||||
/// A slice mapping `K -> V` allocating dense entity references.
|
||||
///
|
||||
@@ -140,6 +141,7 @@ where
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::primary::PrimaryMap;
|
||||
use std::vec::Vec;
|
||||
|
||||
// `EntityRef` impl for testing.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//! A double-ended iterator over entity references and entities.
|
||||
|
||||
use crate::EntityRef;
|
||||
use std::iter::Enumerate;
|
||||
use std::marker::PhantomData;
|
||||
use std::slice;
|
||||
use core::iter::Enumerate;
|
||||
use core::marker::PhantomData;
|
||||
use core::slice;
|
||||
|
||||
/// Iterate over all keys in order.
|
||||
pub struct Iter<'a, K: EntityRef, V>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
//! A double-ended iterator over entity references.
|
||||
//!
|
||||
//! When `std::iter::Step` is stabilized, `Keys` could be implemented as a wrapper around
|
||||
//! `std::ops::Range`, but for now, we implement it manually.
|
||||
//! When `core::iter::Step` is stabilized, `Keys` could be implemented as a wrapper around
|
||||
//! `core::ops::Range`, but for now, we implement it manually.
|
||||
|
||||
use crate::EntityRef;
|
||||
use std::marker::PhantomData;
|
||||
use core::marker::PhantomData;
|
||||
|
||||
/// Iterate over all keys in order.
|
||||
pub struct Keys<K: EntityRef> {
|
||||
|
||||
@@ -50,17 +50,15 @@
|
||||
clippy::use_self
|
||||
)
|
||||
)]
|
||||
// Turns on no_std and alloc features if std is not available.
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![no_std]
|
||||
#![cfg_attr(not(feature = "std"), feature(alloc))]
|
||||
|
||||
/// This replaces `std` in builds with `core`.
|
||||
#[cfg(not(feature = "std"))]
|
||||
mod std {
|
||||
extern crate alloc;
|
||||
pub use self::alloc::{boxed, string, vec};
|
||||
pub use core::*;
|
||||
}
|
||||
#[macro_use]
|
||||
extern crate alloc as std;
|
||||
#[cfg(feature = "std")]
|
||||
#[macro_use]
|
||||
extern crate std;
|
||||
|
||||
// Re-export core so that the macros works with both std and no_std crates
|
||||
#[doc(hidden)]
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//! Small lists of entity references.
|
||||
use crate::packed_option::ReservedValue;
|
||||
use crate::EntityRef;
|
||||
use std::marker::PhantomData;
|
||||
use std::mem;
|
||||
use core::marker::PhantomData;
|
||||
use core::mem;
|
||||
use std::vec::Vec;
|
||||
|
||||
/// A small list of entity references allocated from a pool.
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
use crate::iter::{Iter, IterMut};
|
||||
use crate::keys::Keys;
|
||||
use crate::EntityRef;
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::{Index, IndexMut};
|
||||
use std::slice;
|
||||
use core::marker::PhantomData;
|
||||
use core::ops::{Index, IndexMut};
|
||||
use core::slice;
|
||||
use std::vec::Vec;
|
||||
|
||||
/// A mapping `K -> V` for densely indexed entity references.
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
//! This module provides a `PackedOption<T>` for types that have a reserved value that can be used
|
||||
//! to represent `None`.
|
||||
|
||||
use std::fmt;
|
||||
use std::mem;
|
||||
use core::fmt;
|
||||
use core::mem;
|
||||
|
||||
/// Types that have a reserved value which can't be created any other way.
|
||||
pub trait ReservedValue: Eq {
|
||||
|
||||
@@ -3,10 +3,11 @@ use crate::boxed_slice::BoxedSlice;
|
||||
use crate::iter::{Iter, IterMut};
|
||||
use crate::keys::Keys;
|
||||
use crate::EntityRef;
|
||||
use std::iter::FromIterator;
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::{Index, IndexMut};
|
||||
use std::slice;
|
||||
use core::iter::FromIterator;
|
||||
use core::marker::PhantomData;
|
||||
use core::ops::{Index, IndexMut};
|
||||
use core::slice;
|
||||
use std::boxed::Box;
|
||||
use std::vec::Vec;
|
||||
|
||||
/// A primary mapping `K -> V` allocating dense entity references.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use crate::keys::Keys;
|
||||
use crate::EntityRef;
|
||||
use std::marker::PhantomData;
|
||||
use core::marker::PhantomData;
|
||||
use std::vec::Vec;
|
||||
|
||||
/// A set of `K` for densely indexed entity references.
|
||||
@@ -80,7 +80,7 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::u32;
|
||||
use core::u32;
|
||||
|
||||
// `EntityRef` impl for testing.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
use crate::map::SecondaryMap;
|
||||
use crate::EntityRef;
|
||||
use std::mem;
|
||||
use std::slice;
|
||||
use std::u32;
|
||||
use core::mem;
|
||||
use core::slice;
|
||||
use core::u32;
|
||||
use std::vec::Vec;
|
||||
|
||||
/// Trait for extracting keys from values stored in a `SparseMap`.
|
||||
|
||||
@@ -608,7 +608,7 @@ impl<'a> FunctionBuilder<'a> {
|
||||
"`size` is not a power of two"
|
||||
);
|
||||
assert!(
|
||||
access_size >= u64::from(::std::cmp::min(src_align, dest_align)),
|
||||
access_size >= u64::from(::core::cmp::min(src_align, dest_align)),
|
||||
"`size` is smaller than `dest` and `src`'s alignment value."
|
||||
);
|
||||
|
||||
@@ -777,7 +777,7 @@ impl<'a> FunctionBuilder<'a> {
|
||||
"`size` is not a power of two"
|
||||
);
|
||||
assert!(
|
||||
access_size >= u64::from(::std::cmp::min(src_align, dest_align)),
|
||||
access_size >= u64::from(::core::cmp::min(src_align, dest_align)),
|
||||
"`size` is smaller than `dest` and `src`'s alignment value."
|
||||
);
|
||||
let load_and_store_amount = size / access_size;
|
||||
@@ -962,8 +962,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn memcpy() {
|
||||
use core::str::FromStr;
|
||||
use cranelift_codegen::{isa, settings};
|
||||
use std::str::FromStr;
|
||||
|
||||
let shared_builder = settings::builder();
|
||||
let shared_flags = settings::Flags::new(shared_builder);
|
||||
@@ -1023,8 +1023,8 @@ ebb0:
|
||||
|
||||
#[test]
|
||||
fn small_memcpy() {
|
||||
use core::str::FromStr;
|
||||
use cranelift_codegen::{isa, settings};
|
||||
use std::str::FromStr;
|
||||
|
||||
let shared_builder = settings::builder();
|
||||
let shared_flags = settings::Flags::new(shared_builder);
|
||||
|
||||
@@ -174,12 +174,20 @@
|
||||
clippy::use_self
|
||||
)
|
||||
)]
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![no_std]
|
||||
#![cfg_attr(not(feature = "std"), feature(alloc))]
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
#[macro_use]
|
||||
extern crate alloc;
|
||||
extern crate alloc as std;
|
||||
#[cfg(feature = "std")]
|
||||
#[macro_use]
|
||||
extern crate std;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use hashmap_core::HashMap;
|
||||
#[cfg(feature = "std")]
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub use crate::frontend::{FunctionBuilder, FunctionBuilderContext};
|
||||
pub use crate::switch::Switch;
|
||||
@@ -190,19 +198,5 @@ mod ssa;
|
||||
mod switch;
|
||||
mod variable;
|
||||
|
||||
/// This replaces `std` in builds with `core`.
|
||||
#[cfg(not(feature = "std"))]
|
||||
mod std {
|
||||
pub use alloc::{string, vec};
|
||||
pub use core::*;
|
||||
pub mod collections {
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate hashmap_core;
|
||||
|
||||
pub use self::hashmap_core::map as hash_map;
|
||||
pub use self::hashmap_core::{HashMap, HashSet};
|
||||
}
|
||||
}
|
||||
|
||||
/// Version number of this crate.
|
||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
//! Lecture Notes in Computer Science, vol 7791. Springer, Berlin, Heidelberg
|
||||
|
||||
use crate::Variable;
|
||||
use core::mem;
|
||||
use core::u32;
|
||||
use cranelift_codegen::cursor::{Cursor, FuncCursor};
|
||||
use cranelift_codegen::entity::{EntityRef, PrimaryMap, SecondaryMap};
|
||||
use cranelift_codegen::ir::immediates::{Ieee32, Ieee64};
|
||||
@@ -14,8 +16,6 @@ use cranelift_codegen::ir::types::{F32, F64};
|
||||
use cranelift_codegen::ir::{Ebb, Function, Inst, InstBuilder, InstructionData, Type, Value};
|
||||
use cranelift_codegen::packed_option::PackedOption;
|
||||
use cranelift_codegen::packed_option::ReservedValue;
|
||||
use std::mem;
|
||||
use std::u32;
|
||||
use std::vec::Vec;
|
||||
|
||||
/// Structure containing the data relevant the construction of SSA for a given function.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use super::HashMap;
|
||||
use crate::frontend::FunctionBuilder;
|
||||
use cranelift_codegen::ir::condcodes::IntCC;
|
||||
use cranelift_codegen::ir::*;
|
||||
use log::debug;
|
||||
use std::collections::HashMap;
|
||||
use std::vec::Vec;
|
||||
|
||||
type EntryIndex = u64;
|
||||
@@ -334,7 +334,7 @@ ebb10:
|
||||
|
||||
#[test]
|
||||
fn switch_min_index_value() {
|
||||
let func = setup!(0, [::std::i64::MIN as u64, 1,]);
|
||||
let func = setup!(0, [::core::i64::MIN as u64, 1,]);
|
||||
assert_eq!(
|
||||
func,
|
||||
"ebb0:
|
||||
@@ -350,7 +350,7 @@ ebb10:
|
||||
|
||||
#[test]
|
||||
fn switch_max_index_value() {
|
||||
let func = setup!(0, [::std::i64::MAX as u64, 1,]);
|
||||
let func = setup!(0, [::core::i64::MAX as u64, 1,]);
|
||||
assert_eq!(
|
||||
func,
|
||||
"ebb0:
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
//! their own index types to use them directly. Frontends which don't
|
||||
//! can use the `Variable` defined here.
|
||||
|
||||
use core::u32;
|
||||
use cranelift_codegen::entity::EntityRef;
|
||||
use std::u32;
|
||||
|
||||
///! An opaque reference to a variable.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
|
||||
@@ -14,7 +14,7 @@ edition = "2018"
|
||||
cranelift-codegen = { path = "../codegen", version = "0.26.0", default-features = false }
|
||||
cranelift-entity = { path = "../entity", version = "0.26.0", default-features = false }
|
||||
hashmap_core = { version = "0.1.9", optional = true }
|
||||
failure = "0.1.1"
|
||||
failure = { version = "0.1.1", default-features = false }
|
||||
log = { version = "0.4.6", default-features = false }
|
||||
|
||||
[features]
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user