@@ -36,20 +36,15 @@ struct IdTag {
36
36
IdTag () = default ;
37
37
38
38
explicit IdTag (int32_t id_index, int32_t initial_reserved_ids)
39
- : initial_reserved_ids_(initial_reserved_ids) {
40
- // Shift down by 1 to get out of the high bit to avoid using any negative
41
- // ids, since they have special uses. Shift down by another 1 to free up the
42
- // second highest bit for a marker to indicate whether the index is tagged
43
- // (& needs to be untagged) or not. Add one to the index so it's not
44
- // zero-based, to make it a bit less likely this doesn't collide with
45
- // anything else (though with the second-highest-bit-tagging this might not
46
- // be needed).
47
- id_tag_ = llvm::reverseBits ((((id_index + 1 ) << 1 ) | 1 ) << 1 );
48
- }
49
-
50
- auto GetCheckIRId () const -> int32_t {
51
- return (llvm::reverseBits (id_tag_) >> 2 ) - 1 ;
52
- }
39
+ : // Shift down by 1 to get out of the high bit to avoid using any
40
+ // negative ids, since they have special uses. Shift down by another 1
41
+ // to free up the second highest bit for a marker to indicate whether
42
+ // the index is tagged (& needs to be untagged) or not. Add one to the
43
+ // index so it's not zero-based, to make it a bit less likely this
44
+ // doesn't collide with anything else (though with the
45
+ // second-highest-bit-tagging this might not be needed).
46
+ id_tag_(llvm::reverseBits((((id_index + 1 ) << 1) | 1) << 1)),
47
+ initial_reserved_ids_(initial_reserved_ids) {}
53
48
54
49
auto Apply (int32_t index) const -> int32_t {
55
50
if (index < initial_reserved_ids_) {
@@ -73,16 +68,24 @@ struct IdTag {
73
68
return index;
74
69
}
75
70
71
+ // Gets the value unique to this IdTag instance that is added to indices in
72
+ // Apply, and removed in Remove.
73
+ auto GetContainerTag () const -> int32_t {
74
+ return (llvm::reverseBits (id_tag_) >> 2 ) - 1 ;
75
+ }
76
+
77
+ // Returns whether `tagged_index` has an IdTag applied to it, from this IdTag
78
+ // instance or any other one.
76
79
static auto HasTag (int32_t tagged_index) -> bool {
77
80
return (llvm::reverseBits (2 ) & tagged_index) != 0 ;
78
81
}
79
82
80
- struct IrAndIndex {
81
- int32_t check_ir_id ;
83
+ struct TagAndIndex {
84
+ int32_t tag ;
82
85
int32_t index;
83
86
};
84
87
85
- static auto DecomposeWithBestEffort (int32_t tagged_index) -> IrAndIndex {
88
+ static auto DecomposeWithBestEffort (int32_t tagged_index) -> TagAndIndex {
86
89
if (tagged_index < 0 ) {
87
90
return {-1 , tagged_index};
88
91
}
@@ -110,9 +113,9 @@ struct IdTag {
110
113
return {-1 , tagged_index};
111
114
}
112
115
auto index_mask = llvm::maskTrailingOnes<uint32_t >(location);
113
- auto check_ir_id = (llvm::reverseBits (tagged_index & ~index_mask) >> 2 ) - 1 ;
116
+ auto tag = (llvm::reverseBits (tagged_index & ~index_mask) >> 2 ) - 1 ;
114
117
auto index = tagged_index & index_mask;
115
- return {.check_ir_id = static_cast <int32_t >(check_ir_id ),
118
+ return {.tag = static_cast <int32_t >(tag ),
116
119
.index = static_cast <int32_t >(index)};
117
120
}
118
121
@@ -299,7 +302,7 @@ class ValueStore
299
302
" Untagged index was outside of container range. Possibly tagged "
300
303
" index {0}. Best-effort decomposition: CheckIRId: {1}, index: {2}. "
301
304
" The IdTag for this container is: {3}" ,
302
- id.index , ir_id, decomposed_index, tag_.GetCheckIRId ());
305
+ id.index , ir_id, decomposed_index, tag_.GetContainerTag ());
303
306
}
304
307
#endif
305
308
return index;
0 commit comments