diff --git a/llvm/include/llvm/Analysis/DebugInfo.h b/llvm/include/llvm/Analysis/DebugInfo.h index c626b126b74f..cc9514cade16 100644 --- a/llvm/include/llvm/Analysis/DebugInfo.h +++ b/llvm/include/llvm/Analysis/DebugInfo.h @@ -491,7 +491,6 @@ namespace llvm { Module &M; LLVMContext& VMContext; - const Type *EmptyStructPtr; // "{}*". Function *DeclareFn; // llvm.dbg.declare Function *ValueFn; // llvm.dbg.value @@ -659,7 +658,7 @@ namespace llvm { /// Finds the dbg.declare intrinsic corresponding to this value if any. /// It looks through pointer casts too. - const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts = true); + const DbgDeclareInst *findDbgDeclare(const Value *V); /// Find the debug info descriptor corresponding to this global variable. Value *findDbgGlobalDeclare(GlobalVariable *V); diff --git a/llvm/include/llvm/IntrinsicInst.h b/llvm/include/llvm/IntrinsicInst.h index 151e4344f3b8..d86b33ef50a8 100644 --- a/llvm/include/llvm/IntrinsicInst.h +++ b/llvm/include/llvm/IntrinsicInst.h @@ -82,7 +82,7 @@ namespace llvm { /// class DbgDeclareInst : public DbgInfoIntrinsic { public: - Value *getAddress() const { return getOperand(1); } + Value *getAddress() const; MDNode *getVariable() const { return cast(getOperand(2)); } // Methods for support type inquiry through isa, cast, and dyn_cast: diff --git a/llvm/include/llvm/Intrinsics.td b/llvm/include/llvm/Intrinsics.td index 0cec567fb886..684f8724cf76 100644 --- a/llvm/include/llvm/Intrinsics.td +++ b/llvm/include/llvm/Intrinsics.td @@ -283,7 +283,7 @@ let Properties = [IntrNoMem] in { // places. let Properties = [IntrNoMem] in { def int_dbg_declare : Intrinsic<[llvm_void_ty], - [llvm_descriptor_ty, llvm_metadata_ty]>; + [llvm_metadata_ty, llvm_metadata_ty]>; def int_dbg_value : Intrinsic<[llvm_void_ty], [llvm_metadata_ty, llvm_i64_ty, llvm_metadata_ty]>; diff --git a/llvm/lib/Analysis/DebugInfo.cpp b/llvm/lib/Analysis/DebugInfo.cpp index 15ca1fae085b..59ba807dd027 100644 --- a/llvm/lib/Analysis/DebugInfo.cpp +++ b/llvm/lib/Analysis/DebugInfo.cpp @@ -599,9 +599,7 @@ void DIVariable::dump() const { //===----------------------------------------------------------------------===// DIFactory::DIFactory(Module &m) - : M(m), VMContext(M.getContext()), DeclareFn(0) { - EmptyStructPtr = PointerType::getUnqual(StructType::get(VMContext)); -} + : M(m), VMContext(M.getContext()), DeclareFn(0) {} Constant *DIFactory::GetTagConstant(unsigned TAG) { assert((TAG & LLVMDebugVersionMask) == 0 && @@ -1034,26 +1032,22 @@ DILocation DIFactory::CreateLocation(unsigned LineNo, unsigned ColumnNo, /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call. Instruction *DIFactory::InsertDeclare(Value *Storage, DIVariable D, Instruction *InsertBefore) { - // Cast the storage to a {}* for the call to llvm.dbg.declare. - Storage = new BitCastInst(Storage, EmptyStructPtr, "", InsertBefore); - if (!DeclareFn) DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare); - Value *Args[] = { Storage, D.getNode() }; + Value *Elts[] = { Storage }; + Value *Args[] = { MDNode::get(Storage->getContext(), Elts, 1), D.getNode() }; return CallInst::Create(DeclareFn, Args, Args+2, "", InsertBefore); } /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call. Instruction *DIFactory::InsertDeclare(Value *Storage, DIVariable D, BasicBlock *InsertAtEnd) { - // Cast the storage to a {}* for the call to llvm.dbg.declare. - Storage = new BitCastInst(Storage, EmptyStructPtr, "", InsertAtEnd); - if (!DeclareFn) DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare); - Value *Args[] = { Storage, D.getNode() }; + Value *Elts[] = { Storage }; + Value *Args[] = { MDNode::get(Storage->getContext(), Elts, 1), D.getNode() }; return CallInst::Create(DeclareFn, Args, Args+2, "", InsertAtEnd); } @@ -1258,25 +1252,24 @@ Value *llvm::findDbgGlobalDeclare(GlobalVariable *V) { /// Finds the llvm.dbg.declare intrinsic corresponding to this value if any. /// It looks through pointer casts too. -const DbgDeclareInst *llvm::findDbgDeclare(const Value *V, bool stripCasts) { - if (stripCasts) { - V = V->stripPointerCasts(); - - // Look for the bitcast. - for (Value::use_const_iterator I = V->use_begin(), E =V->use_end(); - I != E; ++I) - if (isa(I)) { - const DbgDeclareInst *DDI = findDbgDeclare(*I, false); - if (DDI) return DDI; - } +const DbgDeclareInst *llvm::findDbgDeclare(const Value *V) { + V = V->stripPointerCasts(); + + if (!isa(V) && !isa(V)) return 0; - } - - // Find llvm.dbg.declare among uses of the instruction. - for (Value::use_const_iterator I = V->use_begin(), E =V->use_end(); - I != E; ++I) - if (const DbgDeclareInst *DDI = dyn_cast(I)) - return DDI; + + const Function *F = NULL; + if (const Instruction *I = dyn_cast(V)) + F = I->getParent()->getParent(); + else if (const Argument *A = dyn_cast(V)) + F = A->getParent(); + + for (Function::const_iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI) + for (BasicBlock::const_iterator BI = (*FI).begin(), BE = (*FI).end(); + BI != BE; ++BI) + if (const DbgDeclareInst *DDI = dyn_cast(BI)) + if (DDI->getAddress() == V) + return DDI; return 0; } diff --git a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp index 8bc95d3d440b..09fd657fffd0 100644 --- a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -332,8 +332,6 @@ bool FastISel::SelectCall(User *I) { return true; Value *Address = DI->getAddress(); - if (BitCastInst *BCI = dyn_cast(Address)) - Address = BCI->getOperand(0); AllocaInst *AI = dyn_cast(Address); // Don't handle byval struct arguments or VLAs, for example. if (!AI) break; diff --git a/llvm/lib/VMCore/AutoUpgrade.cpp b/llvm/lib/VMCore/AutoUpgrade.cpp index 216184188ad2..5e4c9fb76624 100644 --- a/llvm/lib/VMCore/AutoUpgrade.cpp +++ b/llvm/lib/VMCore/AutoUpgrade.cpp @@ -521,7 +521,7 @@ void llvm::CheckDebugInfoIntrinsics(Module *M) { if (Function *Declare = M->getFunction("llvm.dbg.declare")) { if (!Declare->use_empty()) { DbgDeclareInst *DDI = cast(Declare->use_back()); - if (!isa(DDI->getOperand(2))) { + if (!isa(DDI->getOperand(1)) ||!isa(DDI->getOperand(2))) { while (!Declare->use_empty()) { CallInst *CI = cast(Declare->use_back()); CI->eraseFromParent(); diff --git a/llvm/lib/VMCore/IntrinsicInst.cpp b/llvm/lib/VMCore/IntrinsicInst.cpp index cb9252efdf58..d8f015a9e2c7 100644 --- a/llvm/lib/VMCore/IntrinsicInst.cpp +++ b/llvm/lib/VMCore/IntrinsicInst.cpp @@ -50,6 +50,17 @@ Value *DbgInfoIntrinsic::StripCast(Value *C) { return dyn_cast(C); } +//===----------------------------------------------------------------------===// +/// DbgDeclareInst - This represents the llvm.dbg.declare instruction. +/// + +Value *DbgDeclareInst::getAddress() const { + if (MDNode* MD = cast_or_null(getOperand(1))) + return MD->getOperand(0); + else + return NULL; +} + //===----------------------------------------------------------------------===// /// DbgValueInst - This represents the llvm.dbg.value instruction. /// diff --git a/llvm/lib/VMCore/Verifier.cpp b/llvm/lib/VMCore/Verifier.cpp index 66e2a670252d..ec475e472979 100644 --- a/llvm/lib/VMCore/Verifier.cpp +++ b/llvm/lib/VMCore/Verifier.cpp @@ -1590,9 +1590,10 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) { default: break; case Intrinsic::dbg_declare: // llvm.dbg.declare - if (Constant *C = dyn_cast(CI.getOperand(1))) - Assert1(C && !isa(C), - "invalid llvm.dbg.declare intrinsic call", &CI); + if (MDNode *MD = dyn_cast(CI.getOperand(1))) + if (Constant *C = dyn_cast(MD->getOperand(0))) + Assert1(C && !isa(C), + "invalid llvm.dbg.declare intrinsic call", &CI); break; case Intrinsic::memcpy: case Intrinsic::memmove: diff --git a/llvm/test/Assembler/functionlocal-metadata.ll b/llvm/test/Assembler/functionlocal-metadata.ll index 9d83304e892c..16bc9d06c16d 100644 --- a/llvm/test/Assembler/functionlocal-metadata.ll +++ b/llvm/test/Assembler/functionlocal-metadata.ll @@ -5,23 +5,28 @@ entry: %0 = add i32 %a, 1 ; [#uses=1] %two = add i32 %b, %0 ; [#uses=0] %1 = alloca i32 ; [#uses=1] - %three = bitcast i32* %1 to { }* ; <{ }*> [#uses=6] - call void @llvm.dbg.declare({ }* %three, metadata !{i32* %1}) -; CHECK: metadata !{i32* %1} - call void @llvm.dbg.declare({ }* %three, metadata !{{ }* %three}) - call void @llvm.dbg.declare({ }* %three, metadata !{i32 %0}) - call void @llvm.dbg.declare({ }* %three, metadata !{{ }* %three, i32 %0}) - call void @llvm.dbg.declare({ }* %three, metadata !{i32 %b, i32 %0}) - call void @llvm.dbg.declare({ }* %three, metadata !{i32 %a, metadata !"foo"}) -; CHECK: metadata !{i32 %a, metadata !"foo"} - call void @llvm.dbg.declare({ }* %three, metadata !{metadata !0, i32 %two}) + call void @llvm.dbg.declare(metadata !{i32* %1}, metadata !{i32* %1}) +; CHECK: metadata !{i32* %1}, metadata !{i32* %1} + call void @llvm.dbg.declare(metadata !{i32 %two}, metadata !{i32 %0}) +; CHECK: metadata !{i32 %two}, metadata !{i32 %0} + call void @llvm.dbg.declare(metadata !{i32 %0}, metadata !{i32* %1, i32 %0}) +; CHECK: metadata !{i32 %0}, metadata !{i32* %1, i32 %0} + call void @llvm.dbg.declare(metadata !{i32* %1}, metadata !{i32 %b, i32 %0}) +; CHECK: metadata !{i32* %1}, metadata !{i32 %b, i32 %0} + call void @llvm.dbg.declare(metadata !{i32 %a}, metadata !{i32 %a, metadata !"foo"}) +; CHECK: metadata !{i32 %a}, metadata !{i32 %a, metadata !"foo"} + call void @llvm.dbg.declare(metadata !{i32 %b}, metadata !{metadata !0, i32 %two}) +; CHECK: metadata !{i32 %b}, metadata !{metadata !0, i32 %two} call void @llvm.dbg.value(metadata !{ i32 %a }, i64 0, metadata !1) +; CHECK: metadata !{i32 %a}, i64 0, metadata !1 call void @llvm.dbg.value(metadata !{ i32 %0 }, i64 25, metadata !0) +; CHECK: metadata !{i32 %0}, i64 25, metadata !0 call void @llvm.dbg.value(metadata !{ i32* %1 }, i64 16, metadata !"foo") ; CHECK: call void @llvm.dbg.value(metadata !{i32* %1}, i64 16, metadata !"foo") - call void @llvm.dbg.value(metadata !{ { }* %three }, i64 12, metadata !"bar") + call void @llvm.dbg.value(metadata !"foo", i64 12, metadata !"bar") +; CHECK: metadata !"foo", i64 12, metadata !"bar" ret void, !foo !0, !bar !1 ; CHECK: ret void, !foo !0, !bar !1 @@ -30,7 +35,7 @@ entry: !0 = metadata !{i32 662302, i32 26, metadata !1, null} !1 = metadata !{i32 4, metadata !"foo"} -declare void @llvm.dbg.declare({ }*, metadata) nounwind readnone +declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone declare void @llvm.dbg.value(metadata, i64, metadata) nounwind readnone !foo = !{ !0 } diff --git a/llvm/test/DebugInfo/2009-10-16-Scope.ll b/llvm/test/DebugInfo/2009-10-16-Scope.ll index ea43249668a4..9f9fa65d5b79 100644 --- a/llvm/test/DebugInfo/2009-10-16-Scope.ll +++ b/llvm/test/DebugInfo/2009-10-16-Scope.ll @@ -9,8 +9,7 @@ entry: br label %do.body, !dbg !0 do.body: ; preds = %entry - %0 = bitcast i32* %count_ to { }* ; <{ }*> [#uses=1] - call void @llvm.dbg.declare({ }* %0, metadata !4) + call void @llvm.dbg.declare(metadata !{i32* %count_}, metadata !4) %conv = ptrtoint i32* %count_ to i32, !dbg !0 ; [#uses=1] %call = call i32 @foo(i32 %conv) ssp, !dbg !0 ; [#uses=0] br label %do.end, !dbg !0 @@ -19,7 +18,7 @@ do.end: ; preds = %do.body ret void, !dbg !7 } -declare void @llvm.dbg.declare({ }*, metadata) nounwind readnone +declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone declare i32 @foo(i32) ssp diff --git a/llvm/test/DebugInfo/printdbginfo2.ll b/llvm/test/DebugInfo/printdbginfo2.ll index 759310fc9f59..e19395b0df1f 100644 --- a/llvm/test/DebugInfo/printdbginfo2.ll +++ b/llvm/test/DebugInfo/printdbginfo2.ll @@ -19,11 +19,11 @@ entry: call void @llvm.dbg.stoppoint(i32 6, i32 3, metadata !1) call void @llvm.dbg.stoppoint(i32 7, i32 3, metadata !1) %0 = bitcast %struct.foo* %b to { }* ; <{ }*> [#uses=1] - call void @llvm.dbg.declare({ }* %0, metadata !4) + call void @llvm.dbg.declare(metadata !{%struct.foo* %b}, metadata !4) ; CHECK:; %0 is variable b of type foo declared at x.c:7 call void @llvm.dbg.stoppoint(i32 8, i32 3, metadata !1) %1 = bitcast [4 x i32]* %a to { }* ; <{ }*> [#uses=1] - call void @llvm.dbg.declare({ }* %1, metadata !8) + call void @llvm.dbg.declare(metadata !{[4 x i32]* %a}, metadata !8) ; CHECK:; %1 is variable a of type declared at x.c:8 call void @llvm.dbg.stoppoint(i32 9, i32 3, metadata !1) %tmp = getelementptr inbounds %struct.foo* %b, i32 0, i32 0 ; [#uses=1] @@ -46,7 +46,7 @@ declare void @llvm.dbg.func.start(metadata) nounwind readnone declare void @llvm.dbg.stoppoint(i32, i32, metadata) nounwind readnone -declare void @llvm.dbg.declare({ }*, metadata) nounwind readnone +declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone declare void @llvm.dbg.region.end(metadata) nounwind readnone