Skip to content

Commit 2d39298

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 8cb7405 commit 2d39298

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

visa/HWCaps.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,4 +801,13 @@ bool WARLocalization() const {
801801
bool supportPureBF() const {
802802
return false;
803803
}
804+
805+
// WA to support debugger stepping. Currently only enabled when compiling with
806+
// -debug.
807+
bool needNopAfterCFInstWA() const {
808+
const TARGET_PLATFORM p = getPlatform();
809+
if (p == Xe_DG2 || p == Xe_PVC || p == Xe_PVCXT)
810+
return getOption(vISA_Debug);
811+
return false;
812+
}
804813
// end HW capabilities

visa/Optimizer.h

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

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

visa/SWWA.cpp

Lines changed: 38 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,14 @@ void Optimizer::HWWorkaround() {
37673797
if (inst->isIEEEExceptionTrap())
37683798
expandIEEEExceptionTrap(ii, bb);
37693799

3800+
// Currently skip adding Nop for the predicated backward goto as IP + 1
3801+
// of the goto might need to be the join instruction.
3802+
const bool isPredicatedBwdGoto = inst->opcode() == G4_goto &&
3803+
inst->getPredicate() && inst->asCFInst()->isBackward();
3804+
if (inst->isCFInst() && !isPredicatedBwdGoto &&
3805+
builder.needNopAfterCFInstWA())
3806+
insertNopAfterCFInst(ib, ii);
3807+
37703808
ii++;
37713809
}
37723810
}

0 commit comments

Comments
 (0)