60#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
61#include "llvm/IR/Metadata.def"
79 CONSTANTS_INTEGER_ABBREV,
80 CONSTANTS_CE_CAST_Abbrev,
81 CONSTANTS_NULL_Abbrev,
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,
112 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
115 unsigned GlobalValueId;
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)) {
142 for (
auto El : PointerMap)
170 void writeModuleVersion();
171 void writePerModuleGlobalValueSummary();
176 unsigned FSCallsAbbrev,
177 unsigned FSCallsProfileAbbrev,
181 unsigned FSModRefsAbbrev,
182 unsigned FSModVTableRefsAbbrev);
185 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
189 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
192 assert(VMI != GUIDToValueIdMap.end() &&
193 "GUID does not have assigned value Id");
199 if (!VI.haveGVs() || !VI.getValue())
200 return getValueId(VI.getGUID());
204 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
206 uint64_t bitcodeStartBit() {
return BitcodeStartBit; }
210 unsigned createDILocationAbbrev();
211 unsigned createGenericDINodeAbbrev();
213 void writeAttributeGroupTable();
214 void writeAttributeTable();
215 void writeTypeTable();
217 void writeValueSymbolTableForwardDecl();
218 void writeModuleInfo();
316 unsigned createNamedMetadataAbbrev();
318 unsigned createMetadataStringsAbbrev();
323 std::vector<unsigned> *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,
345 void writeGlobalValueSymbolTable(
348 void writeBlockInfo();
352 unsigned getEncodedAlign(
MaybeAlign Alignment) {
return encode(Alignment); }
354 unsigned getTypeID(
Type *
T,
const Value *V =
nullptr);
376 Stream->
Emit((
unsigned)
'B', 8);
377 Stream->
Emit((
unsigned)
'C', 8);
378 Stream->
Emit(0x0, 4);
379 Stream->
Emit(0xC, 4);
380 Stream->
Emit(0xE, 4);
381 Stream->
Emit(0xD, 4);
393 Triple TT(M.getTargetTriple());
394 if (TT.isOSDarwin() || TT.isOSBinFormatMachO())
408 auto Abbv = std::make_shared<BitCodeAbbrev>();
411 auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
424 assert(M.isMaterialized());
425 Mods.push_back(
const_cast<Module *
>(&M));
428 ModuleWriter.
write();
439 case Instruction::Trunc:
441 case Instruction::ZExt:
443 case Instruction::SExt:
445 case Instruction::FPToUI:
447 case Instruction::FPToSI:
449 case Instruction::UIToFP:
451 case Instruction::SIToFP:
453 case Instruction::FPTrunc:
455 case Instruction::FPExt:
457 case Instruction::PtrToInt:
459 case Instruction::IntToPtr:
461 case Instruction::BitCast:
463 case Instruction::AddrSpaceCast:
472 case Instruction::FNeg:
481 case Instruction::Add:
482 case Instruction::FAdd:
484 case Instruction::Sub:
485 case Instruction::FSub:
487 case Instruction::Mul:
488 case Instruction::FMul:
490 case Instruction::UDiv:
492 case Instruction::FDiv:
493 case Instruction::SDiv:
495 case Instruction::URem:
497 case Instruction::FRem:
498 case Instruction::SRem:
500 case Instruction::Shl:
502 case Instruction::LShr:
504 case Instruction::AShr:
506 case Instruction::And:
508 case Instruction::Or:
510 case Instruction::Xor:
515unsigned DXILBitcodeWriter::getTypeID(
Type *
T,
const Value *V) {
516 if (!
T->isPointerTy() &&
519 (!V || !isa<Constant>(V)))
521 auto It = PointerMap.
find(V);
522 if (It != PointerMap.
end())
528 if (V && isa<Constant>(V) && !isa<ConstantPointerNull>(V))
533unsigned DXILBitcodeWriter::getGlobalObjectValueTypeID(
Type *
T,
535 auto It = PointerMap.
find(
G);
536 if (It != PointerMap.
end()) {
602 unsigned AbbrevToUse) {
618 case Attribute::Alignment:
620 case Attribute::AlwaysInline:
622 case Attribute::Builtin:
624 case Attribute::ByVal:
626 case Attribute::Convergent:
628 case Attribute::InAlloca:
630 case Attribute::Cold:
632 case Attribute::InlineHint:
634 case Attribute::InReg:
636 case Attribute::JumpTable:
638 case Attribute::MinSize:
640 case Attribute::Naked:
642 case Attribute::Nest:
644 case Attribute::NoAlias:
646 case Attribute::NoBuiltin:
648 case Attribute::NoCapture:
650 case Attribute::NoDuplicate:
652 case Attribute::NoImplicitFloat:
654 case Attribute::NoInline:
656 case Attribute::NonLazyBind:
658 case Attribute::NonNull:
660 case Attribute::Dereferenceable:
662 case Attribute::DereferenceableOrNull:
664 case Attribute::NoRedZone:
666 case Attribute::NoReturn:
668 case Attribute::NoUnwind:
670 case Attribute::OptimizeForSize:
672 case Attribute::OptimizeNone:
674 case Attribute::ReadNone:
676 case Attribute::ReadOnly:
678 case Attribute::Returned:
680 case Attribute::ReturnsTwice:
682 case Attribute::SExt:
684 case Attribute::StackAlignment:
686 case Attribute::StackProtect:
688 case Attribute::StackProtectReq:
690 case Attribute::StackProtectStrong:
692 case Attribute::SafeStack:
694 case Attribute::StructRet:
696 case Attribute::SanitizeAddress:
698 case Attribute::SanitizeThread:
700 case Attribute::SanitizeMemory:
702 case Attribute::UWTable:
704 case Attribute::ZExt:
715 "should be stripped in DXILPrepare");
735 unsigned NumWords =
A.getActiveWords();
736 const uint64_t *RawData =
A.getRawData();
737 for (
unsigned i = 0; i < NumWords; i++)
744 if (
const auto *OBO = dyn_cast<OverflowingBinaryOperator>(V)) {
745 if (OBO->hasNoSignedWrap())
747 if (OBO->hasNoUnsignedWrap())
749 }
else if (
const auto *PEO = dyn_cast<PossiblyExactOperator>(V)) {
752 }
else if (
const auto *FPMO = dyn_cast<FPMathOperator>(V)) {
753 if (FPMO->hasAllowReassoc())
755 if (FPMO->hasNoNaNs())
757 if (FPMO->hasNoInfs())
759 if (FPMO->hasNoSignedZeros())
761 if (FPMO->hasAllowReciprocal())
763 if (FPMO->hasAllowContract())
765 if (FPMO->hasApproxFunc())
846 switch (
C.getSelectionKind()) {
865void DXILBitcodeWriter::writeAttributeGroupTable() {
866 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
868 if (AttrGrps.empty())
875 unsigned AttrListIndex = Pair.first;
878 Record.push_back(AttrListIndex);
881 if (Attr.isEnumAttribute()) {
884 "DXIL does not support attributes above ATTR_KIND_ARGMEMONLY");
887 }
else if (Attr.isIntAttribute()) {
888 if (Attr.getKindAsEnum() == Attribute::AttrKind::Memory) {
906 "DXIL does not support attributes above ATTR_KIND_ARGMEMONLY");
909 Record.push_back(Attr.getValueAsInt());
932void DXILBitcodeWriter::writeAttributeTable() {
940 for (
unsigned i = 0, e =
Attrs.size(); i != e; ++i) {
942 for (
unsigned i :
AL.indexes()) {
956void DXILBitcodeWriter::writeTypeTable() {
965 auto Abbv = std::make_shared<BitCodeAbbrev>();
969 unsigned PtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
972 Abbv = std::make_shared<BitCodeAbbrev>();
977 unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
980 Abbv = std::make_shared<BitCodeAbbrev>();
985 unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
988 Abbv = std::make_shared<BitCodeAbbrev>();
992 unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
995 Abbv = std::make_shared<BitCodeAbbrev>();
1000 unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1003 Abbv = std::make_shared<BitCodeAbbrev>();
1007 unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1015 for (
Type *
T : TypeList) {
1016 int AbbrevToUse = 0;
1019 switch (
T->getTypeID()) {
1069 AbbrevToUse = PtrAbbrev;
1080 "dxilOpaquePtrReservedName", StructNameAbbrev);
1088 TypeVals.
push_back(getTypeID(FT->getReturnType()));
1089 for (
Type *PTy : FT->params())
1091 AbbrevToUse = FunctionAbbrev;
1099 for (
Type *ElTy :
ST->elements())
1102 if (
ST->isLiteral()) {
1104 AbbrevToUse = StructAnonAbbrev;
1106 if (
ST->isOpaque()) {
1110 AbbrevToUse = StructNamedAbbrev;
1114 if (!
ST->getName().empty())
1124 TypeVals.
push_back(AT->getNumElements());
1125 TypeVals.
push_back(getTypeID(AT->getElementType()));
1126 AbbrevToUse = ArrayAbbrev;
1134 TypeVals.
push_back(VT->getElementCount().getKnownMinValue());
1135 TypeVals.
push_back(getTypeID(VT->getElementType()));
1141 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
1148void DXILBitcodeWriter::writeComdats() {
1153 size_t Size =
C->getName().size();
1156 for (
char Chr :
C->getName())
1163void DXILBitcodeWriter::writeValueSymbolTableForwardDecl() {}
1168void DXILBitcodeWriter::writeModuleInfo() {
1170 if (!
M.getTargetTriple().empty())
1173 const std::string &
DL =
M.getDataLayoutStr();
1176 if (!
M.getModuleInlineAsm().empty())
1182 std::map<std::string, unsigned> SectionMap;
1183 std::map<std::string, unsigned> GCMap;
1185 unsigned MaxGlobalType = 0;
1186 const auto UpdateMaxAlignment = [&MaxAlignment](
const MaybeAlign A) {
1188 MaxAlignment = !MaxAlignment ? *
A : std::max(*MaxAlignment, *
A);
1191 UpdateMaxAlignment(GV.getAlign());
1194 MaxGlobalType = std::max(
1195 MaxGlobalType, getGlobalObjectValueTypeID(GV.getValueType(), &GV));
1196 if (GV.hasSection()) {
1198 unsigned &Entry = SectionMap[std::string(GV.getSection())];
1201 GV.getSection(), 0 );
1202 Entry = SectionMap.size();
1207 UpdateMaxAlignment(
F.getAlign());
1208 if (
F.hasSection()) {
1210 unsigned &Entry = SectionMap[std::string(
F.getSection())];
1214 Entry = SectionMap.size();
1219 unsigned &Entry = GCMap[
F.getGC()];
1223 Entry = GCMap.size();
1229 unsigned SimpleGVarAbbrev = 0;
1230 if (!
M.global_empty()) {
1233 auto Abbv = std::make_shared<BitCodeAbbrev>();
1245 unsigned MaxEncAlignment = getEncodedAlign(MaxAlignment);
1249 if (SectionMap.empty())
1255 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1261 unsigned AbbrevToUse = 0;
1267 Vals.
push_back(getGlobalObjectValueTypeID(GV.getValueType(), &GV));
1269 GV.getType()->getAddressSpace() << 2 | 2 |
1270 (GV.isConstant() ? 1 : 0));
1273 GV.isDeclaration() ? 0 : (VE.
getValueID(GV.getInitializer()) + 1));
1275 Vals.
push_back(getEncodedAlign(GV.getAlign()));
1276 Vals.
push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1278 if (GV.isThreadLocal() ||
1281 GV.isExternallyInitialized() ||
1287 Vals.
push_back(GV.isExternallyInitialized());
1291 AbbrevToUse = SimpleGVarAbbrev;
1303 Vals.
push_back(getGlobalObjectValueTypeID(
F.getFunctionType(), &
F));
1308 Vals.
push_back(getEncodedAlign(
F.getAlign()));
1309 Vals.
push_back(
F.hasSection() ? SectionMap[std::string(
F.getSection())]
1315 F.hasPrologueData() ? (VE.
getValueID(
F.getPrologueData()) + 1) : 0);
1321 F.hasPersonalityFn() ? (VE.
getValueID(
F.getPersonalityFn()) + 1) : 0);
1323 unsigned AbbrevToUse = 0;
1338 unsigned AbbrevToUse = 0;
1344void DXILBitcodeWriter::writeValueAsMetadata(
1348 Type *Ty =
V->getType();
1349 if (
Function *
F = dyn_cast<Function>(V))
1353 Record.push_back(getTypeID(Ty));
1359void DXILBitcodeWriter::writeMDTuple(
const MDTuple *
N,
1362 for (
unsigned i = 0, e =
N->getNumOperands(); i != e; ++i) {
1364 assert(!(MD && isa<LocalAsMetadata>(MD)) &&
1365 "Unexpected function-local metadata");
1374void DXILBitcodeWriter::writeDILocation(
const DILocation *
N,
1378 Abbrev = createDILocationAbbrev();
1379 Record.push_back(
N->isDistinct());
1380 Record.push_back(
N->getLine());
1381 Record.push_back(
N->getColumn());
1392 return I < 0 ? ~(U << 1) : U << 1;
1395void DXILBitcodeWriter::writeDISubrange(
const DISubrange *
N,
1398 Record.push_back(
N->isDistinct());
1403 assert(Count &&
"Count is missing or not ConstantInt");
1407 DISubrange::BoundType LowerBound =
N->getLowerBound();
1409 "Lower bound provided but not ConstantInt");
1417void DXILBitcodeWriter::writeDIEnumerator(
const DIEnumerator *
N,
1420 Record.push_back(
N->isDistinct());
1428void DXILBitcodeWriter::writeDIBasicType(
const DIBasicType *
N,
1431 Record.push_back(
N->isDistinct());
1432 Record.push_back(
N->getTag());
1434 Record.push_back(
N->getSizeInBits());
1435 Record.push_back(
N->getAlignInBits());
1436 Record.push_back(
N->getEncoding());
1442void DXILBitcodeWriter::writeDIDerivedType(
const DIDerivedType *
N,
1445 Record.push_back(
N->isDistinct());
1446 Record.push_back(
N->getTag());
1449 Record.push_back(
N->getLine());
1452 Record.push_back(
N->getSizeInBits());
1453 Record.push_back(
N->getAlignInBits());
1454 Record.push_back(
N->getOffsetInBits());
1455 Record.push_back(
N->getFlags());
1465 Record.push_back(
N->isDistinct());
1466 Record.push_back(
N->getTag());
1469 Record.push_back(
N->getLine());
1472 Record.push_back(
N->getSizeInBits());
1473 Record.push_back(
N->getAlignInBits());
1474 Record.push_back(
N->getOffsetInBits());
1475 Record.push_back(
N->getFlags());
1477 Record.push_back(
N->getRuntimeLang());
1489 Record.push_back(
N->isDistinct());
1490 Record.push_back(
N->getFlags());
1497void DXILBitcodeWriter::writeDIFile(
const DIFile *
N,
1500 Record.push_back(
N->isDistinct());
1508void DXILBitcodeWriter::writeDICompileUnit(
const DICompileUnit *
N,
1511 Record.push_back(
N->isDistinct());
1512 Record.push_back(
N->getSourceLanguage());
1515 Record.push_back(
N->isOptimized());
1517 Record.push_back(
N->getRuntimeVersion());
1519 Record.push_back(
N->getEmissionKind());
1525 Record.push_back(
N->getDWOId());
1531void DXILBitcodeWriter::writeDISubprogram(
const DISubprogram *
N,
1534 Record.push_back(
N->isDistinct());
1539 Record.push_back(
N->getLine());
1541 Record.push_back(
N->isLocalToUnit());
1542 Record.push_back(
N->isDefinition());
1543 Record.push_back(
N->getScopeLine());
1545 Record.push_back(
N->getVirtuality());
1546 Record.push_back(
N->getVirtualIndex());
1547 Record.push_back(
N->getFlags());
1548 Record.push_back(
N->isOptimized());
1561 Record.push_back(
N->isDistinct());
1564 Record.push_back(
N->getLine());
1565 Record.push_back(
N->getColumn());
1571void DXILBitcodeWriter::writeDILexicalBlockFile(
1574 Record.push_back(
N->isDistinct());
1577 Record.push_back(
N->getDiscriminator());
1583void DXILBitcodeWriter::writeDINamespace(
const DINamespace *
N,
1586 Record.push_back(
N->isDistinct());
1596void DXILBitcodeWriter::writeDIModule(
const DIModule *
N,
1599 Record.push_back(
N->isDistinct());
1600 for (
auto &
I :
N->operands())
1607void DXILBitcodeWriter::writeDITemplateTypeParameter(
1610 Record.push_back(
N->isDistinct());
1618void DXILBitcodeWriter::writeDITemplateValueParameter(
1621 Record.push_back(
N->isDistinct());
1622 Record.push_back(
N->getTag());
1634 Record.push_back(
N->isDistinct());
1639 Record.push_back(
N->getLine());
1641 Record.push_back(
N->isLocalToUnit());
1642 Record.push_back(
N->isDefinition());
1653 Record.push_back(
N->isDistinct());
1654 Record.push_back(
N->getTag());
1658 Record.push_back(
N->getLine());
1660 Record.push_back(
N->getArg());
1661 Record.push_back(
N->getFlags());
1667void DXILBitcodeWriter::writeDIExpression(
const DIExpression *
N,
1670 Record.reserve(
N->getElements().size() + 1);
1672 Record.push_back(
N->isDistinct());
1673 Record.append(
N->elements_begin(),
N->elements_end());
1688 Record.push_back(
N->isDistinct());
1689 Record.push_back(
N->getTag());
1692 Record.push_back(
N->getLine());
1699unsigned DXILBitcodeWriter::createDILocationAbbrev() {
1704 std::shared_ptr<BitCodeAbbrev> Abbv = std::make_shared<BitCodeAbbrev>();
1714unsigned DXILBitcodeWriter::createGenericDINodeAbbrev() {
1719 std::shared_ptr<BitCodeAbbrev> Abbv = std::make_shared<BitCodeAbbrev>();
1732 std::vector<unsigned> *MDAbbrevs,
1733 std::vector<uint64_t> *IndexPos) {
1738#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
1739#include "llvm/IR/Metadata.def"
1744 if (
const MDNode *
N = dyn_cast<MDNode>(MD)) {
1745 assert(
N->isResolved() &&
"Expected forward references to be resolved");
1747 switch (
N->getMetadataID()) {
1750#define HANDLE_MDNODE_LEAF(CLASS) \
1751 case Metadata::CLASS##Kind: \
1753 write##CLASS(cast<CLASS>(N), Record, \
1754 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
1756 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
1758#include "llvm/IR/Metadata.def"
1761 writeValueAsMetadata(cast<ValueAsMetadata>(MD),
Record);
1765unsigned DXILBitcodeWriter::createMetadataStringsAbbrev() {
1766 auto Abbv = std::make_shared<BitCodeAbbrev>();
1773void DXILBitcodeWriter::writeMetadataStrings(
1775 if (Strings.empty())
1778 unsigned MDSAbbrev = createMetadataStringsAbbrev();
1780 for (
const Metadata *MD : Strings) {
1781 const MDString *MDS = cast<MDString>(MD);
1791void DXILBitcodeWriter::writeModuleMetadata() {
1792 if (!VE.
hasMDs() &&
M.named_metadata_empty())
1799 std::vector<unsigned> MDAbbrevs;
1802 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
1803 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
1804 createGenericDINodeAbbrev();
1806 unsigned NameAbbrev = 0;
1807 if (!
M.named_metadata_empty()) {
1809 std::shared_ptr<BitCodeAbbrev> Abbv = std::make_shared<BitCodeAbbrev>();
1813 NameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1819 std::vector<uint64_t> IndexPos;
1827 Record.append(Str.bytes_begin(), Str.bytes_end());
1832 for (
const MDNode *
N : NMD.operands())
1841void DXILBitcodeWriter::writeFunctionMetadata(
const Function &
F) {
1852void DXILBitcodeWriter::writeFunctionMetadataAttachment(
const Function &
F) {
1860 F.getAllMetadata(MDs);
1862 for (
const auto &
I : MDs) {
1873 I.getAllMetadataOtherThanDebugLoc(MDs);
1881 for (
unsigned i = 0, e = MDs.size(); i != e; ++i) {
1882 Record.push_back(MDs[i].first);
1892void DXILBitcodeWriter::writeModuleMetadataKinds() {
1898 M.getMDKindNames(Names);
1905 for (
unsigned MDKindID = 0, e = Names.
size(); MDKindID != e; ++MDKindID) {
1906 Record.push_back(MDKindID);
1917void DXILBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
1919 if (FirstVal == LastVal)
1924 unsigned AggregateAbbrev = 0;
1925 unsigned String8Abbrev = 0;
1926 unsigned CString7Abbrev = 0;
1927 unsigned CString6Abbrev = 0;
1931 auto Abbv = std::make_shared<BitCodeAbbrev>();
1936 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1939 Abbv = std::make_shared<BitCodeAbbrev>();
1943 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
1945 Abbv = std::make_shared<BitCodeAbbrev>();
1949 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
1951 Abbv = std::make_shared<BitCodeAbbrev>();
1955 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
1961 Type *LastTy =
nullptr;
1962 for (
unsigned i = FirstVal; i != LastVal; ++i) {
1963 const Value *
V = Vals[i].first;
1965 if (
V->getType() != LastTy) {
1966 LastTy =
V->getType();
1967 Record.push_back(getTypeID(LastTy, V));
1969 CONSTANTS_SETTYPE_ABBREV);
1973 if (
const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
1974 Record.push_back(
unsigned(
IA->hasSideEffects()) |
1975 unsigned(
IA->isAlignStack()) << 1 |
1976 unsigned(
IA->getDialect() & 1) << 2);
1979 const std::string &AsmStr =
IA->getAsmString();
1980 Record.push_back(AsmStr.size());
1981 Record.append(AsmStr.begin(), AsmStr.end());
1984 const std::string &ConstraintStr =
IA->getConstraintString();
1985 Record.push_back(ConstraintStr.size());
1986 Record.append(ConstraintStr.begin(), ConstraintStr.end());
1992 unsigned Code = -1U;
1993 unsigned AbbrevToUse = 0;
1994 if (
C->isNullValue()) {
1996 }
else if (isa<UndefValue>(
C)) {
1999 if (
IV->getBitWidth() <= 64) {
2003 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2009 unsigned NWords =
IV->getValue().getActiveWords();
2010 const uint64_t *RawWords =
IV->getValue().getRawData();
2011 for (
unsigned i = 0; i != NWords; ++i) {
2016 }
else if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
C)) {
2018 Type *Ty = CFP->getType();
2020 Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2024 APInt api = CFP->getValueAPF().bitcastToAPInt();
2026 Record.push_back((p[1] << 48) | (p[0] >> 16));
2027 Record.push_back(p[0] & 0xffffLL);
2029 APInt api = CFP->getValueAPF().bitcastToAPInt();
2034 assert(0 &&
"Unknown FP type!");
2036 }
else if (isa<ConstantDataSequential>(
C) &&
2037 cast<ConstantDataSequential>(
C)->isString()) {
2040 unsigned NumElts = Str->getNumElements();
2042 if (Str->isCString()) {
2047 AbbrevToUse = String8Abbrev;
2051 for (
unsigned i = 0; i != NumElts; ++i) {
2052 unsigned char V = Str->getElementAsInteger(i);
2054 isCStr7 &= (
V & 128) == 0;
2060 AbbrevToUse = CString6Abbrev;
2062 AbbrevToUse = CString7Abbrev;
2064 dyn_cast<ConstantDataSequential>(
C)) {
2066 Type *EltTy = CDS->getElementType();
2067 if (isa<IntegerType>(EltTy)) {
2068 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2069 Record.push_back(CDS->getElementAsInteger(i));
2071 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
2076 F = CDS->getElementAsFloat(i);
2081 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
2086 F = CDS->getElementAsDouble(i);
2090 }
else if (isa<ConstantArray>(
C) || isa<ConstantStruct>(
C) ||
2091 isa<ConstantVector>(
C)) {
2093 for (
const Value *
Op :
C->operands())
2095 AbbrevToUse = AggregateAbbrev;
2096 }
else if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(
C)) {
2097 switch (
CE->getOpcode()) {
2103 getTypeID(
C->getOperand(0)->getType(),
C->getOperand(0)));
2105 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2107 assert(
CE->getNumOperands() == 2 &&
"Unknown constant expr!");
2117 case Instruction::GetElementPtr: {
2119 const auto *GO = cast<GEPOperator>(
C);
2120 if (GO->isInBounds())
2122 Record.push_back(getTypeID(GO->getSourceElementType()));
2123 for (
unsigned i = 0, e =
CE->getNumOperands(); i != e; ++i) {
2125 getTypeID(
C->getOperand(i)->getType(),
C->getOperand(i)));
2130 case Instruction::Select:
2136 case Instruction::ExtractElement:
2138 Record.push_back(getTypeID(
C->getOperand(0)->getType()));
2140 Record.push_back(getTypeID(
C->getOperand(1)->getType()));
2143 case Instruction::InsertElement:
2147 Record.push_back(getTypeID(
C->getOperand(2)->getType()));
2150 case Instruction::ShuffleVector:
2155 if (
C->getType() ==
C->getOperand(0)->getType()) {
2159 Record.push_back(getTypeID(
C->getOperand(0)->getType()));
2165 case Instruction::ICmp:
2166 case Instruction::FCmp:
2168 Record.push_back(getTypeID(
C->getOperand(0)->getType()));
2171 Record.push_back(
CE->getPredicate());
2174 }
else if (
const BlockAddress *BA = dyn_cast<BlockAddress>(
C)) {
2176 Record.push_back(getTypeID(BA->getFunction()->getType()));
2192void DXILBitcodeWriter::writeModuleConstants() {
2197 for (
unsigned i = 0, e = Vals.size(); i != e; ++i) {
2198 if (!isa<GlobalValue>(Vals[i].first)) {
2199 writeConstants(i, Vals.size(),
true);
2213bool DXILBitcodeWriter::pushValueAndType(
const Value *V,
unsigned InstID,
2218 if (
ValID >= InstID) {
2227void DXILBitcodeWriter::pushValue(
const Value *V,
unsigned InstID,
2233void DXILBitcodeWriter::pushValueSigned(
const Value *V,
unsigned InstID,
2236 int64_t diff = ((int32_t)InstID - (int32_t)
ValID);
2241void DXILBitcodeWriter::writeInstruction(
const Instruction &
I,
unsigned InstID,
2244 unsigned AbbrevToUse = 0;
2246 switch (
I.getOpcode()) {
2250 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
2251 AbbrevToUse = (
unsigned)FUNCTION_INST_CAST_ABBREV;
2255 assert(isa<BinaryOperator>(
I) &&
"Unknown instruction!");
2257 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
2258 AbbrevToUse = (
unsigned)FUNCTION_INST_BINOP_ABBREV;
2259 pushValue(
I.getOperand(1), InstID, Vals);
2263 if (AbbrevToUse == (
unsigned)FUNCTION_INST_BINOP_ABBREV)
2264 AbbrevToUse = (
unsigned)FUNCTION_INST_BINOP_FLAGS_ABBREV;
2270 case Instruction::GetElementPtr: {
2272 AbbrevToUse = (
unsigned)FUNCTION_INST_GEP_ABBREV;
2273 auto &GEPInst = cast<GetElementPtrInst>(
I);
2275 Vals.
push_back(getTypeID(GEPInst.getSourceElementType()));
2276 for (
unsigned i = 0, e =
I.getNumOperands(); i != e; ++i)
2277 pushValueAndType(
I.getOperand(i), InstID, Vals);
2280 case Instruction::ExtractValue: {
2282 pushValueAndType(
I.getOperand(0), InstID, Vals);
2287 case Instruction::InsertValue: {
2289 pushValueAndType(
I.getOperand(0), InstID, Vals);
2290 pushValueAndType(
I.getOperand(1), InstID, Vals);
2295 case Instruction::Select:
2297 pushValueAndType(
I.getOperand(1), InstID, Vals);
2298 pushValue(
I.getOperand(2), InstID, Vals);
2299 pushValueAndType(
I.getOperand(0), InstID, Vals);
2301 case Instruction::ExtractElement:
2303 pushValueAndType(
I.getOperand(0), InstID, Vals);
2304 pushValueAndType(
I.getOperand(1), InstID, Vals);
2306 case Instruction::InsertElement:
2308 pushValueAndType(
I.getOperand(0), InstID, Vals);
2309 pushValue(
I.getOperand(1), InstID, Vals);
2310 pushValueAndType(
I.getOperand(2), InstID, Vals);
2312 case Instruction::ShuffleVector:
2314 pushValueAndType(
I.getOperand(0), InstID, Vals);
2315 pushValue(
I.getOperand(1), InstID, Vals);
2316 pushValue(cast<ShuffleVectorInst>(&
I)->getShuffleMaskForBitcode(), InstID,
2319 case Instruction::ICmp:
2320 case Instruction::FCmp: {
2323 pushValueAndType(
I.getOperand(0), InstID, Vals);
2324 pushValue(
I.getOperand(1), InstID, Vals);
2332 case Instruction::Ret: {
2334 unsigned NumOperands =
I.getNumOperands();
2335 if (NumOperands == 0)
2336 AbbrevToUse = (
unsigned)FUNCTION_INST_RET_VOID_ABBREV;
2337 else if (NumOperands == 1) {
2338 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
2339 AbbrevToUse = (
unsigned)FUNCTION_INST_RET_VAL_ABBREV;
2341 for (
unsigned i = 0, e = NumOperands; i !=
e; ++i)
2342 pushValueAndType(
I.getOperand(i), InstID, Vals);
2345 case Instruction::Br: {
2354 case Instruction::Switch: {
2357 Vals.
push_back(getTypeID(
SI.getCondition()->getType()));
2358 pushValue(
SI.getCondition(), InstID, Vals);
2360 for (
auto Case :
SI.cases()) {
2365 case Instruction::IndirectBr:
2367 Vals.
push_back(getTypeID(
I.getOperand(0)->getType()));
2369 pushValue(
I.getOperand(0), InstID, Vals);
2370 for (
unsigned i = 1, e =
I.getNumOperands(); i != e; ++i)
2374 case Instruction::Invoke: {
2385 pushValueAndType(Callee, InstID, Vals);
2388 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
2389 pushValue(
I.getOperand(i), InstID, Vals);
2392 if (FTy->isVarArg()) {
2393 for (
unsigned i = FTy->getNumParams(), e =
I.getNumOperands() - 3; i != e;
2395 pushValueAndType(
I.getOperand(i), InstID, Vals);
2399 case Instruction::Resume:
2401 pushValueAndType(
I.getOperand(0), InstID, Vals);
2403 case Instruction::Unreachable:
2405 AbbrevToUse = (
unsigned)FUNCTION_INST_UNREACHABLE_ABBREV;
2408 case Instruction::PHI: {
2409 const PHINode &PN = cast<PHINode>(
I);
2421 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
2426 case Instruction::LandingPad: {
2437 pushValueAndType(LP.
getClause(
I), InstID, Vals);
2442 case Instruction::Alloca: {
2446 Vals.
push_back(getTypeID(
I.getOperand(0)->getType()));
2449 assert(AlignRecord < 1 << 5 &&
"alignment greater than 1 << 64");
2451 AlignRecord |= 1 << 6;
2456 case Instruction::Load:
2457 if (cast<LoadInst>(
I).isAtomic()) {
2459 pushValueAndType(
I.getOperand(0), InstID, Vals);
2462 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
2463 AbbrevToUse = (
unsigned)FUNCTION_INST_LOAD_ABBREV;
2467 Vals.
push_back(cast<LoadInst>(
I).isVolatile());
2468 if (cast<LoadInst>(
I).isAtomic()) {
2470 Vals.
push_back(getEncodedSyncScopeID(cast<LoadInst>(
I).getSyncScopeID()));
2473 case Instruction::Store:
2474 if (cast<StoreInst>(
I).isAtomic())
2478 pushValueAndType(
I.getOperand(1), InstID, Vals);
2479 pushValueAndType(
I.getOperand(0), InstID, Vals);
2481 Vals.
push_back(cast<StoreInst>(
I).isVolatile());
2482 if (cast<StoreInst>(
I).isAtomic()) {
2485 getEncodedSyncScopeID(cast<StoreInst>(
I).getSyncScopeID()));
2488 case Instruction::AtomicCmpXchg:
2490 pushValueAndType(
I.getOperand(0), InstID, Vals);
2491 pushValueAndType(
I.getOperand(1), InstID, Vals);
2492 pushValue(
I.getOperand(2), InstID, Vals);
2493 Vals.
push_back(cast<AtomicCmpXchgInst>(
I).isVolatile());
2497 getEncodedSyncScopeID(cast<AtomicCmpXchgInst>(
I).getSyncScopeID()));
2500 Vals.
push_back(cast<AtomicCmpXchgInst>(
I).isWeak());
2502 case Instruction::AtomicRMW:
2504 pushValueAndType(
I.getOperand(0), InstID, Vals);
2505 pushValue(
I.getOperand(1), InstID, Vals);
2508 Vals.
push_back(cast<AtomicRMWInst>(
I).isVolatile());
2511 getEncodedSyncScopeID(cast<AtomicRMWInst>(
I).getSyncScopeID()));
2513 case Instruction::Fence:
2516 Vals.
push_back(getEncodedSyncScopeID(cast<FenceInst>(
I).getSyncScopeID()));
2518 case Instruction::Call: {
2531 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
2533 if (FTy->getParamType(i)->isLabelTy())
2540 if (FTy->isVarArg()) {
2541 for (
unsigned i = FTy->getNumParams(), e = CI.
arg_size(); i != e; ++i)
2546 case Instruction::VAArg:
2548 Vals.
push_back(getTypeID(
I.getOperand(0)->getType()));
2549 pushValue(
I.getOperand(0), InstID, Vals);
2559void DXILBitcodeWriter::writeFunctionLevelValueSymbolTable(
2572 for (
auto &VI : VST) {
2577 return A->first() <
B->first();
2580 for (
const ValueName *SI : SortedTable) {
2585 bool isChar6 =
true;
2586 for (
const char *
C =
Name.getKeyData(), *
E =
C +
Name.getKeyLength();
2590 if ((
unsigned char)*
C & 128) {
2596 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
2601 if (isa<BasicBlock>(
SI->getValue())) {
2604 AbbrevToUse = VST_BBENTRY_6_ABBREV;
2608 AbbrevToUse = VST_ENTRY_6_ABBREV;
2610 AbbrevToUse = VST_ENTRY_7_ABBREV;
2614 for (
const char *
P =
Name.getKeyData(),
2615 *
E =
Name.getKeyData() +
Name.getKeyLength();
2620 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
2627void DXILBitcodeWriter::writeFunction(
const Function &
F) {
2640 unsigned CstStart, CstEnd;
2642 writeConstants(CstStart, CstEnd,
false);
2645 writeFunctionMetadata(
F);
2648 unsigned InstID = CstEnd;
2650 bool NeedsMetadataAttachment =
F.hasMetadata();
2658 writeInstruction(*
I, InstID, Vals);
2660 if (!
I->getType()->isVoidTy())
2664 NeedsMetadataAttachment |=
I->hasMetadataOtherThanDebugLoc();
2688 if (
auto *Symtab =
F.getValueSymbolTable())
2689 writeFunctionLevelValueSymbolTable(*Symtab);
2691 if (NeedsMetadataAttachment)
2692 writeFunctionMetadataAttachment(
F);
2699void DXILBitcodeWriter::writeBlockInfo() {
2706 auto Abbv = std::make_shared<BitCodeAbbrev>();
2712 std::move(Abbv)) != VST_ENTRY_8_ABBREV)
2713 assert(
false &&
"Unexpected abbrev ordering!");
2717 auto Abbv = std::make_shared<BitCodeAbbrev>();
2723 std::move(Abbv)) != VST_ENTRY_7_ABBREV)
2724 assert(
false &&
"Unexpected abbrev ordering!");
2727 auto Abbv = std::make_shared<BitCodeAbbrev>();
2733 std::move(Abbv)) != VST_ENTRY_6_ABBREV)
2734 assert(
false &&
"Unexpected abbrev ordering!");
2737 auto Abbv = std::make_shared<BitCodeAbbrev>();
2743 std::move(Abbv)) != VST_BBENTRY_6_ABBREV)
2744 assert(
false &&
"Unexpected abbrev ordering!");
2748 auto Abbv = std::make_shared<BitCodeAbbrev>();
2753 CONSTANTS_SETTYPE_ABBREV)
2754 assert(
false &&
"Unexpected abbrev ordering!");
2758 auto Abbv = std::make_shared<BitCodeAbbrev>();
2762 CONSTANTS_INTEGER_ABBREV)
2763 assert(
false &&
"Unexpected abbrev ordering!");
2767 auto Abbv = std::make_shared<BitCodeAbbrev>();
2775 CONSTANTS_CE_CAST_Abbrev)
2776 assert(
false &&
"Unexpected abbrev ordering!");
2779 auto Abbv = std::make_shared<BitCodeAbbrev>();
2782 CONSTANTS_NULL_Abbrev)
2783 assert(
false &&
"Unexpected abbrev ordering!");
2789 auto Abbv = std::make_shared<BitCodeAbbrev>();
2797 (
unsigned)FUNCTION_INST_LOAD_ABBREV)
2798 assert(
false &&
"Unexpected abbrev ordering!");
2801 auto Abbv = std::make_shared<BitCodeAbbrev>();
2807 (
unsigned)FUNCTION_INST_BINOP_ABBREV)
2808 assert(
false &&
"Unexpected abbrev ordering!");
2811 auto Abbv = std::make_shared<BitCodeAbbrev>();
2818 (
unsigned)FUNCTION_INST_BINOP_FLAGS_ABBREV)
2819 assert(
false &&
"Unexpected abbrev ordering!");
2822 auto Abbv = std::make_shared<BitCodeAbbrev>();
2829 (
unsigned)FUNCTION_INST_CAST_ABBREV)
2830 assert(
false &&
"Unexpected abbrev ordering!");
2834 auto Abbv = std::make_shared<BitCodeAbbrev>();
2837 (
unsigned)FUNCTION_INST_RET_VOID_ABBREV)
2838 assert(
false &&
"Unexpected abbrev ordering!");
2841 auto Abbv = std::make_shared<BitCodeAbbrev>();
2845 (
unsigned)FUNCTION_INST_RET_VAL_ABBREV)
2846 assert(
false &&
"Unexpected abbrev ordering!");
2849 auto Abbv = std::make_shared<BitCodeAbbrev>();
2852 (
unsigned)FUNCTION_INST_UNREACHABLE_ABBREV)
2853 assert(
false &&
"Unexpected abbrev ordering!");
2856 auto Abbv = std::make_shared<BitCodeAbbrev>();
2864 (
unsigned)FUNCTION_INST_GEP_ABBREV)
2865 assert(
false &&
"Unexpected abbrev ordering!");
2871void DXILBitcodeWriter::writeModuleVersion() {
2886 DXILBitcodeWriter::writeModuleVersion();
2892 writeAttributeGroupTable();
2895 writeAttributeTable();
2907 writeModuleConstants();
2910 writeModuleMetadataKinds();
2913 writeModuleMetadata();
2918 writeFunctionLevelValueSymbolTable(M.getValueSymbolTable());
2922 if (!
F.isDeclaration())
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")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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...
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
Module.h This file contains the declarations for the Module class.
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
Sentinal 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.
bool isConditional() const
BasicBlock * getSuccessor(unsigned i) const
Value * getCondition() const
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 parameter 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
BasicBlock * getUnwindDest() const
BasicBlock * getNormalDest() 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_MMXTyID
MMX vectors (64 bits, X86 specific)
@ 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.
BitcodeWriter(SmallVectorImpl< char > &Buffer, raw_fd_stream *FS=nullptr)
Create a BitcodeWriter that writes to Buffer.
void writeModule(const Module &M)
Write the specified module to the buffer specified at construction time.
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...
uint64_t computeBitsRequiredForTypeIndicies() const
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.
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
A raw_ostream of a file for reading/writing/seeking.
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.
bool getAlign(const Function &F, unsigned index, unsigned &align)
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.