Skip to content

Commit 940c1b7

Browse files
committed
Changes from review comments.
1 parent a08b012 commit 940c1b7

16 files changed

+85
-9
lines changed

fuzz/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
target
32
corpus
43
artifacts

fuzz/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
[package]
32
name = "regalloc2-fuzz"
43
version = "0.0.0"

fuzz/fuzz_targets/domtree.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Released under the terms of the Apache 2.0 license with LLVM
3+
* exception. See `LICENSE` for details.
4+
*/
5+
16
#![no_main]
27
use libfuzzer_sys::arbitrary::{Arbitrary, Result, Unstructured};
38
use libfuzzer_sys::fuzz_target;

fuzz/fuzz_targets/ion.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Released under the terms of the Apache 2.0 license with LLVM
3+
* exception. See `LICENSE` for details.
4+
*/
5+
16
#![no_main]
27
use libfuzzer_sys::fuzz_target;
38

fuzz/fuzz_targets/ion_checker.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Released under the terms of the Apache 2.0 license with LLVM
3+
* exception. See `LICENSE` for details.
4+
*/
5+
16
#![no_main]
27
use libfuzzer_sys::fuzz_target;
38
use libfuzzer_sys::arbitrary::{Arbitrary, Unstructured, Result};

fuzz/fuzz_targets/moves.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Released under the terms of the Apache 2.0 license with LLVM
3+
* exception. See `LICENSE` for details.
4+
*/
5+
16
#![no_main]
27
use libfuzzer_sys::arbitrary::{Arbitrary, Result, Unstructured};
38
use libfuzzer_sys::fuzz_target;

fuzz/fuzz_targets/ssagen.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Released under the terms of the Apache 2.0 license with LLVM
3+
* exception. See `LICENSE` for details.
4+
*/
5+
16
#![no_main]
27
use libfuzzer_sys::arbitrary::{Arbitrary, Result, Unstructured};
38
use libfuzzer_sys::fuzz_target;
@@ -23,6 +28,8 @@ impl Arbitrary for TestCase {
2328
control_flow: true,
2429
reducible: false,
2530
always_local_uses: false,
31+
block_params: true,
32+
reftypes: true,
2633
},
2734
)?,
2835
})

src/bin/test.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Released under the terms of the Apache 2.0 license with LLVM
3+
* exception. See `LICENSE` for details.
4+
*/
5+
16
use arbitrary::{Arbitrary, Unstructured};
27
use rand::{Rng, SeedableRng};
38
use rand_chacha::ChaCha8Rng;

src/bitvec.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Released under the terms of the Apache 2.0 license with LLVM
3+
* exception. See `LICENSE` for details.
4+
*/
5+
16
//! Bit vectors.
27
38
use smallvec::{smallvec, SmallVec};

src/cfg.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Released under the terms of the Apache 2.0 license with LLVM
3+
* exception. See `LICENSE` for details.
4+
*/
5+
16
//! Lightweight CFG analyses.
27
38
use crate::{domtree, postorder, Block, Function, Inst, OperandKind, ProgPoint};

src/fuzzing/func.rs

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

src/fuzzing/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Released under the terms of the Apache 2.0 license with LLVM
3+
* exception. See `LICENSE` for details.
4+
*/
5+
16
//! Utilities for fuzzing.
27
38
pub mod func;

src/lib.rs

+18-7
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ impl Operand {
355355

356356
#[inline(always)]
357357
pub fn from_bits(bits: u32) -> Self {
358+
debug_assert!(bits >> 29 <= 4);
358359
Operand { bits }
359360
}
360361
}
@@ -429,9 +430,9 @@ pub struct Allocation {
429430
/// `policy` field in `Operand`, and we are careful to use
430431
/// disjoint ranges of values in this field for each type. We also
431432
/// leave the def-or-use bit (`kind` for `Operand`) unused here so
432-
/// that the client may use it to mark `Allocation`s on
433-
/// instructions as read or write when it edits instructions
434-
/// (which is sometimes useful for post-allocation analyses).
433+
/// that we can use it below in `OperandOrAllocation` to record
434+
/// whether `Allocation`s are defs or uses (which is often useful
435+
/// to know).
435436
///
436437
/// kind:3 unused:1 index:28
437438
bits: u32,
@@ -532,6 +533,7 @@ impl Allocation {
532533

533534
#[inline(always)]
534535
pub fn from_bits(bits: u32) -> Self {
536+
debug_assert!(bits >> 29 >= 5);
535537
Self { bits }
536538
}
537539
}
@@ -566,11 +568,13 @@ pub struct OperandOrAllocation {
566568

567569
impl OperandOrAllocation {
568570
pub fn from_operand(operand: Operand) -> Self {
571+
debug_assert!(operand.bits() >> 29 <= 4);
569572
Self {
570573
bits: operand.bits(),
571574
}
572575
}
573576
pub fn from_alloc(alloc: Allocation) -> Self {
577+
debug_assert!(alloc.bits() >> 29 >= 5);
574578
Self { bits: alloc.bits() }
575579
}
576580
pub fn is_operand(&self) -> bool {
@@ -588,6 +592,10 @@ impl OperandOrAllocation {
588592
}
589593
pub fn as_allocation(&self) -> Option<Allocation> {
590594
if self.is_allocation() {
595+
// Remove the def/use bit -- the canonical `Allocation`
596+
// does not have this, and we want allocs to continue to
597+
// be comparable whether they are used for reads or
598+
// writes.
591599
Some(Allocation::from_bits(self.bits & !(1 << 28)))
592600
} else {
593601
None
@@ -612,6 +620,9 @@ impl OperandOrAllocation {
612620

613621
/// A trait defined by the regalloc client to provide access to its
614622
/// machine-instruction / CFG representation.
623+
///
624+
/// (This trait's design is inspired by, and derives heavily from, the
625+
/// trait of the same name in regalloc.rs.)
615626
pub trait Function {
616627
// -------------
617628
// CFG traversal
@@ -669,10 +680,7 @@ pub trait Function {
669680
/// Get the clobbers for an instruction.
670681
fn inst_clobbers(&self, insn: Inst) -> &[PReg];
671682

672-
/// Get the precise number of `VReg` in use in this function, to allow
673-
/// preallocating data structures. This number *must* be a correct
674-
/// lower-bound, otherwise invalid index failures may happen; it is of
675-
/// course better if it is exact.
683+
/// Get the number of `VReg` in use in this function.
676684
fn num_vregs(&self) -> usize;
677685

678686
/// Get the VRegs that are pointer/reference types. This has the
@@ -724,6 +732,9 @@ pub trait Function {
724732
/// but we also use them for F32 and F64 values, we may use a different
725733
/// store-slot size and smaller-operand store/load instructions for an F64
726734
/// than for a true V128.
735+
///
736+
/// (This trait method's design and doc text derives from
737+
/// regalloc.rs' trait of the same name.)
727738
fn spillslot_size(&self, regclass: RegClass, for_vreg: VReg) -> usize;
728739

729740
/// When providing a spillslot number for a multi-slot spillslot,

src/moves.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Released under the terms of the Apache 2.0 license with LLVM
3+
* exception. See `LICENSE` for details.
4+
*/
5+
16
use crate::Allocation;
27
use smallvec::{smallvec, SmallVec};
38

src/postorder.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Released under the terms of the Apache 2.0 license with LLVM
3+
* exception. See `LICENSE` for details.
4+
*/
5+
16
//! Fast postorder computation with no allocations (aside from result).
27
38
use crate::Block;

src/ssa.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Released under the terms of the Apache 2.0 license with LLVM
3+
* exception. See `LICENSE` for details.
4+
*/
5+
16
//! SSA-related utilities.
27
38
use crate::cfg::CFGInfo;

0 commit comments

Comments
 (0)