47template <
typename MapT>
48static std::optional<MCRegister> lookupOptReg(
const MapT &Map,
49 typename MapT::key_type
Key) {
53 assert(It->second.isValid() &&
"invalid register stored in map");
58 NSDIFlagIsProtected = 1u << 0,
59 NSDIFlagIsPrivate = 1u << 1,
60 NSDIFlagIsPublic = NSDIFlagIsPrivate | NSDIFlagIsProtected,
61 NSDIFlagIsLocal = 1u << 2,
62 NSDIFlagIsDefinition = 1u << 3,
63 NSDIFlagFwdDecl = 1u << 4,
64 NSDIFlagArtificial = 1u << 5,
65 NSDIFlagExplicit = 1u << 6,
66 NSDIFlagPrototyped = 1u << 7,
67 NSDIFlagObjectPointer = 1u << 8,
68 NSDIFlagStaticMember = 1u << 9,
69 NSDIFlagIndirectVariable = 1u << 10,
70 NSDIFlagLValueReference = 1u << 11,
71 NSDIFlagRValueReference = 1u << 12,
72 NSDIFlagIsOptimized = 1u << 13,
73 NSDIFlagIsEnumClass = 1u << 14,
74 NSDIFlagTypePassByValue = 1u << 15,
75 NSDIFlagTypePassByReference = 1u << 16,
76 NSDIFlagUnknownPhysicalLayout = 1u << 17,
82 Flags |= NSDIFlagIsPublic;
84 Flags |= NSDIFlagIsProtected;
86 Flags |= NSDIFlagIsPrivate;
87 if (DFlags & DINode::FlagFwdDecl)
88 Flags |= NSDIFlagFwdDecl;
89 if (DFlags & DINode::FlagArtificial)
90 Flags |= NSDIFlagArtificial;
91 if (DFlags & DINode::FlagExplicit)
92 Flags |= NSDIFlagExplicit;
93 if (DFlags & DINode::FlagPrototyped)
94 Flags |= NSDIFlagPrototyped;
95 if (DFlags & DINode::FlagObjectPointer)
96 Flags |= NSDIFlagObjectPointer;
97 if (DFlags & DINode::FlagStaticMember)
98 Flags |= NSDIFlagStaticMember;
99 if (DFlags & DINode::FlagLValueReference)
100 Flags |= NSDIFlagLValueReference;
101 if (DFlags & DINode::FlagRValueReference)
102 Flags |= NSDIFlagRValueReference;
103 if (DFlags & DINode::FlagTypePassByValue)
104 Flags |= NSDIFlagTypePassByValue;
105 if (DFlags & DINode::FlagTypePassByReference)
106 Flags |= NSDIFlagTypePassByReference;
107 if (DFlags & DINode::FlagEnumClass)
108 Flags |= NSDIFlagIsEnumClass;
115 if (GV->isLocalToUnit())
116 Flags |= NSDIFlagIsLocal;
117 if (GV->isDefinition())
118 Flags |= NSDIFlagIsDefinition;
121 if (SP->isLocalToUnit())
122 Flags |= NSDIFlagIsLocal;
123 if (SP->isOptimized())
124 Flags |= NSDIFlagIsOptimized;
125 if (SP->isDefinition())
126 Flags |= NSDIFlagIsDefinition;
127 Flags |= mapDIFlagsToNonSemantic(SP->getFlags());
129 if (DN->
getTag() == dwarf::DW_TAG_reference_type)
130 Flags |= NSDIFlagLValueReference;
131 if (DN->
getTag() == dwarf::DW_TAG_rvalue_reference_type)
132 Flags |= NSDIFlagRValueReference;
134 Flags |= mapDIFlagsToNonSemantic(Ty->getFlags());
136 Flags |= mapDIFlagsToNonSemantic(LV->getFlags());
142static uint32_t mapCompositeTypeTag(
unsigned Tag) {
144 case dwarf::DW_TAG_class_type:
146 case dwarf::DW_TAG_structure_type:
148 case dwarf::DW_TAG_union_type:
152 ". Expecting 0, 1 or 2");
158static std::optional<uint32_t> mapTypeQualifierTag(
unsigned Tag) {
160 case dwarf::DW_TAG_const_type:
162 case dwarf::DW_TAG_volatile_type:
164 case dwarf::DW_TAG_restrict_type:
166 case dwarf::DW_TAG_atomic_type:
184 bool SeenOpVariable =
false;
186 if (
MI.getOpcode() == SPIRV::OpVariable ||
187 MI.getOpcode() == SPIRV::OpUntypedVariableKHR) {
188 SeenOpVariable =
true;
190 LastOpVariable = &
MI;
194 bool CanInterleaveWithOpVariable =
195 MI.getOpcode() == SPIRV::OpLine ||
MI.getOpcode() == SPIRV::OpNoLine;
196 if (SeenOpVariable && !CanInterleaveWithOpVariable &&
200 return LastOpVariable;
211 const SPIRVOptions &CLOpts = TM.
getCLOpts();
213 UseLexicalBlockDiscriminatorScope =
214 valueOr(CLOpts.debug_lexical_block_discriminator_scope, AMDDefault);
215 UseDebugScopeForwardRefs = CLOpts.debug_scope_forward_refs;
216 AllowDebugDeclareUntypedVariable =
217 valueOr(CLOpts.debug_declare_untyped_variable, AMDDefault);
223unsigned SPIRVNonSemanticDebugHandler::toNSDISrcLang(
unsigned DwarfSrcLang) {
224 switch (DwarfSrcLang) {
225 case dwarf::DW_LANG_OpenCL:
227 case dwarf::DW_LANG_OpenCL_CPP:
229 case dwarf::DW_LANG_CPP_for_OpenCL:
231 case dwarf::DW_LANG_GLSL:
233 case dwarf::DW_LANG_HLSL:
235 case dwarf::DW_LANG_SYCL:
237 case dwarf::DW_LANG_Zig:
245 return BT->getEncoding() == dwarf::DW_ATE_boolean;
254 unsigned Width =
BT->getSizeInBits();
263 ?
Value.trunc(std::min(Width, 64u)).getZExtValue()
264 :
Value.getZExtValue(),
275 unsigned Tag = DT->getTag();
276 if ((Tag != dwarf::DW_TAG_typedef && !mapTypeQualifierTag(Tag)) ||
279 Ty = DT->getBaseType();
290 unsigned Size =
BT->getSizeInBits();
291 switch (
BT->getEncoding()) {
292 case dwarf::DW_ATE_signed:
293 case dwarf::DW_ATE_unsigned:
294 case dwarf::DW_ATE_signed_char:
295 case dwarf::DW_ATE_unsigned_char:
297 case dwarf::DW_ATE_float:
323 for (
const MDNode *
N : SP->getRetainedNodes())
328 Locations.insert(
DL);
331 Locations.insert(
DL);
347 while (S && !Out.contains(S) &&
363 CompileUnits.clear();
365 EnumCompileUnits.clear();
367 UniqueDebugLocations.clear();
368 GlobalVariableDebugInfoMap.clear();
369 LocalVariables.clear();
370 DebugLocalVariableRegs.clear();
371 DebugExpressionRegs.clear();
372 LexicalBlocks.clear();
373 DebugScopeRegs.clear();
374 ScopesInProgress.clear();
375 CanUseForwardRefs =
false;
376 UsedForwardRefs =
false;
377 PendingStrings.clear();
378 PendingGlobalDI.clear();
379 PendingSink =
nullptr;
380 FailedScopes.clear();
381 DebugInlinedAtRegs.clear();
382 ScopeToPathOpStringReg.clear();
383 DebugSourceRegByFileStr.clear();
384 OpStringContentCache.clear();
385 ScalarTypeCache.clear();
386 ScalarConstantCache.clear();
387 ConstantValueRegs.clear();
388 DebugOperationCache.clear();
389 DebugExpressionCache.clear();
390 ModuleScopeIds.clear();
391 GlobalDIEmitted =
false;
392 GlobalNSDIEnabled =
false;
393 CurrentMAI =
nullptr;
395 DebugStringsGenerated =
false;
405 CompileUnitInfo Info;
408 Info.FilePath = File->getFilename();
411 File->getFilename());
414 Info.SpirvSourceLanguage = toNSDISrcLang(
CU->getSourceLanguage().getName());
415 CompileUnits.push_back(std::move(Info));
417 EnumCompileUnits.try_emplace(ET,
CU);
423 if (
const NamedMDNode *Flags = M->getNamedMetadata(
"llvm.module.flags")) {
424 for (
const auto *
Op : Flags->operands()) {
439 return Ty->getTag() != dwarf::DW_TAG_member;
448 G.getDebugInfo(GVEs);
459 GlobalVariableDebugInfoMap.try_emplace(
460 GV, GlobalVariableDebugInfo{Expr, DIGVToLLVMGV.
lookup(GV)});
478 if (
MI.getNumOperands() == 0 || !
MI.getOperand(0).isReg() ||
479 !
MI.getOperand(0).isDef())
486 if (CompileUnits.empty())
488 if (!ST.canUseExtension(SPIRV::Extension::SPV_KHR_non_semantic_info))
495 UseDebugScopeForwardRefs &&
497 SPIRV::Extension::SPV_KHR_relaxed_extended_instruction);
507 ModuleScopeIds.insert(Id);
511void SPIRVNonSemanticDebugHandler::emitMCInst(
MCInst &Inst) {
513 PendingSink->push_back(Inst);
519void SPIRVNonSemanticDebugHandler::flushPendingInsts(
521 for (MCInst &Inst : Insts)
527SPIRVNonSemanticDebugHandler::emitOpString(
StringRef S,
538MCRegister SPIRVNonSemanticDebugHandler::emitOpStringIfNew(
541 assert(!DebugStringsGenerated &&
542 "emitOpStringIfNew is only valid while generating NSDI OpStrings");
544 auto [It,
Inserted] = OpStringContentCache.try_emplace(S, MCRegister());
546 It->second = emitOpString(S, MAI);
553 assert(DebugStringsGenerated &&
554 "getCachedOpStringReg requires generateDebugStrings() first");
556 auto It = OpStringContentCache.find(S);
557 assert(It != OpStringContentCache.end() &&
558 "NSDI OpString missing from cache; generateDebugStrings must cache "
559 "every string used in section 10");
563MCRegister SPIRVNonSemanticDebugHandler::emitAndCacheScopePathOpStringReg(
565 auto [It,
Inserted] = ScopeToPathOpStringReg.try_emplace(Scope, MCRegister());
567 It->second = emitOpStringIfNew(getDebugFullPath(Scope), MAI);
571MCRegister SPIRVNonSemanticDebugHandler::getCachedScopePathOpStringReg(
572 const DIScope *Scope,
bool UseEmptyPathIfNullScope) {
574 assert(UseEmptyPathIfNullScope &&
575 "null scope path lookup requires UseEmptyPathIfNullScope");
576 assert(CachedEmptyStringReg.isValid() &&
577 "empty path OpString must be cached in generateDebugStrings");
578 return CachedEmptyStringReg;
580 auto It = ScopeToPathOpStringReg.find(Scope);
581 assert(It != ScopeToPathOpStringReg.end() &&
582 "path OpString must be cached in generateDebugStrings");
583 MCRegister FileStrReg = It->second;
584 assert(FileStrReg.
isValid() &&
"path OpString id must be valid once cached");
588MCRegister SPIRVNonSemanticDebugHandler::emitOpConstantI32(
590 return findOrEmitConstant(SPIRV::OpConstantI, I32TypeReg,
Value,
594bool SPIRVNonSemanticDebugHandler::markForwardReferencedOperands(
596 bool HasForwardRef =
false;
597 for (
auto &Entry : ScopesInProgress) {
598 InProgressScope &InProgress =
Entry.second;
599 assert(InProgress.Id.isValid() &&
600 "in-progress scope must have a reserved id");
603 InProgress.ForwardReferenced =
true;
604 HasForwardRef =
true;
606 return HasForwardRef;
609MCRegister SPIRVNonSemanticDebugHandler::emitExtInst(
610 SPIRV::NonSemanticExtInst::NonSemanticExtInst Opcode,
613 std::optional<MCRegister> ResultReg) {
614 assert((!ResultReg || ResultReg->isValid()) &&
615 "ResultReg must be a valid id when provided");
622 CanUseForwardRefs && markForwardReferencedOperands(
Operands);
623 assert((!HasForwardRef || PendingSink) &&
624 "forward reference built after OpExtension was printed");
625 UsedForwardRefs |= HasForwardRef;
628 Inst.
setOpcode(HasForwardRef ? SPIRV::OpExtInstWithForwardRefsKHR
640MCRegister SPIRVNonSemanticDebugHandler::getOrEmitOpTypeVoidReg(
642 if (!CachedOpTypeVoidReg.isValid())
643 CachedOpTypeVoidReg = findOrEmitOpTypeVoid(MAI);
644 return CachedOpTypeVoidReg;
647MCRegister SPIRVNonSemanticDebugHandler::getOrEmitOpTypeInt32Reg(
649 if (!CachedOpTypeInt32Reg.isValid())
650 CachedOpTypeInt32Reg = findOrEmitOpTypeInt32(MAI);
651 return CachedOpTypeInt32Reg;
654MCRegister SPIRVNonSemanticDebugHandler::findOrEmitOpTypeVoid(
657 if (
MI->getOpcode() == SPIRV::OpTypeVoid)
674 unsigned Width =
BT->getSizeInBits();
678MCRegister SPIRVNonSemanticDebugHandler::findOrEmitScalarType(
681 bool IsFloat =
BT->getEncoding() == dwarf::DW_ATE_float;
682 unsigned Opcode = IsBool ? SPIRV::OpTypeBool
683 : IsFloat ? SPIRV::OpTypeFloat
687 int64_t Width = IsBool ? 0 :
BT->getSizeInBits();
692 if (Opcode == SPIRV::OpTypeInt && Width == 32)
693 return getOrEmitOpTypeInt32Reg(MAI);
696 ScalarTypeCache.try_emplace({Opcode, Width}, MCRegister());
698 return CacheIt->second;
703 if (
MI->getOpcode() != Opcode)
705 if (IsBool || (
MI->getOperand(1).getImm() == Width &&
706 (IsFloat ||
MI->getOperand(2).getImm() == 0))) {
709 return CacheIt->second;
731 CacheIt->second =
Reg;
738 unsigned Words = IsWide ? 2 : 1;
739 if (
MI.getNumOperands() < 2 + Words)
742 for (
unsigned I = 0;
I < Words; ++
I) {
743 if (!
MI.getOperand(2 +
I).isImm())
749 return Found ==
Value;
752MCRegister SPIRVNonSemanticDebugHandler::findModuleConstant(
756 if (
MI->getOpcode() != Opcode ||
MI->getNumOperands() < 2)
770MCRegister SPIRVNonSemanticDebugHandler::findOrEmitConstant(
773 bool IsBool = Width == 0;
774 bool IsWide = Width == 64;
777 ScalarConstantCache.try_emplace({TypeReg.
id(),
Value}, MCRegister());
779 return CacheIt->second;
782 findModuleConstant(Opcode, TypeReg,
Value, IsBool, IsWide, MAI);
784 CacheIt->second = Found;
800 }
else if (Width == 16) {
807 CacheIt->second =
Reg;
811MCRegister SPIRVNonSemanticDebugHandler::findOrEmitScalarConstant(
813 MCRegister TypeReg = findOrEmitScalarType(
BT, MAI);
818 bool IsFloat =
BT->getEncoding() == dwarf::DW_ATE_float;
820 IsBool ? (
Value ? SPIRV::OpConstantTrue : SPIRV::OpConstantFalse)
821 : IsFloat ?
SPIRV::OpConstantF
822 :
SPIRV::OpConstantI;
823 return findOrEmitConstant(Opcode, TypeReg,
Value,
824 IsBool ? 0 :
BT->getSizeInBits(), MAI);
827MCRegister SPIRVNonSemanticDebugHandler::findOrEmitOpTypeInt32(
830 if (
MI->getOpcode() == SPIRV::OpTypeInt &&
831 MI->getOperand(1).getImm() == 32 &&
MI->getOperand(2).getImm() == 0)
850auto SPIRVNonSemanticDebugHandler::getOrCreateDebugScope(
const DIScope *S)
851 -> EmitResult<MCRegister> {
852 if (!S || FailedScopes.contains(S))
853 return EmitResult<MCRegister>::unsupported();
854 if (
auto Reg = lookupOptReg(DebugScopeRegs, S))
855 return EmitResult<MCRegister>::emitted(*
Reg);
859 auto [InProgressIt, FirstVisit] = ScopesInProgress.try_emplace(S);
861 if (!CanUseForwardRefs)
862 return EmitResult<MCRegister>::inProgress();
866 MCRegister ReservedId = InProgressIt->second.Id;
867 assert(ReservedId.
isValid() &&
"in-progress scope must have a reserved id");
868 return EmitResult<MCRegister>::emitted(ReservedId);
872 assert(CurrentMAI &&
"debug scope id allocation requires CurrentMAI");
874 assert(
Id.isValid() &&
"debug scope id must be a valid register");
875 InProgressIt->second.Id =
Id;
877 EmitResult<PreparedScope>
P = emitDebugScope(S);
878 assert((!CanUseForwardRefs ||
P.Status != EmitStatus::InProgress) &&
879 "InProgress is only returned when forward references are unsupported");
882 InProgressIt = ScopesInProgress.find(S);
883 assert(InProgressIt != ScopesInProgress.end() &&
884 "scope must stay in progress until its instruction is emitted");
885 bool ForwardReferenced = InProgressIt->second.ForwardReferenced;
886 ScopesInProgress.erase(InProgressIt);
890 if (ForwardReferenced) {
891 assert(CanUseForwardRefs &&
892 "a forward reference requires relaxed extended instructions");
893 assert(
P.Status == EmitStatus::Unsupported &&
894 "a forward-referenced scope fails as unsupported");
896 emitExtInst(SPIRV::NonSemanticExtInst::DebugInfoNone,
905 if (
P.Status == EmitStatus::Unsupported)
906 FailedScopes.insert(S);
907 return P.Status == EmitStatus::InProgress
908 ? EmitResult<MCRegister>::inProgress()
915 emitExtInst(
P.Value->Opcode, getOrEmitOpTypeVoidReg(MAI),
918 "debug scope result id must reuse the id reserved at entry");
919 ScopesInProgress.erase(S);
920 assert(!GlobalNSDIEnabled &&
921 "debug type or scope created after module-scope NSDI emission");
922 DebugScopeRegs[S] =
Reg;
923 return EmitResult<MCRegister>::emitted(
Reg);
926auto SPIRVNonSemanticDebugHandler::getOrCreateDebugTypeOrNone(
const DIType *Ty)
927 -> EmitResult<MCRegister> {
929 return getOrCreateDebugScope(Ty);
930 assert(CachedDebugInfoNoneReg.isValid() &&
931 "DebugInfoNone must be emitted before debug types");
932 return EmitResult<MCRegister>::emitted(CachedDebugInfoNoneReg);
935auto SPIRVNonSemanticDebugHandler::emitDebugTypeBasic(
939 return EmitResult<PreparedScope>::unsupported();
941 MCRegister NameReg = getCachedOpStringReg(
BT->getName());
943 static_cast<uint32_t
>(
BT->getSizeInBits()), I32TypeReg, MAI);
947 unsigned Encoding = 0;
948 switch (
BT->getEncoding()) {
949 case dwarf::DW_ATE_address:
952 case dwarf::DW_ATE_boolean:
955 case dwarf::DW_ATE_float:
958 case dwarf::DW_ATE_signed:
961 case dwarf::DW_ATE_signed_char:
964 case dwarf::DW_ATE_unsigned:
967 case dwarf::DW_ATE_unsigned_char:
971 MCRegister EncodingReg = emitOpConstantI32(Encoding, I32TypeReg, MAI);
972 MCRegister FlagsReg = emitOpConstantI32(0, I32TypeReg, MAI);
973 return EmitResult<PreparedScope>::emitted(
974 PreparedScope{SPIRV::NonSemanticExtInst::DebugTypeBasic,
975 {NameReg, SizeReg, EncodingReg, FlagsReg}});
978auto SPIRVNonSemanticDebugHandler::emitDebugScope(
const DIScope *S)
979 -> EmitResult<PreparedScope> {
980 assert(CurrentMAI &&
"emitDebugScope requires CurrentMAI");
983 MCRegister VoidTypeReg = getOrEmitOpTypeVoidReg(MAI);
984 MCRegister I32TypeReg = getOrEmitOpTypeInt32Reg(MAI);
987 return emitDebugTypeBasic(
BT, I32TypeReg, MAI);
989 return emitDebugTypeFunctionForSubroutineType(ST, MAI);
991 return emitDebugTypeForCompositeType(CT, VoidTypeReg, I32TypeReg,
994 return emitDebugTypeForDerivedType(DT, VoidTypeReg, I32TypeReg,
997 return emitDebugLexicalBlock(S, VoidTypeReg, I32TypeReg, ExtInstSetReg,
1000 return emitDebugLexicalBlockDiscriminator(LBF, VoidTypeReg, I32TypeReg,
1001 ExtInstSetReg, MAI);
1003 if (
SP->isDefinition())
1004 return emitDebugFunction(SP, VoidTypeReg, I32TypeReg, ExtInstSetReg, MAI);
1005 return emitDebugFunctionDeclaration(SP, VoidTypeReg, I32TypeReg,
1006 ExtInstSetReg, MAI);
1008 return EmitResult<PreparedScope>::unsupported();
1011auto SPIRVNonSemanticDebugHandler::emitDebugTypeForCompositeType(
1014 -> EmitResult<PreparedScope> {
1015 switch (CT->getTag()) {
1016 case dwarf::DW_TAG_array_type:
1029 return emitDebugTypeVector(CT, MAI);
1030 return emitDebugTypeArray(CT, MAI);
1031 case dwarf::DW_TAG_structure_type:
1032 case dwarf::DW_TAG_class_type:
1033 case dwarf::DW_TAG_union_type:
1034 return emitDebugTypeComposite(CT, VoidTypeReg, I32TypeReg, ExtInstSetReg,
1036 case dwarf::DW_TAG_enumeration_type:
1037 return emitDebugTypeEnum(CT, VoidTypeReg, I32TypeReg, ExtInstSetReg, MAI);
1039 return EmitResult<PreparedScope>::unsupported();
1043auto SPIRVNonSemanticDebugHandler::emitDebugTypeForDerivedType(
1046 -> EmitResult<PreparedScope> {
1047 switch (DT->getTag()) {
1048 case dwarf::DW_TAG_pointer_type:
1049 return emitDebugTypePointer(DT, MAI);
1050 case dwarf::DW_TAG_typedef:
1051 return emitDebugTypedef(DT, VoidTypeReg, I32TypeReg, ExtInstSetReg, MAI);
1052 case dwarf::DW_TAG_member:
1053 return emitDebugTypeMember(DT, VoidTypeReg, I32TypeReg, ExtInstSetReg, MAI);
1055 if (std::optional<uint32_t> Qualifier = mapTypeQualifierTag(DT->getTag()))
1056 return emitDebugTypeQualifier(DT, *Qualifier, MAI);
1057 return EmitResult<PreparedScope>::unsupported();
1061auto SPIRVNonSemanticDebugHandler::emitDebugTypePointer(
1063 -> EmitResult<PreparedScope> {
1066 if (!PT->getDWARFAddressSpace().has_value())
1067 return EmitResult<PreparedScope>::unsupported();
1069 EmitResult<MCRegister>
Base = getOrCreateDebugTypeOrNone(PT->getBaseType());
1071 return EmitResult<PreparedScope>::failure(
Base);
1073 MCRegister I32TypeReg = getOrEmitOpTypeInt32Reg(MAI);
1075 emitOpConstantI32(transDebugFlags(PT), I32TypeReg, MAI);
1080 MCRegister StorageClassReg = emitOpConstantI32(
1084 return EmitResult<PreparedScope>::emitted(
1085 PreparedScope{SPIRV::NonSemanticExtInst::DebugTypePointer,
1086 {*
Base.Value, StorageClassReg, DebugTypePointerFlagsReg}});
1089auto SPIRVNonSemanticDebugHandler::emitDebugTypeQualifier(
1091 -> EmitResult<PreparedScope> {
1092 EmitResult<MCRegister>
Base = getOrCreateDebugTypeOrNone(QT->getBaseType());
1094 return EmitResult<PreparedScope>::failure(
Base);
1097 emitOpConstantI32(Qualifier, getOrEmitOpTypeInt32Reg(MAI), MAI);
1098 return EmitResult<PreparedScope>::emitted(
1099 PreparedScope{SPIRV::NonSemanticExtInst::DebugTypeQualifier,
1100 {*
Base.Value, QualifierReg}});
1103auto SPIRVNonSemanticDebugHandler::emitDebugTypeFunctionForSubroutineType(
1105 -> EmitResult<PreparedScope> {
1106 MCRegister VoidTypeReg = getOrEmitOpTypeVoidReg(MAI);
1107 MCRegister I32TypeReg = getOrEmitOpTypeInt32Reg(MAI);
1109 emitOpConstantI32(transDebugFlags(ST), I32TypeReg, MAI);
1110 DITypeArray
TA =
ST->getTypeArray();
1117 Ops.push_back(VoidTypeReg);
1119 for (
unsigned I = 0,
E =
TA.size();
I !=
E; ++
I) {
1120 bool IsReturnType = (
I == 0);
1121 EmitResult<MCRegister>
Slot =
1122 mapDISignatureTypeToReg(TA[
I], VoidTypeReg, IsReturnType);
1126 return EmitResult<PreparedScope>::failure(Slot);
1130 return EmitResult<PreparedScope>::emitted(
1131 PreparedScope{SPIRV::NonSemanticExtInst::DebugTypeFunction,
Ops});
1135auto SPIRVNonSemanticDebugHandler::resolveScope(
const DIScope *Scope,
1137 -> EmitResult<MCRegister> {
1138 if (!UseLexicalBlockDiscriminatorScope)
1140 Scope = LBF->getScope();
1145 return getOrCreateDebugScope(Scope);
1148 auto CUResult = [](std::optional<MCRegister>
Reg) {
1149 return Reg ? EmitResult<MCRegister>::emitted(*
Reg)
1153 return CUResult(lookupOptReg(DebugScopeRegs, FallbackCU));
1155 if (CompileUnits.empty())
1156 return EmitResult<MCRegister>::unsupported();
1158 return CUResult(lookupOptReg(DebugScopeRegs, CompileUnits[0].TheCU));
1161auto SPIRVNonSemanticDebugHandler::emitDebugLexicalBlock(
1164 -> EmitResult<PreparedScope> {
1166 "S must be a DILexicalBlock or DINamespace in emitDebugLexicalBlock");
1167 EmitResult<MCRegister> Parent =
resolveScope(S->getScope());
1169 return EmitResult<PreparedScope>::failure(Parent);
1171 MCRegister FileStrReg = getCachedScopePathOpStringReg(
1172 S->getFile(),
true);
1173 MCRegister SrcReg = getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg,
1174 ExtInstSetReg, MAI);
1178 MCRegister LineReg = emitOpConstantI32(
static_cast<uint32_t
>(LB->getLine()),
1181 static_cast<uint32_t
>(LB->getColumn()), I32TypeReg, MAI);
1182 Ops = {SrcReg, LineReg, ColReg, *Parent.Value};
1186 MCRegister LineReg = emitOpConstantI32(0, I32TypeReg, MAI);
1187 MCRegister ColReg = emitOpConstantI32(0, I32TypeReg, MAI);
1188 MCRegister NameReg = getCachedOpStringReg(NS->getName());
1189 Ops = {SrcReg, LineReg, ColReg, *Parent.Value, NameReg};
1192 return EmitResult<PreparedScope>::emitted(
1193 PreparedScope{SPIRV::NonSemanticExtInst::DebugLexicalBlock,
Ops});
1196auto SPIRVNonSemanticDebugHandler::emitDebugLexicalBlockDiscriminator(
1200 assert(LBF &&
"LBF must not be null");
1201 EmitResult<MCRegister> Parent =
resolveScope(LBF->getScope());
1203 return EmitResult<PreparedScope>::failure(Parent);
1205 MCRegister FileStrReg = getCachedScopePathOpStringReg(
1206 LBF->getFile(),
true);
1207 MCRegister SrcReg = getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg,
1208 ExtInstSetReg, MAI);
1210 static_cast<uint32_t
>(LBF->getDiscriminator()), I32TypeReg, MAI);
1211 return EmitResult<PreparedScope>::emitted(
1212 PreparedScope{SPIRV::NonSemanticExtInst::DebugLexicalBlockDiscriminator,
1213 {SrcReg, DiscReg, *Parent.Value}});
1216MCRegister SPIRVNonSemanticDebugHandler::getOrEmitDebugInlinedAt(
1219 assert(IA &&
"IA must not be null in getOrEmitDebugInlinedAt");
1221 if (MCRegister Cached = DebugInlinedAtRegs.lookup(IA))
1224 EmitResult<MCRegister>
Scope = resolveScope(
IA->getScope());
1226 return MCRegister();
1228 MCRegister LineReg =
1229 emitOpConstantI32(
static_cast<uint32_t
>(
IA->getLine()), I32TypeReg, MAI);
1234 if (
const DILocation *Outer =
IA->getInlinedAt()) {
1235 MCRegister OuterReg = getOrEmitDebugInlinedAt(
1236 Outer, VoidTypeReg, I32TypeReg, ExtInstSetReg, MAI);
1238 return MCRegister();
1239 Ops.push_back(OuterReg);
1242 MCRegister
Reg = emitExtInst(SPIRV::NonSemanticExtInst::DebugInlinedAt,
1243 VoidTypeReg, ExtInstSetReg,
Ops, MAI);
1244 DebugInlinedAtRegs[
IA] =
Reg;
1248auto SPIRVNonSemanticDebugHandler::emitDebugFunctionDeclaration(
1251 -> EmitResult<PreparedScope> {
1252 assert(SP &&
"SP must not be null in emitDebugFunctionDeclaration");
1254 "SP must not be a definition in emitDebugFunctionDeclaration");
1257 EmitResult<MCRegister> FnTy = getOrCreateDebugScope(
SP->getType());
1259 return EmitResult<PreparedScope>::failure(FnTy);
1261 EmitResult<MCRegister> Parent =
resolveScope(
SP->getScope(),
SP->getUnit());
1263 return EmitResult<PreparedScope>::failure(Parent);
1265 MCRegister FileStrReg = getCachedScopePathOpStringReg(SP);
1267 MCRegister NameReg = getCachedOpStringReg(
SP->getName());
1268 MCRegister LinkageReg = getCachedOpStringReg(
SP->getLinkageName());
1269 MCRegister SrcReg = getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg,
1270 ExtInstSetReg, MAI);
1273 emitOpConstantI32(
static_cast<uint32_t
>(
SP->getLine()), I32TypeReg, MAI);
1274 MCRegister ColReg = emitOpConstantI32(0, I32TypeReg, MAI);
1276 uint32_t FlagsVal = transDebugFlags(SP);
1279 FlagsVal &= ~NSDIFlagIsDefinition;
1280 MCRegister FlagsReg = emitOpConstantI32(FlagsVal, I32TypeReg, MAI);
1282 return EmitResult<PreparedScope>::emitted(
1283 PreparedScope{SPIRV::NonSemanticExtInst::DebugFunctionDeclaration,
1284 {NameReg, *FnTy.Value, SrcReg, LineReg, ColReg,
1285 *Parent.Value, LinkageReg, FlagsReg}});
1288auto SPIRVNonSemanticDebugHandler::emitDebugFunction(
1291 -> EmitResult<PreparedScope> {
1292 assert(SP &&
"SP must not be null in emitDebugFunction");
1293 assert(
SP->isDefinition() &&
"SP must be a definition in emitDebugFunction");
1295 EmitResult<MCRegister> FnTy = getOrCreateDebugScope(
SP->getType());
1297 return EmitResult<PreparedScope>::failure(FnTy);
1299 EmitResult<MCRegister> Parent =
resolveScope(
SP->getScope(),
SP->getUnit());
1301 return EmitResult<PreparedScope>::failure(Parent);
1303 MCRegister NameReg = getCachedOpStringReg(
SP->getName());
1304 MCRegister LinkageReg = getCachedOpStringReg(
SP->getLinkageName());
1305 MCRegister FileStrReg = getCachedScopePathOpStringReg(SP);
1306 MCRegister SrcReg = getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg,
1307 ExtInstSetReg, MAI);
1310 emitOpConstantI32(
static_cast<uint32_t
>(
SP->getLine()), I32TypeReg, MAI);
1313 MCRegister ColReg = emitOpConstantI32(0, I32TypeReg, MAI);
1314 MCRegister FlagsReg = emitOpConstantI32(transDebugFlags(SP), I32TypeReg, MAI);
1316 static_cast<uint32_t
>(
SP->getScopeLine()), I32TypeReg, MAI);
1319 LineReg, ColReg, *Parent.Value,
1320 LinkageReg, FlagsReg, ScopeLineReg};
1323 EmitResult<MCRegister> DeclRes = getOrCreateDebugScope(Decl);
1325 Ops.push_back(*DeclRes.Value);
1328 return EmitResult<PreparedScope>::emitted(
1329 PreparedScope{SPIRV::NonSemanticExtInst::DebugFunction,
Ops});
1332auto SPIRVNonSemanticDebugHandler::mapDISignatureTypeToReg(
1334 -> EmitResult<MCRegister> {
1335 if (!Ty && ReturnType)
1336 return EmitResult<MCRegister>::emitted(VoidTypeReg);
1337 return getOrCreateDebugTypeOrNone(Ty);
1355static std::optional<NonSemanticDebugOp>
1358 case dwarf::DW_OP_deref:
1360 case dwarf::DW_OP_plus:
1362 case dwarf::DW_OP_minus:
1364 case dwarf::DW_OP_plus_uconst:
1366 case dwarf::DW_OP_bit_piece:
1368 case dwarf::DW_OP_swap:
1370 case dwarf::DW_OP_xderef:
1372 case dwarf::DW_OP_stack_value:
1374 case dwarf::DW_OP_constu:
1379 return std::nullopt;
1385static std::optional<SmallVector<uint32_t, 3>>
1387 std::optional<NonSemanticDebugOp> NSOp =
1390 return std::nullopt;
1393 for (
unsigned I = 0,
E =
Op.getNumArgs();
I !=
E; ++
I) {
1396 return std::nullopt;
1402std::optional<MCRegister> SPIRVNonSemanticDebugHandler::emitDebugOperation(
1408 return std::nullopt;
1410 auto [It,
Inserted] = DebugOperationCache.try_emplace(std::move(*
Key));
1415 for (uint32_t
V : It->first)
1416 Operands.push_back(emitOpConstantI32(
V, I32TypeReg, MAI));
1417 MCRegister
Reg = emitExtInst(SPIRV::NonSemanticExtInst::DebugOperation,
1418 VoidTypeReg, ExtInstSetReg,
Operands, MAI);
1423std::optional<MCRegister> SPIRVNonSemanticDebugHandler::emitDebugExpression(
1426 assert(Expr &&
"Expr must not be null in emitDebugExpression");
1429 for (
const DIExpression::ExprOperand &
Op : Expr->
expr_ops()) {
1430 std::optional<MCRegister> OpReg =
1431 emitDebugOperation(
Op, VoidTypeReg, I32TypeReg, ExtInstSetReg, MAI);
1433 return std::nullopt;
1438 DebugExpressionCache.try_emplace(std::move(OperationRegs));
1442 MCRegister
Reg = emitExtInst(SPIRV::NonSemanticExtInst::DebugExpression,
1443 VoidTypeReg, ExtInstSetReg, It->first, MAI);
1448std::optional<MCRegister> SPIRVNonSemanticDebugHandler::emitDebugGlobalVariable(
1452 assert(GV &&
"GV must not be null in emitDebugGlobalVariable");
1454 EmitResult<MCRegister> Parent = resolveScope(GV->
getScope());
1456 return std::nullopt;
1458 MCRegister ParentReg = *Parent.Value;
1464 MCRegister TyReg = CachedDebugInfoNoneReg;
1465 if (
const DIType *Ty = GV->
getType()) {
1466 auto TyRegOpt = lookupOptReg(DebugScopeRegs, Ty);
1468 return std::nullopt;
1472 std::optional<MCRegister> StaticMemberRegOpt;
1475 StaticMemberRegOpt = lookupOptReg(DebugScopeRegs, SM);
1476 if (!StaticMemberRegOpt)
1477 return std::nullopt;
1480 MCRegister NameReg = getCachedOpStringReg(GV->
getName());
1481 MCRegister LinkageReg = getCachedOpStringReg(GV->
getLinkageName());
1482 MCRegister FileStrReg = getCachedScopePathOpStringReg(
1484 MCRegister SrcReg = getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg,
1485 ExtInstSetReg, MAI);
1487 MCRegister LineReg =
1488 emitOpConstantI32(
static_cast<uint32_t
>(GV->
getLine()), I32TypeReg, MAI);
1492 MCRegister ColReg = emitOpConstantI32(0, I32TypeReg, MAI);
1499 MCRegister VariableReg = CachedDebugInfoNoneReg;
1500 if (
const GlobalVariable *LLVMGV =
Info.LLVMGV) {
1503 VariableReg = GVReg;
1504 }
else if (
Info.Expr &&
Info.Expr->getNumElements() != 0) {
1505 if (
auto ExprReg = emitDebugExpression(
Info.Expr, VoidTypeReg, I32TypeReg,
1506 ExtInstSetReg, MAI))
1507 VariableReg = *ExprReg;
1510 MCRegister FlagsReg = emitOpConstantI32(transDebugFlags(GV), I32TypeReg, MAI);
1513 LineReg, ColReg, ParentReg,
1514 LinkageReg, VariableReg, FlagsReg};
1516 if (StaticMemberRegOpt)
1517 Ops.push_back(*StaticMemberRegOpt);
1519 return emitExtInst(SPIRV::NonSemanticExtInst::DebugGlobalVariable,
1520 VoidTypeReg, ExtInstSetReg,
Ops, MAI);
1523std::optional<MCRegister> SPIRVNonSemanticDebugHandler::emitDebugLocalVariable(
1526 assert(LV &&
"LV must not be null in emitDebugLocalVariable");
1528 EmitResult<MCRegister> Parent = resolveScope(LV->
getScope());
1530 return std::nullopt;
1532 MCRegister TyReg = CachedDebugInfoNoneReg;
1533 if (
const DIType *Ty = LV->
getType()) {
1534 auto TyRegOpt = lookupOptReg(DebugScopeRegs, Ty);
1536 return std::nullopt;
1540 MCRegister NameReg = getCachedOpStringReg(LV->
getName());
1541 MCRegister FileStrReg = getCachedScopePathOpStringReg(
1543 MCRegister SrcReg = getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg,
1544 ExtInstSetReg, MAI);
1545 MCRegister LineReg =
1546 emitOpConstantI32(
static_cast<uint32_t
>(LV->
getLine()), I32TypeReg, MAI);
1548 MCRegister ColReg = emitOpConstantI32(0, I32TypeReg, MAI);
1549 MCRegister FlagsReg = emitOpConstantI32(transDebugFlags(LV), I32TypeReg, MAI);
1552 ColReg, *Parent.Value, FlagsReg};
1553 if (
unsigned Arg = LV->
getArg())
1554 Ops.push_back(emitOpConstantI32(Arg, I32TypeReg, MAI));
1556 return emitExtInst(SPIRV::NonSemanticExtInst::DebugLocalVariable, VoidTypeReg,
1557 ExtInstSetReg,
Ops, MAI);
1560auto SPIRVNonSemanticDebugHandler::emitDebugTypeVector(
1562 -> EmitResult<PreparedScope> {
1565 return EmitResult<PreparedScope>::unsupported();
1569 DINodeArray
Elements = VT->getElements();
1571 return EmitResult<PreparedScope>::unsupported();
1575 return EmitResult<PreparedScope>::unsupported();
1577 EmitResult<MCRegister>
Base = getOrCreateDebugScope(BaseTy);
1579 return EmitResult<PreparedScope>::failure(
Base);
1581 MCRegister I32TypeReg = getOrEmitOpTypeInt32Reg(MAI);
1583 static_cast<uint32_t
>(CI->getZExtValue()), I32TypeReg, MAI);
1584 return EmitResult<PreparedScope>::emitted(PreparedScope{
1585 SPIRV::NonSemanticExtInst::DebugTypeVector, {*
Base.Value, CountReg}});
1588auto SPIRVNonSemanticDebugHandler::emitDebugTypeArray(
1590 -> EmitResult<PreparedScope> {
1593 EmitResult<MCRegister>
Base = getOrCreateDebugScope(AT->getBaseType());
1595 return EmitResult<PreparedScope>::failure(
Base);
1597 MCRegister I32TypeReg = getOrEmitOpTypeInt32Reg(MAI);
1605 for (
const DINode *Element : AT->getElements()) {
1617 if (
Value.getActiveBits() <= 32)
1618 Count =
static_cast<uint32_t
>(
Value.getZExtValue());
1620 Ops.push_back(emitOpConstantI32(
Count, I32TypeReg, MAI));
1623 return EmitResult<PreparedScope>::emitted(
1624 PreparedScope{SPIRV::NonSemanticExtInst::DebugTypeArray,
Ops});
1627auto SPIRVNonSemanticDebugHandler::emitDebugTypeMember(
1630 -> EmitResult<PreparedScope> {
1631 EmitResult<MCRegister> Ty = getOrCreateDebugScope(
M->getBaseType());
1633 return EmitResult<PreparedScope>::failure(Ty);
1636 return EmitResult<PreparedScope>::unsupported();
1638 MCRegister NameReg = getCachedOpStringReg(
M->getName());
1639 MCRegister FileStrReg = getCachedScopePathOpStringReg(
1640 M->getFile(),
true);
1641 MCRegister SrcReg = getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg,
1642 ExtInstSetReg, MAI);
1644 emitOpConstantI32(
static_cast<uint32_t
>(
M->getLine()), I32TypeReg, MAI);
1647 MCRegister ColReg = emitOpConstantI32(0, I32TypeReg, MAI);
1649 static_cast<uint32_t
>(
M->getOffsetInBits()), I32TypeReg, MAI);
1651 static_cast<uint32_t
>(
M->getSizeInBits()), I32TypeReg, MAI);
1652 MCRegister FlagsReg = emitOpConstantI32(transDebugFlags(M), I32TypeReg, MAI);
1663 return EmitResult<PreparedScope>::emitted(
1664 PreparedScope{SPIRV::NonSemanticExtInst::DebugTypeMember,
1665 {NameReg, *Ty.Value, SrcReg, LineReg, ColReg, OffsetReg,
1666 SizeReg, FlagsReg}});
1669auto SPIRVNonSemanticDebugHandler::emitDebugTypeComposite(
1672 -> EmitResult<PreparedScope> {
1675 EmitResult<MCRegister> Parent =
resolveScope(CT->getScope());
1677 return EmitResult<PreparedScope>::failure(Parent);
1680 return EmitResult<PreparedScope>::unsupported();
1683 for (
const DINode *Element : CT->getElements()) {
1685 if (!M ||
M->getTag() != dwarf::DW_TAG_member)
1687 EmitResult<MCRegister>
Member = getOrCreateDebugScope(M);
1692 MCRegister NameReg = getCachedOpStringReg(CT->getName());
1693 MCRegister LinkageReg = getCachedOpStringReg(CT->getIdentifier());
1694 MCRegister FileStrReg = getCachedScopePathOpStringReg(
1695 CT->getFile(),
true);
1696 MCRegister SrcReg = getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg,
1697 ExtInstSetReg, MAI);
1700 emitOpConstantI32(mapCompositeTypeTag(CT->getTag()), I32TypeReg, MAI);
1702 emitOpConstantI32(
static_cast<uint32_t
>(CT->getLine()), I32TypeReg, MAI);
1703 MCRegister ColReg = emitOpConstantI32(0, I32TypeReg, MAI);
1707 if (!CT->isForwardDecl())
1708 SizeReg = emitOpConstantI32(
static_cast<uint32_t
>(CT->getSizeInBits()),
1711 MCRegister FlagsReg = emitOpConstantI32(transDebugFlags(CT), I32TypeReg, MAI);
1714 LineReg, ColReg, *Parent.Value,
1715 LinkageReg, SizeReg, FlagsReg};
1717 return EmitResult<PreparedScope>::emitted(
1718 PreparedScope{SPIRV::NonSemanticExtInst::DebugTypeComposite,
Ops});
1721auto SPIRVNonSemanticDebugHandler::emitDebugTypeEnum(
1724 -> EmitResult<PreparedScope> {
1728 return EmitResult<PreparedScope>::unsupported();
1731 getOrCreateDebugTypeOrNone(ET->getBaseType());
1733 return EmitResult<PreparedScope>::failure(Underlying);
1735 EmitResult<MCRegister> Parent =
1736 resolveScope(ET->getScope(), EnumCompileUnits.lookup(ET));
1738 return EmitResult<PreparedScope>::failure(Parent);
1740 MCRegister NameReg = getCachedOpStringReg(ET->getName());
1741 MCRegister FileStrReg = getCachedScopePathOpStringReg(
1742 ET->getFile(),
true);
1743 MCRegister SrcReg = getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg,
1744 ExtInstSetReg, MAI);
1746 emitOpConstantI32(
static_cast<uint32_t
>(ET->getLine()), I32TypeReg, MAI);
1748 MCRegister ColReg = emitOpConstantI32(0, I32TypeReg, MAI);
1750 emitOpConstantI32(
static_cast<uint32_t
>(
Size), I32TypeReg, MAI);
1751 MCRegister FlagsReg = emitOpConstantI32(transDebugFlags(ET), I32TypeReg, MAI);
1754 ColReg, *Parent.Value, SizeReg, FlagsReg};
1759 for (
const DINode *Element : ET->getElements()) {
1764 if (
E->isUnsigned() ? !
Value.isIntN(32) : !
Value.isSignedIntN(32))
1766 uint32_t
Bits =
E->isUnsigned()
1767 ?
static_cast<uint32_t
>(
Value.getZExtValue())
1768 :
static_cast<uint32_t
>(
Value.getSExtValue());
1769 Ops.push_back(emitOpConstantI32(Bits, I32TypeReg, MAI));
1770 Ops.push_back(getCachedOpStringReg(
E->getName()));
1773 return EmitResult<PreparedScope>::emitted(
1774 PreparedScope{SPIRV::NonSemanticExtInst::DebugTypeEnum,
Ops});
1777auto SPIRVNonSemanticDebugHandler::emitDebugTypedef(
1780 -> EmitResult<PreparedScope> {
1781 EmitResult<MCRegister>
Base = getOrCreateDebugTypeOrNone(TD->getBaseType());
1783 return EmitResult<PreparedScope>::failure(
Base);
1785 MCRegister NameReg = getCachedOpStringReg(TD->getName());
1786 MCRegister FileStrReg = getCachedScopePathOpStringReg(
1787 TD->getFile(),
true);
1788 MCRegister SrcReg = getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg,
1789 ExtInstSetReg, MAI);
1791 emitOpConstantI32(
static_cast<uint32_t
>(TD->getLine()), I32TypeReg, MAI);
1793 MCRegister ColReg = emitOpConstantI32(0, I32TypeReg, MAI);
1798 EmitResult<MCRegister> Parent =
resolveScope(TD->getScope());
1800 return EmitResult<PreparedScope>::failure(Parent);
1802 return EmitResult<PreparedScope>::emitted(PreparedScope{
1803 SPIRV::NonSemanticExtInst::DebugTypedef,
1804 {NameReg, *
Base.Value, SrcReg, LineReg, ColReg, *Parent.Value}});
1809 if (GlobalDIEmitted)
1811 GlobalDIEmitted =
true;
1813 if (CompileUnits.empty())
1821 generateDebugStrings(MAI);
1822 generateGlobalDebugInfo(MAI);
1824 if (UsedForwardRefs)
1826 SPIRV::Extension::SPV_KHR_relaxed_extended_instruction);
1831 flushPendingInsts(PendingStrings);
1836 flushPendingInsts(PendingGlobalDI);
1839void SPIRVNonSemanticDebugHandler::generateDebugStrings(
1842 for (
const CompileUnitInfo &Info : CompileUnits) {
1844 MCRegister PathReg = emitOpStringIfNew(Info.FilePath, MAI);
1845 ScopeToPathOpStringReg[Info.TheCU] = PathReg;
1846 if (
const DIFile *
F = Info.TheCU->getFile())
1847 ScopeToPathOpStringReg[
F] = PathReg;
1851 for (
const DISubprogram *SP : Subprograms) {
1852 emitOpStringIfNew(
SP->getName(), MAI);
1853 emitOpStringIfNew(
SP->getLinkageName(), MAI);
1854 emitAndCacheScopePathOpStringReg(SP, MAI);
1857 for (
const DIType *Ty : DebugTypes) {
1859 emitOpStringIfNew(
BT->getName(), MAI);
1865 if (CT->getTag() == dwarf::DW_TAG_enumeration_type) {
1866 emitOpStringIfNew(CT->getName(), MAI);
1867 emitAndCacheScopePathOpStringReg(CT->getFile(), MAI);
1868 for (
const DINode *Element : CT->getElements())
1870 emitOpStringIfNew(
E->getName(), MAI);
1876 if (CT->getTag() != dwarf::DW_TAG_structure_type &&
1877 CT->getTag() != dwarf::DW_TAG_class_type &&
1878 CT->getTag() != dwarf::DW_TAG_union_type)
1880 emitOpStringIfNew(CT->getName(), MAI);
1881 emitOpStringIfNew(CT->getIdentifier(), MAI);
1882 emitAndCacheScopePathOpStringReg(CT->getFile(), MAI);
1883 for (
const DINode *Element : CT->getElements()) {
1885 if (!M ||
M->getTag() != dwarf::DW_TAG_member)
1887 emitOpStringIfNew(
M->getName(), MAI);
1888 emitAndCacheScopePathOpStringReg(
M->getFile(), MAI);
1894 if (TD && TD->getTag() == dwarf::DW_TAG_typedef) {
1895 emitOpStringIfNew(TD->getName(), MAI);
1896 emitAndCacheScopePathOpStringReg(TD->getFile(), MAI);
1900 for (
const auto &[GV,
_] : GlobalVariableDebugInfoMap) {
1901 emitOpStringIfNew(GV->
getName(), MAI);
1903 emitAndCacheScopePathOpStringReg(GV->
getFile(), MAI);
1906 for (
const DILocalVariable *LV : LocalVariables) {
1907 emitOpStringIfNew(LV->
getName(), MAI);
1908 emitAndCacheScopePathOpStringReg(LV->
getFile(), MAI);
1911 for (
const DIScope *S : LexicalBlocks) {
1912 emitAndCacheScopePathOpStringReg(S->getFile(), MAI);
1914 emitOpStringIfNew(NS->getName(), MAI);
1917 for (
const DILocation *
DL : UniqueDebugLocations)
1918 emitAndCacheScopePathOpStringReg(
DL->getScope(), MAI);
1920 CachedEmptyStringReg = emitOpStringIfNew(
"", MAI);
1923 DebugStringsGenerated =
true;
1927void SPIRVNonSemanticDebugHandler::emitDebugFunctionDefinition(
1931 "DebugFunctionDefinition operands must be valid");
1932 MCRegister VoidTypeReg = getOrEmitOpTypeVoidReg(MAI);
1934 emitExtInst(SPIRV::NonSemanticExtInst::DebugFunctionDefinition, VoidTypeReg,
1935 ExtInstSetReg, {DebugFunctionReg, OpFunctionReg}, MAI);
1938void SPIRVNonSemanticDebugHandler::resetPerFunctionDebugState() {
1939 CurrentMF =
nullptr;
1940 LastFunctionOpVariable =
nullptr;
1941 DebugFunctionDefinitionEmitted =
false;
1942 LastLineMI =
nullptr;
1943 LastScopeMI =
nullptr;
1947void SPIRVNonSemanticDebugHandler::preparePerFunctionDebug(
1949 resetPerFunctionDebugState();
1950 if (!GlobalNSDIEnabled || !CurrentMAI)
1961 if (!SP || !
SP->isDefinition())
1967 LastFunctionOpVariable =
1968 findLastFunctionOpVariableDeclaration(*MF, *CurrentMAI);
1970 analyzeDebugRecords(*MF);
1973void SPIRVNonSemanticDebugHandler::tryEmitDebugFunctionDefinition(
1975 if (DebugFunctionDefinitionEmitted || !GlobalNSDIEnabled)
1978 assert(CurrentMF &&
"no current MachineFunction");
1979 const Function &
F = CurrentMF->getFunction();
1980 const DISubprogram *
SP =
F.getSubprogram();
1981 if (!SP || !
SP->isDefinition())
1984 auto DFIt = DebugScopeRegs.find(SP);
1985 if (DFIt == DebugScopeRegs.end())
1992 emitDebugFunctionDefinition(DFIt->second, OpFunctionReg, MAI);
1993 DebugFunctionDefinitionEmitted =
true;
1998 preparePerFunctionDebug(MF);
2003 resetPerFunctionDebugState();
2010 if (!DebugFunctionDefinitionEmitted)
2013 emitAnalyzedRecords(
MI);
2015 std::optional<const MachineInstr *>
Target = resolveDebugLocTarget(
MI);
2019 (void)emitDebugScopeForInstruction(*
Target);
2020 emitDebugLineForInstruction(*
Target);
2031static std::optional<Register>
2035 if (!
MI.isIndirectDebugValue())
2036 return std::nullopt;
2040 Register LocReg =
MI.getDebugOperand(0).getReg();
2042 return std::nullopt;
2053 const MachineInstr *Def =
MI.getMF()->getRegInfo().getUniqueVRegDef(LocReg);
2054 if (!Def || (Def->getOpcode() != SPIRV::OpVariable &&
2055 !(AllowUntypedVariable &&
2056 Def->getOpcode() == SPIRV::OpUntypedVariableKHR)))
2057 return std::nullopt;
2062void SPIRVNonSemanticDebugHandler::emitDebugBinding(
2063 SPIRV::NonSemanticExtInst::NonSemanticExtInst Opcode,
2065 assert(DebugFunctionDefinitionEmitted &&
2066 "DebugFunctionDefinition must be emitted");
2067 assert(CurrentMAI &&
"CurrentMAI must be set");
2069 auto VarRegOpt = lookupOptReg(DebugLocalVariableRegs,
MI->getDebugVariable());
2073 auto ExprRegOpt = lookupOptReg(DebugExpressionRegs,
MI->getDebugExpression());
2077 if (!emitDebugScopeForInstruction(
MI))
2079 emitDebugLineForInstruction(
MI);
2081 SPIRV::ModuleAnalysisInfo &MAI = *CurrentMAI;
2082 MCRegister VoidTypeReg = getOrEmitOpTypeVoidReg(MAI);
2084 emitExtInst(Opcode, VoidTypeReg, ExtInstSetReg,
2085 {*VarRegOpt, LocationReg, *ExprRegOpt}, MAI);
2090static std::optional<std::pair<const DIBasicType *, uint64_t>>
2092 if (!
MI.isNonListDebugValue() ||
MI.isIndirectDebugValue())
2093 return std::nullopt;
2097 return std::nullopt;
2102 return std::nullopt;
2107 else if (
Value.isCImm())
2111 return std::make_pair(
BT, Bits);
2114std::optional<MCRegister> SPIRVNonSemanticDebugHandler::getConstantValueReg(
2116 std::optional<std::pair<const DIBasicType *, uint64_t>>
Const =
2119 return std::nullopt;
2121 auto It = ConstantValueRegs.find(*Const);
2122 if (It == ConstantValueRegs.end() || !It->second.isValid())
2123 return std::nullopt;
2128 if (!
MI.isNonListDebugValue() ||
MI.isIndirectDebugValue())
2129 return std::nullopt;
2133 return std::nullopt;
2137 return std::nullopt;
2139 const MachineInstr *Def =
MI.getMF()->getRegInfo().getUniqueVRegDef(ValueReg);
2140 if (!Def || (Def->isPseudo() && !Def->isPHI()) || Def->isMetaInstruction() ||
2141 Def->getNumOperands() == 0 || !Def->getOperand(0).isReg() ||
2142 !Def->getOperand(0).isDef() || Def->getOperand(0).getReg() != ValueReg)
2143 return std::nullopt;
2149 return Opcode == SPIRV::OpSelectionMerge || Opcode == SPIRV::OpLoopMerge ||
2150 Opcode == SPIRV::OpLoopControlINTEL;
2162 switch (
MI->getOpcode()) {
2163 case SPIRV::OpFunction:
2164 case SPIRV::OpFunctionParameter:
2165 case SPIRV::OpFunctionEnd:
2166 case SPIRV::OpLabel:
2167 case TargetOpcode::PHI:
2178 :
MI->getPrevNode();
2179 Adj; Adj = Forward ? Adj->getNextNode() : Adj->getPrevNode()) {
2187std::optional<const MachineInstr *>
2188SPIRVNonSemanticDebugHandler::resolveDebugLocTarget(
const MachineInstr *
MI) {
2189 assert(CurrentMAI &&
"CurrentMAI must be set");
2190 SPIRV::ModuleAnalysisInfo &MAI = *CurrentMAI;
2195 return std::nullopt;
2203 return std::nullopt;
2209 assert(
MI &&
"Merge instruction must be followed by a terminator");
2213 return std::nullopt;
2219void SPIRVNonSemanticDebugHandler::resolveDebugRecord(
2222 SPIRV::ModuleAnalysisInfo &MAI = *CurrentMAI;
2228 const MachineInstr *Anchor =
2235 if (std::optional<Register> LocReg =
2239 placeRecord(SPIRV::NonSemanticExtInst::DebugDeclare,
MI, StorageReg,
2244 if (std::optional<MCRegister> ConstReg = getConstantValueReg(
MI)) {
2245 placeRecord(SPIRV::NonSemanticExtInst::DebugValue,
MI, *ConstReg, Anchor);
2265 if (ModuleScopeIds.contains(ValueReg) ||
2267 placeRecord(SPIRV::NonSemanticExtInst::DebugValue,
MI, ValueReg, Anchor);
2270void SPIRVNonSemanticDebugHandler::analyzeDebugRecords(
2272 assert(CurrentMAI &&
"CurrentMAI must be set");
2276 std::optional<MachineDominatorTree> DomTree;
2278 for (
const MachineBasicBlock &
MBB : MF) {
2279 const MachineInstr *LastEmitted =
nullptr;
2280 for (
const MachineInstr &
MI :
MBB) {
2281 if (
MI.isDebugValueLike()) {
2284 resolveDebugRecord(
MI, LastEmitted, *DomTree);
2293void SPIRVNonSemanticDebugHandler::placeRecord(
2294 SPIRV::NonSemanticExtInst::NonSemanticExtInst Opcode,
2297 Records[Anchor].push_back({&
MI, Opcode, LocationReg});
2300void SPIRVNonSemanticDebugHandler::emitAnalyzedRecords(
2302 auto It = Records.find(Anchor);
2303 if (It == Records.end())
2305 for (
const DebugRecord &R : It->second)
2306 emitDebugBinding(
R.Opcode,
R.MI,
R.LocationReg);
2309bool SPIRVNonSemanticDebugHandler::emitDebugScopeForInstruction(
2311 assert(DebugFunctionDefinitionEmitted &&
2312 "DebugFunctionDefinition must be emitted");
2313 assert(CurrentMAI &&
"CurrentMAI must be set");
2318 if (LastScopeMI &&
MI->getParent() != LastScopeMI->getParent())
2319 LastScopeMI =
nullptr;
2321 SPIRV::ModuleAnalysisInfo &MAI = *CurrentMAI;
2322 MCRegister VoidTypeReg = getOrEmitOpTypeVoidReg(MAI);
2325 const DILocation *CurDL =
MI->getDebugLoc().get();
2330 emitExtInst(SPIRV::NonSemanticExtInst::DebugNoScope, VoidTypeReg,
2331 ExtInstSetReg, {}, MAI);
2332 LastScopeMI =
nullptr;
2337 const DIScope *CurScope = CurDL->getScope();
2338 const DILocation *CurInlinedAt = CurDL->getInlinedAt();
2341 const DILocation *LastDL = LastScopeMI->getDebugLoc().get();
2342 if (LastDL->getScope() == CurScope &&
2343 LastDL->getInlinedAt() == CurInlinedAt)
2347 EmitResult<MCRegister> CurScopeRes = resolveScope(CurScope);
2354 MCRegister InlinedReg = DebugInlinedAtRegs.lookup(CurInlinedAt);
2357 Ops.push_back(InlinedReg);
2361 emitExtInst(SPIRV::NonSemanticExtInst::DebugScope, VoidTypeReg, ExtInstSetReg,
2368void SPIRVNonSemanticDebugHandler::emitDebugLineForInstruction(
2370 assert(DebugFunctionDefinitionEmitted &&
2371 "DebugFunctionDefinition must be emitted");
2372 assert(CurrentMAI &&
"CurrentMAI must be set");
2377 if (LastLineMI &&
MI->getParent() != LastLineMI->getParent())
2378 LastLineMI =
nullptr;
2380 SPIRV::ModuleAnalysisInfo &MAI = *CurrentMAI;
2381 MCRegister VoidTypeReg = getOrEmitOpTypeVoidReg(MAI);
2384 const DILocation *
DL =
MI->getDebugLoc().get();
2389 emitExtInst(SPIRV::NonSemanticExtInst::DebugNoLine, VoidTypeReg,
2390 ExtInstSetReg, {}, MAI);
2391 LastLineMI =
nullptr;
2401 MCRegister FileStrReg = getCachedScopePathOpStringReg(
2402 DL->getScope(),
true);
2403 unsigned Line =
DL->getLine();
2404 unsigned Col =
DL->getColumn();
2406 unsigned I32TypeId = CachedOpTypeInt32Reg.id();
2407 MCRegister SrcReg = DebugSourceRegByFileStr.lookup(FileStrReg.
id());
2408 MCRegister LineReg = ScalarConstantCache.lookup({I32TypeId,
Line});
2409 MCRegister ColStartReg = ScalarConstantCache.lookup({I32TypeId, Col});
2410 MCRegister ColEndReg = ScalarConstantCache.lookup({I32TypeId, Col + 1});
2422 if (LastLineMI &&
MI->getDebugLoc() == LastLineMI->getDebugLoc())
2426 emitExtInst(SPIRV::NonSemanticExtInst::DebugLine, VoidTypeReg, ExtInstSetReg,
2427 {SrcReg, LineReg, LineReg, ColStartReg, ColEndReg}, MAI);
2436 if (!
MI || !GlobalNSDIEnabled || !CurrentMF)
2439 if (DebugFunctionDefinitionEmitted ||
MI != LastFunctionOpVariable)
2445 assert(CurrentMAI &&
"CurrentMAI must be set");
2446 tryEmitDebugFunctionDefinition(*CurrentMAI);
2451 if (!GlobalNSDIEnabled || DebugFunctionDefinitionEmitted || !CurrentMF)
2454 assert(CurrentMF == &MF &&
2455 "notification does not match the current MachineFunction");
2457 if (LastFunctionOpVariable)
2463 tryEmitDebugFunctionDefinition(*CurrentMAI);
2466void SPIRVNonSemanticDebugHandler::collectDebugExpressions(
2470 Out.insert(
MI->getDebugExpression());
2473void SPIRVNonSemanticDebugHandler::generateGlobalDebugInfo(
2478 assert(ExtInstSetReg.
isValid() &&
"NSDI ext inst set must be registered");
2481 assert(DebugStringsGenerated &&
2482 "generateDebugStrings() must run before generateGlobalDebugInfo()");
2487 MCRegister VoidTypeReg = getOrEmitOpTypeVoidReg(MAI);
2488 MCRegister I32TypeReg = getOrEmitOpTypeInt32Reg(MAI);
2490 CachedDebugInfoNoneReg = emitExtInst(SPIRV::NonSemanticExtInst::DebugInfoNone,
2491 VoidTypeReg, ExtInstSetReg, {}, MAI);
2503 MCRegister DebugInfoVersionReg = emitOpConstantI32(100, I32TypeReg, MAI);
2504 MCRegister DwarfVersionReg =
2505 emitOpConstantI32(
static_cast<uint32_t
>(DwarfVersion), I32TypeReg, MAI);
2510 map_to_vector(CompileUnits, [&](
const CompileUnitInfo &Info) {
2511 return emitOpConstantI32(
Info.SpirvSourceLanguage, I32TypeReg, MAI);
2515 for (
auto [Info, SrcLangReg] :
llvm::zip(CompileUnits, SrcLangRegs)) {
2516 MCRegister FileStrReg = ScopeToPathOpStringReg.lookup(
Info.TheCU);
2518 "CU path OpString must be emitted in generateDebugStrings");
2519 MCRegister DebugSourceReg = getOrEmitDebugSourceForFileStrReg(
2520 FileStrReg, VoidTypeReg, ExtInstSetReg, MAI);
2521 MCRegister CUDbgReg = emitExtInst(
2522 SPIRV::NonSemanticExtInst::DebugCompilationUnit, VoidTypeReg,
2524 {DebugInfoVersionReg, DwarfVersionReg, DebugSourceReg, SrcLangReg},
2527 DebugScopeRegs[
Info.TheCU] = CUDbgReg;
2530 for (
const DIScope *S :
2532 getOrCreateDebugScope(S);
2536 for (
const DILocalVariable *LV : LocalVariables)
2537 if (
auto LVReg = emitDebugLocalVariable(LV, VoidTypeReg, I32TypeReg,
2538 ExtInstSetReg, MAI))
2539 DebugLocalVariableRegs[LV] = *LVReg;
2545 SetVector<const DIExpression *> Expressions;
2546 collectDebugExpressions(MAI, Expressions);
2547 for (
const DIExpression *Expr : Expressions)
2548 if (
auto ExprReg = emitDebugExpression(Expr, VoidTypeReg, I32TypeReg,
2549 ExtInstSetReg, MAI))
2550 DebugExpressionRegs[Expr] = *ExprReg;
2553 for (
const auto &[GV, Info] : GlobalVariableDebugInfoMap)
2554 emitDebugGlobalVariable(GV, Info, VoidTypeReg, I32TypeReg, ExtInstSetReg,
2558 for (
const DILocation *
DL : UniqueDebugLocations)
2559 if (
const DILocation *IA =
DL->getInlinedAt())
2560 getOrEmitDebugInlinedAt(IA, VoidTypeReg, I32TypeReg, ExtInstSetReg, MAI);
2565 std::optional<std::pair<const DIBasicType *, uint64_t>>
Const =
2569 if (!DebugLocalVariableRegs.contains(
MI->getDebugVariable()) ||
2570 !DebugExpressionRegs.contains(
MI->getDebugExpression()))
2572 auto [It,
Inserted] = ConstantValueRegs.try_emplace(*Const, MCRegister());
2574 It->second = findOrEmitScalarConstant(
Const->first,
Const->second, MAI);
2575 if (!It->second.isValid())
2576 ConstantValueRegs.erase(It);
2579 for (
const DILocation *
DL : UniqueDebugLocations) {
2580 emitOpConstantI32(
DL->getLine(), I32TypeReg, MAI);
2581 emitOpConstantI32(
DL->getColumn(), I32TypeReg, MAI);
2582 emitOpConstantI32(
DL->getColumn() + 1, I32TypeReg, MAI);
2583 MCRegister FileStrReg =
2584 getCachedScopePathOpStringReg(
DL->getScope(),
2586 getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg, ExtInstSetReg,
2590 GlobalNSDIEnabled =
true;
2594SPIRVNonSemanticDebugHandler::getDebugFullPath(
const DIScope *Scope)
const {
2595 SmallString<128>
Out;
2603 StringRef Dir =
Scope->getDirectory();
2610MCRegister SPIRVNonSemanticDebugHandler::getOrEmitDebugSourceForFileStrReg(
2613 const unsigned Key = FileStrReg.
id();
2614 auto It = DebugSourceRegByFileStr.find(
Key);
2615 if (It != DebugSourceRegByFileStr.end())
2618 MCRegister
DS = emitExtInst(SPIRV::NonSemanticExtInst::DebugSource,
2619 VoidTypeReg, ExtInstSetReg, {FileStrReg}, MAI);
2620 DebugSourceRegByFileStr[
Key] =
DS;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Expand Atomic instructions
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains constants used for implementing Dwarf debug support.
Module.h This file contains the declarations for the Module class.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
static NVPTX::Scope resolveScope(NVPTX::Scope S, const NVPTXSubtarget *T)
static constexpr StringLiteral Filename
static const MachineInstr * findAdjacentEmittedInstruction(const MachineInstr *MI, SPIRV::ModuleAnalysisInfo &MAI, bool Forward)
static std::optional< SmallVector< uint32_t, 3 > > mapExprOperand(const DIExpression::ExprOperand &Op)
static bool scalarTypeNeedsCapability(const DIBasicType *BT)
static bool isBooleanType(const DIBasicType *BT)
static bool constantHasValue(const MachineInstr &MI, uint64_t Value, bool IsWide)
static std::optional< Register > getDebugDeclareStorageReg(const MachineInstr &MI, bool AllowUntypedVariable)
static void collectLexicalBlockChain(const DIScope *S, SetVector< const DIScope * > &Out)
static bool isMergeInstruction(unsigned Opcode)
static std::optional< std::pair< const DIBasicType *, uint64_t > > getConstantDbgValueBits(const MachineInstr &MI)
static MCRegister getResultId(const MachineInstr &MI, SPIRV::ModuleAnalysisInfo &MAI)
static bool isEmitted(const MachineInstr *MI, SPIRV::ModuleAnalysisInfo &MAI)
static std::optional< Register > getDebugValueReg(const MachineInstr &MI)
static bool isDebugLocTarget(const MachineInstr *MI, SPIRV::ModuleAnalysisInfo &MAI)
static uint64_t constantBits(uint64_t Value, const DIBasicType *BT)
static std::optional< NonSemanticDebugOp > mapDwarfOpToNonSemanticOp(uint64_t DwarfOp)
static const DIBasicType * stripToScalarType(const DIType *Ty)
static void collectDebugLocationsAndLocalVariables(const Module &M, SetVector< const DILocation * > &Locations, SetVector< const DILocalVariable * > &LVs)
#define SPIRV_BACKEND_SERVICE_FUN_NAME
This file provides utility classes that use RAII to save and restore values.
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
Class for arbitrary precision integers.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
This class is intended to be used as a driving class for all asm writers.
TargetMachine & TM
Target machine description.
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
bool isValid() const
Return true if the attribute is any kind of attribute.
Basic type, like 'int' or 'float'.
A lightweight wrapper around an expression operand.
iterator_range< expr_op_iterator > expr_ops() const
A pair of DIGlobalVariable and DIExpression.
DIDerivedType * getStaticDataMemberDeclaration() const
StringRef getLinkageName() const
DILocalScope * getScope() const
Get the local scope for this variable.
Tagged DWARF-like metadata node.
LLVM_ABI dwarf::Tag getTag() const
Base class for scope-like contexts.
LLVM_ABI DIScope * getScope() const
Subprogram description. Uses SubclassData1.
Type array for a subprogram.
DIScope * getScope() const
StringRef getName() const
Base class for non-instruction debug metadata records that have positions within IR.
const MachineInstr * CurMI
If nonnull, stores the current machine instruction we're processing.
AsmPrinter * Asm
Target of debug info emission.
DebugHandlerBase(AsmPrinter *A)
void beginModule(Module *M) override
Utility to find all debug info in a module.
LLVM_ABI void processModule(const Module &M)
Process entire module and collect debug info anchors.
iterator_range< global_variable_expression_iterator > global_variables() const
iterator_range< subprogram_iterator > subprograms() const
iterator_range< type_iterator > types() const
iterator_range< scope_iterator > scopes() const
ValueT lookup(const_arg_type_t< KeyT > Val) const
Return the entry for the specified key, or a default constructed value if no such entry exists.
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
DISubprogram * getSubprogram() const
Get the attached subprogram.
Instances of this class represent a single low-level machine instruction.
void setFlags(unsigned F)
void addOperand(const MCOperand Op)
void setOpcode(unsigned Op)
static MCOperand createReg(MCRegister Reg)
static MCOperand createImm(int64_t Val)
Wrapper class representing physical registers and target specific virtual registers.
constexpr bool isValid() const
constexpr unsigned id() const
Tracking metadata reference owned by Metadata.
bool equalsStr(StringRef Str) const
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
bool dominates(const MachineInstr *A, const MachineInstr *B) const
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineBasicBlock & front() const
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
MachineOperand class - Representation of each machine instruction operand.
LLVM_ABI LLVM_READONLY MachineInstr * getUniqueVRegDef(Register Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
A Module instance is used to store all the information related to an LLVM module.
Wrapper class representing virtual and physical registers.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
void beginInstruction(const MachineInstr *MI) override
Process beginning of an instruction.
void beginModule(Module *M) override
Collect compile-unit metadata from the module.
void emitNonSemanticGlobalDebugInfo(SPIRV::ModuleAnalysisInfo &)
Output the module-scope NSDI built by generateModuleDebugInfo().
void emitNonSemanticDebugStrings(SPIRV::ModuleAnalysisInfo &)
Output the NSDI OpStrings built by generateModuleDebugInfo() into the debug section (section 7 of the...
void endFunctionImpl(const MachineFunction *MF) override
void beginFunctionImpl(const MachineFunction *MF) override
void prepareModuleOutput(const SPIRVSubtarget &ST, SPIRV::ModuleAnalysisInfo &MAI)
Add SPV_KHR_non_semantic_info extension and NonSemantic.Shader.DebugInfo.100 ext inst set entry to MA...
SPIRVNonSemanticDebugHandler(AsmPrinter &AP)
void generateModuleDebugInfo(SPIRV::ModuleAnalysisInfo &MAI)
Buffer the module-scope NSDI and add SPV_KHR_relaxed_extended_instruction to MAI if a forward referen...
void endInstruction() override
Process end of an instruction.
void notifyEntryLabelEmitted(const MachineFunction &MF)
Called after the synthesized entry OpLabel has been emitted.
const SPIRVOptions & getCLOpts() const
A vector that has set insertion semantics.
bool insert(const value_type &X)
Insert a new element into the SetVector.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
reverse_iterator rbegin()
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
const Triple & getTargetTriple() const
Target - Wrapper for Target specific information.
VendorType getVendor() const
Get the parsed vendor type of this triple.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
constexpr std::underlying_type_t< E > Underlying(E Val)
Check that Val is in range for E, and return Val cast to E's underlying type.
@ DW_OP_LLVM_fragment
Only used in LLVM metadata.
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
NodeAddr< DefNode * > Def
LLVM_ABI bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
This is an optimization pass for GlobalISel generic memory operations.
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&...args)
zip iterator for two or more iteratable types.
void addStringImm(StringRef Str, MCInst &Inst)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto map_to_vector(ContainerTy &&C, FuncTy &&F)
Map a range to a SmallVector with element types deduced from the mapping.
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
bool isa_and_nonnull(const Y &Val)
OutputIt copy_if(R &&Range, OutputIt Out, UnaryPredicate P)
Provide wrappers to std::copy_if which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI void reportFatalInternalError(Error Err)
Report a fatal error that indicates a bug in LLVM.
detail::concat_range< ValueT, RangeTs... > concat(RangeTs &&...Ranges)
Returns a concatenated range across two or more ranges.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
auto dyn_cast_or_null(const Y &Val)
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
constexpr uint32_t Hi_32(uint64_t Value)
Return the high 32 bits of a 64 bit value.
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
constexpr uint32_t Lo_32(uint64_t Value)
Return the low 32 bits of a 64 bit value.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
SPIRV::StorageClass::StorageClass addressSpaceToStorageClass(unsigned AddrSpace, const SPIRVSubtarget &STI)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
constexpr bool valueOr(BoolOrDefault X, bool Default)
MCRegister getExtInstSetReg(unsigned SetNum)
DenseMap< unsigned, MCRegister > ExtInstSetMap
InstrList & getMSInstrs(unsigned MSType)
MCRegister getRegisterAlias(const MachineFunction *MF, Register Reg)
bool getSkipEmission(const MachineInstr *MI)
MCRegister getGlobalObjReg(const GlobalObject *GO)
SmallVector< const MachineInstr * > DebugValueMIs
MCRegister getNextIDRegister()
void addExtension(Extension::Extension ToAdd)
A utility class that uses RAII to save and restore the value of a variable.