Skip to content

Commit de2454e

Browse files
committed
--Changes made as per review comments
1 parent e2413dd commit de2454e

File tree

1 file changed

+14
-45
lines changed

1 file changed

+14
-45
lines changed

llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ struct SPIRVEmitNonSemanticDI : public MachineFunctionPass {
196196
SPIRVCodeGenContext &Ctx,
197197
const DenseMap<StringRef, Register> &MacroDefRegs);
198198

199-
void emitDebugTypeEnum(
200-
const SmallPtrSetImpl<const DICompositeType *> &EnumTypes,
201-
SPIRVCodeGenContext &Ctx);
199+
void
200+
emitDebugTypeEnum(const SmallPtrSetImpl<const DICompositeType *> &EnumTypes,
201+
SPIRVCodeGenContext &Ctx);
202202

203203
void emitDebugQualifiedTypes(
204204
const SmallPtrSetImpl<DIDerivedType *> &QualifiedDerivedTypes,
@@ -625,10 +625,6 @@ void SPIRVEmitNonSemanticDI::emitDebugTypeEnum(
625625
}
626626
Register SourceReg =
627627
findRegisterFromMap(EnumTy->getFile(), Ctx.SourceRegPairs);
628-
if (!SourceReg.isValid()) {
629-
SourceReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone,
630-
{}, Ctx, false);
631-
}
632628
Register Line = Ctx.GR->buildConstantInt(EnumTy->getLine(), Ctx.MIRBuilder,
633629
Ctx.I32Ty, false);
634630
Register Column =
@@ -639,10 +635,6 @@ void SPIRVEmitNonSemanticDI::emitDebugTypeEnum(
639635
llvm::errs() << "Warning: Could not find Parent scope register for Enum: "
640636
<< EnumTy->getName() << "\n";
641637
ParentReg = Ctx.GR->getDebugValue(EnumTy->getFile());
642-
if (!ParentReg.isValid()) {
643-
ParentReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone,
644-
{}, Ctx, false);
645-
}
646638
}
647639
Register Size = Ctx.GR->buildConstantInt(EnumTy->getSizeInBits(),
648640
Ctx.MIRBuilder, Ctx.I32Ty, false);
@@ -904,12 +896,12 @@ void SPIRVEmitNonSemanticDI::emitDebugPointerTypes(
904896
Ctx.I32Ty, false, false);
905897

906898
const DIType *BaseTy = PointerDerivedType->getBaseType();
907-
bool HasForwardRef = false;
899+
bool HasForwardRef = false;
908900
Register BaseTypeReg =
909901
findBaseTypeRegisterRecursive(BaseTy, Ctx, HasForwardRef);
910902

911903
if (!BaseTypeReg.isValid()) {
912-
llvm::errs() << "Warning: Failed to find or create placeholder for base "
904+
llvm::errs() << "Warning: Failed to find or create placeholder for base"
913905
"type of pointer.\n";
914906
BaseTypeReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone,
915907
{}, Ctx, false);
@@ -1101,15 +1093,13 @@ void SPIRVEmitNonSemanticDI::emitDebugQualifiedTypes(
11011093
bool IsForwardRef = false;
11021094
Register BaseTypeReg = findBaseTypeRegisterRecursive(
11031095
QualifiedDT->getBaseType(), Ctx, IsForwardRef);
1104-
11051096
if (!BaseTypeReg.isValid()) {
11061097
llvm::errs()
11071098
<< "Warning: Could not find base type for DebugTypeQualifier.\n";
11081099
BaseTypeReg = EmitDIInstruction(
11091100
SPIRV::NonSemanticExtInst::DebugInfoNone, {}, Ctx, false);
11101101
IsForwardRef = false;
11111102
}
1112-
11131103
const uint32_t QualifierValue =
11141104
mapTagToQualifierEncoding(QualifiedDT->getTag());
11151105
const Register QualifierConstReg = Ctx.GR->buildConstantInt(
@@ -1133,17 +1123,14 @@ void SPIRVEmitNonSemanticDI::emitDebugTypedefs(
11331123
bool HasForwardRef = false;
11341124
Register BaseTypeReg = findBaseTypeRegisterRecursive(
11351125
TypedefDT->getBaseType(), Ctx, HasForwardRef);
1136-
11371126
if (!BaseTypeReg.isValid()) {
11381127
llvm::errs() << "Warning: Could not find base type for Typedef: "
11391128
<< TypedefDT->getName() << "\n";
11401129
BaseTypeReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone,
11411130
{}, Ctx, false);
11421131
HasForwardRef = false;
11431132
}
1144-
11451133
Register DefReg = Ctx.GR->getDebugValue(TypedefDT);
1146-
11471134
Register DebugSourceReg =
11481135
findRegisterFromMap(TypedefDT->getFile(), Ctx.SourceRegPairs);
11491136
const Register TypedefNameReg = EmitOpString(TypedefDT->getName(), Ctx);
@@ -1173,8 +1160,14 @@ void SPIRVEmitNonSemanticDI::emitDebugImportedEntities(
11731160
findRegisterFromMap(Imported->getFile(), Ctx.SourceRegPairs);
11741161
// TODO: Handle Entity as there are no current instructions for DINamespace,
11751162
// so replaced by DebugInfoNone
1176-
const Register EntityReg = EmitDIInstruction(
1177-
SPIRV::NonSemanticExtInst::DebugInfoNone, {}, Ctx, false);
1163+
const DINode *Entity = Imported->getEntity();
1164+
bool HasForwardRef = false;
1165+
Register EntityReg;
1166+
if (auto *Ty = dyn_cast<DIType>(Entity))
1167+
EntityReg = findBaseTypeRegisterRecursive(Ty, Ctx, HasForwardRef);
1168+
else
1169+
EntityReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone,
1170+
{}, Ctx, false);
11781171
const Register LineReg = Ctx.GR->buildConstantInt(
11791172
Imported->getLine(), Ctx.MIRBuilder, Ctx.I32Ty, false, false);
11801173
const Register ColumnReg =
@@ -1234,30 +1227,18 @@ Register SPIRVEmitNonSemanticDI::emitDebugGlobalVariable(
12341227
const DIType *Ty = DIGV->getType();
12351228
bool HasForwardRef = false;
12361229
Register TypeReg = findBaseTypeRegisterRecursive(Ty, Ctx, HasForwardRef);
1237-
12381230
if (!TypeReg.isValid()) {
12391231
llvm::errs() << "Warning: Could not find type for Global Variable: " << Name
12401232
<< "\n";
12411233
TypeReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone, {},
12421234
Ctx, false);
12431235
HasForwardRef = false;
12441236
}
1245-
12461237
Register DebugSourceReg =
12471238
findRegisterFromMap(DIGV->getFile(), Ctx.SourceRegPairs);
12481239
Register ParentReg;
12491240
if (ParentScope) {
12501241
ParentReg = Ctx.GR->getDebugValue(ParentScope);
1251-
if (!ParentReg.isValid()) {
1252-
llvm::errs() << "Warning: Could not find parent scope register for "
1253-
"Global Variable.\n";
1254-
ParentReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone,
1255-
{}, Ctx, false);
1256-
}
1257-
} else {
1258-
llvm::errs() << "Warning: DIGlobalVariable has no parent scope\n";
1259-
ParentReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone, {},
1260-
Ctx, false);
12611242
}
12621243
// TODO: Handle Variable Location operand
12631244
Register VariableReg = EmitDIInstruction(
@@ -1285,7 +1266,6 @@ void SPIRVEmitNonSemanticDI::emitDebugArrayTypes(
12851266
bool HasForwardRef = false;
12861267
Register BaseTypeReg =
12871268
findBaseTypeRegisterRecursive(ElementType, Ctx, HasForwardRef);
1288-
12891269
if (!BaseTypeReg.isValid()) {
12901270
llvm::errs()
12911271
<< "Warning: Could not find element type for Array/Vector.\n";
@@ -1382,7 +1362,6 @@ void SPIRVEmitNonSemanticDI::emitAllTemplateDebugInstructions(
13821362
if (auto *TTP = dyn_cast<DITemplateTypeParameter>(MD)) {
13831363
TypeReg = findBaseTypeRegisterRecursive(TTP->getType(), Ctx,
13841364
ParamHasForwardRef);
1385-
13861365
if (!TypeReg.isValid()) {
13871366
llvm::errs()
13881367
<< "Warning: Could not find type for DITemplateTypeParameter: "
@@ -1391,6 +1370,7 @@ void SPIRVEmitNonSemanticDI::emitAllTemplateDebugInstructions(
13911370
{}, Ctx, false);
13921371
ParamHasForwardRef = false;
13931372
}
1373+
13941374
if (ParamHasForwardRef)
13951375
HasForwardRef = true;
13961376

@@ -1414,15 +1394,13 @@ void SPIRVEmitNonSemanticDI::emitAllTemplateDebugInstructions(
14141394
if (TVPTypeForwardRef)
14151395
HasForwardRef = true;
14161396
}
1417-
14181397
if (!TypeReg.isValid()) {
14191398
llvm::errs()
14201399
<< "Warning: Could not find type for DITemplateValueParameter: "
14211400
<< TVP->getName() << "\n";
14221401
TypeReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone,
14231402
{}, Ctx, false);
14241403
}
1425-
14261404
int64_t ActualValue = 0;
14271405
if (auto *CAM = dyn_cast_or_null<ConstantAsMetadata>(TVP->getValue())) {
14281406
if (auto *CI = dyn_cast<ConstantInt>(CAM->getValue())) {
@@ -1663,21 +1641,12 @@ void SPIRVEmitNonSemanticDI::emitDebugTypePtrToMember(
16631641
bool ParentTypeIsFwd = false;
16641642
Register ParentReg =
16651643
findBaseTypeRegisterRecursive(ClassTy, Ctx, ParentTypeIsFwd);
1666-
if (!ParentReg.isValid()) {
1667-
llvm::errs()
1668-
<< "Warning: Could not find Parent Type for PtrToMember.\n";
1669-
ParentReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone,
1670-
{}, Ctx, false);
1671-
ParentTypeIsFwd = false;
1672-
}
16731644
if (ParentTypeIsFwd)
16741645
OpHasForwardRef = true;
1675-
16761646
SmallVector<Register, 3> Ops;
16771647
Ops.push_back(MemberTypeReg);
16781648
Ops.push_back(ParentReg);
16791649
Register DefReg = Ctx.GR->getDebugValue(PtrToMemberType);
1680-
16811650
Register PtrToMemberTypeReg =
16821651
EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugTypePtrToMember,
16831652
Ops, Ctx, OpHasForwardRef, DefReg);

0 commit comments

Comments
 (0)