@@ -116,10 +116,7 @@ class Value {
116
116
117
117
private:
118
118
Type *VTy;
119
- union {
120
- Use *List = nullptr ;
121
- unsigned Count;
122
- } Uses;
119
+ Use *UseList = nullptr ;
123
120
124
121
friend class ValueAsMetadata ; // Allow access to IsUsedByMD.
125
122
friend class ValueHandleBase ; // Allow access to HasValueHandle.
@@ -347,23 +344,21 @@ class Value {
347
344
348
345
bool use_empty () const {
349
346
assertModuleIsMaterialized ();
350
- return hasUseList () ? Uses. List == nullptr : Uses. Count == 0 ;
347
+ return UseList == nullptr ;
351
348
}
352
349
353
- bool materialized_use_empty () const {
354
- return hasUseList () ? Uses.List == nullptr : !Uses.Count ;
355
- }
350
+ bool materialized_use_empty () const { return UseList == nullptr ; }
356
351
357
352
using use_iterator = use_iterator_impl<Use>;
358
353
using const_use_iterator = use_iterator_impl<const Use>;
359
354
360
355
use_iterator materialized_use_begin () {
361
356
assert (hasUseList ());
362
- return use_iterator (Uses. List );
357
+ return use_iterator (UseList );
363
358
}
364
359
const_use_iterator materialized_use_begin () const {
365
360
assert (hasUseList ());
366
- return const_use_iterator (Uses. List );
361
+ return const_use_iterator (UseList );
367
362
}
368
363
use_iterator use_begin () {
369
364
assertModuleIsMaterialized ();
@@ -397,11 +392,11 @@ class Value {
397
392
398
393
user_iterator materialized_user_begin () {
399
394
assert (hasUseList ());
400
- return user_iterator (Uses. List );
395
+ return user_iterator (UseList );
401
396
}
402
397
const_user_iterator materialized_user_begin () const {
403
398
assert (hasUseList ());
404
- return const_user_iterator (Uses. List );
399
+ return const_user_iterator (UseList );
405
400
}
406
401
user_iterator user_begin () {
407
402
assertModuleIsMaterialized ();
@@ -440,11 +435,7 @@ class Value {
440
435
// /
441
436
// / This is specialized because it is a common request and does not require
442
437
// / traversing the whole use list.
443
- bool hasOneUse () const {
444
- if (!hasUseList ())
445
- return Uses.Count == 1 ;
446
- return hasSingleElement (uses ());
447
- }
438
+ bool hasOneUse () const { return UseList && hasSingleElement (uses ()); }
448
439
449
440
// / Return true if this Value has exactly N uses.
450
441
bool hasNUses (unsigned N) const ;
@@ -518,17 +509,8 @@ class Value {
518
509
519
510
// / This method should only be used by the Use class.
520
511
void addUse (Use &U) {
521
- if (hasUseList ())
522
- U.addToList (Uses.List );
523
- else
524
- U.addToList (Uses.Count );
525
- }
526
-
527
- void removeUse (Use &U) {
528
- if (hasUseList ())
529
- U.removeFromList (Uses.List );
530
- else
531
- U.removeFromList (Uses.Count );
512
+ if (UseList || hasUseList ())
513
+ U.addToList (&UseList);
532
514
}
533
515
534
516
// / Concrete subclass of this.
@@ -870,8 +852,7 @@ class Value {
870
852
// /
871
853
// / \return the first element in the list.
872
854
// /
873
- // / \note Completely ignores \a Use::PrevOrCount (doesn't read, doesn't
874
- // / update).
855
+ // / \note Completely ignores \a Use::Prev (doesn't read, doesn't update).
875
856
template <class Compare >
876
857
static Use *mergeUseLists (Use *L, Use *R, Compare Cmp) {
877
858
Use *Merged;
@@ -917,47 +898,8 @@ inline raw_ostream &operator<<(raw_ostream &OS, const Value &V) {
917
898
return OS;
918
899
}
919
900
920
- inline Use::~Use () {
921
- if (Val)
922
- Val->removeUse (*this );
923
- }
924
-
925
- void Use::addToList (unsigned &Count) {
926
- assert (isa<ConstantData>(Val) && " Only ConstantData is ref-counted" );
927
- ++Count;
928
-
929
- // We don't have a uselist - clear the remnant if we are replacing a
930
- // non-constant value.
931
- Prev = nullptr ;
932
- Next = nullptr ;
933
- }
934
-
935
- void Use::addToList (Use *&List) {
936
- assert (!isa<ConstantData>(Val) && " ConstantData has no use-list" );
937
-
938
- Next = List;
939
- if (Next)
940
- Next->Prev = &Next;
941
- Prev = &List;
942
- List = this ;
943
- }
944
-
945
- void Use::removeFromList (unsigned &Count) {
946
- assert (isa<ConstantData>(Val));
947
- assert (Count > 0 && " reference count underflow" );
948
- assert (!Prev && !Next && " should not have uselist remnant" );
949
- --Count;
950
- }
951
-
952
- void Use::removeFromList (Use *&List) {
953
- *Prev = Next;
954
- if (Next)
955
- Next->Prev = Prev;
956
- }
957
-
958
901
void Use::set (Value *V) {
959
- if (Val)
960
- Val->removeUse (*this );
902
+ removeFromList ();
961
903
Val = V;
962
904
if (V)
963
905
V->addUse (*this );
@@ -974,7 +916,7 @@ const Use &Use::operator=(const Use &RHS) {
974
916
}
975
917
976
918
template <class Compare > void Value::sortUseList (Compare Cmp) {
977
- if (!hasUseList () || !Uses. List || !Uses. List ->Next )
919
+ if (!UseList || !UseList ->Next )
978
920
// No need to sort 0 or 1 uses.
979
921
return ;
980
922
@@ -987,10 +929,10 @@ template <class Compare> void Value::sortUseList(Compare Cmp) {
987
929
Use *Slots[MaxSlots];
988
930
989
931
// Collect the first use, turning it into a single-item list.
990
- Use *Next = Uses. List ->Next ;
991
- Uses. List ->Next = nullptr ;
932
+ Use *Next = UseList ->Next ;
933
+ UseList ->Next = nullptr ;
992
934
unsigned NumSlots = 1 ;
993
- Slots[0 ] = Uses. List ;
935
+ Slots[0 ] = UseList ;
994
936
995
937
// Collect all but the last use.
996
938
while (Next->Next ) {
@@ -1026,15 +968,15 @@ template <class Compare> void Value::sortUseList(Compare Cmp) {
1026
968
// Merge all the lists together.
1027
969
assert (Next && " Expected one more Use" );
1028
970
assert (!Next->Next && " Expected only one Use" );
1029
- Uses. List = Next;
971
+ UseList = Next;
1030
972
for (unsigned I = 0 ; I < NumSlots; ++I)
1031
973
if (Slots[I])
1032
- // Since the uses in Slots[I] originally preceded those in Uses.List , send
974
+ // Since the uses in Slots[I] originally preceded those in UseList , send
1033
975
// Slots[I] in as the left parameter to maintain a stable sort.
1034
- Uses. List = mergeUseLists (Slots[I], Uses. List , Cmp);
976
+ UseList = mergeUseLists (Slots[I], UseList , Cmp);
1035
977
1036
978
// Fix the Prev pointers.
1037
- for (Use *I = Uses. List , **Prev = &Uses. List ; I; I = I->Next ) {
979
+ for (Use *I = UseList , **Prev = &UseList ; I; I = I->Next ) {
1038
980
I->Prev = Prev;
1039
981
Prev = &I->Next ;
1040
982
}
0 commit comments