@@ -80,14 +80,13 @@ enum LocalNum {
80
80
LN_Last
81
81
};
82
82
83
- // Associate global and local DFS info with defs and uses, so we can sort them
84
- // into a global domination ordering.
83
+ // Associate global and local DFS info with defs (PInfo set) and uses (U set),
84
+ // so we can sort them into a global domination ordering.
85
85
struct ValueDFS {
86
86
int DFSIn = 0 ;
87
87
int DFSOut = 0 ;
88
88
unsigned int LocalNum = LN_Middle;
89
- // Only one of Def or Use will be set.
90
- Value *Def = nullptr ;
89
+ // Only one of U or PInfo will be set.
91
90
Use *U = nullptr ;
92
91
PredicateBase *PInfo = nullptr ;
93
92
};
@@ -101,7 +100,6 @@ struct ValueDFS_Compare {
101
100
bool operator ()(const ValueDFS &A, const ValueDFS &B) const {
102
101
if (&A == &B)
103
102
return false ;
104
- assert (!A.Def && !B.Def && " Should not have Def during comparison" );
105
103
106
104
// Order by block first.
107
105
if (A.DFSIn != B.DFSIn )
@@ -133,7 +131,7 @@ struct ValueDFS_Compare {
133
131
134
132
// For a phi use, or a non-materialized def, return the edge it represents.
135
133
std::pair<BasicBlock *, BasicBlock *> getBlockEdge (const ValueDFS &VD) const {
136
- if (!VD. Def && VD.U ) {
134
+ if (VD.U ) {
137
135
auto *PHI = cast<PHINode>(VD.U ->getUser ());
138
136
return std::make_pair (PHI->getIncomingBlock (*VD.U ), PHI->getParent ());
139
137
}
@@ -229,7 +227,14 @@ class PredicateInfoBuilder {
229
227
void addInfoFor (SmallVectorImpl<Value *> &OpsToRename, Value *Op,
230
228
PredicateBase *PB);
231
229
232
- typedef SmallVectorImpl<ValueDFS> ValueDFSStack;
230
+ struct StackEntry {
231
+ const ValueDFS *V;
232
+ Value *Def = nullptr ;
233
+
234
+ StackEntry (const ValueDFS *V) : V(V) {}
235
+ };
236
+
237
+ using ValueDFSStack = SmallVectorImpl<StackEntry>;
233
238
void convertUsesToDFSOrdered (Value *, SmallVectorImpl<ValueDFS> &);
234
239
Value *materializeStack (unsigned int &, ValueDFSStack &, Value *);
235
240
bool stackIsInScope (const ValueDFSStack &, const ValueDFS &) const ;
@@ -254,7 +259,7 @@ bool PredicateInfoBuilder::stackIsInScope(const ValueDFSStack &Stack,
254
259
// a LN_Last def, we need to pop the stack. We deliberately sort phi uses
255
260
// next to the defs they must go with so that we can know it's time to pop
256
261
// the stack when we hit the end of the phi uses for a given def.
257
- const ValueDFS &Top = Stack.back ();
262
+ const ValueDFS &Top = * Stack.back (). V ;
258
263
if (Top.LocalNum == LN_Last && Top.PInfo ) {
259
264
if (!VDUse.U )
260
265
return false ;
@@ -496,8 +501,8 @@ Value *PredicateInfoBuilder::materializeStack(unsigned int &Counter,
496
501
RenameIter != RenameStack.end (); ++RenameIter) {
497
502
auto *Op =
498
503
RenameIter == RenameStack.begin () ? OrigOp : (RenameIter - 1 )->Def ;
499
- ValueDFS &Result = *RenameIter;
500
- auto *ValInfo = Result.PInfo ;
504
+ StackEntry &Result = *RenameIter;
505
+ auto *ValInfo = Result.V -> PInfo ;
501
506
ValInfo->RenamedOp = (RenameStack.end () - Start) == RenameStack.begin ()
502
507
? OrigOp
503
508
: (RenameStack.end () - Start - 1 )->Def ;
@@ -625,19 +630,18 @@ void PredicateInfoBuilder::renameUses(SmallVectorImpl<Value *> &OpsToRename) {
625
630
// currently and will be considered equal. We could get rid of the
626
631
// stable sort by creating one if we wanted.
627
632
llvm::stable_sort (OrderedUses, Compare);
628
- SmallVector<ValueDFS , 8 > RenameStack;
633
+ SmallVector<StackEntry , 8 > RenameStack;
629
634
// For each use, sorted into dfs order, push values and replaces uses with
630
635
// top of stack, which will represent the reaching def.
631
- for (auto &VD : OrderedUses) {
636
+ for (const ValueDFS &VD : OrderedUses) {
632
637
// We currently do not materialize copy over copy, but we should decide if
633
638
// we want to.
634
- bool PossibleCopy = VD.PInfo != nullptr ;
635
639
if (RenameStack.empty ()) {
636
640
LLVM_DEBUG (dbgs () << " Rename Stack is empty\n " );
637
641
} else {
638
642
LLVM_DEBUG (dbgs () << " Rename Stack Top DFS numbers are ("
639
- << RenameStack.back ().DFSIn << " ,"
640
- << RenameStack.back ().DFSOut << " )\n " );
643
+ << RenameStack.back ().V -> DFSIn << " ,"
644
+ << RenameStack.back ().V -> DFSOut << " )\n " );
641
645
}
642
646
643
647
LLVM_DEBUG (dbgs () << " Current DFS numbers are (" << VD.DFSIn << " ,"
@@ -646,8 +650,8 @@ void PredicateInfoBuilder::renameUses(SmallVectorImpl<Value *> &OpsToRename) {
646
650
// Sync to our current scope.
647
651
popStackUntilDFSScope (RenameStack, VD);
648
652
649
- if (VD.Def || PossibleCopy ) {
650
- RenameStack.push_back (VD);
653
+ if (VD.PInfo ) {
654
+ RenameStack.push_back (& VD);
651
655
continue ;
652
656
}
653
657
@@ -659,7 +663,7 @@ void PredicateInfoBuilder::renameUses(SmallVectorImpl<Value *> &OpsToRename) {
659
663
LLVM_DEBUG (dbgs () << " Skipping execution due to debug counter\n " );
660
664
continue ;
661
665
}
662
- ValueDFS &Result = RenameStack.back ();
666
+ StackEntry &Result = RenameStack.back ();
663
667
664
668
// If the possible copy dominates something, materialize our stack up to
665
669
// this point. This ensures every comparison that affects our operation
0 commit comments