Skip to content

Commit

Permalink
Changes from review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
cfallin committed Apr 18, 2021
1 parent a08b012 commit 940c1b7
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 9 deletions.
1 change: 0 additions & 1 deletion fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

target
corpus
artifacts
1 change: 0 additions & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

[package]
name = "regalloc2-fuzz"
version = "0.0.0"
Expand Down
5 changes: 5 additions & 0 deletions fuzz/fuzz_targets/domtree.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
5 changes: 5 additions & 0 deletions fuzz/fuzz_targets/ion.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
5 changes: 5 additions & 0 deletions fuzz/fuzz_targets/ion_checker.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
5 changes: 5 additions & 0 deletions fuzz/fuzz_targets/moves.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
7 changes: 7 additions & 0 deletions fuzz/fuzz_targets/ssagen.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -23,6 +28,8 @@ impl Arbitrary for TestCase {
control_flow: true,
reducible: false,
always_local_uses: false,
block_params: true,
reftypes: true,
},
)?,
})
Expand Down
5 changes: 5 additions & 0 deletions src/bin/test.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/bitvec.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
5 changes: 5 additions & 0 deletions src/cfg.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
5 changes: 5 additions & 0 deletions src/fuzzing/func.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/fuzzing/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
25 changes: 18 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ impl Operand {

#[inline(always)]
pub fn from_bits(bits: u32) -> Self {
debug_assert!(bits >> 29 <= 4);
Operand { bits }
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -532,6 +533,7 @@ impl Allocation {

#[inline(always)]
pub fn from_bits(bits: u32) -> Self {
debug_assert!(bits >> 29 >= 5);
Self { bits }
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/moves.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
5 changes: 5 additions & 0 deletions src/postorder.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/ssa.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 940c1b7

Please sign in to comment.