Changes from review comments.

This commit is contained in:
Chris Fallin
2021-04-18 13:02:05 -07:00
parent a08b0121a0
commit 940c1b719d
16 changed files with 85 additions and 9 deletions

1
fuzz/.gitignore vendored
View File

@@ -1,4 +1,3 @@
target
corpus
artifacts

View File

@@ -1,4 +1,3 @@
[package]
name = "regalloc2-fuzz"
version = "0.0.0"

View File

@@ -1,3 +1,8 @@
/*
* Released under the terms of the Apache 2.0 license with LLVM
* exception. See `LICENSE` for details.
*/
#![no_main]
use libfuzzer_sys::arbitrary::{Arbitrary, Result, Unstructured};
use libfuzzer_sys::fuzz_target;

View File

@@ -1,3 +1,8 @@
/*
* Released under the terms of the Apache 2.0 license with LLVM
* exception. See `LICENSE` for details.
*/
#![no_main]
use libfuzzer_sys::fuzz_target;

View File

@@ -1,3 +1,8 @@
/*
* Released under the terms of the Apache 2.0 license with LLVM
* exception. See `LICENSE` for details.
*/
#![no_main]
use libfuzzer_sys::fuzz_target;
use libfuzzer_sys::arbitrary::{Arbitrary, Unstructured, Result};

View File

@@ -1,3 +1,8 @@
/*
* Released under the terms of the Apache 2.0 license with LLVM
* exception. See `LICENSE` for details.
*/
#![no_main]
use libfuzzer_sys::arbitrary::{Arbitrary, Result, Unstructured};
use libfuzzer_sys::fuzz_target;

View File

@@ -1,3 +1,8 @@
/*
* Released under the terms of the Apache 2.0 license with LLVM
* exception. See `LICENSE` for details.
*/
#![no_main]
use libfuzzer_sys::arbitrary::{Arbitrary, Result, Unstructured};
use libfuzzer_sys::fuzz_target;
@@ -23,6 +28,8 @@ impl Arbitrary for TestCase {
control_flow: true,
reducible: false,
always_local_uses: false,
block_params: true,
reftypes: true,
},
)?,
})

View File

@@ -1,3 +1,8 @@
/*
* Released under the terms of the Apache 2.0 license with LLVM
* exception. See `LICENSE` for details.
*/
use arbitrary::{Arbitrary, Unstructured};
use rand::{Rng, SeedableRng};
use rand_chacha::ChaCha8Rng;

View File

@@ -1,3 +1,8 @@
/*
* Released under the terms of the Apache 2.0 license with LLVM
* exception. See `LICENSE` for details.
*/
//! Bit vectors.
use smallvec::{smallvec, SmallVec};

View File

@@ -1,3 +1,8 @@
/*
* Released under the terms of the Apache 2.0 license with LLVM
* exception. See `LICENSE` for details.
*/
//! Lightweight CFG analyses.
use crate::{domtree, postorder, Block, Function, Inst, OperandKind, ProgPoint};

View File

@@ -1,3 +1,8 @@
/*
* Released under the terms of the Apache 2.0 license with LLVM
* exception. See `LICENSE` for details.
*/
use crate::{
domtree, postorder, Allocation, Block, Function, Inst, InstRange, MachineEnv, Operand,
OperandKind, OperandPolicy, OperandPos, PReg, RegClass, VReg,

View File

@@ -1,3 +1,8 @@
/*
* Released under the terms of the Apache 2.0 license with LLVM
* exception. See `LICENSE` for details.
*/
//! Utilities for fuzzing.
pub mod func;

View File

@@ -355,6 +355,7 @@ impl Operand {
#[inline(always)]
pub fn from_bits(bits: u32) -> Self {
debug_assert!(bits >> 29 <= 4);
Operand { bits }
}
}
@@ -429,9 +430,9 @@ pub struct Allocation {
/// `policy` field in `Operand`, and we are careful to use
/// disjoint ranges of values in this field for each type. We also
/// leave the def-or-use bit (`kind` for `Operand`) unused here so
/// that the client may use it to mark `Allocation`s on
/// instructions as read or write when it edits instructions
/// (which is sometimes useful for post-allocation analyses).
/// that we can use it below in `OperandOrAllocation` to record
/// whether `Allocation`s are defs or uses (which is often useful
/// to know).
///
/// kind:3 unused:1 index:28
bits: u32,
@@ -532,6 +533,7 @@ impl Allocation {
#[inline(always)]
pub fn from_bits(bits: u32) -> Self {
debug_assert!(bits >> 29 >= 5);
Self { bits }
}
}
@@ -566,11 +568,13 @@ pub struct OperandOrAllocation {
impl OperandOrAllocation {
pub fn from_operand(operand: Operand) -> Self {
debug_assert!(operand.bits() >> 29 <= 4);
Self {
bits: operand.bits(),
}
}
pub fn from_alloc(alloc: Allocation) -> Self {
debug_assert!(alloc.bits() >> 29 >= 5);
Self { bits: alloc.bits() }
}
pub fn is_operand(&self) -> bool {
@@ -588,6 +592,10 @@ impl OperandOrAllocation {
}
pub fn as_allocation(&self) -> Option<Allocation> {
if self.is_allocation() {
// Remove the def/use bit -- the canonical `Allocation`
// does not have this, and we want allocs to continue to
// be comparable whether they are used for reads or
// writes.
Some(Allocation::from_bits(self.bits & !(1 << 28)))
} else {
None
@@ -612,6 +620,9 @@ impl OperandOrAllocation {
/// A trait defined by the regalloc client to provide access to its
/// machine-instruction / CFG representation.
///
/// (This trait's design is inspired by, and derives heavily from, the
/// trait of the same name in regalloc.rs.)
pub trait Function {
// -------------
// CFG traversal
@@ -669,10 +680,7 @@ pub trait Function {
/// Get the clobbers for an instruction.
fn inst_clobbers(&self, insn: Inst) -> &[PReg];
/// Get the precise number of `VReg` in use in this function, to allow
/// preallocating data structures. This number *must* be a correct
/// lower-bound, otherwise invalid index failures may happen; it is of
/// course better if it is exact.
/// Get the number of `VReg` in use in this function.
fn num_vregs(&self) -> usize;
/// Get the VRegs that are pointer/reference types. This has the
@@ -724,6 +732,9 @@ pub trait Function {
/// but we also use them for F32 and F64 values, we may use a different
/// store-slot size and smaller-operand store/load instructions for an F64
/// than for a true V128.
///
/// (This trait method's design and doc text derives from
/// regalloc.rs' trait of the same name.)
fn spillslot_size(&self, regclass: RegClass, for_vreg: VReg) -> usize;
/// When providing a spillslot number for a multi-slot spillslot,

View File

@@ -1,3 +1,8 @@
/*
* Released under the terms of the Apache 2.0 license with LLVM
* exception. See `LICENSE` for details.
*/
use crate::Allocation;
use smallvec::{smallvec, SmallVec};

View File

@@ -1,3 +1,8 @@
/*
* Released under the terms of the Apache 2.0 license with LLVM
* exception. See `LICENSE` for details.
*/
//! Fast postorder computation with no allocations (aside from result).
use crate::Block;

View File

@@ -1,3 +1,8 @@
/*
* Released under the terms of the Apache 2.0 license with LLVM
* exception. See `LICENSE` for details.
*/
//! SSA-related utilities.
use crate::cfg::CFGInfo;