From f8a481b82a403641440f6fd0de9f50af127fceec Mon Sep 17 00:00:00 2001 From: Martin Nowack Date: Wed, 8 Aug 2018 17:42:46 +0100 Subject: separate between instructions and functions --- lib/Module/InstructionInfoTable.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/Module/InstructionInfoTable.cpp b/lib/Module/InstructionInfoTable.cpp index b67335e3..4d6379de 100644 --- a/lib/Module/InstructionInfoTable.cpp +++ b/lib/Module/InstructionInfoTable.cpp @@ -104,11 +104,8 @@ static std::string getFullPath(llvm::StringRef Directory, class DebugInfoExtractor { std::vector> &internedStrings; - llvm::DebugInfoFinder DIF; - - uint64_t counter; - std::map lineTable; + llvm::DebugInfoFinder DIF; const llvm::Module &module; @@ -116,7 +113,7 @@ public: DebugInfoExtractor( std::vector> &_internedStrings, const llvm::Module &_module) - : internedStrings(_internedStrings), counter(0), module(_module) { + : internedStrings(_internedStrings), module(_module) { DIF.processModule(module); lineTable = buildInstructionToLineMap(module); } @@ -149,13 +146,12 @@ public: auto path = getFullPath(SubProgram.getDirectory(), SubProgram.getFilename()); - return std::unique_ptr( - new FunctionInfo(counter++, getInternedString(path), - SubProgram.getLineNumber(), asmLine)); + return std::unique_ptr(new FunctionInfo( + 0, getInternedString(path), SubProgram.getLineNumber(), asmLine)); } return std::unique_ptr( - new FunctionInfo(counter++, getInternedString(""), 0, asmLine)); + new FunctionInfo(0, getInternedString(""), 0, asmLine)); } std::unique_ptr @@ -167,17 +163,18 @@ public: llvm::DIScope Scope(Loc.getScope(module.getContext())); auto full_path = getFullPath(Scope.getDirectory(), Scope.getFilename()); return std::unique_ptr( - new InstructionInfo(counter++, getInternedString(full_path), - Loc.getLine(), Loc.getCol(), asmLine)); + new InstructionInfo(0, getInternedString(full_path), Loc.getLine(), + Loc.getCol(), asmLine)); } // If nothing found, use the surrounding function return std::unique_ptr( - new InstructionInfo(counter++, f.file, f.line, 0, asmLine)); + new InstructionInfo(0, f.file, f.line, 0, asmLine)); } }; InstructionInfoTable::InstructionInfoTable(const llvm::Module &m) { + // Generate all debug instruction information DebugInfoExtractor DI(internedStrings, m); for (const auto &Func : m) { auto F = DI.getFunctionInfo(Func); @@ -190,6 +187,13 @@ InstructionInfoTable::InstructionInfoTable(const llvm::Module &m) { infos.insert(std::make_pair(instr, DI.getInstructionInfo(*instr, *FD))); } } + + // Make sure that every item has a unique ID + size_t idCounter = 0; + for (auto &item : infos) + item.second->id = idCounter++; + for (auto &item : functionInfos) + item.second->id = idCounter++; } unsigned InstructionInfoTable::getMaxID() const { -- cgit 1.4.1