summaryrefslogtreecommitdiff
path: root/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
commitf05b45fdb2d04db7bc1cde4529ebe0afdb9be148 (patch)
tree9a61f45d821e89428889bb03b6ee7852984daf66 /lib/IR/DebugInfo.cpp
parent9efaf2f2dad82d5455970af0370edace405791b2 (diff)
downloadllvm-f05b45fdb2d04db7bc1cde4529ebe0afdb9be148.tar.gz
llvm-f05b45fdb2d04db7bc1cde4529ebe0afdb9be148.tar.bz2
llvm-f05b45fdb2d04db7bc1cde4529ebe0afdb9be148.tar.xz
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202752 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR/DebugInfo.cpp')
-rw-r--r--lib/IR/DebugInfo.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp
index 749e0b5057..f5884a4a90 100644
--- a/lib/IR/DebugInfo.cpp
+++ b/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) {