diff --git a/visa/G4_BB.cpp b/visa/G4_BB.cpp index 0253419448be..24333af4d0ef 100644 --- a/visa/G4_BB.cpp +++ b/visa/G4_BB.cpp @@ -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()) diff --git a/visa/GraphColor.cpp b/visa/GraphColor.cpp index fda91c5ff167..03d5c6760881 100644 --- a/visa/GraphColor.cpp +++ b/visa/GraphColor.cpp @@ -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 @@ -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 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; @@ -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); } } diff --git a/visa/GraphColor.h b/visa/GraphColor.h index c13d3f4bfe27..c6b2071f889e 100644 --- a/visa/GraphColor.h +++ b/visa/GraphColor.h @@ -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; } diff --git a/visa/include/VISAOptionsDefs.h b/visa/include/VISAOptionsDefs.h index b5412946352a..a3e5b74740bd 100644 --- a/visa/include/VISAOptionsDefs.h +++ b/visa/include/VISAOptionsDefs.h @@ -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",