llvm.org GIT mirror llvm / 7f89271
DebugInfo: Drop rest of DIDescriptor subclasses Delete the remaining subclasses of (the already deleted) `DIDescriptor`. Part of PR23080. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235404 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 4 years ago
28 changed file(s) with 127 addition(s) and 290 deletion(s). Raw diff Collapse all Expand all
8787 const char *Name, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty,
8888 int AlwaysPreserve, unsigned Flags, unsigned ArgNo) {
8989 DIBuilder *D = unwrap(Dref);
90 DIVariable V = D->createLocalVariable(
90 return wrap(D->createLocalVariable(
9191 Tag, unwrap(Scope), Name, unwrap(File), Line,
92 unwrap(Ty), AlwaysPreserve, Flags, ArgNo);
93 return wrap(V);
92 unwrap(Ty), AlwaysPreserve, Flags, ArgNo));
9493 }
9594
9695 LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref,
181180 LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref,
182181 int64_t Lo, int64_t Count) {
183182 DIBuilder *D = unwrap(Dref);
184 DISubrange S = D->getOrCreateSubrange(Lo, Count);
185 return wrap(S);
183 return wrap(D->getOrCreateSubrange(Lo, Count));
186184 }
187185
188186 LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Dref,
208206 LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Dref,
209207 int64_t *Addr, size_t Length) {
210208 DIBuilder *D = unwrap(Dref);
211 DIExpression Expr = D->createExpression(ArrayRef(Addr, Length));
212 return wrap(Expr);
209 return wrap(D->createExpression(ArrayRef(Addr, Length)));
213210 }
214211
215212 LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Dref,
245245
246246 /// \brief Return the debug variable referenced by
247247 /// this DBG_VALUE instruction.
248 DIVariable getDebugVariable() const {
248 const MDLocalVariable *getDebugVariable() const {
249249 assert(isDebugValue() && "not a DBG_VALUE");
250250 return cast(getOperand(2).getMetadata());
251251 }
252252
253253 /// \brief Return the complex address expression referenced by
254254 /// this DBG_VALUE instruction.
255 DIExpression getDebugExpression() const {
255 const MDExpression *getDebugExpression() const {
256256 assert(isDebugValue() && "not a DBG_VALUE");
257257 return cast(getOperand(3).getMetadata());
258258 }
175175 MI->addOperand(*MF, MachineOperand::CreateMetadata(MD));
176176 assert((MI->isDebugValue() ? static_cast(MI->getDebugVariable())
177177 : true) &&
178 "first MDNode argument of a DBG_VALUE not a DIVariable");
178 "first MDNode argument of a DBG_VALUE not a variable");
179179 return *this;
180180 }
181181
355355 const MCInstrDesc &MCID, bool IsIndirect,
356356 unsigned Reg, unsigned Offset,
357357 const MDNode *Variable, const MDNode *Expr) {
358 assert(isa(Variable) && "not a DIVariable");
359 assert(cast(Expr)->isValid() && "not a DIExpression");
358 assert(isa(Variable) && "not a variable");
359 assert(cast(Expr)->isValid() && "not an expression");
360360 assert(cast(Variable)->isValidLocationForIntrinsic(DL) &&
361361 "Expected inlined-at fields to agree");
362362 if (IsIndirect)
384384 const MCInstrDesc &MCID, bool IsIndirect,
385385 unsigned Reg, unsigned Offset,
386386 const MDNode *Variable, const MDNode *Expr) {
387 assert(isa(Variable) && "not a DIVariable");
388 assert(cast(Expr)->isValid() && "not a DIExpression");
387 assert(isa(Variable) && "not a variable");
388 assert(cast(Expr)->isValid() && "not an expression");
389389 MachineFunction &MF = *BB.getParent();
390390 MachineInstr *MI =
391391 BuildMI(MF, DL, MCID, IsIndirect, Reg, Offset, Variable, Expr);
4545 class LLVMContext;
4646 class raw_ostream;
4747
48 class DIVariable;
49 class DIObjCProperty;
50
5148 /// \brief Maps from type identifier to the actual MDNode.
5249 typedef DenseMap DITypeIdentifierMap;
5350
54 #define DECLARE_SIMPLIFY_DESCRIPTOR(DESC) \
55 class DESC; \
56 template <> struct simplify_type; \
57 template <> struct simplify_type;
58 DECLARE_SIMPLIFY_DESCRIPTOR(DISubrange)
59 DECLARE_SIMPLIFY_DESCRIPTOR(DIEnumerator)
60 DECLARE_SIMPLIFY_DESCRIPTOR(DITemplateTypeParameter)
61 DECLARE_SIMPLIFY_DESCRIPTOR(DITemplateValueParameter)
62 DECLARE_SIMPLIFY_DESCRIPTOR(DIGlobalVariable)
63 DECLARE_SIMPLIFY_DESCRIPTOR(DIVariable)
64 DECLARE_SIMPLIFY_DESCRIPTOR(DIExpression)
65 DECLARE_SIMPLIFY_DESCRIPTOR(DILocation)
66 DECLARE_SIMPLIFY_DESCRIPTOR(DIObjCProperty)
67 DECLARE_SIMPLIFY_DESCRIPTOR(DIImportedEntity)
68 #undef DECLARE_SIMPLIFY_DESCRIPTOR
69
7051 typedef DebugNodeArray DIArray;
7152 typedef MDTypeRefArray DITypeArray;
72
73 class DISubrange {
74 MDSubrange *N;
75
76 public:
77 DISubrange(const MDSubrange *N = nullptr) : N(const_cast(N)) {}
78
79 operator MDSubrange *() const { return N; }
80 MDSubrange *operator->() const { return N; }
81 MDSubrange &operator*() const { return *N; }
82 };
83
84 class DIEnumerator {
85 MDEnumerator *N;
86
87 public:
88 DIEnumerator(const MDEnumerator *N = nullptr)
89 : N(const_cast(N)) {}
90
91 operator MDEnumerator *() const { return N; }
92 MDEnumerator *operator->() const { return N; }
93 MDEnumerator &operator*() const { return *N; }
94 };
95
96 class DITemplateTypeParameter {
97 MDTemplateTypeParameter *N;
98
99 public:
100 DITemplateTypeParameter(const MDTemplateTypeParameter *N = nullptr)
101 : N(const_cast(N)) {}
102
103 operator MDTemplateTypeParameter *() const { return N; }
104 MDTemplateTypeParameter *operator->() const { return N; }
105 MDTemplateTypeParameter &operator*() const { return *N; }
106 };
107
108 class DITemplateValueParameter {
109 MDTemplateValueParameter *N;
110
111 public:
112 DITemplateValueParameter(const MDTemplateValueParameter *N = nullptr)
113 : N(const_cast(N)) {}
114
115 operator MDTemplateValueParameter *() const { return N; }
116 MDTemplateValueParameter *operator->() const { return N; }
117 MDTemplateValueParameter &operator*() const { return *N; }
118 };
119
120 class DIGlobalVariable {
121 MDGlobalVariable *N;
122
123 public:
124 DIGlobalVariable(const MDGlobalVariable *N = nullptr)
125 : N(const_cast(N)) {}
126
127 operator MDGlobalVariable *() const { return N; }
128 MDGlobalVariable *operator->() const { return N; }
129 MDGlobalVariable &operator*() const { return *N; }
130 };
131
132 class DIVariable {
133 MDLocalVariable *N;
134
135 public:
136 DIVariable(const MDLocalVariable *N = nullptr)
137 : N(const_cast(N)) {}
138
139 operator MDLocalVariable *() const { return N; }
140 MDLocalVariable *operator->() const { return N; }
141 MDLocalVariable &operator*() const { return *N; }
142 };
143
144 class DIExpression {
145 MDExpression *N;
146
147 public:
148 DIExpression(const MDExpression *N = nullptr)
149 : N(const_cast(N)) {}
150
151 operator MDExpression *() const { return N; }
152 MDExpression *operator->() const { return N; }
153 MDExpression &operator*() const { return *N; }
154 };
155
156 class DILocation {
157 MDLocation *N;
158
159 public:
160 DILocation(const MDLocation *N = nullptr) : N(const_cast(N)) {}
161
162 operator MDLocation *() const { return N; }
163 MDLocation *operator->() const { return N; }
164 MDLocation &operator*() const { return *N; }
165 };
166
167 class DIObjCProperty {
168 MDObjCProperty *N;
169
170 public:
171 DIObjCProperty(const MDObjCProperty *N = nullptr)
172 : N(const_cast(N)) {}
173
174 operator MDObjCProperty *() const { return N; }
175 MDObjCProperty *operator->() const { return N; }
176 MDObjCProperty &operator*() const { return *N; }
177 };
178
179 class DIImportedEntity {
180 MDImportedEntity *N;
181
182 public:
183 DIImportedEntity(const MDImportedEntity *N = nullptr)
184 : N(const_cast(N)) {}
185
186 operator MDImportedEntity *() const { return N; }
187 MDImportedEntity *operator->() const { return N; }
188 MDImportedEntity &operator*() const { return *N; }
189 };
190
191 #define SIMPLIFY_DESCRIPTOR(DESC) \
192 template <> struct simplify_type { \
193 typedef Metadata *SimpleType; \
194 static SimpleType getSimplifiedValue(const DESC &DI) { return DI; } \
195 }; \
196 template <> struct simplify_type : simplify_type {};
197 SIMPLIFY_DESCRIPTOR(DISubrange)
198 SIMPLIFY_DESCRIPTOR(DIEnumerator)
199 SIMPLIFY_DESCRIPTOR(DITemplateTypeParameter)
200 SIMPLIFY_DESCRIPTOR(DITemplateValueParameter)
201 SIMPLIFY_DESCRIPTOR(DIGlobalVariable)
202 SIMPLIFY_DESCRIPTOR(DIVariable)
203 SIMPLIFY_DESCRIPTOR(DIExpression)
204 SIMPLIFY_DESCRIPTOR(DILocation)
205 SIMPLIFY_DESCRIPTOR(DIObjCProperty)
206 SIMPLIFY_DESCRIPTOR(DIImportedEntity)
207 #undef SIMPLIFY_DESCRIPTOR
20853
20954 /// \brief Find subprogram that is enclosing this scope.
21055 MDSubprogram *getDISubprogram(const MDNode *Scope);
25095 void processDeclare(const Module &M, const DbgDeclareInst *DDI);
25196 /// \brief Process DbgValueInst.
25297 void processValue(const Module &M, const DbgValueInst *DVI);
253 /// \brief Process DILocation.
98 /// \brief Process debug info location.
25499 void processLocation(const Module &M, const MDLocation *Loc);
255100
256101 /// \brief Clear all lists.
8989 O << '\n';
9090 }
9191
92 for (DIGlobalVariable GV : Finder.global_variables()) {
92 for (const MDGlobalVariable *GV : Finder.global_variables()) {
9393 O << "Global variable: " << GV->getName();
9494 printFile(O, GV->getFilename(), GV->getDirectory(), GV->getLine());
9595 if (!GV->getLinkageName().empty())
669669 raw_svector_ostream OS(Str);
670670 OS << "DEBUG_VALUE: ";
671671
672 DIVariable V = MI->getDebugVariable();
672 const MDLocalVariable *V = MI->getDebugVariable();
673673 if (auto *SP = dyn_cast(V->getScope())) {
674674 StringRef Name = SP->getDisplayName();
675675 if (!Name.empty())
677677 }
678678 OS << V->getName();
679679
680 DIExpression Expr = MI->getDebugExpression();
680 const MDExpression *Expr = MI->getDebugExpression();
681681 if (Expr->isBitPiece())
682682 OS << " [bit_piece offset=" << Expr->getBitPieceOffset()
683683 << " size=" << Expr->getBitPieceSize() << "]";
203203 // Use the base variable (without any DW_OP_piece expressions)
204204 // as index into History. The full variables including the
205205 // piece expressions are attached to the MI.
206 MDLocalVariable *RawVar = MI.getDebugVariable();
206 const MDLocalVariable *RawVar = MI.getDebugVariable();
207207 assert(RawVar->isValidLocationForIntrinsic(MI.getDebugLoc()) &&
208208 "Expected inlined-at fields to agree");
209209 InlinedVariable Var(RawVar, MI.getDebugLoc()->getInlinedAt());
7171 const ConstantInt *getConstantInt() const { return Constant.CIP; }
7272 MachineLocation getLoc() const { return Loc; }
7373 bool isBitPiece() const { return getExpression()->isBitPiece(); }
74 DIExpression getExpression() const { return Expression; }
74 const MDExpression *getExpression() const { return Expression; }
7575 friend bool operator==(const Value &, const Value &);
7676 friend bool operator<(const Value &, const Value &);
7777 };
9393 /// Return true if the merge was successful.
9494 bool MergeValues(const DebugLocEntry &Next) {
9595 if (Begin == Next.Begin) {
96 DIExpression Expr = cast_or_null(Values[0].Expression);
97 DIExpression NextExpr =
98 cast_or_null(Next.Values[0].Expression);
96 auto *Expr = cast_or_null(Values[0].Expression);
97 auto *NextExpr = cast_or_null(Next.Values[0].Expression);
9998 if (Expr->isBitPiece() && NextExpr->isBitPiece()) {
10099 addValues(Next.Values);
101100 End = Next.End;
9696 }
9797
9898 /// getOrCreateGlobalVariableDIE - get or create global variable DIE.
99 DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE(DIGlobalVariable GV) {
99 DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE(
100 const MDGlobalVariable *GV) {
100101 // Check for pre-existence.
101102 if (DIE *Die = getDIE(GV))
102103 return Die;
631632 }
632633
633634 std::unique_ptr
634 DwarfCompileUnit::constructImportedEntityDIE(const DIImportedEntity &Module) {
635 DwarfCompileUnit::constructImportedEntityDIE(const MDImportedEntity *Module) {
635636 std::unique_ptr IMDie = make_unique((dwarf::Tag)Module->getTag());
636637 insertDIE(Module, IMDie.get());
637638 DIE *EntityDie;
686687 if (!SPDIE)
687688 SPDIE = getDIE(SP);
688689 assert(SPDIE);
689 for (DIVariable DV : Variables) {
690 DbgVariable NewVar(DV, nullptr, DIExpression(), DD);
690 for (const MDLocalVariable *DV : Variables) {
691 DbgVariable NewVar(DV, /* IA */ nullptr, /* Expr */ nullptr, DD);
691692 auto VariableDie = constructVariableDIE(NewVar);
692693 applyVariableAttributes(NewVar, *VariableDie);
693694 SPDIE->addChild(std::move(VariableDie));
762763 DIELoc *Loc = new (DIEValueAllocator) DIELoc();
763764 DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
764765 assert(DV.getExpression().size() == 1);
765 DIExpression Expr = DV.getExpression().back();
766 const MDExpression *Expr = DV.getExpression().back();
766767 bool ValidReg;
767768 if (Location.getOffset()) {
768769 ValidReg = DwarfExpr.AddMachineRegIndirect(Location.getReg(),
7878 void applyStmtList(DIE &D);
7979
8080 /// getOrCreateGlobalVariableDIE - get or create global variable DIE.
81 DIE *getOrCreateGlobalVariableDIE(DIGlobalVariable GV);
81 DIE *getOrCreateGlobalVariableDIE(const MDGlobalVariable *GV);
8282
8383 /// addLabelAddress - Add a dwarf label attribute data and value using
8484 /// either DW_FORM_addr or DW_FORM_GNU_addr_index.
155155
156156 /// \brief Construct import_module DIE.
157157 std::unique_ptr
158 constructImportedEntityDIE(const DIImportedEntity &Module);
158 constructImportedEntityDIE(const MDImportedEntity *Module);
159159
160160 void finishSubprogramDefinition(const MDSubprogram *SP);
161161
421421 }
422422
423423 void DwarfDebug::constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU,
424 const MDNode *N) {
425 DIImportedEntity Module = cast(N);
426 if (DIE *D = TheCU.getOrCreateContextDIE(Module->getScope()))
427 D->addChild(TheCU.constructImportedEntityDIE(Module));
424 const MDImportedEntity *N) {
425 if (DIE *D = TheCU.getOrCreateContextDIE(N->getScope()))
426 D->addChild(TheCU.constructImportedEntityDIE(N));
428427 }
429428
430429 // Emit all Dwarf sections that should come prior to the content. Create
660659 }
661660
662661 // Find abstract variable, if any, associated with Var.
663 DbgVariable *DwarfDebug::getExistingAbstractVariable(InlinedVariable IV,
664 DIVariable &Cleansed) {
662 DbgVariable *
663 DwarfDebug::getExistingAbstractVariable(InlinedVariable IV,
664 const MDLocalVariable *&Cleansed) {
665665 // More then one inlined variable corresponds to one abstract variable.
666666 Cleansed = IV.first;
667667 auto I = AbstractVariables.find(Cleansed);
671671 }
672672
673673 DbgVariable *DwarfDebug::getExistingAbstractVariable(InlinedVariable IV) {
674 DIVariable Cleansed;
674 const MDLocalVariable *Cleansed;
675675 return getExistingAbstractVariable(IV, Cleansed);
676676 }
677677
678 void DwarfDebug::createAbstractVariable(const DIVariable &Var,
678 void DwarfDebug::createAbstractVariable(const MDLocalVariable *Var,
679679 LexicalScope *Scope) {
680680 auto AbsDbgVariable =
681 make_unique(Var, nullptr, DIExpression(), this);
681 make_unique(Var, /* IA */ nullptr, /* Expr */ nullptr, this);
682682 InfoHolder.addScopeVariable(Scope, AbsDbgVariable.get());
683683 AbstractVariables[Var] = std::move(AbsDbgVariable);
684684 }
685685
686686 void DwarfDebug::ensureAbstractVariableIsCreated(InlinedVariable IV,
687687 const MDNode *ScopeNode) {
688 DIVariable Cleansed;
688 const MDLocalVariable *Cleansed = nullptr;
689689 if (getExistingAbstractVariable(IV, Cleansed))
690690 return;
691691
695695
696696 void DwarfDebug::ensureAbstractVariableIsCreatedIfScoped(
697697 InlinedVariable IV, const MDNode *ScopeNode) {
698 DIVariable Cleansed;
698 const MDLocalVariable *Cleansed = nullptr;
699699 if (getExistingAbstractVariable(IV, Cleansed))
700700 return;
701701
721721 if (!Scope)
722722 continue;
723723
724 DIExpression Expr = cast_or_null(VI.Expr);
724 const MDExpression *Expr = cast_or_null(VI.Expr);
725725 ensureAbstractVariableIsCreatedIfScoped(Var, Scope->getScopeNode());
726726 auto RegVar =
727727 make_unique(Var.first, Var.second, Expr, this, VI.Slot);
756756 }
757757
758758 /// Determine whether two variable pieces overlap.
759 static bool piecesOverlap(DIExpression P1, DIExpression P2) {
759 static bool piecesOverlap(const MDExpression *P1, const MDExpression *P2) {
760760 if (!P1->isBitPiece() || !P2->isBitPiece())
761761 return true;
762762 unsigned l1 = P1->getBitPieceOffset();
808808 }
809809
810810 // If this piece overlaps with any open ranges, truncate them.
811 DIExpression DIExpr = Begin->getDebugExpression();
811 const MDExpression *DIExpr = Begin->getDebugExpression();
812812 auto Last = std::remove_if(OpenRanges.begin(), OpenRanges.end(),
813813 [&](DebugLocEntry::Value R) {
814814 return piecesOverlap(DIExpr, R.getExpression());
929929 }
930930
931931 // Collect info for variables that were optimized out.
932 for (DIVariable DV : SP->getVariables()) {
932 for (const MDLocalVariable *DV : SP->getVariables()) {
933933 if (!Processed.insert(InlinedVariable(DV, nullptr)).second)
934934 continue;
935935 if (LexicalScope *Scope = LScopes.findLexicalScope(DV->getScope())) {
936936 ensureAbstractVariableIsCreatedIfScoped(InlinedVariable(DV, nullptr),
937937 Scope->getScopeNode());
938 DIExpression NoExpr;
939 ConcreteVariables.push_back(
940 make_unique(DV, nullptr, NoExpr, this));
938 ConcreteVariables.push_back(make_unique(
939 DV, /* IA */ nullptr, /* Expr */ nullptr, this));
941940 InfoHolder.addScopeVariable(Scope, ConcreteVariables.back().get());
942941 }
943942 }
11281127
11291128 // The first mention of a function argument gets the CurrentFnBegin
11301129 // label, so arguments are visible when breaking at function entry.
1131 DIVariable DIVar = Ranges.front().first->getDebugVariable();
1130 const MDLocalVariable *DIVar = Ranges.front().first->getDebugVariable();
11321131 if (DIVar->getTag() == dwarf::DW_TAG_arg_variable &&
11331132 getDISubprogram(DIVar->getScope())->describes(MF->getFunction())) {
11341133 LabelsBeforeInsn[Ranges.front().first] = Asm->getFunctionBegin();
11351134 if (Ranges.front().first->getDebugExpression()->isBitPiece()) {
11361135 // Mark all non-overlapping initial pieces.
11371136 for (auto I = Ranges.begin(); I != Ranges.end(); ++I) {
1138 DIExpression Piece = I->first->getDebugExpression();
1137 const MDExpression *Piece = I->first->getDebugExpression();
11391138 if (std::all_of(Ranges.begin(), I,
11401139 [&](DbgValueHistoryMap::InstrRange Pred) {
11411140 return !piecesOverlap(Piece, Pred.first->getDebugExpression());
12181217 for (LexicalScope *AScope : LScopes.getAbstractScopesList()) {
12191218 auto *SP = cast(AScope->getScopeNode());
12201219 // Collect info for variables that were optimized out.
1221 for (DIVariable DV : SP->getVariables()) {
1220 for (const MDLocalVariable *DV : SP->getVariables()) {
12221221 if (!ProcessedVars.insert(InlinedVariable(DV, nullptr)).second)
12231222 continue;
12241223 ensureAbstractVariableIsCreated(InlinedVariable(DV, nullptr),
14871486 DwarfExpr.AddUnsignedConstant(Value.getInt());
14881487 } else if (Value.isLocation()) {
14891488 MachineLocation Loc = Value.getLoc();
1490 DIExpression Expr = Value.getExpression();
1489 const MDExpression *Expr = Value.getExpression();
14911490 if (!Expr || !Expr->getNumElements())
14921491 // Regular entry.
14931492 AP.EmitDwarfRegOp(Streamer, Loc);
15221521
15231522 unsigned Offset = 0;
15241523 for (auto Piece : Values) {
1525 DIExpression Expr = Piece.getExpression();
1524 const MDExpression *Expr = Piece.getExpression();
15261525 unsigned PieceOffset = Expr->getBitPieceOffset();
15271526 unsigned PieceSize = Expr->getBitPieceSize();
15281527 assert(Offset <= PieceOffset && "overlapping or duplicate pieces");
7474 /// - Variables that are described by multiple MMI table entries have multiple
7575 /// expressions and frame indices.
7676 class DbgVariable {
77 DIVariable Var; /// Variable Descriptor.
78 DILocation IA; /// Inlined at location.
79 SmallVector Expr; /// Complex address location expression.
77 const MDLocalVariable *Var; /// Variable Descriptor.
78 const MDLocation *IA; /// Inlined at location.
79 SmallVector
80 Expr; /// Complex address location expression.
8081 DIE *TheDIE; /// Variable DIE.
8182 unsigned DebugLocListIndex; /// Offset in DebugLocs.
8283 const MachineInstr *MInsn; /// DBG_VALUE instruction of the variable.
8485 DwarfDebug *DD;
8586
8687 public:
87 /// Construct a DbgVariable from a DIVariable.
88 DbgVariable(DIVariable V, DILocation IA, DIExpression E, DwarfDebug *DD,
89 int FI = ~0)
88 /// Construct a DbgVariable from a variable.
89 DbgVariable(const MDLocalVariable *V, const MDLocation *IA,
90 const MDExpression *E, DwarfDebug *DD, int FI = ~0)
9091 : Var(V), IA(IA), Expr(1, E), TheDIE(nullptr), DebugLocListIndex(~0U),
9192 MInsn(nullptr), DD(DD) {
9293 FrameIndex.push_back(FI);
104105 }
105106
106107 // Accessors.
107 DIVariable getVariable() const { return Var; }
108 DILocation getInlinedAt() const { return IA; }
109 const ArrayRef getExpression() const { return Expr; }
108 const MDLocalVariable *getVariable() const { return Var; }
109 const MDLocation *getInlinedAt() const { return IA; }
110 const ArrayRef getExpression() const { return Expr; }
110111 void setDIE(DIE &D) { TheDIE = &D; }
111112 DIE *getDIE() const { return TheDIE; }
112113 void setDebugLocListIndex(unsigned O) { DebugLocListIndex = O; }
118119 void addMMIEntry(const DbgVariable &V) {
119120 assert(DebugLocListIndex == ~0U && !MInsn && "not an MMI entry");
120121 assert(V.DebugLocListIndex == ~0U && !V.MInsn && "not an MMI entry");
121 assert(V.Var == Var && "conflicting DIVariable");
122 assert(V.Var == Var && "conflicting variable");
122123 assert(V.IA == IA && "conflicting inlined-at location");
123124
124125 if (V.getFrameIndex().back() != ~0) {
127128 Expr.append(E.begin(), E.end());
128129 FrameIndex.append(FI.begin(), FI.end());
129130 }
130 assert(Expr.size() > 1
131 ? std::all_of(Expr.begin(), Expr.end(),
132 [](DIExpression &E) { return E->isBitPiece(); })
133 : (true && "conflicting locations for variable"));
131 assert(Expr.size() > 1 ? std::all_of(Expr.begin(), Expr.end(),
132 [](const MDExpression *E) {
133 return E->isBitPiece();
134 })
135 : (true && "conflicting locations for variable"));
134136 }
135137
136138 // Translate tag to proper Dwarf tag.
333335
334336 /// \brief Find abstract variable associated with Var.
335337 DbgVariable *getExistingAbstractVariable(InlinedVariable IV,
336 DIVariable &Cleansed);
338 const MDLocalVariable *&Cleansed);
337339 DbgVariable *getExistingAbstractVariable(InlinedVariable IV);
338 void createAbstractVariable(const DIVariable &DV, LexicalScope *Scope);
340 void createAbstractVariable(const MDLocalVariable *DV, LexicalScope *Scope);
339341 void ensureAbstractVariableIsCreated(InlinedVariable Var,
340342 const MDNode *Scope);
341343 void ensureAbstractVariableIsCreatedIfScoped(InlinedVariable Var,
454456
455457 /// \brief Construct imported_module or imported_declaration DIE.
456458 void constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU,
457 const MDNode *N);
459 const MDImportedEntity *N);
458460
459461 /// \brief Register a source line with debug info. Returns the unique
460462 /// label that was emitted and which provides correspondence to the
191191 return OffsetInBits;
192192 }
193193
194 bool DwarfExpression::AddMachineRegExpression(DIExpression Expr,
194 bool DwarfExpression::AddMachineRegExpression(const MDExpression *Expr,
195195 unsigned MachineReg,
196196 unsigned PieceOffsetInBits) {
197197 auto I = Expr->expr_op_begin();
258258 EmitOp(dwarf::DW_OP_deref);
259259 break;
260260 default:
261 llvm_unreachable("unhandled opcode found in DIExpression");
262 }
263 }
264 }
261 llvm_unreachable("unhandled opcode found in expression");
262 }
263 }
264 }
8787 /// Emit an unsigned constant.
8888 void AddUnsignedConstant(unsigned Value);
8989
90 /// Emit an entire DIExpression on top of a machine register location.
90 /// \brief Emit an entire expression on top of a machine register location.
91 ///
9192 /// \param PieceOffsetInBits If this is one piece out of a fragmented
9293 /// location, this is the offset of the piece inside the entire variable.
9394 /// \return false if no DWARF register exists for MachineReg.
94 bool AddMachineRegExpression(DIExpression Expr, unsigned MachineReg,
95 bool AddMachineRegExpression(const MDExpression *Expr, unsigned MachineReg,
9596 unsigned PieceOffsetInBits = 0);
9697 /// Emit a the operations remaining the DIExpressionIterator I.
9798 /// \param PieceOffsetInBits If this is one piece out of a fragmented
136136
137137 bool DwarfFile::addScopeVariable(LexicalScope *LS, DbgVariable *Var) {
138138 SmallVectorImpl &Vars = ScopeVariables[LS];
139 DIVariable DV = Var->getVariable();
139 const MDLocalVariable *DV = Var->getVariable();
140140 // Variables with positive arg numbers are parameters.
141141 if (unsigned ArgNum = DV->getArg()) {
142142 // Keep all parameters in order at the start of the variable list to ensure
353353 addUInt(Die, dwarf::DW_AT_decl_line, None, Line);
354354 }
355355
356 void DwarfUnit::addSourceLine(DIE &Die, DIVariable V) {
356 void DwarfUnit::addSourceLine(DIE &Die, const MDLocalVariable *V) {
357357 assert(V);
358358
359359 addSourceLine(Die, V->getLine(), V->getScope()->getFilename(),
360360 V->getScope()->getDirectory());
361361 }
362362
363 void DwarfUnit::addSourceLine(DIE &Die, DIGlobalVariable G) {
363 void DwarfUnit::addSourceLine(DIE &Die, const MDGlobalVariable *G) {
364364 assert(G);
365365
366366 addSourceLine(Die, G->getLine(), G->getFilename(), G->getDirectory());
378378 addSourceLine(Die, Ty->getLine(), Ty->getFilename(), Ty->getDirectory());
379379 }
380380
381 void DwarfUnit::addSourceLine(DIE &Die, DIObjCProperty Ty) {
381 void DwarfUnit::addSourceLine(DIE &Die, const MDObjCProperty *Ty) {
382382 assert(Ty);
383383
384384 addSourceLine(Die, Ty->getLine(), Ty->getFilename(), Ty->getDirectory());
975975 } else {
976976 constructMemberDIE(Buffer, DDTy);
977977 }
978 } else if (DIObjCProperty Property = dyn_cast(Element)) {
978 } else if (auto *Property = dyn_cast(Element)) {
979979 DIE &ElemDie = createAndAddDIE(Property->getTag(), Buffer);
980980 StringRef PropertyName = Property->getName();
981981 addString(ElemDie, dwarf::DW_AT_APPLE_property_name, PropertyName);
10561056 }
10571057 }
10581058
1059 void DwarfUnit::constructTemplateTypeParameterDIE(DIE &Buffer,
1060 DITemplateTypeParameter TP) {
1059 void DwarfUnit::constructTemplateTypeParameterDIE(
1060 DIE &Buffer, const MDTemplateTypeParameter *TP) {
10611061 DIE &ParamDIE =
10621062 createAndAddDIE(dwarf::DW_TAG_template_type_parameter, Buffer);
10631063 // Add the type if it exists, it could be void and therefore no type.
10671067 addString(ParamDIE, dwarf::DW_AT_name, TP->getName());
10681068 }
10691069
1070 void
1071 DwarfUnit::constructTemplateValueParameterDIE(DIE &Buffer,
1072 DITemplateValueParameter VP) {
1070 void DwarfUnit::constructTemplateValueParameterDIE(
1071 DIE &Buffer, const MDTemplateValueParameter *VP) {
10731072 DIE &ParamDIE = createAndAddDIE(VP->getTag(), Buffer);
10741073
10751074 // Add the type if there is one, template template and template parameter
12691268 addFlag(SPDie, dwarf::DW_AT_explicit);
12701269 }
12711270
1272 void DwarfUnit::constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy) {
1271 void DwarfUnit::constructSubrangeDIE(DIE &Buffer, const MDSubrange *SR,
1272 DIE *IndexTy) {
12731273 DIE &DW_Subrange = createAndAddDIE(dwarf::DW_TAG_subrange_type, Buffer);
12741274 addDIEEntry(DW_Subrange, dwarf::DW_AT_type, *IndexTy);
12751275
245245 /// \brief Add location information to specified debug information entry.
246246 void addSourceLine(DIE &Die, unsigned Line, StringRef File,
247247 StringRef Directory);
248 void addSourceLine(DIE &Die, DIVariable V);
249 void addSourceLine(DIE &Die, DIGlobalVariable G);
248 void addSourceLine(DIE &Die, const MDLocalVariable *V);
249 void addSourceLine(DIE &Die, const MDGlobalVariable *G);
250250 void addSourceLine(DIE &Die, const MDSubprogram *SP);
251251 void addSourceLine(DIE &Die, const MDType *Ty);
252252 void addSourceLine(DIE &Die, const MDNamespace *NS);
253 void addSourceLine(DIE &Die, DIObjCProperty Ty);
253 void addSourceLine(DIE &Die, const MDObjCProperty *Ty);
254254
255255 /// \brief Add constant value entry in variable DIE.
256256 void addConstantValue(DIE &Die, const MachineOperand &MO, const MDType *Ty);
354354 void constructTypeDIE(DIE &Buffer, const MDBasicType *BTy);
355355 void constructTypeDIE(DIE &Buffer, const MDDerivedType *DTy);
356356 void constructTypeDIE(DIE &Buffer, const MDSubroutineType *DTy);
357 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
357 void constructSubrangeDIE(DIE &Buffer, const MDSubrange *SR, DIE *IndexTy);
358358 void constructArrayTypeDIE(DIE &Buffer, const MDCompositeType *CTy);
359359 void constructEnumTypeDIE(DIE &Buffer, const MDCompositeType *CTy);
360360 void constructMemberDIE(DIE &Buffer, const MDDerivedType *DT);
361361 void constructTemplateTypeParameterDIE(DIE &Buffer,
362 DITemplateTypeParameter TP);
362 const MDTemplateTypeParameter *TP);
363363 void constructTemplateValueParameterDIE(DIE &Buffer,
364 DITemplateValueParameter TVP);
364 const MDTemplateValueParameter *TVP);
365365
366366 /// \brief Return the default lower bound for an array.
367367 ///
393393 }
394394
395395 void UserValue::print(raw_ostream &OS, const TargetRegisterInfo *TRI) {
396 DIVariable DV = cast(Variable);
396 auto *DV = cast(Variable);
397397 OS << "!\"";
398398 printExtendedName(OS, DV, dl);
399399
16181618 }
16191619 if (isDebugValue() && MO.isMetadata()) {
16201620 // Pretty print DBG_VALUE instructions.
1621 DIVariable DIV = dyn_cast(MO.getMetadata());
1621 auto *DIV = dyn_cast(MO.getMetadata());
16221622 if (DIV && !DIV->getName().empty())
16231623 OS << "!\"" << DIV->getName() << '\"';
16241624 else
17091709 // Print debug location information.
17101710 if (isDebugValue() && getOperand(e - 2).isMetadata()) {
17111711 if (!HaveSemi) OS << ";";
1712 DIVariable DV = cast(getOperand(e - 2).getMetadata());
1712 auto *DV = cast(getOperand(e - 2).getMetadata());
17131713 OS << " line no:" << DV->getLine();
17141714 if (auto *InlinedAt = debugLoc->getInlinedAt()) {
17151715 DebugLoc InlinedAtDL(InlinedAt);
44624462 // Ignore inlined function arguments here.
44634463 //
44644464 // FIXME: Should we be checking DL->inlinedAt() to determine this?
4465 DIVariable DV(Variable);
4466 if (!DV->getScope()->getSubprogram()->describes(MF.getFunction()))
4465 if (!Variable->getScope()->getSubprogram()->describes(MF.getFunction()))
44674466 return false;
44684467
44694468 Optional Op;
46714670 if (const BitCastInst *BCI = dyn_cast(Address))
46724671 Address = BCI->getOperand(0);
46734672 // Parameters are handled specially.
4674 bool isParameter =
4675 (DIVariable(Variable)->getTag() == dwarf::DW_TAG_arg_variable ||
4676 isa(Address));
4673 bool isParameter = Variable->getTag() == dwarf::DW_TAG_arg_variable ||
4674 isa(Address);
46774675
46784676 const AllocaInst *AI = dyn_cast(Address);
46794677
320320 }
321321
322322 // Create our live global variable list.
323 MDGlobalVariableArray GVs = DIC->getGlobalVariables();
324323 bool GlobalVariableChange = false;
325 for (unsigned i = 0, e = GVs.size(); i != e; ++i) {
326 DIGlobalVariable DIG = GVs[i];
327
324 for (MDGlobalVariable *DIG : DIC->getGlobalVariables()) {
328325 // Make sure we only visit each global variable only once.
329326 if (!VisitedSet.insert(DIG).second)
330327 continue;
11651165 } else {
11661166 continue;
11671167 }
1168 DIB.insertDbgValueIntrinsic(Arg, 0, DIVariable(DVI->getVariable()),
1169 DIExpression(DVI->getExpression()),
1170 DVI->getDebugLoc(), Inst);
1168 DIB.insertDbgValueIntrinsic(Arg, 0, DVI->getVariable(),
1169 DVI->getExpression(), DVI->getDebugLoc(),
1170 Inst);
11711171 }
11721172 }
11731173 };
41804180 // Migrate debug information from the old alloca to the new alloca(s)
41814181 // and the individial partitions.
41824182 if (DbgDeclareInst *DbgDecl = FindAllocaDbgDeclare(&AI)) {
4183 DIVariable Var(DbgDecl->getVariable());
4184 DIExpression Expr(DbgDecl->getExpression());
4183 auto *Var = DbgDecl->getVariable();
4184 auto *Expr = DbgDecl->getExpression();
41854185 DIBuilder DIB(*AI.getParent()->getParent()->getParent(),
41864186 /*AllowUnresolved*/ false);
41874187 bool IsSplit = Pieces.size() > 1;
41884188 for (auto Piece : Pieces) {
41894189 // Create a piece expression describing the new partition or reuse AI's
41904190 // expression if there is only one partition.
4191 DIExpression PieceExpr = Expr;
4191 auto *PieceExpr = Expr;
41924192 if (IsSplit || Expr->isBitPiece()) {
41934193 // If this alloca is already a scalar replacement of a larger aggregate,
41944194 // Piece.Offset describes the offset inside the scalar.
223223 if (Lineno < HeaderLineno)
224224 return 0;
225225
226 DILocation DIL = DLoc.get();
226 const MDLocation *DIL = DLoc;
227227 int LOffset = Lineno - HeaderLineno;
228228 unsigned Discriminator = DIL->getDiscriminator();
229229 unsigned Weight = Samples->samplesAt(LOffset, Discriminator);
11161116 } else {
11171117 continue;
11181118 }
1119 DIB->insertDbgValueIntrinsic(Arg, 0, DIVariable(DVI->getVariable()),
1120 DIExpression(DVI->getExpression()),
1121 DVI->getDebugLoc(), Inst);
1119 DIB->insertDbgValueIntrinsic(Arg, 0, DVI->getVariable(),
1120 DVI->getExpression(), DVI->getDebugLoc(),
1121 Inst);
11221122 }
11231123 }
11241124 };
173173 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
174174 BasicBlock *B = I;
175175 TerminatorInst *Last = B->getTerminator();
176 DILocation LastDIL = Last->getDebugLoc().get();
176 const MDLocation *LastDIL = Last->getDebugLoc();
177177 if (!LastDIL)
178178 continue;
179179
180180 for (unsigned I = 0; I < Last->getNumSuccessors(); ++I) {
181181 BasicBlock *Succ = Last->getSuccessor(I);
182182 Instruction *First = Succ->getFirstNonPHIOrDbgOrLifetime();
183 DILocation FirstDIL = First->getDebugLoc().get();
183 const MDLocation *FirstDIL = First->getDebugLoc();
184184 if (!FirstDIL)
185185 continue;
186186
977977 ///
978978
979979 /// See if there is a dbg.value intrinsic for DIVar before I.
980 static bool LdStHasDebugValue(DIVariable &DIVar, Instruction *I) {
980 static bool LdStHasDebugValue(const MDLocalVariable *DIVar, Instruction *I) {
981981 // Since we can't guarantee that the original dbg.declare instrinsic
982982 // is removed by LowerDbgDeclare(), we need to make sure that we are
983983 // not inserting the same dbg.value intrinsic over and over.
997997 /// that has an associated llvm.dbg.decl intrinsic.
998998 bool llvm::ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI,
999999 StoreInst *SI, DIBuilder &Builder) {
1000 DIVariable DIVar = DDI->getVariable();
1001 DIExpression DIExpr = DDI->getExpression();
1000 auto *DIVar = DDI->getVariable();
1001 auto *DIExpr = DDI->getExpression();
10021002 assert(DIVar && "Missing variable");
10031003
10041004 if (LdStHasDebugValue(DIVar, SI))
10241024 /// that has an associated llvm.dbg.decl intrinsic.
10251025 bool llvm::ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI,
10261026 LoadInst *LI, DIBuilder &Builder) {
1027 DIVariable DIVar = DDI->getVariable();
1028 DIExpression DIExpr = DDI->getExpression();
1027 auto *DIVar = DDI->getVariable();
1028 auto *DIExpr = DDI->getExpression();
10291029 assert(DIVar && "Missing variable");
10301030
10311031 if (LdStHasDebugValue(DIVar, LI))
10741074 // This is a call by-value or some other instruction that
10751075 // takes a pointer to the variable. Insert a *value*
10761076 // intrinsic that describes the alloca.
1077 DIB.insertDbgValueIntrinsic(AI, 0, DIVariable(DDI->getVariable()),
1078 DIExpression(DDI->getExpression()),
1079 DDI->getDebugLoc(), CI);
1077 DIB.insertDbgValueIntrinsic(AI, 0, DDI->getVariable(),
1078 DDI->getExpression(), DDI->getDebugLoc(),
1079 CI);
10801080 }
10811081 DDI->eraseFromParent();
10821082 }
11021102 if (!DDI)
11031103 return false;
11041104 DebugLoc Loc = DDI->getDebugLoc();
1105 DIVariable DIVar = DDI->getVariable();
1106 DIExpression DIExpr = DDI->getExpression();
1105 auto *DIVar = DDI->getVariable();
1106 auto *DIExpr = DDI->getExpression();
11071107 assert(DIVar && "Missing variable");
11081108
11091109 if (Deref) {
9393 OS << "]";
9494 }
9595 if (const DbgDeclareInst *DDI = dyn_cast(I)) {
96 DIVariable Var(DDI->getVariable());
9796 if (!Padded) {
9897 OS.PadToColumn(50);
9998 OS << ";";
10099 }
101 OS << " [debug variable = " << Var->getName() << "]";
100 OS << " [debug variable = " << DDI->getVariable()->getName() << "]";
102101 }
103102 else if (const DbgValueInst *DVI = dyn_cast(I)) {
104 DIVariable Var(DVI->getVariable());
105103 if (!Padded) {
106104 OS.PadToColumn(50);
107105 OS << ";";
108106 }
109 OS << " [debug variable = " << Var->getName() << "]";
107 OS << " [debug variable = " << DVI->getVariable()->getName() << "]";
110108 }
111109 }
112110 }
253253 // Create a local variable around the alloca
254254 auto *IntType =
255255 DBuilder.createBasicType("int", 32, 0, dwarf::DW_ATE_signed);
256 DIExpression E = DBuilder.createExpression();
257 DIVariable Variable = DBuilder.createLocalVariable(
258 dwarf::DW_TAG_auto_variable, Subprogram, "x", File, 5, IntType, true);
256 auto *E = DBuilder.createExpression();
257 auto *Variable = DBuilder.createLocalVariable(
258 dwarf::DW_TAG_auto_variable, Subprogram, "x", File, 5, IntType, true);
259259 auto *DL = MDLocation::get(Subprogram->getContext(), 5, 0, Subprogram);
260260 DBuilder.insertDeclare(Alloca, Variable, E, DL, Store);
261261 DBuilder.insertDbgValueIntrinsic(AllocaContent, 0, Variable, E, DL,