Skip to content

Commit 2b6e627

Browse files
zuban32sys_zuul
authored andcommitted
Revert new-reg-per-function behavior in VC RA
Change-Id: Ie6483a09bce2e37bf9b17693a63bdbce45baca0b
1 parent bcae074 commit 2b6e627

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/GenXLiveness.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,22 +1629,26 @@ void LiveRange::sortAndMerge() {
16291629
*
16301630
*/
16311631
void LiveRange::prepareFuncs(FunctionGroupAnalysis *FGA) {
1632-
for (auto &val : getValues()) {
1633-
auto Inst = dyn_cast<Instruction>(val.getValue());
1632+
// Funcs must be empty as it's being filled immediately
1633+
// before it's required in VisaRegAlloc (because most of the passes
1634+
// invalidate this set) once for every LR
1635+
assert(Funcs.empty());
1636+
for (auto &Val : getValues()) {
1637+
auto Inst = dyn_cast<Instruction>(Val.getValue());
16341638
Function *DefFunc = nullptr;
16351639
if (Inst && Inst->getParent())
16361640
DefFunc = Inst->getFunction();
1637-
else if (auto Arg = dyn_cast<Argument>(val.getValue()))
1641+
else if (auto Arg = dyn_cast<Argument>(Val.getValue()))
16381642
DefFunc = Arg->getParent();
16391643

16401644
if (DefFunc)
16411645
Funcs.insert(FGA->getSubGroup(DefFunc)
16421646
? FGA->getSubGroup(DefFunc)->getHead()
16431647
: FGA->getGroup(DefFunc)->getHead());
16441648

1645-
for (auto U : val.getValue()->users())
1646-
if (Instruction *userInst = dyn_cast<Instruction>(U)) {
1647-
auto F = userInst->getFunction();
1649+
for (auto U : Val.getValue()->users())
1650+
if (Instruction *UserInst = dyn_cast<Instruction>(U)) {
1651+
auto F = UserInst->getFunction();
16481652
Funcs.insert(FGA->getSubGroup(F) ? FGA->getSubGroup(F)->getHead()
16491653
: FGA->getGroup(F)->getHead());
16501654
}

IGC/VectorCompiler/lib/GenXCodeGen/GenXVisaRegAlloc.cpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -317,17 +317,12 @@ void GenXVisaRegAlloc::extraCoalescing()
317317
/***********************************************************************
318318
* allocReg : allocate a register for a LiveRange
319319
*/
320-
void GenXVisaRegAlloc::allocReg(LiveRange *LR)
321-
{
320+
void GenXVisaRegAlloc::allocReg(LiveRange *LR) {
322321
if (LR->value_empty())
323322
return;
324323
if (LR->getCategory() >= RegCategory::NUMREALCATEGORIES)
325324
return; // don't allocate register to EM or RM value
326-
LLVM_DEBUG(
327-
dbgs() << "Allocating ";
328-
LR->print(dbgs());
329-
dbgs() << "\n"
330-
);
325+
LLVM_DEBUG(dbgs() << "Allocating "; LR->print(dbgs()); dbgs() << "\n");
331326
SimpleValue V = *LR->value_begin();
332327
Type *Ty = V.getType();
333328
if (auto GV = dyn_cast<GlobalVariable>(V.getValue()))
@@ -336,28 +331,29 @@ void GenXVisaRegAlloc::allocReg(LiveRange *LR)
336331
assert(!Ty->isVoidTy());
337332
if (LR->Category == RegCategory::PREDICATE) {
338333
VectorType *VT = dyn_cast<VectorType>(Ty);
339-
assert((!VT || genx::exactLog2(VT->getNumElements()) >= 0) && "invalid predicate width");
334+
assert((!VT || genx::exactLog2(VT->getNumElements()) >= 0) &&
335+
"invalid predicate width");
340336
(void)VT;
341337
}
342338
// Allocate the register, also setting the alignment.
339+
Reg *NewReg =
340+
createReg(LR->Category, Ty, DONTCARESIGNED, LR->getLogAlignment());
343341
// Assign to the values. If any value is an input arg, ensure the register
344342
// gets its type, to avoid needing an alias for an input arg.
345-
for (auto &F : LR->Funcs) {
346-
Reg *NewReg =
347-
createReg(LR->Category, Ty, DONTCARESIGNED, LR->getLogAlignment());
348-
if (RegMap.count(F) > 0) {
349-
for (LiveRange::value_iterator vi = LR->value_begin(),
350-
ve = LR->value_end();
351-
vi != ve; ++vi) {
352-
LLVM_DEBUG(dbgs() << "Allocating reg " << NewReg->Num << " to "
343+
for (LiveRange::value_iterator vi = LR->value_begin(), ve = LR->value_end();
344+
vi != ve; ++vi) {
345+
for (auto &F : LR->Funcs) {
346+
if (FGA->getGroup(F) == FG) {
347+
assert(RegMap.count(F) > 0);
348+
LLVM_DEBUG(dbgs() << "Allocating reg " << NewReg->Num << " for "
353349
<< *(vi->getValue()) << " in func " << F->getName()
354-
<< "\n";);
350+
<< "\n");
355351
assert(RegMap.at(F).find(*vi) == RegMap.at(F).end());
356352
RegMap.at(F)[*vi] = NewReg;
357-
if (isa<Argument>(vi->getValue()))
358-
NewReg->Ty = vi->getType();
359353
}
360354
}
355+
if (isa<Argument>(vi->getValue()))
356+
NewReg->Ty = vi->getType();
361357
}
362358
}
363359

0 commit comments

Comments
 (0)