Skip to content

Commit dc026d1

Browse files
jaladreipsigcbot
authored andcommitted
Internal performance refinements
Improvements to internal analysis and data handling to reduce overhead.
1 parent 51cd032 commit dc026d1

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

IGC/AdaptorCommon/LivenessUtils/AllocationLivenessAnalyzer.cpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ using namespace llvm;
3333
using namespace IGC;
3434

3535
AllocationLivenessAnalyzer::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+
123139
template <typename range>
124140
static inline void doWorkLoop(SmallVector<BasicBlock *> &worklist, DenseSet<BasicBlock *> &bbSet1,
125141
DenseSet<BasicBlock *> &bbSet2, std::function<range(BasicBlock *)> iterate,

IGC/AdaptorCommon/LivenessUtils/AllocationLivenessAnalyzer.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ SPDX-License-Identifier: MIT
1515

1616
namespace llvm {
1717
class BasicBlock;
18+
class CallInst;
1819
class DominatorTree;
1920
class Instruction;
2021
class LoopInfo;
22+
class Use;
2123
} // namespace llvm
2224

2325
namespace IGC {
@@ -52,10 +54,15 @@ class AllocationLivenessAnalyzer : public llvm::FunctionPass {
5254
AllocationLivenessAnalyzer(char &pid) : llvm::FunctionPass(pid) {}
5355

5456
protected:
55-
LivenessData ProcessInstruction(llvm::Instruction *I, llvm::DominatorTree &DT, llvm::LoopInfo &LI);
57+
LivenessData ProcessInstruction(llvm::Instruction *I, llvm::DominatorTree &DT, llvm::LoopInfo &LI,
58+
bool includeOrigin = false);
5659

5760
void getAnalysisUsage(llvm::AnalysisUsage &AU) const override;
5861
virtual void getAdditionalAnalysisUsage(llvm::AnalysisUsage &AU) const = 0;
62+
virtual void implementCallSpecificBehavior(llvm::CallInst *I, llvm::Use *use,
63+
llvm::SmallVector<llvm::Use *> &worklist,
64+
llvm::SetVector<llvm::Instruction *> &allUsers,
65+
llvm::SetVector<llvm::Instruction *> &lifetimeLeakingUsers);
5966
};
6067

6168
namespace Provenance {

0 commit comments

Comments
 (0)