summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/DIBuilder.cpp
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2017-10-03 20:36:40 +0000
committerReid Kleckner <rnk@google.com>2017-10-03 20:36:40 +0000
commitbc66947433e2a6291d85ec88b7cd7ce2e0ea438f (patch)
tree47edd8630b2bc4d2f98bd0681c0f3b6c8d60a183 /llvm/lib/IR/DIBuilder.cpp
parent283e2076f6a6f23629475a25c64173843e72cf61 (diff)
downloadbcm5719-llvm-bc66947433e2a6291d85ec88b7cd7ce2e0ea438f.tar.gz
bcm5719-llvm-bc66947433e2a6291d85ec88b7cd7ce2e0ea438f.zip
Refactor DIBuilder dbg intrinsic insertion, NFC
Both dbg.declare and dbg.value insertion had duplicate code for the two overloads with different insertion point conventions. llvm-svn: 314839
Diffstat (limited to 'llvm/lib/IR/DIBuilder.cpp')
-rw-r--r--llvm/lib/IR/DIBuilder.cpp115
1 files changed, 57 insertions, 58 deletions
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 88f5b36dd58..18979a8d5cf 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/IR/DIBuilder.h"
+#include "llvm/IR/IRBuilder.h"
#include "LLVMContextImpl.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/BinaryFormat/Dwarf.h"
@@ -771,16 +772,59 @@ DILexicalBlock *DIBuilder::createLexicalBlock(DIScope *Scope, DIFile *File,
File, Line, Col);
}
+Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
+ DIExpression *Expr, const DILocation *DL,
+ Instruction *InsertBefore) {
+ return insertDeclare(Storage, VarInfo, Expr, DL, InsertBefore->getParent(),
+ InsertBefore);
+}
+
+Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
+ DIExpression *Expr, const DILocation *DL,
+ BasicBlock *InsertAtEnd) {
+ // If this block already has a terminator then insert this intrinsic before
+ // the terminator. Otherwise, put it at the end of the block.
+ Instruction *InsertBefore = InsertAtEnd->getTerminator();
+ return insertDeclare(Storage, VarInfo, Expr, DL, InsertAtEnd, InsertBefore);
+}
+
+Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V,
+ DILocalVariable *VarInfo,
+ DIExpression *Expr,
+ const DILocation *DL,
+ Instruction *InsertBefore) {
+ return insertDbgValueIntrinsic(
+ V, VarInfo, Expr, DL, InsertBefore ? InsertBefore->getParent() : nullptr,
+ InsertBefore);
+}
+
+Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V,
+ DILocalVariable *VarInfo,
+ DIExpression *Expr,
+ const DILocation *DL,
+ BasicBlock *InsertAtEnd) {
+ return insertDbgValueIntrinsic(V, VarInfo, Expr, DL, InsertAtEnd, nullptr);
+}
+
+/// Return an IRBuilder for inserting dbg.declare and dbg.value intrinsics. This
+/// abstracts over the various ways to specify an insert position.
+static IRBuilder<> getIRBForDbgInsertion(const DILocation *DL,
+ BasicBlock *InsertBB,
+ Instruction *InsertBefore) {
+ IRBuilder<> B(DL->getContext());
+ if (InsertBefore)
+ B.SetInsertPoint(InsertBefore);
+ else if (InsertBB)
+ B.SetInsertPoint(InsertBB);
+ B.SetCurrentDebugLocation(DL);
+ return B;
+}
+
static Value *getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V) {
assert(V && "no value passed to dbg intrinsic");
return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V));
}
-static Instruction *withDebugLoc(Instruction *I, const DILocation *DL) {
- I->setDebugLoc(const_cast<DILocation *>(DL));
- return I;
-}
-
static Function *getDeclareIntrin(Module &M) {
return Intrinsic::getDeclaration(&M, UseDbgAddr ? Intrinsic::dbg_addr
: Intrinsic::dbg_declare);
@@ -788,7 +832,7 @@ static Function *getDeclareIntrin(Module &M) {
Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
DIExpression *Expr, const DILocation *DL,
- Instruction *InsertBefore) {
+ BasicBlock *InsertBB, Instruction *InsertBefore) {
assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
assert(DL && "Expected debug loc");
assert(DL->getScope()->getSubprogram() ==
@@ -802,60 +846,14 @@ Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage),
MetadataAsValue::get(VMContext, VarInfo),
MetadataAsValue::get(VMContext, Expr)};
- return withDebugLoc(CallInst::Create(DeclareFn, Args, "", InsertBefore), DL);
-}
-Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
- DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertAtEnd) {
- assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
- assert(DL && "Expected debug loc");
- assert(DL->getScope()->getSubprogram() ==
- VarInfo->getScope()->getSubprogram() &&
- "Expected matching subprograms");
- if (!DeclareFn)
- DeclareFn = getDeclareIntrin(M);
-
- trackIfUnresolved(VarInfo);
- trackIfUnresolved(Expr);
- Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage),
- MetadataAsValue::get(VMContext, VarInfo),
- MetadataAsValue::get(VMContext, Expr)};
-
- // If this block already has a terminator then insert this intrinsic
- // before the terminator.
- if (TerminatorInst *T = InsertAtEnd->getTerminator())
- return withDebugLoc(CallInst::Create(DeclareFn, Args, "", T), DL);
- return withDebugLoc(CallInst::Create(DeclareFn, Args, "", InsertAtEnd), DL);
-}
-
-Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V,
- DILocalVariable *VarInfo,
- DIExpression *Expr,
- const DILocation *DL,
- Instruction *InsertBefore) {
- assert(V && "no value passed to dbg.value");
- assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.value");
- assert(DL && "Expected debug loc");
- assert(DL->getScope()->getSubprogram() ==
- VarInfo->getScope()->getSubprogram() &&
- "Expected matching subprograms");
- if (!ValueFn)
- ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
-
- trackIfUnresolved(VarInfo);
- trackIfUnresolved(Expr);
- Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V),
- MetadataAsValue::get(VMContext, VarInfo),
- MetadataAsValue::get(VMContext, Expr)};
- return withDebugLoc(CallInst::Create(ValueFn, Args, "", InsertBefore), DL);
+ IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore);
+ return B.CreateCall(DeclareFn, Args);
}
-Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V,
- DILocalVariable *VarInfo,
- DIExpression *Expr,
- const DILocation *DL,
- BasicBlock *InsertAtEnd) {
+Instruction *DIBuilder::insertDbgValueIntrinsic(
+ Value *V, DILocalVariable *VarInfo, DIExpression *Expr,
+ const DILocation *DL, BasicBlock *InsertBB, Instruction *InsertBefore) {
assert(V && "no value passed to dbg.value");
assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.value");
assert(DL && "Expected debug loc");
@@ -871,7 +869,8 @@ Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V,
MetadataAsValue::get(VMContext, VarInfo),
MetadataAsValue::get(VMContext, Expr)};
- return withDebugLoc(CallInst::Create(ValueFn, Args, "", InsertAtEnd), DL);
+ IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore);
+ return B.CreateCall(ValueFn, Args);
}
void DIBuilder::replaceVTableHolder(DICompositeType *&T,
OpenPOWER on IntegriCloud