Skip to content

Commit b0a526b

Browse files
pratikasharigcbot
authored andcommitted
Emit src file line with RPE
When -emitsrclinetorpe option is passed, VISA attempts to read src line from debug location. If file/line was found, it's emitted as a comment for easy reference. When RPE dump is enabled and -asmOutput is specified, RPE dump is now written to a file in shader dump with .rpe extension.
1 parent 2e80890 commit b0a526b

File tree

4 files changed

+43
-15
lines changed

4 files changed

+43
-15
lines changed

visa/G4_BB.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,24 @@ void G4_BB::emitInstructionSourceLineMapping(std::ostream &output,
273273
// (i.e., debugging) only.
274274
static const char *prevFilename = nullptr;
275275
static int prevSrcLineNo = 0;
276+
static bool resetOnEntry = false;
276277

277278
const char *curFilename = (*it)->getSrcFilename();
278279
int curSrcLineNo = (*it)->getLineNo();
279280

280281
// Reset source locations for each function so that we will always emit them
281282
// at function entry.
282-
if (getParent().getEntryBB() == this) {
283+
if (getParent().getEntryBB() == this && !resetOnEntry) {
283284
prevFilename = nullptr;
284285
prevSrcLineNo = 0;
286+
// First time we process entry BB, we must reset state
287+
resetOnEntry = true;
288+
}
289+
290+
if (getParent().getEntryBB() != this) {
291+
// Once we see some other BB, we should reset state only when we see entry
292+
// again next time.
293+
resetOnEntry = false;
285294
}
286295

287296
if ((*it)->isLabel())

visa/GraphColor.cpp

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11396,8 +11396,9 @@ int GlobalRA::coloringRegAlloc() {
1139611396
GraphColor coloring(liveAnalysis, false, forceSpill);
1139711397

1139811398
if (builder.getOption(vISA_dumpRPE) && iterationNo == 0 && !rematDone) {
11399+
coloring.dumpRPEToFile();
1139911400
// dump pressure the first time we enter global RA
11400-
coloring.dumpRegisterPressure();
11401+
coloring.dumpRegisterPressure(std::cerr);
1140111402
}
1140211403

1140311404
// Get the size of register which are reserved for spill
@@ -11648,23 +11649,37 @@ void GlobalRA::insertPhyRegDecls() {
1164811649
VISA_DEBUG(std::cout << "Local RA used " << numGRFsUsed << " GRFs\n");
1164911650
}
1165011651

11651-
void GraphColor::dumpRegisterPressure() {
11652+
void GraphColor::dumpRPEToFile() {
11653+
// Dump RPE output to file if asmName is set
11654+
auto *asmOutput = builder.getOptions()->getOptionCstr(VISA_AsmFileName);
11655+
if (asmOutput) {
11656+
std::string FN(asmOutput);
11657+
FN += ".rpe";
11658+
std::ofstream OF;
11659+
OF.open(FN, std::ofstream::out);
11660+
dumpRegisterPressure(OF);
11661+
OF.close();
11662+
}
11663+
}
11664+
11665+
void GraphColor::dumpRegisterPressure(std::ostream &OS) {
1165211666
RPE rpe(gra, &liveAnalysis);
1165311667
uint32_t max = 0;
1165411668
std::vector<G4_INST *> maxInst;
1165511669
rpe.run();
1165611670

1165711671
for (auto bb : builder.kernel.fg) {
11658-
std::cerr << "BB " << bb->getId() << ": (Pred: ";
11672+
OS << "BB " << bb->getId() << ": (Pred: ";
1165911673
for (auto pred : bb->Preds) {
11660-
std::cerr << pred->getId() << ",";
11674+
OS << pred->getId() << ",";
1166111675
}
11662-
std::cerr << " Succ: ";
11676+
OS << " Succ: ";
1166311677
for (auto succ : bb->Succs) {
11664-
std::cerr << succ->getId() << ",";
11678+
OS << succ->getId() << ",";
1166511679
}
11666-
std::cerr << ")\n";
11667-
for (auto inst : *bb) {
11680+
OS << ")\n";
11681+
for (auto instIt = bb->begin(); instIt != bb->end(); ++instIt) {
11682+
auto *inst = *instIt;
1166811683
uint32_t pressure = rpe.getRegisterPressure(inst);
1166911684
if (pressure > max) {
1167011685
max = pressure;
@@ -11674,14 +11689,15 @@ void GraphColor::dumpRegisterPressure() {
1167411689
maxInst.push_back(inst);
1167511690
}
1167611691

11677-
std::cerr << "[" << pressure << "] ";
11678-
inst->dump();
11692+
if (kernel.getOption(vISA_EmitSrcFileLineToRPE))
11693+
bb->emitInstructionSourceLineMapping(OS, instIt);
11694+
OS << "[" << pressure << "] ";
11695+
inst->print(OS);
1167911696
}
1168011697
}
11681-
std::cerr << "max pressure: " << max << ", " << maxInst.size()
11682-
<< " inst(s)\n";
11698+
OS << "max pressure: " << max << ", " << maxInst.size() << " inst(s)\n";
1168311699
for (auto inst : maxInst) {
11684-
inst->dump();
11700+
inst->print(OS);
1168511701
}
1168611702
}
1168711703

visa/GraphColor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,8 @@ class GraphColor {
11861186
void addFlagSaveRestoreCode();
11871187
void getSaveRestoreRegister();
11881188
void getCallerSaveRegisters();
1189-
void dumpRegisterPressure();
1189+
void dumpRegisterPressure(std::ostream&);
1190+
void dumpRPEToFile();
11901191
GlobalRA &getGRA() { return gra; }
11911192
G4_SrcRegRegion *getScratchSurface() const;
11921193
unsigned int getNumVars() const { return numVar; }

visa/include/VISAOptionsDefs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ DEF_VISA_OPTION(vISA_storeCE, ET_BOOL, "-storeCE", UNUSED, false)
6767
// debugging
6868
DEF_VISA_OPTION(vISA_UseFriendlyNameInDbg, ET_BOOL, "-useFriendlyNameInDbg",
6969
UNUSED, false)
70+
DEF_VISA_OPTION(vISA_EmitSrcFileLineToRPE, ET_BOOL, "-emitsrclinetorpe",
71+
"makes finalizer emit src line as comment to RPE dump", false)
7072
DEF_VISA_OPTION(vISA_addSWSBInfo, ET_BOOL, "-addSWSBInfo", UNUSED, true)
7173
DEF_VISA_OPTION(vISA_DumpRAIntfGraph, ET_BOOL, "-dumpintf", UNUSED, false)
7274
DEF_VISA_OPTION(vISA_dumpRAMetadata, ET_BOOL_TRUE, "-dumpRAMetadata",

0 commit comments

Comments
 (0)