summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/DebugInfo.cpp
diff options
context:
space:
mode:
authorDiego Novillo <dnovillo@google.com>2014-03-03 20:06:11 +0000
committerDiego Novillo <dnovillo@google.com>2014-03-03 20:06:11 +0000
commitf5041ce5583fd0dbdb362a92571a4709d063d0c1 (patch)
tree4ffc06ad33d4915d28009605c912d01c2e8f545a /llvm/lib/IR/DebugInfo.cpp
parentb2f034b85e001fd79617f2124560509583118c13 (diff)
downloadbcm5719-llvm-f5041ce5583fd0dbdb362a92571a4709d063d0c1.tar.gz
bcm5719-llvm-f5041ce5583fd0dbdb362a92571a4709d063d0c1.zip
Pass to emit DWARF path discriminators.
DWARF discriminators are used to distinguish multiple control flow paths on the same source location. When this happens, instructions across basic block boundaries will share the same debug location. This pass detects this situation and creates a new lexical scope to one of the two instructions. This lexical scope is a child scope of the original and contains a new discriminator value. This discriminator is then picked up from MCObjectStreamer::EmitDwarfLocDirective to be written on the object file. This fixes http://llvm.org/bugs/show_bug.cgi?id=18270. llvm-svn: 202752
Diffstat (limited to 'llvm/lib/IR/DebugInfo.cpp')
-rw-r--r--llvm/lib/IR/DebugInfo.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 749e0b5057a..f5884a4a90a 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -22,6 +22,7 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
+#include "LLVMContextImpl.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Dwarf.h"
@@ -818,6 +819,29 @@ DIArray DICompileUnit::getImportedEntities() const {
return DIArray(getNodeField(DbgNode, 11));
}
+/// copyWithNewScope - Return a copy of this location, replacing the
+/// current scope with the given one.
+DILocation DILocation::copyWithNewScope(LLVMContext &Ctx,
+ DILexicalBlock NewScope) {
+ SmallVector<Value *, 10> Elts;
+ assert(Verify());
+ for (unsigned I = 0; I < DbgNode->getNumOperands(); ++I) {
+ if (I != 2)
+ Elts.push_back(DbgNode->getOperand(I));
+ else
+ Elts.push_back(NewScope);
+ }
+ MDNode *NewDIL = MDNode::get(Ctx, Elts);
+ return DILocation(NewDIL);
+}
+
+/// computeNewDiscriminator - Generate a new discriminator value for this
+/// file and line location.
+unsigned DILocation::computeNewDiscriminator(LLVMContext &Ctx) {
+ std::pair<const char *, unsigned> Key(getFilename().data(), getLineNumber());
+ return ++Ctx.pImpl->DiscriminatorTable[Key];
+}
+
/// fixupSubprogramName - Replace contains special characters used
/// in a typical Objective-C names with '.' in a given string.
static void fixupSubprogramName(DISubprogram Fn, SmallVectorImpl<char> &Out) {
OpenPOWER on IntegriCloud