0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 //===--- DIBuilder.cpp - Debug Information Builder ------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 //
|
147
|
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
4 // See https://llvm.org/LICENSE.txt for license information.
|
|
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 // This file implements the DIBuilder.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12
|
77
|
13 #include "llvm/IR/DIBuilder.h"
|
121
|
14 #include "llvm/IR/IRBuilder.h"
|
|
15 #include "LLVMContextImpl.h"
|
147
|
16 #include "llvm/ADT/Optional.h"
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 #include "llvm/ADT/STLExtras.h"
|
121
|
18 #include "llvm/BinaryFormat/Dwarf.h"
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 #include "llvm/IR/Constants.h"
|
77
|
20 #include "llvm/IR/DebugInfo.h"
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 #include "llvm/IR/IntrinsicInst.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 #include "llvm/IR/Module.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 #include "llvm/Support/Debug.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 using namespace llvm;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 using namespace llvm::dwarf;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27
|
121
|
28 cl::opt<bool>
|
|
29 UseDbgAddr("use-dbg-addr",
|
134
|
30 llvm::cl::desc("Use llvm.dbg.addr for all local variables"),
|
|
31 cl::init(false), cl::Hidden);
|
121
|
32
|
134
|
33 DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes, DICompileUnit *CU)
|
|
34 : M(m), VMContext(M.getContext()), CUNode(CU),
|
147
|
35 DeclareFn(nullptr), ValueFn(nullptr), LabelFn(nullptr),
|
83
|
36 AllowUnresolvedNodes(AllowUnresolvedNodes) {}
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37
|
83
|
38 void DIBuilder::trackIfUnresolved(MDNode *N) {
|
|
39 if (!N)
|
|
40 return;
|
|
41 if (N->isResolved())
|
|
42 return;
|
|
43
|
|
44 assert(AllowUnresolvedNodes && "Cannot handle unresolved nodes");
|
|
45 UnresolvedNodes.emplace_back(N);
|
|
46 }
|
|
47
|
121
|
48 void DIBuilder::finalizeSubprogram(DISubprogram *SP) {
|
147
|
49 MDTuple *Temp = SP->getRetainedNodes().get();
|
121
|
50 if (!Temp || !Temp->isTemporary())
|
|
51 return;
|
|
52
|
147
|
53 SmallVector<Metadata *, 16> RetainedNodes;
|
121
|
54
|
|
55 auto PV = PreservedVariables.find(SP);
|
|
56 if (PV != PreservedVariables.end())
|
147
|
57 RetainedNodes.append(PV->second.begin(), PV->second.end());
|
121
|
58
|
147
|
59 auto PL = PreservedLabels.find(SP);
|
|
60 if (PL != PreservedLabels.end())
|
|
61 RetainedNodes.append(PL->second.begin(), PL->second.end());
|
|
62
|
|
63 DINodeArray Node = getOrCreateArray(RetainedNodes);
|
|
64
|
|
65 TempMDTuple(Temp)->replaceAllUsesWith(Node.get());
|
121
|
66 }
|
|
67
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
68 void DIBuilder::finalize() {
|
95
|
69 if (!CUNode) {
|
|
70 assert(!AllowUnresolvedNodes &&
|
|
71 "creating type nodes without a CU is not supported");
|
|
72 return;
|
|
73 }
|
|
74
|
|
75 CUNode->replaceEnumTypes(MDTuple::get(VMContext, AllEnumTypes));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76
|
83
|
77 SmallVector<Metadata *, 16> RetainValues;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78 // Declarations and definitions of the same type may be retained. Some
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 // clients RAUW these pairs, leaving duplicates in the retained types
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 // list. Use a set to remove the duplicates while we transform the
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 // TrackingVHs back into Values.
|
83
|
82 SmallPtrSet<Metadata *, 16> RetainSet;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
83 for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++)
|
83
|
84 if (RetainSet.insert(AllRetainTypes[I]).second)
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85 RetainValues.push_back(AllRetainTypes[I]);
|
95
|
86
|
|
87 if (!RetainValues.empty())
|
|
88 CUNode->replaceRetainedTypes(MDTuple::get(VMContext, RetainValues));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
89
|
95
|
90 DISubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms);
|
120
|
91 for (auto *SP : SPs)
|
121
|
92 finalizeSubprogram(SP);
|
120
|
93 for (auto *N : RetainValues)
|
|
94 if (auto *SP = dyn_cast<DISubprogram>(N))
|
121
|
95 finalizeSubprogram(SP);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
96
|
95
|
97 if (!AllGVs.empty())
|
|
98 CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
99
|
95
|
100 if (!AllImportedModules.empty())
|
|
101 CUNode->replaceImportedEntities(MDTuple::get(
|
|
102 VMContext, SmallVector<Metadata *, 16>(AllImportedModules.begin(),
|
|
103 AllImportedModules.end())));
|
83
|
104
|
121
|
105 for (const auto &I : AllMacrosPerParent) {
|
|
106 // DIMacroNode's with nullptr parent are DICompileUnit direct children.
|
|
107 if (!I.first) {
|
|
108 CUNode->replaceMacros(MDTuple::get(VMContext, I.second.getArrayRef()));
|
|
109 continue;
|
|
110 }
|
|
111 // Otherwise, it must be a temporary DIMacroFile that need to be resolved.
|
|
112 auto *TMF = cast<DIMacroFile>(I.first);
|
|
113 auto *MF = DIMacroFile::get(VMContext, dwarf::DW_MACINFO_start_file,
|
|
114 TMF->getLine(), TMF->getFile(),
|
|
115 getOrCreateMacroArray(I.second.getArrayRef()));
|
|
116 replaceTemporary(llvm::TempDIMacroNode(TMF), MF);
|
|
117 }
|
|
118
|
83
|
119 // Now that all temp nodes have been replaced or deleted, resolve remaining
|
|
120 // cycles.
|
|
121 for (const auto &N : UnresolvedNodes)
|
|
122 if (N && !N->isResolved())
|
|
123 N->resolveCycles();
|
|
124 UnresolvedNodes.clear();
|
|
125
|
|
126 // Can't handle unresolved nodes anymore.
|
|
127 AllowUnresolvedNodes = false;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
128 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
129
|
83
|
130 /// If N is compile unit return NULL otherwise return N.
|
95
|
131 static DIScope *getNonCompileUnitScope(DIScope *N) {
|
|
132 if (!N || isa<DICompileUnit>(N))
|
77
|
133 return nullptr;
|
95
|
134 return cast<DIScope>(N);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
135 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
136
|
95
|
137 DICompileUnit *DIBuilder::createCompileUnit(
|
121
|
138 unsigned Lang, DIFile *File, StringRef Producer, bool isOptimized,
|
|
139 StringRef Flags, unsigned RunTimeVer, StringRef SplitName,
|
120
|
140 DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId,
|
147
|
141 bool SplitDebugInlining, bool DebugInfoForProfiling,
|
|
142 DICompileUnit::DebugNameTableKind NameTableKind, bool RangesBaseAddress) {
|
77
|
143
|
83
|
144 assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) ||
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
145 (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
146 "Invalid Language tag");
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
147
|
95
|
148 assert(!CUNode && "Can only make one compile unit per DIBuilder instance");
|
|
149 CUNode = DICompileUnit::getDistinct(
|
121
|
150 VMContext, Lang, File, Producer, isOptimized, Flags, RunTimeVer,
|
|
151 SplitName, Kind, nullptr, nullptr, nullptr, nullptr, nullptr, DWOId,
|
147
|
152 SplitDebugInlining, DebugInfoForProfiling, NameTableKind,
|
|
153 RangesBaseAddress);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
154
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
155 // Create a named metadata so that it is easier to find cu in a module.
|
120
|
156 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
|
|
157 NMD->addOperand(CUNode);
|
83
|
158 trackIfUnresolved(CUNode);
|
95
|
159 return CUNode;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
160 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
161
|
95
|
162 static DIImportedEntity *
|
|
163 createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context,
|
121
|
164 Metadata *NS, DIFile *File, unsigned Line, StringRef Name,
|
83
|
165 SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) {
|
121
|
166 if (Line)
|
|
167 assert(File && "Source location has line number but no file");
|
120
|
168 unsigned EntitiesCount = C.pImpl->DIImportedEntitys.size();
|
147
|
169 auto *M = DIImportedEntity::get(C, Tag, Context, cast_or_null<DINode>(NS),
|
|
170 File, Line, Name);
|
120
|
171 if (EntitiesCount < C.pImpl->DIImportedEntitys.size())
|
|
172 // A new Imported Entity was just added to the context.
|
|
173 // Add it to the Imported Modules list.
|
|
174 AllImportedModules.emplace_back(M);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
175 return M;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
176 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
177
|
95
|
178 DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context,
|
121
|
179 DINamespace *NS, DIFile *File,
|
95
|
180 unsigned Line) {
|
77
|
181 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
|
121
|
182 Context, NS, File, Line, StringRef(),
|
|
183 AllImportedModules);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
184 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
185
|
95
|
186 DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context,
|
|
187 DIImportedEntity *NS,
|
121
|
188 DIFile *File, unsigned Line) {
|
77
|
189 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
|
121
|
190 Context, NS, File, Line, StringRef(),
|
|
191 AllImportedModules);
|
77
|
192 }
|
|
193
|
95
|
194 DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, DIModule *M,
|
121
|
195 DIFile *File, unsigned Line) {
|
95
|
196 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module,
|
121
|
197 Context, M, File, Line, StringRef(),
|
|
198 AllImportedModules);
|
95
|
199 }
|
|
200
|
|
201 DIImportedEntity *DIBuilder::createImportedDeclaration(DIScope *Context,
|
|
202 DINode *Decl,
|
121
|
203 DIFile *File,
|
95
|
204 unsigned Line,
|
|
205 StringRef Name) {
|
83
|
206 // Make sure to use the unique identifier based metadata reference for
|
|
207 // types that have one.
|
77
|
208 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
|
121
|
209 Context, Decl, File, Line, Name,
|
|
210 AllImportedModules);
|
|
211 }
|
|
212
|
|
213 DIFile *DIBuilder::createFile(StringRef Filename, StringRef Directory,
|
147
|
214 Optional<DIFile::ChecksumInfo<StringRef>> CS,
|
|
215 Optional<StringRef> Source) {
|
|
216 return DIFile::get(VMContext, Filename, Directory, CS, Source);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
217 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
218
|
121
|
219 DIMacro *DIBuilder::createMacro(DIMacroFile *Parent, unsigned LineNumber,
|
|
220 unsigned MacroType, StringRef Name,
|
|
221 StringRef Value) {
|
|
222 assert(!Name.empty() && "Unable to create macro without name");
|
|
223 assert((MacroType == dwarf::DW_MACINFO_undef ||
|
|
224 MacroType == dwarf::DW_MACINFO_define) &&
|
|
225 "Unexpected macro type");
|
|
226 auto *M = DIMacro::get(VMContext, MacroType, LineNumber, Name, Value);
|
|
227 AllMacrosPerParent[Parent].insert(M);
|
|
228 return M;
|
|
229 }
|
|
230
|
|
231 DIMacroFile *DIBuilder::createTempMacroFile(DIMacroFile *Parent,
|
|
232 unsigned LineNumber, DIFile *File) {
|
|
233 auto *MF = DIMacroFile::getTemporary(VMContext, dwarf::DW_MACINFO_start_file,
|
|
234 LineNumber, File, DIMacroNodeArray())
|
|
235 .release();
|
|
236 AllMacrosPerParent[Parent].insert(MF);
|
|
237 // Add the new temporary DIMacroFile to the macro per parent map as a parent.
|
|
238 // This is needed to assure DIMacroFile with no children to have an entry in
|
|
239 // the map. Otherwise, it will not be resolved in DIBuilder::finalize().
|
|
240 AllMacrosPerParent.insert({MF, {}});
|
|
241 return MF;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
242 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
243
|
134
|
244 DIEnumerator *DIBuilder::createEnumerator(StringRef Name, int64_t Val,
|
|
245 bool IsUnsigned) {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
246 assert(!Name.empty() && "Unable to create enumerator without name");
|
134
|
247 return DIEnumerator::get(VMContext, Val, IsUnsigned, Name);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
248 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
249
|
95
|
250 DIBasicType *DIBuilder::createUnspecifiedType(StringRef Name) {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
251 assert(!Name.empty() && "Unable to create type without name");
|
95
|
252 return DIBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
253 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
254
|
95
|
255 DIBasicType *DIBuilder::createNullPtrType() {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
256 return createUnspecifiedType("decltype(nullptr)");
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
257 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
258
|
95
|
259 DIBasicType *DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
|
147
|
260 unsigned Encoding,
|
|
261 DINode::DIFlags Flags) {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
262 assert(!Name.empty() && "Unable to create type without name");
|
95
|
263 return DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits,
|
147
|
264 0, Encoding, Flags);
|
95
|
265 }
|
|
266
|
|
267 DIDerivedType *DIBuilder::createQualifiedType(unsigned Tag, DIType *FromTy) {
|
120
|
268 return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, FromTy, 0,
|
121
|
269 0, 0, None, DINode::FlagZero);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
270 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
271
|
121
|
272 DIDerivedType *DIBuilder::createPointerType(
|
|
273 DIType *PointeeTy,
|
|
274 uint64_t SizeInBits,
|
|
275 uint32_t AlignInBits,
|
|
276 Optional<unsigned> DWARFAddressSpace,
|
|
277 StringRef Name) {
|
95
|
278 // FIXME: Why is there a name here?
|
|
279 return DIDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name,
|
120
|
280 nullptr, 0, nullptr, PointeeTy, SizeInBits,
|
121
|
281 AlignInBits, 0, DWARFAddressSpace,
|
|
282 DINode::FlagZero);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
283 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
284
|
95
|
285 DIDerivedType *DIBuilder::createMemberPointerType(DIType *PointeeTy,
|
|
286 DIType *Base,
|
|
287 uint64_t SizeInBits,
|
120
|
288 uint32_t AlignInBits,
|
|
289 DINode::DIFlags Flags) {
|
95
|
290 return DIDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "",
|
120
|
291 nullptr, 0, nullptr, PointeeTy, SizeInBits,
|
121
|
292 AlignInBits, 0, None, Flags, Base);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
293 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
294
|
121
|
295 DIDerivedType *DIBuilder::createReferenceType(
|
|
296 unsigned Tag, DIType *RTy,
|
|
297 uint64_t SizeInBits,
|
|
298 uint32_t AlignInBits,
|
|
299 Optional<unsigned> DWARFAddressSpace) {
|
95
|
300 assert(RTy && "Unable to create reference type");
|
120
|
301 return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, RTy,
|
121
|
302 SizeInBits, AlignInBits, 0, DWARFAddressSpace,
|
|
303 DINode::FlagZero);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
304 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
305
|
95
|
306 DIDerivedType *DIBuilder::createTypedef(DIType *Ty, StringRef Name,
|
|
307 DIFile *File, unsigned LineNo,
|
|
308 DIScope *Context) {
|
|
309 return DIDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, File,
|
120
|
310 LineNo, getNonCompileUnitScope(Context), Ty, 0, 0,
|
121
|
311 0, None, DINode::FlagZero);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
312 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
313
|
95
|
314 DIDerivedType *DIBuilder::createFriend(DIType *Ty, DIType *FriendTy) {
|
|
315 assert(Ty && "Invalid type!");
|
|
316 assert(FriendTy && "Invalid friend type!");
|
120
|
317 return DIDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0, Ty,
|
121
|
318 FriendTy, 0, 0, 0, None, DINode::FlagZero);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
319 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
320
|
95
|
321 DIDerivedType *DIBuilder::createInheritance(DIType *Ty, DIType *BaseTy,
|
|
322 uint64_t BaseOffset,
|
147
|
323 uint32_t VBPtrOffset,
|
120
|
324 DINode::DIFlags Flags) {
|
95
|
325 assert(Ty && "Unable to create inheritance");
|
147
|
326 Metadata *ExtraData = ConstantAsMetadata::get(
|
|
327 ConstantInt::get(IntegerType::get(VMContext, 32), VBPtrOffset));
|
95
|
328 return DIDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr,
|
147
|
329 0, Ty, BaseTy, 0, 0, BaseOffset, None,
|
|
330 Flags, ExtraData);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
331 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
332
|
95
|
333 DIDerivedType *DIBuilder::createMemberType(DIScope *Scope, StringRef Name,
|
|
334 DIFile *File, unsigned LineNumber,
|
|
335 uint64_t SizeInBits,
|
120
|
336 uint32_t AlignInBits,
|
95
|
337 uint64_t OffsetInBits,
|
120
|
338 DINode::DIFlags Flags, DIType *Ty) {
|
|
339 return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
|
|
340 LineNumber, getNonCompileUnitScope(Scope), Ty,
|
121
|
341 SizeInBits, AlignInBits, OffsetInBits, None, Flags);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
342 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
343
|
95
|
344 static ConstantAsMetadata *getConstantOrNull(Constant *C) {
|
83
|
345 if (C)
|
|
346 return ConstantAsMetadata::get(C);
|
|
347 return nullptr;
|
|
348 }
|
|
349
|
147
|
350 DIDerivedType *DIBuilder::createVariantMemberType(
|
|
351 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
|
|
352 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
|
|
353 Constant *Discriminant, DINode::DIFlags Flags, DIType *Ty) {
|
134
|
354 return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
|
|
355 LineNumber, getNonCompileUnitScope(Scope), Ty,
|
|
356 SizeInBits, AlignInBits, OffsetInBits, None, Flags,
|
|
357 getConstantOrNull(Discriminant));
|
|
358 }
|
|
359
|
120
|
360 DIDerivedType *DIBuilder::createBitFieldMemberType(
|
|
361 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
|
|
362 uint64_t SizeInBits, uint64_t OffsetInBits, uint64_t StorageOffsetInBits,
|
|
363 DINode::DIFlags Flags, DIType *Ty) {
|
|
364 Flags |= DINode::FlagBitField;
|
95
|
365 return DIDerivedType::get(
|
|
366 VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
|
120
|
367 getNonCompileUnitScope(Scope), Ty, SizeInBits, /* AlignInBits */ 0,
|
121
|
368 OffsetInBits, None, Flags,
|
120
|
369 ConstantAsMetadata::get(ConstantInt::get(IntegerType::get(VMContext, 64),
|
|
370 StorageOffsetInBits)));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
371 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
372
|
120
|
373 DIDerivedType *
|
|
374 DIBuilder::createStaticMemberType(DIScope *Scope, StringRef Name, DIFile *File,
|
|
375 unsigned LineNumber, DIType *Ty,
|
|
376 DINode::DIFlags Flags, llvm::Constant *Val,
|
|
377 uint32_t AlignInBits) {
|
|
378 Flags |= DINode::FlagStaticMember;
|
|
379 return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
|
|
380 LineNumber, getNonCompileUnitScope(Scope), Ty, 0,
|
121
|
381 AlignInBits, 0, None, Flags,
|
|
382 getConstantOrNull(Val));
|
120
|
383 }
|
|
384
|
|
385 DIDerivedType *
|
|
386 DIBuilder::createObjCIVar(StringRef Name, DIFile *File, unsigned LineNumber,
|
|
387 uint64_t SizeInBits, uint32_t AlignInBits,
|
|
388 uint64_t OffsetInBits, DINode::DIFlags Flags,
|
|
389 DIType *Ty, MDNode *PropertyNode) {
|
|
390 return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
|
|
391 LineNumber, getNonCompileUnitScope(File), Ty,
|
121
|
392 SizeInBits, AlignInBits, OffsetInBits, None, Flags,
|
120
|
393 PropertyNode);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
394 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
395
|
95
|
396 DIObjCProperty *
|
|
397 DIBuilder::createObjCProperty(StringRef Name, DIFile *File, unsigned LineNumber,
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
398 StringRef GetterName, StringRef SetterName,
|
95
|
399 unsigned PropertyAttributes, DIType *Ty) {
|
|
400 return DIObjCProperty::get(VMContext, Name, File, LineNumber, GetterName,
|
120
|
401 SetterName, PropertyAttributes, Ty);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
402 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
403
|
95
|
404 DITemplateTypeParameter *
|
|
405 DIBuilder::createTemplateTypeParameter(DIScope *Context, StringRef Name,
|
|
406 DIType *Ty) {
|
|
407 assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
|
120
|
408 return DITemplateTypeParameter::get(VMContext, Name, Ty);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
409 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
410
|
95
|
411 static DITemplateValueParameter *
|
83
|
412 createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag,
|
95
|
413 DIScope *Context, StringRef Name, DIType *Ty,
|
|
414 Metadata *MD) {
|
|
415 assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
|
120
|
416 return DITemplateValueParameter::get(VMContext, Tag, Name, Ty, MD);
|
83
|
417 }
|
|
418
|
95
|
419 DITemplateValueParameter *
|
|
420 DIBuilder::createTemplateValueParameter(DIScope *Context, StringRef Name,
|
|
421 DIType *Ty, Constant *Val) {
|
83
|
422 return createTemplateValueParameterHelper(
|
|
423 VMContext, dwarf::DW_TAG_template_value_parameter, Context, Name, Ty,
|
|
424 getConstantOrNull(Val));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
425 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
426
|
95
|
427 DITemplateValueParameter *
|
|
428 DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name,
|
|
429 DIType *Ty, StringRef Val) {
|
83
|
430 return createTemplateValueParameterHelper(
|
|
431 VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
|
|
432 MDString::get(VMContext, Val));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
433 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
434
|
95
|
435 DITemplateValueParameter *
|
|
436 DIBuilder::createTemplateParameterPack(DIScope *Context, StringRef Name,
|
|
437 DIType *Ty, DINodeArray Val) {
|
83
|
438 return createTemplateValueParameterHelper(
|
|
439 VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty,
|
95
|
440 Val.get());
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
441 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
442
|
95
|
443 DICompositeType *DIBuilder::createClassType(
|
|
444 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
|
120
|
445 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
|
|
446 DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements,
|
95
|
447 DIType *VTableHolder, MDNode *TemplateParams, StringRef UniqueIdentifier) {
|
|
448 assert((!Context || isa<DIScope>(Context)) &&
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
449 "createClassType should be called with a valid Context");
|
95
|
450
|
|
451 auto *R = DICompositeType::get(
|
|
452 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
|
120
|
453 getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits,
|
|
454 OffsetInBits, Flags, Elements, 0, VTableHolder,
|
95
|
455 cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier);
|
83
|
456 trackIfUnresolved(R);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
457 return R;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
458 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
459
|
95
|
460 DICompositeType *DIBuilder::createStructType(
|
|
461 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
|
120
|
462 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
|
95
|
463 DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang,
|
|
464 DIType *VTableHolder, StringRef UniqueIdentifier) {
|
|
465 auto *R = DICompositeType::get(
|
|
466 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
|
120
|
467 getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0,
|
|
468 Flags, Elements, RunTimeLang, VTableHolder, nullptr, UniqueIdentifier);
|
83
|
469 trackIfUnresolved(R);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
470 return R;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
471 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
472
|
95
|
473 DICompositeType *DIBuilder::createUnionType(
|
|
474 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
|
120
|
475 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
|
95
|
476 DINodeArray Elements, unsigned RunTimeLang, StringRef UniqueIdentifier) {
|
|
477 auto *R = DICompositeType::get(
|
|
478 VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber,
|
120
|
479 getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
|
|
480 Elements, RunTimeLang, nullptr, nullptr, UniqueIdentifier);
|
83
|
481 trackIfUnresolved(R);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
482 return R;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
483 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
484
|
134
|
485 DICompositeType *DIBuilder::createVariantPart(
|
|
486 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
|
|
487 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
|
|
488 DIDerivedType *Discriminator, DINodeArray Elements, StringRef UniqueIdentifier) {
|
|
489 auto *R = DICompositeType::get(
|
|
490 VMContext, dwarf::DW_TAG_variant_part, Name, File, LineNumber,
|
|
491 getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
|
|
492 Elements, 0, nullptr, nullptr, UniqueIdentifier, Discriminator);
|
|
493 trackIfUnresolved(R);
|
|
494 return R;
|
|
495 }
|
|
496
|
100
|
497 DISubroutineType *DIBuilder::createSubroutineType(DITypeRefArray ParameterTypes,
|
120
|
498 DINode::DIFlags Flags,
|
|
499 unsigned CC) {
|
|
500 return DISubroutineType::get(VMContext, Flags, CC, ParameterTypes);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
501 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
502
|
95
|
503 DICompositeType *DIBuilder::createEnumerationType(
|
|
504 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
|
120
|
505 uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements,
|
147
|
506 DIType *UnderlyingType, StringRef UniqueIdentifier, bool IsScoped) {
|
95
|
507 auto *CTy = DICompositeType::get(
|
|
508 VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber,
|
120
|
509 getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0,
|
147
|
510 IsScoped ? DINode::FlagEnumClass : DINode::FlagZero, Elements, 0, nullptr,
|
134
|
511 nullptr, UniqueIdentifier);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
512 AllEnumTypes.push_back(CTy);
|
83
|
513 trackIfUnresolved(CTy);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
514 return CTy;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
515 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
516
|
120
|
517 DICompositeType *DIBuilder::createArrayType(uint64_t Size,
|
|
518 uint32_t AlignInBits, DIType *Ty,
|
95
|
519 DINodeArray Subscripts) {
|
|
520 auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
|
120
|
521 nullptr, 0, nullptr, Ty, Size, AlignInBits, 0,
|
|
522 DINode::FlagZero, Subscripts, 0, nullptr);
|
83
|
523 trackIfUnresolved(R);
|
|
524 return R;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
525 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
526
|
95
|
527 DICompositeType *DIBuilder::createVectorType(uint64_t Size,
|
120
|
528 uint32_t AlignInBits, DIType *Ty,
|
95
|
529 DINodeArray Subscripts) {
|
120
|
530 auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
|
|
531 nullptr, 0, nullptr, Ty, Size, AlignInBits, 0,
|
|
532 DINode::FlagVector, Subscripts, 0, nullptr);
|
83
|
533 trackIfUnresolved(R);
|
|
534 return R;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
535 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
536
|
147
|
537 DISubprogram *DIBuilder::createArtificialSubprogram(DISubprogram *SP) {
|
|
538 auto NewSP = SP->cloneWithFlags(SP->getFlags() | DINode::FlagArtificial);
|
|
539 return MDNode::replaceWithDistinct(std::move(NewSP));
|
|
540 }
|
|
541
|
|
542 static DIType *createTypeWithFlags(const DIType *Ty,
|
120
|
543 DINode::DIFlags FlagsToSet) {
|
147
|
544 auto NewTy = Ty->cloneWithFlags(Ty->getFlags() | FlagsToSet);
|
95
|
545 return MDNode::replaceWithUniqued(std::move(NewTy));
|
83
|
546 }
|
|
547
|
95
|
548 DIType *DIBuilder::createArtificialType(DIType *Ty) {
|
|
549 // FIXME: Restrict this to the nodes where it's valid.
|
|
550 if (Ty->isArtificial())
|
|
551 return Ty;
|
147
|
552 return createTypeWithFlags(Ty, DINode::FlagArtificial);
|
83
|
553 }
|
|
554
|
95
|
555 DIType *DIBuilder::createObjectPointerType(DIType *Ty) {
|
|
556 // FIXME: Restrict this to the nodes where it's valid.
|
|
557 if (Ty->isObjectPointer())
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
558 return Ty;
|
120
|
559 DINode::DIFlags Flags = DINode::FlagObjectPointer | DINode::FlagArtificial;
|
147
|
560 return createTypeWithFlags(Ty, Flags);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
561 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
562
|
120
|
563 void DIBuilder::retainType(DIScope *T) {
|
95
|
564 assert(T && "Expected non-null type");
|
120
|
565 assert((isa<DIType>(T) || (isa<DISubprogram>(T) &&
|
|
566 cast<DISubprogram>(T)->isDefinition() == false)) &&
|
|
567 "Expected type or subprogram declaration");
|
95
|
568 AllRetainTypes.emplace_back(T);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
569 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
570
|
95
|
571 DIBasicType *DIBuilder::createUnspecifiedParameter() { return nullptr; }
|
|
572
|
|
573 DICompositeType *
|
|
574 DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIScope *Scope,
|
|
575 DIFile *F, unsigned Line, unsigned RuntimeLang,
|
120
|
576 uint64_t SizeInBits, uint32_t AlignInBits,
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
577 StringRef UniqueIdentifier) {
|
95
|
578 // FIXME: Define in terms of createReplaceableForwardDecl() by calling
|
|
579 // replaceWithUniqued().
|
|
580 auto *RetTy = DICompositeType::get(
|
120
|
581 VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
|
|
582 SizeInBits, AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang,
|
|
583 nullptr, nullptr, UniqueIdentifier);
|
95
|
584 trackIfUnresolved(RetTy);
|
|
585 return RetTy;
|
|
586 }
|
|
587
|
|
588 DICompositeType *DIBuilder::createReplaceableCompositeType(
|
|
589 unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
|
120
|
590 unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
|
|
591 DINode::DIFlags Flags, StringRef UniqueIdentifier) {
|
|
592 auto *RetTy =
|
|
593 DICompositeType::getTemporary(
|
|
594 VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
|
|
595 SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, nullptr,
|
|
596 nullptr, UniqueIdentifier)
|
|
597 .release();
|
83
|
598 trackIfUnresolved(RetTy);
|
77
|
599 return RetTy;
|
|
600 }
|
|
601
|
95
|
602 DINodeArray DIBuilder::getOrCreateArray(ArrayRef<Metadata *> Elements) {
|
|
603 return MDTuple::get(VMContext, Elements);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
604 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
605
|
121
|
606 DIMacroNodeArray
|
|
607 DIBuilder::getOrCreateMacroArray(ArrayRef<Metadata *> Elements) {
|
|
608 return MDTuple::get(VMContext, Elements);
|
|
609 }
|
|
610
|
95
|
611 DITypeRefArray DIBuilder::getOrCreateTypeArray(ArrayRef<Metadata *> Elements) {
|
83
|
612 SmallVector<llvm::Metadata *, 16> Elts;
|
77
|
613 for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
|
|
614 if (Elements[i] && isa<MDNode>(Elements[i]))
|
120
|
615 Elts.push_back(cast<DIType>(Elements[i]));
|
77
|
616 else
|
|
617 Elts.push_back(Elements[i]);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
618 }
|
95
|
619 return DITypeRefArray(MDNode::get(VMContext, Elts));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
620 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
621
|
95
|
622 DISubrange *DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
|
|
623 return DISubrange::get(VMContext, Count, Lo);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
624 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
625
|
134
|
626 DISubrange *DIBuilder::getOrCreateSubrange(int64_t Lo, Metadata *CountNode) {
|
|
627 return DISubrange::get(VMContext, CountNode, Lo);
|
|
628 }
|
|
629
|
95
|
630 static void checkGlobalVariableScope(DIScope *Context) {
|
|
631 #ifndef NDEBUG
|
|
632 if (auto *CT =
|
|
633 dyn_cast_or_null<DICompositeType>(getNonCompileUnitScope(Context)))
|
|
634 assert(CT->getIdentifier().empty() &&
|
83
|
635 "Context of a global variable should not be a type with identifier");
|
95
|
636 #endif
|
|
637 }
|
83
|
638
|
121
|
639 DIGlobalVariableExpression *DIBuilder::createGlobalVariableExpression(
|
95
|
640 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
|
121
|
641 unsigned LineNumber, DIType *Ty, bool isLocalToUnit, DIExpression *Expr,
|
147
|
642 MDNode *Decl, MDTuple *templateParams, uint32_t AlignInBits) {
|
95
|
643 checkGlobalVariableScope(Context);
|
83
|
644
|
121
|
645 auto *GV = DIGlobalVariable::getDistinct(
|
120
|
646 VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
|
121
|
647 LineNumber, Ty, isLocalToUnit, true, cast_or_null<DIDerivedType>(Decl),
|
147
|
648 templateParams, AlignInBits);
|
121
|
649 if (!Expr)
|
|
650 Expr = createExpression();
|
|
651 auto *N = DIGlobalVariableExpression::get(VMContext, GV, Expr);
|
95
|
652 AllGVs.push_back(N);
|
|
653 return N;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
654 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
655
|
95
|
656 DIGlobalVariable *DIBuilder::createTempGlobalVariableFwdDecl(
|
|
657 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
|
121
|
658 unsigned LineNumber, DIType *Ty, bool isLocalToUnit, MDNode *Decl,
|
147
|
659 MDTuple *templateParams, uint32_t AlignInBits) {
|
95
|
660 checkGlobalVariableScope(Context);
|
|
661
|
|
662 return DIGlobalVariable::getTemporary(
|
|
663 VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
|
121
|
664 LineNumber, Ty, isLocalToUnit, false,
|
147
|
665 cast_or_null<DIDerivedType>(Decl), templateParams, AlignInBits)
|
95
|
666 .release();
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
667 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
668
|
95
|
669 static DILocalVariable *createLocalVariable(
|
|
670 LLVMContext &VMContext,
|
120
|
671 DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> &PreservedVariables,
|
95
|
672 DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
|
120
|
673 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
|
|
674 uint32_t AlignInBits) {
|
95
|
675 // FIXME: Why getNonCompileUnitScope()?
|
|
676 // FIXME: Why is "!Context" okay here?
|
|
677 // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT
|
|
678 // the only valid scopes)?
|
|
679 DIScope *Context = getNonCompileUnitScope(Scope);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
680
|
95
|
681 auto *Node =
|
|
682 DILocalVariable::get(VMContext, cast_or_null<DILocalScope>(Context), Name,
|
120
|
683 File, LineNo, Ty, ArgNo, Flags, AlignInBits);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
684 if (AlwaysPreserve) {
|
95
|
685 // The optimizer may remove local variables. If there is an interest
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
686 // to preserve variable info in such situation then stash it in a
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
687 // named mdnode.
|
95
|
688 DISubprogram *Fn = getDISubprogram(Scope);
|
83
|
689 assert(Fn && "Missing subprogram for local variable");
|
|
690 PreservedVariables[Fn].emplace_back(Node);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
691 }
|
95
|
692 return Node;
|
|
693 }
|
|
694
|
|
695 DILocalVariable *DIBuilder::createAutoVariable(DIScope *Scope, StringRef Name,
|
|
696 DIFile *File, unsigned LineNo,
|
|
697 DIType *Ty, bool AlwaysPreserve,
|
120
|
698 DINode::DIFlags Flags,
|
|
699 uint32_t AlignInBits) {
|
95
|
700 return createLocalVariable(VMContext, PreservedVariables, Scope, Name,
|
|
701 /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve,
|
120
|
702 Flags, AlignInBits);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
703 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
704
|
95
|
705 DILocalVariable *DIBuilder::createParameterVariable(
|
|
706 DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
|
120
|
707 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags) {
|
95
|
708 assert(ArgNo && "Expected non-zero argument number for parameter");
|
|
709 return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo,
|
120
|
710 File, LineNo, Ty, AlwaysPreserve, Flags,
|
|
711 /* AlignInBits */0);
|
77
|
712 }
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
713
|
147
|
714 DILabel *DIBuilder::createLabel(
|
|
715 DIScope *Scope, StringRef Name, DIFile *File,
|
|
716 unsigned LineNo, bool AlwaysPreserve) {
|
|
717 DIScope *Context = getNonCompileUnitScope(Scope);
|
|
718
|
|
719 auto *Node =
|
|
720 DILabel::get(VMContext, cast_or_null<DILocalScope>(Context), Name,
|
|
721 File, LineNo);
|
|
722
|
|
723 if (AlwaysPreserve) {
|
|
724 /// The optimizer may remove labels. If there is an interest
|
|
725 /// to preserve label info in such situation then append it to
|
|
726 /// the list of retained nodes of the DISubprogram.
|
|
727 DISubprogram *Fn = getDISubprogram(Scope);
|
|
728 assert(Fn && "Missing subprogram for label");
|
|
729 PreservedLabels[Fn].emplace_back(Node);
|
|
730 }
|
|
731 return Node;
|
|
732 }
|
|
733
|
95
|
734 DIExpression *DIBuilder::createExpression(ArrayRef<uint64_t> Addr) {
|
|
735 return DIExpression::get(VMContext, Addr);
|
|
736 }
|
|
737
|
|
738 DIExpression *DIBuilder::createExpression(ArrayRef<int64_t> Signed) {
|
83
|
739 // TODO: Remove the callers of this signed version and delete.
|
|
740 SmallVector<uint64_t, 8> Addr(Signed.begin(), Signed.end());
|
|
741 return createExpression(Addr);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
742 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
743
|
95
|
744 template <class... Ts>
|
|
745 static DISubprogram *getSubprogram(bool IsDistinct, Ts &&... Args) {
|
|
746 if (IsDistinct)
|
|
747 return DISubprogram::getDistinct(std::forward<Ts>(Args)...);
|
|
748 return DISubprogram::get(std::forward<Ts>(Args)...);
|
83
|
749 }
|
|
750
|
100
|
751 DISubprogram *DIBuilder::createFunction(
|
|
752 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
|
147
|
753 unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine,
|
|
754 DINode::DIFlags Flags, DISubprogram::DISPFlags SPFlags,
|
|
755 DITemplateParameterArray TParams, DISubprogram *Decl,
|
121
|
756 DITypeArray ThrownTypes) {
|
147
|
757 bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
|
120
|
758 auto *Node = getSubprogram(
|
147
|
759 /*IsDistinct=*/IsDefinition, VMContext, getNonCompileUnitScope(Context),
|
|
760 Name, LinkageName, File, LineNo, Ty, ScopeLine, nullptr, 0, 0, Flags,
|
|
761 SPFlags, IsDefinition ? CUNode : nullptr, TParams, Decl,
|
121
|
762 MDTuple::getTemporary(VMContext, None).release(), ThrownTypes);
|
83
|
763
|
147
|
764 if (IsDefinition)
|
95
|
765 AllSubprograms.push_back(Node);
|
|
766 trackIfUnresolved(Node);
|
|
767 return Node;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
768 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
769
|
95
|
770 DISubprogram *DIBuilder::createTempFunctionFwdDecl(
|
|
771 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
|
147
|
772 unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine,
|
|
773 DINode::DIFlags Flags, DISubprogram::DISPFlags SPFlags,
|
|
774 DITemplateParameterArray TParams, DISubprogram *Decl,
|
121
|
775 DITypeArray ThrownTypes) {
|
147
|
776 bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
|
|
777 return DISubprogram::getTemporary(VMContext, getNonCompileUnitScope(Context),
|
|
778 Name, LinkageName, File, LineNo, Ty,
|
|
779 ScopeLine, nullptr, 0, 0, Flags, SPFlags,
|
|
780 IsDefinition ? CUNode : nullptr, TParams,
|
|
781 Decl, nullptr, ThrownTypes)
|
95
|
782 .release();
|
83
|
783 }
|
|
784
|
121
|
785 DISubprogram *DIBuilder::createMethod(
|
|
786 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
|
147
|
787 unsigned LineNo, DISubroutineType *Ty, unsigned VIndex, int ThisAdjustment,
|
|
788 DIType *VTableHolder, DINode::DIFlags Flags,
|
|
789 DISubprogram::DISPFlags SPFlags, DITemplateParameterArray TParams,
|
|
790 DITypeArray ThrownTypes) {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
791 assert(getNonCompileUnitScope(Context) &&
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
792 "Methods should have both a Context and a context that isn't "
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
793 "the compile unit.");
|
95
|
794 // FIXME: Do we want to use different scope/lines?
|
147
|
795 bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
|
100
|
796 auto *SP = getSubprogram(
|
147
|
797 /*IsDistinct=*/IsDefinition, VMContext, cast<DIScope>(Context), Name,
|
|
798 LinkageName, F, LineNo, Ty, LineNo, VTableHolder, VIndex, ThisAdjustment,
|
|
799 Flags, SPFlags, IsDefinition ? CUNode : nullptr, TParams, nullptr,
|
|
800 nullptr, ThrownTypes);
|
95
|
801
|
147
|
802 if (IsDefinition)
|
95
|
803 AllSubprograms.push_back(SP);
|
|
804 trackIfUnresolved(SP);
|
|
805 return SP;
|
|
806 }
|
|
807
|
147
|
808 DICommonBlock *DIBuilder::createCommonBlock(
|
|
809 DIScope *Scope, DIGlobalVariable *Decl, StringRef Name, DIFile *File,
|
|
810 unsigned LineNo) {
|
|
811 return DICommonBlock::get(
|
|
812 VMContext, Scope, Decl, Name, File, LineNo);
|
|
813 }
|
|
814
|
95
|
815 DINamespace *DIBuilder::createNameSpace(DIScope *Scope, StringRef Name,
|
120
|
816 bool ExportSymbols) {
|
121
|
817
|
|
818 // It is okay to *not* make anonymous top-level namespaces distinct, because
|
|
819 // all nodes that have an anonymous namespace as their parent scope are
|
|
820 // guaranteed to be unique and/or are linked to their containing
|
|
821 // DICompileUnit. This decision is an explicit tradeoff of link time versus
|
|
822 // memory usage versus code simplicity and may get revisited in the future.
|
|
823 return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), Name,
|
|
824 ExportSymbols);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
825 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
826
|
95
|
827 DIModule *DIBuilder::createModule(DIScope *Scope, StringRef Name,
|
|
828 StringRef ConfigurationMacros,
|
|
829 StringRef IncludePath,
|
|
830 StringRef ISysRoot) {
|
|
831 return DIModule::get(VMContext, getNonCompileUnitScope(Scope), Name,
|
|
832 ConfigurationMacros, IncludePath, ISysRoot);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
833 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
834
|
95
|
835 DILexicalBlockFile *DIBuilder::createLexicalBlockFile(DIScope *Scope,
|
|
836 DIFile *File,
|
|
837 unsigned Discriminator) {
|
|
838 return DILexicalBlockFile::get(VMContext, Scope, File, Discriminator);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
839 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
840
|
95
|
841 DILexicalBlock *DIBuilder::createLexicalBlock(DIScope *Scope, DIFile *File,
|
|
842 unsigned Line, unsigned Col) {
|
|
843 // Make these distinct, to avoid merging two lexical blocks on the same
|
|
844 // file/line/column.
|
|
845 return DILexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope),
|
|
846 File, Line, Col);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
847 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
848
|
121
|
849 Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
|
|
850 DIExpression *Expr, const DILocation *DL,
|
|
851 Instruction *InsertBefore) {
|
|
852 return insertDeclare(Storage, VarInfo, Expr, DL, InsertBefore->getParent(),
|
|
853 InsertBefore);
|
|
854 }
|
|
855
|
|
856 Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
|
|
857 DIExpression *Expr, const DILocation *DL,
|
|
858 BasicBlock *InsertAtEnd) {
|
|
859 // If this block already has a terminator then insert this intrinsic before
|
|
860 // the terminator. Otherwise, put it at the end of the block.
|
|
861 Instruction *InsertBefore = InsertAtEnd->getTerminator();
|
|
862 return insertDeclare(Storage, VarInfo, Expr, DL, InsertAtEnd, InsertBefore);
|
|
863 }
|
|
864
|
147
|
865 Instruction *DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
|
|
866 Instruction *InsertBefore) {
|
|
867 return insertLabel(
|
|
868 LabelInfo, DL, InsertBefore ? InsertBefore->getParent() : nullptr,
|
|
869 InsertBefore);
|
|
870 }
|
|
871
|
|
872 Instruction *DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
|
|
873 BasicBlock *InsertAtEnd) {
|
|
874 return insertLabel(LabelInfo, DL, InsertAtEnd, nullptr);
|
|
875 }
|
|
876
|
121
|
877 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V,
|
|
878 DILocalVariable *VarInfo,
|
|
879 DIExpression *Expr,
|
|
880 const DILocation *DL,
|
|
881 Instruction *InsertBefore) {
|
|
882 return insertDbgValueIntrinsic(
|
|
883 V, VarInfo, Expr, DL, InsertBefore ? InsertBefore->getParent() : nullptr,
|
|
884 InsertBefore);
|
|
885 }
|
|
886
|
|
887 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V,
|
|
888 DILocalVariable *VarInfo,
|
|
889 DIExpression *Expr,
|
|
890 const DILocation *DL,
|
|
891 BasicBlock *InsertAtEnd) {
|
|
892 return insertDbgValueIntrinsic(V, VarInfo, Expr, DL, InsertAtEnd, nullptr);
|
|
893 }
|
|
894
|
|
895 /// Return an IRBuilder for inserting dbg.declare and dbg.value intrinsics. This
|
|
896 /// abstracts over the various ways to specify an insert position.
|
|
897 static IRBuilder<> getIRBForDbgInsertion(const DILocation *DL,
|
|
898 BasicBlock *InsertBB,
|
|
899 Instruction *InsertBefore) {
|
|
900 IRBuilder<> B(DL->getContext());
|
|
901 if (InsertBefore)
|
|
902 B.SetInsertPoint(InsertBefore);
|
|
903 else if (InsertBB)
|
|
904 B.SetInsertPoint(InsertBB);
|
|
905 B.SetCurrentDebugLocation(DL);
|
|
906 return B;
|
|
907 }
|
|
908
|
83
|
909 static Value *getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V) {
|
|
910 assert(V && "no value passed to dbg intrinsic");
|
|
911 return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V));
|
|
912 }
|
|
913
|
121
|
914 static Function *getDeclareIntrin(Module &M) {
|
|
915 return Intrinsic::getDeclaration(&M, UseDbgAddr ? Intrinsic::dbg_addr
|
|
916 : Intrinsic::dbg_declare);
|
95
|
917 }
|
|
918
|
|
919 Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
|
|
920 DIExpression *Expr, const DILocation *DL,
|
121
|
921 BasicBlock *InsertBB, Instruction *InsertBefore) {
|
95
|
922 assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare");
|
|
923 assert(DL && "Expected debug loc");
|
|
924 assert(DL->getScope()->getSubprogram() ==
|
|
925 VarInfo->getScope()->getSubprogram() &&
|
|
926 "Expected matching subprograms");
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
927 if (!DeclareFn)
|
121
|
928 DeclareFn = getDeclareIntrin(M);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
929
|
83
|
930 trackIfUnresolved(VarInfo);
|
|
931 trackIfUnresolved(Expr);
|
|
932 Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage),
|
|
933 MetadataAsValue::get(VMContext, VarInfo),
|
|
934 MetadataAsValue::get(VMContext, Expr)};
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
935
|
121
|
936 IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore);
|
|
937 return B.CreateCall(DeclareFn, Args);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
938 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
939
|
121
|
940 Instruction *DIBuilder::insertDbgValueIntrinsic(
|
|
941 Value *V, DILocalVariable *VarInfo, DIExpression *Expr,
|
|
942 const DILocation *DL, BasicBlock *InsertBB, Instruction *InsertBefore) {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
943 assert(V && "no value passed to dbg.value");
|
95
|
944 assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.value");
|
|
945 assert(DL && "Expected debug loc");
|
|
946 assert(DL->getScope()->getSubprogram() ==
|
|
947 VarInfo->getScope()->getSubprogram() &&
|
|
948 "Expected matching subprograms");
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
949 if (!ValueFn)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
950 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
951
|
83
|
952 trackIfUnresolved(VarInfo);
|
|
953 trackIfUnresolved(Expr);
|
|
954 Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V),
|
|
955 MetadataAsValue::get(VMContext, VarInfo),
|
|
956 MetadataAsValue::get(VMContext, Expr)};
|
95
|
957
|
121
|
958 IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore);
|
|
959 return B.CreateCall(ValueFn, Args);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
960 }
|
83
|
961
|
147
|
962 Instruction *DIBuilder::insertLabel(
|
|
963 DILabel *LabelInfo, const DILocation *DL,
|
|
964 BasicBlock *InsertBB, Instruction *InsertBefore) {
|
|
965 assert(LabelInfo && "empty or invalid DILabel* passed to dbg.label");
|
|
966 assert(DL && "Expected debug loc");
|
|
967 assert(DL->getScope()->getSubprogram() ==
|
|
968 LabelInfo->getScope()->getSubprogram() &&
|
|
969 "Expected matching subprograms");
|
|
970 if (!LabelFn)
|
|
971 LabelFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_label);
|
|
972
|
|
973 trackIfUnresolved(LabelInfo);
|
|
974 Value *Args[] = {MetadataAsValue::get(VMContext, LabelInfo)};
|
|
975
|
|
976 IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore);
|
|
977 return B.CreateCall(LabelFn, Args);
|
|
978 }
|
|
979
|
95
|
980 void DIBuilder::replaceVTableHolder(DICompositeType *&T,
|
134
|
981 DIType *VTableHolder) {
|
95
|
982 {
|
|
983 TypedTrackingMDRef<DICompositeType> N(T);
|
120
|
984 N->replaceVTableHolder(VTableHolder);
|
95
|
985 T = N.get();
|
|
986 }
|
83
|
987
|
|
988 // If this didn't create a self-reference, just return.
|
|
989 if (T != VTableHolder)
|
|
990 return;
|
|
991
|
|
992 // Look for unresolved operands. T will drop RAUW support, orphaning any
|
|
993 // cycles underneath it.
|
|
994 if (T->isResolved())
|
|
995 for (const MDOperand &O : T->operands())
|
|
996 if (auto *N = dyn_cast_or_null<MDNode>(O))
|
|
997 trackIfUnresolved(N);
|
|
998 }
|
|
999
|
95
|
1000 void DIBuilder::replaceArrays(DICompositeType *&T, DINodeArray Elements,
|
|
1001 DINodeArray TParams) {
|
|
1002 {
|
|
1003 TypedTrackingMDRef<DICompositeType> N(T);
|
|
1004 if (Elements)
|
|
1005 N->replaceElements(Elements);
|
|
1006 if (TParams)
|
|
1007 N->replaceTemplateParams(DITemplateParameterArray(TParams));
|
|
1008 T = N.get();
|
|
1009 }
|
83
|
1010
|
|
1011 // If T isn't resolved, there's no problem.
|
|
1012 if (!T->isResolved())
|
|
1013 return;
|
|
1014
|
95
|
1015 // If T is resolved, it may be due to a self-reference cycle. Track the
|
83
|
1016 // arrays explicitly if they're unresolved, or else the cycles will be
|
|
1017 // orphaned.
|
|
1018 if (Elements)
|
95
|
1019 trackIfUnresolved(Elements.get());
|
83
|
1020 if (TParams)
|
95
|
1021 trackIfUnresolved(TParams.get());
|
83
|
1022 }
|