@@ -33,7 +33,7 @@ using namespace llvm;
3333using namespace IGC ;
3434
3535AllocationLivenessAnalyzer::LivenessData
36- AllocationLivenessAnalyzer::ProcessInstruction (Instruction *I, DominatorTree &DT, LoopInfo &LI) {
36+ AllocationLivenessAnalyzer::ProcessInstruction (Instruction *I, DominatorTree &DT, LoopInfo &LI, bool includeOrigin ) {
3737 // static allocas are usually going to be in the entry block
3838 // that's a practice, but we only care about the last block that dominates all uses
3939 BasicBlock *commonDominator = nullptr ;
@@ -73,6 +73,10 @@ AllocationLivenessAnalyzer::ProcessInstruction(Instruction *I, DominatorTree &DT
7373
7474 switch (II->getOpcode ()) {
7575 case Instruction::PHI:
76+
77+ for (auto *bb : cast<PHINode>(II)->blocks ())
78+ commonDominator = DT.findNearestCommonDominator (commonDominator, bb);
79+ [[fallthrough]];
7680 case Instruction::GetElementPtr:
7781 case Instruction::BitCast:
7882 case Instruction::Select:
@@ -93,14 +97,9 @@ AllocationLivenessAnalyzer::ProcessInstruction(Instruction *I, DominatorTree &DT
9397 }
9498 }
9599 } 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 ;
104103 case Instruction::Load:
105104 if (II->getType ()->isPointerTy ())
106105 addUsesFn (II->uses ());
@@ -111,6 +110,9 @@ AllocationLivenessAnalyzer::ProcessInstruction(Instruction *I, DominatorTree &DT
111110 }
112111 }
113112
113+ if (includeOrigin)
114+ allUsers.insert (I);
115+
114116 return LivenessData (I, std::move (allUsers), LI, DT, commonDominator, std::move (lifetimeLeakingUsers));
115117}
116118
@@ -120,6 +122,20 @@ void AllocationLivenessAnalyzer::getAnalysisUsage(llvm::AnalysisUsage &AU) const
120122 getAdditionalAnalysisUsage (AU);
121123}
122124
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+
123139template <typename range>
124140static inline void doWorkLoop (SmallVector<BasicBlock *> &worklist, DenseSet<BasicBlock *> &bbSet1,
125141 DenseSet<BasicBlock *> &bbSet2, std::function<range(BasicBlock *)> iterate,
0 commit comments