LLVM: lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
54
55namespace llvm {
56namespace dxil {
57
58
60#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
61#include "llvm/IR/Metadata.def"
64
66
67
68
69
70 enum {
71
73 VST_ENTRY_7_ABBREV,
74 VST_ENTRY_6_ABBREV,
75 VST_BBENTRY_6_ABBREV,
76
77
79 CONSTANTS_INTEGER_ABBREV,
80 CONSTANTS_CE_CAST_Abbrev,
81 CONSTANTS_NULL_Abbrev,
82
83
85 FUNCTION_INST_BINOP_ABBREV,
86 FUNCTION_INST_BINOP_FLAGS_ABBREV,
87 FUNCTION_INST_CAST_ABBREV,
88 FUNCTION_INST_RET_VOID_ABBREV,
89 FUNCTION_INST_RET_VAL_ABBREV,
90 FUNCTION_INST_UNREACHABLE_ABBREV,
91 FUNCTION_INST_GEP_ABBREV,
92 };
93
94
96 Type *I8PtrTy;
97
98
100
102
103
105
106
108
109
110
111
112 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
113
114
115 unsigned GlobalValueId;
116
117
118
119 uint64_t VSTOffsetPlaceholder = 0;
120
121
123
124
126
127
129
130public:
131
132
135 : I8Ty(Type::getInt8Ty(M.getContext())),
137 StrtabBuilder(StrtabBuilder), M(M), VE(M, I8PtrTy), Buffer(Buffer),
138 BitcodeStartBit(Stream.GetCurrentBitNo()),
139 PointerMap(PointerTypeAnalysis::run(M)) {
140 GlobalValueId = VE.getValues().size();
141
142 for (auto El : PointerMap)
144 }
145
146
148
151 StringRef Str, unsigned AbbrevToUse);
155
168
169private:
170 void writeModuleVersion();
171 void writePerModuleGlobalValueSummary();
172
175 unsigned ValueID,
176 unsigned FSCallsAbbrev,
177 unsigned FSCallsProfileAbbrev,
179 void writeModuleLevelReferences(const GlobalVariable &V,
181 unsigned FSModRefsAbbrev,
182 unsigned FSModVTableRefsAbbrev);
183
185 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
186 }
187
189 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
190
191
192 assert(VMI != GUIDToValueIdMap.end() &&
193 "GUID does not have assigned value Id");
194 return VMI->second;
195 }
196
197
198 unsigned getValueId(ValueInfo VI) {
199 if (!VI.haveGVs() || !VI.getValue())
200 return getValueId(VI.getGUID());
202 }
203
204 std::map<GlobalValue::GUID, unsigned> &valueIds() { return GUIDToValueIdMap; }
205
206 uint64_t bitcodeStartBit() { return BitcodeStartBit; }
207
208 size_t addToStrtab(StringRef Str);
209
210 unsigned createDILocationAbbrev();
211 unsigned createGenericDINodeAbbrev();
212
213 void writeAttributeGroupTable();
214 void writeAttributeTable();
215 void writeTypeTable();
216 void writeComdats();
217 void writeValueSymbolTableForwardDecl();
218 void writeModuleInfo();
222 unsigned Abbrev);
224 unsigned &Abbrev);
228 }
230 unsigned Abbrev);
233 unsigned Abbrev) {
234 llvm_unreachable("DXIL cannot contain DIGenericSubrange Nodes");
235 }
239 unsigned Abbrev);
243 }
250 unsigned Abbrev);
252 unsigned Abbrev);
261 unsigned Abbrev);
265 }
267 unsigned Abbrev);
269 unsigned Abbrev) {
271 }
273 unsigned Abbrev) {
275 }
277 unsigned Abbrev) {
279 }
281 unsigned Abbrev) {
282
283
284
286 }
288 unsigned Abbrev);
291 unsigned Abbrev);
294 unsigned Abbrev);
297 unsigned Abbrev);
301 unsigned Abbrev) {
303 }
308 unsigned Abbrev) {
309 llvm_unreachable("DXIL cannot contain GlobalVariableExpression Nodes");
310 }
315 unsigned Abbrev);
316 unsigned createNamedMetadataAbbrev();
318 unsigned createMetadataStringsAbbrev();
323 std::vector *MDAbbrevs = nullptr,
324 std::vector<uint64_t> *IndexPos = nullptr);
325 void writeModuleMetadata();
326 void writeFunctionMetadata(const Function &F);
327 void writeFunctionMetadataAttachment(const Function &F);
330 void writeModuleMetadataKinds();
331 void writeOperandBundleTags();
332 void writeSyncScopeNames();
333 void writeConstants(unsigned FirstVal, unsigned LastVal, bool isGlobal);
334 void writeModuleConstants();
335 bool pushValueAndType(const Value *V, unsigned InstID,
337 void writeOperandBundles(const CallBase &CB, unsigned InstID);
338 void pushValue(const Value *V, unsigned InstID,
340 void pushValueSigned(const Value *V, unsigned InstID,
342 void writeInstruction(const Instruction &I, unsigned InstID,
344 void writeFunctionLevelValueSymbolTable(const ValueSymbolTable &VST);
345 void writeGlobalValueSymbolTable(
347 void writeFunction(const Function &F);
348 void writeBlockInfo();
349
351
352 unsigned getEncodedAlign(MaybeAlign Alignment) { return encode(Alignment); }
353
354 unsigned getTypeID(Type *T, const Value *V = nullptr);
355
356
357
358
360};
361
362}
363}
364
365using namespace llvm;
367
368
369
370
371
374
375 Stream->Emit((unsigned)'B', 8);
376 Stream->Emit((unsigned)'C', 8);
377 Stream->Emit(0x0, 4);
378 Stream->Emit(0xC, 4);
379 Stream->Emit(0xE, 4);
380 Stream->Emit(0xD, 4);
381}
382
384
385
388 Buffer.reserve(256 * 1024);
389
390
391
392 Triple TT(M.getTargetTriple());
393 if (TT.isOSDarwin() || TT.isOSBinFormatMachO())
395
398
399
400 if (!Buffer.empty())
402}
403
404void BitcodeWriter::writeBlob(unsigned Block, unsigned Record, StringRef Blob) {
406
407 auto Abbv = std::make_shared();
410 auto AbbrevNo = Stream->EmitAbbrev(std::move(Abbv));
411
413
415}
416
418
419
420
421
422
423 assert(M.isMaterialized());
424 Mods.push_back(const_cast<Module *>(&M));
425
426 DXILBitcodeWriter ModuleWriter(M, Buffer, StrtabBuilder, *Stream);
427 ModuleWriter.write();
428}
429
430
431
432
433
435 switch (Opcode) {
436 default:
438 case Instruction::Trunc:
440 case Instruction::ZExt:
442 case Instruction::SExt:
444 case Instruction::FPToUI:
446 case Instruction::FPToSI:
448 case Instruction::UIToFP:
450 case Instruction::SIToFP:
452 case Instruction::FPTrunc:
454 case Instruction::FPExt:
456 case Instruction::PtrToInt:
458 case Instruction::IntToPtr:
460 case Instruction::BitCast:
462 case Instruction::AddrSpaceCast:
464 }
465}
466
468 switch (Opcode) {
469 default:
471 case Instruction::FNeg:
473 }
474}
475
477 switch (Opcode) {
478 default:
480 case Instruction::Add:
481 case Instruction::FAdd:
483 case Instruction::Sub:
484 case Instruction::FSub:
486 case Instruction::Mul:
487 case Instruction::FMul:
489 case Instruction::UDiv:
491 case Instruction::FDiv:
492 case Instruction::SDiv:
494 case Instruction::URem:
496 case Instruction::FRem:
497 case Instruction::SRem:
499 case Instruction::Shl:
501 case Instruction::LShr:
503 case Instruction::AShr:
505 case Instruction::And:
507 case Instruction::Or:
509 case Instruction::Xor:
511 }
512}
513
514unsigned DXILBitcodeWriter::getTypeID(Type *T, const Value *V) {
515 if (->isPointerTy() &&
516
517
518 (!V || !isa(V)))
520 auto It = PointerMap.find(V);
521 if (It != PointerMap.end())
523
524
525
526
527 if (V && isa(V) && !isa(V))
530}
531
532unsigned DXILBitcodeWriter::getGlobalObjectValueTypeID(Type *T,
534 auto It = PointerMap.find(G);
535 if (It != PointerMap.end()) {
536 TypedPointerType *PtrTy = cast(It->second);
538 }
540}
541
543 switch (Op) {
544 default:
576 }
577}
578
580 switch (Ordering) {
595 }
597}
598
601 unsigned AbbrevToUse) {
603
604
605 for (char C : Str) {
607 AbbrevToUse = 0;
609 }
610
611
612 Stream.EmitRecord(Code, Vals, AbbrevToUse);
613}
614
616 switch (Kind) {
617 case Attribute::Alignment:
619 case Attribute::AlwaysInline:
621 case Attribute::Builtin:
623 case Attribute::ByVal:
625 case Attribute::Convergent:
627 case Attribute::InAlloca:
629 case Attribute::Cold:
631 case Attribute::InlineHint:
633 case Attribute::InReg:
635 case Attribute::JumpTable:
637 case Attribute::MinSize:
639 case Attribute::Naked:
641 case Attribute::Nest:
643 case Attribute::NoAlias:
645 case Attribute::NoBuiltin:
647 case Attribute::NoCapture:
649 case Attribute::NoDuplicate:
651 case Attribute::NoImplicitFloat:
653 case Attribute::NoInline:
655 case Attribute::NonLazyBind:
657 case Attribute::NonNull:
659 case Attribute::Dereferenceable:
661 case Attribute::DereferenceableOrNull:
663 case Attribute::NoRedZone:
665 case Attribute::NoReturn:
667 case Attribute::NoUnwind:
669 case Attribute::OptimizeForSize:
671 case Attribute::OptimizeNone:
673 case Attribute::ReadNone:
675 case Attribute::ReadOnly:
677 case Attribute::Returned:
679 case Attribute::ReturnsTwice:
681 case Attribute::SExt:
683 case Attribute::StackAlignment:
685 case Attribute::StackProtect:
687 case Attribute::StackProtectReq:
689 case Attribute::StackProtectStrong:
691 case Attribute::SafeStack:
693 case Attribute::StructRet:
695 case Attribute::SanitizeAddress:
697 case Attribute::SanitizeThread:
699 case Attribute::SanitizeMemory:
701 case Attribute::UWTable:
703 case Attribute::ZExt:
706 llvm_unreachable("Can not encode end-attribute kinds marker.");
712 default:
713 llvm_unreachable("Trying to encode attribute not supported by DXIL. These "
714 "should be stripped in DXILPrepare");
715 }
716
718}
719
722 if ((int64_t)V >= 0)
724 else
726}
727
730
731
732
733
734 unsigned NumWords = A.getActiveWords();
735 const uint64_t *RawData = A.getRawData();
736 for (unsigned i = 0; i < NumWords; i++)
738}
739
742
743 if (const auto *OBO = dyn_cast(V)) {
744 if (OBO->hasNoSignedWrap())
746 if (OBO->hasNoUnsignedWrap())
748 } else if (const auto *PEO = dyn_cast(V)) {
749 if (PEO->isExact())
751 } else if (const auto *FPMO = dyn_cast(V)) {
752 if (FPMO->hasAllowReassoc() || FPMO->hasAllowContract())
754 if (FPMO->hasNoNaNs())
756 if (FPMO->hasNoInfs())
758 if (FPMO->hasNoSignedZeros())
760 if (FPMO->hasAllowReciprocal())
762 }
763
764 return Flags;
765}
766
767unsigned
769 switch (Linkage) {
771 return 0;
773 return 16;
775 return 2;
777 return 3;
779 return 18;
781 return 7;
783 return 8;
785 return 9;
787 return 17;
789 return 19;
791 return 12;
792 }
794}
795
798}
799
803 return 0;
805 return 1;
807 return 2;
808 }
810}
811
815 return 0;
817 return 1;
819 return 2;
820 }
822}
823
827 return 0;
829 return 1;
831 return 2;
833 return 3;
835 return 4;
836 }
838}
839
841 switch (C.getSelectionKind()) {
852 }
854}
855
856
857
858
859
860void DXILBitcodeWriter::writeAttributeGroupTable() {
861 const std::vectorValueEnumerator::IndexAndAttrSet &AttrGrps =
863 if (AttrGrps.empty())
864 return;
865
867
870 unsigned AttrListIndex = Pair.first;
873 Record.push_back(AttrListIndex);
874
876 if (Attr.isEnumAttribute()) {
879 "DXIL does not support attributes above ATTR_KIND_ARGMEMONLY");
881 Record.push_back(Val);
882 } else if (Attr.isIntAttribute()) {
883 if (Attr.getKindAsEnum() == Attribute::AttrKind::Memory) {
888 } else {
892 }
896 }
897 }
898 } else {
901 "DXIL does not support attributes above ATTR_KIND_ARGMEMONLY");
903 Record.push_back(Val);
904 Record.push_back(Attr.getValueAsInt());
905 }
906 } else {
908 StringRef Val = Attr.getValueAsString();
909
913 if (!Val.empty()) {
916 }
917 }
918 }
919
922 }
923
925}
926
927void DXILBitcodeWriter::writeAttributeTable() {
929 if (Attrs.empty())
930 return;
931
933
936 for (unsigned i : AL.indexes()) {
940 }
941
944 }
945
947}
948
949
950void DXILBitcodeWriter::writeTypeTable() {
952
955
957
958
959 auto Abbv = std::make_shared();
963 unsigned PtrAbbrev = Stream.EmitAbbrev(std::move(Abbv));
964
965
966 Abbv = std::make_shared();
971 unsigned FunctionAbbrev = Stream.EmitAbbrev(std::move(Abbv));
972
973
974 Abbv = std::make_shared();
979 unsigned StructAnonAbbrev = Stream.EmitAbbrev(std::move(Abbv));
980
981
982 Abbv = std::make_shared();
986 unsigned StructNameAbbrev = Stream.EmitAbbrev(std::move(Abbv));
987
988
989 Abbv = std::make_shared();
994 unsigned StructNamedAbbrev = Stream.EmitAbbrev(std::move(Abbv));
995
996
997 Abbv = std::make_shared();
1001 unsigned ArrayAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1002
1003
1004 TypeVals.push_back(TypeList.size());
1006 TypeVals.clear();
1007
1008
1009 for (Type *T : TypeList) {
1010 int AbbrevToUse = 0;
1011 unsigned Code = 0;
1012
1013 switch (T->getTypeID()) {
1019 break;
1022 break;
1025 break;
1028 break;
1031 break;
1034 break;
1037 break;
1040 break;
1043 break;
1046 break;
1048
1051 break;
1054
1060 AbbrevToUse = PtrAbbrev;
1061 break;
1062 }
1064
1065
1066
1067
1071 "dxilOpaquePtrReservedName", StructNameAbbrev);
1072 break;
1073 }
1076
1078 TypeVals.push_back(FT->isVarArg());
1079 TypeVals.push_back(getTypeID(FT->getReturnType()));
1080 for (Type *PTy : FT->params())
1081 TypeVals.push_back(getTypeID(PTy));
1082 AbbrevToUse = FunctionAbbrev;
1083 break;
1084 }
1087
1089
1090 for (Type *ElTy : ST->elements())
1091 TypeVals.push_back(getTypeID(ElTy));
1092
1093 if (ST->isLiteral()) {
1095 AbbrevToUse = StructAnonAbbrev;
1096 } else {
1097 if (ST->isOpaque()) {
1099 } else {
1101 AbbrevToUse = StructNamedAbbrev;
1102 }
1103
1104
1105 if (->getName().empty())
1107 StructNameAbbrev);
1108 }
1109 break;
1110 }
1113
1115 TypeVals.push_back(AT->getNumElements());
1116 TypeVals.push_back(getTypeID(AT->getElementType()));
1117 AbbrevToUse = ArrayAbbrev;
1118 break;
1119 }
1123
1125 TypeVals.push_back(VT->getElementCount().getKnownMinValue());
1126 TypeVals.push_back(getTypeID(VT->getElementType()));
1127 break;
1128 }
1129 }
1130
1131
1132 Stream.EmitRecord(Code, TypeVals, AbbrevToUse);
1133 TypeVals.clear();
1134 }
1135
1137}
1138
1139void DXILBitcodeWriter::writeComdats() {
1142
1144 size_t Size = C->getName().size();
1147 for (char Chr : C->getName())
1148 Vals.push_back((unsigned char)Chr);
1151 }
1152}
1153
1154void DXILBitcodeWriter::writeValueSymbolTableForwardDecl() {}
1155
1156
1157
1158
1159void DXILBitcodeWriter::writeModuleInfo() {
1160
1161 if (.getTargetTriple().empty())
1163 0 );
1164 const std::string &DL = M.getDataLayoutStr();
1167 if (.getModuleInlineAsm().empty())
1169 0 );
1170
1171
1172
1173 std::map<std::string, unsigned> SectionMap;
1174 std::map<std::string, unsigned> GCMap;
1176 unsigned MaxGlobalType = 0;
1177 const auto UpdateMaxAlignment = [&MaxAlignment](const MaybeAlign A) {
1178 if (A)
1179 MaxAlignment = !MaxAlignment ? *A : std::max(*MaxAlignment, *A);
1180 };
1182 UpdateMaxAlignment(GV.getAlign());
1183
1184
1185 MaxGlobalType = std::max(
1186 MaxGlobalType, getGlobalObjectValueTypeID(GV.getValueType(), &GV));
1187 if (GV.hasSection()) {
1188
1189 unsigned &Entry = SectionMap[std::string(GV.getSection())];
1190 if (!Entry) {
1192 GV.getSection(), 0 );
1193 Entry = SectionMap.size();
1194 }
1195 }
1196 }
1198 UpdateMaxAlignment(F.getAlign());
1199 if (F.hasSection()) {
1200
1201 unsigned &Entry = SectionMap[std::string(F.getSection())];
1202 if (!Entry) {
1204 0 );
1205 Entry = SectionMap.size();
1206 }
1207 }
1208 if (F.hasGC()) {
1209
1210 unsigned &Entry = GCMap[F.getGC()];
1211 if (!Entry) {
1213 0 );
1214 Entry = GCMap.size();
1215 }
1216 }
1217 }
1218
1219
1220 unsigned SimpleGVarAbbrev = 0;
1221 if (.global_empty()) {
1222
1223
1224 auto Abbv = std::make_shared();
1229
1230
1233 if (!MaxAlignment)
1235 else {
1236 unsigned MaxEncAlignment = getEncodedAlign(MaxAlignment);
1239 }
1240 if (SectionMap.empty())
1242 else
1245
1246 SimpleGVarAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1247 }
1248
1249
1252 unsigned AbbrevToUse = 0;
1253
1254
1255
1256
1257
1258 Vals.push_back(getGlobalObjectValueTypeID(GV.getValueType(), &GV));
1260 GV.getType()->getAddressSpace() << 2 | 2 |
1261 (GV.isConstant() ? 1 : 0));
1262
1264 GV.isDeclaration() ? 0 : (VE.getValueID(GV.getInitializer()) + 1));
1266 Vals.push_back(getEncodedAlign(GV.getAlign()));
1267 Vals.push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1268 : 0);
1269 if (GV.isThreadLocal() ||
1272 GV.isExternallyInitialized() ||
1274 GV.hasComdat()) {
1278 Vals.push_back(GV.isExternallyInitialized());
1281 } else {
1282 AbbrevToUse = SimpleGVarAbbrev;
1283 }
1284
1287 }
1288
1289
1291
1292
1293
1294 Vals.push_back(getGlobalObjectValueTypeID(F.getFunctionType(), &F));
1299 Vals.push_back(getEncodedAlign(F.getAlign()));
1300 Vals.push_back(F.hasSection() ? SectionMap[std::string(F.getSection())]
1301 : 0);
1303 Vals.push_back(F.hasGC() ? GCMap[F.getGC()] : 0);
1306 F.hasPrologueData() ? (VE.getValueID(F.getPrologueData()) + 1) : 0);
1310 : 0);
1312 F.hasPersonalityFn() ? (VE.getValueID(F.getPersonalityFn()) + 1) : 0);
1313
1314 unsigned AbbrevToUse = 0;
1317 }
1318
1319
1321
1322 Vals.push_back(getTypeID(A.getValueType(), &A));
1329 unsigned AbbrevToUse = 0;
1332 }
1333}
1334
1335void DXILBitcodeWriter::writeValueAsMetadata(
1337
1340 if (Function *F = dyn_cast(V))
1342 else if (GlobalVariable *GV = dyn_cast(V))
1344 Record.push_back(getTypeID(Ty, V));
1348}
1349
1350void DXILBitcodeWriter::writeMDTuple(const MDTuple *N,
1352 unsigned Abbrev) {
1353 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
1354 Metadata *MD = N->getOperand(i);
1355 assert(!(MD && isa(MD)) &&
1356 "Unexpected function-local metadata");
1358 }
1363}
1364
1365void DXILBitcodeWriter::writeDILocation(const DILocation *N,
1367 unsigned &Abbrev) {
1368 if (!Abbrev)
1369 Abbrev = createDILocationAbbrev();
1370 Record.push_back(N->isDistinct());
1371 Record.push_back(N->getLine());
1372 Record.push_back(N->getColumn());
1375
1378}
1379
1383 return I < 0 ? ~(U << 1) : U << 1;
1384}
1385
1386void DXILBitcodeWriter::writeDISubrange(const DISubrange *N,
1388 unsigned Abbrev) {
1389 Record.push_back(N->isDistinct());
1390
1391
1392
1393 ConstantInt *Count = dyn_cast<ConstantInt *>(N->getCount());
1394 assert(Count && "Count is missing or not ConstantInt");
1396
1397
1398 DISubrange::BoundType LowerBound = N->getLowerBound();
1399 assert((LowerBound.isNull() || isa<ConstantInt *>(LowerBound)) &&
1400 "Lower bound provided but not ConstantInt");
1402 LowerBound ? rotateSign(cast<ConstantInt *>(LowerBound)->getValue()) : 0);
1403
1406}
1407
1408void DXILBitcodeWriter::writeDIEnumerator(const DIEnumerator *N,
1410 unsigned Abbrev) {
1411 Record.push_back(N->isDistinct());
1414
1417}
1418
1419void DXILBitcodeWriter::writeDIBasicType(const DIBasicType *N,
1421 unsigned Abbrev) {
1422 Record.push_back(N->isDistinct());
1423 Record.push_back(N->getTag());
1425 Record.push_back(N->getSizeInBits());
1426 Record.push_back(N->getAlignInBits());
1427 Record.push_back(N->getEncoding());
1428
1431}
1432
1433void DXILBitcodeWriter::writeDIDerivedType(const DIDerivedType *N,
1435 unsigned Abbrev) {
1436 Record.push_back(N->isDistinct());
1437 Record.push_back(N->getTag());
1440 Record.push_back(N->getLine());
1443 Record.push_back(N->getSizeInBits());
1444 Record.push_back(N->getAlignInBits());
1445 Record.push_back(N->getOffsetInBits());
1446 Record.push_back(N->getFlags());
1448
1451}
1452
1453void DXILBitcodeWriter::writeDICompositeType(const DICompositeType *N,
1455 unsigned Abbrev) {
1456 Record.push_back(N->isDistinct());
1457 Record.push_back(N->getTag());
1460 Record.push_back(N->getLine());
1463 Record.push_back(N->getSizeInBits());
1464 Record.push_back(N->getAlignInBits());
1465 Record.push_back(N->getOffsetInBits());
1466 Record.push_back(N->getFlags());
1468 Record.push_back(N->getRuntimeLang());
1472
1475}
1476
1477void DXILBitcodeWriter::writeDISubroutineType(const DISubroutineType *N,
1479 unsigned Abbrev) {
1480 Record.push_back(N->isDistinct());
1481 Record.push_back(N->getFlags());
1483
1486}
1487
1488void DXILBitcodeWriter::writeDIFile(const DIFile *N,
1490 unsigned Abbrev) {
1491 Record.push_back(N->isDistinct());
1494
1497}
1498
1499void DXILBitcodeWriter::writeDICompileUnit(const DICompileUnit *N,
1501 unsigned Abbrev) {
1502 Record.push_back(N->isDistinct());
1503 Record.push_back(N->getSourceLanguage());
1506 Record.push_back(N->isOptimized());
1508 Record.push_back(N->getRuntimeVersion());
1510 Record.push_back(N->getEmissionKind());
1513 Record.push_back( 0);
1516 Record.push_back(N->getDWOId());
1517
1520}
1521
1522void DXILBitcodeWriter::writeDISubprogram(const DISubprogram *N,
1524 unsigned Abbrev) {
1525 Record.push_back(N->isDistinct());
1530 Record.push_back(N->getLine());
1532 Record.push_back(N->isLocalToUnit());
1533 Record.push_back(N->isDefinition());
1534 Record.push_back(N->getScopeLine());
1536 Record.push_back(N->getVirtuality());
1537 Record.push_back(N->getVirtualIndex());
1538 Record.push_back(N->getFlags());
1539 Record.push_back(N->isOptimized());
1544
1547}
1548
1549void DXILBitcodeWriter::writeDILexicalBlock(const DILexicalBlock *N,
1551 unsigned Abbrev) {
1552 Record.push_back(N->isDistinct());
1555 Record.push_back(N->getLine());
1556 Record.push_back(N->getColumn());
1557
1560}
1561
1562void DXILBitcodeWriter::writeDILexicalBlockFile(
1564 unsigned Abbrev) {
1565 Record.push_back(N->isDistinct());
1568 Record.push_back(N->getDiscriminator());
1569
1572}
1573
1574void DXILBitcodeWriter::writeDINamespace(const DINamespace *N,
1576 unsigned Abbrev) {
1577 Record.push_back(N->isDistinct());
1581 Record.push_back( 0);
1582
1585}
1586
1587void DXILBitcodeWriter::writeDIModule(const DIModule *N,
1589 unsigned Abbrev) {
1590 Record.push_back(N->isDistinct());
1591 for (auto &I : N->operands())
1593
1596}
1597
1598void DXILBitcodeWriter::writeDITemplateTypeParameter(
1600 unsigned Abbrev) {
1601 Record.push_back(N->isDistinct());
1604
1607}
1608
1609void DXILBitcodeWriter::writeDITemplateValueParameter(
1611 unsigned Abbrev) {
1612 Record.push_back(N->isDistinct());
1613 Record.push_back(N->getTag());
1617
1620}
1621
1622void DXILBitcodeWriter::writeDIGlobalVariable(const DIGlobalVariable *N,
1624 unsigned Abbrev) {
1625 Record.push_back(N->isDistinct());
1630 Record.push_back(N->getLine());
1632 Record.push_back(N->isLocalToUnit());
1633 Record.push_back(N->isDefinition());
1634 Record.push_back( 0);
1636
1639}
1640
1641void DXILBitcodeWriter::writeDILocalVariable(const DILocalVariable *N,
1643 unsigned Abbrev) {
1644 Record.push_back(N->isDistinct());
1645 Record.push_back(N->getTag());
1649 Record.push_back(N->getLine());
1651 Record.push_back(N->getArg());
1652 Record.push_back(N->getFlags());
1653
1656}
1657
1658void DXILBitcodeWriter::writeDIExpression(const DIExpression *N,
1660 unsigned Abbrev) {
1661 Record.reserve(N->getElements().size() + 1);
1662
1663 Record.push_back(N->isDistinct());
1664 Record.append(N->elements_begin(), N->elements_end());
1665
1668}
1669
1670void DXILBitcodeWriter::writeDIObjCProperty(const DIObjCProperty *N,
1672 unsigned Abbrev) {
1674}
1675
1676void DXILBitcodeWriter::writeDIImportedEntity(const DIImportedEntity *N,
1678 unsigned Abbrev) {
1679 Record.push_back(N->isDistinct());
1680 Record.push_back(N->getTag());
1683 Record.push_back(N->getLine());
1685
1688}
1689
1690unsigned DXILBitcodeWriter::createDILocationAbbrev() {
1691
1692
1693
1694
1695 std::shared_ptr Abbv = std::make_shared();
1702 return Stream.EmitAbbrev(std::move(Abbv));
1703}
1704
1705unsigned DXILBitcodeWriter::createGenericDINodeAbbrev() {
1706
1707
1708
1709
1710 std::shared_ptr Abbv = std::make_shared();
1718 return Stream.EmitAbbrev(std::move(Abbv));
1719}
1720
1723 std::vector *MDAbbrevs,
1724 std::vector<uint64_t> *IndexPos) {
1725 if (MDs.empty())
1726 return;
1727
1728
1729#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
1730#include "llvm/IR/Metadata.def"
1731
1732 for (const Metadata *MD : MDs) {
1733 if (IndexPos)
1735 if (const MDNode *N = dyn_cast(MD)) {
1736 assert(N->isResolved() && "Expected forward references to be resolved");
1737
1738 switch (N->getMetadataID()) {
1739 default:
1741#define HANDLE_MDNODE_LEAF(CLASS) \
1742 case Metadata::CLASS##Kind: \
1743 if (MDAbbrevs) \
1744 write##CLASS(cast(N), Record, \
1745 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
1746 else \
1747 write##CLASS(cast(N), Record, CLASS##Abbrev); \
1748 continue;
1749#include "llvm/IR/Metadata.def"
1750 }
1751 }
1752 writeValueAsMetadata(cast(MD), Record);
1753 }
1754}
1755
1756unsigned DXILBitcodeWriter::createMetadataStringsAbbrev() {
1757 auto Abbv = std::make_shared();
1761 return Stream.EmitAbbrev(std::move(Abbv));
1762}
1763
1764void DXILBitcodeWriter::writeMetadataStrings(
1766 if (Strings.empty())
1767 return;
1768
1769 unsigned MDSAbbrev = createMetadataStringsAbbrev();
1770
1771 for (const Metadata *MD : Strings) {
1772 const MDString *MDS = cast(MD);
1773
1775
1776
1779 }
1780}
1781
1782void DXILBitcodeWriter::writeModuleMetadata() {
1783 if (!VE.hasMDs() && M.named_metadata_empty())
1784 return;
1785
1787
1788
1789
1790 std::vector MDAbbrevs;
1791
1793 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
1794 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
1795 createGenericDINodeAbbrev();
1796
1797 unsigned NameAbbrev = 0;
1798 if (.named_metadata_empty()) {
1799
1800 std::shared_ptr Abbv = std::make_shared();
1804 NameAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1805 }
1806
1809
1810 std::vector<uint64_t> IndexPos;
1813
1814
1815 for (const NamedMDNode &NMD : M.named_metadata()) {
1816
1818 Record.append(Str.bytes_begin(), Str.bytes_end());
1821
1822
1823 for (const MDNode *N : NMD.operands())
1827 }
1828
1830}
1831
1832void DXILBitcodeWriter::writeFunctionMetadata(const Function &F) {
1834 return;
1835
1841}
1842
1843void DXILBitcodeWriter::writeFunctionMetadataAttachment(const Function &F) {
1845
1847
1848
1849
1851 F.getAllMetadata(MDs);
1852 if (!MDs.empty()) {
1853 for (const auto &I : MDs) {
1854 Record.push_back(I.first);
1856 }
1859 }
1860
1863 MDs.clear();
1864 I.getAllMetadataOtherThanDebugLoc(MDs);
1865
1866
1867 if (MDs.empty())
1868 continue;
1869
1871
1872 for (unsigned i = 0, e = MDs.size(); i != e; ++i) {
1873 Record.push_back(MDs[i].first);
1875 }
1878 }
1879
1881}
1882
1883void DXILBitcodeWriter::writeModuleMetadataKinds() {
1885
1886
1887
1889 M.getMDKindNames(Names);
1890
1891 if (Names.empty())
1892 return;
1893
1895
1896 for (unsigned MDKindID = 0, e = Names.size(); MDKindID != e; ++MDKindID) {
1897 Record.push_back(MDKindID);
1898 StringRef KName = Names[MDKindID];
1900
1903 }
1904
1906}
1907
1908void DXILBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal,
1909 bool isGlobal) {
1910 if (FirstVal == LastVal)
1911 return;
1912
1914
1915 unsigned AggregateAbbrev = 0;
1916 unsigned String8Abbrev = 0;
1917 unsigned CString7Abbrev = 0;
1918 unsigned CString6Abbrev = 0;
1919
1920 if (isGlobal) {
1921
1922 auto Abbv = std::make_shared();
1925 Abbv->Add(
1927 AggregateAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1928
1929
1930 Abbv = std::make_shared();
1934 String8Abbrev = Stream.EmitAbbrev(std::move(Abbv));
1935
1936 Abbv = std::make_shared();
1940 CString7Abbrev = Stream.EmitAbbrev(std::move(Abbv));
1941
1942 Abbv = std::make_shared();
1946 CString6Abbrev = Stream.EmitAbbrev(std::move(Abbv));
1947 }
1948
1950
1952 Type *LastTy = nullptr;
1953 for (unsigned i = FirstVal; i != LastVal; ++i) {
1954 const Value *V = Vals[i].first;
1955
1956 if (V->getType() != LastTy) {
1957 LastTy = V->getType();
1958 Record.push_back(getTypeID(LastTy, V));
1960 CONSTANTS_SETTYPE_ABBREV);
1962 }
1963
1964 if (const InlineAsm *IA = dyn_cast(V)) {
1965 Record.push_back(unsigned(IA->hasSideEffects()) |
1966 unsigned(IA->isAlignStack()) << 1 |
1967 unsigned(IA->getDialect() & 1) << 2);
1968
1969
1970 const std::string &AsmStr = IA->getAsmString();
1971 Record.push_back(AsmStr.size());
1972 Record.append(AsmStr.begin(), AsmStr.end());
1973
1974
1975 const std::string &ConstraintStr = IA->getConstraintString();
1976 Record.push_back(ConstraintStr.size());
1977 Record.append(ConstraintStr.begin(), ConstraintStr.end());
1980 continue;
1981 }
1982 const Constant *C = cast(V);
1983 unsigned Code = -1U;
1984 unsigned AbbrevToUse = 0;
1985 if (C->isNullValue()) {
1987 } else if (isa(C)) {
1989 } else if (const ConstantInt *IV = dyn_cast(C)) {
1990 if (IV->getBitWidth() <= 64) {
1994 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
1995 } else {
1996
1997
1998
1999
2000 unsigned NWords = IV->getValue().getActiveWords();
2001 const uint64_t *RawWords = IV->getValue().getRawData();
2002 for (unsigned i = 0; i != NWords; ++i) {
2004 }
2006 }
2007 } else if (const ConstantFP *CFP = dyn_cast(C)) {
2009 Type *Ty = CFP->getType();
2011 Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2013
2014
2015 APInt api = CFP->getValueAPF().bitcastToAPInt();
2017 Record.push_back((p[1] << 48) | (p[0] >> 16));
2018 Record.push_back(p[0] & 0xffffLL);
2020 APInt api = CFP->getValueAPF().bitcastToAPInt();
2022 Record.push_back(p[0]);
2023 Record.push_back(p[1]);
2024 } else {
2025 assert(0 && "Unknown FP type!");
2026 }
2027 } else if (isa(C) &&
2028 cast(C)->isString()) {
2030
2031 unsigned NumElts = Str->getNumElements();
2032
2033 if (Str->isCString()) {
2035 --NumElts;
2036 } else {
2038 AbbrevToUse = String8Abbrev;
2039 }
2042 for (unsigned i = 0; i != NumElts; ++i) {
2043 unsigned char V = Str->getElementAsInteger(i);
2044 Record.push_back(V);
2045 isCStr7 &= (V & 128) == 0;
2046 if (isCStrChar6)
2048 }
2049
2050 if (isCStrChar6)
2051 AbbrevToUse = CString6Abbrev;
2052 else if (isCStr7)
2053 AbbrevToUse = CString7Abbrev;
2055 dyn_cast(C)) {
2057 Type *EltTy = CDS->getElementType();
2058 if (isa(EltTy)) {
2059 for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2060 Record.push_back(CDS->getElementAsInteger(i));
2061 } else if (EltTy->isFloatTy()) {
2062 for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
2063 union {
2064 float F;
2066 };
2067 F = CDS->getElementAsFloat(i);
2069 }
2070 } else {
2071 assert(EltTy->isDoubleTy() && "Unknown ConstantData element type");
2072 for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
2073 union {
2074 double F;
2076 };
2077 F = CDS->getElementAsDouble(i);
2079 }
2080 }
2081 } else if (isa(C) || isa(C) ||
2082 isa(C)) {
2084 for (const Value *Op : C->operands())
2086 AbbrevToUse = AggregateAbbrev;
2087 } else if (const ConstantExpr *CE = dyn_cast(C)) {
2088 switch (CE->getOpcode()) {
2089 default:
2094 getTypeID(C->getOperand(0)->getType(), C->getOperand(0)));
2096 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2097 } else {
2098 assert(CE->getNumOperands() == 2 && "Unknown constant expr!");
2104 if (Flags != 0)
2105 Record.push_back(Flags);
2106 }
2107 break;
2108 case Instruction::GetElementPtr: {
2110 const auto *GO = cast(C);
2111 if (GO->isInBounds())
2113 Record.push_back(getTypeID(GO->getSourceElementType()));
2114 for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i) {
2116 getTypeID(C->getOperand(i)->getType(), C->getOperand(i)));
2118 }
2119 break;
2120 }
2121 case Instruction::Select:
2126 break;
2127 case Instruction::ExtractElement:
2129 Record.push_back(getTypeID(C->getOperand(0)->getType()));
2131 Record.push_back(getTypeID(C->getOperand(1)->getType()));
2133 break;
2134 case Instruction::InsertElement:
2138 Record.push_back(getTypeID(C->getOperand(2)->getType()));
2140 break;
2141 case Instruction::ShuffleVector:
2142
2143
2144
2145
2146 if (C->getType() == C->getOperand(0)->getType()) {
2148 } else {
2150 Record.push_back(getTypeID(C->getOperand(0)->getType()));
2151 }
2155 break;
2156 }
2157 } else if (const BlockAddress *BA = dyn_cast(C)) {
2159 Record.push_back(getTypeID(BA->getFunction()->getType()));
2162 } else {
2163#ifndef NDEBUG
2164 C->dump();
2165#endif
2167 }
2170 }
2171
2173}
2174
2175void DXILBitcodeWriter::writeModuleConstants() {
2177
2178
2179
2180 for (unsigned i = 0, e = Vals.size(); i != e; ++i) {
2181 if (!isa(Vals[i].first)) {
2182 writeConstants(i, Vals.size(), true);
2183 return;
2184 }
2185 }
2186}
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196bool DXILBitcodeWriter::pushValueAndType(const Value *V, unsigned InstID,
2199
2201 if (ValID >= InstID) {
2202 Vals.push_back(getTypeID(V->getType(), V));
2203 return true;
2204 }
2205 return false;
2206}
2207
2208
2209
2210void DXILBitcodeWriter::pushValue(const Value *V, unsigned InstID,
2214}
2215
2216void DXILBitcodeWriter::pushValueSigned(const Value *V, unsigned InstID,
2219 int64_t diff = ((int32_t)InstID - (int32_t)ValID);
2221}
2222
2223
2224void DXILBitcodeWriter::writeInstruction(const Instruction &I, unsigned InstID,
2226 unsigned Code = 0;
2227 unsigned AbbrevToUse = 0;
2229 switch (I.getOpcode()) {
2230 default:
2233 if (!pushValueAndType(I.getOperand(0), InstID, Vals))
2234 AbbrevToUse = (unsigned)FUNCTION_INST_CAST_ABBREV;
2235 Vals.push_back(getTypeID(I.getType(), &I));
2237 } else {
2238 assert(isa(I) && "Unknown instruction!");
2240 if (!pushValueAndType(I.getOperand(0), InstID, Vals))
2241 AbbrevToUse = (unsigned)FUNCTION_INST_BINOP_ABBREV;
2242 pushValue(I.getOperand(1), InstID, Vals);
2245 if (Flags != 0) {
2246 if (AbbrevToUse == (unsigned)FUNCTION_INST_BINOP_ABBREV)
2247 AbbrevToUse = (unsigned)FUNCTION_INST_BINOP_FLAGS_ABBREV;
2249 }
2250 }
2251 break;
2252
2253 case Instruction::GetElementPtr: {
2255 AbbrevToUse = (unsigned)FUNCTION_INST_GEP_ABBREV;
2256 auto &GEPInst = cast(I);
2257 Vals.push_back(GEPInst.isInBounds());
2258 Vals.push_back(getTypeID(GEPInst.getSourceElementType()));
2259 for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i)
2260 pushValueAndType(I.getOperand(i), InstID, Vals);
2261 break;
2262 }
2263 case Instruction::ExtractValue: {
2265 pushValueAndType(I.getOperand(0), InstID, Vals);
2268 break;
2269 }
2270 case Instruction::InsertValue: {
2272 pushValueAndType(I.getOperand(0), InstID, Vals);
2273 pushValueAndType(I.getOperand(1), InstID, Vals);
2276 break;
2277 }
2278 case Instruction::Select:
2280 pushValueAndType(I.getOperand(1), InstID, Vals);
2281 pushValue(I.getOperand(2), InstID, Vals);
2282 pushValueAndType(I.getOperand(0), InstID, Vals);
2283 break;
2284 case Instruction::ExtractElement:
2286 pushValueAndType(I.getOperand(0), InstID, Vals);
2287 pushValueAndType(I.getOperand(1), InstID, Vals);
2288 break;
2289 case Instruction::InsertElement:
2291 pushValueAndType(I.getOperand(0), InstID, Vals);
2292 pushValue(I.getOperand(1), InstID, Vals);
2293 pushValueAndType(I.getOperand(2), InstID, Vals);
2294 break;
2295 case Instruction::ShuffleVector:
2297 pushValueAndType(I.getOperand(0), InstID, Vals);
2298 pushValue(I.getOperand(1), InstID, Vals);
2299 pushValue(cast(&I)->getShuffleMaskForBitcode(), InstID,
2300 Vals);
2301 break;
2302 case Instruction::ICmp:
2303 case Instruction::FCmp: {
2304
2306 pushValueAndType(I.getOperand(0), InstID, Vals);
2307 pushValue(I.getOperand(1), InstID, Vals);
2310 if (Flags != 0)
2312 break;
2313 }
2314
2315 case Instruction::Ret: {
2317 unsigned NumOperands = I.getNumOperands();
2318 if (NumOperands == 0)
2319 AbbrevToUse = (unsigned)FUNCTION_INST_RET_VOID_ABBREV;
2320 else if (NumOperands == 1) {
2321 if (!pushValueAndType(I.getOperand(0), InstID, Vals))
2322 AbbrevToUse = (unsigned)FUNCTION_INST_RET_VAL_ABBREV;
2323 } else {
2324 for (unsigned i = 0, e = NumOperands; i != e; ++i)
2325 pushValueAndType(I.getOperand(i), InstID, Vals);
2326 }
2327 } break;
2328 case Instruction::Br: {
2332 if (II.isConditional()) {
2334 pushValue(II.getCondition(), InstID, Vals);
2335 }
2336 } break;
2337 case Instruction::Switch: {
2340 Vals.push_back(getTypeID(SI.getCondition()->getType()));
2341 pushValue(SI.getCondition(), InstID, Vals);
2343 for (auto Case : SI.cases()) {
2346 }
2347 } break;
2348 case Instruction::IndirectBr:
2350 Vals.push_back(getTypeID(I.getOperand(0)->getType()));
2351
2352 pushValue(I.getOperand(0), InstID, Vals);
2353 for (unsigned i = 1, e = I.getNumOperands(); i != e; ++i)
2355 break;
2356
2357 case Instruction::Invoke: {
2362
2364 Vals.push_back(II->getCallingConv() | 1 << 13);
2368 pushValueAndType(Callee, InstID, Vals);
2369
2370
2371 for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
2372 pushValue(I.getOperand(i), InstID, Vals);
2373
2374
2375 if (FTy->isVarArg()) {
2376 for (unsigned i = FTy->getNumParams(), e = I.getNumOperands() - 3; i != e;
2377 ++i)
2378 pushValueAndType(I.getOperand(i), InstID, Vals);
2379 }
2380 break;
2381 }
2382 case Instruction::Resume:
2384 pushValueAndType(I.getOperand(0), InstID, Vals);
2385 break;
2386 case Instruction::Unreachable:
2388 AbbrevToUse = (unsigned)FUNCTION_INST_UNREACHABLE_ABBREV;
2389 break;
2390
2391 case Instruction::PHI: {
2392 const PHINode &PN = cast(I);
2394
2395
2396
2402 }
2403
2404 Stream.EmitRecord(Code, Vals64, AbbrevToUse);
2406 return;
2407 }
2408
2409 case Instruction::LandingPad: {
2418 else
2420 pushValueAndType(LP.getClause(I), InstID, Vals);
2421 }
2422 break;
2423 }
2424
2425 case Instruction::Alloca: {
2427 const AllocaInst &AI = cast(I);
2429 Vals.push_back(getTypeID(I.getOperand(0)->getType()));
2432 assert(AlignRecord < 1 << 5 && "alignment greater than 1 << 64");
2434 AlignRecord |= 1 << 6;
2436 break;
2437 }
2438
2439 case Instruction::Load:
2440 if (cast(I).isAtomic()) {
2442 pushValueAndType(I.getOperand(0), InstID, Vals);
2443 } else {
2445 if (!pushValueAndType(I.getOperand(0), InstID, Vals))
2446 AbbrevToUse = (unsigned)FUNCTION_INST_LOAD_ABBREV;
2447 }
2448 Vals.push_back(getTypeID(I.getType()));
2450 Vals.push_back(cast(I).isVolatile());
2451 if (cast(I).isAtomic()) {
2453 Vals.push_back(getEncodedSyncScopeID(cast(I).getSyncScopeID()));
2454 }
2455 break;
2456 case Instruction::Store:
2457 if (cast(I).isAtomic())
2459 else
2461 pushValueAndType(I.getOperand(1), InstID, Vals);
2462 pushValueAndType(I.getOperand(0), InstID, Vals);
2464 Vals.push_back(cast(I).isVolatile());
2465 if (cast(I).isAtomic()) {
2468 getEncodedSyncScopeID(cast(I).getSyncScopeID()));
2469 }
2470 break;
2471 case Instruction::AtomicCmpXchg:
2473 pushValueAndType(I.getOperand(0), InstID, Vals);
2474 pushValueAndType(I.getOperand(1), InstID, Vals);
2475 pushValue(I.getOperand(2), InstID, Vals);
2476 Vals.push_back(cast(I).isVolatile());
2480 getEncodedSyncScopeID(cast(I).getSyncScopeID()));
2483 Vals.push_back(cast(I).isWeak());
2484 break;
2485 case Instruction::AtomicRMW:
2487 pushValueAndType(I.getOperand(0), InstID, Vals);
2488 pushValue(I.getOperand(1), InstID, Vals);
2491 Vals.push_back(cast(I).isVolatile());
2494 getEncodedSyncScopeID(cast(I).getSyncScopeID()));
2495 break;
2496 case Instruction::Fence:
2499 Vals.push_back(getEncodedSyncScopeID(cast(I).getSyncScopeID()));
2500 break;
2501 case Instruction::Call: {
2502 const CallInst &CI = cast(I);
2504
2506
2511 pushValueAndType(CI.getCalledOperand(), InstID, Vals);
2512
2513
2514 for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
2515
2516 if (FTy->getParamType(i)->isLabelTy())
2518 else
2519 pushValue(CI.getArgOperand(i), InstID, Vals);
2520 }
2521
2522
2523 if (FTy->isVarArg()) {
2524 for (unsigned i = FTy->getNumParams(), e = CI.arg_size(); i != e; ++i)
2525 pushValueAndType(CI.getArgOperand(i), InstID, Vals);
2526 }
2527 break;
2528 }
2529 case Instruction::VAArg:
2531 Vals.push_back(getTypeID(I.getOperand(0)->getType()));
2532 pushValue(I.getOperand(0), InstID, Vals);
2533 Vals.push_back(getTypeID(I.getType()));
2534 break;
2535 }
2536
2537 Stream.EmitRecord(Code, Vals, AbbrevToUse);
2539}
2540
2541
2542void DXILBitcodeWriter::writeFunctionLevelValueSymbolTable(
2544 if (VST.empty())
2545 return;
2547
2549
2550
2551
2552
2554
2555 for (auto &VI : VST) {
2556 SortedTable.push_back(VI.second->getValueName());
2557 }
2558
2560 return A->first() < B->first();
2561 });
2562
2563 for (const ValueName *SI : SortedTable) {
2565
2566
2567 bool is7Bit = true;
2568 bool isChar6 = true;
2569 for (const char *C = Name.getKeyData(), *E = C + Name.getKeyLength();
2571 if (isChar6)
2573 if ((unsigned char)*C & 128) {
2574 is7Bit = false;
2575 break;
2576 }
2577 }
2578
2579 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
2580
2581
2582
2583 unsigned Code;
2584 if (isa(SI->getValue())) {
2586 if (isChar6)
2587 AbbrevToUse = VST_BBENTRY_6_ABBREV;
2588 } else {
2590 if (isChar6)
2591 AbbrevToUse = VST_ENTRY_6_ABBREV;
2592 else if (is7Bit)
2593 AbbrevToUse = VST_ENTRY_7_ABBREV;
2594 }
2595
2597 for (const char *P = Name.getKeyData(),
2598 *E = Name.getKeyData() + Name.getKeyLength();
2600 NameVals.push_back((unsigned char)*P);
2601
2602
2603 Stream.EmitRecord(Code, NameVals, AbbrevToUse);
2604 NameVals.clear();
2605 }
2607}
2608
2609
2610void DXILBitcodeWriter::writeFunction(const Function &F) {
2613
2615
2616
2617
2621
2622
2623 unsigned CstStart, CstEnd;
2625 writeConstants(CstStart, CstEnd, false);
2626
2627
2628 writeFunctionMetadata(F);
2629
2630
2631 unsigned InstID = CstEnd;
2632
2633 bool NeedsMetadataAttachment = F.hasMetadata();
2634
2636
2637
2640 ++I) {
2641 writeInstruction(*I, InstID, Vals);
2642
2643 if (->getType()->isVoidTy())
2644 ++InstID;
2645
2646
2647 NeedsMetadataAttachment |= I->hasMetadataOtherThanDebugLoc();
2648
2649
2651 if ()
2652 continue;
2653
2654 if (DL == LastDL) {
2655
2657 continue;
2658 }
2659
2666
2667 LastDL = DL;
2668 }
2669
2670
2671 if (auto *Symtab = F.getValueSymbolTable())
2672 writeFunctionLevelValueSymbolTable(*Symtab);
2673
2674 if (NeedsMetadataAttachment)
2675 writeFunctionMetadataAttachment(F);
2676
2679}
2680
2681
2682void DXILBitcodeWriter::writeBlockInfo() {
2683
2684
2685
2687
2688 {
2689 auto Abbv = std::make_shared();
2695 std::move(Abbv)) != VST_ENTRY_8_ABBREV)
2696 assert(false && "Unexpected abbrev ordering!");
2697 }
2698
2699 {
2700 auto Abbv = std::make_shared();
2706 std::move(Abbv)) != VST_ENTRY_7_ABBREV)
2707 assert(false && "Unexpected abbrev ordering!");
2708 }
2709 {
2710 auto Abbv = std::make_shared();
2716 std::move(Abbv)) != VST_ENTRY_6_ABBREV)
2717 assert(false && "Unexpected abbrev ordering!");
2718 }
2719 {
2720 auto Abbv = std::make_shared();
2726 std::move(Abbv)) != VST_BBENTRY_6_ABBREV)
2727 assert(false && "Unexpected abbrev ordering!");
2728 }
2729
2730 {
2731 auto Abbv = std::make_shared();
2736 CONSTANTS_SETTYPE_ABBREV)
2737 assert(false && "Unexpected abbrev ordering!");
2738 }
2739
2740 {
2741 auto Abbv = std::make_shared();
2745 CONSTANTS_INTEGER_ABBREV)
2746 assert(false && "Unexpected abbrev ordering!");
2747 }
2748
2749 {
2750 auto Abbv = std::make_shared();
2756
2758 CONSTANTS_CE_CAST_Abbrev)
2759 assert(false && "Unexpected abbrev ordering!");
2760 }
2761 {
2762 auto Abbv = std::make_shared();
2765 CONSTANTS_NULL_Abbrev)
2766 assert(false && "Unexpected abbrev ordering!");
2767 }
2768
2769
2770
2771 {
2772 auto Abbv = std::make_shared();
2780 (unsigned)FUNCTION_INST_LOAD_ABBREV)
2781 assert(false && "Unexpected abbrev ordering!");
2782 }
2783 {
2784 auto Abbv = std::make_shared();
2790 (unsigned)FUNCTION_INST_BINOP_ABBREV)
2791 assert(false && "Unexpected abbrev ordering!");
2792 }
2793 {
2794 auto Abbv = std::make_shared();
2801 (unsigned)FUNCTION_INST_BINOP_FLAGS_ABBREV)
2802 assert(false && "Unexpected abbrev ordering!");
2803 }
2804 {
2805 auto Abbv = std::make_shared();
2812 (unsigned)FUNCTION_INST_CAST_ABBREV)
2813 assert(false && "Unexpected abbrev ordering!");
2814 }
2815
2816 {
2817 auto Abbv = std::make_shared();
2820 (unsigned)FUNCTION_INST_RET_VOID_ABBREV)
2821 assert(false && "Unexpected abbrev ordering!");
2822 }
2823 {
2824 auto Abbv = std::make_shared();
2828 (unsigned)FUNCTION_INST_RET_VAL_ABBREV)
2829 assert(false && "Unexpected abbrev ordering!");
2830 }
2831 {
2832 auto Abbv = std::make_shared();
2835 (unsigned)FUNCTION_INST_UNREACHABLE_ABBREV)
2836 assert(false && "Unexpected abbrev ordering!");
2837 }
2838 {
2839 auto Abbv = std::make_shared();
2847 (unsigned)FUNCTION_INST_GEP_ABBREV)
2848 assert(false && "Unexpected abbrev ordering!");
2849 }
2850
2852}
2853
2854void DXILBitcodeWriter::writeModuleVersion() {
2855
2857}
2858
2859
2861
2862
2863
2864
2866
2867
2868
2869 DXILBitcodeWriter::writeModuleVersion();
2870
2871
2872 writeBlockInfo();
2873
2874
2875 writeAttributeGroupTable();
2876
2877
2878 writeAttributeTable();
2879
2880
2881 writeTypeTable();
2882
2883 writeComdats();
2884
2885
2886
2887 writeModuleInfo();
2888
2889
2890 writeModuleConstants();
2891
2892
2893 writeModuleMetadataKinds();
2894
2895
2896 writeModuleMetadata();
2897
2898
2899
2900
2901 writeFunctionLevelValueSymbolTable(M.getValueSymbolTable());
2902
2903
2905 if (.isDeclaration())
2906 writeFunction(F);
2907
2909}
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static uint64_t rotateSign(APInt Val)
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
Module.h This file contains the declarations for the Module class.
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
uint64_t IntrinsicInst * II
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
static const uint32_t IV[8]
Class for arbitrary precision integers.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
int64_t getSExtValue() const
Get sign extended value.
an instruction to allocate memory on the stack
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool empty() const
empty - Check if the array is empty.
BinOp
This enumeration lists the possible modifications atomicrmw can make.
@ Min
*p = old <signed v ? old : v
@ Max
*p = old >signed v ? old : v
@ UMin
*p = old <unsigned v ? old : v
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
@ UMax
*p = old >unsigned v ? old : v
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
bool hasAttributes() const
Return true if attributes exists in this set.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ TombstoneKey
Use as Tombstone key for DenseMap of AttrKind.
@ None
No attributes have been set.
@ EmptyKey
Use as Empty key for DenseMap of AttrKind.
@ EndAttrKinds
Sentinel value useful for loops.
LLVM Basic Block Representation.
InstListType::const_iterator const_iterator
BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
static bool isChar6(char C)
isChar6 - Return true if this character is legal in the Char6 encoding.
unsigned EmitAbbrev(std::shared_ptr< BitCodeAbbrev > Abbv)
Emits the abbreviation Abbv to the stream.
void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev=0)
EmitRecord - Emit the specified record to the stream, using an abbrev if we have one to compress the ...
void Emit(uint32_t Val, unsigned NumBits)
void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals, StringRef Blob)
EmitRecordWithBlob - Emit the specified record to the stream, using an abbrev that includes a blob at...
unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr< BitCodeAbbrev > Abbv)
EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified BlockID.
void EnterBlockInfoBlock()
EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
void EnterSubblock(unsigned BlockID, unsigned CodeLen)
uint64_t GetCurrentBitNo() const
Retrieve the current position in the stream, in bits.
The address of a basic block.
Conditional or Unconditional Branch instruction.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
CallingConv::ID getCallingConv() const
Value * getCalledOperand() const
Value * getArgOperand(unsigned i) const
FunctionType * getFunctionType() const
unsigned arg_size() const
AttributeList getAttributes() const
Return the attributes for this call.
This class represents a function call, abstracting a target machine's calling convention.
bool isMustTailCall() const
@ Largest
The linker will choose the largest COMDAT.
@ SameSize
The data referenced by the COMDAT must be the same size.
@ Any
The linker may choose any COMDAT.
@ NoDeduplicate
No deduplication is performed.
@ ExactMatch
The data referenced by the COMDAT must be the same.
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
A constant value that is initialized with an expression using other constant values.
ConstantFP - Floating Point Values [float, double].
This is the shared class of boolean and integer constants.
const APInt & getValue() const
Return the constant as an APInt value reference.
This is an important base class in LLVM.
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
Basic type, like 'int' or 'float'.
A pair of DIGlobalVariable and DIExpression.
An imported module (C++ using directive or similar).
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
String type, Fortran CHARACTER(n)
Type array for a subprogram.
This class represents an Operation in the Expression.
iterator find(const_arg_type_t< KeyT > Val)
BasicBlockListType::const_iterator const_iterator
Generic tagged DWARF-like metadata node.
Function and variable summary information to aid decisions and implementation of importing.
VisibilityTypes getVisibility() const
LinkageTypes getLinkage() const
ThreadLocalMode getThreadLocalMode() const
@ DLLExportStorageClass
Function to be accessible from DLL.
@ DLLImportStorageClass
Function to be imported from DLL.
@ DefaultVisibility
The GV is visible.
@ HiddenVisibility
The GV is hidden.
@ ProtectedVisibility
The GV is protected.
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ CommonLinkage
Tentative definitions.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
@ AppendingLinkage
Special purpose, only applies to global arrays.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
DLLStorageClassTypes getDLLStorageClass() const
This instruction inserts a struct field of array element value into an aggregate value.
idx_iterator idx_end() const
idx_iterator idx_begin() const
The landingpad instruction holds all of the information necessary to generate correct exception handl...
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
const unsigned char * bytes_begin() const
const unsigned char * bytes_end() const
bool doesNotAccessMemory() const
Whether this function accesses no memory.
bool onlyAccessesArgPointees() const
Whether this function only (at most) accesses argument memory.
bool onlyReadsMemory() const
Whether this function only (at most) reads memory.
A Module instance is used to store all the information related to an LLVM module.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
Utility for building string tables with deduplicated suffixes.
Class to represent struct types.
Triple - Helper class for working with autoconf configuration names.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isX86_FP80Ty() const
Return true if this is x86 long double.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
@ TypedPointerTyID
Typed pointer used by some GPU targets.
@ HalfTyID
16-bit floating point type
@ TargetExtTyID
Target extension type.
@ VoidTyID
type with no size
@ ScalableVectorTyID
Scalable SIMD vector type.
@ FloatTyID
32-bit floating point type
@ IntegerTyID
Arbitrary bit width integers.
@ FixedVectorTyID
Fixed width SIMD vector type.
@ BFloatTyID
16-bit floating point type (7-bit significand)
@ DoubleTyID
64-bit floating point type
@ X86_FP80TyID
80-bit floating point type (X87)
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
@ FP128TyID
128-bit floating point type (112-bit significand)
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
bool isFP128Ty() const
Return true if this is 'fp128'.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
A few GPU targets, such as DXIL and SPIR-V, have typed pointers.
Type * getElementType() const
static TypedPointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
std::vector< std::pair< const Value *, unsigned > > ValueList
std::vector< Type * > TypeList
This class provides a symbol table of name/value pairs.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
void writeModule(const Module &M)
Write the specified module to the buffer specified at construction time.
BitcodeWriter(SmallVectorImpl< char > &Buffer)
Create a BitcodeWriter that writes to Buffer.
static void emitWideAPInt(SmallVectorImpl< uint64_t > &Vals, const APInt &A)
static unsigned getEncodedThreadLocalMode(const GlobalValue &GV)
static unsigned getEncodedCastOpcode(unsigned Opcode)
Begin dxil::BitcodeWriterBase Implementation.
static void writeStringRecord(BitstreamWriter &Stream, unsigned Code, StringRef Str, unsigned AbbrevToUse)
static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind)
static unsigned getEncodedDLLStorageClass(const GlobalValue &GV)
static unsigned getEncodedOrdering(AtomicOrdering Ordering)
static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage)
static unsigned getEncodedVisibility(const GlobalValue &GV)
void write()
Emit the current module to the bitstream.
static void writeIdentificationBlock(BitstreamWriter &Stream)
static unsigned getEncodedBinaryOpcode(unsigned Opcode)
static void emitSignedInt64(SmallVectorImpl< uint64_t > &Vals, uint64_t V)
static unsigned getEncodedUnaryOpcode(unsigned Opcode)
static unsigned getEncodedRMWOperation(AtomicRMWInst::BinOp Op)
DXILBitcodeWriter(const Module &M, SmallVectorImpl< char > &Buffer, StringTableBuilder &StrtabBuilder, BitstreamWriter &Stream)
Constructs a ModuleBitcodeWriter object for the given Module, writing to the provided Buffer.
static unsigned getEncodedComdatSelectionKind(const Comdat &C)
static uint64_t getOptimizationFlags(const Value *V)
ArrayRef< const Metadata * > getNonMDStrings() const
Get the non-MDString metadata for this block.
unsigned getValueID(const Value *V) const
std::pair< unsigned, AttributeSet > IndexAndAttrSet
Attribute groups as encoded in bitcode are almost AttributeSets, but they include the AttributeList i...
void setInstructionID(const Instruction *I)
void EnumerateType(Type *T)
unsigned getMetadataOrNullID(const Metadata *MD) const
const std::vector< IndexAndAttrSet > & getAttributeGroups() const
unsigned getComdatID(const Comdat *C) const
ArrayRef< const Metadata * > getMDStrings() const
Get the MDString metadata for this block.
bool hasMDs() const
Check whether the current block has any metadata to emit.
uint64_t computeBitsRequiredForTypeIndices() const
const ComdatSetType & getComdats() const
unsigned getAttributeListID(AttributeList PAL) const
unsigned getMetadataID(const Metadata *MD) const
const TypeList & getTypes() const
const std::vector< AttributeList > & getAttributeLists() const
void incorporateFunction(const Function &F)
incorporateFunction/purgeFunction - If you'd like to deal with a function, use these two methods to g...
unsigned getTypeID(Type *T) const
unsigned getInstructionID(const Instruction *I) const
const ValueList & getValues() const
unsigned getGlobalBasicBlockID(const BasicBlock *BB) const
getGlobalBasicBlockID - This returns the function-specific ID for the specified basic block.
void getFunctionConstantRange(unsigned &Start, unsigned &End) const
getFunctionConstantRange - Return the range of values that corresponds to function-local constants.
const std::vector< const BasicBlock * > & getBasicBlocks() const
unsigned getAttributeGroupID(IndexAndAttrSet Group) const
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write(unsigned char C)
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
@ C
The default llvm calling convention, compatible with C.
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
@ CE
Windows NT (Windows on ARM)
@ METADATA_TEMPLATE_VALUE
@ METADATA_LEXICAL_BLOCK_FILE
@ METADATA_SUBROUTINE_TYPE
@ METADATA_IMPORTED_ENTITY
@ METADATA_COMPOSITE_TYPE
@ CST_CODE_CE_INBOUNDS_GEP
@ COMDAT_SELECTION_KIND_LARGEST
@ COMDAT_SELECTION_KIND_ANY
@ COMDAT_SELECTION_KIND_SAME_SIZE
@ COMDAT_SELECTION_KIND_EXACT_MATCH
@ COMDAT_SELECTION_KIND_NO_DUPLICATES
@ ATTR_KIND_STACK_PROTECT
@ ATTR_KIND_STACK_PROTECT_STRONG
@ ATTR_KIND_SANITIZE_MEMORY
@ ATTR_KIND_OPTIMIZE_FOR_SIZE
@ ATTR_KIND_SANITIZE_ADDRESS
@ ATTR_KIND_NO_IMPLICIT_FLOAT
@ ATTR_KIND_STACK_ALIGNMENT
@ ATTR_KIND_STACK_PROTECT_REQ
@ ATTR_KIND_RETURNS_TWICE
@ ATTR_KIND_NON_LAZY_BIND
@ ATTR_KIND_DEREFERENCEABLE
@ ATTR_KIND_OPTIMIZE_NONE
@ ATTR_KIND_DEREFERENCEABLE_OR_NULL
@ ATTR_KIND_ALWAYS_INLINE
@ ATTR_KIND_SANITIZE_THREAD
@ PARAMATTR_GROUP_BLOCK_ID
@ MODULE_CODE_SECTIONNAME
@ FUNC_CODE_INST_LANDINGPAD
@ FUNC_CODE_INST_EXTRACTVAL
@ FUNC_CODE_INST_LOADATOMIC
@ FUNC_CODE_INST_STOREATOMIC
@ FUNC_CODE_INST_ATOMICRMW
@ FUNC_CODE_DEBUG_LOC_AGAIN
@ FUNC_CODE_INST_EXTRACTELT
@ FUNC_CODE_INST_INDIRECTBR
@ FUNC_CODE_INST_INSERTVAL
@ FUNC_CODE_DECLAREBLOCKS
@ FUNC_CODE_INST_INSERTELT
@ FUNC_CODE_INST_SHUFFLEVEC
@ FUNC_CODE_INST_UNREACHABLE
@ FIRST_APPLICATION_ABBREV
@ PARAMATTR_GRP_CODE_ENTRY
void WriteDXILToFile(const Module &M, raw_ostream &Out)
Write the specified module to the specified raw output stream.
NodeAddr< CodeNode * > Code
This is an optimization pass for GlobalISel generic memory operations.
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
MaybeAlign getAlign(const Function &F, unsigned Index)
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
void sort(IteratorTy Start, IteratorTy End)
AtomicOrdering
Atomic ordering for LLVM's memory model.
unsigned Log2(Align A)
Returns the log2 of the alignment.
uint64_t value() const
This is a hole in the type system and should not be abused.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
ValID - Represents a reference of a definition of some sort with no type.
Struct that holds a reference to a particular GUID in a global value summary.