Skip to content

Commit 502f555

Browse files
petechouigcbot
authored andcommitted
Reland the WA that emits a NOP after branch instruction to support single stepping in debugger.
The WA is enabled only when compiling with -O0 currently.
1 parent e5bc891 commit 502f555

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

IGC/Compiler/CISACodeGen/CISABuilder.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5102,6 +5102,12 @@ namespace IGC
51025102
if (IGC_IS_FLAG_ENABLED(deadLoopForFloatException)) {
51035103
SaveOption(vISA_AddIEEEExceptionTrap, true);
51045104
}
5105+
5106+
// WA to support single stepping in debugger. Currently only enabled it
5107+
// when compiling with -O0.
5108+
if (isOptDisabled && m_program->m_Platform->WaAddNopAfterBranchInst()) {
5109+
SaveOption(vISA_GenerateNopAfterCFInst, true);
5110+
}
51055111
} // InitVISABuilderOptions
51065112

51075113
// Get a unqiue label for inline asm instruction blocks at the module level.

IGC/Compiler/CISACodeGen/Platform.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,5 +1490,18 @@ unsigned int roundUpTgsmSize(DWORD size) const
14901490
return iSTD::RoundPower2(size) * blockSize;
14911491
}
14921492

1493+
bool WaAddNopAfterBranchInst() const
1494+
{
1495+
if (m_platformInfo.eProductFamily == IGFX_PVC)
1496+
return true;
1497+
1498+
if (m_platformInfo.eProductFamily == IGFX_DG2 &&
1499+
(GFX_IS_DG2_G11_CONFIG(m_platformInfo.usDeviceID) ||
1500+
GFX_IS_DG2_G12_CONFIG(m_platformInfo.usDeviceID)))
1501+
return true;
1502+
1503+
return false;
1504+
}
1505+
14931506
};
14941507
}//namespace IGC

visa/Optimizer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ class Optimizer {
260260
void applyNamedBarrierWA(INST_LIST_ITER it, G4_BB *bb);
261261
void insertIEEEExceptionTrap();
262262
void expandIEEEExceptionTrap(INST_LIST_ITER it, G4_BB *bb);
263+
void insertNopAfterCFInst(BB_LIST_ITER ib, INST_LIST_ITER it);
263264

264265
typedef std::vector<vISA::G4_INST *> InstListType;
265266
// create instruction sequence to calculate call offset from ip

visa/SWWA.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3337,6 +3337,36 @@ void Optimizer::expandIEEEExceptionTrap(INST_LIST_ITER it, G4_BB *bb) {
33373337
*it = restoreFlag;
33383338
}
33393339

3340+
void Optimizer::insertNopAfterCFInst(BB_LIST_ITER ib, INST_LIST_ITER ii) {
3341+
// If the CF inst is not the last inst of current BB, simply insert
3342+
// a nop after it. Otherwise, insert a dummy BB to hold a nop between
3343+
// the current BB and the fall-through BB.
3344+
G4_BB *bb = *ib;
3345+
G4_INST *inst = *ii;
3346+
if (inst != bb->back()) {
3347+
bb->insertAfter(ii, builder.createNop(InstOpt_NoOpt));
3348+
} else {
3349+
G4_BB *dummyBB = fg.createNewBBWithLabel("CFInstWA_BB");
3350+
dummyBB->push_back(builder.createNop(InstOpt_NoOpt));
3351+
BB_LIST_ITER nextBI = std::next(ib);
3352+
fg.insert(nextBI, dummyBB);
3353+
// Update the pred/succ edges accordingly.
3354+
bb->setPhysicalSucc(dummyBB);
3355+
dummyBB->setPhysicalPred(bb);
3356+
if (nextBI != fg.end()) {
3357+
G4_BB *nextBB = *nextBI;
3358+
dummyBB->setPhysicalSucc(nextBB);
3359+
nextBB->setPhysicalPred(dummyBB);
3360+
if (std::any_of(bb->Succs.begin(), bb->Succs.end(),
3361+
[=](G4_BB *succ) { return succ == nextBB; } )) {
3362+
fg.removePredSuccEdges(bb, nextBB);
3363+
fg.addPredSuccEdges(bb, dummyBB);
3364+
fg.addPredSuccEdges(dummyBB, nextBB);
3365+
}
3366+
}
3367+
}
3368+
}
3369+
33403370
// For a subroutine, insert a dummy move with {Switch} option immediately
33413371
// before the first non-label instruction in BB. Otherwie, for a following
33423372
// basic block, insert a dummy move before *any* instruction to ensure that
@@ -3767,6 +3797,9 @@ void Optimizer::HWWorkaround() {
37673797
if (inst->isIEEEExceptionTrap())
37683798
expandIEEEExceptionTrap(ii, bb);
37693799

3800+
if (inst->isCFInst() && builder.getOption(vISA_GenerateNopAfterCFInst))
3801+
insertNopAfterCFInst(ib, ii);
3802+
37703803
ii++;
37713804
}
37723805
}

visa/include/VISAOptionsDefs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,8 @@ DEF_VISA_OPTION(vISA_noIndirectSrcForCompressedInstWA, ET_BOOL,
641641
DEF_VISA_OPTION(vISA_GenerateDebugInfo, ET_BOOL, "-generateDebugInfo", UNUSED,
642642
false)
643643
DEF_VISA_OPTION(vISA_setStartBreakPoint, ET_BOOL, "-setstartbp", UNUSED, false)
644+
DEF_VISA_OPTION(vISA_GenerateNopAfterCFInst, ET_BOOL,
645+
"-generateNopAfterCFInst", UNUSED, false)
644646
DEF_VISA_OPTION(vISA_InsertHashMovs, ET_BOOL, NULLSTR, UNUSED, false)
645647
DEF_VISA_OPTION(vISA_InsertDummyMovForHWRSWA, ET_BOOL, "-insertRSDummyMov",
646648
UNUSED, false)

0 commit comments

Comments
 (0)