Skip to content

Commit 104ad92

Browse files
authored
[SelectionDAG] Rename SDNode::uses() to users(). (#120499)
This function is most often used in range based loops or algorithms where the iterator is implicitly dereferenced. The dereference returns an SDNode * of the user rather than SDUse * so users() is a better name. I've long beeen annoyed that we can't write a range based loop over SDUse when we need getOperandNo. I plan to rename use_iterator to user_iterator and add a use_iterator that returns SDUse& on dereference. This will make it more like IR.
1 parent c94ce0c commit 104ad92

29 files changed

+190
-185
lines changed

llvm/include/llvm/CodeGen/SelectionDAGNodes.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ END_TWO_BYTE_PACK()
750750
bool use_empty() const { return UseList == nullptr; }
751751

752752
/// Return true if there is exactly one use of this node.
753-
bool hasOneUse() const { return hasSingleElement(uses()); }
753+
bool hasOneUse() const { return hasSingleElement(users()); }
754754

755755
/// Return the number of uses of this node. This method takes
756756
/// time proportional to the number of uses.
@@ -844,10 +844,14 @@ END_TWO_BYTE_PACK()
844844

845845
static use_iterator use_end() { return use_iterator(nullptr); }
846846

847-
inline iterator_range<use_iterator> uses() {
847+
// Dereferencing use_iterator returns the user SDNode* making it closer to a
848+
// user_iterator thus this function is called users() to reflect that.
849+
// FIXME: Rename to user_iterator and introduce a use_iterator that returns
850+
// SDUse*.
851+
inline iterator_range<use_iterator> users() {
848852
return make_range(use_begin(), use_end());
849853
}
850-
inline iterator_range<use_iterator> uses() const {
854+
inline iterator_range<use_iterator> users() const {
851855
return make_range(use_begin(), use_end());
852856
}
853857

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ namespace {
202202
/// When an instruction is simplified, add all users of the instruction to
203203
/// the work lists because they might get more simplified now.
204204
void AddUsersToWorklist(SDNode *N) {
205-
for (SDNode *Node : N->uses())
205+
for (SDNode *Node : N->users())
206206
AddToWorklist(Node);
207207
}
208208

@@ -1113,7 +1113,7 @@ bool DAGCombiner::reassociationCanBreakAddressingModePattern(unsigned Opc,
11131113
: N1.getConstantOperandVal(1)));
11141114
if (Opc == ISD::SUB)
11151115
ScalableOffset = -ScalableOffset;
1116-
if (all_of(N->uses(), [&](SDNode *Node) {
1116+
if (all_of(N->users(), [&](SDNode *Node) {
11171117
if (auto *LoadStore = dyn_cast<MemSDNode>(Node);
11181118
LoadStore && LoadStore->getBasePtr().getNode() == N) {
11191119
TargetLoweringBase::AddrMode AM;
@@ -1151,7 +1151,7 @@ bool DAGCombiner::reassociationCanBreakAddressingModePattern(unsigned Opc,
11511151
return false;
11521152
const int64_t CombinedValue = CombinedValueIntVal.getSExtValue();
11531153

1154-
for (SDNode *Node : N->uses()) {
1154+
for (SDNode *Node : N->users()) {
11551155
if (auto *LoadStore = dyn_cast<MemSDNode>(Node)) {
11561156
// Is x[offset2] already not a legal addressing mode? If so then
11571157
// reassociating the constants breaks nothing (we test offset2 because
@@ -1176,7 +1176,7 @@ bool DAGCombiner::reassociationCanBreakAddressingModePattern(unsigned Opc,
11761176
if (GA->getOpcode() == ISD::GlobalAddress && TLI.isOffsetFoldingLegal(GA))
11771177
return false;
11781178

1179-
for (SDNode *Node : N->uses()) {
1179+
for (SDNode *Node : N->users()) {
11801180
auto *LoadStore = dyn_cast<MemSDNode>(Node);
11811181
if (!LoadStore)
11821182
return false;
@@ -4720,7 +4720,7 @@ SDValue DAGCombiner::useDivRem(SDNode *Node) {
47204720
SDValue Op0 = Node->getOperand(0);
47214721
SDValue Op1 = Node->getOperand(1);
47224722
SDValue combined;
4723-
for (SDNode *User : Op0->uses()) {
4723+
for (SDNode *User : Op0->users()) {
47244724
if (User == Node || User->getOpcode() == ISD::DELETED_NODE ||
47254725
User->use_empty())
47264726
continue;
@@ -10369,7 +10369,7 @@ static SDValue combineShiftToMULH(SDNode *N, const SDLoc &DL, SelectionDAG &DAG,
1036910369
unsigned MulLoHiOp = IsSignExt ? ISD::SMUL_LOHI : ISD::UMUL_LOHI;
1037010370
if (!ShiftOperand.hasOneUse() &&
1037110371
TLI.isOperationLegalOrCustom(MulLoHiOp, NarrowVT) &&
10372-
llvm::any_of(ShiftOperand->uses(), UserOfLowerBits)) {
10372+
llvm::any_of(ShiftOperand->users(), UserOfLowerBits)) {
1037310373
return SDValue();
1037410374
}
1037510375

@@ -13570,7 +13570,7 @@ static SDValue tryToFoldExtOfLoad(SelectionDAG &DAG, DAGCombiner &Combiner,
1357013570
if (NonNegZExt) {
1357113571
assert(ExtLoadType == ISD::ZEXTLOAD && ExtOpc == ISD::ZERO_EXTEND &&
1357213572
"Unexpected load type or opcode");
13573-
for (SDNode *User : N0->uses()) {
13573+
for (SDNode *User : N0->users()) {
1357413574
if (User->getOpcode() == ISD::SETCC) {
1357513575
ISD::CondCode CC = cast<CondCodeSDNode>(User->getOperand(2))->get();
1357613576
if (ISD::isSignedIntSetCC(CC)) {
@@ -17673,7 +17673,7 @@ SDValue DAGCombiner::combineRepeatedFPDivisors(SDNode *N) {
1767317673
// Find all FDIV users of the same divisor.
1767417674
// Use a set because duplicates may be present in the user list.
1767517675
SetVector<SDNode *> Users;
17676-
for (auto *U : N1->uses()) {
17676+
for (auto *U : N1->users()) {
1767717677
if (U->getOpcode() == ISD::FDIV && U->getOperand(1) == N1) {
1767817678
// Skip X/sqrt(X) that has not been simplified to sqrt(X) yet.
1767917679
if (U->getOperand(1).getOpcode() == ISD::FSQRT &&
@@ -18965,15 +18965,15 @@ bool DAGCombiner::CombineToPreIndexedLoadStore(SDNode *N) {
1896518965
// Now check for #3 and #4.
1896618966
bool RealUse = false;
1896718967

18968-
for (SDNode *Use : Ptr->uses()) {
18969-
if (Use == N)
18968+
for (SDNode *User : Ptr->users()) {
18969+
if (User == N)
1897018970
continue;
18971-
if (SDNode::hasPredecessorHelper(Use, Visited, Worklist, MaxSteps))
18971+
if (SDNode::hasPredecessorHelper(User, Visited, Worklist, MaxSteps))
1897218972
return false;
1897318973

1897418974
// If Ptr may be folded in addressing mode of other use, then it's
1897518975
// not profitable to do this transformation.
18976-
if (!canFoldInAddressingMode(Ptr.getNode(), Use, DAG, TLI))
18976+
if (!canFoldInAddressingMode(Ptr.getNode(), User, DAG, TLI))
1897718977
RealUse = true;
1897818978
}
1897918979

@@ -19089,29 +19089,29 @@ static bool shouldCombineToPostInc(SDNode *N, SDValue Ptr, SDNode *PtrUse,
1908919089

1909019090
SmallPtrSet<const SDNode *, 32> Visited;
1909119091
unsigned MaxSteps = SelectionDAG::getHasPredecessorMaxSteps();
19092-
for (SDNode *Use : BasePtr->uses()) {
19093-
if (Use == Ptr.getNode())
19092+
for (SDNode *User : BasePtr->users()) {
19093+
if (User == Ptr.getNode())
1909419094
continue;
1909519095

1909619096
// No if there's a later user which could perform the index instead.
19097-
if (isa<MemSDNode>(Use)) {
19097+
if (isa<MemSDNode>(User)) {
1909819098
bool IsLoad = true;
1909919099
bool IsMasked = false;
1910019100
SDValue OtherPtr;
19101-
if (getCombineLoadStoreParts(Use, ISD::POST_INC, ISD::POST_DEC, IsLoad,
19101+
if (getCombineLoadStoreParts(User, ISD::POST_INC, ISD::POST_DEC, IsLoad,
1910219102
IsMasked, OtherPtr, TLI)) {
1910319103
SmallVector<const SDNode *, 2> Worklist;
19104-
Worklist.push_back(Use);
19104+
Worklist.push_back(User);
1910519105
if (SDNode::hasPredecessorHelper(N, Visited, Worklist, MaxSteps))
1910619106
return false;
1910719107
}
1910819108
}
1910919109

1911019110
// If all the uses are load / store addresses, then don't do the
1911119111
// transformation.
19112-
if (Use->getOpcode() == ISD::ADD || Use->getOpcode() == ISD::SUB) {
19113-
for (SDNode *UseUse : Use->uses())
19114-
if (canFoldInAddressingMode(Use, UseUse, DAG, TLI))
19112+
if (User->getOpcode() == ISD::ADD || User->getOpcode() == ISD::SUB) {
19113+
for (SDNode *UserUser : User->users())
19114+
if (canFoldInAddressingMode(User, UserUser, DAG, TLI))
1911519115
return false;
1911619116
}
1911719117
}
@@ -19136,7 +19136,7 @@ static SDNode *getPostIndexedLoadStoreOp(SDNode *N, bool &IsLoad,
1913619136
// nor a successor of N. Otherwise, if Op is folded that would
1913719137
// create a cycle.
1913819138
unsigned MaxSteps = SelectionDAG::getHasPredecessorMaxSteps();
19139-
for (SDNode *Op : Ptr->uses()) {
19139+
for (SDNode *Op : Ptr->users()) {
1914019140
// Check for #1.
1914119141
if (!shouldCombineToPostInc(N, Ptr, Op, BasePtr, Offset, AM, DAG, TLI))
1914219142
continue;
@@ -20515,24 +20515,24 @@ bool DAGCombiner::isMulAddWithConstProfitable(SDNode *MulNode, SDValue AddNode,
2051520515
return true;
2051620516

2051720517
// Walk all the users of the constant with which we're multiplying.
20518-
for (SDNode *Use : ConstNode->uses()) {
20519-
if (Use == MulNode) // This use is the one we're on right now. Skip it.
20518+
for (SDNode *User : ConstNode->users()) {
20519+
if (User == MulNode) // This use is the one we're on right now. Skip it.
2052020520
continue;
2052120521

20522-
if (Use->getOpcode() == ISD::MUL) { // We have another multiply use.
20522+
if (User->getOpcode() == ISD::MUL) { // We have another multiply use.
2052320523
SDNode *OtherOp;
2052420524
SDNode *MulVar = AddNode.getOperand(0).getNode();
2052520525

2052620526
// OtherOp is what we're multiplying against the constant.
20527-
if (Use->getOperand(0) == ConstNode)
20528-
OtherOp = Use->getOperand(1).getNode();
20527+
if (User->getOperand(0) == ConstNode)
20528+
OtherOp = User->getOperand(1).getNode();
2052920529
else
20530-
OtherOp = Use->getOperand(0).getNode();
20530+
OtherOp = User->getOperand(0).getNode();
2053120531

2053220532
// Check to see if multiply is with the same operand of our "add".
2053320533
//
2053420534
// ConstNode = CONST
20535-
// Use = ConstNode * A <-- visiting Use. OtherOp is A.
20535+
// User = ConstNode * A <-- visiting User. OtherOp is A.
2053620536
// ...
2053720537
// AddNode = (A + c1) <-- MulVar is A.
2053820538
// = AddNode * ConstNode <-- current visiting instruction.
@@ -20550,7 +20550,7 @@ bool DAGCombiner::isMulAddWithConstProfitable(SDNode *MulNode, SDValue AddNode,
2055020550
// ... = AddNode * ConstNode <-- current visiting instruction.
2055120551
// ...
2055220552
// OtherOp = (A + c2)
20553-
// Use = OtherOp * ConstNode <-- visiting Use.
20553+
// User = OtherOp * ConstNode <-- visiting User.
2055420554
//
2055520555
// If we make this transformation, we will have a common
2055620556
// multiply (CONST * A) after we also do the same transformation
@@ -22902,7 +22902,7 @@ bool DAGCombiner::refineExtractVectorEltIntoMultipleNarrowExtractVectorElts(
2290222902
// Did we fail to model any of the users of the Producer?
2290322903
bool ProducerIsLeaf = false;
2290422904
// Look at each user of this Producer.
22905-
for (SDNode *User : E.Producer->uses()) {
22905+
for (SDNode *User : E.Producer->users()) {
2290622906
switch (User->getOpcode()) {
2290722907
// TODO: support ISD::BITCAST
2290822908
// TODO: support ISD::ANY_EXTEND
@@ -23176,14 +23176,14 @@ SDValue DAGCombiner::visitEXTRACT_VECTOR_ELT(SDNode *N) {
2317623176

2317723177
// If only EXTRACT_VECTOR_ELT nodes use the source vector we can
2317823178
// simplify it based on the (valid) extraction indices.
23179-
if (llvm::all_of(VecOp->uses(), [&](SDNode *Use) {
23179+
if (llvm::all_of(VecOp->users(), [&](SDNode *Use) {
2318023180
return Use->getOpcode() == ISD::EXTRACT_VECTOR_ELT &&
2318123181
Use->getOperand(0) == VecOp &&
2318223182
isa<ConstantSDNode>(Use->getOperand(1));
2318323183
})) {
2318423184
APInt DemandedElts = APInt::getZero(NumElts);
23185-
for (SDNode *Use : VecOp->uses()) {
23186-
auto *CstElt = cast<ConstantSDNode>(Use->getOperand(1));
23185+
for (SDNode *User : VecOp->users()) {
23186+
auto *CstElt = cast<ConstantSDNode>(User->getOperand(1));
2318723187
if (CstElt->getAPIntValue().ult(NumElts))
2318823188
DemandedElts.setBit(CstElt->getZExtValue());
2318923189
}
@@ -27302,7 +27302,7 @@ SDValue DAGCombiner::visitGET_FPENV_MEM(SDNode *N) {
2730227302
// Check if the memory, where FP state is written to, is used only in a single
2730327303
// load operation.
2730427304
LoadSDNode *LdNode = nullptr;
27305-
for (auto *U : Ptr->uses()) {
27305+
for (auto *U : Ptr->users()) {
2730627306
if (U == N)
2730727307
continue;
2730827308
if (auto *Ld = dyn_cast<LoadSDNode>(U)) {
@@ -27352,7 +27352,7 @@ SDValue DAGCombiner::visitSET_FPENV_MEM(SDNode *N) {
2735227352

2735327353
// Check if the address of FP state is used also in a store operation only.
2735427354
StoreSDNode *StNode = nullptr;
27355-
for (auto *U : Ptr->uses()) {
27355+
for (auto *U : Ptr->users()) {
2735627356
if (U == N)
2735727357
continue;
2735827358
if (auto *St = dyn_cast<StoreSDNode>(U)) {

llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void InstrEmitter::EmitCopyFromReg(SDNode *Node, unsigned ResNo, bool IsClone,
105105
if (TLI->isTypeLegal(VT))
106106
UseRC = TLI->getRegClassFor(VT, Node->isDivergent());
107107

108-
for (SDNode *User : Node->uses()) {
108+
for (SDNode *User : Node->users()) {
109109
bool Match = true;
110110
if (User->getOpcode() == ISD::CopyToReg &&
111111
User->getOperand(2).getNode() == Node &&
@@ -225,7 +225,7 @@ void InstrEmitter::CreateVirtualRegisters(SDNode *Node,
225225
}
226226

227227
if (!VRBase && !IsClone && !IsCloned)
228-
for (SDNode *User : Node->uses()) {
228+
for (SDNode *User : Node->users()) {
229229
if (User->getOpcode() == ISD::CopyToReg &&
230230
User->getOperand(2).getNode() == Node &&
231231
User->getOperand(2).getResNo() == i) {
@@ -502,7 +502,7 @@ void InstrEmitter::EmitSubregNode(SDNode *Node, VRBaseMapType &VRBaseMap,
502502

503503
// If the node is only used by a CopyToReg and the dest reg is a vreg, use
504504
// the CopyToReg'd destination register instead of creating a new vreg.
505-
for (SDNode *User : Node->uses()) {
505+
for (SDNode *User : Node->users()) {
506506
if (User->getOpcode() == ISD::CopyToReg &&
507507
User->getOperand(2).getNode() == Node) {
508508
Register DestReg = cast<RegisterSDNode>(User->getOperand(1))->getReg();

llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ SDValue SelectionDAGLegalize::ExpandExtractFromVectorThroughStack(SDValue Op) {
13941394
Visited.insert(Op.getNode());
13951395
Worklist.push_back(Idx.getNode());
13961396
SDValue StackPtr, Ch;
1397-
for (SDNode *User : Vec.getNode()->uses()) {
1397+
for (SDNode *User : Vec.getNode()->users()) {
13981398
if (StoreSDNode *ST = dyn_cast<StoreSDNode>(User)) {
13991399
if (ST->isIndexed() || ST->isTruncatingStore() ||
14001400
ST->getValue() != Vec)
@@ -2293,7 +2293,7 @@ static bool useSinCos(SDNode *Node) {
22932293
? ISD::FCOS : ISD::FSIN;
22942294

22952295
SDValue Op0 = Node->getOperand(0);
2296-
for (const SDNode *User : Op0.getNode()->uses()) {
2296+
for (const SDNode *User : Op0.getNode()->users()) {
22972297
if (User == Node)
22982298
continue;
22992299
// The other user might have been turned into sincos already.

llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ void DAGTypeLegalizer::PerformExpensiveChecks() {
189189
#ifndef NDEBUG
190190
// Checked that NewNodes are only used by other NewNodes.
191191
for (SDNode *N : NewNodes) {
192-
for (SDNode *U : N->uses())
192+
for (SDNode *U : N->users())
193193
assert(U->getNodeId() == NewNode && "NewNode used by non-NewNode!");
194194
}
195195
#endif
@@ -399,7 +399,7 @@ bool DAGTypeLegalizer::run() {
399399
assert(N->getNodeId() == ReadyToProcess && "Node ID recalculated?");
400400
N->setNodeId(Processed);
401401

402-
for (SDNode *User : N->uses()) {
402+
for (SDNode *User : N->users()) {
403403
int NodeId = User->getNodeId();
404404

405405
// This node has two options: it can either be a new node or its Node ID

llvm/lib/CodeGen/SelectionDAG/ScheduleDAGFast.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ void ScheduleDAGLinearize::Schedule() {
756756
// Glue user must be scheduled together with the glue operand. So other
757757
// users of the glue operand must be treated as its users.
758758
SDNode *ImmGUser = Glue->getGluedUser();
759-
for (const SDNode *U : Glue->uses())
759+
for (const SDNode *U : Glue->users())
760760
if (U == ImmGUser)
761761
--Degree;
762762
GUser->setNodeId(UDegree + Degree);

llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ void ScheduleDAGSDNodes::BuildSchedUnits() {
388388

389389
// There are either zero or one users of the Glue result.
390390
bool HasGlueUse = false;
391-
for (SDNode *U : N->uses())
391+
for (SDNode *U : N->users())
392392
if (GlueVal.isOperandOf(U)) {
393393
HasGlueUse = true;
394394
assert(N->getNodeId() == -1 && "Node already inserted!");

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,7 +2556,7 @@ bool SelectionDAG::expandMultipleResultFPLibCall(
25562556
// destination pointers can be used instead of creating stack allocations.
25572557
SDValue StoresInChain;
25582558
SmallVector<StoreSDNode *, 2> ResultStores(NumResults);
2559-
for (SDNode *User : Node->uses()) {
2559+
for (SDNode *User : Node->users()) {
25602560
if (!ISD::isNormalStore(User))
25612561
continue;
25622562
auto *ST = cast<StoreSDNode>(User);
@@ -7933,7 +7933,7 @@ SDValue SelectionDAG::getStackArgumentTokenFactor(SDValue Chain) {
79337933
ArgChains.push_back(Chain);
79347934

79357935
// Add a chain value for each stack argument.
7936-
for (SDNode *U : getEntryNode().getNode()->uses())
7936+
for (SDNode *U : getEntryNode().getNode()->users())
79377937
if (LoadSDNode *L = dyn_cast<LoadSDNode>(U))
79387938
if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(L->getBasePtr()))
79397939
if (FI->getIndex() < 0)
@@ -11926,7 +11926,7 @@ void SelectionDAG::updateDivergence(SDNode *N) {
1192611926
bool IsDivergent = calculateDivergence(N);
1192711927
if (N->SDNodeBits.IsDivergent != IsDivergent) {
1192811928
N->SDNodeBits.IsDivergent = IsDivergent;
11929-
llvm::append_range(Worklist, N->uses());
11929+
llvm::append_range(Worklist, N->users());
1193011930
}
1193111931
} while (!Worklist.empty());
1193211932
}
@@ -11942,7 +11942,7 @@ void SelectionDAG::CreateTopologicalOrder(std::vector<SDNode *> &Order) {
1194211942
}
1194311943
for (size_t I = 0; I != Order.size(); ++I) {
1194411944
SDNode *N = Order[I];
11945-
for (auto *U : N->uses()) {
11945+
for (auto *U : N->users()) {
1194611946
unsigned &UnsortedOps = Degree[U];
1194711947
if (0 == --UnsortedOps)
1194811948
Order.push_back(U);
@@ -12071,7 +12071,7 @@ unsigned SelectionDAG::AssignTopologicalOrder() {
1207112071
checkForCycles(N, this);
1207212072
// N is in sorted position, so all its uses have one less operand
1207312073
// that needs to be sorted.
12074-
for (SDNode *P : N->uses()) {
12074+
for (SDNode *P : N->users()) {
1207512075
unsigned Degree = P->getNodeId();
1207612076
assert(Degree != 0 && "Invalid node degree");
1207712077
--Degree;
@@ -12489,7 +12489,7 @@ bool SDNode::hasAnyUseOfValue(unsigned Value) const {
1248912489
/// isOnlyUserOf - Return true if this node is the only use of N.
1249012490
bool SDNode::isOnlyUserOf(const SDNode *N) const {
1249112491
bool Seen = false;
12492-
for (const SDNode *User : N->uses()) {
12492+
for (const SDNode *User : N->users()) {
1249312493
if (User == this)
1249412494
Seen = true;
1249512495
else
@@ -12502,7 +12502,7 @@ bool SDNode::isOnlyUserOf(const SDNode *N) const {
1250212502
/// Return true if the only users of N are contained in Nodes.
1250312503
bool SDNode::areOnlyUsersOf(ArrayRef<const SDNode *> Nodes, const SDNode *N) {
1250412504
bool Seen = false;
12505-
for (const SDNode *User : N->uses()) {
12505+
for (const SDNode *User : N->users()) {
1250612506
if (llvm::is_contained(Nodes, User))
1250712507
Seen = true;
1250812508
else

0 commit comments

Comments
 (0)