@@ -355,6 +355,7 @@ impl Operand {
355
355
356
356
#[ inline( always) ]
357
357
pub fn from_bits ( bits : u32 ) -> Self {
358
+ debug_assert ! ( bits >> 29 <= 4 ) ;
358
359
Operand { bits }
359
360
}
360
361
}
@@ -429,9 +430,9 @@ pub struct Allocation {
429
430
/// `policy` field in `Operand`, and we are careful to use
430
431
/// disjoint ranges of values in this field for each type. We also
431
432
/// 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 ).
435
436
///
436
437
/// kind:3 unused:1 index:28
437
438
bits : u32 ,
@@ -532,6 +533,7 @@ impl Allocation {
532
533
533
534
#[ inline( always) ]
534
535
pub fn from_bits ( bits : u32 ) -> Self {
536
+ debug_assert ! ( bits >> 29 >= 5 ) ;
535
537
Self { bits }
536
538
}
537
539
}
@@ -566,11 +568,13 @@ pub struct OperandOrAllocation {
566
568
567
569
impl OperandOrAllocation {
568
570
pub fn from_operand ( operand : Operand ) -> Self {
571
+ debug_assert ! ( operand. bits( ) >> 29 <= 4 ) ;
569
572
Self {
570
573
bits : operand. bits ( ) ,
571
574
}
572
575
}
573
576
pub fn from_alloc ( alloc : Allocation ) -> Self {
577
+ debug_assert ! ( alloc. bits( ) >> 29 >= 5 ) ;
574
578
Self { bits : alloc. bits ( ) }
575
579
}
576
580
pub fn is_operand ( & self ) -> bool {
@@ -588,6 +592,10 @@ impl OperandOrAllocation {
588
592
}
589
593
pub fn as_allocation ( & self ) -> Option < Allocation > {
590
594
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.
591
599
Some ( Allocation :: from_bits ( self . bits & !( 1 << 28 ) ) )
592
600
} else {
593
601
None
0 commit comments