llvm.org GIT mirror llvm / 5f03238
Revert r93504 because older uses of llvm.dbg.declare intrinsics need to be auto-upgraded git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93515 91177308-0d34-0410-b5e6-96231b3b80d8 Victor Hernandez 9 years ago
9 changed file(s) with 55 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
490490 Module &M;
491491 LLVMContext& VMContext;
492492
493 const Type *EmptyStructPtr; // "{}*".
493494 Function *DeclareFn; // llvm.dbg.declare
494495 Function *ValueFn; // llvm.dbg.value
495496
657658
658659 /// Finds the dbg.declare intrinsic corresponding to this value if any.
659660 /// It looks through pointer casts too.
660 const DbgDeclareInst *findDbgDeclare(const Value *V);
661 const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts = true);
661662
662663 /// Find the debug info descriptor corresponding to this global variable.
663664 Value *findDbgGlobalDeclare(GlobalVariable *V);
2424 #define LLVM_INTRINSICINST_H
2525
2626 #include "llvm/Constants.h"
27 #include "llvm/Metadata.h"
2827 #include "llvm/Function.h"
2928 #include "llvm/Instructions.h"
3029 #include "llvm/Intrinsics.h"
8281 ///
8382 class DbgDeclareInst : public DbgInfoIntrinsic {
8483 public:
85 Value *getAddress() const {
86 if (MDNode* MD = dyn_cast(getOperand(1)))
87 return MD->getOperand(0);
88 else
89 return NULL;
90 }
84 Value *getAddress() const { return getOperand(1); }
9185 MDNode *getVariable() const { return cast(getOperand(2)); }
9286
9387 // Methods for support type inquiry through isa, cast, and dyn_cast:
282282 // places.
283283 let Properties = [IntrNoMem] in {
284284 def int_dbg_declare : Intrinsic<[llvm_void_ty],
285 [llvm_metadata_ty, llvm_metadata_ty]>;
285 [llvm_descriptor_ty, llvm_metadata_ty]>;
286286 def int_dbg_value : Intrinsic<[llvm_void_ty],
287287 [llvm_metadata_ty, llvm_i64_ty,
288288 llvm_metadata_ty]>;
598598 //===----------------------------------------------------------------------===//
599599
600600 DIFactory::DIFactory(Module &m)
601 : M(m), VMContext(M.getContext()), DeclareFn(0) {}
601 : M(m), VMContext(M.getContext()), DeclareFn(0) {
602 EmptyStructPtr = PointerType::getUnqual(StructType::get(VMContext));
603 }
602604
603605 Constant *DIFactory::GetTagConstant(unsigned TAG) {
604606 assert((TAG & LLVMDebugVersionMask) == 0 &&
10311033 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
10321034 Instruction *DIFactory::InsertDeclare(Value *Storage, DIVariable D,
10331035 Instruction *InsertBefore) {
1036 // Cast the storage to a {}* for the call to llvm.dbg.declare.
1037 Storage = new BitCastInst(Storage, EmptyStructPtr, "", InsertBefore);
1038
10341039 if (!DeclareFn)
10351040 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
10361041
1037 Value *Elts[] = { Storage };
1038 Value *Args[] = { MDNode::get(Storage->getContext(), Elts, 1), D.getNode() };
1042 Value *Args[] = { Storage, D.getNode() };
10391043 return CallInst::Create(DeclareFn, Args, Args+2, "", InsertBefore);
10401044 }
10411045
10421046 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
10431047 Instruction *DIFactory::InsertDeclare(Value *Storage, DIVariable D,
10441048 BasicBlock *InsertAtEnd) {
1049 // Cast the storage to a {}* for the call to llvm.dbg.declare.
1050 Storage = new BitCastInst(Storage, EmptyStructPtr, "", InsertAtEnd);
1051
10451052 if (!DeclareFn)
10461053 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
10471054
1048 Value *Elts[] = { Storage };
1049 Value *Args[] = { MDNode::get(Storage->getContext(), Elts, 1), D.getNode() };
1055 Value *Args[] = { Storage, D.getNode() };
10501056 return CallInst::Create(DeclareFn, Args, Args+2, "", InsertAtEnd);
10511057 }
10521058
12511257
12521258 /// Finds the llvm.dbg.declare intrinsic corresponding to this value if any.
12531259 /// It looks through pointer casts too.
1254 const DbgDeclareInst *llvm::findDbgDeclare(const Value *V) {
1255 V = V->stripPointerCasts();
1256
1257 if (!isa(V) && !isa(V))
1260 const DbgDeclareInst *llvm::findDbgDeclare(const Value *V, bool stripCasts) {
1261 if (stripCasts) {
1262 V = V->stripPointerCasts();
1263
1264 // Look for the bitcast.
1265 for (Value::use_const_iterator I = V->use_begin(), E =V->use_end();
1266 I != E; ++I)
1267 if (isa(I)) {
1268 const DbgDeclareInst *DDI = findDbgDeclare(*I, false);
1269 if (DDI) return DDI;
1270 }
12581271 return 0;
1259
1260 const Function *F = NULL;
1261 if (const Instruction *I = dyn_cast(V))
1262 F = I->getParent()->getParent();
1263 else if (const Argument *A = dyn_cast(V))
1264 F = A->getParent();
1265
1266 for (Function::const_iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI)
1267 for (BasicBlock::const_iterator BI = (*FI).begin(), BE = (*FI).end();
1268 BI != BE; ++BI)
1269 if (const DbgDeclareInst *DDI = dyn_cast(BI))
1270 if (DDI->getAddress() == V)
1271 return DDI;
1272 }
1273
1274 // Find llvm.dbg.declare among uses of the instruction.
1275 for (Value::use_const_iterator I = V->use_begin(), E =V->use_end();
1276 I != E; ++I)
1277 if (const DbgDeclareInst *DDI = dyn_cast(I))
1278 return DDI;
12721279
12731280 return 0;
12741281 }
331331 return true;
332332
333333 Value *Address = DI->getAddress();
334 if (BitCastInst *BCI = dyn_cast(Address))
335 Address = BCI->getOperand(0);
334336 AllocaInst *AI = dyn_cast(Address);
335337 // Don't handle byval struct arguments or VLAs, for example.
336338 if (!AI) break;
15891589 default:
15901590 break;
15911591 case Intrinsic::dbg_declare: // llvm.dbg.declare
1592 if (MDNode *MD = dyn_cast(CI.getOperand(1)))
1593 if (Constant *C = dyn_cast(MD->getOperand(0)))
1594 Assert1(C && !isa(C),
1595 "invalid llvm.dbg.declare intrinsic call", &CI);
1592 if (Constant *C = dyn_cast(CI.getOperand(1)))
1593 Assert1(C && !isa(C),
1594 "invalid llvm.dbg.declare intrinsic call", &CI);
15961595 break;
15971596 case Intrinsic::memcpy:
15981597 case Intrinsic::memmove:
44 %0 = add i32 %a, 1 ; [#uses=1]
55 %two = add i32 %b, %0 ; [#uses=0]
66 %1 = alloca i32 ; [#uses=1]
7 %three = bitcast i32* %1 to { }* ; <{ }*> [#uses=6]
78
8 call void @llvm.dbg.declare(metadata !{i32* %1}, metadata !{i32* %1})
9 ; CHECK: metadata !{i32* %1}, metadata !{i32* %1}
10 call void @llvm.dbg.declare(metadata !{i32 %two}, metadata !{i32 %0})
11 call void @llvm.dbg.declare(metadata !{i32 %0}, metadata !{i32* %1, i32 %0})
12 call void @llvm.dbg.declare(metadata !{i32* %1}, metadata !{i32 %b, i32 %0})
13 call void @llvm.dbg.declare(metadata !{i32 %a}, metadata !{i32 %a, metadata !"foo"})
9 call void @llvm.dbg.declare({ }* %three, metadata !{i32* %1})
10 ; CHECK: metadata !{i32* %1}
11 call void @llvm.dbg.declare({ }* %three, metadata !{{ }* %three})
12 call void @llvm.dbg.declare({ }* %three, metadata !{i32 %0})
13 call void @llvm.dbg.declare({ }* %three, metadata !{{ }* %three, i32 %0})
14 call void @llvm.dbg.declare({ }* %three, metadata !{i32 %b, i32 %0})
15 call void @llvm.dbg.declare({ }* %three, metadata !{i32 %a, metadata !"foo"})
1416 ; CHECK: metadata !{i32 %a, metadata !"foo"}
15 call void @llvm.dbg.declare(metadata !{i32 %b}, metadata !{metadata !0, i32 %two})
17 call void @llvm.dbg.declare({ }* %three, metadata !{metadata !0, i32 %two})
1618
1719 call void @llvm.dbg.value(metadata !{ i32 %a }, i64 0, metadata !1)
1820 call void @llvm.dbg.value(metadata !{ i32 %0 }, i64 25, metadata !0)
1921 call void @llvm.dbg.value(metadata !{ i32* %1 }, i64 16, metadata !"foo")
2022 ; CHECK: call void @llvm.dbg.value(metadata !{i32* %1}, i64 16, metadata !"foo")
21 call void @llvm.dbg.value(metadata !"foo", i64 12, metadata !"bar")
23 call void @llvm.dbg.value(metadata !{ { }* %three }, i64 12, metadata !"bar")
2224
2325 ret void, !foo !0, !bar !1
2426 ; CHECK: ret void, !foo !0, !bar !1
2729 !0 = metadata !{i32 662302, i32 26, metadata !1, null}
2830 !1 = metadata !{i32 4, metadata !"foo"}
2931
30 declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
32 declare void @llvm.dbg.declare({ }*, metadata) nounwind readnone
3133 declare void @llvm.dbg.value(metadata, i64, metadata) nounwind readnone
3234
3335 !foo = !{ !0 }
88 br label %do.body, !dbg !0
99
1010 do.body: ; preds = %entry
11 call void @llvm.dbg.declare(metadata !{i32* %count_}, metadata !4)
11 %0 = bitcast i32* %count_ to { }* ; <{ }*> [#uses=1]
12 call void @llvm.dbg.declare({ }* %0, metadata !4)
1213 %conv = ptrtoint i32* %count_ to i32, !dbg !0 ; [#uses=1]
1314 %call = call i32 @foo(i32 %conv) ssp, !dbg !0 ; [#uses=0]
1415 br label %do.end, !dbg !0
1718 ret void, !dbg !7
1819 }
1920
20 declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
21 declare void @llvm.dbg.declare({ }*, metadata) nounwind readnone
2122
2223 declare i32 @foo(i32) ssp
2324
1818 call void @llvm.dbg.stoppoint(i32 6, i32 3, metadata !1)
1919 call void @llvm.dbg.stoppoint(i32 7, i32 3, metadata !1)
2020 %0 = bitcast %struct.foo* %b to { }* ; <{ }*> [#uses=1]
21 call void @llvm.dbg.declare(metadata !{%struct.foo* %b}, metadata !4)
21 call void @llvm.dbg.declare({ }* %0, metadata !4)
2222 ; CHECK:; %0 is variable b of type foo declared at x.c:7
2323 call void @llvm.dbg.stoppoint(i32 8, i32 3, metadata !1)
2424 %1 = bitcast [4 x i32]* %a to { }* ; <{ }*> [#uses=1]
25 call void @llvm.dbg.declare(metadata !{[4 x i32]* %a}, metadata !8)
25 call void @llvm.dbg.declare({ }* %1, metadata !8)
2626 ; CHECK:; %1 is variable a of type declared at x.c:8
2727 call void @llvm.dbg.stoppoint(i32 9, i32 3, metadata !1)
2828 %tmp = getelementptr inbounds %struct.foo* %b, i32 0, i32 0 ; [#uses=1]
4545
4646 declare void @llvm.dbg.stoppoint(i32, i32, metadata) nounwind readnone
4747
48 declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
48 declare void @llvm.dbg.declare({ }*, metadata) nounwind readnone
4949
5050 declare void @llvm.dbg.region.end(metadata) nounwind readnone
5151