Skip to content

Commit 5936c02

Browse files
committed
Revert "IR: Remove uselist for constantdata (#137313)"
Possibly breaks the build: https://lab.llvm.org/buildbot/#/builders/24/builds/8119 This reverts commit 87f312a.
1 parent 0274232 commit 5936c02

27 files changed

+104
-247
lines changed

llvm/docs/ReleaseNotes.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ Makes programs 10x faster by doing Special New Thing.
5656
Changes to the LLVM IR
5757
----------------------
5858

59-
* It is no longer permitted to inspect the uses of ConstantData
60-
6159
* The `nocapture` attribute has been replaced by `captures(none)`.
6260
* The constant expression variants of the following instructions have been
6361
removed:

llvm/include/llvm/IR/Constants.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ template <class ConstantClass> struct ConstantAggrKeyType;
5050
/// These constants have no operands; they represent their data directly.
5151
/// Since they can be in use by unrelated modules (and are never based on
5252
/// GlobalValues), it never makes sense to RAUW them.
53-
///
54-
/// These do not have use lists. It is illegal to inspect the uses.
5553
class ConstantData : public Constant {
5654
constexpr static IntrusiveOperandsAllocMarker AllocMarker{0};
5755

llvm/include/llvm/IR/Use.h

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
namespace llvm {
2424

2525
template <typename> struct simplify_type;
26-
class ConstantData;
2726
class User;
2827
class Value;
2928

@@ -43,7 +42,10 @@ class Use {
4342

4443
private:
4544
/// Destructor - Only for zap()
46-
~Use();
45+
~Use() {
46+
if (Val)
47+
removeFromList();
48+
}
4749

4850
/// Constructor
4951
Use(User *Parent) : Parent(Parent) {}
@@ -85,10 +87,19 @@ class Use {
8587
Use **Prev = nullptr;
8688
User *Parent = nullptr;
8789

88-
inline void addToList(unsigned &Count);
89-
inline void addToList(Use *&List);
90-
inline void removeFromList(unsigned &Count);
91-
inline void removeFromList(Use *&List);
90+
void addToList(Use **List) {
91+
Next = *List;
92+
if (Next)
93+
Next->Prev = &Next;
94+
Prev = List;
95+
*Prev = this;
96+
}
97+
98+
void removeFromList() {
99+
*Prev = Next;
100+
if (Next)
101+
Next->Prev = Prev;
102+
}
92103
};
93104

94105
/// Allow clients to treat uses just like values when using

llvm/include/llvm/IR/Value.h

Lines changed: 24 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ class Value {
116116

117117
private:
118118
Type *VTy;
119-
union {
120-
Use *List = nullptr;
121-
unsigned Count;
122-
} Uses;
119+
Use *UseList;
123120

124121
friend class ValueAsMetadata; // Allow access to IsUsedByMD.
125122
friend class ValueHandleBase; // Allow access to HasValueHandle.
@@ -342,28 +339,21 @@ class Value {
342339
#endif
343340
}
344341

345-
/// Check if this Value has a use-list.
346-
bool hasUseList() const { return !isa<ConstantData>(this); }
347-
348342
bool use_empty() const {
349343
assertModuleIsMaterialized();
350-
return hasUseList() ? Uses.List == nullptr : Uses.Count == 0;
344+
return UseList == nullptr;
351345
}
352346

353347
bool materialized_use_empty() const {
354-
return hasUseList() ? Uses.List == nullptr : !Uses.Count;
348+
return UseList == nullptr;
355349
}
356350

357351
using use_iterator = use_iterator_impl<Use>;
358352
using const_use_iterator = use_iterator_impl<const Use>;
359353

360-
use_iterator materialized_use_begin() {
361-
assert(hasUseList());
362-
return use_iterator(Uses.List);
363-
}
354+
use_iterator materialized_use_begin() { return use_iterator(UseList); }
364355
const_use_iterator materialized_use_begin() const {
365-
assert(hasUseList());
366-
return const_use_iterator(Uses.List);
356+
return const_use_iterator(UseList);
367357
}
368358
use_iterator use_begin() {
369359
assertModuleIsMaterialized();
@@ -390,18 +380,17 @@ class Value {
390380
return materialized_uses();
391381
}
392382

393-
bool user_empty() const { return use_empty(); }
383+
bool user_empty() const {
384+
assertModuleIsMaterialized();
385+
return UseList == nullptr;
386+
}
394387

395388
using user_iterator = user_iterator_impl<User>;
396389
using const_user_iterator = user_iterator_impl<const User>;
397390

398-
user_iterator materialized_user_begin() {
399-
assert(hasUseList());
400-
return user_iterator(Uses.List);
401-
}
391+
user_iterator materialized_user_begin() { return user_iterator(UseList); }
402392
const_user_iterator materialized_user_begin() const {
403-
assert(hasUseList());
404-
return const_user_iterator(Uses.List);
393+
return const_user_iterator(UseList);
405394
}
406395
user_iterator user_begin() {
407396
assertModuleIsMaterialized();
@@ -440,11 +429,7 @@ class Value {
440429
///
441430
/// This is specialized because it is a common request and does not require
442431
/// traversing the whole use list.
443-
bool hasOneUse() const {
444-
if (!hasUseList())
445-
return Uses.Count == 1;
446-
return hasSingleElement(uses());
447-
}
432+
bool hasOneUse() const { return hasSingleElement(uses()); }
448433

449434
/// Return true if this Value has exactly N uses.
450435
bool hasNUses(unsigned N) const;
@@ -506,8 +491,6 @@ class Value {
506491
static void dropDroppableUse(Use &U);
507492

508493
/// Check if this value is used in the specified basic block.
509-
///
510-
/// Not supported for ConstantData.
511494
bool isUsedInBasicBlock(const BasicBlock *BB) const;
512495

513496
/// This method computes the number of uses of this Value.
@@ -517,19 +500,7 @@ class Value {
517500
unsigned getNumUses() const;
518501

519502
/// This method should only be used by the Use class.
520-
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);
532-
}
503+
void addUse(Use &U) { U.addToList(&UseList); }
533504

534505
/// Concrete subclass of this.
535506
///
@@ -870,8 +841,7 @@ class Value {
870841
///
871842
/// \return the first element in the list.
872843
///
873-
/// \note Completely ignores \a Use::PrevOrCount (doesn't read, doesn't
874-
/// update).
844+
/// \note Completely ignores \a Use::Prev (doesn't read, doesn't update).
875845
template <class Compare>
876846
static Use *mergeUseLists(Use *L, Use *R, Compare Cmp) {
877847
Use *Merged;
@@ -917,50 +887,10 @@ inline raw_ostream &operator<<(raw_ostream &OS, const Value &V) {
917887
return OS;
918888
}
919889

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-
958890
void Use::set(Value *V) {
959-
if (Val)
960-
Val->removeUse(*this);
891+
if (Val) removeFromList();
961892
Val = V;
962-
if (V)
963-
V->addUse(*this);
893+
if (V) V->addUse(*this);
964894
}
965895

966896
Value *Use::operator=(Value *RHS) {
@@ -974,7 +904,7 @@ const Use &Use::operator=(const Use &RHS) {
974904
}
975905

976906
template <class Compare> void Value::sortUseList(Compare Cmp) {
977-
if (!hasUseList() || !Uses.List || !Uses.List->Next)
907+
if (!UseList || !UseList->Next)
978908
// No need to sort 0 or 1 uses.
979909
return;
980910

@@ -987,10 +917,10 @@ template <class Compare> void Value::sortUseList(Compare Cmp) {
987917
Use *Slots[MaxSlots];
988918

989919
// Collect the first use, turning it into a single-item list.
990-
Use *Next = Uses.List->Next;
991-
Uses.List->Next = nullptr;
920+
Use *Next = UseList->Next;
921+
UseList->Next = nullptr;
992922
unsigned NumSlots = 1;
993-
Slots[0] = Uses.List;
923+
Slots[0] = UseList;
994924

995925
// Collect all but the last use.
996926
while (Next->Next) {
@@ -1026,15 +956,15 @@ template <class Compare> void Value::sortUseList(Compare Cmp) {
1026956
// Merge all the lists together.
1027957
assert(Next && "Expected one more Use");
1028958
assert(!Next->Next && "Expected only one Use");
1029-
Uses.List = Next;
959+
UseList = Next;
1030960
for (unsigned I = 0; I < NumSlots; ++I)
1031961
if (Slots[I])
1032-
// Since the uses in Slots[I] originally preceded those in Uses.List, send
962+
// Since the uses in Slots[I] originally preceded those in UseList, send
1033963
// Slots[I] in as the left parameter to maintain a stable sort.
1034-
Uses.List = mergeUseLists(Slots[I], Uses.List, Cmp);
964+
UseList = mergeUseLists(Slots[I], UseList, Cmp);
1035965

1036966
// Fix the Prev pointers.
1037-
for (Use *I = Uses.List, **Prev = &Uses.List; I; I = I->Next) {
967+
for (Use *I = UseList, **Prev = &UseList; I; I = I->Next) {
1038968
I->Prev = Prev;
1039969
Prev = &I->Next;
1040970
}

llvm/lib/Analysis/TypeMetadataUtils.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ findCallsAtConstantOffset(SmallVectorImpl<DevirtCallSite> &DevirtCalls,
5454
static void findLoadCallsAtConstantOffset(
5555
const Module *M, SmallVectorImpl<DevirtCallSite> &DevirtCalls, Value *VPtr,
5656
int64_t Offset, const CallInst *CI, DominatorTree &DT) {
57-
if (!VPtr->hasUseList())
58-
return;
59-
6057
for (const Use &U : VPtr->uses()) {
6158
Value *User = U.getUser();
6259
if (isa<BitCastInst>(User)) {

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8869,8 +8869,6 @@ bool LLParser::parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts) {
88698869
//===----------------------------------------------------------------------===//
88708870
bool LLParser::sortUseListOrder(Value *V, ArrayRef<unsigned> Indexes,
88718871
SMLoc Loc) {
8872-
if (!V->hasUseList())
8873-
return false;
88748872
if (V->use_empty())
88758873
return error(Loc, "value has no uses");
88768874

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3860,10 +3860,6 @@ Error BitcodeReader::parseUseLists() {
38603860
V = FunctionBBs[ID];
38613861
} else
38623862
V = ValueList[ID];
3863-
3864-
if (!V->hasUseList())
3865-
break;
3866-
38673863
unsigned NumUses = 0;
38683864
SmallDenseMap<const Use *, unsigned, 16> Order;
38693865
for (const Use &U : V->materialized_uses()) {

llvm/lib/Bitcode/Writer/ValueEnumerator.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,6 @@ static void predictValueUseListOrderImpl(const Value *V, const Function *F,
230230

231231
static void predictValueUseListOrder(const Value *V, const Function *F,
232232
OrderMap &OM, UseListOrderStack &Stack) {
233-
if (!V->hasUseList())
234-
return;
235-
236233
auto &IDPair = OM[V];
237234
assert(IDPair.first && "Unmapped value");
238235
if (IDPair.second)

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4002,7 +4002,7 @@ static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *CV,
40024002
// Globals with sub-elements such as combinations of arrays and structs
40034003
// are handled recursively by emitGlobalConstantImpl. Keep track of the
40044004
// constant symbol base and the current position with BaseCV and Offset.
4005-
if (!isa<ConstantData>(CV) && !BaseCV && CV->hasOneUse())
4005+
if (!BaseCV && CV->hasOneUse())
40064006
BaseCV = dyn_cast<Constant>(CV->user_back());
40074007

40084008
if (isa<ConstantAggregateZero>(CV)) {

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8591,9 +8591,6 @@ static bool optimizeBranch(BranchInst *Branch, const TargetLowering &TLI,
85918591
return false;
85928592

85938593
Value *X = Cmp->getOperand(0);
8594-
if (!X->hasUseList())
8595-
return false;
8596-
85978594
APInt CmpC = cast<ConstantInt>(Cmp->getOperand(1))->getValue();
85988595

85998596
for (auto *U : X->users()) {

llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,9 +1034,6 @@ ComplexDeinterleavingGraph::identifyPartialReduction(Value *R, Value *I) {
10341034
if (!isa<VectorType>(R->getType()) || !isa<VectorType>(I->getType()))
10351035
return nullptr;
10361036

1037-
if (!R->hasUseList() || !I->hasUseList())
1038-
return nullptr;
1039-
10401037
auto CommonUser =
10411038
findCommonBetweenCollections<Value *>(R->users(), I->users());
10421039
if (!CommonUser)

llvm/lib/IR/AsmWriter.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,11 @@ static void orderValue(const Value *V, OrderMap &OM) {
125125
if (OM.lookup(V))
126126
return;
127127

128-
if (const Constant *C = dyn_cast<Constant>(V)) {
129-
if (isa<ConstantData>(C))
130-
return;
131-
128+
if (const Constant *C = dyn_cast<Constant>(V))
132129
if (C->getNumOperands() && !isa<GlobalValue>(C))
133130
for (const Value *Op : C->operands())
134131
if (!isa<BasicBlock>(Op) && !isa<GlobalValue>(Op))
135132
orderValue(Op, OM);
136-
}
137133

138134
// Note: we cannot cache this lookup above, since inserting into the map
139135
// changes the map's size, and thus affects the other IDs.
@@ -279,8 +275,7 @@ static UseListOrderMap predictUseListOrder(const Module *M) {
279275
UseListOrderMap ULOM;
280276
for (const auto &Pair : OM) {
281277
const Value *V = Pair.first;
282-
if (!V->hasUseList() || V->use_empty() ||
283-
std::next(V->use_begin()) == V->use_end())
278+
if (V->use_empty() || std::next(V->use_begin()) == V->use_end())
284279
continue;
285280

286281
std::vector<unsigned> Shuffle =

llvm/lib/IR/Instruction.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,7 @@ std::optional<BasicBlock::iterator> Instruction::getInsertionPointAfterDef() {
373373
}
374374

375375
bool Instruction::isOnlyUserOfAnyOperand() {
376-
return any_of(operands(), [](const Value *V) {
377-
return V->hasUseList() && V->hasOneUser();
378-
});
376+
return any_of(operands(), [](Value *V) { return V->hasOneUser(); });
379377
}
380378

381379
void Instruction::setHasNoUnsignedWrap(bool b) {

0 commit comments

Comments
 (0)