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"
63};
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()),
140 GlobalValueId = VE.getValues().size();
141
142 for (auto El : PointerMap)
143 VE.EnumerateType(El.second);
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());
201 return VE.getValueID(VI.getValue());
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();
219 void writeValueAsMetadata(const ValueAsMetadata *MD,
220 SmallVectorImpl<uint64_t> &Record);
221 void writeMDTuple(const MDTuple *N, SmallVectorImpl<uint64_t> &Record,
222 unsigned Abbrev);
223 void writeDILocation(const DILocation *N, SmallVectorImpl<uint64_t> &Record,
224 unsigned &Abbrev);
225 void writeGenericDINode(const GenericDINode *N,
226 SmallVectorImpl<uint64_t> &Record, unsigned &Abbrev) {
228 }
229 void writeDISubrange(const DISubrange *N, SmallVectorImpl<uint64_t> &Record,
230 unsigned Abbrev);
231 void writeDIGenericSubrange(const DIGenericSubrange *N,
232 SmallVectorImpl<uint64_t> &Record,
233 unsigned Abbrev) {
234 llvm_unreachable("DXIL cannot contain DIGenericSubrange Nodes");
235 }
236 void writeDIEnumerator(const DIEnumerator *N,
237 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
238 void writeDIBasicType(const DIBasicType *N, SmallVectorImpl<uint64_t> &Record,
239 unsigned Abbrev);
240 void writeDIFixedPointType(const DIFixedPointType *N,
241 SmallVectorImpl<uint64_t> &Record,
242 unsigned Abbrev) {
243 llvm_unreachable("DXIL cannot contain DIFixedPointType Nodes");
244 }
245 void writeDIStringType(const DIStringType *N,
246 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev) {
248 }
249 void writeDIDerivedType(const DIDerivedType *N,
250 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
251 void writeDISubrangeType(const DISubrangeType *N,
252 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev) {
253 llvm_unreachable("DXIL cannot contain DISubrangeType Nodes");
254 }
255 void writeDICompositeType(const DICompositeType *N,
256 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
257 void writeDISubroutineType(const DISubroutineType *N,
258 SmallVectorImpl<uint64_t> &Record,
259 unsigned Abbrev);
260 void writeDIFile(const DIFile *N, SmallVectorImpl<uint64_t> &Record,
261 unsigned Abbrev);
262 void writeDICompileUnit(const DICompileUnit *N,
263 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
264 void writeDISubprogram(const DISubprogram *N,
265 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
266 void writeDILexicalBlock(const DILexicalBlock *N,
267 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
268 void writeDILexicalBlockFile(const DILexicalBlockFile *N,
269 SmallVectorImpl<uint64_t> &Record,
270 unsigned Abbrev);
271 void writeDICommonBlock(const DICommonBlock *N,
272 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev) {
274 }
275 void writeDINamespace(const DINamespace *N, SmallVectorImpl<uint64_t> &Record,
276 unsigned Abbrev);
277 void writeDIMacro(const DIMacro *N, SmallVectorImpl<uint64_t> &Record,
278 unsigned Abbrev) {
280 }
281 void writeDIMacroFile(const DIMacroFile *N, SmallVectorImpl<uint64_t> &Record,
282 unsigned Abbrev) {
284 }
285 void writeDIArgList(const DIArgList *N, SmallVectorImpl<uint64_t> &Record,
286 unsigned Abbrev) {
288 }
289 void writeDIAssignID(const DIAssignID *N, SmallVectorImpl<uint64_t> &Record,
290 unsigned Abbrev) {
291
292
293
295 }
296 void writeDIModule(const DIModule *N, SmallVectorImpl<uint64_t> &Record,
297 unsigned Abbrev);
298 void writeDITemplateTypeParameter(const DITemplateTypeParameter *N,
299 SmallVectorImpl<uint64_t> &Record,
300 unsigned Abbrev);
301 void writeDITemplateValueParameter(const DITemplateValueParameter *N,
302 SmallVectorImpl<uint64_t> &Record,
303 unsigned Abbrev);
304 void writeDIGlobalVariable(const DIGlobalVariable *N,
305 SmallVectorImpl<uint64_t> &Record,
306 unsigned Abbrev);
307 void writeDILocalVariable(const DILocalVariable *N,
308 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
309 void writeDILabel(const DILabel *N, SmallVectorImpl<uint64_t> &Record,
310 unsigned Abbrev) {
312 }
313 void writeDIExpression(const DIExpression *N,
314 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
315 void writeDIGlobalVariableExpression(const DIGlobalVariableExpression *N,
316 SmallVectorImpl<uint64_t> &Record,
317 unsigned Abbrev) {
318 llvm_unreachable("DXIL cannot contain GlobalVariableExpression Nodes");
319 }
320 void writeDIObjCProperty(const DIObjCProperty *N,
321 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
322 void writeDIImportedEntity(const DIImportedEntity *N,
323 SmallVectorImpl<uint64_t> &Record,
324 unsigned Abbrev);
325 unsigned createNamedMetadataAbbrev();
326 void writeNamedMetadata(SmallVectorImpl<uint64_t> &Record);
327 unsigned createMetadataStringsAbbrev();
329 SmallVectorImpl<uint64_t> &Record);
331 SmallVectorImpl<uint64_t> &Record,
332 std::vector *MDAbbrevs = nullptr,
333 std::vector<uint64_t> *IndexPos = nullptr);
334 void writeModuleMetadata();
335 void writeFunctionMetadata(const Function &F);
336 void writeFunctionMetadataAttachment(const Function &F);
337 void pushGlobalMetadataAttachment(SmallVectorImpl<uint64_t> &Record,
338 const GlobalObject &GO);
339 void writeModuleMetadataKinds();
340 void writeOperandBundleTags();
341 void writeSyncScopeNames();
342 void writeConstants(unsigned FirstVal, unsigned LastVal, bool isGlobal);
343 void writeModuleConstants();
344 bool pushValueAndType(const Value *V, unsigned InstID,
345 SmallVectorImpl &Vals);
346 void writeOperandBundles(const CallBase &CB, unsigned InstID);
347 void pushValue(const Value *V, unsigned InstID,
348 SmallVectorImpl &Vals);
349 void pushValueSigned(const Value *V, unsigned InstID,
350 SmallVectorImpl<uint64_t> &Vals);
351 void writeInstruction(const Instruction &I, unsigned InstID,
352 SmallVectorImpl &Vals);
353 void writeFunctionLevelValueSymbolTable(const ValueSymbolTable &VST);
354 void writeGlobalValueSymbolTable(
355 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
356 void writeFunction(const Function &F);
357 void writeBlockInfo();
358
359 unsigned getEncodedSyncScopeID(SyncScope::ID SSID) { return unsigned(SSID); }
360
361 unsigned getEncodedAlign(MaybeAlign Alignment) { return encode(Alignment); }
362
363 unsigned getTypeID(Type *T, const Value *V = nullptr);
364
365
366
367
368 unsigned getGlobalObjectValueTypeID(Type *T, const GlobalObject *G);
369};
370
371}
372}
373
374using namespace llvm;
376
377
378
379
380
383
384 Stream->Emit((unsigned)'B', 8);
385 Stream->Emit((unsigned)'C', 8);
386 Stream->Emit(0x0, 4);
387 Stream->Emit(0xC, 4);
388 Stream->Emit(0xE, 4);
389 Stream->Emit(0xD, 4);
390}
391
393
394
397 Buffer.reserve(256 * 1024);
398
399
400
401 Triple TT(M.getTargetTriple());
402 if (TT.isOSDarwin() || TT.isOSBinFormatMachO())
404
407
408
409 if (!Buffer.empty())
411}
412
413void BitcodeWriter::writeBlob(unsigned Block, unsigned Record, StringRef Blob) {
415
416 auto Abbv = std::make_shared();
419 auto AbbrevNo = Stream->EmitAbbrev(std::move(Abbv));
420
422
424}
425
427
428
429
430
431
432 assert(M.isMaterialized());
433 Mods.push_back(const_cast<Module *>(&M));
434
435 DXILBitcodeWriter ModuleWriter(M, Buffer, StrtabBuilder, *Stream);
436 ModuleWriter.write();
437}
438
439
440
441
442
444 switch (Opcode) {
445 default:
447 case Instruction::Trunc:
449 case Instruction::ZExt:
451 case Instruction::SExt:
453 case Instruction::FPToUI:
455 case Instruction::FPToSI:
457 case Instruction::UIToFP:
459 case Instruction::SIToFP:
461 case Instruction::FPTrunc:
463 case Instruction::FPExt:
465 case Instruction::PtrToInt:
467 case Instruction::IntToPtr:
469 case Instruction::BitCast:
471 case Instruction::AddrSpaceCast:
473 }
474}
475
477 switch (Opcode) {
478 default:
480 case Instruction::FNeg:
482 }
483}
484
486 switch (Opcode) {
487 default:
489 case Instruction::Add:
490 case Instruction::FAdd:
492 case Instruction::Sub:
493 case Instruction::FSub:
495 case Instruction::Mul:
496 case Instruction::FMul:
498 case Instruction::UDiv:
500 case Instruction::FDiv:
501 case Instruction::SDiv:
503 case Instruction::URem:
505 case Instruction::FRem:
506 case Instruction::SRem:
508 case Instruction::Shl:
510 case Instruction::LShr:
512 case Instruction::AShr:
514 case Instruction::And:
516 case Instruction::Or:
518 case Instruction::Xor:
520 }
521}
522
523unsigned DXILBitcodeWriter::getTypeID(Type *T, const Value *V) {
524 if (->isPointerTy() &&
525
526
529 auto It = PointerMap.find(V);
530 if (It != PointerMap.end())
531 return VE.getTypeID(It->second);
532
533
534
535
538 return VE.getTypeID(I8PtrTy);
539}
540
541unsigned DXILBitcodeWriter::getGlobalObjectValueTypeID(Type *T,
543 auto It = PointerMap.find(G);
544 if (It != PointerMap.end()) {
547 }
549}
550
552 switch (Op) {
553 default:
585 }
586}
587
589 switch (Ordering) {
604 }
606}
607
610 unsigned AbbrevToUse) {
612
613
614 for (char C : Str) {
616 AbbrevToUse = 0;
618 }
619
620
621 Stream.EmitRecord(Code, Vals, AbbrevToUse);
622}
623
625 switch (Kind) {
626 case Attribute::Alignment:
628 case Attribute::AlwaysInline:
630 case Attribute::Builtin:
632 case Attribute::ByVal:
634 case Attribute::Convergent:
636 case Attribute::InAlloca:
638 case Attribute::Cold:
640 case Attribute::InlineHint:
642 case Attribute::InReg:
644 case Attribute::JumpTable:
646 case Attribute::MinSize:
648 case Attribute::Naked:
650 case Attribute::Nest:
652 case Attribute::NoAlias:
654 case Attribute::NoBuiltin:
656 case Attribute::NoDuplicate:
658 case Attribute::NoImplicitFloat:
660 case Attribute::NoInline:
662 case Attribute::NonLazyBind:
664 case Attribute::NonNull:
666 case Attribute::Dereferenceable:
668 case Attribute::DereferenceableOrNull:
670 case Attribute::NoRedZone:
672 case Attribute::NoReturn:
674 case Attribute::NoUnwind:
676 case Attribute::OptimizeForSize:
678 case Attribute::OptimizeNone:
680 case Attribute::ReadNone:
682 case Attribute::ReadOnly:
684 case Attribute::Returned:
686 case Attribute::ReturnsTwice:
688 case Attribute::SExt:
690 case Attribute::StackAlignment:
692 case Attribute::StackProtect:
694 case Attribute::StackProtectReq:
696 case Attribute::StackProtectStrong:
698 case Attribute::SafeStack:
700 case Attribute::StructRet:
702 case Attribute::SanitizeAddress:
704 case Attribute::SanitizeThread:
706 case Attribute::SanitizeMemory:
708 case Attribute::UWTable:
710 case Attribute::ZExt:
713 llvm_unreachable("Can not encode end-attribute kinds marker.");
719 default:
720 llvm_unreachable("Trying to encode attribute not supported by DXIL. These "
721 "should be stripped in DXILPrepare");
722 }
723
725}
726
729 if ((int64_t)V >= 0)
731 else
733}
734
737
738
739
740
741 unsigned NumWords = A.getActiveWords();
742 const uint64_t *RawData = A.getRawData();
743 for (unsigned i = 0; i < NumWords; i++)
745}
746
749
751 if (OBO->hasNoSignedWrap())
753 if (OBO->hasNoUnsignedWrap())
756 if (PEO->isExact())
759 if (FPMO->hasAllowReassoc() || FPMO->hasAllowContract())
761 if (FPMO->hasNoNaNs())
763 if (FPMO->hasNoInfs())
765 if (FPMO->hasNoSignedZeros())
767 if (FPMO->hasAllowReciprocal())
769 }
770
771 return Flags;
772}
773
774unsigned
776 switch (Linkage) {
778 return 0;
780 return 16;
782 return 2;
784 return 3;
786 return 18;
788 return 7;
790 return 8;
792 return 9;
794 return 17;
796 return 19;
798 return 12;
799 }
801}
802
806
810 return 0;
812 return 1;
814 return 2;
815 }
817}
818
822 return 0;
824 return 1;
826 return 2;
827 }
829}
830
834 return 0;
836 return 1;
838 return 2;
840 return 3;
842 return 4;
843 }
845}
846
848 switch (C.getSelectionKind()) {
859 }
861}
862
863
864
865
866
867void DXILBitcodeWriter::writeAttributeGroupTable() {
868 const std::vectorValueEnumerator::IndexAndAttrSet &AttrGrps =
869 VE.getAttributeGroups();
870 if (AttrGrps.empty())
871 return;
872
874
877 unsigned AttrListIndex = Pair.first;
879 Record.push_back(VE.getAttributeGroupID(Pair));
880 Record.push_back(AttrListIndex);
881
883 if (Attr.isEnumAttribute()) {
886 "DXIL does not support attributes above ATTR_KIND_ARGMEMONLY");
888 Record.push_back(Val);
889 } else if (Attr.isIntAttribute()) {
890 if (Attr.getKindAsEnum() == Attribute::AttrKind::Memory) {
895 } else {
899 }
903 }
904 }
905 } else {
908 "DXIL does not support attributes above ATTR_KIND_ARGMEMONLY");
911 Record.push_back(Attr.getValueAsInt());
912 }
913 } else {
914 StringRef Kind = Attr.getKindAsString();
915 StringRef Val = Attr.getValueAsString();
916
920 if (!Val.empty()) {
923 }
924 }
925 }
926
929 }
930
931 Stream.ExitBlock();
932}
933
934void DXILBitcodeWriter::writeAttributeTable() {
935 const std::vector &Attrs = VE.getAttributeLists();
936 if (Attrs.empty())
937 return;
938
940
941 SmallVector<uint64_t, 64> Record;
942 for (AttributeList AL : Attrs) {
943 for (unsigned i : AL.indexes()) {
944 AttributeSet AS = AL.getAttributes(i);
946 Record.push_back(VE.getAttributeGroupID({i, AS}));
947 }
948
951 }
952
953 Stream.ExitBlock();
954}
955
956
957void DXILBitcodeWriter::writeTypeTable() {
959
961 SmallVector<uint64_t, 64> TypeVals;
962
963 uint64_t NumBits = VE.computeBitsRequiredForTypeIndices();
964
965
966 auto Abbv = std::make_shared();
969 Abbv->Add(BitCodeAbbrevOp(0));
970 unsigned PtrAbbrev = Stream.EmitAbbrev(std::move(Abbv));
971
972
973 Abbv = std::make_shared();
978 unsigned FunctionAbbrev = Stream.EmitAbbrev(std::move(Abbv));
979
980
981 Abbv = std::make_shared();
986 unsigned StructAnonAbbrev = Stream.EmitAbbrev(std::move(Abbv));
987
988
989 Abbv = std::make_shared();
993 unsigned StructNameAbbrev = Stream.EmitAbbrev(std::move(Abbv));
994
995
996 Abbv = std::make_shared();
1001 unsigned StructNamedAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1002
1003
1004 Abbv = std::make_shared();
1008 unsigned ArrayAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1009
1010
1011 TypeVals.push_back(TypeList.size());
1013 TypeVals.clear();
1014
1015
1016 for (Type *T : TypeList) {
1017 int AbbrevToUse = 0;
1018 unsigned Code = 0;
1019
1020 switch (T->getTypeID()) {
1026 break;
1029 break;
1032 break;
1035 break;
1038 break;
1041 break;
1044 break;
1047 break;
1050 break;
1053 break;
1055
1058 break;
1061
1067 AbbrevToUse = PtrAbbrev;
1068 break;
1069 }
1071
1072
1073
1074
1078 "dxilOpaquePtrReservedName", StructNameAbbrev);
1079 break;
1080 }
1083
1085 TypeVals.push_back(FT->isVarArg());
1086 TypeVals.push_back(getTypeID(FT->getReturnType()));
1087 for (Type *PTy : FT->params())
1088 TypeVals.push_back(getTypeID(PTy));
1089 AbbrevToUse = FunctionAbbrev;
1090 break;
1091 }
1094
1096
1097 for (Type *ElTy : ST->elements())
1098 TypeVals.push_back(getTypeID(ElTy));
1099
1100 if (ST->isLiteral()) {
1102 AbbrevToUse = StructAnonAbbrev;
1103 } else {
1104 if (ST->isOpaque()) {
1106 } else {
1108 AbbrevToUse = StructNamedAbbrev;
1109 }
1110
1111
1112 if (->getName().empty())
1114 StructNameAbbrev);
1115 }
1116 break;
1117 }
1120
1122 TypeVals.push_back(AT->getNumElements());
1123 TypeVals.push_back(getTypeID(AT->getElementType()));
1124 AbbrevToUse = ArrayAbbrev;
1125 break;
1126 }
1130
1132 TypeVals.push_back(VT->getElementCount().getKnownMinValue());
1133 TypeVals.push_back(getTypeID(VT->getElementType()));
1134 break;
1135 }
1136 }
1137
1138
1139 Stream.EmitRecord(Code, TypeVals, AbbrevToUse);
1140 TypeVals.clear();
1141 }
1142
1143 Stream.ExitBlock();
1144}
1145
1146void DXILBitcodeWriter::writeComdats() {
1148 for (const Comdat *C : VE.getComdats()) {
1149
1151 size_t Size = C->getName().size();
1154 for (char Chr : C->getName())
1155 Vals.push_back((unsigned char)Chr);
1158 }
1159}
1160
1161void DXILBitcodeWriter::writeValueSymbolTableForwardDecl() {}
1162
1163
1164
1165
1166void DXILBitcodeWriter::writeModuleInfo() {
1167
1168
1169
1170
1171 StringRef Triple = "dxil-ms-dx";
1172 StringRef DL = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-"
1173 "f16:16-f32:32-f64:64-n8:16:32:64";
1176
1177 if (!M.getModuleInlineAsm().empty())
1179 0 );
1180
1181
1182
1183 std::map<std::string, unsigned> SectionMap;
1184 std::map<std::string, unsigned> GCMap;
1186 unsigned MaxGlobalType = 0;
1187 const auto UpdateMaxAlignment = [&MaxAlignment](const MaybeAlign A) {
1188 if (A)
1190 };
1191 for (const GlobalVariable &GV : M.globals()) {
1192 UpdateMaxAlignment(GV.getAlign());
1193
1194
1195 MaxGlobalType = std::max(
1196 MaxGlobalType, getGlobalObjectValueTypeID(GV.getValueType(), &GV));
1197 if (GV.hasSection()) {
1198
1199 unsigned &Entry = SectionMap[std::string(GV.getSection())];
1200 if (!Entry) {
1202 GV.getSection(), 0 );
1203 Entry = SectionMap.size();
1204 }
1205 }
1206 }
1207 for (const Function &F : M) {
1208 UpdateMaxAlignment(F.getAlign());
1209 if (F.hasSection()) {
1210
1211 unsigned &Entry = SectionMap[std::string(F.getSection())];
1212 if (!Entry) {
1214 0 );
1215 Entry = SectionMap.size();
1216 }
1217 }
1218 if (F.hasGC()) {
1219
1220 unsigned &Entry = GCMap[F.getGC()];
1221 if (!Entry) {
1223 0 );
1224 Entry = GCMap.size();
1225 }
1226 }
1227 }
1228
1229
1230 unsigned SimpleGVarAbbrev = 0;
1231 if (!M.global_empty()) {
1232
1233
1234 auto Abbv = std::make_shared();
1239
1240
1243 if (!MaxAlignment)
1244 Abbv->Add(BitCodeAbbrevOp(0));
1245 else {
1246 unsigned MaxEncAlignment = getEncodedAlign(MaxAlignment);
1249 }
1250 if (SectionMap.empty())
1251 Abbv->Add(BitCodeAbbrevOp(0));
1252 else
1255
1256 SimpleGVarAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1257 }
1258
1259
1261 for (const GlobalVariable &GV : M.globals()) {
1262 unsigned AbbrevToUse = 0;
1263
1264
1265
1266
1267
1268 Vals.push_back(getGlobalObjectValueTypeID(GV.getValueType(), &GV));
1270 GV.getType()->getAddressSpace() << 2 | 2 |
1271 (GV.isConstant() ? 1 : 0));
1272
1274 GV.isDeclaration() ? 0 : (VE.getValueID(GV.getInitializer()) + 1));
1276 Vals.push_back(getEncodedAlign(GV.getAlign()));
1277 Vals.push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1278 : 0);
1279 if (GV.isThreadLocal() ||
1282 GV.isExternallyInitialized() ||
1284 GV.hasComdat()) {
1288 Vals.push_back(GV.isExternallyInitialized());
1290 Vals.push_back(GV.hasComdat() ? VE.getComdatID(GV.getComdat()) : 0);
1291 } else {
1292 AbbrevToUse = SimpleGVarAbbrev;
1293 }
1294
1297 }
1298
1299
1300 for (const Function &F : M) {
1301
1302
1303
1304 Vals.push_back(getGlobalObjectValueTypeID(F.getFunctionType(), &F));
1308 Vals.push_back(VE.getAttributeListID(F.getAttributes()));
1309 Vals.push_back(getEncodedAlign(F.getAlign()));
1310 Vals.push_back(F.hasSection() ? SectionMap[std::string(F.getSection())]
1311 : 0);
1313 Vals.push_back(F.hasGC() ? GCMap[F.getGC()] : 0);
1316 F.hasPrologueData() ? (VE.getValueID(F.getPrologueData()) + 1) : 0);
1318 Vals.push_back(F.hasComdat() ? VE.getComdatID(F.getComdat()) : 0);
1319 Vals.push_back(F.hasPrefixData() ? (VE.getValueID(F.getPrefixData()) + 1)
1320 : 0);
1322 F.hasPersonalityFn() ? (VE.getValueID(F.getPersonalityFn()) + 1) : 0);
1323
1324 unsigned AbbrevToUse = 0;
1327 }
1328
1329
1330 for (const GlobalAlias &A : M.aliases()) {
1331
1332 Vals.push_back(getTypeID(A.getValueType(), &A));
1333 Vals.push_back(VE.getValueID(A.getAliasee()));
1339 unsigned AbbrevToUse = 0;
1342 }
1343}
1344
1345void DXILBitcodeWriter::writeValueAsMetadata(
1346 const ValueAsMetadata *MD, SmallVectorImpl<uint64_t> &Record) {
1347
1354 Record.push_back(getTypeID(Ty, V));
1355 Record.push_back(VE.getValueID(V));
1358}
1359
1360void DXILBitcodeWriter::writeMDTuple(const MDTuple *N,
1361 SmallVectorImpl<uint64_t> &Record,
1362 unsigned Abbrev) {
1363 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
1364 Metadata *MD = N->getOperand(i);
1366 "Unexpected function-local metadata");
1367 Record.push_back(VE.getMetadataOrNullID(MD));
1368 }
1371 Record, Abbrev);
1373}
1374
1375void DXILBitcodeWriter::writeDILocation(const DILocation *N,
1376 SmallVectorImpl<uint64_t> &Record,
1377 unsigned &Abbrev) {
1378 if (!Abbrev)
1379 Abbrev = createDILocationAbbrev();
1383 Record.push_back(VE.getMetadataID(N->getScope()));
1384 Record.push_back(VE.getMetadataOrNullID(N->getInlinedAt()));
1385
1388}
1389
1393 return I < 0 ? ~(U << 1) : U << 1;
1394}
1395
1396void DXILBitcodeWriter::writeDISubrange(const DISubrange *N,
1397 SmallVectorImpl<uint64_t> &Record,
1398 unsigned Abbrev) {
1400
1401
1402
1404 assert(Count && "Count is missing or not ConstantInt");
1406
1407
1408 DISubrange::BoundType LowerBound = N->getLowerBound();
1410 "Lower bound provided but not ConstantInt");
1413
1416}
1417
1418void DXILBitcodeWriter::writeDIEnumerator(const DIEnumerator *N,
1419 SmallVectorImpl<uint64_t> &Record,
1420 unsigned Abbrev) {
1423 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1424
1427}
1428
1429void DXILBitcodeWriter::writeDIBasicType(const DIBasicType *N,
1430 SmallVectorImpl<uint64_t> &Record,
1431 unsigned Abbrev) {
1434 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1435 Record.push_back(N->getSizeInBits());
1436 Record.push_back(N->getAlignInBits());
1438
1441}
1442
1443void DXILBitcodeWriter::writeDIDerivedType(const DIDerivedType *N,
1444 SmallVectorImpl<uint64_t> &Record,
1445 unsigned Abbrev) {
1448 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1449 Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1451 Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1452 Record.push_back(VE.getMetadataOrNullID(N->getBaseType()));
1453 Record.push_back(N->getSizeInBits());
1454 Record.push_back(N->getAlignInBits());
1455 Record.push_back(N->getOffsetInBits());
1457 Record.push_back(VE.getMetadataOrNullID(N->getExtraData()));
1458
1461}
1462
1463void DXILBitcodeWriter::writeDICompositeType(const DICompositeType *N,
1464 SmallVectorImpl<uint64_t> &Record,
1465 unsigned Abbrev) {
1468 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1469 Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1471 Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1472 Record.push_back(VE.getMetadataOrNullID(N->getBaseType()));
1473 Record.push_back(N->getSizeInBits());
1474 Record.push_back(N->getAlignInBits());
1475 Record.push_back(N->getOffsetInBits());
1477 Record.push_back(VE.getMetadataOrNullID(N->getElements().get()));
1478 Record.push_back(N->getRuntimeLang());
1479 Record.push_back(VE.getMetadataOrNullID(N->getVTableHolder()));
1480 Record.push_back(VE.getMetadataOrNullID(N->getTemplateParams().get()));
1481 Record.push_back(VE.getMetadataOrNullID(N->getRawIdentifier()));
1482
1485}
1486
1487void DXILBitcodeWriter::writeDISubroutineType(const DISubroutineType *N,
1488 SmallVectorImpl<uint64_t> &Record,
1489 unsigned Abbrev) {
1492 Record.push_back(VE.getMetadataOrNullID(N->getTypeArray().get()));
1493
1496}
1497
1498void DXILBitcodeWriter::writeDIFile(const DIFile *N,
1499 SmallVectorImpl<uint64_t> &Record,
1500 unsigned Abbrev) {
1502 Record.push_back(VE.getMetadataOrNullID(N->getRawFilename()));
1503 Record.push_back(VE.getMetadataOrNullID(N->getRawDirectory()));
1504
1507}
1508
1509void DXILBitcodeWriter::writeDICompileUnit(const DICompileUnit *N,
1510 SmallVectorImpl<uint64_t> &Record,
1511 unsigned Abbrev) {
1513 Record.push_back(N->getSourceLanguage().getUnversionedName());
1514 Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1515 Record.push_back(VE.getMetadataOrNullID(N->getRawProducer()));
1517 Record.push_back(VE.getMetadataOrNullID(N->getRawFlags()));
1518 Record.push_back(N->getRuntimeVersion());
1519 Record.push_back(VE.getMetadataOrNullID(N->getRawSplitDebugFilename()));
1520 Record.push_back(N->getEmissionKind());
1521 Record.push_back(VE.getMetadataOrNullID(N->getEnumTypes().get()));
1522 Record.push_back(VE.getMetadataOrNullID(N->getRetainedTypes().get()));
1523 Record.push_back( 0);
1524 Record.push_back(VE.getMetadataOrNullID(N->getGlobalVariables().get()));
1525 Record.push_back(VE.getMetadataOrNullID(N->getImportedEntities().get()));
1527
1530}
1531
1532void DXILBitcodeWriter::writeDISubprogram(const DISubprogram *N,
1533 SmallVectorImpl<uint64_t> &Record,
1534 unsigned Abbrev) {
1536 Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1537 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1538 Record.push_back(VE.getMetadataOrNullID(N->getRawLinkageName()));
1539 Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1541 Record.push_back(VE.getMetadataOrNullID(N->getType()));
1542 Record.push_back(N->isLocalToUnit());
1543 Record.push_back(N->isDefinition());
1544 Record.push_back(N->getScopeLine());
1545 Record.push_back(VE.getMetadataOrNullID(N->getContainingType()));
1546 Record.push_back(N->getVirtuality());
1547 Record.push_back(N->getVirtualIndex());
1550 Record.push_back(VE.getMetadataOrNullID(N->getRawUnit()));
1551 Record.push_back(VE.getMetadataOrNullID(N->getTemplateParams().get()));
1552 Record.push_back(VE.getMetadataOrNullID(N->getDeclaration()));
1553 Record.push_back(VE.getMetadataOrNullID(N->getRetainedNodes().get()));
1554
1557}
1558
1559void DXILBitcodeWriter::writeDILexicalBlock(const DILexicalBlock *N,
1560 SmallVectorImpl<uint64_t> &Record,
1561 unsigned Abbrev) {
1563 Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1564 Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1567
1570}
1571
1572void DXILBitcodeWriter::writeDILexicalBlockFile(
1573 const DILexicalBlockFile *N, SmallVectorImpl<uint64_t> &Record,
1574 unsigned Abbrev) {
1576 Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1577 Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1578 Record.push_back(N->getDiscriminator());
1579
1582}
1583
1584void DXILBitcodeWriter::writeDINamespace(const DINamespace *N,
1585 SmallVectorImpl<uint64_t> &Record,
1586 unsigned Abbrev) {
1588 Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1589 Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1590 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1591 Record.push_back( 0);
1592
1595}
1596
1597void DXILBitcodeWriter::writeDIModule(const DIModule *N,
1598 SmallVectorImpl<uint64_t> &Record,
1599 unsigned Abbrev) {
1601 for (auto &I : N->operands())
1602 Record.push_back(VE.getMetadataOrNullID(I));
1603
1606}
1607
1608void DXILBitcodeWriter::writeDITemplateTypeParameter(
1609 const DITemplateTypeParameter *N, SmallVectorImpl<uint64_t> &Record,
1610 unsigned Abbrev) {
1612 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1613 Record.push_back(VE.getMetadataOrNullID(N->getType()));
1614
1617}
1618
1619void DXILBitcodeWriter::writeDITemplateValueParameter(
1620 const DITemplateValueParameter *N, SmallVectorImpl<uint64_t> &Record,
1621 unsigned Abbrev) {
1624 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1625 Record.push_back(VE.getMetadataOrNullID(N->getType()));
1626 Record.push_back(VE.getMetadataOrNullID(N->getValue()));
1627
1630}
1631
1632void DXILBitcodeWriter::writeDIGlobalVariable(const DIGlobalVariable *N,
1633 SmallVectorImpl<uint64_t> &Record,
1634 unsigned Abbrev) {
1636 Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1637 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1638 Record.push_back(VE.getMetadataOrNullID(N->getRawLinkageName()));
1639 Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1641 Record.push_back(VE.getMetadataOrNullID(N->getType()));
1642 Record.push_back(N->isLocalToUnit());
1643 Record.push_back(N->isDefinition());
1644 Record.push_back( 0);
1645 Record.push_back(VE.getMetadataOrNullID(N->getStaticDataMemberDeclaration()));
1646
1649}
1650
1651void DXILBitcodeWriter::writeDILocalVariable(const DILocalVariable *N,
1652 SmallVectorImpl<uint64_t> &Record,
1653 unsigned Abbrev) {
1656 Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1657 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1658 Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1660 Record.push_back(VE.getMetadataOrNullID(N->getType()));
1663
1666}
1667
1668void DXILBitcodeWriter::writeDIExpression(const DIExpression *N,
1669 SmallVectorImpl<uint64_t> &Record,
1670 unsigned Abbrev) {
1671 Record.reserve(N->getElements().size() + 1);
1672
1674 Record.append(N->elements_begin(), N->elements_end());
1675
1678}
1679
1680void DXILBitcodeWriter::writeDIObjCProperty(const DIObjCProperty *N,
1681 SmallVectorImpl<uint64_t> &Record,
1682 unsigned Abbrev) {
1684}
1685
1686void DXILBitcodeWriter::writeDIImportedEntity(const DIImportedEntity *N,
1687 SmallVectorImpl<uint64_t> &Record,
1688 unsigned Abbrev) {
1691 Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1692 Record.push_back(VE.getMetadataOrNullID(N->getEntity()));
1694 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1695
1698}
1699
1700unsigned DXILBitcodeWriter::createDILocationAbbrev() {
1701
1702
1703
1704
1705 std::shared_ptr Abbv = std::make_shared();
1712 return Stream.EmitAbbrev(std::move(Abbv));
1713}
1714
1715unsigned DXILBitcodeWriter::createGenericDINodeAbbrev() {
1716
1717
1718
1719
1720 std::shared_ptr Abbv = std::make_shared();
1728 return Stream.EmitAbbrev(std::move(Abbv));
1729}
1730
1732 SmallVectorImpl<uint64_t> &Record,
1733 std::vector *MDAbbrevs,
1734 std::vector<uint64_t> *IndexPos) {
1735 if (MDs.empty())
1736 return;
1737
1738
1739#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
1740#include "llvm/IR/Metadata.def"
1741
1742 for (const Metadata *MD : MDs) {
1743 if (IndexPos)
1744 IndexPos->push_back(Stream.GetCurrentBitNo());
1746 assert(N->isResolved() && "Expected forward references to be resolved");
1747
1748 switch (N->getMetadataID()) {
1749 default:
1751#define HANDLE_MDNODE_LEAF(CLASS) \
1752 case Metadata::CLASS##Kind: \
1753 if (MDAbbrevs) \
1754 write##CLASS(cast(N), Record, \
1755 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
1756 else \
1757 write##CLASS(cast(N), Record, CLASS##Abbrev); \
1758 continue;
1759#include "llvm/IR/Metadata.def"
1760 }
1761 }
1763 }
1764}
1765
1766unsigned DXILBitcodeWriter::createMetadataStringsAbbrev() {
1767 auto Abbv = std::make_shared();
1771 return Stream.EmitAbbrev(std::move(Abbv));
1772}
1773
1774void DXILBitcodeWriter::writeMetadataStrings(
1776 if (Strings.empty())
1777 return;
1778
1779 unsigned MDSAbbrev = createMetadataStringsAbbrev();
1780
1781 for (const Metadata *MD : Strings) {
1783
1785
1786
1789 }
1790}
1791
1792void DXILBitcodeWriter::writeModuleMetadata() {
1793 if (!VE.hasMDs() && M.named_metadata_empty())
1794 return;
1795
1797
1798
1799
1800 std::vector MDAbbrevs;
1801
1803 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
1804 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
1805 createGenericDINodeAbbrev();
1806
1807 unsigned NameAbbrev = 0;
1808 if (!M.named_metadata_empty()) {
1809
1810 std::shared_ptr Abbv = std::make_shared();
1814 NameAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1815 }
1816
1817 SmallVector<uint64_t, 64> Record;
1818 writeMetadataStrings(VE.getMDStrings(), Record);
1819
1820 std::vector<uint64_t> IndexPos;
1821 IndexPos.reserve(VE.getNonMDStrings().size());
1822 writeMetadataRecords(VE.getNonMDStrings(), Record, &MDAbbrevs, &IndexPos);
1823
1824
1825 for (const NamedMDNode &NMD : M.named_metadata()) {
1826
1827 StringRef Str = NMD.getName();
1828 Record.append(Str.bytes_begin(), Str.bytes_end());
1831
1832
1833 for (const MDNode *N : NMD.operands())
1834 Record.push_back(VE.getMetadataID(N));
1837 }
1838
1839 Stream.ExitBlock();
1840}
1841
1842void DXILBitcodeWriter::writeFunctionMetadata(const Function &F) {
1843 if (!VE.hasMDs())
1844 return;
1845
1847 SmallVector<uint64_t, 64> Record;
1848 writeMetadataStrings(VE.getMDStrings(), Record);
1849 writeMetadataRecords(VE.getNonMDStrings(), Record);
1850 Stream.ExitBlock();
1851}
1852
1853void DXILBitcodeWriter::writeFunctionMetadataAttachment(const Function &F) {
1855
1856 SmallVector<uint64_t, 64> Record;
1857
1858
1859
1861 F.getAllMetadata(MDs);
1862 if (!MDs.empty()) {
1863 for (const auto &I : MDs) {
1865 Record.push_back(VE.getMetadataID(I.second));
1866 }
1869 }
1870
1871 for (const BasicBlock &BB : F)
1872 for (const Instruction &I : BB) {
1873 MDs.clear();
1874 I.getAllMetadataOtherThanDebugLoc(MDs);
1875
1876
1877 if (MDs.empty())
1878 continue;
1879
1880 Record.push_back(VE.getInstructionID(&I));
1881
1882 for (unsigned i = 0, e = MDs.size(); i != e; ++i) {
1884 Record.push_back(VE.getMetadataID(MDs[i].second));
1885 }
1888 }
1889
1890 Stream.ExitBlock();
1891}
1892
1893void DXILBitcodeWriter::writeModuleMetadataKinds() {
1894 SmallVector<uint64_t, 64> Record;
1895
1896
1897
1899 M.getMDKindNames(Names);
1900
1901 if (Names.empty())
1902 return;
1903
1905
1906 for (unsigned MDKindID = 0, e = Names.size(); MDKindID != e; ++MDKindID) {
1908 StringRef KName = Names[MDKindID];
1910
1913 }
1914
1915 Stream.ExitBlock();
1916}
1917
1918void DXILBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal,
1919 bool isGlobal) {
1920 if (FirstVal == LastVal)
1921 return;
1922
1924
1925 unsigned AggregateAbbrev = 0;
1926 unsigned String8Abbrev = 0;
1927 unsigned CString7Abbrev = 0;
1928 unsigned CString6Abbrev = 0;
1929
1930 if (isGlobal) {
1931
1932 auto Abbv = std::make_shared();
1935 Abbv->Add(
1937 AggregateAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1938
1939
1940 Abbv = std::make_shared();
1944 String8Abbrev = Stream.EmitAbbrev(std::move(Abbv));
1945
1946 Abbv = std::make_shared();
1950 CString7Abbrev = Stream.EmitAbbrev(std::move(Abbv));
1951
1952 Abbv = std::make_shared();
1956 CString6Abbrev = Stream.EmitAbbrev(std::move(Abbv));
1957 }
1958
1959 SmallVector<uint64_t, 64> Record;
1960
1962 Type *LastTy = nullptr;
1963 for (unsigned i = FirstVal; i != LastVal; ++i) {
1964 const Value *V = Vals[i].first;
1965
1966 if (V->getType() != LastTy) {
1967 LastTy = V->getType();
1968 Record.push_back(getTypeID(LastTy, V));
1970 CONSTANTS_SETTYPE_ABBREV);
1972 }
1973
1975 Record.push_back(unsigned(IA->hasSideEffects()) |
1976 unsigned(IA->isAlignStack()) << 1 |
1977 unsigned(IA->getDialect() & 1) << 2);
1978
1979
1980 StringRef AsmStr = IA->getAsmString();
1983
1984
1985 StringRef ConstraintStr = IA->getConstraintString();
1987 Record.append(ConstraintStr.begin(), ConstraintStr.end());
1990 continue;
1991 }
1993 unsigned Code = -1U;
1994 unsigned AbbrevToUse = 0;
1995 if (C->isNullValue()) {
2000 if (IV->getBitWidth() <= 64) {
2001 uint64_t V = IV->getSExtValue();
2004 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2005 } else {
2006
2007
2008
2009
2010 unsigned NWords = IV->getValue().getActiveWords();
2011 const uint64_t *RawWords = IV->getValue().getRawData();
2012 for (unsigned i = 0; i != NWords; ++i) {
2014 }
2016 }
2019 Type *Ty = CFP->getType();
2021 Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2023
2024
2025 APInt api = CFP->getValueAPF().bitcastToAPInt();
2027 Record.push_back((p[1] << 48) | (p[0] >> 16));
2028 Record.push_back(p[0] & 0xffffLL);
2030 APInt api = CFP->getValueAPF().bitcastToAPInt();
2034 } else {
2035 assert(0 && "Unknown FP type!");
2036 }
2040
2041 unsigned NumElts = Str->getNumElements();
2042
2043 if (Str->isCString()) {
2045 --NumElts;
2046 } else {
2048 AbbrevToUse = String8Abbrev;
2049 }
2052 for (unsigned i = 0; i != NumElts; ++i) {
2053 unsigned char V = Str->getElementAsInteger(i);
2055 isCStr7 &= (V & 128) == 0;
2056 if (isCStrChar6)
2058 }
2059
2060 if (isCStrChar6)
2061 AbbrevToUse = CString6Abbrev;
2062 else if (isCStr7)
2063 AbbrevToUse = CString7Abbrev;
2064 } else if (const ConstantDataSequential *CDS =
2067 Type *EltTy = CDS->getElementType();
2069 for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2070 Record.push_back(CDS->getElementAsInteger(i));
2071 } else if (EltTy->isFloatTy()) {
2072 for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
2073 union {
2074 float F;
2075 uint32_t I;
2076 };
2077 F = CDS->getElementAsFloat(i);
2079 }
2080 } else {
2081 assert(EltTy->isDoubleTy() && "Unknown ConstantData element type");
2082 for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
2083 union {
2084 double F;
2085 uint64_t I;
2086 };
2087 F = CDS->getElementAsDouble(i);
2089 }
2090 }
2094 for (const Value *Op : C->operands())
2096 AbbrevToUse = AggregateAbbrev;
2098 switch (CE->getOpcode()) {
2099 default:
2104 getTypeID(C->getOperand(0)->getType(), C->getOperand(0)));
2105 Record.push_back(VE.getValueID(C->getOperand(0)));
2106 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2107 } else {
2108 assert(CE->getNumOperands() == 2 && "Unknown constant expr!");
2111 Record.push_back(VE.getValueID(C->getOperand(0)));
2112 Record.push_back(VE.getValueID(C->getOperand(1)));
2114 if (Flags != 0)
2116 }
2117 break;
2118 case Instruction::GetElementPtr: {
2121 if (GO->isInBounds())
2123 Record.push_back(getTypeID(GO->getSourceElementType()));
2124 for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i) {
2126 getTypeID(C->getOperand(i)->getType(), C->getOperand(i)));
2127 Record.push_back(VE.getValueID(C->getOperand(i)));
2128 }
2129 break;
2130 }
2131 case Instruction::Select:
2133 Record.push_back(VE.getValueID(C->getOperand(0)));
2134 Record.push_back(VE.getValueID(C->getOperand(1)));
2135 Record.push_back(VE.getValueID(C->getOperand(2)));
2136 break;
2137 case Instruction::ExtractElement:
2139 Record.push_back(getTypeID(C->getOperand(0)->getType()));
2140 Record.push_back(VE.getValueID(C->getOperand(0)));
2141 Record.push_back(getTypeID(C->getOperand(1)->getType()));
2142 Record.push_back(VE.getValueID(C->getOperand(1)));
2143 break;
2144 case Instruction::InsertElement:
2146 Record.push_back(VE.getValueID(C->getOperand(0)));
2147 Record.push_back(VE.getValueID(C->getOperand(1)));
2148 Record.push_back(getTypeID(C->getOperand(2)->getType()));
2149 Record.push_back(VE.getValueID(C->getOperand(2)));
2150 break;
2151 case Instruction::ShuffleVector:
2152
2153
2154
2155
2156 if (C->getType() == C->getOperand(0)->getType()) {
2158 } else {
2160 Record.push_back(getTypeID(C->getOperand(0)->getType()));
2161 }
2162 Record.push_back(VE.getValueID(C->getOperand(0)));
2163 Record.push_back(VE.getValueID(C->getOperand(1)));
2164 Record.push_back(VE.getValueID(C->getOperand(2)));
2165 break;
2166 }
2169 Record.push_back(getTypeID(BA->getFunction()->getType()));
2170 Record.push_back(VE.getValueID(BA->getFunction()));
2171 Record.push_back(VE.getGlobalBasicBlockID(BA->getBasicBlock()));
2172 } else {
2173#ifndef NDEBUG
2174 C->dump();
2175#endif
2177 }
2178 Stream.EmitRecord(Code, Record, AbbrevToUse);
2180 }
2181
2182 Stream.ExitBlock();
2183}
2184
2185void DXILBitcodeWriter::writeModuleConstants() {
2187
2188
2189
2190 for (unsigned i = 0, e = Vals.size(); i != e; ++i) {
2192 writeConstants(i, Vals.size(), true);
2193 return;
2194 }
2195 }
2196}
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206bool DXILBitcodeWriter::pushValueAndType(const Value *V, unsigned InstID,
2207 SmallVectorImpl &Vals) {
2208 unsigned ValID = VE.getValueID(V);
2209
2211 if (ValID >= InstID) {
2212 Vals.push_back(getTypeID(V->getType(), V));
2213 return true;
2214 }
2215 return false;
2216}
2217
2218
2219
2220void DXILBitcodeWriter::pushValue(const Value *V, unsigned InstID,
2221 SmallVectorImpl &Vals) {
2222 unsigned ValID = VE.getValueID(V);
2224}
2225
2226void DXILBitcodeWriter::pushValueSigned(const Value *V, unsigned InstID,
2227 SmallVectorImpl<uint64_t> &Vals) {
2228 unsigned ValID = VE.getValueID(V);
2229 int64_t diff = ((int32_t)InstID - (int32_t)ValID);
2231}
2232
2233
2234void DXILBitcodeWriter::writeInstruction(const Instruction &I, unsigned InstID,
2235 SmallVectorImpl &Vals) {
2236 unsigned Code = 0;
2237 unsigned AbbrevToUse = 0;
2238 VE.setInstructionID(&I);
2239 switch (I.getOpcode()) {
2240 default:
2243 if (!pushValueAndType(I.getOperand(0), InstID, Vals))
2244 AbbrevToUse = (unsigned)FUNCTION_INST_CAST_ABBREV;
2245 Vals.push_back(getTypeID(I.getType(), &I));
2247 } else {
2250 if (!pushValueAndType(I.getOperand(0), InstID, Vals))
2251 AbbrevToUse = (unsigned)FUNCTION_INST_BINOP_ABBREV;
2252 pushValue(I.getOperand(1), InstID, Vals);
2255 if (Flags != 0) {
2256 if (AbbrevToUse == (unsigned)FUNCTION_INST_BINOP_ABBREV)
2257 AbbrevToUse = (unsigned)FUNCTION_INST_BINOP_FLAGS_ABBREV;
2259 }
2260 }
2261 break;
2262
2263 case Instruction::GetElementPtr: {
2265 AbbrevToUse = (unsigned)FUNCTION_INST_GEP_ABBREV;
2267 Vals.push_back(GEPInst.isInBounds());
2268 Vals.push_back(getTypeID(GEPInst.getSourceElementType()));
2269 for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i)
2270 pushValueAndType(I.getOperand(i), InstID, Vals);
2271 break;
2272 }
2273 case Instruction::ExtractValue: {
2275 pushValueAndType(I.getOperand(0), InstID, Vals);
2278 break;
2279 }
2280 case Instruction::InsertValue: {
2282 pushValueAndType(I.getOperand(0), InstID, Vals);
2283 pushValueAndType(I.getOperand(1), InstID, Vals);
2286 break;
2287 }
2288 case Instruction::Select:
2290 pushValueAndType(I.getOperand(1), InstID, Vals);
2291 pushValue(I.getOperand(2), InstID, Vals);
2292 pushValueAndType(I.getOperand(0), InstID, Vals);
2293 break;
2294 case Instruction::ExtractElement:
2296 pushValueAndType(I.getOperand(0), InstID, Vals);
2297 pushValueAndType(I.getOperand(1), InstID, Vals);
2298 break;
2299 case Instruction::InsertElement:
2301 pushValueAndType(I.getOperand(0), InstID, Vals);
2302 pushValue(I.getOperand(1), InstID, Vals);
2303 pushValueAndType(I.getOperand(2), InstID, Vals);
2304 break;
2305 case Instruction::ShuffleVector:
2307 pushValueAndType(I.getOperand(0), InstID, Vals);
2308 pushValue(I.getOperand(1), InstID, Vals);
2310 Vals);
2311 break;
2312 case Instruction::ICmp:
2313 case Instruction::FCmp: {
2314
2316 pushValueAndType(I.getOperand(0), InstID, Vals);
2317 pushValue(I.getOperand(1), InstID, Vals);
2320 if (Flags != 0)
2322 break;
2323 }
2324
2325 case Instruction::Ret: {
2327 unsigned NumOperands = I.getNumOperands();
2328 if (NumOperands == 0)
2329 AbbrevToUse = (unsigned)FUNCTION_INST_RET_VOID_ABBREV;
2330 else if (NumOperands == 1) {
2331 if (!pushValueAndType(I.getOperand(0), InstID, Vals))
2332 AbbrevToUse = (unsigned)FUNCTION_INST_RET_VAL_ABBREV;
2333 } else {
2334 for (unsigned i = 0, e = NumOperands; i != e; ++i)
2335 pushValueAndType(I.getOperand(i), InstID, Vals);
2336 }
2337 } break;
2338 case Instruction::Br: {
2341 Vals.push_back(VE.getValueID(II.getSuccessor(0)));
2342 if (II.isConditional()) {
2343 Vals.push_back(VE.getValueID(II.getSuccessor(1)));
2344 pushValue(II.getCondition(), InstID, Vals);
2345 }
2346 } break;
2347 case Instruction::Switch: {
2350 Vals.push_back(getTypeID(SI.getCondition()->getType()));
2351 pushValue(SI.getCondition(), InstID, Vals);
2352 Vals.push_back(VE.getValueID(SI.getDefaultDest()));
2353 for (auto Case : SI.cases()) {
2354 Vals.push_back(VE.getValueID(Case.getCaseValue()));
2355 Vals.push_back(VE.getValueID(Case.getCaseSuccessor()));
2356 }
2357 } break;
2358 case Instruction::IndirectBr:
2360 Vals.push_back(getTypeID(I.getOperand(0)->getType()));
2361
2362 pushValue(I.getOperand(0), InstID, Vals);
2363 for (unsigned i = 1, e = I.getNumOperands(); i != e; ++i)
2364 Vals.push_back(VE.getValueID(I.getOperand(i)));
2365 break;
2366
2367 case Instruction::Invoke: {
2370 FunctionType *FTy = II->getFunctionType();
2372
2373 Vals.push_back(VE.getAttributeListID(II->getAttributes()));
2374 Vals.push_back(II->getCallingConv() | 1 << 13);
2375 Vals.push_back(VE.getValueID(II->getNormalDest()));
2376 Vals.push_back(VE.getValueID(II->getUnwindDest()));
2378 pushValueAndType(Callee, InstID, Vals);
2379
2380
2381 for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
2382 pushValue(I.getOperand(i), InstID, Vals);
2383
2384
2385 if (FTy->isVarArg()) {
2386 for (unsigned i = FTy->getNumParams(), e = I.getNumOperands() - 3; i != e;
2387 ++i)
2388 pushValueAndType(I.getOperand(i), InstID, Vals);
2389 }
2390 break;
2391 }
2392 case Instruction::Resume:
2394 pushValueAndType(I.getOperand(0), InstID, Vals);
2395 break;
2396 case Instruction::Unreachable:
2398 AbbrevToUse = (unsigned)FUNCTION_INST_UNREACHABLE_ABBREV;
2399 break;
2400
2401 case Instruction::PHI: {
2404
2405
2406
2412 }
2413
2414 Stream.EmitRecord(Code, Vals64, AbbrevToUse);
2416 return;
2417 }
2418
2419 case Instruction::LandingPad: {
2428 else
2430 pushValueAndType(LP.getClause(I), InstID, Vals);
2431 }
2432 break;
2433 }
2434
2435 case Instruction::Alloca: {
2439 Vals.push_back(getTypeID(I.getOperand(0)->getType()));
2440 Vals.push_back(VE.getValueID(I.getOperand(0)));
2442 assert(AlignRecord < 1 << 5 && "alignment greater than 1 << 64");
2444 AlignRecord |= 1 << 6;
2446 break;
2447 }
2448
2449 case Instruction::Load:
2452 pushValueAndType(I.getOperand(0), InstID, Vals);
2453 } else {
2455 if (!pushValueAndType(I.getOperand(0), InstID, Vals))
2456 AbbrevToUse = (unsigned)FUNCTION_INST_LOAD_ABBREV;
2457 }
2458 Vals.push_back(getTypeID(I.getType()));
2464 }
2465 break;
2466 case Instruction::Store:
2469 else
2471 pushValueAndType(I.getOperand(1), InstID, Vals);
2472 pushValueAndType(I.getOperand(0), InstID, Vals);
2478 getEncodedSyncScopeID(cast(I).getSyncScopeID()));
2479 }
2480 break;
2481 case Instruction::AtomicCmpXchg:
2483 pushValueAndType(I.getOperand(0), InstID, Vals);
2484 pushValueAndType(I.getOperand(1), InstID, Vals);
2485 pushValue(I.getOperand(2), InstID, Vals);
2494 break;
2495 case Instruction::AtomicRMW:
2497 pushValueAndType(I.getOperand(0), InstID, Vals);
2498 pushValue(I.getOperand(1), InstID, Vals);
2505 break;
2506 case Instruction::Fence:
2510 break;
2511 case Instruction::Call: {
2514
2516
2521 pushValueAndType(CI.getCalledOperand(), InstID, Vals);
2522
2523
2524 for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
2525
2526 if (FTy->getParamType(i)->isLabelTy())
2528 else
2529 pushValue(CI.getArgOperand(i), InstID, Vals);
2530 }
2531
2532
2533 if (FTy->isVarArg()) {
2534 for (unsigned i = FTy->getNumParams(), e = CI.arg_size(); i != e; ++i)
2535 pushValueAndType(CI.getArgOperand(i), InstID, Vals);
2536 }
2537 break;
2538 }
2539 case Instruction::VAArg:
2541 Vals.push_back(getTypeID(I.getOperand(0)->getType()));
2542 pushValue(I.getOperand(0), InstID, Vals);
2543 Vals.push_back(getTypeID(I.getType()));
2544 break;
2545 }
2546
2547 Stream.EmitRecord(Code, Vals, AbbrevToUse);
2549}
2550
2551
2552void DXILBitcodeWriter::writeFunctionLevelValueSymbolTable(
2553 const ValueSymbolTable &VST) {
2554 if (VST.empty())
2555 return;
2557
2559
2560
2561
2562
2564
2565 for (auto &VI : VST) {
2566 SortedTable.push_back(VI.second->getValueName());
2567 }
2568
2570 return A->first() < B->first();
2571 });
2572
2573 for (const ValueName *SI : SortedTable) {
2575
2576
2577 bool is7Bit = true;
2578 bool isChar6 = true;
2579 for (const char *C = Name.getKeyData(), *E = C + Name.getKeyLength();
2581 if (isChar6)
2583 if ((unsigned char)*C & 128) {
2584 is7Bit = false;
2585 break;
2586 }
2587 }
2588
2589 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
2590
2591
2592
2593 unsigned Code;
2596 if (isChar6)
2597 AbbrevToUse = VST_BBENTRY_6_ABBREV;
2598 } else {
2600 if (isChar6)
2601 AbbrevToUse = VST_ENTRY_6_ABBREV;
2602 else if (is7Bit)
2603 AbbrevToUse = VST_ENTRY_7_ABBREV;
2604 }
2605
2606 NameVals.push_back(VE.getValueID(SI->getValue()));
2607 for (const char *P = Name.getKeyData(),
2608 *E = Name.getKeyData() + Name.getKeyLength();
2610 NameVals.push_back((unsigned char)*P);
2611
2612
2613 Stream.EmitRecord(Code, NameVals, AbbrevToUse);
2614 NameVals.clear();
2615 }
2616 Stream.ExitBlock();
2617}
2618
2619
2620void DXILBitcodeWriter::writeFunction(const Function &F) {
2622 VE.incorporateFunction(F);
2623
2625
2626
2627
2628 Vals.push_back(VE.getBasicBlocks().size());
2631
2632
2633 unsigned CstStart, CstEnd;
2634 VE.getFunctionConstantRange(CstStart, CstEnd);
2635 writeConstants(CstStart, CstEnd, false);
2636
2637
2638 writeFunctionMetadata(F);
2639
2640
2641 unsigned InstID = CstEnd;
2642
2643 bool NeedsMetadataAttachment = F.hasMetadata();
2644
2645 DILocation *LastDL = nullptr;
2646
2647
2650 ++I) {
2651 writeInstruction(*I, InstID, Vals);
2652
2653 if (->getType()->isVoidTy())
2654 ++InstID;
2655
2656
2657 NeedsMetadataAttachment |= I->hasMetadataOtherThanDebugLoc();
2658
2659
2660 DILocation *DL = I->getDebugLoc();
2661 if ()
2662 continue;
2663
2664 if (DL == LastDL) {
2665
2667 continue;
2668 }
2669
2672 Vals.push_back(VE.getMetadataOrNullID(DL->getScope()));
2673 Vals.push_back(VE.getMetadataOrNullID(DL->getInlinedAt()));
2676
2677 LastDL = DL;
2678 }
2679
2680
2681 if (auto *Symtab = F.getValueSymbolTable())
2682 writeFunctionLevelValueSymbolTable(*Symtab);
2683
2684 if (NeedsMetadataAttachment)
2685 writeFunctionMetadataAttachment(F);
2686
2687 VE.purgeFunction();
2688 Stream.ExitBlock();
2689}
2690
2691
2692void DXILBitcodeWriter::writeBlockInfo() {
2693
2694
2695
2696 Stream.EnterBlockInfoBlock();
2697
2698 {
2699 auto Abbv = std::make_shared();
2705 std::move(Abbv)) != VST_ENTRY_8_ABBREV)
2706 assert(false && "Unexpected abbrev ordering!");
2707 }
2708
2709 {
2710 auto Abbv = std::make_shared();
2716 std::move(Abbv)) != VST_ENTRY_7_ABBREV)
2717 assert(false && "Unexpected abbrev ordering!");
2718 }
2719 {
2720 auto Abbv = std::make_shared();
2726 std::move(Abbv)) != VST_ENTRY_6_ABBREV)
2727 assert(false && "Unexpected abbrev ordering!");
2728 }
2729 {
2730 auto Abbv = std::make_shared();
2736 std::move(Abbv)) != VST_BBENTRY_6_ABBREV)
2737 assert(false && "Unexpected abbrev ordering!");
2738 }
2739
2740 {
2741 auto Abbv = std::make_shared();
2744 VE.computeBitsRequiredForTypeIndices()));
2746 CONSTANTS_SETTYPE_ABBREV)
2747 assert(false && "Unexpected abbrev ordering!");
2748 }
2749
2750 {
2751 auto Abbv = std::make_shared();
2755 CONSTANTS_INTEGER_ABBREV)
2756 assert(false && "Unexpected abbrev ordering!");
2757 }
2758
2759 {
2760 auto Abbv = std::make_shared();
2764 VE.computeBitsRequiredForTypeIndices()));
2766
2768 CONSTANTS_CE_CAST_Abbrev)
2769 assert(false && "Unexpected abbrev ordering!");
2770 }
2771 {
2772 auto Abbv = std::make_shared();
2775 CONSTANTS_NULL_Abbrev)
2776 assert(false && "Unexpected abbrev ordering!");
2777 }
2778
2779
2780
2781 {
2782 auto Abbv = std::make_shared();
2786 VE.computeBitsRequiredForTypeIndices()));
2790 (unsigned)FUNCTION_INST_LOAD_ABBREV)
2791 assert(false && "Unexpected abbrev ordering!");
2792 }
2793 {
2794 auto Abbv = std::make_shared();
2800 (unsigned)FUNCTION_INST_BINOP_ABBREV)
2801 assert(false && "Unexpected abbrev ordering!");
2802 }
2803 {
2804 auto Abbv = std::make_shared();
2811 (unsigned)FUNCTION_INST_BINOP_FLAGS_ABBREV)
2812 assert(false && "Unexpected abbrev ordering!");
2813 }
2814 {
2815 auto Abbv = std::make_shared();
2819 VE.computeBitsRequiredForTypeIndices()));
2822 (unsigned)FUNCTION_INST_CAST_ABBREV)
2823 assert(false && "Unexpected abbrev ordering!");
2824 }
2825
2826 {
2827 auto Abbv = std::make_shared();
2830 (unsigned)FUNCTION_INST_RET_VOID_ABBREV)
2831 assert(false && "Unexpected abbrev ordering!");
2832 }
2833 {
2834 auto Abbv = std::make_shared();
2838 (unsigned)FUNCTION_INST_RET_VAL_ABBREV)
2839 assert(false && "Unexpected abbrev ordering!");
2840 }
2841 {
2842 auto Abbv = std::make_shared();
2845 (unsigned)FUNCTION_INST_UNREACHABLE_ABBREV)
2846 assert(false && "Unexpected abbrev ordering!");
2847 }
2848 {
2849 auto Abbv = std::make_shared();
2857 (unsigned)FUNCTION_INST_GEP_ABBREV)
2858 assert(false && "Unexpected abbrev ordering!");
2859 }
2860
2861 Stream.ExitBlock();
2862}
2863
2864void DXILBitcodeWriter::writeModuleVersion() {
2865
2867}
2868
2869
2871
2872
2873
2874
2876
2877
2878
2879 DXILBitcodeWriter::writeModuleVersion();
2880
2881
2882 writeBlockInfo();
2883
2884
2885 writeAttributeGroupTable();
2886
2887
2888 writeAttributeTable();
2889
2890
2891 writeTypeTable();
2892
2893 writeComdats();
2894
2895
2896
2897 writeModuleInfo();
2898
2899
2900 writeModuleConstants();
2901
2902
2903 writeModuleMetadataKinds();
2904
2905
2906 writeModuleMetadata();
2907
2908
2909
2910
2911 writeFunctionLevelValueSymbolTable(M.getValueSymbolTable());
2912
2913
2915 if (.isDeclaration())
2916 writeFunction(F);
2917
2918 Stream.ExitBlock();
2919}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static uint64_t rotateSign(APInt Val)
Definition DXILBitcodeWriter.cpp:1390
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
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.
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.
This class holds the attributes for a particular argument, parameter, function, or return value.
bool hasAttributes() const
Return true if attributes exists in this set.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
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.
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 EmitRecordWithBlob(unsigned Abbrev, const Container &Vals, StringRef Blob)
EmitRecordWithBlob - Emit the specified record to the stream, using an abbrev that includes a blob at...
void EnterSubblock(unsigned BlockID, unsigned CodeLen)
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.
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.
iterator find(const_arg_type_t< KeyT > Val)
BasicBlockListType::const_iterator const_iterator
Function and variable summary information to aid decisions and implementation of importing.
VisibilityTypes getVisibility() const
LinkageTypes getLinkage() const
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
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
idx_iterator idx_end() const
idx_iterator idx_begin() const
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.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
Utility for building string tables with deduplicated suffixes.
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 LLVM_ABI 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.
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.
Definition DXILBitcodeWriter.cpp:426
BitcodeWriter(SmallVectorImpl< char > &Buffer)
Create a BitcodeWriter that writes to Buffer.
Definition DXILBitcodeWriter.cpp:381
~BitcodeWriter()
Definition DXILBitcodeWriter.cpp:392
static void emitWideAPInt(SmallVectorImpl< uint64_t > &Vals, const APInt &A)
Definition DXILBitcodeWriter.cpp:735
static unsigned getEncodedThreadLocalMode(const GlobalValue &GV)
Definition DXILBitcodeWriter.cpp:831
static unsigned getEncodedCastOpcode(unsigned Opcode)
Begin dxil::BitcodeWriterBase Implementation.
Definition DXILBitcodeWriter.cpp:443
static void writeStringRecord(BitstreamWriter &Stream, unsigned Code, StringRef Str, unsigned AbbrevToUse)
Definition DXILBitcodeWriter.cpp:608
static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind)
Definition DXILBitcodeWriter.cpp:624
static unsigned getEncodedDLLStorageClass(const GlobalValue &GV)
Definition DXILBitcodeWriter.cpp:819
static unsigned getEncodedOrdering(AtomicOrdering Ordering)
Definition DXILBitcodeWriter.cpp:588
static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage)
Definition DXILBitcodeWriter.cpp:775
static unsigned getEncodedVisibility(const GlobalValue &GV)
Definition DXILBitcodeWriter.cpp:807
void write()
Emit the current module to the bitstream.
Definition DXILBitcodeWriter.cpp:2870
static void writeIdentificationBlock(BitstreamWriter &Stream)
static unsigned getEncodedBinaryOpcode(unsigned Opcode)
Definition DXILBitcodeWriter.cpp:485
static void emitSignedInt64(SmallVectorImpl< uint64_t > &Vals, uint64_t V)
Definition DXILBitcodeWriter.cpp:727
static unsigned getEncodedUnaryOpcode(unsigned Opcode)
Definition DXILBitcodeWriter.cpp:476
static unsigned getEncodedRMWOperation(AtomicRMWInst::BinOp Op)
Definition DXILBitcodeWriter.cpp:551
DXILBitcodeWriter(const Module &M, SmallVectorImpl< char > &Buffer, StringTableBuilder &StrtabBuilder, BitstreamWriter &Stream)
Constructs a ModuleBitcodeWriter object for the given Module, writing to the provided Buffer.
Definition DXILBitcodeWriter.cpp:133
static unsigned getEncodedComdatSelectionKind(const Comdat &C)
Definition DXILBitcodeWriter.cpp:847
static uint64_t getOptimizationFlags(const Value *V)
Definition DXILBitcodeWriter.cpp:747
std::pair< unsigned, AttributeSet > IndexAndAttrSet
Attribute groups as encoded in bitcode are almost AttributeSets, but they include the AttributeList i...
std::vector< std::pair< const Value *, unsigned > > ValueList
std::vector< Type * > TypeList
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
An analysis to compute the PointerTypes for pointers in a Module.
void WriteDXILToFile(const Module &M, raw_ostream &Out)
Write the specified module to the specified raw output stream.
Definition DXILBitcodeWriter.cpp:395
MetadataAbbrev
Definition DXILBitcodeWriter.cpp:59
@ LastPlusOne
Definition DXILBitcodeWriter.cpp:62
DenseMap< const Value *, Type * > PointerTypeMap
NodeAddr< CodeNode * > Code
constexpr size_t MaxAlignment
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.
FunctionAddr VTableAddr Value
StringMapEntry< Value * > ValueName
MaybeAlign getAlign(const CallInst &I, unsigned Index)
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
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)
FunctionAddr VTableAddr Count
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
AtomicOrdering
Atomic ordering for LLVM's memory model.
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
unsigned Log2(Align A)
Returns the log2 of the alignment.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
Struct that holds a reference to a particular GUID in a global value summary.