diff options
author | Devang Patel <dpatel@apple.com> | 2009-09-16 18:16:11 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2009-09-16 18:16:11 +0000 |
commit | 95c1984e6b0b299f74d8a428fac6b6be266ae169 (patch) | |
tree | 7c91274bfffa1b91dbfb5bf77030b164875ee104 /include | |
parent | 937b1e92a9862862722732cb0f72d5ade77ac4c8 (diff) | |
download | external_llvm-95c1984e6b0b299f74d8a428fac6b6be266ae169.zip external_llvm-95c1984e6b0b299f74d8a428fac6b6be266ae169.tar.gz external_llvm-95c1984e6b0b299f74d8a428fac6b6be266ae169.tar.bz2 |
Add an interface to attach debugging information with an instruction.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82062 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Support/IRBuilder.h | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h index 4080f90..b1f4354 100644 --- a/include/llvm/Support/IRBuilder.h +++ b/include/llvm/Support/IRBuilder.h @@ -20,6 +20,7 @@ #include "llvm/GlobalAlias.h" #include "llvm/GlobalVariable.h" #include "llvm/Function.h" +#include "llvm/Metadata.h" #include "llvm/LLVMContext.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/ConstantFolder.h" @@ -60,35 +61,38 @@ template<bool preserveNames = true, typename T = ConstantFolder, class IRBuilder : public Inserter { BasicBlock *BB; BasicBlock::iterator InsertPt; + MDKindID MDKind; + MDNode *CurLocation; LLVMContext &Context; T Folder; public: IRBuilder(LLVMContext &C, const T &F, const Inserter &I = Inserter()) - : Inserter(I), Context(C), Folder(F) { + : Inserter(I), MDKind(0), CurLocation(0), Context(C), Folder(F) { ClearInsertionPoint(); } - explicit IRBuilder(LLVMContext &C) : Context(C), Folder(C) { + explicit IRBuilder(LLVMContext &C) + : MDKind(0), CurLocation(0), Context(C), Folder(C) { ClearInsertionPoint(); } explicit IRBuilder(BasicBlock *TheBB, const T &F) - : Context(TheBB->getContext()), Folder(F) { + : MDKind(0), CurLocation(0), Context(TheBB->getContext()), Folder(F) { SetInsertPoint(TheBB); } explicit IRBuilder(BasicBlock *TheBB) - : Context(TheBB->getContext()), Folder(Context) { + : MDKind(0), CurLocation(0), Context(TheBB->getContext()), Folder(Context) { SetInsertPoint(TheBB); } IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T& F) - : Context(TheBB->getContext()), Folder(F) { + : MDKind(0), CurLocation(0), Context(TheBB->getContext()), Folder(F) { SetInsertPoint(TheBB, IP); } IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP) - : Context(TheBB->getContext()), Folder(Context) { + : MDKind(0), CurLocation(0), Context(TheBB->getContext()), Folder(Context) { SetInsertPoint(TheBB, IP); } @@ -127,10 +131,24 @@ public: InsertPt = IP; } + /// SetCurrentLocation - This specifies the location information used + /// by debugging information. + void SetCurrentLocation(MDNode *L) { + if (MDKind == 0) { + Context.getMetadata().RegisterMDKind("dbg"); + MDKind = Context.getMetadata().getMDKind("dbg"); + } + CurLocation = L; + } + + MDNode *getCurrentLocation() const { return CurLocation; } + /// Insert - Insert and return the specified instruction. template<typename InstTy> InstTy *Insert(InstTy *I, const Twine &Name = "") const { this->InsertHelper(I, Name, BB, InsertPt); + if (CurLocation) + Context.getMetadata().setMD(MDKind, CurLocation, I); return I; } |