diff --git a/include/llvm/Analysis/DebugInfo.h b/include/llvm/Analysis/DebugInfo.h index c560ec2e359..4ddde0158af 100644 --- a/include/llvm/Analysis/DebugInfo.h +++ b/include/llvm/Analysis/DebugInfo.h @@ -492,6 +492,7 @@ namespace llvm { const Type *EmptyStructPtr; // "{}*". Function *DeclareFn; // llvm.dbg.declare + Function *ValueFn; // llvm.dbg.value DIFactory(const DIFactory &); // DO NOT IMPLEMENT void operator=(const DIFactory&); // DO NOT IMPLEMENT @@ -639,6 +640,13 @@ namespace llvm { Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D, Instruction *InsertBefore); + /// InsertValue - Insert a new llvm.dbg.value intrinsic call. + Instruction *InsertValue(llvm::Value *V, llvm::Value *Offset, + DIVariable D, BasicBlock *InsertAtEnd); + + /// InsertValue - Insert a new llvm.dbg.value intrinsic call. + Instruction *InsertValue(llvm::Value *V, llvm::Value *Offset, + DIVariable D, Instruction *InsertBefore); private: Constant *GetTagConstant(unsigned TAG); }; diff --git a/include/llvm/IntrinsicInst.h b/include/llvm/IntrinsicInst.h index 1e1dca2ebab..a5164092962 100644 --- a/include/llvm/IntrinsicInst.h +++ b/include/llvm/IntrinsicInst.h @@ -70,6 +70,7 @@ namespace llvm { case Intrinsic::dbg_region_start: case Intrinsic::dbg_region_end: case Intrinsic::dbg_declare: + case Intrinsic::dbg_value: return true; default: return false; } @@ -171,6 +172,25 @@ namespace llvm { } }; + /// DbgValueInst - This represents the llvm.dbg.value instruction. + /// + struct DbgValueInst : public DbgInfoIntrinsic { + Value *getValue() const { + return cast(getOperand(1))->getElement(0); + } + Value *getOffset() const { return getOperand(2); } + MDNode *getVariable() const { return cast(getOperand(3)); } + + // Methods for support type inquiry through isa, cast, and dyn_cast: + static inline bool classof(const DbgValueInst *) { return true; } + static inline bool classof(const IntrinsicInst *I) { + return I->getIntrinsicID() == Intrinsic::dbg_value; + } + static inline bool classof(const Value *V) { + return isa(V) && classof(cast(V)); + } + }; + /// MemIntrinsic - This is the common base class for memset/memcpy/memmove. /// struct MemIntrinsic : public IntrinsicInst { diff --git a/include/llvm/Intrinsics.td b/include/llvm/Intrinsics.td index b3b0678a24e..6ff87ba1506 100644 --- a/include/llvm/Intrinsics.td +++ b/include/llvm/Intrinsics.td @@ -290,6 +290,9 @@ let Properties = [IntrNoMem] in { def int_dbg_func_start : Intrinsic<[llvm_void_ty], [llvm_metadata_ty]>; def int_dbg_declare : Intrinsic<[llvm_void_ty], [llvm_descriptor_ty, llvm_metadata_ty]>; + def int_dbg_value : Intrinsic<[llvm_void_ty], + [llvm_metadata_ty, llvm_i64_ty, + llvm_metadata_ty]>; } //===------------------ Exception Handling Intrinsics----------------------===// diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp index 4a012ce484f..74d9e1e1794 100644 --- a/lib/Analysis/DebugInfo.cpp +++ b/lib/Analysis/DebugInfo.cpp @@ -1050,6 +1050,35 @@ Instruction *DIFactory::InsertDeclare(Value *Storage, DIVariable D, return CallInst::Create(DeclareFn, Args, Args+2, "", InsertAtEnd); } +/// InsertValue - Insert a new llvm.dbg.value intrinsic call. +Instruction *DIFactory::InsertValue(Value *V, Value *Offset, DIVariable D, + Instruction *InsertBefore) { + assert(V && "no value passed to dbg.value"); + assert(Offset->getType() == Type::getInt64Ty(V->getContext()) && + "offset must be i64"); + if (!ValueFn) + ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value); + + Value *Elts[] = { V }; + Value *Args[] = { MDNode::get(V->getContext(), Elts, 1), Offset, + D.getNode() }; + return CallInst::Create(ValueFn, Args, Args+3, "", InsertBefore); +} + +/// InsertValue - Insert a new llvm.dbg.value intrinsic call. +Instruction *DIFactory::InsertValue(Value *V, Value *Offset, DIVariable D, + BasicBlock *InsertAtEnd) { + assert(V && "no value passed to dbg.value"); + assert(Offset->getType() == Type::getInt64Ty(V->getContext()) && + "offset must be i64"); + if (!ValueFn) + ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value); + + Value *Elts[] = { V }; + Value *Args[] = { MDNode::get(V->getContext(), Elts, 1), Offset, + D.getNode() }; + return CallInst::Create(ValueFn, Args, Args+3, "", InsertAtEnd); +} //===----------------------------------------------------------------------===// // DebugInfoFinder implementations.