Skip to content

Commit

Permalink
Emit src file line with RPE
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pratikashar authored and igcbot committed Dec 10, 2024
1 parent 2e80890 commit b0a526b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
11 changes: 10 additions & 1 deletion visa/G4_BB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,24 @@ void G4_BB::emitInstructionSourceLineMapping(std::ostream &output,
// (i.e., debugging) only.
static const char *prevFilename = nullptr;
static int prevSrcLineNo = 0;
static bool resetOnEntry = false;

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

// Reset source locations for each function so that we will always emit them
// at function entry.
if (getParent().getEntryBB() == this) {
if (getParent().getEntryBB() == this && !resetOnEntry) {
prevFilename = nullptr;
prevSrcLineNo = 0;
// First time we process entry BB, we must reset state
resetOnEntry = true;
}

if (getParent().getEntryBB() != this) {
// Once we see some other BB, we should reset state only when we see entry
// again next time.
resetOnEntry = false;
}

if ((*it)->isLabel())
Expand Down
42 changes: 29 additions & 13 deletions visa/GraphColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11396,8 +11396,9 @@ int GlobalRA::coloringRegAlloc() {
GraphColor coloring(liveAnalysis, false, forceSpill);

if (builder.getOption(vISA_dumpRPE) && iterationNo == 0 && !rematDone) {
coloring.dumpRPEToFile();
// dump pressure the first time we enter global RA
coloring.dumpRegisterPressure();
coloring.dumpRegisterPressure(std::cerr);
}

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

void GraphColor::dumpRegisterPressure() {
void GraphColor::dumpRPEToFile() {
// Dump RPE output to file if asmName is set
auto *asmOutput = builder.getOptions()->getOptionCstr(VISA_AsmFileName);
if (asmOutput) {
std::string FN(asmOutput);
FN += ".rpe";
std::ofstream OF;
OF.open(FN, std::ofstream::out);
dumpRegisterPressure(OF);
OF.close();
}
}

void GraphColor::dumpRegisterPressure(std::ostream &OS) {
RPE rpe(gra, &liveAnalysis);
uint32_t max = 0;
std::vector<G4_INST *> maxInst;
rpe.run();

for (auto bb : builder.kernel.fg) {
std::cerr << "BB " << bb->getId() << ": (Pred: ";
OS << "BB " << bb->getId() << ": (Pred: ";
for (auto pred : bb->Preds) {
std::cerr << pred->getId() << ",";
OS << pred->getId() << ",";
}
std::cerr << " Succ: ";
OS << " Succ: ";
for (auto succ : bb->Succs) {
std::cerr << succ->getId() << ",";
OS << succ->getId() << ",";
}
std::cerr << ")\n";
for (auto inst : *bb) {
OS << ")\n";
for (auto instIt = bb->begin(); instIt != bb->end(); ++instIt) {
auto *inst = *instIt;
uint32_t pressure = rpe.getRegisterPressure(inst);
if (pressure > max) {
max = pressure;
Expand All @@ -11674,14 +11689,15 @@ void GraphColor::dumpRegisterPressure() {
maxInst.push_back(inst);
}

std::cerr << "[" << pressure << "] ";
inst->dump();
if (kernel.getOption(vISA_EmitSrcFileLineToRPE))
bb->emitInstructionSourceLineMapping(OS, instIt);
OS << "[" << pressure << "] ";
inst->print(OS);
}
}
std::cerr << "max pressure: " << max << ", " << maxInst.size()
<< " inst(s)\n";
OS << "max pressure: " << max << ", " << maxInst.size() << " inst(s)\n";
for (auto inst : maxInst) {
inst->dump();
inst->print(OS);
}
}

Expand Down
3 changes: 2 additions & 1 deletion visa/GraphColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,8 @@ class GraphColor {
void addFlagSaveRestoreCode();
void getSaveRestoreRegister();
void getCallerSaveRegisters();
void dumpRegisterPressure();
void dumpRegisterPressure(std::ostream&);
void dumpRPEToFile();
GlobalRA &getGRA() { return gra; }
G4_SrcRegRegion *getScratchSurface() const;
unsigned int getNumVars() const { return numVar; }
Expand Down
2 changes: 2 additions & 0 deletions visa/include/VISAOptionsDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ DEF_VISA_OPTION(vISA_storeCE, ET_BOOL, "-storeCE", UNUSED, false)
// debugging
DEF_VISA_OPTION(vISA_UseFriendlyNameInDbg, ET_BOOL, "-useFriendlyNameInDbg",
UNUSED, false)
DEF_VISA_OPTION(vISA_EmitSrcFileLineToRPE, ET_BOOL, "-emitsrclinetorpe",
"makes finalizer emit src line as comment to RPE dump", false)
DEF_VISA_OPTION(vISA_addSWSBInfo, ET_BOOL, "-addSWSBInfo", UNUSED, true)
DEF_VISA_OPTION(vISA_DumpRAIntfGraph, ET_BOOL, "-dumpintf", UNUSED, false)
DEF_VISA_OPTION(vISA_dumpRAMetadata, ET_BOOL_TRUE, "-dumpRAMetadata",
Expand Down

0 comments on commit b0a526b

Please sign in to comment.