Skip to content

Commit 9ee4906

Browse files
jgu222gfxbot
authored andcommitted
Prepare LiveVars for merging two LVInfo. This change will generate distanceMap first, so that we can use distanceMap to check if an arbitrary use is the kill under ScanAllKills = true, rather than assuming a topDown traversal within a BB.
Change-Id: I0e78daebb3d96bf172fe2bcd3b84112974e0f99b
1 parent 194e257 commit 9ee4906

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

IGC/Compiler/CISACodeGen/LiveVars.cpp

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,13 @@ void LiveVars::HandleVirtRegUse(Value *VL, BasicBlock *MBB,
318318
// scan all the kills in order to replace the right one.
319319
if (ScanAllKills) {
320320
for (unsigned i = 0, e = VRInfo.Kills.size(); i != e; ++i) {
321-
if (VRInfo.Kills[i]->getParent() == MBB){
322-
VRInfo.Kills[i] = MI;
321+
if (VRInfo.Kills[i]->getParent() == MBB) {
322+
Instruction* killInst = VRInfo.Kills[i];
323+
assert(DistanceMap.count(killInst) && DistanceMap.count(MI) &&
324+
"DistanceMap not set up yet.");
325+
if (DistanceMap[killInst] < DistanceMap[MI]) {
326+
VRInfo.Kills[i] = MI;
327+
}
323328
return;
324329
}
325330
}
@@ -413,6 +418,20 @@ void LiveVars::HandleVirtRegDef(Instruction* MI)
413418
VRInfo.Kills.push_back(MI);
414419
}
415420

421+
void LiveVars::initDistance(Function& F)
422+
{
423+
DistanceMap.clear();
424+
425+
for (auto &BB : F)
426+
{
427+
unsigned Dist = 0;
428+
for (auto &II : BB) {
429+
Instruction *MI = &II;
430+
DistanceMap.insert(std::make_pair(MI, Dist++));
431+
}
432+
}
433+
}
434+
416435
void LiveVars::ComputeLiveness(Function* mf, WIAnalysis* wia)
417436
{
418437
releaseMemory();
@@ -421,6 +440,10 @@ void LiveVars::ComputeLiveness(Function* mf, WIAnalysis* wia)
421440

422441
preAllocMemory(*MF);
423442

443+
// First, set up DistanceMap
444+
// save distance map
445+
initDistance(*MF);
446+
424447
analyzePHINodes(*mf);
425448
BasicBlock *Entry = &(*MF->begin());
426449
typedef df_iterator_default_set<BasicBlock*,16> VisitedTy;
@@ -447,14 +470,6 @@ void LiveVars::ComputeLiveness(Function* mf, WIAnalysis* wia)
447470
MarkVirtRegAliveInBlock(getLVInfo(DefV), DefBlk, MBB);
448471
}
449472
}
450-
451-
// save distance map
452-
unsigned Dist = 0;
453-
for (BasicBlock::iterator I = MBB->begin(), E = MBB->end();
454-
I != E; ++I) {
455-
Instruction *MI = &(*I);
456-
DistanceMap.insert(std::make_pair(MI, Dist++));
457-
}
458473
}
459474
}
460475

@@ -582,6 +597,8 @@ void LiveVars::Calculate(Function* mf, WIAnalysis* wia)
582597

583598
preAllocMemory(*MF);
584599

600+
initDistance(*MF);
601+
585602
analyzePHINodes(*mf);
586603

587604
BasicBlock *Entry = &(*MF->begin());
@@ -594,12 +611,10 @@ void LiveVars::Calculate(Function* mf, WIAnalysis* wia)
594611
BasicBlock *MBB = *DFI;
595612

596613
// Loop over all of the instructions, processing them.
597-
unsigned Dist = 0;
598614
for (BasicBlock::iterator I = MBB->begin(), E = MBB->end();
599615
I != E; ++I)
600616
{
601617
Instruction *MI = &(*I);
602-
DistanceMap.insert(std::make_pair(MI, Dist++));
603618

604619
// Unless it is a PHI node. In this case, ONLY process the DEF, not any
605620
// of the uses. They will be handled in other basic blocks.

IGC/Compiler/CISACodeGen/LiveVars.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ class LiveVars{
176176
/// is coming from.
177177
void analyzePHINodes(const llvm::Function &MF);
178178

179+
/// Initialize DistanceMap
180+
void initDistance(llvm::Function& F);
181+
179182
public:
180183

181184
/// Can be called to release memory when the object won't be used anymore.

0 commit comments

Comments
 (0)