From d59e30dfb7cf7ecfa16557cd36da645df2d600d7 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Tue, 14 Apr 2015 01:35:55 +0000 Subject: [PATCH] DebugInfo: Gut DILocation This is along the same lines as r234832, but for `DILocation`. Clean out all accessors from `DILocation`. Any callers should be using `MDLocation` directly (e.g., via `operator->()`). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234835 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/DebugInfo.h | 27 ++++++--------------- lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp | 6 ++--- lib/IR/DebugInfo.cpp | 4 +-- lib/IR/DiagnosticInfo.cpp | 7 +++--- lib/Transforms/Scalar/SampleProfile.cpp | 2 +- lib/Transforms/Utils/AddDiscriminators.cpp | 14 +++++------ 6 files changed, 23 insertions(+), 37 deletions(-) diff --git a/include/llvm/IR/DebugInfo.h b/include/llvm/IR/DebugInfo.h index d7aebeecdcb..717d0a23e9c 100644 --- a/include/llvm/IR/DebugInfo.h +++ b/include/llvm/IR/DebugInfo.h @@ -663,28 +663,15 @@ public: MDExpression &operator*() const { return *N; } }; -/// \brief This object holds location information. -/// -/// This object is not associated with any DWARF tag. -class DILocation : public DIDescriptor { -public: - DILocation() = default; - DILocation(const MDLocation *N) : DIDescriptor(N) {} +class DILocation { + MDLocation *N; - MDLocation *get() const { - return cast_or_null(DIDescriptor::get()); - } - operator MDLocation *() const { return get(); } - MDLocation *operator->() const { return get(); } - MDLocation &operator*() const { return *get(); } +public: + DILocation(const MDLocation *N = nullptr) : N(const_cast(N)) {} - unsigned getLineNumber() const { return get()->getLine(); } - unsigned getColumnNumber() const { return get()->getColumn(); } - DIScope getScope() const { return DIScope(get()->getScope()); } - DILocation getOrigLocation() const { return get()->getInlinedAt(); } - StringRef getFilename() const { return get()->getFilename(); } - StringRef getDirectory() const { return get()->getDirectory(); } - unsigned getDiscriminator() const { return get()->getDiscriminator(); } + operator MDLocation *() const { return N; } + MDLocation *operator->() const { return N; } + MDLocation &operator*() const { return *N; } }; class DIObjCProperty : public DIDescriptor { diff --git a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp index bc4d5e75fa0..4f051fbb52e 100644 --- a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -430,10 +430,10 @@ DwarfCompileUnit::constructInlinedScopeDIE(LexicalScope *Scope) { attachRangesOrLowHighPC(*ScopeDIE, Scope->getRanges()); // Add the call site information to the DIE. - DILocation DL(Scope->getInlinedAt()); + const MDLocation *IA = Scope->getInlinedAt(); addUInt(*ScopeDIE, dwarf::DW_AT_call_file, None, - getOrCreateSourceID(DL.getFilename(), DL.getDirectory())); - addUInt(*ScopeDIE, dwarf::DW_AT_call_line, None, DL.getLineNumber()); + getOrCreateSourceID(IA->getFilename(), IA->getDirectory())); + addUInt(*ScopeDIE, dwarf::DW_AT_call_line, None, IA->getLine()); // Add name to the name table, we do this here because we're guaranteed // to have concrete versions of our DW_TAG_inlined_subprogram nodes. diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp index 6bb69bad37a..2c3d00b2597 100644 --- a/lib/IR/DebugInfo.cpp +++ b/lib/IR/DebugInfo.cpp @@ -179,8 +179,8 @@ void DebugInfoFinder::processLocation(const Module &M, DILocation Loc) { if (!Loc) return; InitializeTypeMap(M); - processScope(Loc.getScope()); - processLocation(M, Loc.getOrigLocation()); + processScope(Loc->getScope()); + processLocation(M, Loc->getInlinedAt()); } void DebugInfoFinder::processType(DIType DT) { diff --git a/lib/IR/DiagnosticInfo.cpp b/lib/IR/DiagnosticInfo.cpp index d5c8e3b8aa7..91635f67959 100644 --- a/lib/IR/DiagnosticInfo.cpp +++ b/lib/IR/DiagnosticInfo.cpp @@ -136,10 +136,9 @@ void DiagnosticInfoOptimizationBase::getLocation(StringRef *Filename, unsigned *Line, unsigned *Column) const { MDLocation *L = getDebugLoc(); - DILocation DIL = L; - *Filename = DIL.getFilename(); - *Line = DIL.getLineNumber(); - *Column = DIL.getColumnNumber(); + *Filename = L->getFilename(); + *Line = L->getLine(); + *Column = L->getColumn(); } const std::string DiagnosticInfoOptimizationBase::getLocationStr() const { diff --git a/lib/Transforms/Scalar/SampleProfile.cpp b/lib/Transforms/Scalar/SampleProfile.cpp index 705d042a809..6487ea64da5 100644 --- a/lib/Transforms/Scalar/SampleProfile.cpp +++ b/lib/Transforms/Scalar/SampleProfile.cpp @@ -226,7 +226,7 @@ unsigned SampleProfileLoader::getInstWeight(Instruction &Inst) { DILocation DIL = DLoc.get(); int LOffset = Lineno - HeaderLineno; - unsigned Discriminator = DIL.getDiscriminator(); + unsigned Discriminator = DIL->getDiscriminator(); unsigned Weight = Samples->samplesAt(LOffset, Discriminator); DEBUG(dbgs() << " " << Lineno << "." << Discriminator << ":" << Inst << " (line offset: " << LOffset << "." << Discriminator diff --git a/lib/Transforms/Utils/AddDiscriminators.cpp b/lib/Transforms/Utils/AddDiscriminators.cpp index 2cbe93e30aa..526dc34d65b 100644 --- a/lib/Transforms/Utils/AddDiscriminators.cpp +++ b/lib/Transforms/Utils/AddDiscriminators.cpp @@ -192,8 +192,8 @@ bool AddDiscriminators::runOnFunction(Function &F) { if (!FirstDIL->canDiscriminate(*LastDIL)) { // Create a new lexical scope and compute a new discriminator // number for it. - StringRef Filename = FirstDIL.getFilename(); - DIScope Scope = FirstDIL.getScope(); + StringRef Filename = FirstDIL->getFilename(); + DIScope Scope = FirstDIL->getScope(); DIFile File = Builder.createFile(Filename, Scope.getDirectory()); // FIXME: Calculate the discriminator here, based on local information, @@ -204,10 +204,10 @@ bool AddDiscriminators::runOnFunction(Function &F) { unsigned Discriminator = FirstDIL->computeNewDiscriminator(); DILexicalBlockFile NewScope = Builder.createLexicalBlockFile(Scope, File, Discriminator); - DILocation NewDIL = + auto *NewDIL = MDLocation::get(Ctx, FirstDIL->getLine(), FirstDIL->getColumn(), NewScope, FirstDIL->getInlinedAt()); - DebugLoc newDebugLoc = NewDIL.get(); + DebugLoc newDebugLoc = NewDIL; // Attach this new debug location to First and every // instruction following First that shares the same location. @@ -216,9 +216,9 @@ bool AddDiscriminators::runOnFunction(Function &F) { if (I1->getDebugLoc().get() != FirstDIL) break; I1->setDebugLoc(newDebugLoc); - DEBUG(dbgs() << NewDIL.getFilename() << ":" << NewDIL.getLineNumber() - << ":" << NewDIL.getColumnNumber() << ":" - << NewDIL.getDiscriminator() << *I1 << "\n"); + DEBUG(dbgs() << NewDIL->getFilename() << ":" << NewDIL->getLine() + << ":" << NewDIL->getColumn() << ":" + << NewDIL->getDiscriminator() << *I1 << "\n"); } DEBUG(dbgs() << "\n"); Changed = true; -- 2.34.1