@@ -33,7 +33,7 @@ using namespace llvm;
33
33
using namespace IGC ;
34
34
35
35
AllocationLivenessAnalyzer::LivenessData
36
- AllocationLivenessAnalyzer::ProcessInstruction (Instruction *I, DominatorTree &DT, LoopInfo &LI) {
36
+ AllocationLivenessAnalyzer::ProcessInstruction (Instruction *I, DominatorTree &DT, LoopInfo &LI, bool includeOrigin ) {
37
37
// static allocas are usually going to be in the entry block
38
38
// that's a practice, but we only care about the last block that dominates all uses
39
39
BasicBlock *commonDominator = nullptr ;
@@ -73,6 +73,10 @@ AllocationLivenessAnalyzer::ProcessInstruction(Instruction *I, DominatorTree &DT
73
73
74
74
switch (II->getOpcode ()) {
75
75
case Instruction::PHI:
76
+
77
+ for (auto *bb : cast<PHINode>(II)->blocks ())
78
+ commonDominator = DT.findNearestCommonDominator (commonDominator, bb);
79
+ [[fallthrough]];
76
80
case Instruction::GetElementPtr:
77
81
case Instruction::BitCast:
78
82
case Instruction::Select:
@@ -93,14 +97,9 @@ AllocationLivenessAnalyzer::ProcessInstruction(Instruction *I, DominatorTree &DT
93
97
}
94
98
}
95
99
} break ;
96
- case Instruction::Call: {
97
- auto *callI = cast<CallInst>(II);
98
- if (!callI->doesNotCapture (use->getOperandNo ()))
99
- lifetimeLeakingUsers.insert (II);
100
-
101
- if (II->getType ()->isPointerTy ())
102
- addUsesFn (II->uses ());
103
- } break ;
100
+ case Instruction::Call:
101
+ implementCallSpecificBehavior (cast<CallInst>(II), use, worklist, allUsers, lifetimeLeakingUsers);
102
+ break ;
104
103
case Instruction::Load:
105
104
if (II->getType ()->isPointerTy ())
106
105
addUsesFn (II->uses ());
@@ -111,6 +110,9 @@ AllocationLivenessAnalyzer::ProcessInstruction(Instruction *I, DominatorTree &DT
111
110
}
112
111
}
113
112
113
+ if (includeOrigin)
114
+ allUsers.insert (I);
115
+
114
116
return LivenessData (I, std::move (allUsers), LI, DT, commonDominator, std::move (lifetimeLeakingUsers));
115
117
}
116
118
@@ -120,6 +122,20 @@ void AllocationLivenessAnalyzer::getAnalysisUsage(llvm::AnalysisUsage &AU) const
120
122
getAdditionalAnalysisUsage (AU);
121
123
}
122
124
125
+ void AllocationLivenessAnalyzer::implementCallSpecificBehavior (CallInst *callI, Use* use, SmallVector<Use *> &worklist,
126
+ SetVector<Instruction *> &allUsers,
127
+ SetVector<Instruction *> &lifetimeLeakingUsers) {
128
+
129
+ if (!callI->doesNotCapture (use->getOperandNo ()))
130
+ lifetimeLeakingUsers.insert (callI);
131
+
132
+ if (callI->getType ()->isPointerTy ()) {
133
+
134
+ for (auto &use : callI->uses ())
135
+ worklist.push_back (&use);
136
+ }
137
+ }
138
+
123
139
template <typename range>
124
140
static inline void doWorkLoop (SmallVector<BasicBlock *> &worklist, DenseSet<BasicBlock *> &bbSet1,
125
141
DenseSet<BasicBlock *> &bbSet2, std::function<range(BasicBlock *)> iterate,
0 commit comments