45template <
typename MapT>
46static std::optional<MCRegister> lookupOptReg(
const MapT &Map,
47 typename MapT::key_type
Key) {
51 assert(It->second.isValid() &&
"invalid register stored in map");
56 NSDIFlagIsProtected = 1u << 0,
57 NSDIFlagIsPrivate = 1u << 1,
58 NSDIFlagIsPublic = NSDIFlagIsPrivate | NSDIFlagIsProtected,
59 NSDIFlagIsLocal = 1u << 2,
60 NSDIFlagIsDefinition = 1u << 3,
61 NSDIFlagFwdDecl = 1u << 4,
62 NSDIFlagArtificial = 1u << 5,
63 NSDIFlagExplicit = 1u << 6,
64 NSDIFlagPrototyped = 1u << 7,
65 NSDIFlagObjectPointer = 1u << 8,
66 NSDIFlagStaticMember = 1u << 9,
67 NSDIFlagIndirectVariable = 1u << 10,
68 NSDIFlagLValueReference = 1u << 11,
69 NSDIFlagRValueReference = 1u << 12,
70 NSDIFlagIsOptimized = 1u << 13,
71 NSDIFlagIsEnumClass = 1u << 14,
72 NSDIFlagTypePassByValue = 1u << 15,
73 NSDIFlagTypePassByReference = 1u << 16,
74 NSDIFlagUnknownPhysicalLayout = 1u << 17,
80 Flags |= NSDIFlagIsPublic;
82 Flags |= NSDIFlagIsProtected;
84 Flags |= NSDIFlagIsPrivate;
85 if (DFlags & DINode::FlagFwdDecl)
86 Flags |= NSDIFlagFwdDecl;
87 if (DFlags & DINode::FlagArtificial)
88 Flags |= NSDIFlagArtificial;
89 if (DFlags & DINode::FlagExplicit)
90 Flags |= NSDIFlagExplicit;
91 if (DFlags & DINode::FlagPrototyped)
92 Flags |= NSDIFlagPrototyped;
93 if (DFlags & DINode::FlagObjectPointer)
94 Flags |= NSDIFlagObjectPointer;
95 if (DFlags & DINode::FlagStaticMember)
96 Flags |= NSDIFlagStaticMember;
97 if (DFlags & DINode::FlagLValueReference)
98 Flags |= NSDIFlagLValueReference;
99 if (DFlags & DINode::FlagRValueReference)
100 Flags |= NSDIFlagRValueReference;
101 if (DFlags & DINode::FlagTypePassByValue)
102 Flags |= NSDIFlagTypePassByValue;
103 if (DFlags & DINode::FlagTypePassByReference)
104 Flags |= NSDIFlagTypePassByReference;
105 if (DFlags & DINode::FlagEnumClass)
106 Flags |= NSDIFlagIsEnumClass;
113 if (GV->isLocalToUnit())
114 Flags |= NSDIFlagIsLocal;
115 if (GV->isDefinition())
116 Flags |= NSDIFlagIsDefinition;
119 if (SP->isLocalToUnit())
120 Flags |= NSDIFlagIsLocal;
121 if (SP->isOptimized())
122 Flags |= NSDIFlagIsOptimized;
123 if (SP->isDefinition())
124 Flags |= NSDIFlagIsDefinition;
125 Flags |= mapDIFlagsToNonSemantic(SP->getFlags());
127 if (DN->
getTag() == dwarf::DW_TAG_reference_type)
128 Flags |= NSDIFlagLValueReference;
129 if (DN->
getTag() == dwarf::DW_TAG_rvalue_reference_type)
130 Flags |= NSDIFlagRValueReference;
132 Flags |= mapDIFlagsToNonSemantic(Ty->getFlags());
134 Flags |= mapDIFlagsToNonSemantic(LV->getFlags());
140static uint32_t mapCompositeTypeTag(
unsigned Tag) {
142 case dwarf::DW_TAG_class_type:
144 case dwarf::DW_TAG_structure_type:
146 case dwarf::DW_TAG_union_type:
150 ". Expecting 0, 1 or 2");
156static std::optional<uint32_t> mapTypeQualifierTag(
unsigned Tag) {
158 case dwarf::DW_TAG_const_type:
160 case dwarf::DW_TAG_volatile_type:
162 case dwarf::DW_TAG_restrict_type:
164 case dwarf::DW_TAG_atomic_type:
182 bool SeenOpVariable =
false;
184 if (
MI.getOpcode() == SPIRV::OpVariable) {
185 SeenOpVariable =
true;
187 LastOpVariable = &
MI;
191 bool CanInterleaveWithOpVariable =
192 MI.getOpcode() == SPIRV::OpLine ||
MI.getOpcode() == SPIRV::OpNoLine;
193 if (SeenOpVariable && !CanInterleaveWithOpVariable &&
197 return LastOpVariable;
209unsigned SPIRVNonSemanticDebugHandler::toNSDISrcLang(
unsigned DwarfSrcLang) {
210 switch (DwarfSrcLang) {
211 case dwarf::DW_LANG_OpenCL:
213 case dwarf::DW_LANG_OpenCL_CPP:
215 case dwarf::DW_LANG_CPP_for_OpenCL:
217 case dwarf::DW_LANG_GLSL:
219 case dwarf::DW_LANG_HLSL:
221 case dwarf::DW_LANG_SYCL:
223 case dwarf::DW_LANG_Zig:
231 return BT->getEncoding() == dwarf::DW_ATE_boolean;
240 unsigned Width =
BT->getSizeInBits();
249 ?
Value.trunc(std::min(Width, 64u)).getZExtValue()
250 :
Value.getZExtValue(),
261 unsigned Tag = DT->getTag();
262 if ((Tag != dwarf::DW_TAG_typedef && !mapTypeQualifierTag(Tag)) ||
265 Ty = DT->getBaseType();
276 unsigned Size =
BT->getSizeInBits();
277 switch (
BT->getEncoding()) {
278 case dwarf::DW_ATE_signed:
279 case dwarf::DW_ATE_unsigned:
280 case dwarf::DW_ATE_signed_char:
281 case dwarf::DW_ATE_unsigned_char:
283 case dwarf::DW_ATE_float:
309 for (
const MDNode *
N : SP->getRetainedNodes())
314 Locations.insert(
DL);
317 Locations.insert(
DL);
333 while (S && !Out.contains(S) &&
349 CompileUnits.clear();
351 EnumCompileUnits.clear();
353 UniqueDebugLocations.clear();
354 GlobalVariableDebugInfoMap.clear();
355 LocalVariables.clear();
356 DebugLocalVariableRegs.clear();
357 DebugExpressionRegs.clear();
358 LexicalBlocks.clear();
359 DebugScopeRegs.clear();
360 ScopesInProgress.clear();
361 HasRelaxedExtInst =
false;
362 FailedScopes.clear();
363 DebugInlinedAtRegs.clear();
364 ScopeToPathOpStringReg.clear();
365 DebugSourceRegByFileStr.clear();
366 OpStringContentCache.clear();
367 ScalarTypeCache.clear();
368 ScalarConstantCache.clear();
369 ConstantValueRegs.clear();
370 DebugOperationCache.clear();
371 DebugExpressionCache.clear();
372 ModuleScopeIds.clear();
373 GlobalDIEmitted =
false;
374 GlobalNSDIEnabled =
false;
375 CurrentMAI =
nullptr;
377 NonSemanticOpStringsSectionEmitted =
false;
387 CompileUnitInfo Info;
390 Info.FilePath = File->getFilename();
393 File->getFilename());
396 Info.SpirvSourceLanguage = toNSDISrcLang(
CU->getSourceLanguage().getName());
397 CompileUnits.push_back(std::move(Info));
399 EnumCompileUnits.try_emplace(ET,
CU);
405 if (
const NamedMDNode *Flags = M->getNamedMetadata(
"llvm.module.flags")) {
406 for (
const auto *
Op : Flags->operands()) {
421 return Ty->getTag() != dwarf::DW_TAG_member;
430 G.getDebugInfo(GVEs);
441 GlobalVariableDebugInfoMap.try_emplace(
442 GV, GlobalVariableDebugInfo{Expr, DIGVToLLVMGV.
lookup(GV)});
460 if (
MI.getNumOperands() == 0 || !
MI.getOperand(0).isReg() ||
461 !
MI.getOperand(0).isDef())
468 if (CompileUnits.empty())
470 if (!ST.canUseExtension(SPIRV::Extension::SPV_KHR_non_semantic_info))
477 CLOpts.debug_scope_forward_refs &&
479 SPIRV::Extension::SPV_KHR_relaxed_extended_instruction);
480 if (HasRelaxedExtInst)
482 SPIRV::Extension::SPV_KHR_relaxed_extended_instruction);
492 ModuleScopeIds.insert(Id);
496void SPIRVNonSemanticDebugHandler::emitMCInst(
MCInst &Inst) {
501SPIRVNonSemanticDebugHandler::emitOpString(
StringRef S,
512MCRegister SPIRVNonSemanticDebugHandler::emitOpStringIfNew(
515 assert(!NonSemanticOpStringsSectionEmitted &&
516 "emitOpStringIfNew is only valid while emitting SPIR-V section 7");
518 auto [It,
Inserted] = OpStringContentCache.try_emplace(S, MCRegister());
520 It->second = emitOpString(S, MAI);
527 assert(NonSemanticOpStringsSectionEmitted &&
528 "getCachedOpStringReg requires emitNonSemanticDebugStrings() first");
530 auto It = OpStringContentCache.find(S);
531 assert(It != OpStringContentCache.end() &&
532 "NSDI OpString missing from cache; emitNonSemanticDebugStrings must "
533 "cache every string used in section 10");
537MCRegister SPIRVNonSemanticDebugHandler::emitAndCacheScopePathOpStringReg(
539 auto [It,
Inserted] = ScopeToPathOpStringReg.try_emplace(Scope, MCRegister());
541 It->second = emitOpStringIfNew(getDebugFullPath(Scope), MAI);
545MCRegister SPIRVNonSemanticDebugHandler::getCachedScopePathOpStringReg(
546 const DIScope *Scope,
bool UseEmptyPathIfNullScope) {
548 assert(UseEmptyPathIfNullScope &&
549 "null scope path lookup requires UseEmptyPathIfNullScope");
550 assert(CachedEmptyStringReg.isValid() &&
551 "empty path OpString must be cached in emitNonSemanticDebugStrings");
552 return CachedEmptyStringReg;
554 auto It = ScopeToPathOpStringReg.find(Scope);
555 assert(It != ScopeToPathOpStringReg.end() &&
556 "path OpString must be cached in emitNonSemanticDebugStrings");
557 MCRegister FileStrReg = It->second;
558 assert(FileStrReg.
isValid() &&
"path OpString id must be valid once cached");
562MCRegister SPIRVNonSemanticDebugHandler::emitOpConstantI32(
564 return findOrEmitConstant(SPIRV::OpConstantI, I32TypeReg,
Value,
568bool SPIRVNonSemanticDebugHandler::markForwardReferencedOperands(
570 bool HasForwardRef =
false;
571 for (
auto &Entry : ScopesInProgress) {
572 InProgressScope &InProgress =
Entry.second;
573 assert(InProgress.Id.isValid() &&
574 "in-progress scope must have a reserved id");
577 InProgress.ForwardReferenced =
true;
578 HasForwardRef =
true;
580 return HasForwardRef;
583MCRegister SPIRVNonSemanticDebugHandler::emitExtInst(
584 SPIRV::NonSemanticExtInst::NonSemanticExtInst Opcode,
587 std::optional<MCRegister> ResultReg) {
588 assert((!ResultReg || ResultReg->isValid()) &&
589 "ResultReg must be a valid id when provided");
596 HasRelaxedExtInst && markForwardReferencedOperands(
Operands);
599 Inst.
setOpcode(HasForwardRef ? SPIRV::OpExtInstWithForwardRefsKHR
611MCRegister SPIRVNonSemanticDebugHandler::getOrEmitOpTypeVoidReg(
613 if (!CachedOpTypeVoidReg.isValid())
614 CachedOpTypeVoidReg = findOrEmitOpTypeVoid(MAI);
615 return CachedOpTypeVoidReg;
618MCRegister SPIRVNonSemanticDebugHandler::getOrEmitOpTypeInt32Reg(
620 if (!CachedOpTypeInt32Reg.isValid())
621 CachedOpTypeInt32Reg = findOrEmitOpTypeInt32(MAI);
622 return CachedOpTypeInt32Reg;
625MCRegister SPIRVNonSemanticDebugHandler::findOrEmitOpTypeVoid(
628 if (
MI->getOpcode() == SPIRV::OpTypeVoid)
645 unsigned Width =
BT->getSizeInBits();
649MCRegister SPIRVNonSemanticDebugHandler::findOrEmitScalarType(
652 bool IsFloat =
BT->getEncoding() == dwarf::DW_ATE_float;
653 unsigned Opcode = IsBool ? SPIRV::OpTypeBool
654 : IsFloat ? SPIRV::OpTypeFloat
658 int64_t Width = IsBool ? 0 :
BT->getSizeInBits();
663 if (Opcode == SPIRV::OpTypeInt && Width == 32)
664 return getOrEmitOpTypeInt32Reg(MAI);
667 ScalarTypeCache.try_emplace({Opcode, Width}, MCRegister());
669 return CacheIt->second;
674 if (
MI->getOpcode() != Opcode)
676 if (IsBool || (
MI->getOperand(1).getImm() == Width &&
677 (IsFloat ||
MI->getOperand(2).getImm() == 0))) {
680 return CacheIt->second;
702 CacheIt->second =
Reg;
709 unsigned Words = IsWide ? 2 : 1;
710 if (
MI.getNumOperands() < 2 + Words)
713 for (
unsigned I = 0;
I < Words; ++
I) {
714 if (!
MI.getOperand(2 +
I).isImm())
720 return Found ==
Value;
723MCRegister SPIRVNonSemanticDebugHandler::findModuleConstant(
727 if (
MI->getOpcode() != Opcode ||
MI->getNumOperands() < 2)
741MCRegister SPIRVNonSemanticDebugHandler::findOrEmitConstant(
744 bool IsBool = Width == 0;
745 bool IsWide = Width == 64;
748 ScalarConstantCache.try_emplace({TypeReg.
id(),
Value}, MCRegister());
750 return CacheIt->second;
753 findModuleConstant(Opcode, TypeReg,
Value, IsBool, IsWide, MAI);
755 CacheIt->second = Found;
771 }
else if (Width == 16) {
778 CacheIt->second =
Reg;
782MCRegister SPIRVNonSemanticDebugHandler::findOrEmitScalarConstant(
784 MCRegister TypeReg = findOrEmitScalarType(
BT, MAI);
789 bool IsFloat =
BT->getEncoding() == dwarf::DW_ATE_float;
791 IsBool ? (
Value ? SPIRV::OpConstantTrue : SPIRV::OpConstantFalse)
792 : IsFloat ?
SPIRV::OpConstantF
793 :
SPIRV::OpConstantI;
794 return findOrEmitConstant(Opcode, TypeReg,
Value,
795 IsBool ? 0 :
BT->getSizeInBits(), MAI);
798MCRegister SPIRVNonSemanticDebugHandler::findOrEmitOpTypeInt32(
801 if (
MI->getOpcode() == SPIRV::OpTypeInt &&
802 MI->getOperand(1).getImm() == 32 &&
MI->getOperand(2).getImm() == 0)
821auto SPIRVNonSemanticDebugHandler::getOrCreateDebugScope(
const DIScope *S)
822 -> EmitResult<MCRegister> {
823 if (!S || FailedScopes.contains(S))
824 return EmitResult<MCRegister>::unsupported();
825 if (
auto Reg = lookupOptReg(DebugScopeRegs, S))
826 return EmitResult<MCRegister>::emitted(*
Reg);
830 auto [InProgressIt, FirstVisit] = ScopesInProgress.try_emplace(S);
832 if (!HasRelaxedExtInst)
833 return EmitResult<MCRegister>::inProgress();
837 MCRegister ReservedId = InProgressIt->second.Id;
838 assert(ReservedId.
isValid() &&
"in-progress scope must have a reserved id");
839 return EmitResult<MCRegister>::emitted(ReservedId);
843 assert(CurrentMAI &&
"debug scope id allocation requires CurrentMAI");
845 assert(
Id.isValid() &&
"debug scope id must be a valid register");
846 InProgressIt->second.Id =
Id;
848 EmitResult<PreparedScope>
P = emitDebugScope(S);
849 assert((!HasRelaxedExtInst ||
P.Status != EmitStatus::InProgress) &&
850 "InProgress is only returned when forward references are unsupported");
853 InProgressIt = ScopesInProgress.find(S);
854 assert(InProgressIt != ScopesInProgress.end() &&
855 "scope must stay in progress until its instruction is emitted");
856 bool ForwardReferenced = InProgressIt->second.ForwardReferenced;
857 ScopesInProgress.erase(InProgressIt);
861 if (ForwardReferenced) {
862 assert(HasRelaxedExtInst &&
863 "a forward reference requires relaxed extended instructions");
864 assert(
P.Status == EmitStatus::Unsupported &&
865 "a forward-referenced scope fails as unsupported");
867 emitExtInst(SPIRV::NonSemanticExtInst::DebugInfoNone,
876 if (
P.Status == EmitStatus::Unsupported)
877 FailedScopes.insert(S);
878 return P.Status == EmitStatus::InProgress
879 ? EmitResult<MCRegister>::inProgress()
886 emitExtInst(
P.Value->Opcode, getOrEmitOpTypeVoidReg(MAI),
889 "debug scope result id must reuse the id reserved at entry");
890 ScopesInProgress.erase(S);
891 assert(!GlobalNSDIEnabled &&
892 "debug type or scope created after module-scope NSDI emission");
893 DebugScopeRegs[S] =
Reg;
894 return EmitResult<MCRegister>::emitted(
Reg);
897auto SPIRVNonSemanticDebugHandler::getOrCreateDebugTypeOrNone(
const DIType *Ty)
898 -> EmitResult<MCRegister> {
900 return getOrCreateDebugScope(Ty);
901 assert(CachedDebugInfoNoneReg.isValid() &&
902 "DebugInfoNone must be emitted before debug types");
903 return EmitResult<MCRegister>::emitted(CachedDebugInfoNoneReg);
906auto SPIRVNonSemanticDebugHandler::emitDebugTypeBasic(
910 return EmitResult<PreparedScope>::unsupported();
912 MCRegister NameReg = getCachedOpStringReg(
BT->getName());
914 static_cast<uint32_t
>(
BT->getSizeInBits()), I32TypeReg, MAI);
918 unsigned Encoding = 0;
919 switch (
BT->getEncoding()) {
920 case dwarf::DW_ATE_address:
923 case dwarf::DW_ATE_boolean:
926 case dwarf::DW_ATE_float:
929 case dwarf::DW_ATE_signed:
932 case dwarf::DW_ATE_signed_char:
935 case dwarf::DW_ATE_unsigned:
938 case dwarf::DW_ATE_unsigned_char:
942 MCRegister EncodingReg = emitOpConstantI32(Encoding, I32TypeReg, MAI);
943 MCRegister FlagsReg = emitOpConstantI32(0, I32TypeReg, MAI);
944 return EmitResult<PreparedScope>::emitted(
945 PreparedScope{SPIRV::NonSemanticExtInst::DebugTypeBasic,
946 {NameReg, SizeReg, EncodingReg, FlagsReg}});
949auto SPIRVNonSemanticDebugHandler::emitDebugScope(
const DIScope *S)
950 -> EmitResult<PreparedScope> {
951 assert(CurrentMAI &&
"emitDebugScope requires CurrentMAI");
954 MCRegister VoidTypeReg = getOrEmitOpTypeVoidReg(MAI);
955 MCRegister I32TypeReg = getOrEmitOpTypeInt32Reg(MAI);
958 return emitDebugTypeBasic(
BT, I32TypeReg, MAI);
960 return emitDebugTypeFunctionForSubroutineType(ST, MAI);
962 return emitDebugTypeForCompositeType(CT, VoidTypeReg, I32TypeReg,
965 return emitDebugTypeForDerivedType(DT, VoidTypeReg, I32TypeReg,
968 return emitDebugLexicalBlock(S, VoidTypeReg, I32TypeReg, ExtInstSetReg,
971 return emitDebugLexicalBlockDiscriminator(LBF, VoidTypeReg, I32TypeReg,
974 if (
SP->isDefinition())
975 return emitDebugFunction(SP, VoidTypeReg, I32TypeReg, ExtInstSetReg, MAI);
976 return emitDebugFunctionDeclaration(SP, VoidTypeReg, I32TypeReg,
979 return EmitResult<PreparedScope>::unsupported();
982auto SPIRVNonSemanticDebugHandler::emitDebugTypeForCompositeType(
985 -> EmitResult<PreparedScope> {
986 switch (CT->getTag()) {
987 case dwarf::DW_TAG_array_type:
1000 return emitDebugTypeVector(CT, MAI);
1001 return emitDebugTypeArray(CT, MAI);
1002 case dwarf::DW_TAG_structure_type:
1003 case dwarf::DW_TAG_class_type:
1004 case dwarf::DW_TAG_union_type:
1005 return emitDebugTypeComposite(CT, VoidTypeReg, I32TypeReg, ExtInstSetReg,
1007 case dwarf::DW_TAG_enumeration_type:
1008 return emitDebugTypeEnum(CT, VoidTypeReg, I32TypeReg, ExtInstSetReg, MAI);
1010 return EmitResult<PreparedScope>::unsupported();
1014auto SPIRVNonSemanticDebugHandler::emitDebugTypeForDerivedType(
1017 -> EmitResult<PreparedScope> {
1018 switch (DT->getTag()) {
1019 case dwarf::DW_TAG_pointer_type:
1020 return emitDebugTypePointer(DT, MAI);
1021 case dwarf::DW_TAG_typedef:
1022 return emitDebugTypedef(DT, VoidTypeReg, I32TypeReg, ExtInstSetReg, MAI);
1023 case dwarf::DW_TAG_member:
1024 return emitDebugTypeMember(DT, VoidTypeReg, I32TypeReg, ExtInstSetReg, MAI);
1026 if (std::optional<uint32_t> Qualifier = mapTypeQualifierTag(DT->getTag()))
1027 return emitDebugTypeQualifier(DT, *Qualifier, MAI);
1028 return EmitResult<PreparedScope>::unsupported();
1032auto SPIRVNonSemanticDebugHandler::emitDebugTypePointer(
1034 -> EmitResult<PreparedScope> {
1037 if (!PT->getDWARFAddressSpace().has_value())
1038 return EmitResult<PreparedScope>::unsupported();
1040 EmitResult<MCRegister>
Base = getOrCreateDebugTypeOrNone(PT->getBaseType());
1042 return EmitResult<PreparedScope>::failure(
Base);
1044 MCRegister I32TypeReg = getOrEmitOpTypeInt32Reg(MAI);
1046 emitOpConstantI32(transDebugFlags(PT), I32TypeReg, MAI);
1051 MCRegister StorageClassReg = emitOpConstantI32(
1055 return EmitResult<PreparedScope>::emitted(
1056 PreparedScope{SPIRV::NonSemanticExtInst::DebugTypePointer,
1057 {*
Base.Value, StorageClassReg, DebugTypePointerFlagsReg}});
1060auto SPIRVNonSemanticDebugHandler::emitDebugTypeQualifier(
1062 -> EmitResult<PreparedScope> {
1063 EmitResult<MCRegister>
Base = getOrCreateDebugTypeOrNone(QT->getBaseType());
1065 return EmitResult<PreparedScope>::failure(
Base);
1068 emitOpConstantI32(Qualifier, getOrEmitOpTypeInt32Reg(MAI), MAI);
1069 return EmitResult<PreparedScope>::emitted(
1070 PreparedScope{SPIRV::NonSemanticExtInst::DebugTypeQualifier,
1071 {*
Base.Value, QualifierReg}});
1074auto SPIRVNonSemanticDebugHandler::emitDebugTypeFunctionForSubroutineType(
1076 -> EmitResult<PreparedScope> {
1077 MCRegister VoidTypeReg = getOrEmitOpTypeVoidReg(MAI);
1078 MCRegister I32TypeReg = getOrEmitOpTypeInt32Reg(MAI);
1080 emitOpConstantI32(transDebugFlags(ST), I32TypeReg, MAI);
1081 DITypeArray
TA =
ST->getTypeArray();
1088 Ops.push_back(VoidTypeReg);
1090 for (
unsigned I = 0,
E =
TA.size();
I !=
E; ++
I) {
1091 bool IsReturnType = (
I == 0);
1092 EmitResult<MCRegister>
Slot =
1093 mapDISignatureTypeToReg(TA[
I], VoidTypeReg, IsReturnType);
1097 return EmitResult<PreparedScope>::failure(Slot);
1101 return EmitResult<PreparedScope>::emitted(
1102 PreparedScope{SPIRV::NonSemanticExtInst::DebugTypeFunction,
Ops});
1106auto SPIRVNonSemanticDebugHandler::resolveScope(
const DIScope *Scope,
1108 -> EmitResult<MCRegister> {
1109 if (!CLOpts.debug_lexical_block_discriminator_scope)
1111 Scope = LBF->getScope();
1116 return getOrCreateDebugScope(Scope);
1119 auto CUResult = [](std::optional<MCRegister>
Reg) {
1120 return Reg ? EmitResult<MCRegister>::emitted(*
Reg)
1124 return CUResult(lookupOptReg(DebugScopeRegs, FallbackCU));
1126 if (CompileUnits.empty())
1127 return EmitResult<MCRegister>::unsupported();
1129 return CUResult(lookupOptReg(DebugScopeRegs, CompileUnits[0].TheCU));
1132auto SPIRVNonSemanticDebugHandler::emitDebugLexicalBlock(
1135 -> EmitResult<PreparedScope> {
1137 "S must be a DILexicalBlock or DINamespace in emitDebugLexicalBlock");
1138 EmitResult<MCRegister> Parent =
resolveScope(S->getScope());
1140 return EmitResult<PreparedScope>::failure(Parent);
1142 MCRegister FileStrReg = getCachedScopePathOpStringReg(
1143 S->getFile(),
true);
1144 MCRegister SrcReg = getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg,
1145 ExtInstSetReg, MAI);
1149 MCRegister LineReg = emitOpConstantI32(
static_cast<uint32_t
>(LB->getLine()),
1152 static_cast<uint32_t
>(LB->getColumn()), I32TypeReg, MAI);
1153 Ops = {SrcReg, LineReg, ColReg, *Parent.Value};
1157 MCRegister LineReg = emitOpConstantI32(0, I32TypeReg, MAI);
1158 MCRegister ColReg = emitOpConstantI32(0, I32TypeReg, MAI);
1159 MCRegister NameReg = getCachedOpStringReg(NS->getName());
1160 Ops = {SrcReg, LineReg, ColReg, *Parent.Value, NameReg};
1163 return EmitResult<PreparedScope>::emitted(
1164 PreparedScope{SPIRV::NonSemanticExtInst::DebugLexicalBlock,
Ops});
1167auto SPIRVNonSemanticDebugHandler::emitDebugLexicalBlockDiscriminator(
1171 assert(LBF &&
"LBF must not be null");
1172 EmitResult<MCRegister> Parent =
resolveScope(LBF->getScope());
1174 return EmitResult<PreparedScope>::failure(Parent);
1176 MCRegister FileStrReg = getCachedScopePathOpStringReg(
1177 LBF->getFile(),
true);
1178 MCRegister SrcReg = getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg,
1179 ExtInstSetReg, MAI);
1181 static_cast<uint32_t
>(LBF->getDiscriminator()), I32TypeReg, MAI);
1182 return EmitResult<PreparedScope>::emitted(
1183 PreparedScope{SPIRV::NonSemanticExtInst::DebugLexicalBlockDiscriminator,
1184 {SrcReg, DiscReg, *Parent.Value}});
1187MCRegister SPIRVNonSemanticDebugHandler::getOrEmitDebugInlinedAt(
1190 assert(IA &&
"IA must not be null in getOrEmitDebugInlinedAt");
1192 if (MCRegister Cached = DebugInlinedAtRegs.lookup(IA))
1195 EmitResult<MCRegister>
Scope = resolveScope(
IA->getScope());
1197 return MCRegister();
1199 MCRegister LineReg =
1200 emitOpConstantI32(
static_cast<uint32_t
>(
IA->getLine()), I32TypeReg, MAI);
1205 if (
const DILocation *Outer =
IA->getInlinedAt()) {
1206 MCRegister OuterReg = getOrEmitDebugInlinedAt(
1207 Outer, VoidTypeReg, I32TypeReg, ExtInstSetReg, MAI);
1209 return MCRegister();
1210 Ops.push_back(OuterReg);
1213 MCRegister
Reg = emitExtInst(SPIRV::NonSemanticExtInst::DebugInlinedAt,
1214 VoidTypeReg, ExtInstSetReg,
Ops, MAI);
1215 DebugInlinedAtRegs[
IA] =
Reg;
1219auto SPIRVNonSemanticDebugHandler::emitDebugFunctionDeclaration(
1222 -> EmitResult<PreparedScope> {
1223 assert(SP &&
"SP must not be null in emitDebugFunctionDeclaration");
1225 "SP must not be a definition in emitDebugFunctionDeclaration");
1228 EmitResult<MCRegister> FnTy = getOrCreateDebugScope(
SP->getType());
1230 return EmitResult<PreparedScope>::failure(FnTy);
1232 EmitResult<MCRegister> Parent =
resolveScope(
SP->getScope(),
SP->getUnit());
1234 return EmitResult<PreparedScope>::failure(Parent);
1236 MCRegister FileStrReg = getCachedScopePathOpStringReg(SP);
1238 MCRegister NameReg = getCachedOpStringReg(
SP->getName());
1239 MCRegister LinkageReg = getCachedOpStringReg(
SP->getLinkageName());
1240 MCRegister SrcReg = getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg,
1241 ExtInstSetReg, MAI);
1244 emitOpConstantI32(
static_cast<uint32_t
>(
SP->getLine()), I32TypeReg, MAI);
1245 MCRegister ColReg = emitOpConstantI32(0, I32TypeReg, MAI);
1247 uint32_t FlagsVal = transDebugFlags(SP);
1250 FlagsVal &= ~NSDIFlagIsDefinition;
1251 MCRegister FlagsReg = emitOpConstantI32(FlagsVal, I32TypeReg, MAI);
1253 return EmitResult<PreparedScope>::emitted(
1254 PreparedScope{SPIRV::NonSemanticExtInst::DebugFunctionDeclaration,
1255 {NameReg, *FnTy.Value, SrcReg, LineReg, ColReg,
1256 *Parent.Value, LinkageReg, FlagsReg}});
1259auto SPIRVNonSemanticDebugHandler::emitDebugFunction(
1262 -> EmitResult<PreparedScope> {
1263 assert(SP &&
"SP must not be null in emitDebugFunction");
1264 assert(
SP->isDefinition() &&
"SP must be a definition in emitDebugFunction");
1266 EmitResult<MCRegister> FnTy = getOrCreateDebugScope(
SP->getType());
1268 return EmitResult<PreparedScope>::failure(FnTy);
1270 EmitResult<MCRegister> Parent =
resolveScope(
SP->getScope(),
SP->getUnit());
1272 return EmitResult<PreparedScope>::failure(Parent);
1274 MCRegister NameReg = getCachedOpStringReg(
SP->getName());
1275 MCRegister LinkageReg = getCachedOpStringReg(
SP->getLinkageName());
1276 MCRegister FileStrReg = getCachedScopePathOpStringReg(SP);
1277 MCRegister SrcReg = getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg,
1278 ExtInstSetReg, MAI);
1281 emitOpConstantI32(
static_cast<uint32_t
>(
SP->getLine()), I32TypeReg, MAI);
1284 MCRegister ColReg = emitOpConstantI32(0, I32TypeReg, MAI);
1285 MCRegister FlagsReg = emitOpConstantI32(transDebugFlags(SP), I32TypeReg, MAI);
1287 static_cast<uint32_t
>(
SP->getScopeLine()), I32TypeReg, MAI);
1290 LineReg, ColReg, *Parent.Value,
1291 LinkageReg, FlagsReg, ScopeLineReg};
1294 EmitResult<MCRegister> DeclRes = getOrCreateDebugScope(Decl);
1296 Ops.push_back(*DeclRes.Value);
1299 return EmitResult<PreparedScope>::emitted(
1300 PreparedScope{SPIRV::NonSemanticExtInst::DebugFunction,
Ops});
1303auto SPIRVNonSemanticDebugHandler::mapDISignatureTypeToReg(
1305 -> EmitResult<MCRegister> {
1306 if (!Ty && ReturnType)
1307 return EmitResult<MCRegister>::emitted(VoidTypeReg);
1308 return getOrCreateDebugTypeOrNone(Ty);
1326static std::optional<NonSemanticDebugOp>
1329 case dwarf::DW_OP_deref:
1331 case dwarf::DW_OP_plus:
1333 case dwarf::DW_OP_minus:
1335 case dwarf::DW_OP_plus_uconst:
1337 case dwarf::DW_OP_bit_piece:
1339 case dwarf::DW_OP_swap:
1341 case dwarf::DW_OP_xderef:
1343 case dwarf::DW_OP_stack_value:
1345 case dwarf::DW_OP_constu:
1350 return std::nullopt;
1356static std::optional<SmallVector<uint32_t, 3>>
1358 std::optional<NonSemanticDebugOp> NSOp =
1361 return std::nullopt;
1364 for (
unsigned I = 0,
E =
Op.getNumArgs();
I !=
E; ++
I) {
1367 return std::nullopt;
1373std::optional<MCRegister> SPIRVNonSemanticDebugHandler::emitDebugOperation(
1379 return std::nullopt;
1381 auto [It,
Inserted] = DebugOperationCache.try_emplace(std::move(*
Key));
1386 for (uint32_t
V : It->first)
1387 Operands.push_back(emitOpConstantI32(
V, I32TypeReg, MAI));
1388 MCRegister
Reg = emitExtInst(SPIRV::NonSemanticExtInst::DebugOperation,
1389 VoidTypeReg, ExtInstSetReg,
Operands, MAI);
1394std::optional<MCRegister> SPIRVNonSemanticDebugHandler::emitDebugExpression(
1397 assert(Expr &&
"Expr must not be null in emitDebugExpression");
1400 for (
const DIExpression::ExprOperand &
Op : Expr->
expr_ops()) {
1401 std::optional<MCRegister> OpReg =
1402 emitDebugOperation(
Op, VoidTypeReg, I32TypeReg, ExtInstSetReg, MAI);
1404 return std::nullopt;
1409 DebugExpressionCache.try_emplace(std::move(OperationRegs));
1413 MCRegister
Reg = emitExtInst(SPIRV::NonSemanticExtInst::DebugExpression,
1414 VoidTypeReg, ExtInstSetReg, It->first, MAI);
1419std::optional<MCRegister> SPIRVNonSemanticDebugHandler::emitDebugGlobalVariable(
1423 assert(GV &&
"GV must not be null in emitDebugGlobalVariable");
1425 EmitResult<MCRegister> Parent = resolveScope(GV->
getScope());
1427 return std::nullopt;
1429 MCRegister ParentReg = *Parent.Value;
1435 MCRegister TyReg = CachedDebugInfoNoneReg;
1436 if (
const DIType *Ty = GV->
getType()) {
1437 auto TyRegOpt = lookupOptReg(DebugScopeRegs, Ty);
1439 return std::nullopt;
1443 std::optional<MCRegister> StaticMemberRegOpt;
1446 StaticMemberRegOpt = lookupOptReg(DebugScopeRegs, SM);
1447 if (!StaticMemberRegOpt)
1448 return std::nullopt;
1451 MCRegister NameReg = getCachedOpStringReg(GV->
getName());
1452 MCRegister LinkageReg = getCachedOpStringReg(GV->
getLinkageName());
1453 MCRegister FileStrReg = getCachedScopePathOpStringReg(
1455 MCRegister SrcReg = getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg,
1456 ExtInstSetReg, MAI);
1458 MCRegister LineReg =
1459 emitOpConstantI32(
static_cast<uint32_t
>(GV->
getLine()), I32TypeReg, MAI);
1463 MCRegister ColReg = emitOpConstantI32(0, I32TypeReg, MAI);
1470 MCRegister VariableReg = CachedDebugInfoNoneReg;
1471 if (
const GlobalVariable *LLVMGV =
Info.LLVMGV) {
1474 VariableReg = GVReg;
1475 }
else if (
Info.Expr &&
Info.Expr->getNumElements() != 0) {
1476 if (
auto ExprReg = emitDebugExpression(
Info.Expr, VoidTypeReg, I32TypeReg,
1477 ExtInstSetReg, MAI))
1478 VariableReg = *ExprReg;
1481 MCRegister FlagsReg = emitOpConstantI32(transDebugFlags(GV), I32TypeReg, MAI);
1484 LineReg, ColReg, ParentReg,
1485 LinkageReg, VariableReg, FlagsReg};
1487 if (StaticMemberRegOpt)
1488 Ops.push_back(*StaticMemberRegOpt);
1490 return emitExtInst(SPIRV::NonSemanticExtInst::DebugGlobalVariable,
1491 VoidTypeReg, ExtInstSetReg,
Ops, MAI);
1494std::optional<MCRegister> SPIRVNonSemanticDebugHandler::emitDebugLocalVariable(
1497 assert(LV &&
"LV must not be null in emitDebugLocalVariable");
1499 EmitResult<MCRegister> Parent = resolveScope(LV->
getScope());
1501 return std::nullopt;
1503 MCRegister TyReg = CachedDebugInfoNoneReg;
1504 if (
const DIType *Ty = LV->
getType()) {
1505 auto TyRegOpt = lookupOptReg(DebugScopeRegs, Ty);
1507 return std::nullopt;
1511 MCRegister NameReg = getCachedOpStringReg(LV->
getName());
1512 MCRegister FileStrReg = getCachedScopePathOpStringReg(
1514 MCRegister SrcReg = getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg,
1515 ExtInstSetReg, MAI);
1516 MCRegister LineReg =
1517 emitOpConstantI32(
static_cast<uint32_t
>(LV->
getLine()), I32TypeReg, MAI);
1519 MCRegister ColReg = emitOpConstantI32(0, I32TypeReg, MAI);
1520 MCRegister FlagsReg = emitOpConstantI32(transDebugFlags(LV), I32TypeReg, MAI);
1523 ColReg, *Parent.Value, FlagsReg};
1524 if (
unsigned Arg = LV->
getArg())
1525 Ops.push_back(emitOpConstantI32(Arg, I32TypeReg, MAI));
1527 return emitExtInst(SPIRV::NonSemanticExtInst::DebugLocalVariable, VoidTypeReg,
1528 ExtInstSetReg,
Ops, MAI);
1531auto SPIRVNonSemanticDebugHandler::emitDebugTypeVector(
1533 -> EmitResult<PreparedScope> {
1536 return EmitResult<PreparedScope>::unsupported();
1540 DINodeArray
Elements = VT->getElements();
1542 return EmitResult<PreparedScope>::unsupported();
1546 return EmitResult<PreparedScope>::unsupported();
1548 EmitResult<MCRegister>
Base = getOrCreateDebugScope(BaseTy);
1550 return EmitResult<PreparedScope>::failure(
Base);
1552 MCRegister I32TypeReg = getOrEmitOpTypeInt32Reg(MAI);
1554 static_cast<uint32_t
>(CI->getZExtValue()), I32TypeReg, MAI);
1555 return EmitResult<PreparedScope>::emitted(PreparedScope{
1556 SPIRV::NonSemanticExtInst::DebugTypeVector, {*
Base.Value, CountReg}});
1559auto SPIRVNonSemanticDebugHandler::emitDebugTypeArray(
1561 -> EmitResult<PreparedScope> {
1564 EmitResult<MCRegister>
Base = getOrCreateDebugScope(AT->getBaseType());
1566 return EmitResult<PreparedScope>::failure(
Base);
1568 MCRegister I32TypeReg = getOrEmitOpTypeInt32Reg(MAI);
1576 for (
const DINode *Element : AT->getElements()) {
1588 if (
Value.getActiveBits() <= 32)
1589 Count =
static_cast<uint32_t
>(
Value.getZExtValue());
1591 Ops.push_back(emitOpConstantI32(
Count, I32TypeReg, MAI));
1594 return EmitResult<PreparedScope>::emitted(
1595 PreparedScope{SPIRV::NonSemanticExtInst::DebugTypeArray,
Ops});
1598auto SPIRVNonSemanticDebugHandler::emitDebugTypeMember(
1601 -> EmitResult<PreparedScope> {
1602 EmitResult<MCRegister> Ty = getOrCreateDebugScope(
M->getBaseType());
1604 return EmitResult<PreparedScope>::failure(Ty);
1607 return EmitResult<PreparedScope>::unsupported();
1609 MCRegister NameReg = getCachedOpStringReg(
M->getName());
1610 MCRegister FileStrReg = getCachedScopePathOpStringReg(
1611 M->getFile(),
true);
1612 MCRegister SrcReg = getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg,
1613 ExtInstSetReg, MAI);
1615 emitOpConstantI32(
static_cast<uint32_t
>(
M->getLine()), I32TypeReg, MAI);
1618 MCRegister ColReg = emitOpConstantI32(0, I32TypeReg, MAI);
1620 static_cast<uint32_t
>(
M->getOffsetInBits()), I32TypeReg, MAI);
1622 static_cast<uint32_t
>(
M->getSizeInBits()), I32TypeReg, MAI);
1623 MCRegister FlagsReg = emitOpConstantI32(transDebugFlags(M), I32TypeReg, MAI);
1634 return EmitResult<PreparedScope>::emitted(
1635 PreparedScope{SPIRV::NonSemanticExtInst::DebugTypeMember,
1636 {NameReg, *Ty.Value, SrcReg, LineReg, ColReg, OffsetReg,
1637 SizeReg, FlagsReg}});
1640auto SPIRVNonSemanticDebugHandler::emitDebugTypeComposite(
1643 -> EmitResult<PreparedScope> {
1646 EmitResult<MCRegister> Parent =
resolveScope(CT->getScope());
1648 return EmitResult<PreparedScope>::failure(Parent);
1651 return EmitResult<PreparedScope>::unsupported();
1654 for (
const DINode *Element : CT->getElements()) {
1656 if (!M ||
M->getTag() != dwarf::DW_TAG_member)
1658 EmitResult<MCRegister>
Member = getOrCreateDebugScope(M);
1663 MCRegister NameReg = getCachedOpStringReg(CT->getName());
1664 MCRegister LinkageReg = getCachedOpStringReg(CT->getIdentifier());
1665 MCRegister FileStrReg = getCachedScopePathOpStringReg(
1666 CT->getFile(),
true);
1667 MCRegister SrcReg = getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg,
1668 ExtInstSetReg, MAI);
1671 emitOpConstantI32(mapCompositeTypeTag(CT->getTag()), I32TypeReg, MAI);
1673 emitOpConstantI32(
static_cast<uint32_t
>(CT->getLine()), I32TypeReg, MAI);
1674 MCRegister ColReg = emitOpConstantI32(0, I32TypeReg, MAI);
1678 if (!CT->isForwardDecl())
1679 SizeReg = emitOpConstantI32(
static_cast<uint32_t
>(CT->getSizeInBits()),
1682 MCRegister FlagsReg = emitOpConstantI32(transDebugFlags(CT), I32TypeReg, MAI);
1685 LineReg, ColReg, *Parent.Value,
1686 LinkageReg, SizeReg, FlagsReg};
1688 return EmitResult<PreparedScope>::emitted(
1689 PreparedScope{SPIRV::NonSemanticExtInst::DebugTypeComposite,
Ops});
1692auto SPIRVNonSemanticDebugHandler::emitDebugTypeEnum(
1695 -> EmitResult<PreparedScope> {
1699 return EmitResult<PreparedScope>::unsupported();
1702 getOrCreateDebugTypeOrNone(ET->getBaseType());
1704 return EmitResult<PreparedScope>::failure(Underlying);
1706 EmitResult<MCRegister> Parent =
1707 resolveScope(ET->getScope(), EnumCompileUnits.lookup(ET));
1709 return EmitResult<PreparedScope>::failure(Parent);
1711 MCRegister NameReg = getCachedOpStringReg(ET->getName());
1712 MCRegister FileStrReg = getCachedScopePathOpStringReg(
1713 ET->getFile(),
true);
1714 MCRegister SrcReg = getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg,
1715 ExtInstSetReg, MAI);
1717 emitOpConstantI32(
static_cast<uint32_t
>(ET->getLine()), I32TypeReg, MAI);
1719 MCRegister ColReg = emitOpConstantI32(0, I32TypeReg, MAI);
1721 emitOpConstantI32(
static_cast<uint32_t
>(
Size), I32TypeReg, MAI);
1722 MCRegister FlagsReg = emitOpConstantI32(transDebugFlags(ET), I32TypeReg, MAI);
1725 ColReg, *Parent.Value, SizeReg, FlagsReg};
1730 for (
const DINode *Element : ET->getElements()) {
1735 if (
E->isUnsigned() ? !
Value.isIntN(32) : !
Value.isSignedIntN(32))
1737 uint32_t
Bits =
E->isUnsigned()
1738 ?
static_cast<uint32_t
>(
Value.getZExtValue())
1739 :
static_cast<uint32_t
>(
Value.getSExtValue());
1740 Ops.push_back(emitOpConstantI32(Bits, I32TypeReg, MAI));
1741 Ops.push_back(getCachedOpStringReg(
E->getName()));
1744 return EmitResult<PreparedScope>::emitted(
1745 PreparedScope{SPIRV::NonSemanticExtInst::DebugTypeEnum,
Ops});
1748auto SPIRVNonSemanticDebugHandler::emitDebugTypedef(
1751 -> EmitResult<PreparedScope> {
1752 EmitResult<MCRegister>
Base = getOrCreateDebugScope(TD->getBaseType());
1754 return EmitResult<PreparedScope>::failure(
Base);
1756 MCRegister NameReg = getCachedOpStringReg(TD->getName());
1757 MCRegister FileStrReg = getCachedScopePathOpStringReg(
1758 TD->getFile(),
true);
1759 MCRegister SrcReg = getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg,
1760 ExtInstSetReg, MAI);
1762 emitOpConstantI32(
static_cast<uint32_t
>(TD->getLine()), I32TypeReg, MAI);
1764 MCRegister ColReg = emitOpConstantI32(0, I32TypeReg, MAI);
1769 EmitResult<MCRegister> Parent =
resolveScope(TD->getScope());
1771 return EmitResult<PreparedScope>::failure(Parent);
1773 return EmitResult<PreparedScope>::emitted(PreparedScope{
1774 SPIRV::NonSemanticExtInst::DebugTypedef,
1775 {NameReg, *
Base.Value, SrcReg, LineReg, ColReg, *Parent.Value}});
1780 if (CompileUnits.empty())
1788 for (
const CompileUnitInfo &Info : CompileUnits) {
1790 MCRegister PathReg = emitOpStringIfNew(Info.FilePath, MAI);
1791 ScopeToPathOpStringReg[Info.TheCU] = PathReg;
1792 if (
const DIFile *
F = Info.TheCU->getFile())
1793 ScopeToPathOpStringReg[
F] = PathReg;
1798 emitOpStringIfNew(SP->getName(), MAI);
1799 emitOpStringIfNew(SP->getLinkageName(), MAI);
1800 emitAndCacheScopePathOpStringReg(SP, MAI);
1803 for (
const DIType *Ty : DebugTypes) {
1805 emitOpStringIfNew(
BT->getName(), MAI);
1811 if (CT->getTag() == dwarf::DW_TAG_enumeration_type) {
1812 emitOpStringIfNew(CT->getName(), MAI);
1813 emitAndCacheScopePathOpStringReg(CT->getFile(), MAI);
1814 for (
const DINode *Element : CT->getElements())
1816 emitOpStringIfNew(E->getName(), MAI);
1822 if (CT->getTag() != dwarf::DW_TAG_structure_type &&
1823 CT->getTag() != dwarf::DW_TAG_class_type &&
1824 CT->getTag() != dwarf::DW_TAG_union_type)
1826 emitOpStringIfNew(CT->getName(), MAI);
1827 emitOpStringIfNew(CT->getIdentifier(), MAI);
1828 emitAndCacheScopePathOpStringReg(CT->getFile(), MAI);
1829 for (
const DINode *Element : CT->getElements()) {
1831 if (!M || M->getTag() != dwarf::DW_TAG_member)
1833 emitOpStringIfNew(M->getName(), MAI);
1834 emitAndCacheScopePathOpStringReg(M->getFile(), MAI);
1840 if (TD && TD->getTag() == dwarf::DW_TAG_typedef) {
1841 emitOpStringIfNew(TD->getName(), MAI);
1842 emitAndCacheScopePathOpStringReg(TD->getFile(), MAI);
1846 for (
const auto &[GV,
_] : GlobalVariableDebugInfoMap) {
1847 emitOpStringIfNew(GV->
getName(), MAI);
1849 emitAndCacheScopePathOpStringReg(GV->
getFile(), MAI);
1853 emitOpStringIfNew(LV->
getName(), MAI);
1854 emitAndCacheScopePathOpStringReg(LV->
getFile(), MAI);
1857 for (
const DIScope *S : LexicalBlocks) {
1858 emitAndCacheScopePathOpStringReg(S->getFile(), MAI);
1860 emitOpStringIfNew(NS->getName(), MAI);
1864 emitAndCacheScopePathOpStringReg(
DL->getScope(), MAI);
1866 CachedEmptyStringReg = emitOpStringIfNew(
"", MAI);
1869 NonSemanticOpStringsSectionEmitted =
true;
1873void SPIRVNonSemanticDebugHandler::emitDebugFunctionDefinition(
1877 "DebugFunctionDefinition operands must be valid");
1878 MCRegister VoidTypeReg = getOrEmitOpTypeVoidReg(MAI);
1880 emitExtInst(SPIRV::NonSemanticExtInst::DebugFunctionDefinition, VoidTypeReg,
1881 ExtInstSetReg, {DebugFunctionReg, OpFunctionReg}, MAI);
1884void SPIRVNonSemanticDebugHandler::resetPerFunctionDebugState() {
1885 CurrentMF =
nullptr;
1886 LastFunctionOpVariable =
nullptr;
1887 DebugFunctionDefinitionEmitted =
false;
1888 LastLineMI =
nullptr;
1889 LastScopeMI =
nullptr;
1893void SPIRVNonSemanticDebugHandler::preparePerFunctionDebug(
1895 resetPerFunctionDebugState();
1896 if (!GlobalNSDIEnabled || !CurrentMAI)
1907 if (!SP || !
SP->isDefinition())
1912 LastFunctionOpVariable =
1913 findLastFunctionOpVariableDeclaration(*MF, *CurrentMAI);
1915 analyzeDebugRecords(*MF);
1918void SPIRVNonSemanticDebugHandler::tryEmitDebugFunctionDefinition(
1920 if (DebugFunctionDefinitionEmitted || !GlobalNSDIEnabled)
1923 assert(CurrentMF &&
"no current MachineFunction");
1924 const Function &
F = CurrentMF->getFunction();
1925 const DISubprogram *
SP =
F.getSubprogram();
1926 if (!SP || !
SP->isDefinition())
1929 auto DFIt = DebugScopeRegs.find(SP);
1930 if (DFIt == DebugScopeRegs.end())
1937 emitDebugFunctionDefinition(DFIt->second, OpFunctionReg, MAI);
1938 DebugFunctionDefinitionEmitted =
true;
1943 preparePerFunctionDebug(MF);
1948 resetPerFunctionDebugState();
1955 if (!DebugFunctionDefinitionEmitted)
1958 emitAnalyzedRecords(
MI);
1960 std::optional<const MachineInstr *>
Target = resolveDebugLocTarget(
MI);
1964 (void)emitDebugScopeForInstruction(*
Target);
1965 emitDebugLineForInstruction(*
Target);
1975static std::optional<Register>
1979 if (!
MI.isIndirectDebugValue())
1980 return std::nullopt;
1984 Register LocReg =
MI.getDebugOperand(0).getReg();
1986 return std::nullopt;
1997 const MachineInstr *Def =
MI.getMF()->getRegInfo().getUniqueVRegDef(LocReg);
1998 if (!Def || Def->getOpcode() != SPIRV::OpVariable)
1999 return std::nullopt;
2004void SPIRVNonSemanticDebugHandler::emitDebugBinding(
2005 SPIRV::NonSemanticExtInst::NonSemanticExtInst Opcode,
2007 assert(DebugFunctionDefinitionEmitted &&
2008 "DebugFunctionDefinition must be emitted");
2009 assert(CurrentMAI &&
"CurrentMAI must be set");
2011 auto VarRegOpt = lookupOptReg(DebugLocalVariableRegs,
MI->getDebugVariable());
2015 auto ExprRegOpt = lookupOptReg(DebugExpressionRegs,
MI->getDebugExpression());
2019 if (!emitDebugScopeForInstruction(
MI))
2021 emitDebugLineForInstruction(
MI);
2023 SPIRV::ModuleAnalysisInfo &MAI = *CurrentMAI;
2024 MCRegister VoidTypeReg = getOrEmitOpTypeVoidReg(MAI);
2026 emitExtInst(Opcode, VoidTypeReg, ExtInstSetReg,
2027 {*VarRegOpt, LocationReg, *ExprRegOpt}, MAI);
2032static std::optional<std::pair<const DIBasicType *, uint64_t>>
2034 if (!
MI.isNonListDebugValue() ||
MI.isIndirectDebugValue())
2035 return std::nullopt;
2039 return std::nullopt;
2044 return std::nullopt;
2049 else if (
Value.isCImm())
2053 return std::make_pair(
BT, Bits);
2056std::optional<MCRegister> SPIRVNonSemanticDebugHandler::getConstantValueReg(
2058 std::optional<std::pair<const DIBasicType *, uint64_t>>
Const =
2061 return std::nullopt;
2063 auto It = ConstantValueRegs.find(*Const);
2064 if (It == ConstantValueRegs.end() || !It->second.isValid())
2065 return std::nullopt;
2070 if (!
MI.isNonListDebugValue() ||
MI.isIndirectDebugValue())
2071 return std::nullopt;
2075 return std::nullopt;
2079 return std::nullopt;
2081 const MachineInstr *Def =
MI.getMF()->getRegInfo().getUniqueVRegDef(ValueReg);
2082 if (!Def || (Def->isPseudo() && !Def->isPHI()) || Def->isMetaInstruction() ||
2083 Def->getNumOperands() == 0 || !Def->getOperand(0).isReg() ||
2084 !Def->getOperand(0).isDef() || Def->getOperand(0).getReg() != ValueReg)
2085 return std::nullopt;
2091 return Opcode == SPIRV::OpSelectionMerge || Opcode == SPIRV::OpLoopMerge ||
2092 Opcode == SPIRV::OpLoopControlINTEL;
2104 switch (
MI->getOpcode()) {
2105 case SPIRV::OpFunction:
2106 case SPIRV::OpFunctionParameter:
2107 case SPIRV::OpFunctionEnd:
2108 case SPIRV::OpLabel:
2109 case TargetOpcode::PHI:
2120 :
MI->getPrevNode();
2121 Adj; Adj = Forward ? Adj->getNextNode() : Adj->getPrevNode()) {
2129std::optional<const MachineInstr *>
2130SPIRVNonSemanticDebugHandler::resolveDebugLocTarget(
const MachineInstr *
MI) {
2131 assert(CurrentMAI &&
"CurrentMAI must be set");
2132 SPIRV::ModuleAnalysisInfo &MAI = *CurrentMAI;
2137 return std::nullopt;
2145 return std::nullopt;
2151 assert(
MI &&
"Merge instruction must be followed by a terminator");
2155 return std::nullopt;
2161void SPIRVNonSemanticDebugHandler::resolveDebugRecord(
2164 SPIRV::ModuleAnalysisInfo &MAI = *CurrentMAI;
2170 const MachineInstr *Anchor =
2180 placeRecord(SPIRV::NonSemanticExtInst::DebugDeclare,
MI, StorageReg,
2185 if (std::optional<MCRegister> ConstReg = getConstantValueReg(
MI)) {
2186 placeRecord(SPIRV::NonSemanticExtInst::DebugValue,
MI, *ConstReg, Anchor);
2206 if (ModuleScopeIds.contains(ValueReg) ||
2208 placeRecord(SPIRV::NonSemanticExtInst::DebugValue,
MI, ValueReg, Anchor);
2211void SPIRVNonSemanticDebugHandler::analyzeDebugRecords(
2213 assert(CurrentMAI &&
"CurrentMAI must be set");
2217 std::optional<MachineDominatorTree> DomTree;
2219 for (
const MachineBasicBlock &
MBB : MF) {
2220 const MachineInstr *LastEmitted =
nullptr;
2221 for (
const MachineInstr &
MI :
MBB) {
2222 if (
MI.isDebugValueLike()) {
2225 resolveDebugRecord(
MI, LastEmitted, *DomTree);
2234void SPIRVNonSemanticDebugHandler::placeRecord(
2235 SPIRV::NonSemanticExtInst::NonSemanticExtInst Opcode,
2238 Records[Anchor].push_back({&
MI, Opcode, LocationReg});
2241void SPIRVNonSemanticDebugHandler::emitAnalyzedRecords(
2243 auto It = Records.find(Anchor);
2244 if (It == Records.end())
2246 for (
const DebugRecord &R : It->second)
2247 emitDebugBinding(
R.Opcode,
R.MI,
R.LocationReg);
2250bool SPIRVNonSemanticDebugHandler::emitDebugScopeForInstruction(
2252 assert(DebugFunctionDefinitionEmitted &&
2253 "DebugFunctionDefinition must be emitted");
2254 assert(CurrentMAI &&
"CurrentMAI must be set");
2259 if (LastScopeMI &&
MI->getParent() != LastScopeMI->getParent())
2260 LastScopeMI =
nullptr;
2262 SPIRV::ModuleAnalysisInfo &MAI = *CurrentMAI;
2263 MCRegister VoidTypeReg = getOrEmitOpTypeVoidReg(MAI);
2266 const DILocation *CurDL =
MI->getDebugLoc().get();
2271 emitExtInst(SPIRV::NonSemanticExtInst::DebugNoScope, VoidTypeReg,
2272 ExtInstSetReg, {}, MAI);
2273 LastScopeMI =
nullptr;
2278 const DIScope *CurScope = CurDL->getScope();
2279 const DILocation *CurInlinedAt = CurDL->getInlinedAt();
2282 const DILocation *LastDL = LastScopeMI->getDebugLoc().get();
2283 if (LastDL->getScope() == CurScope &&
2284 LastDL->getInlinedAt() == CurInlinedAt)
2288 EmitResult<MCRegister> CurScopeRes = resolveScope(CurScope);
2295 MCRegister InlinedReg = DebugInlinedAtRegs.lookup(CurInlinedAt);
2298 Ops.push_back(InlinedReg);
2302 emitExtInst(SPIRV::NonSemanticExtInst::DebugScope, VoidTypeReg, ExtInstSetReg,
2309void SPIRVNonSemanticDebugHandler::emitDebugLineForInstruction(
2311 assert(DebugFunctionDefinitionEmitted &&
2312 "DebugFunctionDefinition must be emitted");
2313 assert(CurrentMAI &&
"CurrentMAI must be set");
2318 if (LastLineMI &&
MI->getParent() != LastLineMI->getParent())
2319 LastLineMI =
nullptr;
2321 SPIRV::ModuleAnalysisInfo &MAI = *CurrentMAI;
2322 MCRegister VoidTypeReg = getOrEmitOpTypeVoidReg(MAI);
2325 const DILocation *
DL =
MI->getDebugLoc().get();
2330 emitExtInst(SPIRV::NonSemanticExtInst::DebugNoLine, VoidTypeReg,
2331 ExtInstSetReg, {}, MAI);
2332 LastLineMI =
nullptr;
2342 MCRegister FileStrReg = getCachedScopePathOpStringReg(
2343 DL->getScope(),
true);
2344 unsigned Line =
DL->getLine();
2345 unsigned Col =
DL->getColumn();
2347 unsigned I32TypeId = CachedOpTypeInt32Reg.id();
2348 MCRegister SrcReg = DebugSourceRegByFileStr.lookup(FileStrReg.
id());
2349 MCRegister LineReg = ScalarConstantCache.lookup({I32TypeId,
Line});
2350 MCRegister ColStartReg = ScalarConstantCache.lookup({I32TypeId, Col});
2351 MCRegister ColEndReg = ScalarConstantCache.lookup({I32TypeId, Col + 1});
2363 if (LastLineMI &&
MI->getDebugLoc() == LastLineMI->getDebugLoc())
2367 emitExtInst(SPIRV::NonSemanticExtInst::DebugLine, VoidTypeReg, ExtInstSetReg,
2368 {SrcReg, LineReg, LineReg, ColStartReg, ColEndReg}, MAI);
2377 if (!
MI || !GlobalNSDIEnabled || !CurrentMF)
2380 if (DebugFunctionDefinitionEmitted ||
MI != LastFunctionOpVariable)
2386 assert(CurrentMAI &&
"CurrentMAI must be set");
2387 tryEmitDebugFunctionDefinition(*CurrentMAI);
2392 if (!GlobalNSDIEnabled || DebugFunctionDefinitionEmitted || !CurrentMF)
2395 assert(CurrentMF == &MF &&
2396 "notification does not match the current MachineFunction");
2398 if (LastFunctionOpVariable)
2404 tryEmitDebugFunctionDefinition(*CurrentMAI);
2407void SPIRVNonSemanticDebugHandler::collectDebugExpressions(
2411 Out.insert(
MI->getDebugExpression());
2416 if (GlobalDIEmitted)
2419 GlobalDIEmitted =
true;
2421 if (CompileUnits.empty()) {
2422 GlobalNSDIEnabled =
false;
2428 if (!ExtInstSetReg.
isValid()) {
2429 GlobalNSDIEnabled =
false;
2434 assert(NonSemanticOpStringsSectionEmitted &&
2435 "emitNonSemanticDebugStrings() must run before "
2436 "emitNonSemanticGlobalDebugInfo()");
2441 MCRegister VoidTypeReg = getOrEmitOpTypeVoidReg(MAI);
2442 MCRegister I32TypeReg = getOrEmitOpTypeInt32Reg(MAI);
2444 CachedDebugInfoNoneReg = emitExtInst(SPIRV::NonSemanticExtInst::DebugInfoNone,
2445 VoidTypeReg, ExtInstSetReg, {}, MAI);
2457 MCRegister DebugInfoVersionReg = emitOpConstantI32(100, I32TypeReg, MAI);
2459 emitOpConstantI32(
static_cast<uint32_t>(DwarfVersion), I32TypeReg, MAI);
2464 map_to_vector(CompileUnits, [&](
const CompileUnitInfo &Info) {
2465 return emitOpConstantI32(Info.SpirvSourceLanguage, I32TypeReg, MAI);
2469 for (
auto [Info, SrcLangReg] :
llvm::zip(CompileUnits, SrcLangRegs)) {
2470 MCRegister FileStrReg = ScopeToPathOpStringReg.lookup(Info.TheCU);
2472 "CU path OpString must be emitted in emitNonSemanticDebugStrings");
2473 MCRegister DebugSourceReg = getOrEmitDebugSourceForFileStrReg(
2474 FileStrReg, VoidTypeReg, ExtInstSetReg, MAI);
2476 SPIRV::NonSemanticExtInst::DebugCompilationUnit, VoidTypeReg,
2478 {DebugInfoVersionReg, DwarfVersionReg, DebugSourceReg, SrcLangReg},
2481 DebugScopeRegs[Info.TheCU] = CUDbgReg;
2486 getOrCreateDebugScope(S);
2491 if (
auto LVReg = emitDebugLocalVariable(LV, VoidTypeReg, I32TypeReg,
2492 ExtInstSetReg, MAI))
2493 DebugLocalVariableRegs[LV] = *LVReg;
2500 collectDebugExpressions(MAI, Expressions);
2502 if (
auto ExprReg = emitDebugExpression(Expr, VoidTypeReg, I32TypeReg,
2503 ExtInstSetReg, MAI))
2504 DebugExpressionRegs[Expr] = *ExprReg;
2507 for (
const auto &[GV, Info] : GlobalVariableDebugInfoMap)
2508 emitDebugGlobalVariable(GV, Info, VoidTypeReg, I32TypeReg, ExtInstSetReg,
2514 getOrEmitDebugInlinedAt(IA, VoidTypeReg, I32TypeReg, ExtInstSetReg, MAI);
2519 std::optional<std::pair<const DIBasicType *, uint64_t>> Const =
2523 if (!DebugLocalVariableRegs.contains(
MI->getDebugVariable()) ||
2524 !DebugExpressionRegs.contains(
MI->getDebugExpression()))
2526 auto [It, Inserted] = ConstantValueRegs.try_emplace(*Const,
MCRegister());
2528 It->second = findOrEmitScalarConstant(Const->first, Const->second, MAI);
2529 if (!It->second.isValid())
2530 ConstantValueRegs.erase(It);
2534 emitOpConstantI32(
DL->getLine(), I32TypeReg, MAI);
2535 emitOpConstantI32(
DL->getColumn(), I32TypeReg, MAI);
2536 emitOpConstantI32(
DL->getColumn() + 1, I32TypeReg, MAI);
2538 getCachedScopePathOpStringReg(
DL->getScope(),
2540 getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg, ExtInstSetReg,
2544 GlobalNSDIEnabled =
true;
2548SPIRVNonSemanticDebugHandler::getDebugFullPath(
const DIScope *Scope)
const {
2558 Out.assign(Dir.
begin(), Dir.
end());
2564MCRegister SPIRVNonSemanticDebugHandler::getOrEmitDebugSourceForFileStrReg(
2567 const unsigned Key = FileStrReg.
id();
2568 auto It = DebugSourceRegByFileStr.find(
Key);
2569 if (It != DebugSourceRegByFileStr.end())
2572 MCRegister
DS = emitExtInst(SPIRV::NonSemanticExtInst::DebugSource,
2573 VoidTypeReg, ExtInstSetReg, {FileStrReg}, MAI);
2574 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 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< Register > getDebugDeclareStorageReg(const MachineInstr &MI)
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 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.
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. Should be passed by value.
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 emitNonSemanticDebugStrings(SPIRV::ModuleAnalysisInfo &MAI)
Emit OpString instructions for all NSDI file paths and basic type names into the debug section (secti...
void beginModule(Module *M) override
Collect compile-unit metadata from the module.
void endFunctionImpl(const MachineFunction *MF) override
void beginFunctionImpl(const MachineFunction *MF) override
void emitNonSemanticGlobalDebugInfo(SPIRV::ModuleAnalysisInfo &MAI)
Emit module-scope NSDI instructions (DebugSource, DebugCompilationUnit, DebugTypeBasic,...
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 endInstruction() override
Process end of an instruction.
void notifyEntryLabelEmitted(const MachineFunction &MF)
Called after the synthesized entry OpLabel has been emitted.
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...
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.
Target - Wrapper for Target specific information.
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.
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)