Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fastalloc1 #181

Merged
merged 103 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 79 commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
9e35679
added implementation of SSRA for a single basic block
d-sonuga Mar 19, 2024
46e38c3
extended implementation to account for multiple basic blocks
d-sonuga Mar 19, 2024
ac293b8
updated readme
d-sonuga Mar 19, 2024
1456d2b
some progress
d-sonuga May 19, 2024
fe31f41
basic algorithm correct
d-sonuga May 29, 2024
1ce6169
can now handle reused inputs
d-sonuga Jul 18, 2024
ed6c3f2
can now handle fixed registers
d-sonuga Jul 22, 2024
fc7bfed
can now handle fixed non-allocatable constraints
d-sonuga Jul 22, 2024
90d3c4f
can now handle clobbers
d-sonuga Jul 23, 2024
7bf8e09
can now handle safepoint instructions
d-sonuga Jul 25, 2024
b93cb6a
remove stack only alloc panic
d-sonuga Jul 26, 2024
516e026
Merge branch 'bytecodealliance:main' into fastalloc1
d-sonuga Jul 29, 2024
2fbb251
fixed bug with the LRU's PReg handling
d-sonuga Aug 1, 2024
d1a868e
fix: registers can now be evicted to use as scratch registers
d-sonuga Aug 2, 2024
8e88c40
fixed bugs
d-sonuga Aug 4, 2024
06b7bfc
fixed bug with lru management
d-sonuga Aug 4, 2024
28278dd
fixed problems with LRU management
d-sonuga Aug 4, 2024
a909242
fixed register leak of clobbered regs
d-sonuga Aug 4, 2024
747d975
rethought reuse operand handling
d-sonuga Aug 5, 2024
792bd18
condition to remove clobber from free list changed
d-sonuga Aug 5, 2024
5f3b355
fixed bug with adding clobbers back to the free list
d-sonuga Aug 5, 2024
7f26dc6
fixed bug with adding clobbers back to the free list
d-sonuga Aug 5, 2024
98d3861
Merge branch 'fastalloc1' of https://github.com/d-sonuga/regalloc2 in…
d-sonuga Aug 5, 2024
677baed
Merge branch 'bytecodealliance:main' into main
d-sonuga Aug 5, 2024
90fb2f4
Merge branch 'main' into fastalloc1
d-sonuga Aug 5, 2024
958864c
change condition to remove clobber from free list
d-sonuga Aug 6, 2024
70d6fde
added cfgs to logging and validation function calls
d-sonuga Aug 7, 2024
c3cf1e4
remove support for safepoints
d-sonuga Aug 7, 2024
0824a18
added FromIterator implementation to PRegSet
d-sonuga Aug 7, 2024
0fa2735
now using PRegSet for sets of physical registers
d-sonuga Aug 7, 2024
2ea4e2d
now using u8s in the LRU. moved unnecessary cfg calculations
d-sonuga Aug 7, 2024
2dd493f
refactor operand iterators
d-sonuga Aug 7, 2024
7099412
changed interface to specify which algorithm to run
d-sonuga Aug 7, 2024
7b13bf8
changed guess of number of operands
d-sonuga Aug 7, 2024
1fdaef4
using PRegSet union to free registers
d-sonuga Aug 7, 2024
04c53dc
remove std imports; better checks for trace logging
d-sonuga Aug 7, 2024
cd351d8
implement display for PRegSet
d-sonuga Aug 8, 2024
f7ce37d
implemented display for PartedByRegClass; rethought reuse operands (a…
d-sonuga Aug 8, 2024
093ba10
better error handling
d-sonuga Aug 8, 2024
6ce9d56
fixed regression with LRU management
d-sonuga Aug 8, 2024
8680569
removed unnecessary tracking of liveout vregs
d-sonuga Aug 8, 2024
956a041
WIP
d-sonuga Aug 8, 2024
da20287
using matches instead of OperandConstraintKind in operand iterators
d-sonuga Aug 8, 2024
b2916bf
updated outdated comments; changed debug_assertion checks in LRU; rem…
d-sonuga Aug 8, 2024
73396f0
removed unnecessary loop and function call in process_branch
d-sonuga Aug 8, 2024
51b4b32
rework reload_at_begin
d-sonuga Aug 8, 2024
376b45c
simplified handling of reuse operands
d-sonuga Aug 9, 2024
455ea84
Merge branch 'fastalloc1' into fastalloc-vregset-as-bitset
d-sonuga Aug 9, 2024
832eeb4
now using vreg sets as bitsets
d-sonuga Aug 10, 2024
af5ec31
vreg sets are now initialized with num of vregs capacity
d-sonuga Aug 10, 2024
abc10bd
now using bitsets to represent vreg sets
d-sonuga Aug 10, 2024
2982c6d
removed live_vregs clone in reload_at_begin
d-sonuga Aug 10, 2024
3096725
now using custom vregset for live_vregs
d-sonuga Aug 11, 2024
4afc7f6
removed check for livein vregs in entry block
d-sonuga Aug 11, 2024
47eed23
num spillslots is now included in the output
d-sonuga Aug 12, 2024
5813060
fixed clobber handling bug
d-sonuga Aug 12, 2024
feb1067
now checks for and panics on safepoint instructions, removed std dep
d-sonuga Aug 13, 2024
2ad7f3d
changed safepoint check
d-sonuga Aug 13, 2024
c2f9fab
fixed out-of-order edits problem that arose when using a vreg as a br…
d-sonuga Aug 13, 2024
014ee3d
formatting
d-sonuga Aug 15, 2024
647fe5c
removed unnecessary field
d-sonuga Aug 15, 2024
08cce9c
live vregs now represented by an indexset
d-sonuga Aug 17, 2024
c93a4a1
now representing live vregs with a linked list
d-sonuga Aug 17, 2024
4a3973c
now preallocating edits queues
d-sonuga Aug 17, 2024
0e9b929
added intersect_from, invert and is_empty functions to PRegSet
d-sonuga Aug 22, 2024
5aa10eb
algorithm simplifications
d-sonuga Aug 22, 2024
52afa1b
fixed bug in process_branch state updates
d-sonuga Aug 23, 2024
5dcafe4
simplified handling edits
d-sonuga Aug 25, 2024
f697273
removed unnecessary fields
d-sonuga Aug 25, 2024
2e55a76
fixed available regsets handling bug
d-sonuga Aug 26, 2024
c93476e
simplified edit handling: edits are added directly to the edits vecto…
d-sonuga Aug 29, 2024
6952cd7
fixed bug with state update in process_branch
d-sonuga Aug 29, 2024
8cce4d5
now tracks debug info
d-sonuga Sep 2, 2024
a50361c
added verbose log
d-sonuga Sep 2, 2024
ac75d21
removed unnecessary comments and code, renamed tests to better names
d-sonuga Sep 2, 2024
1d59643
formatting
d-sonuga Sep 2, 2024
eff84bd
Merge branch 'bytecodealliance:main' into main
d-sonuga Sep 2, 2024
3a44226
Merge branch 'main-main' into fastalloc1
d-sonuga Sep 2, 2024
b94b4ea
removed stack constraint support and reftype vreg checks
d-sonuga Sep 2, 2024
6700627
removed unnecessary clobber check in allocd_within_constraint
d-sonuga Sep 5, 2024
baae3ca
simplified vregset
d-sonuga Sep 5, 2024
004c19e
simplify lru
d-sonuga Sep 5, 2024
a64ee57
improved allocs initialization
d-sonuga Sep 5, 2024
bb1855c
added bitand and bitor impls for PRegSet
d-sonuga Sep 5, 2024
8bd9a46
corrected available set issue with reg allocation from operands
d-sonuga Sep 5, 2024
f464dd5
removed unnecessary loop
d-sonuga Sep 5, 2024
05b7dd1
removed unnecessary check in process_operand_allocation
d-sonuga Sep 5, 2024
e5592d8
fixed problem with scratch register evictions
d-sonuga Sep 5, 2024
21ec7f8
removed unnecessary operand iter function
d-sonuga Sep 5, 2024
0fd7b52
removed unnecessary operand num guess in allocs initialization; refac…
d-sonuga Sep 5, 2024
b6094fe
updated outdated vregset comment
d-sonuga Sep 5, 2024
8df9209
process_branch now uses parallel move resolver
d-sonuga Sep 5, 2024
7af8283
formatting
d-sonuga Sep 5, 2024
f2f2daa
added loop in alloc_inst to correct scratch reg alloc issue
d-sonuga Sep 6, 2024
5c7c307
fixed issue with scratch register handling in reload_at_begin
d-sonuga Sep 6, 2024
b26d928
formatting
d-sonuga Sep 6, 2024
e365469
fixed issue with scratch reg function for parallel moves in process_b…
d-sonuga Sep 6, 2024
4d6be14
removed unnecessary imports in test
d-sonuga Sep 14, 2024
784fc66
vregset insert now asserts vreg absence
d-sonuga Sep 14, 2024
e4b9fc0
removed duplicated functions
d-sonuga Sep 14, 2024
da22294
changed the edits length guess for initializing the edits vector
d-sonuga Sep 14, 2024
cd5a7c2
removed unnecessary loop in alloc_inst
d-sonuga Sep 21, 2024
afb1802
removed unnecessary iter function and lru constant
d-sonuga Sep 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ path = "fuzz_targets/ion_checker.rs"
test = false
doc = false

[[bin]]
name = "fastalloc_checker"
path = "fuzz_targets/fastalloc_checker.rs"
test = false
doc = false

# Enable debug assertions and overflow checks when fuzzing
[profile.release]
debug = true
Expand Down
45 changes: 45 additions & 0 deletions fuzz/fuzz_targets/fastalloc_checker.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Released under the terms of the Apache 2.0 license with LLVM
* exception. See `LICENSE` for details.
*/

#![no_main]
use regalloc2::fuzzing::arbitrary::{Arbitrary, Result, Unstructured};
use regalloc2::fuzzing::checker::Checker;
use regalloc2::fuzzing::func::{Func, Options};
use regalloc2::fuzzing::fuzz_target;

#[derive(Clone, Debug)]
struct TestCase {
func: Func,
}

impl Arbitrary<'_> for TestCase {
fn arbitrary(u: &mut Unstructured) -> Result<TestCase> {
Ok(TestCase {
func: Func::arbitrary_with_options(
u,
&Options {
reused_inputs: true,
fixed_regs: true,
fixed_nonallocatable: true,
clobbers: true,
reftypes: false,
},
)?,
})
}
}

fuzz_target!(|testcase: TestCase| {
let func = testcase.func;
let _ = env_logger::try_init();
log::trace!("func:\n{:?}", func);
let env = regalloc2::fuzzing::func::machine_env();
let out =
regalloc2::fuzzing::fastalloc::run(&func, &env, true, false).expect("regalloc did not succeed");

let mut checker = Checker::new(&func, &env);
checker.prepare(&out);
checker.run().expect("checker failed");
});
23 changes: 21 additions & 2 deletions regalloc2-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::path::PathBuf;

use clap::Parser;
use regalloc2::{
checker::Checker, serialize::SerializableFunction, Block, Edit, Function, InstOrEdit, Output,
RegallocOptions,
checker::Checker, serialize::SerializableFunction, Algorithm, Block, Edit, Function,
InstOrEdit, Output, RegallocOptions,
};

#[derive(Parser)]
Expand All @@ -15,6 +15,24 @@ struct Args {

/// Input file containing a bincode-encoded SerializedFunction.
input: PathBuf,

/// Which register allocation algorithm to use.
algorithm: CliAlgorithm,
}

#[derive(Clone, Copy, Debug, clap::ValueEnum)]
enum CliAlgorithm {
Ion,
Fastalloc,
}

impl From<CliAlgorithm> for Algorithm {
fn from(cli_algo: CliAlgorithm) -> Algorithm {
match cli_algo {
CliAlgorithm::Ion => Algorithm::Ion,
CliAlgorithm::Fastalloc => Algorithm::Fastalloc,
}
}
}

fn main() {
Expand All @@ -32,6 +50,7 @@ fn main() {
let options = RegallocOptions {
verbose_log: true,
validate_ssa: true,
algorithm: args.algorithm.into(),
};
let output = match regalloc2::run(&function, function.machine_env(), &options) {
Ok(output) => output,
Expand Down
51 changes: 51 additions & 0 deletions src/fastalloc/iter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use crate::{Operand, OperandConstraint, OperandKind};

pub struct Operands<'a>(pub &'a [Operand]);

impl<'a> Operands<'a> {
pub fn new(operands: &'a [Operand]) -> Self {
Self(operands)
}

pub fn matches<F: Fn(Operand) -> bool + 'a>(
&self,
predicate: F,
) -> impl Iterator<Item = (usize, Operand)> + 'a {
self.0
.iter()
.cloned()
.enumerate()
.filter(move |(_, op)| predicate(*op))
}

pub fn def_ops(&self) -> impl Iterator<Item = (usize, Operand)> + 'a {
self.matches(|op| op.kind() == OperandKind::Def)
}

pub fn use_ops(&self) -> impl Iterator<Item = (usize, Operand)> + 'a {
self.matches(|op| op.kind() == OperandKind::Use)
}

pub fn reuse(&self) -> impl Iterator<Item = (usize, Operand)> + 'a {
self.matches(|op| matches!(op.constraint(), OperandConstraint::Reuse(_)))
}

pub fn fixed(&self) -> impl Iterator<Item = (usize, Operand)> + 'a {
self.matches(|op| matches!(op.constraint(), OperandConstraint::FixedReg(_)))
}

pub fn non_fixed_use(&self) -> impl Iterator<Item = (usize, Operand)> + 'a {
self.matches(|op| {
!matches!(op.constraint(), OperandConstraint::FixedReg(_))
&& op.kind() == OperandKind::Use
})
}
}

impl<'a> core::ops::Index<usize> for Operands<'a> {
type Output = Operand;

fn index(&self, index: usize) -> &Self::Output {
&self.0[index]
}
}
Loading
Loading