-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is the initial implementation of the fast register allocator in `src/fastalloc`.
- Loading branch information
Showing
10 changed files
with
2,309 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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(_))) | ||
} | ||
} | ||
|
||
impl<'a> core::ops::Index<usize> for Operands<'a> { | ||
type Output = Operand; | ||
|
||
fn index(&self, index: usize) -> &Self::Output { | ||
&self.0[index] | ||
} | ||
} |
Oops, something went wrong.