llvm.org GIT mirror llvm / 4b02ed3
Revert r313825: "[IR] Add llvm.dbg.addr, a control-dependent version of llvm.dbg.declare" .. as well as the two subsequent changes r313826 and r313875. This leads to segfaults in combination with ASAN. Will forward repro instructions to the original author (rnk). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313876 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Jasper 2 years ago
18 changed file(s) with 138 addition(s) and 780 deletion(s). Raw diff Collapse all Expand all
170170 ----------------------------
171171
172172 LLVM uses several intrinsic functions (name prefixed with "``llvm.dbg``") to
173 track source local variables through optimization and code generation.
174
175 ``llvm.dbg.addr``
173 provide debug information at various points in generated code.
174
175 ``llvm.dbg.declare``
176176 ^^^^^^^^^^^^^^^^^^^^
177177
178178 .. code-block:: llvm
179179
180 void @llvm.dbg.addr(metadata, metadata, metadata)
181
182 This intrinsic provides information about a local element (e.g., variable).
183 The first argument is metadata holding the address of variable, typically a
184 static alloca in the function entry block. The second argument is a
185 `local variable `_ containing a description of
186 the variable. The third argument is a `complex expression
187 `_. An `llvm.dbg.addr` intrinsic describes the
188 *address* of a source variable.
180 void @llvm.dbg.declare(metadata, metadata, metadata)
181
182 This intrinsic provides information about a local element (e.g., variable). The
183 first argument is metadata holding the alloca for the variable. The second
184 argument is a `local variable `_ containing a
185 description of the variable. The third argument is a `complex expression
186 `_. An `llvm.dbg.declare` instrinsic describes the
187 *location* of a source variable.
189188
190189 .. code-block:: llvm
191190
192191 %i.addr = alloca i32, align 4
193 call void @llvm.dbg.addr(metadata i32* %i.addr, metadata !1,
194 metadata !DIExpression()), !dbg !2
192 call void @llvm.dbg.declare(metadata i32* %i.addr, metadata !1, metadata !2), !dbg !3
195193 !1 = !DILocalVariable(name: "i", ...) ; int i
196 !2 = !DILocation(...)
194 !2 = !DIExpression()
195 !3 = !DILocation(...)
197196 ...
198197 %buffer = alloca [256 x i8], align 8
199198 ; The address of i is buffer+64.
200 call void @llvm.dbg.addr(metadata [256 x i8]* %buffer, metadata !3,
201 metadata !DIExpression(DW_OP_plus, 64)), !dbg !4
202 !3 = !DILocalVariable(name: "i", ...) ; int i
203 !4 = !DILocation(...)
204
205 A frontend should generate exactly one call to ``llvm.dbg.addr`` at the point
206 of declaration of a source variable. Optimization passes that fully promote the
207 variable from memory to SSA values will replace this call with possibly
208 multiple calls to `llvm.dbg.value`. Passes that delete stores are effectively
209 partial promotion, and they will insert a mix of calls to ``llvm.dbg.value``
210 and ``llvm.dbg.addr`` to track the source variable value when it is available.
211 After optimization, there may be multiple calls to ``llvm.dbg.addr`` describing
212 the program points where the variables lives in memory. All calls for the same
213 concrete source variable must agree on the memory location.
214
215
216 ``llvm.dbg.declare``
217 ^^^^^^^^^^^^^^^^^^^^
218
219 .. code-block:: llvm
220
221 void @llvm.dbg.declare(metadata, metadata, metadata)
222
223 This intrinsic is identical to `llvm.dbg.addr`, except that there can only be
224 one call to `llvm.dbg.declare` for a given concrete `local variable
225 `_. It is not control-dependent, meaning that if
226 a call to `llvm.dbg.declare` exists and has a valid location argument, that
227 address is considered to be the true home of the variable across its entire
228 lifetime. This makes it hard for optimizations to preserve accurate debug info
229 in the presence of ``llvm.dbg.declare``, so we are transitioning away from it,
230 and we plan to deprecate it in future LLVM releases.
199 call void @llvm.dbg.declare(metadata [256 x i8]* %buffer, metadata !1, metadata !2)
200 !1 = !DILocalVariable(name: "i", ...) ; int i
201 !2 = !DIExpression(DW_OP_plus, 64)
231202
232203
233204 ``llvm.dbg.value``
269240 7. }
270241 8. X = Y;
271242 9. }
272
273 .. FIXME: Update the following example to use llvm.dbg.addr once that is the
274 default in clang.
275243
276244 Compiled to LLVM, this function would be represented like this:
277245
7070 /// variable's value or its address.
7171 Value *getVariableLocation(bool AllowNullOp = true) const;
7272
73 /// Does this describe the address of a local variable. True for dbg.addr
74 /// and dbg.declare, but not dbg.value, which describes its value.
75 bool isAddressOfVariable() const {
76 return getIntrinsicID() != Intrinsic::dbg_value;
77 }
78
7973 DILocalVariable *getVariable() const {
8074 return cast(getRawVariable());
8175 }
9286 return cast(getArgOperand(2))->getMetadata();
9387 }
9488
95 /// \name Casting methods
96 /// @{
89 // Methods for support type inquiry through isa, cast, and dyn_cast:
9790 static bool classof(const IntrinsicInst *I) {
9891 switch (I->getIntrinsicID()) {
9992 case Intrinsic::dbg_declare:
10093 case Intrinsic::dbg_value:
101 case Intrinsic::dbg_addr:
10294 return true;
10395 default: return false;
10496 }
10698 static bool classof(const Value *V) {
10799 return isa(V) && classof(cast(V));
108100 }
109 /// @}
110101 };
111102
112103 /// This represents the llvm.dbg.declare instruction.
114105 public:
115106 Value *getAddress() const { return getVariableLocation(); }
116107
117 /// \name Casting methods
118 /// @{
108 // Methods for support type inquiry through isa, cast, and dyn_cast:
119109 static bool classof(const IntrinsicInst *I) {
120110 return I->getIntrinsicID() == Intrinsic::dbg_declare;
121 }
122 static bool classof(const Value *V) {
123 return isa(V) && classof(cast(V));
124 }
125 /// @}
126 };
127
128 /// This represents the llvm.dbg.addr instruction.
129 class DbgAddrIntrinsic : public DbgInfoIntrinsic {
130 public:
131 Value *getAddress() const { return getVariableLocation(); }
132
133 /// \name Casting methods
134 /// @{
135 static bool classof(const IntrinsicInst *I) {
136 return I->getIntrinsicID() == Intrinsic::dbg_addr;
137111 }
138112 static bool classof(const Value *V) {
139113 return isa(V) && classof(cast(V));
147121 return getVariableLocation(/* AllowNullOp = */ false);
148122 }
149123
150 /// \name Casting methods
151 /// @{
124 // Methods for support type inquiry through isa, cast, and dyn_cast:
152125 static bool classof(const IntrinsicInst *I) {
153126 return I->getIntrinsicID() == Intrinsic::dbg_value;
154127 }
155128 static bool classof(const Value *V) {
156129 return isa(V) && classof(cast(V));
157130 }
158 /// @}
159131 };
160132
161133 /// This is the common base class for constrained floating point intrinsics.
582582 let IntrProperties = [IntrNoMem, IntrSpeculatable] in {
583583 def int_dbg_declare : Intrinsic<[],
584584 [llvm_metadata_ty,
585 llvm_metadata_ty,
586 llvm_metadata_ty]>;
585 llvm_metadata_ty,
586 llvm_metadata_ty]>;
587587 def int_dbg_value : Intrinsic<[],
588 [llvm_metadata_ty,
589 llvm_metadata_ty,
590 llvm_metadata_ty]>;
591 def int_dbg_addr : Intrinsic<[],
592588 [llvm_metadata_ty,
593589 llvm_metadata_ty,
594590 llvm_metadata_ty]>;
1515 #define LLVM_TRANSFORMS_UTILS_LOCAL_H
1616
1717 #include "llvm/ADT/SmallPtrSet.h"
18 #include "llvm/ADT/TinyPtrVector.h"
1918 #include "llvm/Analysis/AliasAnalysis.h"
2019 #include "llvm/IR/DataLayout.h"
2120 #include "llvm/IR/Dominators.h"
3231 class Instruction;
3332 class CallInst;
3433 class DbgDeclareInst;
35 class DbgInfoIntrinsic;
3634 class DbgValueInst;
3735 class StoreInst;
3836 class LoadInst;
263261 ///
264262
265263 /// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value
266 /// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
267 void ConvertDebugDeclareToDebugValue(DbgInfoIntrinsic *DII,
264 /// that has an associated llvm.dbg.decl intrinsic.
265 void ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI,
268266 StoreInst *SI, DIBuilder &Builder);
269267
270268 /// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value
271 /// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
272 void ConvertDebugDeclareToDebugValue(DbgInfoIntrinsic *DII,
269 /// that has an associated llvm.dbg.decl intrinsic.
270 void ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI,
273271 LoadInst *LI, DIBuilder &Builder);
274272
275 /// Inserts a llvm.dbg.value intrinsic after a phi that has an associated
276 /// llvm.dbg.declare or llvm.dbg.addr intrinsic.
277 void ConvertDebugDeclareToDebugValue(DbgInfoIntrinsic *DII,
273 /// Inserts a llvm.dbg.value intrinsic after a phi of an alloca'd value
274 /// that has an associated llvm.dbg.decl intrinsic.
275 void ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI,
278276 PHINode *LI, DIBuilder &Builder);
279277
280278 /// Lowers llvm.dbg.declare intrinsics into appropriate set of
281279 /// llvm.dbg.value intrinsics.
282280 bool LowerDbgDeclare(Function &F);
283281
284 /// Finds all intrinsics declaring local variables as living in the memory that
285 /// 'V' points to. This may include a mix of dbg.declare and
286 /// dbg.addr intrinsics.
287 TinyPtrVector FindDbgAddrUses(Value *V);
282 /// Finds the llvm.dbg.declare intrinsic corresponding to an alloca, if any.
283 DbgDeclareInst *FindAllocaDbgDeclare(Value *V);
288284
289285 /// Finds the llvm.dbg.value intrinsics describing a value.
290286 void findDbgValues(SmallVectorImpl &DbgValues, Value *V);
51085108 DAG.setRoot(CallResult.second);
51095109 return nullptr;
51105110 }
5111 case Intrinsic::dbg_addr:
51125111 case Intrinsic::dbg_declare: {
5113 const DbgInfoIntrinsic &DI = cast>(I);
5112 const DbgDeclareInst &DI = cast>(I);
51145113 DILocalVariable *Variable = DI.getVariable();
51155114 DIExpression *Expression = DI.getExpression();
5115 const Value *Address = DI.getAddress();
51165116 assert(Variable && "Missing variable");
5117 if (!Address) {
5118 DEBUG(dbgs() << "Dropping debug info for " << DI << "\n");
5119 return nullptr;
5120 }
51175121
51185122 // Check if address has undef value.
5119 const Value *Address = DI.getVariableLocation();
5120 if (!Address || isa(Address) ||
5123 if (isa(Address) ||
51215124 (Address->use_empty() && !isa(Address))) {
51225125 DEBUG(dbgs() << "Dropping debug info for " << DI << "\n");
51235126 return nullptr;
51245127 }
51255128
5126 bool isParameter = Variable->isParameter() || isa(Address);
5127
5128 // Check if this variable can be described by a frame index, typically
5129 // either as a static alloca or a byval parameter.
5130 int FI = INT_MAX;
5129 // Static allocas are handled more efficiently in the variable frame index
5130 // side table.
51315131 if (const auto *AI =
5132 dyn_cast(Address->stripInBoundsConstantOffsets())) {
5133 if (AI->isStaticAlloca()) {
5134 auto I = FuncInfo.StaticAllocaMap.find(AI);
5135 if (I != FuncInfo.StaticAllocaMap.end())
5136 FI = I->second;
5137 }
5138 } else if (const auto *Arg = dyn_cast(
5139 Address->stripInBoundsConstantOffsets())) {
5140 FI = FuncInfo.getArgumentFrameIndex(Arg);
5141 }
5142
5143 // llvm.dbg.addr is control dependent and always generates indirect
5144 // DBG_VALUE instructions. llvm.dbg.declare is handled as a frame index in
5145 // the MachineFunction variable table.
5146 if (FI != INT_MAX) {
5147 if (Intrinsic == Intrinsic::dbg_addr)
5148 DAG.AddDbgValue(DAG.getFrameIndexDbgValue(Variable, Expression, FI, dl,
5149 SDNodeOrder),
5150 getRoot().getNode(), isParameter);
5151 return nullptr;
5152 }
5132 dyn_cast(Address->stripInBoundsConstantOffsets()))
5133 if (AI->isStaticAlloca() && FuncInfo.StaticAllocaMap.count(AI))
5134 return nullptr;
5135
5136 // Byval arguments with frame indices were already handled after argument
5137 // lowering and before isel.
5138 if (const auto *Arg =
5139 dyn_cast(Address->stripInBoundsConstantOffsets()))
5140 if (FuncInfo.getArgumentFrameIndex(Arg) != INT_MAX)
5141 return nullptr;
51535142
51545143 SDValue &N = NodeMap[Address];
51555144 if (!N.getNode() && isa(Address))
51605149 if (const BitCastInst *BCI = dyn_cast(Address))
51615150 Address = BCI->getOperand(0);
51625151 // Parameters are handled specially.
5152 bool isParameter = Variable->isParameter() || isa(Address);
51635153 auto FINode = dyn_cast(N.getNode());
51645154 if (isParameter && FINode) {
51655155 // Byval parameter. We have a frame index at this point.
2222
2323 using namespace llvm;
2424 using namespace llvm::dwarf;
25
26 cl::opt
27 UseDbgAddr("use-dbg-addr",
28 llvm::cl::desc("Use llvm.dbg.addr for all local variables"),
29 cl::init(false));
3025
3126 DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes)
3227 : M(m), VMContext(M.getContext()), CUNode(nullptr),
780775 return I;
781776 }
782777
783 static Function *getDeclareIntrin(Module &M) {
784 return Intrinsic::getDeclaration(&M, UseDbgAddr ? Intrinsic::dbg_addr
785 : Intrinsic::dbg_declare);
786 }
787
788778 Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
789779 DIExpression *Expr, const DILocation *DL,
790780 Instruction *InsertBefore) {
794784 VarInfo->getScope()->getSubprogram() &&
795785 "Expected matching subprograms");
796786 if (!DeclareFn)
797 DeclareFn = getDeclareIntrin(M);
787 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
798788
799789 trackIfUnresolved(VarInfo);
800790 trackIfUnresolved(Expr);
813803 VarInfo->getScope()->getSubprogram() &&
814804 "Expected matching subprograms");
815805 if (!DeclareFn)
816 DeclareFn = getDeclareIntrin(M);
806 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
817807
818808 trackIfUnresolved(VarInfo);
819809 trackIfUnresolved(Expr);
40004000 "invalid llvm.dbg.declare intrinsic call 1", CS);
40014001 visitDbgIntrinsic("declare", cast(*CS.getInstruction()));
40024002 break;
4003 case Intrinsic::dbg_addr: // llvm.dbg.addr
4004 visitDbgIntrinsic("addr", cast(*CS.getInstruction()));
40054003 case Intrinsic::dbg_value: // llvm.dbg.value
40064004 visitDbgIntrinsic("value", cast(*CS.getInstruction()));
40074005 break;
21052105
21062106 // If we are removing an alloca with a dbg.declare, insert dbg.value calls
21072107 // before each store.
2108 TinyPtrVector DIIs;
2108 DbgDeclareInst *DDI = nullptr;
21092109 std::unique_ptr DIB;
21102110 if (isa(MI)) {
2111 DIIs = FindDbgAddrUses(&MI);
2111 DDI = FindAllocaDbgDeclare(&MI);
21122112 DIB.reset(new DIBuilder(*MI.getModule(), /*AllowUnresolved=*/false));
21132113 }
21142114
21442144 } else if (isa(I) || isa(I) ||
21452145 isa(I)) {
21462146 replaceInstUsesWith(*I, UndefValue::get(I->getType()));
2147 } else if (auto *SI = dyn_cast(I)) {
2148 for (auto *DII : DIIs)
2149 ConvertDebugDeclareToDebugValue(DII, SI, *DIB);
2147 } else if (DDI && isa(I)) {
2148 ConvertDebugDeclareToDebugValue(DDI, cast(I), *DIB);
21502149 }
21512150 eraseInstFromFunction(*I);
21522151 }
21592158 None, "", II->getParent());
21602159 }
21612160
2162 for (auto *DII : DIIs)
2163 eraseInstFromFunction(*DII);
2161 if (DDI)
2162 eraseInstFromFunction(*DDI);
21642163
21652164 return eraseInstFromFunction(MI);
21662165 }
41014101
41024102 // Migrate debug information from the old alloca to the new alloca(s)
41034103 // and the individual partitions.
4104 TinyPtrVector DbgDeclares = FindDbgAddrUses(&AI);
4105 if (!DbgDeclares.empty()) {
4106 auto *Var = DbgDeclares.front()->getVariable();
4107 auto *Expr = DbgDeclares.front()->getExpression();
4104 if (DbgDeclareInst *DbgDecl = FindAllocaDbgDeclare(&AI)) {
4105 auto *Var = DbgDecl->getVariable();
4106 auto *Expr = DbgDecl->getExpression();
41084107 DIBuilder DIB(*AI.getModule(), /*AllowUnresolved*/ false);
41094108 uint64_t AllocaSize = DL.getTypeSizeInBits(AI.getAllocatedType());
41104109 for (auto Fragment : Fragments) {
41364135 DIExpression::createFragmentExpression(Expr, Start, Size);
41374136 }
41384137
4139 // Remove any existing intrinsics describing the same alloca.
4140 for (DbgInfoIntrinsic *OldDII : FindDbgAddrUses(Fragment.Alloca))
4141 OldDII->eraseFromParent();
4138 // Remove any existing dbg.declare intrinsic describing the same alloca.
4139 if (DbgDeclareInst *OldDDI = FindAllocaDbgDeclare(Fragment.Alloca))
4140 OldDDI->eraseFromParent();
41424141
41434142 DIB.insertDeclare(Fragment.Alloca, Var, FragmentExpr,
4144 DbgDeclares.front()->getDebugLoc(), &AI);
4143 DbgDecl->getDebugLoc(), &AI);
41454144 }
41464145 }
41474146 return Changed;
42464245 Instruction *I = DeadInsts.pop_back_val();
42474246 DEBUG(dbgs() << "Deleting dead instruction: " << *I << "\n");
42484247
4249 // If the instruction is an alloca, find the possible dbg.declare connected
4250 // to it, and remove it too. We must do this before calling RAUW or we will
4251 // not be able to find it.
4252 if (AllocaInst *AI = dyn_cast(I)) {
4253 DeletedAllocas.insert(AI);
4254 for (DbgInfoIntrinsic *OldDII : FindDbgAddrUses(AI))
4255 OldDII->eraseFromParent();
4256 }
4257
42584248 I->replaceAllUsesWith(UndefValue::get(I->getType()));
42594249
42604250 for (Use &Operand : I->operands())
42644254 if (isInstructionTriviallyDead(U))
42654255 DeadInsts.insert(U);
42664256 }
4257
4258 if (AllocaInst *AI = dyn_cast(I)) {
4259 DeletedAllocas.insert(AI);
4260 if (DbgDeclareInst *DbgDecl = FindAllocaDbgDeclare(AI))
4261 DbgDecl->eraseFromParent();
4262 }
42674263
42684264 ++NumDeleted;
42694265 I->eraseFromParent();
10971097 }
10981098
10991099 /// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value
1100 /// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
1101 void llvm::ConvertDebugDeclareToDebugValue(DbgInfoIntrinsic *DII,
1100 /// that has an associated llvm.dbg.decl intrinsic.
1101 void llvm::ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI,
11021102 StoreInst *SI, DIBuilder &Builder) {
1103 assert(DII->isAddressOfVariable());
1104 auto *DIVar = DII->getVariable();
1103 auto *DIVar = DDI->getVariable();
11051104 assert(DIVar && "Missing variable");
1106 auto *DIExpr = DII->getExpression();
1105 auto *DIExpr = DDI->getExpression();
11071106 Value *DV = SI->getOperand(0);
11081107
11091108 // If an argument is zero extended then use argument directly. The ZExt
11141113 if (SExtInst *SExt = dyn_cast(SI->getOperand(0)))
11151114 ExtendedArg = dyn_cast(SExt->getOperand(0));
11161115 if (ExtendedArg) {
1117 // If this DII was already describing only a fragment of a variable, ensure
1116 // If this DDI was already describing only a fragment of a variable, ensure
11181117 // that fragment is appropriately narrowed here.
11191118 // But if a fragment wasn't used, describe the value as the original
11201119 // argument (rather than the zext or sext) so that it remains described even
11271126 DIExpr->elements_end() - 3);
11281127 Ops.push_back(dwarf::DW_OP_LLVM_fragment);
11291128 Ops.push_back(FragmentOffset);
1130 const DataLayout &DL = DII->getModule()->getDataLayout();
1129 const DataLayout &DL = DDI->getModule()->getDataLayout();
11311130 Ops.push_back(DL.getTypeSizeInBits(ExtendedArg->getType()));
11321131 DIExpr = Builder.createExpression(Ops);
11331132 }
11341133 DV = ExtendedArg;
11351134 }
11361135 if (!LdStHasDebugValue(DIVar, DIExpr, SI))
1137 Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, DII->getDebugLoc(),
1136 Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, DDI->getDebugLoc(),
11381137 SI);
11391138 }
11401139
11411140 /// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value
1142 /// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
1143 void llvm::ConvertDebugDeclareToDebugValue(DbgInfoIntrinsic *DII,
1141 /// that has an associated llvm.dbg.decl intrinsic.
1142 void llvm::ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI,
11441143 LoadInst *LI, DIBuilder &Builder) {
1145 auto *DIVar = DII->getVariable();
1146 auto *DIExpr = DII->getExpression();
1144 auto *DIVar = DDI->getVariable();
1145 auto *DIExpr = DDI->getExpression();
11471146 assert(DIVar && "Missing variable");
11481147
11491148 if (LdStHasDebugValue(DIVar, DIExpr, LI))
11541153 // preferable to keep tracking both the loaded value and the original
11551154 // address in case the alloca can not be elided.
11561155 Instruction *DbgValue = Builder.insertDbgValueIntrinsic(
1157 LI, DIVar, DIExpr, DII->getDebugLoc(), (Instruction *)nullptr);
1156 LI, DIVar, DIExpr, DDI->getDebugLoc(), (Instruction *)nullptr);
11581157 DbgValue->insertAfter(LI);
11591158 }
11601159
1161 /// Inserts a llvm.dbg.value intrinsic after a phi that has an associated
1162 /// llvm.dbg.declare or llvm.dbg.addr intrinsic.
1163 void llvm::ConvertDebugDeclareToDebugValue(DbgInfoIntrinsic *DII,
1160 /// Inserts a llvm.dbg.value intrinsic after a phi
1161 /// that has an associated llvm.dbg.decl intrinsic.
1162 void llvm::ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI,
11641163 PHINode *APN, DIBuilder &Builder) {
1165 auto *DIVar = DII->getVariable();
1166 auto *DIExpr = DII->getExpression();
1164 auto *DIVar = DDI->getVariable();
1165 auto *DIExpr = DDI->getExpression();
11671166 assert(DIVar && "Missing variable");
11681167
11691168 if (PhiHasDebugValue(DIVar, DIExpr, APN))
11761175 // insertion point.
11771176 // FIXME: Insert dbg.value markers in the successors when appropriate.
11781177 if (InsertionPt != BB->end())
1179 Builder.insertDbgValueIntrinsic(APN, DIVar, DIExpr, DII->getDebugLoc(),
1178 Builder.insertDbgValueIntrinsic(APN, DIVar, DIExpr, DDI->getDebugLoc(),
11801179 &*InsertionPt);
11811180 }
11821181
12311230 return true;
12321231 }
12331232
1234 /// Finds all intrinsics declaring local variables as living in the memory that
1235 /// 'V' points to. This may include a mix of dbg.declare and
1236 /// dbg.addr intrinsics.
1237 TinyPtrVector llvm::FindDbgAddrUses(Value *V) {
1238 auto *L = LocalAsMetadata::getIfExists(V);
1239 if (!L)
1240 return {};
1241 auto *MDV = MetadataAsValue::getIfExists(V->getContext(), L);
1242 if (!MDV)
1243 return {};
1244
1245 TinyPtrVector Declares;
1246 for (User *U : MDV->users()) {
1247 if (auto *DII = dyn_cast(U))
1248 if (DII->isAddressOfVariable())
1249 Declares.push_back(DII);
1250 }
1251
1252 return Declares;
1233 /// FindAllocaDbgDeclare - Finds the llvm.dbg.declare intrinsic describing the
1234 /// alloca 'V', if any.
1235 DbgDeclareInst *llvm::FindAllocaDbgDeclare(Value *V) {
1236 if (auto *L = LocalAsMetadata::getIfExists(V))
1237 if (auto *MDV = MetadataAsValue::getIfExists(V->getContext(), L))
1238 for (User *U : MDV->users())
1239 if (DbgDeclareInst *DDI = dyn_cast(U))
1240 return DDI;
1241
1242 return nullptr;
12531243 }
12541244
12551245 void llvm::findDbgValues(SmallVectorImpl &DbgValues, Value *V) {
12601250 DbgValues.push_back(DVI);
12611251 }
12621252
1253
12631254 bool llvm::replaceDbgDeclare(Value *Address, Value *NewAddress,
12641255 Instruction *InsertBefore, DIBuilder &Builder,
12651256 bool Deref, int Offset) {
1266 auto DbgAddrs = FindDbgAddrUses(Address);
1267 for (DbgInfoIntrinsic *DII : DbgAddrs) {
1268 DebugLoc Loc = DII->getDebugLoc();
1269 auto *DIVar = DII->getVariable();
1270 auto *DIExpr = DII->getExpression();
1271 assert(DIVar && "Missing variable");
1272 DIExpr = DIExpression::prepend(DIExpr, Deref, Offset);
1273 // Insert llvm.dbg.declare immediately after the original alloca, and remove
1274 // old llvm.dbg.declare.
1275 Builder.insertDeclare(NewAddress, DIVar, DIExpr, Loc, InsertBefore);
1276 DII->eraseFromParent();
1277 }
1278 return !DbgAddrs.empty();
1257 DbgDeclareInst *DDI = FindAllocaDbgDeclare(Address);
1258 if (!DDI)
1259 return false;
1260 DebugLoc Loc = DDI->getDebugLoc();
1261 auto *DIVar = DDI->getVariable();
1262 auto *DIExpr = DDI->getExpression();
1263 assert(DIVar && "Missing variable");
1264 DIExpr = DIExpression::prepend(DIExpr, Deref, Offset);
1265 // Insert llvm.dbg.declare immediately after the original alloca, and remove
1266 // old llvm.dbg.declare.
1267 Builder.insertDeclare(NewAddress, DIVar, DIExpr, Loc, InsertBefore);
1268 DDI->eraseFromParent();
1269 return true;
12791270 }
12801271
12811272 bool llvm::replaceDbgDeclareForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
102102 bool OnlyUsedInOneBlock;
103103
104104 Value *AllocaPointerVal;
105 TinyPtrVector DbgDeclares;
105 DbgDeclareInst *DbgDeclare;
106106
107107 void clear() {
108108 DefiningBlocks.clear();
111111 OnlyBlock = nullptr;
112112 OnlyUsedInOneBlock = true;
113113 AllocaPointerVal = nullptr;
114 DbgDeclares.clear();
114 DbgDeclare = nullptr;
115115 }
116116
117117 /// Scan the uses of the specified alloca, filling in the AllocaInfo used
146146 }
147147 }
148148
149 DbgDeclares = FindDbgAddrUses(AI);
149 DbgDeclare = FindAllocaDbgDeclare(AI);
150150 }
151151 };
152152
244244 /// For each alloca, we keep track of the dbg.declare intrinsic that
245245 /// describes it, if any, so that we can convert it to a dbg.value
246246 /// intrinsic if the alloca gets promoted.
247 SmallVector<TinyPtrVector, 8> AllocaDbgDeclares;
247 SmallVector<DbgDeclareInst *, 8> AllocaDbgDeclares;
248248
249249 /// The set of basic blocks the renamer has already visited.
250250 ///
408408
409409 // Record debuginfo for the store and remove the declaration's
410410 // debuginfo.
411 for (DbgInfoIntrinsic *DII : Info.DbgDeclares) {
411 if (DbgDeclareInst *DDI = Info.DbgDeclare) {
412412 DIBuilder DIB(*AI->getModule(), /*AllowUnresolved*/ false);
413 ConvertDebugDeclareToDebugValue(DII, Info.OnlyStore, DIB);
414 DII->eraseFromParent();
415 LBI.deleteValue(DII);
413 ConvertDebugDeclareToDebugValue(DDI, Info.OnlyStore, DIB);
414 DDI->eraseFromParent();
415 LBI.deleteValue(DDI);
416416 }
417417 // Remove the (now dead) store and alloca.
418418 Info.OnlyStore->eraseFromParent();
504504 while (!AI->use_empty()) {
505505 StoreInst *SI = cast(AI->user_back());
506506 // Record debuginfo for the store before removing it.
507 for (DbgInfoIntrinsic *DII : Info.DbgDeclares) {
507 if (DbgDeclareInst *DDI = Info.DbgDeclare) {
508508 DIBuilder DIB(*AI->getModule(), /*AllowUnresolved*/ false);
509 ConvertDebugDeclareToDebugValue(DII, SI, DIB);
509 ConvertDebugDeclareToDebugValue(DDI, SI, DIB);
510510 }
511511 SI->eraseFromParent();
512512 LBI.deleteValue(SI);
516516 LBI.deleteValue(AI);
517517
518518 // The alloca's debuginfo can be removed as well.
519 for (DbgInfoIntrinsic *DII : Info.DbgDeclares) {
520 DII->eraseFromParent();
521 LBI.deleteValue(DII);
519 if (DbgDeclareInst *DDI = Info.DbgDeclare) {
520 DDI->eraseFromParent();
521 LBI.deleteValue(DDI);
522522 }
523523
524524 ++NumLocalPromoted;
586586 }
587587
588588 // Remember the dbg.declare intrinsic describing this alloca, if any.
589 if (!Info.DbgDeclares.empty())
590 AllocaDbgDeclares[AllocaNum] = Info.DbgDeclares;
589 if (Info.DbgDeclare)
590 AllocaDbgDeclares[AllocaNum] = Info.DbgDeclare;
591591
592592 // Keep the reverse mapping of the 'Allocas' array for the rename pass.
593593 AllocaLookup[Allocas[AllocaNum]] = AllocaNum;
665665 }
666666
667667 // Remove alloca's dbg.declare instrinsics from the function.
668 for (auto &Declares : AllocaDbgDeclares)
669 for (auto *DII : Declares)
670 DII->eraseFromParent();
668 for (DbgDeclareInst *DDI : AllocaDbgDeclares)
669 if (DDI)
670 DDI->eraseFromParent();
671671
672672 // Loop over all of the PHI nodes and see if there are any that we can get
673673 // rid of because they merge all of the same incoming values. This can
894894
895895 // The currently active variable for this block is now the PHI.
896896 IncomingVals[AllocaNo] = APN;
897 for (DbgInfoIntrinsic *DII : AllocaDbgDeclares[AllocaNo])
898 ConvertDebugDeclareToDebugValue(DII, APN, DIB);
897 if (DbgDeclareInst *DDI = AllocaDbgDeclares[AllocaNo])
898 ConvertDebugDeclareToDebugValue(DDI, APN, DIB);
899899
900900 // Get the next phi node.
901901 ++PNI;
951951 // what value were we writing?
952952 IncomingVals[ai->second] = SI->getOperand(0);
953953 // Record debuginfo for the store before removing it.
954 for (DbgInfoIntrinsic *DII : AllocaDbgDeclares[ai->second])
955 ConvertDebugDeclareToDebugValue(DII, SI, DIB);
954 if (DbgDeclareInst *DDI = AllocaDbgDeclares[ai->second])
955 ConvertDebugDeclareToDebugValue(DDI, SI, DIB);
956956 BB->getInstList().erase(SI);
957957 }
958958 }
+0
-100
test/DebugInfo/X86/dbg-addr-dse.ll less more
None ; RUN: llc %s -o %t.s
1 ; RUN: llvm-mc %t.s -filetype=obj -triple=x86_64-windows-msvc -o %t.o
2 ; RUN: FileCheck %s < %t.s --check-prefix=ASM
3 ; RUN: llvm-dwarfdump %t.o | FileCheck %s --check-prefix=DWARF
4
5 ; In this example, the variable lives mostly in memory, but at the point of the
6 ; assignment to global, it lives nowhere, and is described as the constant
7 ; value 1.
8
9 ; C source:
10 ;
11 ; void escape(int *);
12 ; extern int global;
13 ; void f(int x) {
14 ; escape(&x);
15 ; x = 1; // DSE should delete and insert dbg.value(i32 1)
16 ; global = x;
17 ; x = 2; // DSE should insert dbg.addr
18 ; escape(&x);
19 ; }
20
21 ; ModuleID = 'dse.c'
22 source_filename = "dse.c"
23 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
24 target triple = "x86_64-pc-windows-msvc19.0.24215"
25
26 declare void @llvm.dbg.addr(metadata, metadata, metadata) #2
27 declare void @llvm.dbg.value(metadata, metadata, metadata) #2
28 declare void @escape(i32*)
29
30 @global = external global i32, align 4
31
32 ; Function Attrs: nounwind uwtable
33 define void @f(i32 %x) #0 !dbg !8 {
34 entry:
35 %x.addr = alloca i32, align 4
36 store i32 %x, i32* %x.addr, align 4
37 call void @llvm.dbg.addr(metadata i32* %x.addr, metadata !13, metadata !DIExpression()), !dbg !18
38 call void @escape(i32* %x.addr), !dbg !19
39 call void @llvm.dbg.value(metadata i32 1, metadata !13, metadata !DIExpression()), !dbg !20
40 store i32 1, i32* @global, align 4, !dbg !22
41 call void @llvm.dbg.addr(metadata i32* %x.addr, metadata !13, metadata !DIExpression()), !dbg !23
42 store i32 2, i32* %x.addr, align 4, !dbg !23
43 call void @escape(i32* %x.addr), !dbg !24
44 ret void, !dbg !25
45 }
46
47 ; ASM-LABEL: f: # @f
48 ; ASM: movl %ecx, [[OFF_X:[0-9]+]](%rsp)
49 ; ASM: #DEBUG_VALUE: f:x <- [DW_OP_plus_uconst [[OFF_X]]] [%RSP+0]
50 ; ASM: callq escape
51 ; ASM: #DEBUG_VALUE: f:x <- 1
52 ; ASM: movl $1, global(%rip)
53 ; FIXME: Needs a fix to LiveDebugVariables
54 ; ASMX: #DEBUG_VALUE: f:x <- [DW_OP_plus_uconst [[OFF_X]]] [%RSP+0]
55 ; ASM: movl $2, [[OFF_X]](%rsp)
56 ; ASM: callq escape
57 ; ASM: retq
58
59 ; DWARF: DW_TAG_formal_parameter
60 ; DWARF-NEXT: DW_AT_location (0x00000000
61 ; DWARF-NEXT: {{[^:]*}}: DW_OP_breg7 RSP+{{[0-9]+}}
62 ; DWARF-NEXT: {{[^:]*}}: DW_OP_consts +1, DW_OP_stack_value
63 ; FIXME: Needs a fix to LiveDebugVariables
64 ; DWARFX-NEXT: {{[^:]*}}: DW_OP_breg7 RSP+{{[0-9]+}})
65 ; DWARF-NEXT: DW_AT_name ("x")
66
67 attributes #0 = { nounwind uwtable }
68 attributes #2 = { nounwind readnone speculatable }
69
70 !llvm.dbg.cu = !{!0}
71 !llvm.module.flags = !{!3, !4, !5, !6}
72 !llvm.ident = !{!7}
73
74 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
75 !1 = !DIFile(filename: "dse.c", directory: "C:\5Csrc\5Cllvm-project\5Cbuild")
76 !2 = !{}
77 !3 = !{i32 2, !"Dwarf Version", i32 4}
78 !4 = !{i32 2, !"Debug Info Version", i32 3}
79 !5 = !{i32 1, !"wchar_size", i32 2}
80 !6 = !{i32 7, !"PIC Level", i32 2}
81 !7 = !{!"clang version 6.0.0 "}
82 !8 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 3, type: !9, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !12)
83 !9 = !DISubroutineType(types: !10)
84 !10 = !{null, !11}
85 !11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
86 !12 = !{!13}
87 !13 = !DILocalVariable(name: "x", arg: 1, scope: !8, file: !1, line: 3, type: !11)
88 !14 = !{!15, !15, i64 0}
89 !15 = !{!"int", !16, i64 0}
90 !16 = !{!"omnipotent char", !17, i64 0}
91 !17 = !{!"Simple C/C++ TBAA"}
92 !18 = !DILocation(line: 3, column: 12, scope: !8)
93 !19 = !DILocation(line: 4, column: 3, scope: !8)
94 !20 = !DILocation(line: 5, column: 5, scope: !8)
95 !21 = !DILocation(line: 6, column: 12, scope: !8)
96 !22 = !DILocation(line: 6, column: 10, scope: !8)
97 !23 = !DILocation(line: 7, column: 5, scope: !8)
98 !24 = !DILocation(line: 8, column: 3, scope: !8)
99 !25 = !DILocation(line: 9, column: 1, scope: !8)
+0
-67
test/DebugInfo/X86/dbg-addr.ll less more
None ; RUN: llc %s -o %t.s
1 ; RUN: llvm-mc -triple x86_64--linux %t.s -filetype=obj -o %t.o
2 ; RUN: FileCheck < %t.s %s
3 ; RUN: llvm-dwarfdump %t.o | FileCheck %s --check-prefix=DWARF
4
5 ; Unlike dbg.declare, dbg.addr should be lowered to DBG_VALUE instructions. It
6 ; is control-dependent.
7
8 ; CHECK-LABEL: use_dbg_addr:
9 ; CHECK: #DEBUG_VALUE: use_dbg_addr:o <- [%RSP+0]
10
11 ; FIXME: Avoid the use of a single-location location list and use
12 ; DW_AT_start_offset instead.
13
14 ; DWARF: DW_TAG_variable
15 ; DWARF-NEXT: DW_AT_location (0x00000000
16 ; DWARF-NEXT: 0x{{.*}} - 0x{{.*}}: DW_OP_breg7 RSP+0)
17 ; DWARF-NEXT: DW_AT_name ("o")
18
19
20 ; ModuleID = 't.c'
21 source_filename = "t.c"
22 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
23 target triple = "x86_64--linux"
24
25 %struct.Foo = type { i32 }
26
27 ; Function Attrs: noinline nounwind uwtable
28 define void @use_dbg_addr() #0 !dbg !7 {
29 entry:
30 %o = alloca %struct.Foo, align 4
31 call void @llvm.dbg.addr(metadata %struct.Foo* %o, metadata !10, metadata !15), !dbg !16
32 call void @escape_foo(%struct.Foo* %o), !dbg !17
33 ret void, !dbg !18
34 }
35
36 ; Function Attrs: nounwind readnone speculatable
37 declare void @llvm.dbg.addr(metadata, metadata, metadata) #1
38
39 declare void @escape_foo(%struct.Foo*)
40
41 attributes #0 = { noinline nounwind uwtable }
42 attributes #1 = { nounwind readnone speculatable }
43
44 !llvm.dbg.cu = !{!0}
45 !llvm.module.flags = !{!3, !4, !5}
46 !llvm.ident = !{!6}
47
48 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
49 !1 = !DIFile(filename: "t.c", directory: "C:\5Csrc\5Cllvm-project\5Cbuild")
50 !2 = !{}
51 !3 = !{i32 2, !"Dwarf Version", i32 4}
52 !4 = !{i32 2, !"Debug Info Version", i32 3}
53 !5 = !{i32 1, !"wchar_size", i32 4}
54 !6 = !{!"clang version 6.0.0 "}
55 !7 = distinct !DISubprogram(name: "use_dbg_addr", scope: !1, file: !1, line: 3, type: !8, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
56 !8 = !DISubroutineType(types: !9)
57 !9 = !{null}
58 !10 = !DILocalVariable(name: "o", scope: !7, file: !1, line: 4, type: !11)
59 !11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", file: !1, line: 1, size: 32, elements: !12)
60 !12 = !{!13}
61 !13 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !11, file: !1, line: 1, baseType: !14, size: 32)
62 !14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
63 !15 = !DIExpression()
64 !16 = !DILocation(line: 4, column: 14, scope: !7)
65 !17 = !DILocation(line: 5, column: 3, scope: !7)
66 !18 = !DILocation(line: 6, column: 1, scope: !7)
1919 ;
2020 ; There should be no debug info for the padding.
2121 ; CHECK-NOT: DW_OP_LLVM_fragment, 56
22 ; CHECK: DIExpression(DW_OP_LLVM_fragment, 32, 24)
23 ; CHECK-NOT: DW_OP_LLVM_fragment, 56
2224 ; CHECK: DIExpression(DW_OP_LLVM_fragment, 0, 32)
23 ; CHECK-NOT: DW_OP_LLVM_fragment, 56
24 ; CHECK: DIExpression(DW_OP_LLVM_fragment, 32, 24)
2525 ; CHECK-NOT: DW_OP_LLVM_fragment, 56
2626 %struct.prog_src_register = type { i32, i24 }
2727
+0
-59
test/DebugInfo/X86/sroasplit-dbg-declare.ll less more
None ; RUN: opt -S -sroa -o - %s | FileCheck %s
1
2 ; SROA should split the alloca in two new ones, each with its own dbg.declare.
3 ; The original alloca and dbg.declare should be removed.
4
5 define void @f1() {
6 entry:
7 %0 = alloca [9 x i32]
8 call void @llvm.dbg.declare(metadata [9 x i32]* %0, metadata !11, metadata !DIExpression()), !dbg !17
9 %1 = bitcast [9 x i32]* %0 to i8*
10 call void @llvm.memset.p0i8.i64(i8* %1, i8 0, i64 36, i32 16, i1 true)
11 %2 = getelementptr [9 x i32], [9 x i32]* %0, i32 0, i32 0
12 store volatile i32 1, i32* %2
13 ret void
14 }
15
16 ; Function Attrs: nounwind readnone speculatable
17 declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
18
19 ; Function Attrs: argmemonly nounwind
20 declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i32, i1) #0
21
22 attributes #0 = { argmemonly nounwind }
23 attributes #1 = { nounwind readnone speculatable }
24
25 !llvm.dbg.cu = !{!0}
26 !llvm.module.flags = !{!3, !4, !5}
27 !llvm.ident = !{!6}
28
29 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
30 !1 = !DIFile(filename: "foo.c", directory: "/bar")
31 !2 = !{}
32 !3 = !{i32 2, !"Dwarf Version", i32 4}
33 !4 = !{i32 2, !"Debug Info Version", i32 3}
34 !5 = !{i32 1, !"wchar_size", i32 4}
35 !6 = !{!"clang version 6.0.0"}
36 !7 = distinct !DISubprogram(name: "f1", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !10)
37 !8 = !DISubroutineType(types: !9)
38 !9 = !{null}
39 !10 = !{!11}
40 !11 = !DILocalVariable(name: "b", scope: !7, file: !1, line: 3, type: !12)
41 !12 = !DICompositeType(tag: DW_TAG_array_type, baseType: !13, size: 288, elements: !15)
42 !13 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !14)
43 !14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
44 !15 = !{!16}
45 !16 = !DISubrange(count: 9)
46 !17 = !DILocation(line: 3, column: 18, scope: !7)
47
48 ; CHECK-NOT: = alloca [9 x i32]
49 ; CHECK-NOT: call void @llvm.dbg.declare(metadata [9 x i32]*
50
51 ; CHECK: %[[VAR1:.*]] = alloca i32
52 ; CHECK-NEXT: %[[VAR2:.*]] = alloca [8 x i32]
53 ; CHECK-NEXT: call void @llvm.dbg.declare(metadata i32* %[[VAR1]]
54 ; CHECK-NEXT: call void @llvm.dbg.declare(metadata [8 x i32]* %[[VAR2]]
55
56 ; CHECK-NOT: = alloca [9 x i32]
57 ; CHECK-NOT: call void @llvm.dbg.declare(metadata [9 x i32]*
58
+0
-94
test/Transforms/Mem2Reg/dbg-addr-inline-dse.ll less more
None ; RUN: opt -mem2reg -S < %s | FileCheck %s -implicit-check-not="call void @llvm.dbg.addr"
1
2 ; This example is intended to simulate this pass pipeline, which may not exist
3 ; in practice:
4 ; 1. DSE f from the original C source
5 ; 2. Inline escape
6 ; 3. mem2reg
7 ; This exercises the corner case of multiple llvm.dbg.addr intrinsics.
8
9 ; C source:
10 ;
11 ; void escape(int *px) { ++*px; }
12 ; extern int global;
13 ; void f(int x) {
14 ; escape(&x);
15 ; x = 1; // DSE should delete and insert dbg.value(i32 1)
16 ; global = x;
17 ; x = 2; // DSE should insert dbg.addr
18 ; escape(&x);
19 ; }
20
21 ; ModuleID = 'dse.c'
22 source_filename = "dse.c"
23 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
24 target triple = "x86_64-pc-windows-msvc19.0.24215"
25
26 declare void @llvm.dbg.addr(metadata, metadata, metadata) #2
27 declare void @llvm.dbg.value(metadata, metadata, metadata) #2
28
29 @global = external global i32, align 4
30
31 ; Function Attrs: nounwind uwtable
32 define void @f(i32 %x) #0 !dbg !8 {
33 entry:
34 %x.addr = alloca i32, align 4
35 store i32 %x, i32* %x.addr, align 4
36 call void @llvm.dbg.addr(metadata i32* %x.addr, metadata !13, metadata !DIExpression()), !dbg !18
37 %ld.1 = load i32, i32* %x.addr, align 4, !dbg !19
38 %inc.1 = add nsw i32 %ld.1, 1, !dbg !19
39 store i32 %inc.1, i32* %x.addr, align 4, !dbg !19
40 call void @llvm.dbg.value(metadata i32 1, metadata !13, metadata !DIExpression()), !dbg !20
41 store i32 1, i32* @global, align 4, !dbg !22
42 call void @llvm.dbg.addr(metadata i32* %x.addr, metadata !13, metadata !DIExpression()), !dbg !23
43 store i32 2, i32* %x.addr, align 4, !dbg !23
44 %ld.2 = load i32, i32* %x.addr, align 4, !dbg !19
45 %inc.2 = add nsw i32 %ld.2, 1, !dbg !19
46 store i32 %inc.2, i32* %x.addr, align 4, !dbg !19
47 ret void, !dbg !25
48 }
49
50 ; CHECK-LABEL: define void @f(i32 %x)
51 ; CHECK: call void @llvm.dbg.value(metadata i32 %x, metadata !13, metadata !DIExpression())
52 ; CHECK: %inc.1 = add nsw i32 %x, 1
53 ; CHECK: call void @llvm.dbg.value(metadata i32 %inc.1, metadata !13, metadata !DIExpression())
54 ; CHECK: call void @llvm.dbg.value(metadata i32 1, metadata !13, metadata !DIExpression())
55 ; CHECK: store i32 1, i32* @global, align 4
56 ; CHECK: call void @llvm.dbg.value(metadata i32 2, metadata !13, metadata !DIExpression())
57 ; CHECK: %inc.2 = add nsw i32 2, 1
58 ; CHECK: call void @llvm.dbg.value(metadata i32 %inc.2, metadata !13, metadata !DIExpression())
59 ; CHECK: ret void
60
61 attributes #0 = { nounwind uwtable }
62 attributes #2 = { nounwind readnone speculatable }
63
64 !llvm.dbg.cu = !{!0}
65 !llvm.module.flags = !{!3, !4, !5, !6}
66 !llvm.ident = !{!7}
67
68 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
69 !1 = !DIFile(filename: "dse.c", directory: "C:\5Csrc\5Cllvm-project\5Cbuild")
70 !2 = !{}
71 !3 = !{i32 2, !"Dwarf Version", i32 4}
72 !4 = !{i32 2, !"Debug Info Version", i32 3}
73 !5 = !{i32 1, !"wchar_size", i32 2}
74 !6 = !{i32 7, !"PIC Level", i32 2}
75 !7 = !{!"clang version 6.0.0 "}
76 !8 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 3, type: !9, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !12)
77 !9 = !DISubroutineType(types: !10)
78 !10 = !{null, !11}
79 !11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
80 !12 = !{!13}
81 !13 = !DILocalVariable(name: "x", arg: 1, scope: !8, file: !1, line: 3, type: !11)
82 !14 = !{!15, !15, i64 0}
83 !15 = !{!"int", !16, i64 0}
84 !16 = !{!"omnipotent char", !17, i64 0}
85 !17 = !{!"Simple C/C++ TBAA"}
86 !18 = !DILocation(line: 3, column: 12, scope: !8)
87 !19 = !DILocation(line: 4, column: 3, scope: !8)
88 !20 = !DILocation(line: 5, column: 5, scope: !8)
89 !21 = !DILocation(line: 6, column: 12, scope: !8)
90 !22 = !DILocation(line: 6, column: 10, scope: !8)
91 !23 = !DILocation(line: 7, column: 5, scope: !8)
92 !24 = !DILocation(line: 8, column: 3, scope: !8)
93 !25 = !DILocation(line: 9, column: 1, scope: !8)
+0
-91
test/Transforms/Mem2Reg/dbg-addr.ll less more
None ; RUN: opt -mem2reg -S < %s | FileCheck %s
1
2 ; ModuleID = 'newvars.c'
3 source_filename = "newvars.c"
4 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-pc-windows-msvc19.0.24215"
6
7 ; Function Attrs: nounwind uwtable
8 define i32 @if_else(i32 %cond, i32 %a, i32 %b) !dbg !8 {
9 entry:
10 %x = alloca i32, align 4
11 call void @llvm.dbg.addr(metadata i32* %x, metadata !16, metadata !DIExpression()), !dbg !26
12 store i32 %a, i32* %x, align 4, !dbg !26, !tbaa !17
13 %tobool = icmp ne i32 %cond, 0, !dbg !28
14 br i1 %tobool, label %if.then, label %if.else, !dbg !30
15
16 if.then: ; preds = %entry
17 store i32 0, i32* %x, align 4, !dbg !31, !tbaa !17
18 br label %if.end, !dbg !33
19
20 if.else: ; preds = %entry
21 store i32 %b, i32* %x, align 4, !dbg !36, !tbaa !17
22 br label %if.end
23
24 if.end: ; preds = %if.else, %if.then
25 %rv = load i32, i32* %x, align 4, !dbg !37, !tbaa !17
26 ret i32 %rv, !dbg !39
27 }
28
29 ; CHECK-LABEL: define i32 @if_else({{.*}})
30 ; CHECK: entry:
31 ; CHECK-NOT: alloca i32
32 ; CHECK: call void @llvm.dbg.value(metadata i32 %a, metadata ![[X_LOCAL:[0-9]+]], metadata !DIExpression())
33 ; CHECK: if.then: ; preds = %entry
34 ; CHECK: call void @llvm.dbg.value(metadata i32 0, metadata ![[X_LOCAL]], metadata !DIExpression())
35 ; CHECK: if.else: ; preds = %entry
36 ; CHECK: call void @llvm.dbg.value(metadata i32 %b, metadata ![[X_LOCAL]], metadata !DIExpression())
37 ; CHECK: if.end: ; preds = %if.else, %if.then
38 ; CHECK: %[[PHI:[^ ]*]] = phi i32 [ 0, %if.then ], [ %b, %if.else ]
39 ; CHECK: call void @llvm.dbg.value(metadata i32 %[[PHI]], metadata ![[X_LOCAL]], metadata !DIExpression())
40 ; CHECK: ret i32
41
42 ; CHECK: ![[X_LOCAL]] = !DILocalVariable(name: "x", {{.*}})
43
44 ; Function Attrs: nounwind readnone speculatable
45 declare void @llvm.dbg.declare(metadata, metadata, metadata)
46 declare void @llvm.dbg.addr(metadata, metadata, metadata)
47
48 !llvm.dbg.cu = !{!0}
49 !llvm.module.flags = !{!3, !4, !5, !6}
50 !llvm.ident = !{!7}
51
52 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
53 !1 = !DIFile(filename: "newvars.c", directory: "C:\5Csrc\5Cllvm-project\5Cbuild")
54 !2 = !{}
55 !3 = !{i32 2, !"Dwarf Version", i32 4}
56 !4 = !{i32 2, !"Debug Info Version", i32 3}
57 !5 = !{i32 1, !"wchar_size", i32 2}
58 !6 = !{i32 7, !"PIC Level", i32 2}
59 !7 = !{!"clang version 6.0.0 "}
60 !8 = distinct !DISubprogram(name: "if_else", scope: !1, file: !1, line: 1, type: !9, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !12)
61 !9 = !DISubroutineType(types: !10)
62 !10 = !{!11, !11, !11, !11}
63 !11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
64 !12 = !{!13, !14, !15, !16}
65 !13 = !DILocalVariable(name: "b", arg: 3, scope: !8, file: !1, line: 1, type: !11)
66 !14 = !DILocalVariable(name: "a", arg: 2, scope: !8, file: !1, line: 1, type: !11)
67 !15 = !DILocalVariable(name: "cond", arg: 1, scope: !8, file: !1, line: 1, type: !11)
68 !16 = !DILocalVariable(name: "x", scope: !8, file: !1, line: 2, type: !11)
69 !17 = !{!18, !18, i64 0}
70 !18 = !{!"int", !19, i64 0}
71 !19 = !{!"omnipotent char", !20, i64 0}
72 !20 = !{!"Simple C/C++ TBAA"}
73 !22 = !DILocation(line: 1, column: 34, scope: !8)
74 !23 = !DILocation(line: 1, column: 27, scope: !8)
75 !24 = !DILocation(line: 1, column: 17, scope: !8)
76 !25 = !DILocation(line: 2, column: 3, scope: !8)
77 !26 = !DILocation(line: 2, column: 7, scope: !8)
78 !27 = !DILocation(line: 2, column: 11, scope: !8)
79 !28 = !DILocation(line: 3, column: 7, scope: !29)
80 !29 = distinct !DILexicalBlock(scope: !8, file: !1, line: 3, column: 7)
81 !30 = !DILocation(line: 3, column: 7, scope: !8)
82 !31 = !DILocation(line: 4, column: 7, scope: !32)
83 !32 = distinct !DILexicalBlock(scope: !29, file: !1, line: 3, column: 13)
84 !33 = !DILocation(line: 5, column: 3, scope: !32)
85 !34 = !DILocation(line: 6, column: 9, scope: !35)
86 !35 = distinct !DILexicalBlock(scope: !29, file: !1, line: 5, column: 10)
87 !36 = !DILocation(line: 6, column: 7, scope: !35)
88 !37 = !DILocation(line: 8, column: 10, scope: !8)
89 !38 = !DILocation(line: 9, column: 1, scope: !8)
90 !39 = !DILocation(line: 8, column: 3, scope: !8)
+0
-127
test/Transforms/SROA/dbg-addr-diamond.ll less more
None ; RUN: opt -use-dbg-addr -sroa -S < %s | FileCheck %s
1
2 ; ModuleID = ''
3 source_filename = "newvars.c"
4 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-pc-windows-msvc19.0.24215"
6
7 %struct.Pair = type { i32, i32 }
8
9 @pair = internal global %struct.Pair zeroinitializer
10
11 ; Function Attrs: nounwind uwtable
12 define void @if_else(i32 %cond, i32 %a, i32 %b) !dbg !8 {
13 entry:
14 %p = alloca %struct.Pair, align 4
15 %0 = bitcast %struct.Pair* %p to i8*, !dbg !25
16 call void @llvm.dbg.addr(metadata %struct.Pair* %p, metadata !20, metadata !DIExpression()), !dbg !26
17 %x = getelementptr inbounds %struct.Pair, %struct.Pair* %p, i32 0, i32 0, !dbg !27
18 store i32 %a, i32* %x, align 4, !dbg !28
19 %y = getelementptr inbounds %struct.Pair, %struct.Pair* %p, i32 0, i32 1, !dbg !34
20 store i32 %b, i32* %y, align 4, !dbg !35
21 %tobool = icmp ne i32 %cond, 0, !dbg !37
22 br i1 %tobool, label %if.then, label %if.else, !dbg !39
23
24 if.then: ; preds = %entry
25 %x1 = getelementptr inbounds %struct.Pair, %struct.Pair* %p, i32 0, i32 0, !dbg !40
26 store i32 0, i32* %x1, align 4, !dbg !42
27 %y2 = getelementptr inbounds %struct.Pair, %struct.Pair* %p, i32 0, i32 1, !dbg !43
28 store i32 %a, i32* %y2, align 4, !dbg !44
29 br label %if.end, !dbg !45
30
31 if.else: ; preds = %entry
32 %x3 = getelementptr inbounds %struct.Pair, %struct.Pair* %p, i32 0, i32 0, !dbg !46
33 store i32 %b, i32* %x3, align 4, !dbg !48
34 %y4 = getelementptr inbounds %struct.Pair, %struct.Pair* %p, i32 0, i32 1, !dbg !49
35 store i32 0, i32* %y4, align 4, !dbg !50
36 br label %if.end
37
38 if.end: ; preds = %if.else, %if.then
39 %1 = bitcast %struct.Pair* %p to i8*, !dbg !51
40 %2 = bitcast %struct.Pair* @pair to i8*, !dbg !51
41 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %2, i8* %1, i64 8, i32 4, i1 false), !dbg !51
42 ret void
43 }
44
45 ; CHECK-LABEL: define void @if_else(i32 %cond, i32 %a, i32 %b)
46 ; CHECK: entry:
47 ; CHECK: call void @llvm.dbg.value(metadata i32 %a, metadata ![[PVAR:[0-9]+]], metadata ![[XFRAG:DIExpression\(DW_OP_LLVM_fragment, 0, 32\)]])
48 ; CHECK: call void @llvm.dbg.value(metadata i32 %b, metadata ![[PVAR]], metadata ![[YFRAG:DIExpression\(DW_OP_LLVM_fragment, 32, 32\)]])
49 ; CHECK: if.then:
50 ; CHECK: call void @llvm.dbg.value(metadata i32 0, metadata ![[PVAR]], metadata ![[XFRAG]])
51 ; CHECK: call void @llvm.dbg.value(metadata i32 %a, metadata ![[PVAR]], metadata ![[YFRAG]])
52 ; CHECK: if.else:
53 ; CHECK: call void @llvm.dbg.value(metadata i32 %b, metadata ![[PVAR]], metadata ![[XFRAG]])
54 ; CHECK: call void @llvm.dbg.value(metadata i32 0, metadata ![[PVAR]], metadata ![[YFRAG]])
55 ; CHECK: if.end:
56 ; CHECK: %p.sroa.4.0 = phi i32 [ %a, %if.then ], [ 0, %if.else ]
57 ; CHECK: %p.sroa.0.0 = phi i32 [ 0, %if.then ], [ %b, %if.else ]
58 ; CHECK: call void @llvm.dbg.value(metadata i32 %p.sroa.0.0, metadata ![[PVAR]], metadata ![[XFRAG]])
59 ; CHECK: call void @llvm.dbg.value(metadata i32 %p.sroa.4.0, metadata ![[PVAR]], metadata ![[YFRAG]])
60
61 ; CHECK: ![[PVAR]] = !DILocalVariable(name: "p", {{.*}})
62
63 ; Function Attrs: argmemonly nounwind
64 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i32, i1) #2
65
66 ; Function Attrs: nounwind readnone speculatable
67 declare void @llvm.dbg.addr(metadata, metadata, metadata)
68
69 !llvm.dbg.cu = !{!0}
70 !llvm.module.flags = !{!3, !4, !5, !6}
71 !llvm.ident = !{!7}
72
73 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
74 !1 = !DIFile(filename: "newvars.c", directory: "C:\5Csrc\5Cllvm-project\5Cbuild")
75 !2 = !{}
76 !3 = !{i32 2, !"Dwarf Version", i32 4}
77 !4 = !{i32 2, !"Debug Info Version", i32 3}
78 !5 = !{i32 1, !"wchar_size", i32 2}
79 !6 = !{i32 7, !"PIC Level", i32 2}
80 !7 = !{!"clang version 6.0.0 "}
81 !8 = distinct !DISubprogram(name: "if_else", scope: !1, file: !1, line: 2, type: !9, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !16)
82 !9 = !DISubroutineType(types: !10)
83 !10 = !{!11, !14, !14, !14}
84 !11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Pair", file: !1, line: 1, size: 64, elements: !12)
85 !12 = !{!13, !15}
86 !13 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !11, file: !1, line: 1, baseType: !14, size: 32)
87 !14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
88 !15 = !DIDerivedType(tag: DW_TAG_member, name: "y", scope: !11, file: !1, line: 1, baseType: !14, size: 32, offset: 32)
89 !16 = !{!17, !18, !19, !20}
90 !17 = !DILocalVariable(name: "b", arg: 3, scope: !8, file: !1, line: 2, type: !14)
91 !18 = !DILocalVariable(name: "a", arg: 2, scope: !8, file: !1, line: 2, type: !14)
92 !19 = !DILocalVariable(name: "cond", arg: 1, scope: !8, file: !1, line: 2, type: !14)
93 !20 = !DILocalVariable(name: "p", scope: !8, file: !1, line: 3, type: !11)
94 !22 = !DILocation(line: 2, column: 42, scope: !8)
95 !23 = !DILocation(line: 2, column: 35, scope: !8)
96 !24 = !DILocation(line: 2, column: 25, scope: !8)
97 !25 = !DILocation(line: 3, column: 3, scope: !8)
98 !26 = !DILocation(line: 3, column: 15, scope: !8)
99 !27 = !DILocation(line: 4, column: 5, scope: !8)
100 !28 = !DILocation(line: 4, column: 7, scope: !8)
101 !29 = !{!30, !31, i64 0}
102 !30 = !{!"Pair", !31, i64 0, !31, i64 4}
103 !31 = !{!"int", !32, i64 0}
104 !32 = !{!"omnipotent char", !33, i64 0}
105 !33 = !{!"Simple C/C++ TBAA"}
106 !34 = !DILocation(line: 5, column: 5, scope: !8)
107 !35 = !DILocation(line: 5, column: 7, scope: !8)
108 !36 = !{!30, !31, i64 4}
109 !37 = !DILocation(line: 6, column: 7, scope: !38)
110 !38 = distinct !DILexicalBlock(scope: !8, file: !1, line: 6, column: 7)
111 !39 = !DILocation(line: 6, column: 7, scope: !8)
112 !40 = !DILocation(line: 7, column: 7, scope: !41)
113 !41 = distinct !DILexicalBlock(scope: !38, file: !1, line: 6, column: 13)
114 !42 = !DILocation(line: 7, column: 9, scope: !41)
115 !43 = !DILocation(line: 8, column: 7, scope: !41)
116 !44 = !DILocation(line: 8, column: 9, scope: !41)
117 !45 = !DILocation(line: 9, column: 3, scope: !41)
118 !46 = !DILocation(line: 10, column: 7, scope: !47)
119 !47 = distinct !DILexicalBlock(scope: !38, file: !1, line: 9, column: 10)
120 !48 = !DILocation(line: 10, column: 9, scope: !47)
121 !49 = !DILocation(line: 11, column: 7, scope: !47)
122 !50 = !DILocation(line: 11, column: 9, scope: !47)
123 !51 = !DILocation(line: 13, column: 10, scope: !8)
124 !52 = !{i64 0, i64 4, !53, i64 4, i64 4, !53}
125 !53 = !{!31, !31, i64 0}
126 !54 = !DILocation(line: 14, column: 1, scope: !8)