Skip to content

Commit 5e5823c

Browse files
gang chenigcbot
authored andcommitted
Improve LiveVar time by changing data-structure
and check liveThru set first
1 parent 884ed92 commit 5e5823c

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

IGC/Compiler/CISACodeGen/LiveVars.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ LiveVars::LVInfo::findKill(const BasicBlock* MBB) const {
7575

7676
void LiveVars::LVInfo::print(raw_ostream& OS) const {
7777
OS << " Alive in blocks: ";
78-
for (SmallPtrSet<BasicBlock*, 8>::iterator I = AliveBlocks.begin(),
79-
E = AliveBlocks.end(); I != E; ++I) {
78+
for (auto I = AliveBlocks.begin(), E = AliveBlocks.end(); I != E; ++I) {
8079
(*I)->print(OS);
8180
OS << ", ";
8281
}
@@ -162,8 +161,8 @@ void LiveVars::dump(Function* F)
162161
OS << "\n{";
163162
V->print(OS);
164163
OS << "\n Alive in blocks: ";
165-
for (SmallPtrSet<BasicBlock*, 8>::iterator I = LVI->AliveBlocks.begin(),
166-
E = LVI->AliveBlocks.end(); I != E; ++I) {
164+
for (auto I = LVI->AliveBlocks.begin(), E = LVI->AliveBlocks.end();
165+
I != E; ++I) {
167166
BasicBlock* BB = *I;
168167
if (BBIds.count(BB) > 0)
169168
{
@@ -236,6 +235,9 @@ void LiveVars::MarkVirtRegAliveInBlock(LiveVars::LVInfo& VRInfo,
236235
BasicBlock* MBB,
237236
std::vector<BasicBlock*>& WorkList) {
238237

238+
if (VRInfo.AliveBlocks.count(MBB))
239+
return; // We already know the block is live
240+
239241
// Check to see if this basic block is one of the killing blocks. If so,
240242
// remove it.
241243
for (unsigned i = 0, e = VRInfo.Kills.size(); i != e; ++i)
@@ -249,9 +251,6 @@ void LiveVars::MarkVirtRegAliveInBlock(LiveVars::LVInfo& VRInfo,
249251
if (MBB == DefBlock)
250252
return; // Terminate recursion
251253

252-
if (VRInfo.AliveBlocks.count(MBB))
253-
return; // We already know the block is live
254-
255254
// Mark the variable known alive in this bb
256255
VRInfo.AliveBlocks.insert(MBB);
257256

@@ -293,7 +292,6 @@ void LiveVars::MarkVirtRegAliveInBlock(LiveVars::LVInfo& VRInfo,
293292
BasicBlock* MBB) {
294293
std::vector<BasicBlock*> WorkList;
295294
MarkVirtRegAliveInBlock(VRInfo, DefBlock, MBB, WorkList);
296-
297295
while (!WorkList.empty()) {
298296
BasicBlock* Pred = WorkList.back();
299297
WorkList.pop_back();

IGC/Compiler/CISACodeGen/LiveVars.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ namespace IGC
113113
struct LVInfo {
114114
/// AliveBlocks - Set of blocks in which this value is alive completely
115115
/// through.
116-
llvm::SmallPtrSet<llvm::BasicBlock*, 16> AliveBlocks;
116+
std::set<llvm::BasicBlock*> AliveBlocks;
117117

118118
/// NumUses - Number of uses of this register across the entire function.
119119
///

IGC/Compiler/CISACodeGen/LivenessAnalysis.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ void LivenessAnalysis::calculate(Function* F)
246246
defBB = defInst->getParent();
247247
}
248248

249-
for (SmallPtrSet<BasicBlock*, 8>::iterator II = lvi->AliveBlocks.begin(),
250-
IE = lvi->AliveBlocks.end();
249+
for (auto II = lvi->AliveBlocks.begin(), IE = lvi->AliveBlocks.end();
251250
II != IE; ++II)
252251
{
253252
BasicBlock* BB = *II;

0 commit comments

Comments
 (0)