Skip to content

Commit 7d4e0cc

Browse files
aparshin-inteligcbot
authored andcommitted
debug info fixes for VC
1 parent 8de4b1c commit 7d4e0cc

File tree

11 files changed

+216
-109
lines changed

11 files changed

+216
-109
lines changed

IGC/DebugInfo/VISADebugEmitter.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5353
#include "Probe/Assertion.h"
5454
#include "secure_mem.h"
5555

56+
#define DEBUG_TYPE "GENX_DEBUG_INFO"
57+
5658
using namespace llvm;
5759
using namespace IGC;
5860

@@ -157,8 +159,8 @@ std::vector<char> DebugEmitter::Finalize(bool finalize, DbgDecoder* decodedDbg)
157159
// Emit src line mapping directly instead of
158160
// relying on dbgmerge. elf generated will have
159161
// text section and debug_line sections populated.
160-
auto& VISAIndexToInst = m_pVISAModule->VISAIndexToInst;
161-
auto& VISAIndexToSize = m_pVISAModule->VISAIndexToSize;
162+
const auto& VISAIndexToInst = m_pVISAModule->VISAIndexToInst;
163+
const auto& VISAIndexToSize = m_pVISAModule->VISAIndexToSize;
162164
std::vector<std::pair<unsigned int, unsigned int>> GenISAToVISAIndex;
163165
unsigned int subEnd = m_pVISAModule->GetCurrentVISAId();
164166
unsigned int prevLastGenOff = lastGenOff;
@@ -328,6 +330,8 @@ std::vector<char> DebugEmitter::Finalize(bool finalize, DbgDecoder* decodedDbg)
328330
if (m_pVISAModule->isDirectElfInput)
329331
setElfType(is64Bit, Result.data());
330332

333+
LLVM_DEBUG(dbgs() << "Finalized Visa Module:\n");
334+
LLVM_DEBUG(m_pVISAModule->dump());
331335
// Reset all members and prepare for next beginModule() call.
332336
Reset();
333337

IGC/DebugInfo/VISAModule.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,6 @@ void VISAModule::buildDirectElfMaps()
357357
VISAIndexToSize.insert(std::make_pair(index,
358358
std::make_pair(currOffset, currSize)));
359359
}
360-
361360
GenISAToVISAIndex.clear();
362361
for (auto i = 0;
363362
i != co->CISAIndexMap.size();
@@ -522,6 +521,18 @@ void VISAModule::coalesceRanges(std::vector<std::pair<unsigned int, unsigned int
522521
it++;
523522
}
524523
}
524+
void VISAModule::print (raw_ostream &OS) const {
525+
526+
OS << "[DBG] VisaModule\n";
527+
OS << " Module VISAIndexToInst Dump\n ---\n";
528+
for (const auto &Item: VISAIndexToInst)
529+
OS << " visa_index: " << Item.first << " -> inst: " <<
530+
*(Item.second) << "\n";
531+
OS << " Module VISAIndexToSize Dump\n ---\n";
532+
for (const auto &Item: VISAIndexToSize)
533+
OS << " visa_index: " << Item.first << " -> {offset: " <<
534+
Item.second.first << ", size: " << Item.second.second << "}\n";
535+
}
525536

526537
std::vector<std::pair<unsigned int, unsigned int>> VISAModule::getGenISARange(const InsnRange& Range)
527538
{

IGC/DebugInfo/VISAModule.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3030
#include "llvm/Support/DataTypes.h"
3131
#include "llvm/IR/Function.h"
3232
#include "llvm/ADT/APInt.h"
33+
#include "llvm/Support/Debug.h"
3334
#include "common/LLVMWarningsPop.hpp"
3435

3536
#include "VISAIDebugEmitter.hpp"
@@ -534,6 +535,9 @@ namespace IGC
534535
// This function coalesces GenISARange which is a vector of <start ip, end ip>
535536
static void coalesceRanges(std::vector<std::pair<unsigned int, unsigned int>>& GenISARange);
536537

538+
void dump() const { print(llvm::dbgs()); }
539+
void print (llvm::raw_ostream &OS) const;
540+
537541
private:
538542
std::string m_triple = "vISA_64";
539543
const llvm::Module* m_pModule = nullptr;

IGC/VectorCompiler/lib/GenXCodeGen/GenXCisaBuilder.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,8 @@ void GenXKernelBuilder::buildInstructions() {
13051305

13061306
unsigned LabelID = getOrCreateLabel(Func, LABEL_SUBROUTINE);
13071307
CISA_CALL(Kernel->AppendVISACFLabelInst(Labels[LabelID]));
1308+
GM->updateVisaMapping(KernFunc, nullptr, Kernel->getvIsaInstCount(),
1309+
"SubRoutine");
13081310

13091311
beginFunction(Func);
13101312
LastAlloca = nullptr;
@@ -4863,17 +4865,23 @@ void GenXKernelBuilder::addDebugInfo() {
48634865
sys::path::append(Filename, PendingFilename);
48644866
}
48654867
CISA_CALL(Kernel->AppendVISAMiscFileInst(Filename.c_str()));
4868+
GM->updateVisaMapping(KernFunc, nullptr, Kernel->getvIsaInstCount(),
4869+
"FILE");
48664870
LastDirectory = PendingDirectory;
48674871
LastFilename = PendingFilename;
48684872
}
48694873
if (PendingLine != LastLine) {
48704874
LLVM_DEBUG(dbgs() << "LOC instruction appended:" << PendingLine << "\n");
48714875
CISA_CALL(Kernel->AppendVISAMiscLOC(PendingLine));
4876+
GM->updateVisaMapping(KernFunc, nullptr, Kernel->getvIsaInstCount(),
4877+
"LOC");
48724878
LastLine = PendingLine;
48734879
PendingLine = 0;
48744880
}
48754881
}
4876-
GM->updateVisaDebugInfo(KernFunc, CurrentInst);
4882+
// +1 since we update debug info BEFORE appending the instruction
4883+
GM->updateVisaMapping(KernFunc, CurrentInst, Kernel->getvIsaInstCount() + 1,
4884+
CurrentInst ? CurrentInst->getName() : "Init_Special");
48774885
}
48784886

48794887
void GenXKernelBuilder::emitOptimizationHints() {
@@ -4902,7 +4910,7 @@ void GenXKernelBuilder::emitOptimizationHints() {
49024910
* addLabelInst : add a label instruction for a basic block or join
49034911
*/
49044912
void GenXKernelBuilder::addLabelInst(Value *BB) {
4905-
GM->updateVisaDebugInfo(KernFunc, nullptr);
4913+
GM->updateVisaMapping(KernFunc, nullptr, Kernel->getvIsaInstCount(), "LBL");
49064914
// Skip this for now, because we don't know how to patch labels of branches.
49074915
if (0) { // LastLabel >= 0) {
49084916
// There has been no code since the last label, so use the same label

0 commit comments

Comments
 (0)