@@ -88,6 +88,7 @@ bool SPIRVEmitNonSemanticDI::emitGlobalDI(MachineFunction &MF) {
88
88
int64_t DwarfVersion = 0 ;
89
89
int64_t DebugInfoVersion = 0 ;
90
90
SmallPtrSet<DIBasicType *, 12 > BasicTypes;
91
+ SmallPtrSet<DIDerivedType *, 12 > PointerDerivedTypes;
91
92
// Searching through the Module metadata to find nescessary
92
93
// information like DwarfVersion or SourceLanguage
93
94
{
@@ -129,8 +130,22 @@ bool SPIRVEmitNonSemanticDI::emitGlobalDI(MachineFunction &MF) {
129
130
for (DbgVariableRecord &DVR : filterDbgVars (I.getDbgRecordRange ())) {
130
131
DILocalVariable *LocalVariable = DVR.getVariable ();
131
132
if (auto *BasicType =
132
- dyn_cast<DIBasicType>(LocalVariable->getType ()))
133
+ dyn_cast<DIBasicType>(LocalVariable->getType ())) {
133
134
BasicTypes.insert (BasicType);
135
+ } else if (auto *DerivedType =
136
+ dyn_cast<DIDerivedType>(LocalVariable->getType ())) {
137
+ if (DerivedType->getTag () == dwarf::DW_TAG_pointer_type) {
138
+ PointerDerivedTypes.insert (DerivedType);
139
+ // DIBasicType can be unreachable from DbgRecord and only
140
+ // pointed on from other DI types
141
+ // DerivedType->getBaseType is null when pointer
142
+ // is representing a void type
143
+ if (DerivedType->getBaseType ()) {
144
+ BasicTypes.insert (
145
+ cast<DIBasicType>(DerivedType->getBaseType ()));
146
+ }
147
+ }
148
+ }
134
149
}
135
150
}
136
151
}
@@ -160,7 +175,6 @@ bool SPIRVEmitNonSemanticDI::emitGlobalDI(MachineFunction &MF) {
160
175
return StrReg;
161
176
};
162
177
163
- // Emit OpString with FilePath which is required by DebugSource
164
178
const Register FilePathStrReg = EmitOpString (FilePath);
165
179
166
180
const SPIRVType *VoidTy =
@@ -187,15 +201,12 @@ bool SPIRVEmitNonSemanticDI::emitGlobalDI(MachineFunction &MF) {
187
201
return InstReg;
188
202
};
189
203
190
- // Emit DebugSource which is required by DebugCompilationUnit
191
204
const Register DebugSourceResIdReg = EmitDIInstruction (
192
205
SPIRV::NonSemanticExtInst::DebugSource, {FilePathStrReg});
193
206
194
207
const SPIRVType *I32Ty =
195
208
GR->getOrCreateSPIRVType (Type::getInt32Ty (*Context), MIRBuilder);
196
209
197
- // Convert DwarfVersion, DebugInfo and SourceLanguage integers to OpConstant
198
- // instructions required by DebugCompilationUnit
199
210
const Register DwarfVersionReg =
200
211
GR->buildConstantInt (DwarfVersion, MIRBuilder, I32Ty, false );
201
212
const Register DebugInfoVersionReg =
@@ -214,6 +225,11 @@ bool SPIRVEmitNonSemanticDI::emitGlobalDI(MachineFunction &MF) {
214
225
const Register I32ZeroReg =
215
226
GR->buildConstantInt (0 , MIRBuilder, I32Ty, false );
216
227
228
+ // We need to store pairs because further instructions reference
229
+ // the DIBasicTypes and size will be always small so there isn't
230
+ // need for any kind of map
231
+ SmallVector<std::pair<const DIBasicType *const , const Register>, 12 >
232
+ BasicTypeRegPairs;
217
233
for (auto *BasicType : BasicTypes) {
218
234
const Register BasicTypeStrReg = EmitOpString (BasicType->getName ());
219
235
@@ -247,11 +263,31 @@ bool SPIRVEmitNonSemanticDI::emitGlobalDI(MachineFunction &MF) {
247
263
const Register AttributeEncodingReg =
248
264
GR->buildConstantInt (AttributeEncoding, MIRBuilder, I32Ty, false );
249
265
250
- [[maybe_unused]]
251
266
const Register BasicTypeReg =
252
267
EmitDIInstruction (SPIRV::NonSemanticExtInst::DebugTypeBasic,
253
268
{BasicTypeStrReg, ConstIntBitwidthReg,
254
269
AttributeEncodingReg, I32ZeroReg});
270
+ BasicTypeRegPairs.emplace_back (BasicType, BasicTypeReg);
271
+ }
272
+
273
+ if (PointerDerivedTypes.size ()) {
274
+ const Register GenericStorageClass =
275
+ GR->buildConstantInt (8 , MIRBuilder, I32Ty, false );
276
+ for (const auto *PointerDerivedType : PointerDerivedTypes) {
277
+ // If the Pointer is representing a void type it's getBaseType
278
+ // is a nullptr
279
+ const auto *MaybeBT =
280
+ cast_or_null<DIBasicType>(PointerDerivedType->getBaseType ());
281
+ for (const auto &BasicTypeRegPair : BasicTypeRegPairs) {
282
+ const auto &[SBT, Reg] = BasicTypeRegPair;
283
+ if (SBT == MaybeBT) {
284
+ [[maybe_unused]]
285
+ const Register DebugPointerTypeReg =
286
+ EmitDIInstruction (SPIRV::NonSemanticExtInst::DebugTypePointer,
287
+ {Reg, GenericStorageClass, I32ZeroReg});
288
+ }
289
+ }
290
+ }
255
291
}
256
292
}
257
293
return true ;
0 commit comments