Skip to content
106 changes: 13 additions & 93 deletions llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ struct SPIRVEmitNonSemanticDI : public MachineFunctionPass {
SPIRVCodeGenContext &Ctx,
const DenseMap<StringRef, Register> &MacroDefRegs);

void emitDebugTypeEnum(
const SmallPtrSetImpl<const DICompositeType *> &EnumTypes,
SPIRVCodeGenContext &Ctx);
void
emitDebugTypeEnum(const SmallPtrSetImpl<const DICompositeType *> &EnumTypes,
SPIRVCodeGenContext &Ctx);

void emitDebugQualifiedTypes(
const SmallPtrSetImpl<DIDerivedType *> &QualifiedDerivedTypes,
Expand Down Expand Up @@ -618,17 +618,8 @@ void SPIRVEmitNonSemanticDI::emitDebugTypeEnum(
bool UnderlyingTypeIsFwd = false;
Register UnderlyingTypeReg = findBaseTypeRegisterRecursive(
EnumTy->getBaseType(), Ctx, UnderlyingTypeIsFwd);
if (!UnderlyingTypeReg.isValid()) {
UnderlyingTypeReg = EmitDIInstruction(
SPIRV::NonSemanticExtInst::DebugInfoNone, {}, Ctx, false);
UnderlyingTypeIsFwd = false;
}
Register SourceReg =
findRegisterFromMap(EnumTy->getFile(), Ctx.SourceRegPairs);
if (!SourceReg.isValid()) {
SourceReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone,
{}, Ctx, false);
}
Register Line = Ctx.GR->buildConstantInt(EnumTy->getLine(), Ctx.MIRBuilder,
Ctx.I32Ty, false);
Register Column =
Expand All @@ -639,10 +630,6 @@ void SPIRVEmitNonSemanticDI::emitDebugTypeEnum(
llvm::errs() << "Warning: Could not find Parent scope register for Enum: "
<< EnumTy->getName() << "\n";
ParentReg = Ctx.GR->getDebugValue(EnumTy->getFile());
if (!ParentReg.isValid()) {
ParentReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone,
{}, Ctx, false);
}
}
Register Size = Ctx.GR->buildConstantInt(EnumTy->getSizeInBits(),
Ctx.MIRBuilder, Ctx.I32Ty, false);
Expand Down Expand Up @@ -904,12 +891,12 @@ void SPIRVEmitNonSemanticDI::emitDebugPointerTypes(
Ctx.I32Ty, false, false);

const DIType *BaseTy = PointerDerivedType->getBaseType();
bool HasForwardRef = false;
bool HasForwardRef = false;
Register BaseTypeReg =
findBaseTypeRegisterRecursive(BaseTy, Ctx, HasForwardRef);

if (!BaseTypeReg.isValid()) {
llvm::errs() << "Warning: Failed to find or create placeholder for base "
llvm::errs() << "Warning: Failed to find or create placeholder for base"
"type of pointer.\n";
BaseTypeReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone,
{}, Ctx, false);
Expand Down Expand Up @@ -1102,14 +1089,6 @@ void SPIRVEmitNonSemanticDI::emitDebugQualifiedTypes(
Register BaseTypeReg = findBaseTypeRegisterRecursive(
QualifiedDT->getBaseType(), Ctx, IsForwardRef);

if (!BaseTypeReg.isValid()) {
llvm::errs()
<< "Warning: Could not find base type for DebugTypeQualifier.\n";
BaseTypeReg = EmitDIInstruction(
SPIRV::NonSemanticExtInst::DebugInfoNone, {}, Ctx, false);
IsForwardRef = false;
}

const uint32_t QualifierValue =
mapTagToQualifierEncoding(QualifiedDT->getTag());
const Register QualifierConstReg = Ctx.GR->buildConstantInt(
Expand All @@ -1134,14 +1113,6 @@ void SPIRVEmitNonSemanticDI::emitDebugTypedefs(
Register BaseTypeReg = findBaseTypeRegisterRecursive(
TypedefDT->getBaseType(), Ctx, HasForwardRef);

if (!BaseTypeReg.isValid()) {
llvm::errs() << "Warning: Could not find base type for Typedef: "
<< TypedefDT->getName() << "\n";
BaseTypeReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone,
{}, Ctx, false);
HasForwardRef = false;
}

Register DefReg = Ctx.GR->getDebugValue(TypedefDT);

Register DebugSourceReg =
Expand Down Expand Up @@ -1173,8 +1144,14 @@ void SPIRVEmitNonSemanticDI::emitDebugImportedEntities(
findRegisterFromMap(Imported->getFile(), Ctx.SourceRegPairs);
// TODO: Handle Entity as there are no current instructions for DINamespace,
// so replaced by DebugInfoNone
const Register EntityReg = EmitDIInstruction(
SPIRV::NonSemanticExtInst::DebugInfoNone, {}, Ctx, false);
const DINode *Entity = Imported->getEntity();
bool HasForwardRef = false;
Register EntityReg;
if (auto *Ty = dyn_cast<DIType>(Entity))
EntityReg = findBaseTypeRegisterRecursive(Ty, Ctx, HasForwardRef);
else
EntityReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone,
{}, Ctx, false);
const Register LineReg = Ctx.GR->buildConstantInt(
Imported->getLine(), Ctx.MIRBuilder, Ctx.I32Ty, false, false);
const Register ColumnReg =
Expand Down Expand Up @@ -1234,30 +1211,11 @@ Register SPIRVEmitNonSemanticDI::emitDebugGlobalVariable(
const DIType *Ty = DIGV->getType();
bool HasForwardRef = false;
Register TypeReg = findBaseTypeRegisterRecursive(Ty, Ctx, HasForwardRef);

if (!TypeReg.isValid()) {
llvm::errs() << "Warning: Could not find type for Global Variable: " << Name
<< "\n";
TypeReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone, {},
Ctx, false);
HasForwardRef = false;
}

Register DebugSourceReg =
findRegisterFromMap(DIGV->getFile(), Ctx.SourceRegPairs);
Register ParentReg;
if (ParentScope) {
ParentReg = Ctx.GR->getDebugValue(ParentScope);
if (!ParentReg.isValid()) {
llvm::errs() << "Warning: Could not find parent scope register for "
"Global Variable.\n";
ParentReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone,
{}, Ctx, false);
}
} else {
llvm::errs() << "Warning: DIGlobalVariable has no parent scope\n";
ParentReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone, {},
Ctx, false);
}
// TODO: Handle Variable Location operand
Register VariableReg = EmitDIInstruction(
Expand Down Expand Up @@ -1286,14 +1244,6 @@ void SPIRVEmitNonSemanticDI::emitDebugArrayTypes(
Register BaseTypeReg =
findBaseTypeRegisterRecursive(ElementType, Ctx, HasForwardRef);

if (!BaseTypeReg.isValid()) {
llvm::errs()
<< "Warning: Could not find element type for Array/Vector.\n";
BaseTypeReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone,
{}, Ctx, false);
HasForwardRef = false;
}

DINodeArray Subranges = ArrayTy->getElements();
if (ArrayTy->isVector()) {
assert(Subranges.size() == 1 && "Only 1D vectors supported!");
Expand Down Expand Up @@ -1383,14 +1333,6 @@ void SPIRVEmitNonSemanticDI::emitAllTemplateDebugInstructions(
TypeReg = findBaseTypeRegisterRecursive(TTP->getType(), Ctx,
ParamHasForwardRef);

if (!TypeReg.isValid()) {
llvm::errs()
<< "Warning: Could not find type for DITemplateTypeParameter: "
<< TTP->getName() << "\n";
TypeReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone,
{}, Ctx, false);
ParamHasForwardRef = false;
}
if (ParamHasForwardRef)
HasForwardRef = true;

Expand All @@ -1415,14 +1357,6 @@ void SPIRVEmitNonSemanticDI::emitAllTemplateDebugInstructions(
HasForwardRef = true;
}

if (!TypeReg.isValid()) {
llvm::errs()
<< "Warning: Could not find type for DITemplateValueParameter: "
<< TVP->getName() << "\n";
TypeReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone,
{}, Ctx, false);
}

int64_t ActualValue = 0;
if (auto *CAM = dyn_cast_or_null<ConstantAsMetadata>(TVP->getValue())) {
if (auto *CI = dyn_cast<ConstantInt>(CAM->getValue())) {
Expand Down Expand Up @@ -1650,26 +1584,12 @@ void SPIRVEmitNonSemanticDI::emitDebugTypePtrToMember(
bool MemberTypeIsFwd = false;
Register MemberTypeReg =
findBaseTypeRegisterRecursive(BaseTy, Ctx, MemberTypeIsFwd);
if (!MemberTypeReg.isValid()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep DebugInfoNone for types and sort it out later either in the specification or implementation.

llvm::errs()
<< "Warning: Could not find Member Type for PtrToMember.\n";
MemberTypeReg = EmitDIInstruction(
SPIRV::NonSemanticExtInst::DebugInfoNone, {}, Ctx, false);
MemberTypeIsFwd = false;
}
if (MemberTypeIsFwd)
OpHasForwardRef = true;
const DIType *ClassTy = PtrToMemberType->getClassType();
bool ParentTypeIsFwd = false;
Register ParentReg =
findBaseTypeRegisterRecursive(ClassTy, Ctx, ParentTypeIsFwd);
if (!ParentReg.isValid()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean, that we keep translating the debug instruction, even if !ParentReg.isValid()? If backend would emit nothing in this case, then removal of these lines are fine. Otherwise, DebugTypePtrToMember must not be emitted in the first place. Same applicable for every instruction, that might have not-valid scope/parent operand.

llvm::errs()
<< "Warning: Could not find Parent Type for PtrToMember.\n";
ParentReg = EmitDIInstruction(SPIRV::NonSemanticExtInst::DebugInfoNone,
{}, Ctx, false);
ParentTypeIsFwd = false;
}
if (ParentTypeIsFwd)
OpHasForwardRef = true;

Expand Down
Loading