Make regalloc2 #![no_std] (#119)
* Make regalloc2 `#![no_std]` This crate doesn't require any features from the standard library, so it can be made `no_std` to allow it to be used in environments that can't use the Rust standard library. This PR mainly performs the following mechanical changes: - `std::collections` is replaced with `alloc::collections`. - `std::*` is replaced with `core::*`. - `Vec`, `vec!`, `format!` and `ToString` are imported when needed since they are no longer in the prelude. - `HashSet` and `HashMap` are taken from the `hashbrown` crate, which is the same implementation that the standard library uses. - `FxHashSet` and `FxHashMap` are typedefs in `lib.rs` that are based on the `hashbrown` types. The only functional change is that `RegAllocError` no longer implements the `Error` trait since that is not available in `core`. Dependencies were adjusted to not require `std` and this is tested in CI by building against the `thumbv6m-none-eabi` target that doesn't have `std`. * Add the Error trait impl back under a "std" feature
This commit is contained in:
@@ -22,12 +22,11 @@ use crate::{
|
||||
CodeRange, BUNDLE_MAX_NORMAL_SPILL_WEIGHT, MAX_SPLITS_PER_SPILLSET,
|
||||
MINIMAL_BUNDLE_SPILL_WEIGHT, MINIMAL_FIXED_BUNDLE_SPILL_WEIGHT,
|
||||
},
|
||||
Allocation, Function, Inst, InstPosition, OperandConstraint, OperandKind, PReg, ProgPoint,
|
||||
RegAllocError,
|
||||
Allocation, Function, FxHashSet, Inst, InstPosition, OperandConstraint, OperandKind, PReg,
|
||||
ProgPoint, RegAllocError,
|
||||
};
|
||||
use fxhash::FxHashSet;
|
||||
use core::fmt::Debug;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use std::fmt::Debug;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum AllocRegResult {
|
||||
@@ -159,7 +158,7 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
trace!(" -> conflict bundle {:?}", conflict_bundle);
|
||||
if self.conflict_set.insert(conflict_bundle) {
|
||||
conflicts.push(conflict_bundle);
|
||||
max_conflict_weight = std::cmp::max(
|
||||
max_conflict_weight = core::cmp::max(
|
||||
max_conflict_weight,
|
||||
self.bundles[conflict_bundle.index()].cached_spill_weight(),
|
||||
);
|
||||
@@ -172,7 +171,7 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
}
|
||||
|
||||
if first_conflict.is_none() {
|
||||
first_conflict = Some(ProgPoint::from_index(std::cmp::max(
|
||||
first_conflict = Some(ProgPoint::from_index(core::cmp::max(
|
||||
preg_key.from,
|
||||
key.from,
|
||||
)));
|
||||
@@ -334,7 +333,7 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
self.bundles[bundle.index()].prio,
|
||||
final_weight
|
||||
);
|
||||
std::cmp::min(BUNDLE_MAX_NORMAL_SPILL_WEIGHT, final_weight)
|
||||
core::cmp::min(BUNDLE_MAX_NORMAL_SPILL_WEIGHT, final_weight)
|
||||
} else {
|
||||
0
|
||||
}
|
||||
@@ -824,7 +823,7 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
// (up to the Before of the next inst), *unless*
|
||||
// the original LR was only over the Before (up to
|
||||
// the After) of this inst.
|
||||
let to = std::cmp::min(ProgPoint::before(u.pos.inst().next()), lr_to);
|
||||
let to = core::cmp::min(ProgPoint::before(u.pos.inst().next()), lr_to);
|
||||
|
||||
// If the last bundle was at the same inst, add a new
|
||||
// LR to the same bundle; otherwise, create a LR and a
|
||||
@@ -863,7 +862,7 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
|
||||
// Otherwise, create a new LR.
|
||||
let pos = ProgPoint::before(u.pos.inst());
|
||||
let pos = std::cmp::max(lr_from, pos);
|
||||
let pos = core::cmp::max(lr_from, pos);
|
||||
let cr = CodeRange { from: pos, to };
|
||||
let lr = self.create_liverange(cr);
|
||||
new_lrs.push((vreg, lr));
|
||||
@@ -1036,7 +1035,7 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
self.get_or_create_spill_bundle(bundle, /* create_if_absent = */ false)
|
||||
{
|
||||
let mut list =
|
||||
std::mem::replace(&mut self.bundles[bundle.index()].ranges, smallvec![]);
|
||||
core::mem::replace(&mut self.bundles[bundle.index()].ranges, smallvec![]);
|
||||
for entry in &list {
|
||||
self.ranges[entry.index.index()].bundle = spill;
|
||||
}
|
||||
@@ -1107,7 +1106,7 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
lowest_cost_evict_conflict_cost,
|
||||
lowest_cost_split_conflict_cost,
|
||||
) {
|
||||
(Some(a), Some(b)) => Some(std::cmp::max(a, b)),
|
||||
(Some(a), Some(b)) => Some(core::cmp::max(a, b)),
|
||||
_ => None,
|
||||
};
|
||||
match self.try_to_allocate_bundle_to_reg(bundle, preg_idx, scan_limit_cost) {
|
||||
@@ -1291,7 +1290,7 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
);
|
||||
let bundle_start = self.bundles[bundle.index()].ranges[0].range.from;
|
||||
let mut split_at_point =
|
||||
std::cmp::max(lowest_cost_split_conflict_point, bundle_start);
|
||||
core::cmp::max(lowest_cost_split_conflict_point, bundle_start);
|
||||
let requeue_with_reg = lowest_cost_split_conflict_reg;
|
||||
|
||||
// Adjust `split_at_point` if it is within a deeper loop
|
||||
|
||||
Reference in New Issue
Block a user