diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-03-30 19:40:05 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-03-30 19:40:05 +0000 |
commit | ab659fb3d03005114e176cb86449636e0635f16a (patch) | |
tree | 8382ab9e3536192f4e3e815e6ff85a6dbb89a687 /llvm/lib | |
parent | 364266663bc16789c0fd07fe6ed5e5e8049573f4 (diff) | |
download | bcm5719-llvm-ab659fb3d03005114e176cb86449636e0635f16a.tar.gz bcm5719-llvm-ab659fb3d03005114e176cb86449636e0635f16a.zip |
IR: Use the new DebugLoc API, NFC
Update lib/IR and lib/Bitcode to use the new `DebugLoc` API. Added an
explicit conversion to `bool` (avoiding a conversion to `MDLocation`),
since a couple of these use cases need to handle broken code.
llvm-svn: 233585
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 21 | ||||
-rw-r--r-- | llvm/lib/Bitcode/Writer/ValueEnumerator.cpp | 10 | ||||
-rw-r--r-- | llvm/lib/IR/Core.cpp | 5 | ||||
-rw-r--r-- | llvm/lib/IR/DebugInfo.cpp | 22 | ||||
-rw-r--r-- | llvm/lib/IR/DiagnosticInfo.cpp | 5 | ||||
-rw-r--r-- | llvm/lib/IR/Metadata.cpp | 4 |
6 files changed, 28 insertions, 39 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index d80d21d01c5..71ba01e6668 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -2089,7 +2089,7 @@ static void WriteFunction(const Function &F, ValueEnumerator &VE, bool NeedsMetadataAttachment = false; - DebugLoc LastDL; + MDLocation *LastDL = nullptr; // Finally, emit all the instructions, in order. for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) @@ -2104,10 +2104,9 @@ static void WriteFunction(const Function &F, ValueEnumerator &VE, NeedsMetadataAttachment |= I->hasMetadataOtherThanDebugLoc(); // If the instruction has a debug location, emit it. - DebugLoc DL = I->getDebugLoc(); - if (DL.isUnknown()) { + MDLocation *DL = I->getDebugLoc(); + if (!DL) continue; - } if (DL == LastDL) { // Just repeat the same debug loc as last time. @@ -2115,18 +2114,12 @@ static void WriteFunction(const Function &F, ValueEnumerator &VE, continue; } - MDNode *Scope, *IA; - DL.getScopeAndInlinedAt(Scope, IA, I->getContext()); - assert(Scope && "Expected valid scope"); - - Vals.push_back(DL.getLine()); - Vals.push_back(DL.getCol()); - Vals.push_back(VE.getMetadataOrNullID(Scope)); - Vals.push_back(VE.getMetadataOrNullID(IA)); + Vals.push_back(DL->getLine()); + Vals.push_back(DL->getColumn()); + Vals.push_back(VE.getMetadataOrNullID(DL->getScope())); + Vals.push_back(VE.getMetadataOrNullID(DL->getInlinedAt())); Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC, Vals); Vals.clear(); - - LastDL = DL; } // Emit names for all the instructions etc. diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp index 549e94fc96a..a450f697f20 100644 --- a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -373,12 +373,10 @@ ValueEnumerator::ValueEnumerator(const Module &M) for (unsigned i = 0, e = MDs.size(); i != e; ++i) EnumerateMetadata(MDs[i].second); - if (!I.getDebugLoc().isUnknown()) { - MDNode *Scope, *IA; - I.getDebugLoc().getScopeAndInlinedAt(Scope, IA, I.getContext()); - if (Scope) EnumerateMetadata(Scope); - if (IA) EnumerateMetadata(IA); - } + // Don't enumerate the location directly -- it has a special record + // type -- but enumerate its operands. + if (MDLocation *L = I.getDebugLoc()) + EnumerateMDNodeOperands(L); } } diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index 613147e5145..fcb1aa54914 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -2181,14 +2181,13 @@ void LLVMDisposeBuilder(LLVMBuilderRef Builder) { void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L) { MDNode *Loc = L ? cast<MDNode>(unwrap<MetadataAsValue>(L)->getMetadata()) : nullptr; - unwrap(Builder)->SetCurrentDebugLocation(DebugLoc::getFromDILocation(Loc)); + unwrap(Builder)->SetCurrentDebugLocation(DebugLoc(Loc)); } LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder) { LLVMContext &Context = unwrap(Builder)->getContext(); return wrap(MetadataAsValue::get( - Context, - unwrap(Builder)->getCurrentDebugLocation().getAsMDNode(Context))); + Context, unwrap(Builder)->getCurrentDebugLocation().getAsMDNode())); } void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst) { diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index d2956d58e2c..91f7c717580 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -343,8 +343,7 @@ bool DISubprogram::Verify() const { if (auto *F = getFunction()) { for (auto &BB : *F) { for (auto &I : BB) { - MDLocation *DL = - cast_or_null<MDLocation>(I.getDebugLoc().getAsMDNode()); + MDLocation *DL = I.getDebugLoc(); if (!DL) continue; @@ -585,12 +584,12 @@ DISubprogram llvm::getDISubprogram(const Function *F) { // We look for the first instr that has a debug annotation leading back to F. for (auto &BB : *F) { auto Inst = std::find_if(BB.begin(), BB.end(), [](const Instruction &Inst) { - return !Inst.getDebugLoc().isUnknown(); + return Inst.getDebugLoc(); }); if (Inst == BB.end()) continue; DebugLoc DLoc = Inst->getDebugLoc(); - const MDNode *Scope = DLoc.getScopeNode(); + const MDNode *Scope = DLoc.getInlinedAtScope(); DISubprogram Subprogram = getDISubprogram(Scope); return Subprogram.describes(F) ? Subprogram : DISubprogram(); } @@ -889,10 +888,10 @@ void DIDescriptor::print(raw_ostream &OS) const { static void printDebugLoc(DebugLoc DL, raw_ostream &CommentOS, const LLVMContext &Ctx) { - if (DL.isUnknown()) + if (!DL) return; - DIScope Scope(DL.getScope(Ctx)); + DIScope Scope(DL.getScope()); assert(Scope.isScope() && "Scope of a DebugLoc should be a DIScope."); // Omit the directory, because it's likely to be long and uninteresting. CommentOS << Scope.getFilename(); @@ -900,8 +899,8 @@ static void printDebugLoc(DebugLoc DL, raw_ostream &CommentOS, if (DL.getCol() != 0) CommentOS << ':' << DL.getCol(); - DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(DL.getInlinedAt(Ctx)); - if (InlinedAtDL.isUnknown()) + DebugLoc InlinedAtDL = DL.getInlinedAt(); + if (!InlinedAtDL) return; CommentOS << " @[ "; @@ -914,9 +913,8 @@ void DIVariable::printExtendedName(raw_ostream &OS) const { StringRef Res = getName(); if (!Res.empty()) OS << Res << "," << getLineNumber(); - if (MDNode *InlinedAt = getInlinedAt()) { - DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(InlinedAt); - if (!InlinedAtDL.isUnknown()) { + if (auto *InlinedAt = get()->getInlinedAt()) { + if (DebugLoc InlinedAtDL = InlinedAt) { OS << " @["; printDebugLoc(InlinedAtDL, OS, Ctx); OS << "]"; @@ -985,7 +983,7 @@ bool llvm::StripDebugInfo(Module &M) { ++FI) for (BasicBlock::iterator BI = FI->begin(), BE = FI->end(); BI != BE; ++BI) { - if (!BI->getDebugLoc().isUnknown()) { + if (BI->getDebugLoc()) { Changed = true; BI->setDebugLoc(DebugLoc()); } diff --git a/llvm/lib/IR/DiagnosticInfo.cpp b/llvm/lib/IR/DiagnosticInfo.cpp index 01a942b6140..d5c8e3b8aa7 100644 --- a/llvm/lib/IR/DiagnosticInfo.cpp +++ b/llvm/lib/IR/DiagnosticInfo.cpp @@ -129,13 +129,14 @@ void DiagnosticInfoSampleProfile::print(DiagnosticPrinter &DP) const { } bool DiagnosticInfoOptimizationBase::isLocationAvailable() const { - return !getDebugLoc().isUnknown(); + return getDebugLoc(); } void DiagnosticInfoOptimizationBase::getLocation(StringRef *Filename, unsigned *Line, unsigned *Column) const { - DILocation DIL(getDebugLoc().getAsMDNode(getFunction().getContext())); + MDLocation *L = getDebugLoc(); + DILocation DIL = L; *Filename = DIL.getFilename(); *Line = DIL.getLineNumber(); *Column = DIL.getColumnNumber(); diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp index 0ad3c5c04ba..7691ab016cc 100644 --- a/llvm/lib/IR/Metadata.cpp +++ b/llvm/lib/IR/Metadata.cpp @@ -1035,7 +1035,7 @@ void Instruction::setMetadata(unsigned KindID, MDNode *Node) { // Handle 'dbg' as a special case since it is not stored in the hash table. if (KindID == LLVMContext::MD_dbg) { - DbgLoc = DebugLoc::getFromDILocation(Node); + DbgLoc = DebugLoc(Node); return; } @@ -1114,7 +1114,7 @@ void Instruction::getAllMetadataImpl( Result.clear(); // Handle 'dbg' as a special case since it is not stored in the hash table. - if (!DbgLoc.isUnknown()) { + if (DbgLoc) { Result.push_back( std::make_pair((unsigned)LLVMContext::MD_dbg, DbgLoc.getAsMDNode())); if (!hasMetadataHashEntry()) return; |