Skip to content

Commit bb6f829

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

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/lib.rs

+11-3
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

0 commit comments

Comments
 (0)