Skip to content

Commit 507f3c0

Browse files
committed
Keep track of DISubprogram in LLParser::PerFunctionState, Change assigning of debug info metadata
1 parent 938fa5d commit 507f3c0

File tree

4 files changed

+28
-27
lines changed

4 files changed

+28
-27
lines changed

src/AsmParser/LLParser.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,10 @@ bool LLParser::ParseDefine() {
421421
if(ParseFunctionHeader(F, true))
422422
return true;
423423

424-
DebugInfo.addFunction(F);
424+
DISubprogram *SP = DebugInfo.addFunction(F);
425425

426426
return ParseOptionalFunctionMetadata(*F) ||
427-
ParseFunctionBody(*F);
427+
ParseFunctionBody(*F, SP);
428428
}
429429

430430
/// ParseGlobalType
@@ -2291,8 +2291,8 @@ bool LLParser::ParseArrayVectorType(Type *&Result, bool isVector) {
22912291
//===----------------------------------------------------------------------===//
22922292

22932293
LLParser::PerFunctionState::PerFunctionState(LLParser &p, Function &f,
2294-
int functionNumber)
2295-
: P(p), F(f), FunctionNumber(functionNumber) {
2294+
int functionNumber, DISubprogram *DebugSubprogram)
2295+
: P(p), F(f), FunctionNumber(functionNumber), DebugSubprogram(DebugSubprogram) {
22962296

22972297
// Insert unnamed arguments into the NumberedVals list.
22982298
for (Argument &A : F.args())
@@ -4613,15 +4613,15 @@ bool LLParser::PerFunctionState::resolveForwardRefBlockAddresses() {
46134613

46144614
/// ParseFunctionBody
46154615
/// ::= '{' BasicBlock+ UseListOrderDirective* '}'
4616-
bool LLParser::ParseFunctionBody(Function &Fn) {
4616+
bool LLParser::ParseFunctionBody(Function &Fn, DISubprogram *SP) {
46174617
if (Lex.getKind() != lltok::lbrace)
46184618
return TokError("expected '{' in function body");
46194619
Lex.Lex(); // eat the {.
46204620

46214621
int FunctionNumber = -1;
46224622
if (!Fn.hasName()) FunctionNumber = NumberedVals.size()-1;
46234623

4624-
PerFunctionState PFS(*this, Fn, FunctionNumber);
4624+
PerFunctionState PFS(*this, Fn, FunctionNumber, SP);
46254625

46264626
// Resolve block addresses and allow basic blocks to be forward-declared
46274627
// within this function.
@@ -4693,7 +4693,7 @@ bool LLParser::ParseBasicBlock(PerFunctionState &PFS) {
46934693
default: llvm_unreachable("Unknown ParseInstruction result!");
46944694
case InstError: return true;
46954695
case InstNormal:
4696-
DebugInfo.addInstruction(Inst, InstLine);
4696+
DebugInfo.addInstruction(Inst, PFS.getDebugSubprogram(), InstLine);
46974697
BB->getInstList().push_back(Inst);
46984698

46994699
// With a normal result, we check to see if the instruction is followed by
@@ -4703,7 +4703,7 @@ bool LLParser::ParseBasicBlock(PerFunctionState &PFS) {
47034703
return true;
47044704
break;
47054705
case InstExtraComma:
4706-
DebugInfo.addInstruction(Inst, InstLine);
4706+
DebugInfo.addInstruction(Inst, PFS.getDebugSubprogram(), InstLine);
47074707
BB->getInstList().push_back(Inst);
47084708

47094709
// If the instruction parser ate an extra comma at the end of it, it

src/AsmParser/LLParser.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,17 @@ namespace llvm {
317317
std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
318318
std::vector<Value*> NumberedVals;
319319

320+
DISubprogram *DebugSubprogram;
321+
320322
/// FunctionNumber - If this is an unnamed function, this is the slot
321323
/// number of it, otherwise it is -1.
322324
int FunctionNumber;
323325
public:
324-
PerFunctionState(LLParser &p, Function &f, int FunctionNumber);
326+
PerFunctionState(LLParser &p, Function &f, int FunctionNumber, DISubprogram *DebugSubprogram);
325327
~PerFunctionState();
326328

327329
Function &getFunction() const { return F; }
330+
DISubprogram *getDebugSubprogram() const { return DebugSubprogram; };
328331

329332
bool FinishFunction();
330333

@@ -445,7 +448,7 @@ namespace llvm {
445448
};
446449
bool ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList, bool &isVarArg);
447450
bool ParseFunctionHeader(Function *&Fn, bool isDefine);
448-
bool ParseFunctionBody(Function &Fn);
451+
bool ParseFunctionBody(Function &Fn, DISubprogram *SP);
449452
bool ParseBasicBlock(PerFunctionState &PFS);
450453

451454
enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail };

src/LLDebugInfo/LLDebugInfo.cpp

+13-12
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,27 @@ LLDebugInfo::LLDebugInfo(llvm::Module *M, StringRef Filename, StringRef Director
1818
M->addModuleFlag(Module::Error, "Dwarf Version", 4);
1919

2020
CU = DIB.createCompileUnit(dwarf::DW_LANG_lo_user,
21-
Filename,
22-
Directory,
23-
"llvm-dbas",
24-
false,
25-
"",
26-
0);
21+
Filename,
22+
Directory,
23+
"llvm-dbas",
24+
false,
25+
"",
26+
0);
2727

2828
File = CU->getFile();
2929
}
3030

31-
void LLDebugInfo::addFunction(Function *F) {
31+
DISubprogram *LLDebugInfo::addFunction(Function *F) {
3232
DITypeRefArray a;
3333
DISubroutineType *ST = DIB.createSubroutineType(a);
34-
Subprogram = DIB.createFunction(File, F->getName(), F->getName(), File, 0, ST, true, true, 0);
35-
F->setMetadata("dbg", Subprogram);
34+
DISubprogram *SP = DIB.createFunction(File, F->getName(), F->getName(), File, 0, ST, true, true, 0);
35+
F->setSubprogram(SP);
36+
return SP;
3637
}
3738

38-
void LLDebugInfo::addInstruction(Instruction *I, unsigned int Line) {
39-
DILocation *DebugLocation = DILocation::get(M->getContext(), Line + 1, 0, Subprogram);
40-
I->setMetadata("dbg", DebugLocation);
39+
void LLDebugInfo::addInstruction(Instruction *I, DISubprogram *SP, unsigned int Line) {
40+
DebugLoc loc = DebugLoc::get(Line, 0, SP);
41+
I->setDebugLoc(loc);
4142
}
4243

4344
void LLDebugInfo::finalize() {

src/LLDebugInfo/LLDebugInfo.h

+2-5
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,11 @@ namespace llvm {
2525
DICompileUnit *CU;
2626
DIFile *File;
2727

28-
// TODO: do not save this as a member
29-
DISubprogram *Subprogram;
30-
3128
public:
3229
LLDebugInfo(llvm::Module *M, StringRef File, StringRef Directory);
3330

34-
void addFunction(Function *F);
35-
void addInstruction(Instruction *I, unsigned int line);
31+
DISubprogram *addFunction(Function *F);
32+
void addInstruction(Instruction *I, DISubprogram *SP, unsigned int line);
3633
void finalize();
3734
};
3835
}

0 commit comments

Comments
 (0)