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 target
corpus corpus
artifacts artifacts

View File

@@ -1,4 +1,3 @@
[package] [package]
name = "regalloc2-fuzz" name = "regalloc2-fuzz"
version = "0.0.0" 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] #![no_main]
use libfuzzer_sys::arbitrary::{Arbitrary, Result, Unstructured}; use libfuzzer_sys::arbitrary::{Arbitrary, Result, Unstructured};
use libfuzzer_sys::fuzz_target; 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] #![no_main]
use libfuzzer_sys::fuzz_target; 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] #![no_main]
use libfuzzer_sys::fuzz_target; use libfuzzer_sys::fuzz_target;
use libfuzzer_sys::arbitrary::{Arbitrary, Unstructured, Result}; 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] #![no_main]
use libfuzzer_sys::arbitrary::{Arbitrary, Result, Unstructured}; use libfuzzer_sys::arbitrary::{Arbitrary, Result, Unstructured};
use libfuzzer_sys::fuzz_target; 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] #![no_main]
use libfuzzer_sys::arbitrary::{Arbitrary, Result, Unstructured}; use libfuzzer_sys::arbitrary::{Arbitrary, Result, Unstructured};
use libfuzzer_sys::fuzz_target; use libfuzzer_sys::fuzz_target;
@@ -23,6 +28,8 @@ impl Arbitrary for TestCase {
control_flow: true, control_flow: true,
reducible: false, reducible: false,
always_local_uses: 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 arbitrary::{Arbitrary, Unstructured};
use rand::{Rng, SeedableRng}; use rand::{Rng, SeedableRng};
use rand_chacha::ChaCha8Rng; 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. //! Bit vectors.
use smallvec::{smallvec, SmallVec}; 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. //! Lightweight CFG analyses.
use crate::{domtree, postorder, Block, Function, Inst, OperandKind, ProgPoint}; 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::{ use crate::{
domtree, postorder, Allocation, Block, Function, Inst, InstRange, MachineEnv, Operand, domtree, postorder, Allocation, Block, Function, Inst, InstRange, MachineEnv, Operand,
OperandKind, OperandPolicy, OperandPos, PReg, RegClass, VReg, 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. //! Utilities for fuzzing.
pub mod func; pub mod func;

View File

@@ -355,6 +355,7 @@ impl Operand {
#[inline(always)] #[inline(always)]
pub fn from_bits(bits: u32) -> Self { pub fn from_bits(bits: u32) -> Self {
debug_assert!(bits >> 29 <= 4);
Operand { bits } Operand { bits }
} }
} }
@@ -429,9 +430,9 @@ pub struct Allocation {
/// `policy` field in `Operand`, and we are careful to use /// `policy` field in `Operand`, and we are careful to use
/// disjoint ranges of values in this field for each type. We also /// disjoint ranges of values in this field for each type. We also
/// leave the def-or-use bit (`kind` for `Operand`) unused here so /// leave the def-or-use bit (`kind` for `Operand`) unused here so
/// that the client may use it to mark `Allocation`s on /// that we can use it below in `OperandOrAllocation` to record
/// instructions as read or write when it edits instructions /// whether `Allocation`s are defs or uses (which is often useful
/// (which is sometimes useful for post-allocation analyses). /// to know).
/// ///
/// kind:3 unused:1 index:28 /// kind:3 unused:1 index:28
bits: u32, bits: u32,
@@ -532,6 +533,7 @@ impl Allocation {
#[inline(always)] #[inline(always)]
pub fn from_bits(bits: u32) -> Self { pub fn from_bits(bits: u32) -> Self {
debug_assert!(bits >> 29 >= 5);
Self { bits } Self { bits }
} }
} }
@@ -566,11 +568,13 @@ pub struct OperandOrAllocation {
impl OperandOrAllocation { impl OperandOrAllocation {
pub fn from_operand(operand: Operand) -> Self { pub fn from_operand(operand: Operand) -> Self {
debug_assert!(operand.bits() >> 29 <= 4);
Self { Self {
bits: operand.bits(), bits: operand.bits(),
} }
} }
pub fn from_alloc(alloc: Allocation) -> Self { pub fn from_alloc(alloc: Allocation) -> Self {
debug_assert!(alloc.bits() >> 29 >= 5);
Self { bits: alloc.bits() } Self { bits: alloc.bits() }
} }
pub fn is_operand(&self) -> bool { pub fn is_operand(&self) -> bool {
@@ -588,6 +592,10 @@ impl OperandOrAllocation {
} }
pub fn as_allocation(&self) -> Option<Allocation> { pub fn as_allocation(&self) -> Option<Allocation> {
if self.is_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))) Some(Allocation::from_bits(self.bits & !(1 << 28)))
} else { } else {
None None
@@ -612,6 +620,9 @@ impl OperandOrAllocation {
/// A trait defined by the regalloc client to provide access to its /// A trait defined by the regalloc client to provide access to its
/// machine-instruction / CFG representation. /// 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 { pub trait Function {
// ------------- // -------------
// CFG traversal // CFG traversal
@@ -669,10 +680,7 @@ pub trait Function {
/// Get the clobbers for an instruction. /// Get the clobbers for an instruction.
fn inst_clobbers(&self, insn: Inst) -> &[PReg]; fn inst_clobbers(&self, insn: Inst) -> &[PReg];
/// Get the precise number of `VReg` in use in this function, to allow /// Get the number of `VReg` in use in this function.
/// 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.
fn num_vregs(&self) -> usize; fn num_vregs(&self) -> usize;
/// Get the VRegs that are pointer/reference types. This has the /// 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 /// 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 /// store-slot size and smaller-operand store/load instructions for an F64
/// than for a true V128. /// 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; fn spillslot_size(&self, regclass: RegClass, for_vreg: VReg) -> usize;
/// When providing a spillslot number for a multi-slot spillslot, /// 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 crate::Allocation;
use smallvec::{smallvec, SmallVec}; 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). //! Fast postorder computation with no allocations (aside from result).
use crate::Block; 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. //! SSA-related utilities.
use crate::cfg::CFGInfo; use crate::cfg::CFGInfo;