LLVM 18.0.0git
DXILBitcodeWriter.cpp
Go to the documentation of this file.
1//===- Bitcode/Writer/DXILBitcodeWriter.cpp - DXIL Bitcode Writer ---------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Bitcode writer implementation.
10//
11//===----------------------------------------------------------------------===//
12
13#include "DXILBitcodeWriter.h"
14#include "DXILValueEnumerator.h"
16#include "llvm/ADT/STLExtras.h"
22#include "llvm/IR/Attributes.h"
23#include "llvm/IR/BasicBlock.h"
24#include "llvm/IR/Comdat.h"
25#include "llvm/IR/Constant.h"
26#include "llvm/IR/Constants.h"
28#include "llvm/IR/DebugLoc.h"
30#include "llvm/IR/Function.h"
31#include "llvm/IR/GlobalAlias.h"
32#include "llvm/IR/GlobalIFunc.h"
34#include "llvm/IR/GlobalValue.h"
36#include "llvm/IR/InlineAsm.h"
37#include "llvm/IR/InstrTypes.h"
38#include "llvm/IR/Instruction.h"
40#include "llvm/IR/LLVMContext.h"
41#include "llvm/IR/Metadata.h"
42#include "llvm/IR/Module.h"
44#include "llvm/IR/Operator.h"
45#include "llvm/IR/Type.h"
47#include "llvm/IR/Value.h"
51#include "llvm/Support/ModRef.h"
52#include "llvm/Support/SHA1.h"
54
55namespace llvm {
56namespace dxil {
57
58// Generates an enum to use as an index in the Abbrev array of Metadata record.
59enum MetadataAbbrev : unsigned {
60#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
61#include "llvm/IR/Metadata.def"
63};
64
66
67 /// These are manifest constants used by the bitcode writer. They do not need
68 /// to be kept in sync with the reader, but need to be consistent within this
69 /// file.
70 enum {
71 // VALUE_SYMTAB_BLOCK abbrev id's.
72 VST_ENTRY_8_ABBREV = bitc::FIRST_APPLICATION_ABBREV,
73 VST_ENTRY_7_ABBREV,
74 VST_ENTRY_6_ABBREV,
75 VST_BBENTRY_6_ABBREV,
76
77 // CONSTANTS_BLOCK abbrev id's.
78 CONSTANTS_SETTYPE_ABBREV = bitc::FIRST_APPLICATION_ABBREV,
79 CONSTANTS_INTEGER_ABBREV,
80 CONSTANTS_CE_CAST_Abbrev,
81 CONSTANTS_NULL_Abbrev,
82
83 // FUNCTION_BLOCK abbrev id's.
84 FUNCTION_INST_LOAD_ABBREV = bitc::FIRST_APPLICATION_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,
92 };
93
94 // Cache some types
95 Type *I8Ty;
96 Type *I8PtrTy;
97
98 /// The stream created and owned by the client.
99 BitstreamWriter &Stream;
100
101 StringTableBuilder &StrtabBuilder;
102
103 /// The Module to write to bitcode.
104 const Module &M;
105
106 /// Enumerates ids for all values in the module.
108
109 /// Map that holds the correspondence between GUIDs in the summary index,
110 /// that came from indirect call profiles, and a value id generated by this
111 /// class to use in the VST and summary block records.
112 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
113
114 /// Tracks the last value id recorded in the GUIDToValueMap.
115 unsigned GlobalValueId;
116
117 /// Saves the offset of the VSTOffset record that must eventually be
118 /// backpatched with the offset of the actual VST.
119 uint64_t VSTOffsetPlaceholder = 0;
120
121 /// Pointer to the buffer allocated by caller for bitcode writing.
122 const SmallVectorImpl<char> &Buffer;
123
124 /// The start bit of the identification block.
125 uint64_t BitcodeStartBit;
126
127 /// This maps values to their typed pointers
128 PointerTypeMap PointerMap;
129
130public:
131 /// Constructs a ModuleBitcodeWriter object for the given Module,
132 /// writing to the provided \p Buffer.
134 StringTableBuilder &StrtabBuilder, BitstreamWriter &Stream)
135 : I8Ty(Type::getInt8Ty(M.getContext())),
136 I8PtrTy(TypedPointerType::get(I8Ty, 0)), Stream(Stream),
137 StrtabBuilder(StrtabBuilder), M(M), VE(M, I8PtrTy), Buffer(Buffer),
138 BitcodeStartBit(Stream.GetCurrentBitNo()),
139 PointerMap(PointerTypeAnalysis::run(M)) {
140 GlobalValueId = VE.getValues().size();
141 // Enumerate the typed pointers
142 for (auto El : PointerMap)
143 VE.EnumerateType(El.second);
144 }
145
146 /// Emit the current module to the bitstream.
147 void write();
148
150 static void writeStringRecord(BitstreamWriter &Stream, unsigned Code,
151 StringRef Str, unsigned AbbrevToUse);
154 static void emitWideAPInt(SmallVectorImpl<uint64_t> &Vals, const APInt &A);
155
156 static unsigned getEncodedComdatSelectionKind(const Comdat &C);
157 static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage);
158 static unsigned getEncodedLinkage(const GlobalValue &GV);
159 static unsigned getEncodedVisibility(const GlobalValue &GV);
160 static unsigned getEncodedThreadLocalMode(const GlobalValue &GV);
161 static unsigned getEncodedDLLStorageClass(const GlobalValue &GV);
162 static unsigned getEncodedCastOpcode(unsigned Opcode);
163 static unsigned getEncodedUnaryOpcode(unsigned Opcode);
164 static unsigned getEncodedBinaryOpcode(unsigned Opcode);
166 static unsigned getEncodedOrdering(AtomicOrdering Ordering);
167 static uint64_t getOptimizationFlags(const Value *V);
168
169private:
170 void writeModuleVersion();
171 void writePerModuleGlobalValueSummary();
172
173 void writePerModuleFunctionSummaryRecord(SmallVector<uint64_t, 64> &NameVals,
174 GlobalValueSummary *Summary,
175 unsigned ValueID,
176 unsigned FSCallsAbbrev,
177 unsigned FSCallsProfileAbbrev,
178 const Function &F);
179 void writeModuleLevelReferences(const GlobalVariable &V,
181 unsigned FSModRefsAbbrev,
182 unsigned FSModVTableRefsAbbrev);
183
184 void assignValueId(GlobalValue::GUID ValGUID) {
185 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
186 }
187
188 unsigned getValueId(GlobalValue::GUID ValGUID) {
189 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
190 // Expect that any GUID value had a value Id assigned by an
191 // earlier call to assignValueId.
192 assert(VMI != GUIDToValueIdMap.end() &&
193 "GUID does not have assigned value Id");
194 return VMI->second;
195 }
196
197 // Helper to get the valueId for the type of value recorded in VI.
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,
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) {
227 llvm_unreachable("DXIL cannot contain GenericDI Nodes");
228 }
229 void writeDISubrange(const DISubrange *N, SmallVectorImpl<uint64_t> &Record,
230 unsigned Abbrev);
231 void writeDIGenericSubrange(const DIGenericSubrange *N,
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 writeDIStringType(const DIStringType *N,
241 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev) {
242 llvm_unreachable("DXIL cannot contain DIStringType Nodes");
243 }
244 void writeDIDerivedType(const DIDerivedType *N,
245 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
246 void writeDICompositeType(const DICompositeType *N,
247 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
248 void writeDISubroutineType(const DISubroutineType *N,
250 unsigned Abbrev);
251 void writeDIFile(const DIFile *N, SmallVectorImpl<uint64_t> &Record,
252 unsigned Abbrev);
253 void writeDICompileUnit(const DICompileUnit *N,
254 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
255 void writeDISubprogram(const DISubprogram *N,
256 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
257 void writeDILexicalBlock(const DILexicalBlock *N,
258 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
259 void writeDILexicalBlockFile(const DILexicalBlockFile *N,
261 unsigned Abbrev);
262 void writeDICommonBlock(const DICommonBlock *N,
263 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev) {
264 llvm_unreachable("DXIL cannot contain DICommonBlock Nodes");
265 }
266 void writeDINamespace(const DINamespace *N, SmallVectorImpl<uint64_t> &Record,
267 unsigned Abbrev);
268 void writeDIMacro(const DIMacro *N, SmallVectorImpl<uint64_t> &Record,
269 unsigned Abbrev) {
270 llvm_unreachable("DXIL cannot contain DIMacro Nodes");
271 }
272 void writeDIMacroFile(const DIMacroFile *N, SmallVectorImpl<uint64_t> &Record,
273 unsigned Abbrev) {
274 llvm_unreachable("DXIL cannot contain DIMacroFile Nodes");
275 }
276 void writeDIArgList(const DIArgList *N, SmallVectorImpl<uint64_t> &Record,
277 unsigned Abbrev) {
278 llvm_unreachable("DXIL cannot contain DIArgList Nodes");
279 }
280 void writeDIAssignID(const DIAssignID *N, SmallVectorImpl<uint64_t> &Record,
281 unsigned Abbrev) {
282 // DIAssignID is experimental feature to track variable location in IR..
283 // FIXME: translate DIAssignID to debug info DXIL supports.
284 // See https://github.com/llvm/llvm-project/issues/58989
285 llvm_unreachable("DXIL cannot contain DIAssignID Nodes");
286 }
287 void writeDIModule(const DIModule *N, SmallVectorImpl<uint64_t> &Record,
288 unsigned Abbrev);
289 void writeDITemplateTypeParameter(const DITemplateTypeParameter *N,
291 unsigned Abbrev);
292 void writeDITemplateValueParameter(const DITemplateValueParameter *N,
294 unsigned Abbrev);
295 void writeDIGlobalVariable(const DIGlobalVariable *N,
297 unsigned Abbrev);
298 void writeDILocalVariable(const DILocalVariable *N,
299 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
300 void writeDILabel(const DILabel *N, SmallVectorImpl<uint64_t> &Record,
301 unsigned Abbrev) {
302 llvm_unreachable("DXIL cannot contain DILabel Nodes");
303 }
304 void writeDIExpression(const DIExpression *N,
305 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
306 void writeDIGlobalVariableExpression(const DIGlobalVariableExpression *N,
308 unsigned Abbrev) {
309 llvm_unreachable("DXIL cannot contain GlobalVariableExpression Nodes");
310 }
311 void writeDIObjCProperty(const DIObjCProperty *N,
312 SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
313 void writeDIImportedEntity(const DIImportedEntity *N,
315 unsigned Abbrev);
316 unsigned createNamedMetadataAbbrev();
317 void writeNamedMetadata(SmallVectorImpl<uint64_t> &Record);
318 unsigned createMetadataStringsAbbrev();
319 void writeMetadataStrings(ArrayRef<const Metadata *> Strings,
321 void writeMetadataRecords(ArrayRef<const Metadata *> MDs,
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);
328 void pushGlobalMetadataAttachment(SmallVectorImpl<uint64_t> &Record,
329 const GlobalObject &GO);
330 void writeModuleMetadataKinds();
331 void writeOperandBundleTags();
332 void writeSyncScopeNames();
333 void writeConstants(unsigned FirstVal, unsigned LastVal, bool isGlobal);
334 void writeModuleConstants();
335 bool pushValueAndType(const Value *V, unsigned InstID,
337 void writeOperandBundles(const CallBase &CB, unsigned InstID);
338 void pushValue(const Value *V, unsigned InstID,
340 void pushValueSigned(const Value *V, unsigned InstID,
342 void writeInstruction(const Instruction &I, unsigned InstID,
344 void writeFunctionLevelValueSymbolTable(const ValueSymbolTable &VST);
345 void writeGlobalValueSymbolTable(
346 DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
347 void writeFunction(const Function &F);
348 void writeBlockInfo();
349
350 unsigned getEncodedSyncScopeID(SyncScope::ID SSID) { return unsigned(SSID); }
351
352 unsigned getEncodedAlign(MaybeAlign Alignment) { return encode(Alignment); }
353
354 unsigned getTypeID(Type *T, const Value *V = nullptr);
355 /// getGlobalObjectValueTypeID - returns the element type for a GlobalObject
356 ///
357 /// GlobalObject types are saved by PointerTypeAnalysis as pointers to the
358 /// GlobalObject, but in the bitcode writer we need the pointer element type.
359 unsigned getGlobalObjectValueTypeID(Type *T, const GlobalObject *G);
360};
361
362} // namespace dxil
363} // namespace llvm
364
365using namespace llvm;
366using namespace llvm::dxil;
367
368////////////////////////////////////////////////////////////////////////////////
369/// Begin dxil::BitcodeWriter Implementation
370////////////////////////////////////////////////////////////////////////////////
371
373 raw_fd_stream *FS)
374 : Buffer(Buffer), Stream(new BitstreamWriter(Buffer, FS, 512)) {
375 // Emit the file header.
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);
382}
383
385
386/// Write the specified module to the specified output stream.
389 Buffer.reserve(256 * 1024);
390
391 // If this is darwin or another generic macho target, reserve space for the
392 // header.
393 Triple TT(M.getTargetTriple());
394 if (TT.isOSDarwin() || TT.isOSBinFormatMachO())
395 Buffer.insert(Buffer.begin(), BWH_HeaderSize, 0);
396
397 BitcodeWriter Writer(Buffer, dyn_cast<raw_fd_stream>(&Out));
398 Writer.writeModule(M);
399
400 // Write the generated bitstream to "Out".
401 if (!Buffer.empty())
402 Out.write((char *)&Buffer.front(), Buffer.size());
403}
404
405void BitcodeWriter::writeBlob(unsigned Block, unsigned Record, StringRef Blob) {
406 Stream->EnterSubblock(Block, 3);
407
408 auto Abbv = std::make_shared<BitCodeAbbrev>();
409 Abbv->Add(BitCodeAbbrevOp(Record));
411 auto AbbrevNo = Stream->EmitAbbrev(std::move(Abbv));
412
413 Stream->EmitRecordWithBlob(AbbrevNo, ArrayRef<uint64_t>{Record}, Blob);
414
415 Stream->ExitBlock();
416}
417
419
420 // The Mods vector is used by irsymtab::build, which requires non-const
421 // Modules in case it needs to materialize metadata. But the bitcode writer
422 // requires that the module is materialized, so we can cast to non-const here,
423 // after checking that it is in fact materialized.
424 assert(M.isMaterialized());
425 Mods.push_back(const_cast<Module *>(&M));
426
427 DXILBitcodeWriter ModuleWriter(M, Buffer, StrtabBuilder, *Stream);
428 ModuleWriter.write();
429}
430
431////////////////////////////////////////////////////////////////////////////////
432/// Begin dxil::BitcodeWriterBase Implementation
433////////////////////////////////////////////////////////////////////////////////
434
436 switch (Opcode) {
437 default:
438 llvm_unreachable("Unknown cast instruction!");
439 case Instruction::Trunc:
440 return bitc::CAST_TRUNC;
441 case Instruction::ZExt:
442 return bitc::CAST_ZEXT;
443 case Instruction::SExt:
444 return bitc::CAST_SEXT;
445 case Instruction::FPToUI:
446 return bitc::CAST_FPTOUI;
447 case Instruction::FPToSI:
448 return bitc::CAST_FPTOSI;
449 case Instruction::UIToFP:
450 return bitc::CAST_UITOFP;
451 case Instruction::SIToFP:
452 return bitc::CAST_SITOFP;
453 case Instruction::FPTrunc:
454 return bitc::CAST_FPTRUNC;
455 case Instruction::FPExt:
456 return bitc::CAST_FPEXT;
457 case Instruction::PtrToInt:
458 return bitc::CAST_PTRTOINT;
459 case Instruction::IntToPtr:
460 return bitc::CAST_INTTOPTR;
461 case Instruction::BitCast:
462 return bitc::CAST_BITCAST;
463 case Instruction::AddrSpaceCast:
465 }
466}
467
469 switch (Opcode) {
470 default:
471 llvm_unreachable("Unknown binary instruction!");
472 case Instruction::FNeg:
473 return bitc::UNOP_FNEG;
474 }
475}
476
478 switch (Opcode) {
479 default:
480 llvm_unreachable("Unknown binary instruction!");
481 case Instruction::Add:
482 case Instruction::FAdd:
483 return bitc::BINOP_ADD;
484 case Instruction::Sub:
485 case Instruction::FSub:
486 return bitc::BINOP_SUB;
487 case Instruction::Mul:
488 case Instruction::FMul:
489 return bitc::BINOP_MUL;
490 case Instruction::UDiv:
491 return bitc::BINOP_UDIV;
492 case Instruction::FDiv:
493 case Instruction::SDiv:
494 return bitc::BINOP_SDIV;
495 case Instruction::URem:
496 return bitc::BINOP_UREM;
497 case Instruction::FRem:
498 case Instruction::SRem:
499 return bitc::BINOP_SREM;
500 case Instruction::Shl:
501 return bitc::BINOP_SHL;
502 case Instruction::LShr:
503 return bitc::BINOP_LSHR;
504 case Instruction::AShr:
505 return bitc::BINOP_ASHR;
506 case Instruction::And:
507 return bitc::BINOP_AND;
508 case Instruction::Or:
509 return bitc::BINOP_OR;
510 case Instruction::Xor:
511 return bitc::BINOP_XOR;
512 }
513}
514
515unsigned DXILBitcodeWriter::getTypeID(Type *T, const Value *V) {
516 if (!T->isPointerTy() &&
517 // For Constant, always check PointerMap to make sure OpaquePointer in
518 // things like constant struct/array works.
519 (!V || !isa<Constant>(V)))
520 return VE.getTypeID(T);
521 auto It = PointerMap.find(V);
522 if (It != PointerMap.end())
523 return VE.getTypeID(It->second);
524 // For Constant, return T when cannot find in PointerMap.
525 // FIXME: support ConstantPointerNull which could map to more than one
526 // TypedPointerType.
527 // See https://github.com/llvm/llvm-project/issues/57942.
528 if (V && isa<Constant>(V) && !isa<ConstantPointerNull>(V))
529 return VE.getTypeID(T);
530 return VE.getTypeID(I8PtrTy);
531}
532
533unsigned DXILBitcodeWriter::getGlobalObjectValueTypeID(Type *T,
534 const GlobalObject *G) {
535 auto It = PointerMap.find(G);
536 if (It != PointerMap.end()) {
537 TypedPointerType *PtrTy = cast<TypedPointerType>(It->second);
538 return VE.getTypeID(PtrTy->getElementType());
539 }
540 return VE.getTypeID(T);
541}
542
544 switch (Op) {
545 default:
546 llvm_unreachable("Unknown RMW operation!");
548 return bitc::RMW_XCHG;
550 return bitc::RMW_ADD;
552 return bitc::RMW_SUB;
554 return bitc::RMW_AND;
556 return bitc::RMW_NAND;
558 return bitc::RMW_OR;
560 return bitc::RMW_XOR;
562 return bitc::RMW_MAX;
564 return bitc::RMW_MIN;
566 return bitc::RMW_UMAX;
568 return bitc::RMW_UMIN;
570 return bitc::RMW_FADD;
572 return bitc::RMW_FSUB;
574 return bitc::RMW_FMAX;
576 return bitc::RMW_FMIN;
577 }
578}
579
581 switch (Ordering) {
596 }
597 llvm_unreachable("Invalid ordering");
598}
599
601 unsigned Code, StringRef Str,
602 unsigned AbbrevToUse) {
604
605 // Code: [strchar x N]
606 for (char C : Str) {
607 if (AbbrevToUse && !BitCodeAbbrevOp::isChar6(C))
608 AbbrevToUse = 0;
609 Vals.push_back(C);
610 }
611
612 // Emit the finished record.
613 Stream.EmitRecord(Code, Vals, AbbrevToUse);
614}
615
617 switch (Kind) {
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:
707 llvm_unreachable("Can not encode end-attribute kinds marker.");
708 case Attribute::None:
709 llvm_unreachable("Can not encode none-attribute.");
712 llvm_unreachable("Trying to encode EmptyKey/TombstoneKey");
713 default:
714 llvm_unreachable("Trying to encode attribute not supported by DXIL. These "
715 "should be stripped in DXILPrepare");
716 }
717
718 llvm_unreachable("Trying to encode unknown attribute");
719}
720
722 uint64_t V) {
723 if ((int64_t)V >= 0)
724 Vals.push_back(V << 1);
725 else
726 Vals.push_back((-V << 1) | 1);
727}
728
730 const APInt &A) {
731 // We have an arbitrary precision integer value to write whose
732 // bit width is > 64. However, in canonical unsigned integer
733 // format it is likely that the high bits are going to be zero.
734 // So, we only write the number of active words.
735 unsigned NumWords = A.getActiveWords();
736 const uint64_t *RawData = A.getRawData();
737 for (unsigned i = 0; i < NumWords; i++)
738 emitSignedInt64(Vals, RawData[i]);
739}
740
742 uint64_t Flags = 0;
743
744 if (const auto *OBO = dyn_cast<OverflowingBinaryOperator>(V)) {
745 if (OBO->hasNoSignedWrap())
746 Flags |= 1 << bitc::OBO_NO_SIGNED_WRAP;
747 if (OBO->hasNoUnsignedWrap())
748 Flags |= 1 << bitc::OBO_NO_UNSIGNED_WRAP;
749 } else if (const auto *PEO = dyn_cast<PossiblyExactOperator>(V)) {
750 if (PEO->isExact())
751 Flags |= 1 << bitc::PEO_EXACT;
752 } else if (const auto *FPMO = dyn_cast<FPMathOperator>(V)) {
753 if (FPMO->hasAllowReassoc())
754 Flags |= bitc::AllowReassoc;
755 if (FPMO->hasNoNaNs())
756 Flags |= bitc::NoNaNs;
757 if (FPMO->hasNoInfs())
758 Flags |= bitc::NoInfs;
759 if (FPMO->hasNoSignedZeros())
760 Flags |= bitc::NoSignedZeros;
761 if (FPMO->hasAllowReciprocal())
762 Flags |= bitc::AllowReciprocal;
763 if (FPMO->hasAllowContract())
764 Flags |= bitc::AllowContract;
765 if (FPMO->hasApproxFunc())
766 Flags |= bitc::ApproxFunc;
767 }
768
769 return Flags;
770}
771
772unsigned
774 switch (Linkage) {
776 return 0;
778 return 16;
780 return 2;
782 return 3;
784 return 18;
786 return 7;
788 return 8;
790 return 9;
792 return 17;
794 return 19;
796 return 12;
797 }
798 llvm_unreachable("Invalid linkage");
799}
800
802 return getEncodedLinkage(GV.getLinkage());
803}
804
806 switch (GV.getVisibility()) {
808 return 0;
810 return 1;
812 return 2;
813 }
814 llvm_unreachable("Invalid visibility");
815}
816
818 switch (GV.getDLLStorageClass()) {
820 return 0;
822 return 1;
824 return 2;
825 }
826 llvm_unreachable("Invalid DLL storage class");
827}
828
830 switch (GV.getThreadLocalMode()) {
832 return 0;
834 return 1;
836 return 2;
838 return 3;
840 return 4;
841 }
842 llvm_unreachable("Invalid TLS model");
843}
844
846 switch (C.getSelectionKind()) {
847 case Comdat::Any:
851 case Comdat::Largest:
855 case Comdat::SameSize:
857 }
858 llvm_unreachable("Invalid selection kind");
859}
860
861////////////////////////////////////////////////////////////////////////////////
862/// Begin DXILBitcodeWriter Implementation
863////////////////////////////////////////////////////////////////////////////////
864
865void DXILBitcodeWriter::writeAttributeGroupTable() {
866 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
868 if (AttrGrps.empty())
869 return;
870
872
874 for (ValueEnumerator::IndexAndAttrSet Pair : AttrGrps) {
875 unsigned AttrListIndex = Pair.first;
876 AttributeSet AS = Pair.second;
877 Record.push_back(VE.getAttributeGroupID(Pair));
878 Record.push_back(AttrListIndex);
879
880 for (Attribute Attr : AS) {
881 if (Attr.isEnumAttribute()) {
882 uint64_t Val = getAttrKindEncoding(Attr.getKindAsEnum());
884 "DXIL does not support attributes above ATTR_KIND_ARGMEMONLY");
885 Record.push_back(0);
886 Record.push_back(Val);
887 } else if (Attr.isIntAttribute()) {
888 if (Attr.getKindAsEnum() == Attribute::AttrKind::Memory) {
889 MemoryEffects ME = Attr.getMemoryEffects();
890 if (ME.doesNotAccessMemory()) {
891 Record.push_back(0);
893 } else {
894 if (ME.onlyReadsMemory()) {
895 Record.push_back(0);
897 }
898 if (ME.onlyAccessesArgPointees()) {
899 Record.push_back(0);
901 }
902 }
903 } else {
904 uint64_t Val = getAttrKindEncoding(Attr.getKindAsEnum());
906 "DXIL does not support attributes above ATTR_KIND_ARGMEMONLY");
907 Record.push_back(1);
908 Record.push_back(Val);
909 Record.push_back(Attr.getValueAsInt());
910 }
911 } else {
912 StringRef Kind = Attr.getKindAsString();
913 StringRef Val = Attr.getValueAsString();
914
915 Record.push_back(Val.empty() ? 3 : 4);
916 Record.append(Kind.begin(), Kind.end());
917 Record.push_back(0);
918 if (!Val.empty()) {
919 Record.append(Val.begin(), Val.end());
920 Record.push_back(0);
921 }
922 }
923 }
924
926 Record.clear();
927 }
928
929 Stream.ExitBlock();
930}
931
932void DXILBitcodeWriter::writeAttributeTable() {
933 const std::vector<AttributeList> &Attrs = VE.getAttributeLists();
934 if (Attrs.empty())
935 return;
936
938
940 for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
942 for (unsigned i : AL.indexes()) {
943 AttributeSet AS = AL.getAttributes(i);
944 if (AS.hasAttributes())
945 Record.push_back(VE.getAttributeGroupID({i, AS}));
946 }
947
949 Record.clear();
950 }
951
952 Stream.ExitBlock();
953}
954
955/// WriteTypeTable - Write out the type table for a module.
956void DXILBitcodeWriter::writeTypeTable() {
957 const ValueEnumerator::TypeList &TypeList = VE.getTypes();
958
959 Stream.EnterSubblock(bitc::TYPE_BLOCK_ID_NEW, 4 /*count from # abbrevs */);
961
963
964 // Abbrev for TYPE_CODE_POINTER.
965 auto Abbv = std::make_shared<BitCodeAbbrev>();
967 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits));
968 Abbv->Add(BitCodeAbbrevOp(0)); // Addrspace = 0
969 unsigned PtrAbbrev = Stream.EmitAbbrev(std::move(Abbv));
970
971 // Abbrev for TYPE_CODE_FUNCTION.
972 Abbv = std::make_shared<BitCodeAbbrev>();
974 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isvararg
976 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits));
977 unsigned FunctionAbbrev = Stream.EmitAbbrev(std::move(Abbv));
978
979 // Abbrev for TYPE_CODE_STRUCT_ANON.
980 Abbv = std::make_shared<BitCodeAbbrev>();
982 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ispacked
984 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits));
985 unsigned StructAnonAbbrev = Stream.EmitAbbrev(std::move(Abbv));
986
987 // Abbrev for TYPE_CODE_STRUCT_NAME.
988 Abbv = std::make_shared<BitCodeAbbrev>();
992 unsigned StructNameAbbrev = Stream.EmitAbbrev(std::move(Abbv));
993
994 // Abbrev for TYPE_CODE_STRUCT_NAMED.
995 Abbv = std::make_shared<BitCodeAbbrev>();
997 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ispacked
999 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits));
1000 unsigned StructNamedAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1001
1002 // Abbrev for TYPE_CODE_ARRAY.
1003 Abbv = std::make_shared<BitCodeAbbrev>();
1005 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // size
1006 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits));
1007 unsigned ArrayAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1008
1009 // Emit an entry count so the reader can reserve space.
1010 TypeVals.push_back(TypeList.size());
1011 Stream.EmitRecord(bitc::TYPE_CODE_NUMENTRY, TypeVals);
1012 TypeVals.clear();
1013
1014 // Loop over all of the types, emitting each in turn.
1015 for (Type *T : TypeList) {
1016 int AbbrevToUse = 0;
1017 unsigned Code = 0;
1018
1019 switch (T->getTypeID()) {
1020 case Type::BFloatTyID:
1021 case Type::X86_AMXTyID:
1022 case Type::TokenTyID:
1024 llvm_unreachable("These should never be used!!!");
1025 break;
1026 case Type::VoidTyID:
1028 break;
1029 case Type::HalfTyID:
1031 break;
1032 case Type::FloatTyID:
1034 break;
1035 case Type::DoubleTyID:
1037 break;
1038 case Type::X86_FP80TyID:
1040 break;
1041 case Type::FP128TyID:
1043 break;
1046 break;
1047 case Type::LabelTyID:
1049 break;
1050 case Type::MetadataTyID:
1052 break;
1053 case Type::X86_MMXTyID:
1055 break;
1056 case Type::IntegerTyID:
1057 // INTEGER: [width]
1059 TypeVals.push_back(cast<IntegerType>(T)->getBitWidth());
1060 break;
1062 TypedPointerType *PTy = cast<TypedPointerType>(T);
1063 // POINTER: [pointee type, address space]
1065 TypeVals.push_back(getTypeID(PTy->getElementType()));
1066 unsigned AddressSpace = PTy->getAddressSpace();
1067 TypeVals.push_back(AddressSpace);
1068 if (AddressSpace == 0)
1069 AbbrevToUse = PtrAbbrev;
1070 break;
1071 }
1072 case Type::PointerTyID: {
1073 // POINTER: [pointee type, address space]
1074 // Emitting an empty struct type for the pointer's type allows this to be
1075 // order-independent. Non-struct types must be emitted in bitcode before
1076 // they can be referenced.
1077 TypeVals.push_back(false);
1080 "dxilOpaquePtrReservedName", StructNameAbbrev);
1081 break;
1082 }
1083 case Type::FunctionTyID: {
1084 FunctionType *FT = cast<FunctionType>(T);
1085 // FUNCTION: [isvararg, retty, paramty x N]
1087 TypeVals.push_back(FT->isVarArg());
1088 TypeVals.push_back(getTypeID(FT->getReturnType()));
1089 for (Type *PTy : FT->params())
1090 TypeVals.push_back(getTypeID(PTy));
1091 AbbrevToUse = FunctionAbbrev;
1092 break;
1093 }
1094 case Type::StructTyID: {
1095 StructType *ST = cast<StructType>(T);
1096 // STRUCT: [ispacked, eltty x N]
1097 TypeVals.push_back(ST->isPacked());
1098 // Output all of the element types.
1099 for (Type *ElTy : ST->elements())
1100 TypeVals.push_back(getTypeID(ElTy));
1101
1102 if (ST->isLiteral()) {
1104 AbbrevToUse = StructAnonAbbrev;
1105 } else {
1106 if (ST->isOpaque()) {
1108 } else {
1110 AbbrevToUse = StructNamedAbbrev;
1111 }
1112
1113 // Emit the name if it is present.
1114 if (!ST->getName().empty())
1116 StructNameAbbrev);
1117 }
1118 break;
1119 }
1120 case Type::ArrayTyID: {
1121 ArrayType *AT = cast<ArrayType>(T);
1122 // ARRAY: [numelts, eltty]
1124 TypeVals.push_back(AT->getNumElements());
1125 TypeVals.push_back(getTypeID(AT->getElementType()));
1126 AbbrevToUse = ArrayAbbrev;
1127 break;
1128 }
1131 VectorType *VT = cast<VectorType>(T);
1132 // VECTOR [numelts, eltty]
1134 TypeVals.push_back(VT->getElementCount().getKnownMinValue());
1135 TypeVals.push_back(getTypeID(VT->getElementType()));
1136 break;
1137 }
1138 }
1139
1140 // Emit the finished record.
1141 Stream.EmitRecord(Code, TypeVals, AbbrevToUse);
1142 TypeVals.clear();
1143 }
1144
1145 Stream.ExitBlock();
1146}
1147
1148void DXILBitcodeWriter::writeComdats() {
1150 for (const Comdat *C : VE.getComdats()) {
1151 // COMDAT: [selection_kind, name]
1153 size_t Size = C->getName().size();
1154 assert(isUInt<16>(Size));
1155 Vals.push_back(Size);
1156 for (char Chr : C->getName())
1157 Vals.push_back((unsigned char)Chr);
1158 Stream.EmitRecord(bitc::MODULE_CODE_COMDAT, Vals, /*AbbrevToUse=*/0);
1159 Vals.clear();
1160 }
1161}
1162
1163void DXILBitcodeWriter::writeValueSymbolTableForwardDecl() {}
1164
1165/// Emit top-level description of module, including target triple, inline asm,
1166/// descriptors for global variables, and function prototype info.
1167/// Returns the bit offset to backpatch with the location of the real VST.
1168void DXILBitcodeWriter::writeModuleInfo() {
1169 // Emit various pieces of data attached to a module.
1170 if (!M.getTargetTriple().empty())
1171 writeStringRecord(Stream, bitc::MODULE_CODE_TRIPLE, M.getTargetTriple(),
1172 0 /*TODO*/);
1173 const std::string &DL = M.getDataLayoutStr();
1174 if (!DL.empty())
1176 if (!M.getModuleInlineAsm().empty())
1177 writeStringRecord(Stream, bitc::MODULE_CODE_ASM, M.getModuleInlineAsm(),
1178 0 /*TODO*/);
1179
1180 // Emit information about sections and GC, computing how many there are. Also
1181 // compute the maximum alignment value.
1182 std::map<std::string, unsigned> SectionMap;
1183 std::map<std::string, unsigned> GCMap;
1184 MaybeAlign MaxAlignment;
1185 unsigned MaxGlobalType = 0;
1186 const auto UpdateMaxAlignment = [&MaxAlignment](const MaybeAlign A) {
1187 if (A)
1188 MaxAlignment = !MaxAlignment ? *A : std::max(*MaxAlignment, *A);
1189 };
1190 for (const GlobalVariable &GV : M.globals()) {
1191 UpdateMaxAlignment(GV.getAlign());
1192 // Use getGlobalObjectValueTypeID to look up the enumerated type ID for
1193 // Global Variable types.
1194 MaxGlobalType = std::max(
1195 MaxGlobalType, getGlobalObjectValueTypeID(GV.getValueType(), &GV));
1196 if (GV.hasSection()) {
1197 // Give section names unique ID's.
1198 unsigned &Entry = SectionMap[std::string(GV.getSection())];
1199 if (!Entry) {
1201 GV.getSection(), 0 /*TODO*/);
1202 Entry = SectionMap.size();
1203 }
1204 }
1205 }
1206 for (const Function &F : M) {
1207 UpdateMaxAlignment(F.getAlign());
1208 if (F.hasSection()) {
1209 // Give section names unique ID's.
1210 unsigned &Entry = SectionMap[std::string(F.getSection())];
1211 if (!Entry) {
1213 0 /*TODO*/);
1214 Entry = SectionMap.size();
1215 }
1216 }
1217 if (F.hasGC()) {
1218 // Same for GC names.
1219 unsigned &Entry = GCMap[F.getGC()];
1220 if (!Entry) {
1222 0 /*TODO*/);
1223 Entry = GCMap.size();
1224 }
1225 }
1226 }
1227
1228 // Emit abbrev for globals, now that we know # sections and max alignment.
1229 unsigned SimpleGVarAbbrev = 0;
1230 if (!M.global_empty()) {
1231 // Add an abbrev for common globals with no visibility or thread
1232 // localness.
1233 auto Abbv = std::make_shared<BitCodeAbbrev>();
1236 Log2_32_Ceil(MaxGlobalType + 1)));
1237 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddrSpace << 2
1238 //| explicitType << 1
1239 //| constant
1240 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Initializer.
1241 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); // Linkage.
1242 if (!MaxAlignment) // Alignment.
1243 Abbv->Add(BitCodeAbbrevOp(0));
1244 else {
1245 unsigned MaxEncAlignment = getEncodedAlign(MaxAlignment);
1247 Log2_32_Ceil(MaxEncAlignment + 1)));
1248 }
1249 if (SectionMap.empty()) // Section.
1250 Abbv->Add(BitCodeAbbrevOp(0));
1251 else
1253 Log2_32_Ceil(SectionMap.size() + 1)));
1254 // Don't bother emitting vis + thread local.
1255 SimpleGVarAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1256 }
1257
1258 // Emit the global variable information.
1260 for (const GlobalVariable &GV : M.globals()) {
1261 unsigned AbbrevToUse = 0;
1262
1263 // GLOBALVAR: [type, isconst, initid,
1264 // linkage, alignment, section, visibility, threadlocal,
1265 // unnamed_addr, externally_initialized, dllstorageclass,
1266 // comdat]
1267 Vals.push_back(getGlobalObjectValueTypeID(GV.getValueType(), &GV));
1268 Vals.push_back(
1269 GV.getType()->getAddressSpace() << 2 | 2 |
1270 (GV.isConstant() ? 1 : 0)); // HLSL Change - bitwise | was used with
1271 // unsigned int and bool
1272 Vals.push_back(
1273 GV.isDeclaration() ? 0 : (VE.getValueID(GV.getInitializer()) + 1));
1274 Vals.push_back(getEncodedLinkage(GV));
1275 Vals.push_back(getEncodedAlign(GV.getAlign()));
1276 Vals.push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1277 : 0);
1278 if (GV.isThreadLocal() ||
1279 GV.getVisibility() != GlobalValue::DefaultVisibility ||
1280 GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1281 GV.isExternallyInitialized() ||
1282 GV.getDLLStorageClass() != GlobalValue::DefaultStorageClass ||
1283 GV.hasComdat()) {
1286 Vals.push_back(GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None);
1287 Vals.push_back(GV.isExternallyInitialized());
1289 Vals.push_back(GV.hasComdat() ? VE.getComdatID(GV.getComdat()) : 0);
1290 } else {
1291 AbbrevToUse = SimpleGVarAbbrev;
1292 }
1293
1294 Stream.EmitRecord(bitc::MODULE_CODE_GLOBALVAR, Vals, AbbrevToUse);
1295 Vals.clear();
1296 }
1297
1298 // Emit the function proto information.
1299 for (const Function &F : M) {
1300 // FUNCTION: [type, callingconv, isproto, linkage, paramattrs, alignment,
1301 // section, visibility, gc, unnamed_addr, prologuedata,
1302 // dllstorageclass, comdat, prefixdata, personalityfn]
1303 Vals.push_back(getGlobalObjectValueTypeID(F.getFunctionType(), &F));
1304 Vals.push_back(F.getCallingConv());
1305 Vals.push_back(F.isDeclaration());
1307 Vals.push_back(VE.getAttributeListID(F.getAttributes()));
1308 Vals.push_back(getEncodedAlign(F.getAlign()));
1309 Vals.push_back(F.hasSection() ? SectionMap[std::string(F.getSection())]
1310 : 0);
1312 Vals.push_back(F.hasGC() ? GCMap[F.getGC()] : 0);
1313 Vals.push_back(F.getUnnamedAddr() != GlobalValue::UnnamedAddr::None);
1314 Vals.push_back(
1315 F.hasPrologueData() ? (VE.getValueID(F.getPrologueData()) + 1) : 0);
1317 Vals.push_back(F.hasComdat() ? VE.getComdatID(F.getComdat()) : 0);
1318 Vals.push_back(F.hasPrefixData() ? (VE.getValueID(F.getPrefixData()) + 1)
1319 : 0);
1320 Vals.push_back(
1321 F.hasPersonalityFn() ? (VE.getValueID(F.getPersonalityFn()) + 1) : 0);
1322
1323 unsigned AbbrevToUse = 0;
1324 Stream.EmitRecord(bitc::MODULE_CODE_FUNCTION, Vals, AbbrevToUse);
1325 Vals.clear();
1326 }
1327
1328 // Emit the alias information.
1329 for (const GlobalAlias &A : M.aliases()) {
1330 // ALIAS: [alias type, aliasee val#, linkage, visibility]
1331 Vals.push_back(getTypeID(A.getValueType(), &A));
1332 Vals.push_back(VE.getValueID(A.getAliasee()));
1337 Vals.push_back(A.getUnnamedAddr() != GlobalValue::UnnamedAddr::None);
1338 unsigned AbbrevToUse = 0;
1339 Stream.EmitRecord(bitc::MODULE_CODE_ALIAS_OLD, Vals, AbbrevToUse);
1340 Vals.clear();
1341 }
1342}
1343
1344void DXILBitcodeWriter::writeValueAsMetadata(
1346 // Mimic an MDNode with a value as one operand.
1347 Value *V = MD->getValue();
1348 Type *Ty = V->getType();
1349 if (Function *F = dyn_cast<Function>(V))
1350 Ty = TypedPointerType::get(F->getFunctionType(), F->getAddressSpace());
1351 else if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
1352 Ty = TypedPointerType::get(GV->getValueType(), GV->getAddressSpace());
1353 Record.push_back(getTypeID(Ty));
1354 Record.push_back(VE.getValueID(V));
1356 Record.clear();
1357}
1358
1359void DXILBitcodeWriter::writeMDTuple(const MDTuple *N,
1361 unsigned Abbrev) {
1362 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
1363 Metadata *MD = N->getOperand(i);
1364 assert(!(MD && isa<LocalAsMetadata>(MD)) &&
1365 "Unexpected function-local metadata");
1366 Record.push_back(VE.getMetadataOrNullID(MD));
1367 }
1368 Stream.EmitRecord(N->isDistinct() ? bitc::METADATA_DISTINCT_NODE
1370 Record, Abbrev);
1371 Record.clear();
1372}
1373
1374void DXILBitcodeWriter::writeDILocation(const DILocation *N,
1376 unsigned &Abbrev) {
1377 if (!Abbrev)
1378 Abbrev = createDILocationAbbrev();
1379 Record.push_back(N->isDistinct());
1380 Record.push_back(N->getLine());
1381 Record.push_back(N->getColumn());
1382 Record.push_back(VE.getMetadataID(N->getScope()));
1383 Record.push_back(VE.getMetadataOrNullID(N->getInlinedAt()));
1384
1385 Stream.EmitRecord(bitc::METADATA_LOCATION, Record, Abbrev);
1386 Record.clear();
1387}
1388
1390 int64_t I = Val.getSExtValue();
1391 uint64_t U = I;
1392 return I < 0 ? ~(U << 1) : U << 1;
1393}
1394
1395void DXILBitcodeWriter::writeDISubrange(const DISubrange *N,
1397 unsigned Abbrev) {
1398 Record.push_back(N->isDistinct());
1399
1400 // TODO: Do we need to handle DIExpression here? What about cases where Count
1401 // isn't specified but UpperBound and such are?
1402 ConstantInt *Count = N->getCount().dyn_cast<ConstantInt *>();
1403 assert(Count && "Count is missing or not ConstantInt");
1404 Record.push_back(Count->getValue().getSExtValue());
1405
1406 // TODO: Similarly, DIExpression is allowed here now
1407 DISubrange::BoundType LowerBound = N->getLowerBound();
1408 assert((LowerBound.isNull() || LowerBound.is<ConstantInt *>()) &&
1409 "Lower bound provided but not ConstantInt");
1410 Record.push_back(
1411 LowerBound ? rotateSign(LowerBound.get<ConstantInt *>()->getValue()) : 0);
1412
1413 Stream.EmitRecord(bitc::METADATA_SUBRANGE, Record, Abbrev);
1414 Record.clear();
1415}
1416
1417void DXILBitcodeWriter::writeDIEnumerator(const DIEnumerator *N,
1419 unsigned Abbrev) {
1420 Record.push_back(N->isDistinct());
1421 Record.push_back(rotateSign(N->getValue()));
1422 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1423
1425 Record.clear();
1426}
1427
1428void DXILBitcodeWriter::writeDIBasicType(const DIBasicType *N,
1430 unsigned Abbrev) {
1431 Record.push_back(N->isDistinct());
1432 Record.push_back(N->getTag());
1433 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1434 Record.push_back(N->getSizeInBits());
1435 Record.push_back(N->getAlignInBits());
1436 Record.push_back(N->getEncoding());
1437
1439 Record.clear();
1440}
1441
1442void DXILBitcodeWriter::writeDIDerivedType(const DIDerivedType *N,
1444 unsigned Abbrev) {
1445 Record.push_back(N->isDistinct());
1446 Record.push_back(N->getTag());
1447 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1448 Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1449 Record.push_back(N->getLine());
1450 Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1451 Record.push_back(VE.getMetadataOrNullID(N->getBaseType()));
1452 Record.push_back(N->getSizeInBits());
1453 Record.push_back(N->getAlignInBits());
1454 Record.push_back(N->getOffsetInBits());
1455 Record.push_back(N->getFlags());
1456 Record.push_back(VE.getMetadataOrNullID(N->getExtraData()));
1457
1459 Record.clear();
1460}
1461
1462void DXILBitcodeWriter::writeDICompositeType(const DICompositeType *N,
1464 unsigned Abbrev) {
1465 Record.push_back(N->isDistinct());
1466 Record.push_back(N->getTag());
1467 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1468 Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1469 Record.push_back(N->getLine());
1470 Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1471 Record.push_back(VE.getMetadataOrNullID(N->getBaseType()));
1472 Record.push_back(N->getSizeInBits());
1473 Record.push_back(N->getAlignInBits());
1474 Record.push_back(N->getOffsetInBits());
1475 Record.push_back(N->getFlags());
1476 Record.push_back(VE.getMetadataOrNullID(N->getElements().get()));
1477 Record.push_back(N->getRuntimeLang());
1478 Record.push_back(VE.getMetadataOrNullID(N->getVTableHolder()));
1479 Record.push_back(VE.getMetadataOrNullID(N->getTemplateParams().get()));
1480 Record.push_back(VE.getMetadataOrNullID(N->getRawIdentifier()));
1481
1483 Record.clear();
1484}
1485
1486void DXILBitcodeWriter::writeDISubroutineType(const DISubroutineType *N,
1488 unsigned Abbrev) {
1489 Record.push_back(N->isDistinct());
1490 Record.push_back(N->getFlags());
1491 Record.push_back(VE.getMetadataOrNullID(N->getTypeArray().get()));
1492
1494 Record.clear();
1495}
1496
1497void DXILBitcodeWriter::writeDIFile(const DIFile *N,
1499 unsigned Abbrev) {
1500 Record.push_back(N->isDistinct());
1501 Record.push_back(VE.getMetadataOrNullID(N->getRawFilename()));
1502 Record.push_back(VE.getMetadataOrNullID(N->getRawDirectory()));
1503
1504 Stream.EmitRecord(bitc::METADATA_FILE, Record, Abbrev);
1505 Record.clear();
1506}
1507
1508void DXILBitcodeWriter::writeDICompileUnit(const DICompileUnit *N,
1510 unsigned Abbrev) {
1511 Record.push_back(N->isDistinct());
1512 Record.push_back(N->getSourceLanguage());
1513 Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1514 Record.push_back(VE.getMetadataOrNullID(N->getRawProducer()));
1515 Record.push_back(N->isOptimized());
1516 Record.push_back(VE.getMetadataOrNullID(N->getRawFlags()));
1517 Record.push_back(N->getRuntimeVersion());
1518 Record.push_back(VE.getMetadataOrNullID(N->getRawSplitDebugFilename()));
1519 Record.push_back(N->getEmissionKind());
1520 Record.push_back(VE.getMetadataOrNullID(N->getEnumTypes().get()));
1521 Record.push_back(VE.getMetadataOrNullID(N->getRetainedTypes().get()));
1522 Record.push_back(/* subprograms */ 0);
1523 Record.push_back(VE.getMetadataOrNullID(N->getGlobalVariables().get()));
1524 Record.push_back(VE.getMetadataOrNullID(N->getImportedEntities().get()));
1525 Record.push_back(N->getDWOId());
1526
1528 Record.clear();
1529}
1530
1531void DXILBitcodeWriter::writeDISubprogram(const DISubprogram *N,
1533 unsigned Abbrev) {
1534 Record.push_back(N->isDistinct());
1535 Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1536 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1537 Record.push_back(VE.getMetadataOrNullID(N->getRawLinkageName()));
1538 Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1539 Record.push_back(N->getLine());
1540 Record.push_back(VE.getMetadataOrNullID(N->getType()));
1541 Record.push_back(N->isLocalToUnit());
1542 Record.push_back(N->isDefinition());
1543 Record.push_back(N->getScopeLine());
1544 Record.push_back(VE.getMetadataOrNullID(N->getContainingType()));
1545 Record.push_back(N->getVirtuality());
1546 Record.push_back(N->getVirtualIndex());
1547 Record.push_back(N->getFlags());
1548 Record.push_back(N->isOptimized());
1549 Record.push_back(VE.getMetadataOrNullID(N->getRawUnit()));
1550 Record.push_back(VE.getMetadataOrNullID(N->getTemplateParams().get()));
1551 Record.push_back(VE.getMetadataOrNullID(N->getDeclaration()));
1552 Record.push_back(VE.getMetadataOrNullID(N->getRetainedNodes().get()));
1553
1555 Record.clear();
1556}
1557
1558void DXILBitcodeWriter::writeDILexicalBlock(const DILexicalBlock *N,
1560 unsigned Abbrev) {
1561 Record.push_back(N->isDistinct());
1562 Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1563 Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1564 Record.push_back(N->getLine());
1565 Record.push_back(N->getColumn());
1566
1568 Record.clear();
1569}
1570
1571void DXILBitcodeWriter::writeDILexicalBlockFile(
1573 unsigned Abbrev) {
1574 Record.push_back(N->isDistinct());
1575 Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1576 Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1577 Record.push_back(N->getDiscriminator());
1578
1580 Record.clear();
1581}
1582
1583void DXILBitcodeWriter::writeDINamespace(const DINamespace *N,
1585 unsigned Abbrev) {
1586 Record.push_back(N->isDistinct());
1587 Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1588 Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1589 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1590 Record.push_back(/* line number */ 0);
1591
1593 Record.clear();
1594}
1595
1596void DXILBitcodeWriter::writeDIModule(const DIModule *N,
1598 unsigned Abbrev) {
1599 Record.push_back(N->isDistinct());
1600 for (auto &I : N->operands())
1601 Record.push_back(VE.getMetadataOrNullID(I));
1602
1603 Stream.EmitRecord(bitc::METADATA_MODULE, Record, Abbrev);
1604 Record.clear();
1605}
1606
1607void DXILBitcodeWriter::writeDITemplateTypeParameter(
1609 unsigned Abbrev) {
1610 Record.push_back(N->isDistinct());
1611 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1612 Record.push_back(VE.getMetadataOrNullID(N->getType()));
1613
1615 Record.clear();
1616}
1617
1618void DXILBitcodeWriter::writeDITemplateValueParameter(
1620 unsigned Abbrev) {
1621 Record.push_back(N->isDistinct());
1622 Record.push_back(N->getTag());
1623 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1624 Record.push_back(VE.getMetadataOrNullID(N->getType()));
1625 Record.push_back(VE.getMetadataOrNullID(N->getValue()));
1626
1628 Record.clear();
1629}
1630
1631void DXILBitcodeWriter::writeDIGlobalVariable(const DIGlobalVariable *N,
1633 unsigned Abbrev) {
1634 Record.push_back(N->isDistinct());
1635 Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1636 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1637 Record.push_back(VE.getMetadataOrNullID(N->getRawLinkageName()));
1638 Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1639 Record.push_back(N->getLine());
1640 Record.push_back(VE.getMetadataOrNullID(N->getType()));
1641 Record.push_back(N->isLocalToUnit());
1642 Record.push_back(N->isDefinition());
1643 Record.push_back(/* N->getRawVariable() */ 0);
1644 Record.push_back(VE.getMetadataOrNullID(N->getStaticDataMemberDeclaration()));
1645
1647 Record.clear();
1648}
1649
1650void DXILBitcodeWriter::writeDILocalVariable(const DILocalVariable *N,
1652 unsigned Abbrev) {
1653 Record.push_back(N->isDistinct());
1654 Record.push_back(N->getTag());
1655 Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1656 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1657 Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1658 Record.push_back(N->getLine());
1659 Record.push_back(VE.getMetadataOrNullID(N->getType()));
1660 Record.push_back(N->getArg());
1661 Record.push_back(N->getFlags());
1662
1664 Record.clear();
1665}
1666
1667void DXILBitcodeWriter::writeDIExpression(const DIExpression *N,
1669 unsigned Abbrev) {
1670 Record.reserve(N->getElements().size() + 1);
1671
1672 Record.push_back(N->isDistinct());
1673 Record.append(N->elements_begin(), N->elements_end());
1674
1676 Record.clear();
1677}
1678
1679void DXILBitcodeWriter::writeDIObjCProperty(const DIObjCProperty *N,
1681 unsigned Abbrev) {
1682 llvm_unreachable("DXIL does not support objc!!!");
1683}
1684
1685void DXILBitcodeWriter::writeDIImportedEntity(const DIImportedEntity *N,
1687 unsigned Abbrev) {
1688 Record.push_back(N->isDistinct());
1689 Record.push_back(N->getTag());
1690 Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1691 Record.push_back(VE.getMetadataOrNullID(N->getEntity()));
1692 Record.push_back(N->getLine());
1693 Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1694
1696 Record.clear();
1697}
1698
1699unsigned DXILBitcodeWriter::createDILocationAbbrev() {
1700 // Abbrev for METADATA_LOCATION.
1701 //
1702 // Assume the column is usually under 128, and always output the inlined-at
1703 // location (it's never more expensive than building an array size 1).
1704 std::shared_ptr<BitCodeAbbrev> Abbv = std::make_shared<BitCodeAbbrev>();
1711 return Stream.EmitAbbrev(std::move(Abbv));
1712}
1713
1714unsigned DXILBitcodeWriter::createGenericDINodeAbbrev() {
1715 // Abbrev for METADATA_GENERIC_DEBUG.
1716 //
1717 // Assume the column is usually under 128, and always output the inlined-at
1718 // location (it's never more expensive than building an array size 1).
1719 std::shared_ptr<BitCodeAbbrev> Abbv = std::make_shared<BitCodeAbbrev>();
1727 return Stream.EmitAbbrev(std::move(Abbv));
1728}
1729
1730void DXILBitcodeWriter::writeMetadataRecords(ArrayRef<const Metadata *> MDs,
1732 std::vector<unsigned> *MDAbbrevs,
1733 std::vector<uint64_t> *IndexPos) {
1734 if (MDs.empty())
1735 return;
1736
1737 // Initialize MDNode abbreviations.
1738#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
1739#include "llvm/IR/Metadata.def"
1740
1741 for (const Metadata *MD : MDs) {
1742 if (IndexPos)
1743 IndexPos->push_back(Stream.GetCurrentBitNo());
1744 if (const MDNode *N = dyn_cast<MDNode>(MD)) {
1745 assert(N->isResolved() && "Expected forward references to be resolved");
1746
1747 switch (N->getMetadataID()) {
1748 default:
1749 llvm_unreachable("Invalid MDNode subclass");
1750#define HANDLE_MDNODE_LEAF(CLASS) \
1751 case Metadata::CLASS##Kind: \
1752 if (MDAbbrevs) \
1753 write##CLASS(cast<CLASS>(N), Record, \
1754 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
1755 else \
1756 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
1757 continue;
1758#include "llvm/IR/Metadata.def"
1759 }
1760 }
1761 writeValueAsMetadata(cast<ValueAsMetadata>(MD), Record);
1762 }
1763}
1764
1765unsigned DXILBitcodeWriter::createMetadataStringsAbbrev() {
1766 auto Abbv = std::make_shared<BitCodeAbbrev>();
1770 return Stream.EmitAbbrev(std::move(Abbv));
1771}
1772
1773void DXILBitcodeWriter::writeMetadataStrings(
1775 if (Strings.empty())
1776 return;
1777
1778 unsigned MDSAbbrev = createMetadataStringsAbbrev();
1779
1780 for (const Metadata *MD : Strings) {
1781 const MDString *MDS = cast<MDString>(MD);
1782 // Code: [strchar x N]
1783 Record.append(MDS->bytes_begin(), MDS->bytes_end());
1784
1785 // Emit the finished record.
1786 Stream.EmitRecord(bitc::METADATA_STRING_OLD, Record, MDSAbbrev);
1787 Record.clear();
1788 }
1789}
1790
1791void DXILBitcodeWriter::writeModuleMetadata() {
1792 if (!VE.hasMDs() && M.named_metadata_empty())
1793 return;
1794
1796
1797 // Emit all abbrevs upfront, so that the reader can jump in the middle of the
1798 // block and load any metadata.
1799 std::vector<unsigned> MDAbbrevs;
1800
1801 MDAbbrevs.resize(MetadataAbbrev::LastPlusOne);
1802 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
1803 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
1804 createGenericDINodeAbbrev();
1805
1806 unsigned NameAbbrev = 0;
1807 if (!M.named_metadata_empty()) {
1808 // Abbrev for METADATA_NAME.
1809 std::shared_ptr<BitCodeAbbrev> Abbv = std::make_shared<BitCodeAbbrev>();
1813 NameAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1814 }
1815
1817 writeMetadataStrings(VE.getMDStrings(), Record);
1818
1819 std::vector<uint64_t> IndexPos;
1820 IndexPos.reserve(VE.getNonMDStrings().size());
1821 writeMetadataRecords(VE.getNonMDStrings(), Record, &MDAbbrevs, &IndexPos);
1822
1823 // Write named metadata.
1824 for (const NamedMDNode &NMD : M.named_metadata()) {
1825 // Write name.
1826 StringRef Str = NMD.getName();
1827 Record.append(Str.bytes_begin(), Str.bytes_end());
1828 Stream.EmitRecord(bitc::METADATA_NAME, Record, NameAbbrev);
1829 Record.clear();
1830
1831 // Write named metadata operands.
1832 for (const MDNode *N : NMD.operands())
1833 Record.push_back(VE.getMetadataID(N));
1835 Record.clear();
1836 }
1837
1838 Stream.ExitBlock();
1839}
1840
1841void DXILBitcodeWriter::writeFunctionMetadata(const Function &F) {
1842 if (!VE.hasMDs())
1843 return;
1844
1847 writeMetadataStrings(VE.getMDStrings(), Record);
1848 writeMetadataRecords(VE.getNonMDStrings(), Record);
1849 Stream.ExitBlock();
1850}
1851
1852void DXILBitcodeWriter::writeFunctionMetadataAttachment(const Function &F) {
1854
1856
1857 // Write metadata attachments
1858 // METADATA_ATTACHMENT - [m x [value, [n x [id, mdnode]]]
1860 F.getAllMetadata(MDs);
1861 if (!MDs.empty()) {
1862 for (const auto &I : MDs) {
1863 Record.push_back(I.first);
1864 Record.push_back(VE.getMetadataID(I.second));
1865 }
1867 Record.clear();
1868 }
1869
1870 for (const BasicBlock &BB : F)
1871 for (const Instruction &I : BB) {
1872 MDs.clear();
1873 I.getAllMetadataOtherThanDebugLoc(MDs);
1874
1875 // If no metadata, ignore instruction.
1876 if (MDs.empty())
1877 continue;
1878
1879 Record.push_back(VE.getInstructionID(&I));
1880
1881 for (unsigned i = 0, e = MDs.size(); i != e; ++i) {
1882 Record.push_back(MDs[i].first);
1883 Record.push_back(VE.getMetadataID(MDs[i].second));
1884 }
1886 Record.clear();
1887 }
1888
1889 Stream.ExitBlock();
1890}
1891
1892void DXILBitcodeWriter::writeModuleMetadataKinds() {
1894
1895 // Write metadata kinds
1896 // METADATA_KIND - [n x [id, name]]
1898 M.getMDKindNames(Names);
1899
1900 if (Names.empty())
1901 return;
1902
1904
1905 for (unsigned MDKindID = 0, e = Names.size(); MDKindID != e; ++MDKindID) {
1906 Record.push_back(MDKindID);
1907 StringRef KName = Names[MDKindID];
1908 Record.append(KName.begin(), KName.end());
1909
1911 Record.clear();
1912 }
1913
1914 Stream.ExitBlock();
1915}
1916
1917void DXILBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal,
1918 bool isGlobal) {
1919 if (FirstVal == LastVal)
1920 return;
1921
1923
1924 unsigned AggregateAbbrev = 0;
1925 unsigned String8Abbrev = 0;
1926 unsigned CString7Abbrev = 0;
1927 unsigned CString6Abbrev = 0;
1928 // If this is a constant pool for the module, emit module-specific abbrevs.
1929 if (isGlobal) {
1930 // Abbrev for CST_CODE_AGGREGATE.
1931 auto Abbv = std::make_shared<BitCodeAbbrev>();
1934 Abbv->Add(
1936 AggregateAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1937
1938 // Abbrev for CST_CODE_STRING.
1939 Abbv = std::make_shared<BitCodeAbbrev>();
1943 String8Abbrev = Stream.EmitAbbrev(std::move(Abbv));
1944 // Abbrev for CST_CODE_CSTRING.
1945 Abbv = std::make_shared<BitCodeAbbrev>();
1949 CString7Abbrev = Stream.EmitAbbrev(std::move(Abbv));
1950 // Abbrev for CST_CODE_CSTRING.
1951 Abbv = std::make_shared<BitCodeAbbrev>();
1955 CString6Abbrev = Stream.EmitAbbrev(std::move(Abbv));
1956 }
1957
1959
1960 const ValueEnumerator::ValueList &Vals = VE.getValues();
1961 Type *LastTy = nullptr;
1962 for (unsigned i = FirstVal; i != LastVal; ++i) {
1963 const Value *V = Vals[i].first;
1964 // If we need to switch types, do so now.
1965 if (V->getType() != LastTy) {
1966 LastTy = V->getType();
1967 Record.push_back(getTypeID(LastTy, V));
1969 CONSTANTS_SETTYPE_ABBREV);
1970 Record.clear();
1971 }
1972
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);
1977
1978 // Add the asm string.
1979 const std::string &AsmStr = IA->getAsmString();
1980 Record.push_back(AsmStr.size());
1981 Record.append(AsmStr.begin(), AsmStr.end());
1982
1983 // Add the constraint string.
1984 const std::string &ConstraintStr = IA->getConstraintString();
1985 Record.push_back(ConstraintStr.size());
1986 Record.append(ConstraintStr.begin(), ConstraintStr.end());
1988 Record.clear();
1989 continue;
1990 }
1991 const Constant *C = cast<Constant>(V);
1992 unsigned Code = -1U;
1993 unsigned AbbrevToUse = 0;
1994 if (C->isNullValue()) {
1996 } else if (isa<UndefValue>(C)) {
1998 } else if (const ConstantInt *IV = dyn_cast<ConstantInt>(C)) {
1999 if (IV->getBitWidth() <= 64) {
2000 uint64_t V = IV->getSExtValue();
2003 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2004 } else { // Wide integers, > 64 bits in size.
2005 // We have an arbitrary precision integer value to write whose
2006 // bit width is > 64. However, in canonical unsigned integer
2007 // format it is likely that the high bits are going to be zero.
2008 // So, we only write the number of active words.
2009 unsigned NWords = IV->getValue().getActiveWords();
2010 const uint64_t *RawWords = IV->getValue().getRawData();
2011 for (unsigned i = 0; i != NWords; ++i) {
2012 emitSignedInt64(Record, RawWords[i]);
2013 }
2015 }
2016 } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
2018 Type *Ty = CFP->getType();
2019 if (Ty->isHalfTy() || Ty->isFloatTy() || Ty->isDoubleTy()) {
2020 Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2021 } else if (Ty->isX86_FP80Ty()) {
2022 // api needed to prevent premature destruction
2023 // bits are not in the same order as a normal i80 APInt, compensate.
2024 APInt api = CFP->getValueAPF().bitcastToAPInt();
2025 const uint64_t *p = api.getRawData();
2026 Record.push_back((p[1] << 48) | (p[0] >> 16));
2027 Record.push_back(p[0] & 0xffffLL);
2028 } else if (Ty->isFP128Ty() || Ty->isPPC_FP128Ty()) {
2029 APInt api = CFP->getValueAPF().bitcastToAPInt();
2030 const uint64_t *p = api.getRawData();
2031 Record.push_back(p[0]);
2032 Record.push_back(p[1]);
2033 } else {
2034 assert(0 && "Unknown FP type!");
2035 }
2036 } else if (isa<ConstantDataSequential>(C) &&
2037 cast<ConstantDataSequential>(C)->isString()) {
2038 const ConstantDataSequential *Str = cast<ConstantDataSequential>(C);
2039 // Emit constant strings specially.
2040 unsigned NumElts = Str->getNumElements();
2041 // If this is a null-terminated string, use the denser CSTRING encoding.
2042 if (Str->isCString()) {
2044 --NumElts; // Don't encode the null, which isn't allowed by char6.
2045 } else {
2047 AbbrevToUse = String8Abbrev;
2048 }
2049 bool isCStr7 = Code == bitc::CST_CODE_CSTRING;
2050 bool isCStrChar6 = Code == bitc::CST_CODE_CSTRING;
2051 for (unsigned i = 0; i != NumElts; ++i) {
2052 unsigned char V = Str->getElementAsInteger(i);
2053 Record.push_back(V);
2054 isCStr7 &= (V & 128) == 0;
2055 if (isCStrChar6)
2056 isCStrChar6 = BitCodeAbbrevOp::isChar6(V);
2057 }
2058
2059 if (isCStrChar6)
2060 AbbrevToUse = CString6Abbrev;
2061 else if (isCStr7)
2062 AbbrevToUse = CString7Abbrev;
2063 } else if (const ConstantDataSequential *CDS =
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));
2070 } else if (EltTy->isFloatTy()) {
2071 for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
2072 union {
2073 float F;
2074 uint32_t I;
2075 };
2076 F = CDS->getElementAsFloat(i);
2077 Record.push_back(I);
2078 }
2079 } else {
2080 assert(EltTy->isDoubleTy() && "Unknown ConstantData element type");
2081 for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
2082 union {
2083 double F;
2084 uint64_t I;
2085 };
2086 F = CDS->getElementAsDouble(i);
2087 Record.push_back(I);
2088 }
2089 }
2090 } else if (isa<ConstantArray>(C) || isa<ConstantStruct>(C) ||
2091 isa<ConstantVector>(C)) {
2093 for (const Value *Op : C->operands())
2094 Record.push_back(VE.getValueID(Op));
2095 AbbrevToUse = AggregateAbbrev;
2096 } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
2097 switch (CE->getOpcode()) {
2098 default:
2099 if (Instruction::isCast(CE->getOpcode())) {
2101 Record.push_back(getEncodedCastOpcode(CE->getOpcode()));
2102 Record.push_back(
2103 getTypeID(C->getOperand(0)->getType(), C->getOperand(0)));
2104 Record.push_back(VE.getValueID(C->getOperand(0)));
2105 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2106 } else {
2107 assert(CE->getNumOperands() == 2 && "Unknown constant expr!");
2109 Record.push_back(getEncodedBinaryOpcode(CE->getOpcode()));
2110 Record.push_back(VE.getValueID(C->getOperand(0)));
2111 Record.push_back(VE.getValueID(C->getOperand(1)));
2113 if (Flags != 0)
2114 Record.push_back(Flags);
2115 }
2116 break;
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) {
2124 Record.push_back(
2125 getTypeID(C->getOperand(i)->getType(), C->getOperand(i)));
2126 Record.push_back(VE.getValueID(C->getOperand(i)));
2127 }
2128 break;
2129 }
2130 case Instruction::Select:
2132 Record.push_back(VE.getValueID(C->getOperand(0)));
2133 Record.push_back(VE.getValueID(C->getOperand(1)));
2134 Record.push_back(VE.getValueID(C->getOperand(2)));
2135 break;
2136 case Instruction::ExtractElement:
2138 Record.push_back(getTypeID(C->getOperand(0)->getType()));
2139 Record.push_back(VE.getValueID(C->getOperand(0)));
2140 Record.push_back(getTypeID(C->getOperand(1)->getType()));
2141 Record.push_back(VE.getValueID(C->getOperand(1)));
2142 break;
2143 case Instruction::InsertElement:
2145 Record.push_back(VE.getValueID(C->getOperand(0)));
2146 Record.push_back(VE.getValueID(C->getOperand(1)));
2147 Record.push_back(getTypeID(C->getOperand(2)->getType()));
2148 Record.push_back(VE.getValueID(C->getOperand(2)));
2149 break;
2150 case Instruction::ShuffleVector:
2151 // If the return type and argument types are the same, this is a
2152 // standard shufflevector instruction. If the types are different,
2153 // then the shuffle is widening or truncating the input vectors, and
2154 // the argument type must also be encoded.
2155 if (C->getType() == C->getOperand(0)->getType()) {
2157 } else {
2159 Record.push_back(getTypeID(C->getOperand(0)->getType()));
2160 }
2161 Record.push_back(VE.getValueID(C->getOperand(0)));
2162 Record.push_back(VE.getValueID(C->getOperand(1)));
2163 Record.push_back(VE.getValueID(C->getOperand(2)));
2164 break;
2165 case Instruction::ICmp:
2166 case Instruction::FCmp:
2168 Record.push_back(getTypeID(C->getOperand(0)->getType()));
2169 Record.push_back(VE.getValueID(C->getOperand(0)));
2170 Record.push_back(VE.getValueID(C->getOperand(1)));
2171 Record.push_back(CE->getPredicate());
2172 break;
2173 }
2174 } else if (const BlockAddress *BA = dyn_cast<BlockAddress>(C)) {
2176 Record.push_back(getTypeID(BA->getFunction()->getType()));
2177 Record.push_back(VE.getValueID(BA->getFunction()));
2178 Record.push_back(VE.getGlobalBasicBlockID(BA->getBasicBlock()));
2179 } else {
2180#ifndef NDEBUG
2181 C->dump();
2182#endif
2183 llvm_unreachable("Unknown constant!");
2184 }
2185 Stream.EmitRecord(Code, Record, AbbrevToUse);
2186 Record.clear();
2187 }
2188
2189 Stream.ExitBlock();
2190}
2191
2192void DXILBitcodeWriter::writeModuleConstants() {
2193 const ValueEnumerator::ValueList &Vals = VE.getValues();
2194
2195 // Find the first constant to emit, which is the first non-globalvalue value.
2196 // We know globalvalues have been emitted by WriteModuleInfo.
2197 for (unsigned i = 0, e = Vals.size(); i != e; ++i) {
2198 if (!isa<GlobalValue>(Vals[i].first)) {
2199 writeConstants(i, Vals.size(), true);
2200 return;
2201 }
2202 }
2203}
2204
2205/// pushValueAndType - The file has to encode both the value and type id for
2206/// many values, because we need to know what type to create for forward
2207/// references. However, most operands are not forward references, so this type
2208/// field is not needed.
2209///
2210/// This function adds V's value ID to Vals. If the value ID is higher than the
2211/// instruction ID, then it is a forward reference, and it also includes the
2212/// type ID. The value ID that is written is encoded relative to the InstID.
2213bool DXILBitcodeWriter::pushValueAndType(const Value *V, unsigned InstID,
2215 unsigned ValID = VE.getValueID(V);
2216 // Make encoding relative to the InstID.
2217 Vals.push_back(InstID - ValID);
2218 if (ValID >= InstID) {
2219 Vals.push_back(getTypeID(V->getType(), V));
2220 return true;
2221 }
2222 return false;
2223}
2224
2225/// pushValue - Like pushValueAndType, but where the type of the value is
2226/// omitted (perhaps it was already encoded in an earlier operand).
2227void DXILBitcodeWriter::pushValue(const Value *V, unsigned InstID,
2229 unsigned ValID = VE.getValueID(V);
2230 Vals.push_back(InstID - ValID);
2231}
2232
2233void DXILBitcodeWriter::pushValueSigned(const Value *V, unsigned InstID,
2235 unsigned ValID = VE.getValueID(V);
2236 int64_t diff = ((int32_t)InstID - (int32_t)ValID);
2237 emitSignedInt64(Vals, diff);
2238}
2239
2240/// WriteInstruction - Emit an instruction
2241void DXILBitcodeWriter::writeInstruction(const Instruction &I, unsigned InstID,
2243 unsigned Code = 0;
2244 unsigned AbbrevToUse = 0;
2245 VE.setInstructionID(&I);
2246 switch (I.getOpcode()) {
2247 default:
2248 if (Instruction::isCast(I.getOpcode())) {
2250 if (!pushValueAndType(I.getOperand(0), InstID, Vals))
2251 AbbrevToUse = (unsigned)FUNCTION_INST_CAST_ABBREV;
2252 Vals.push_back(getTypeID(I.getType(), &I));
2253 Vals.push_back(getEncodedCastOpcode(I.getOpcode()));
2254 } else {
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);
2260 Vals.push_back(getEncodedBinaryOpcode(I.getOpcode()));
2262 if (Flags != 0) {
2263 if (AbbrevToUse == (unsigned)FUNCTION_INST_BINOP_ABBREV)
2264 AbbrevToUse = (unsigned)FUNCTION_INST_BINOP_FLAGS_ABBREV;
2265 Vals.push_back(Flags);
2266 }
2267 }
2268 break;
2269
2270 case Instruction::GetElementPtr: {
2272 AbbrevToUse = (unsigned)FUNCTION_INST_GEP_ABBREV;
2273 auto &GEPInst = cast<GetElementPtrInst>(I);
2274 Vals.push_back(GEPInst.isInBounds());
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);
2278 break;
2279 }
2280 case Instruction::ExtractValue: {
2282 pushValueAndType(I.getOperand(0), InstID, Vals);
2283 const ExtractValueInst *EVI = cast<ExtractValueInst>(&I);
2284 Vals.append(EVI->idx_begin(), EVI->idx_end());
2285 break;
2286 }
2287 case Instruction::InsertValue: {
2289 pushValueAndType(I.getOperand(0), InstID, Vals);
2290 pushValueAndType(I.getOperand(1), InstID, Vals);
2291 const InsertValueInst *IVI = cast<InsertValueInst>(&I);
2292 Vals.append(IVI->idx_begin(), IVI->idx_end());
2293 break;
2294 }
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);
2300 break;
2301 case Instruction::ExtractElement:
2303 pushValueAndType(I.getOperand(0), InstID, Vals);
2304 pushValueAndType(I.getOperand(1), InstID, Vals);
2305 break;
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);
2311 break;
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,
2317 Vals);
2318 break;
2319 case Instruction::ICmp:
2320 case Instruction::FCmp: {
2321 // compare returning Int1Ty or vector of Int1Ty
2323 pushValueAndType(I.getOperand(0), InstID, Vals);
2324 pushValue(I.getOperand(1), InstID, Vals);
2325 Vals.push_back(cast<CmpInst>(I).getPredicate());
2327 if (Flags != 0)
2328 Vals.push_back(Flags);
2329 break;
2330 }
2331
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;
2340 } else {
2341 for (unsigned i = 0, e = NumOperands; i != e; ++i)
2342 pushValueAndType(I.getOperand(i), InstID, Vals);
2343 }
2344 } break;
2345 case Instruction::Br: {
2347 const BranchInst &II = cast<BranchInst>(I);
2348 Vals.push_back(VE.getValueID(II.getSuccessor(0)));
2349 if (II.isConditional()) {
2350 Vals.push_back(VE.getValueID(II.getSuccessor(1)));
2351 pushValue(II.getCondition(), InstID, Vals);
2352 }
2353 } break;
2354 case Instruction::Switch: {
2356 const SwitchInst &SI = cast<SwitchInst>(I);
2357 Vals.push_back(getTypeID(SI.getCondition()->getType()));
2358 pushValue(SI.getCondition(), InstID, Vals);
2359 Vals.push_back(VE.getValueID(SI.getDefaultDest()));
2360 for (auto Case : SI.cases()) {
2361 Vals.push_back(VE.getValueID(Case.getCaseValue()));
2362 Vals.push_back(VE.getValueID(Case.getCaseSuccessor()));
2363 }
2364 } break;
2365 case Instruction::IndirectBr:
2367 Vals.push_back(getTypeID(I.getOperand(0)->getType()));
2368 // Encode the address operand as relative, but not the basic blocks.
2369 pushValue(I.getOperand(0), InstID, Vals);
2370 for (unsigned i = 1, e = I.getNumOperands(); i != e; ++i)
2371 Vals.push_back(VE.getValueID(I.getOperand(i)));
2372 break;
2373
2374 case Instruction::Invoke: {
2375 const InvokeInst *II = cast<InvokeInst>(&I);
2376 const Value *Callee = II->getCalledOperand();
2377 FunctionType *FTy = II->getFunctionType();
2379
2381 Vals.push_back(II->getCallingConv() | 1 << 13);
2382 Vals.push_back(VE.getValueID(II->getNormalDest()));
2383 Vals.push_back(VE.getValueID(II->getUnwindDest()));
2384 Vals.push_back(getTypeID(FTy));
2385 pushValueAndType(Callee, InstID, Vals);
2386
2387 // Emit value #'s for the fixed parameters.
2388 for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
2389 pushValue(I.getOperand(i), InstID, Vals); // fixed param.
2390
2391 // Emit type/value pairs for varargs params.
2392 if (FTy->isVarArg()) {
2393 for (unsigned i = FTy->getNumParams(), e = I.getNumOperands() - 3; i != e;
2394 ++i)
2395 pushValueAndType(I.getOperand(i), InstID, Vals); // vararg
2396 }
2397 break;
2398 }
2399 case Instruction::Resume:
2401 pushValueAndType(I.getOperand(0), InstID, Vals);
2402 break;
2403 case Instruction::Unreachable:
2405 AbbrevToUse = (unsigned)FUNCTION_INST_UNREACHABLE_ABBREV;
2406 break;
2407
2408 case Instruction::PHI: {
2409 const PHINode &PN = cast<PHINode>(I);
2411 // With the newer instruction encoding, forward references could give
2412 // negative valued IDs. This is most common for PHIs, so we use
2413 // signed VBRs.
2415 Vals64.push_back(getTypeID(PN.getType()));
2416 for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) {
2417 pushValueSigned(PN.getIncomingValue(i), InstID, Vals64);
2418 Vals64.push_back(VE.getValueID(PN.getIncomingBlock(i)));
2419 }
2420 // Emit a Vals64 vector and exit.
2421 Stream.EmitRecord(Code, Vals64, AbbrevToUse);
2422 Vals64.clear();
2423 return;
2424 }
2425
2426 case Instruction::LandingPad: {
2427 const LandingPadInst &LP = cast<LandingPadInst>(I);
2429 Vals.push_back(getTypeID(LP.getType()));
2430 Vals.push_back(LP.isCleanup());
2431 Vals.push_back(LP.getNumClauses());
2432 for (unsigned I = 0, E = LP.getNumClauses(); I != E; ++I) {
2433 if (LP.isCatch(I))
2435 else
2437 pushValueAndType(LP.getClause(I), InstID, Vals);
2438 }
2439 break;
2440 }
2441
2442 case Instruction::Alloca: {
2444 const AllocaInst &AI = cast<AllocaInst>(I);
2445 Vals.push_back(getTypeID(AI.getAllocatedType()));
2446 Vals.push_back(getTypeID(I.getOperand(0)->getType()));
2447 Vals.push_back(VE.getValueID(I.getOperand(0))); // size.
2448 unsigned AlignRecord = Log2_32(AI.getAlign().value()) + 1;
2449 assert(AlignRecord < 1 << 5 && "alignment greater than 1 << 64");
2450 AlignRecord |= AI.isUsedWithInAlloca() << 5;
2451 AlignRecord |= 1 << 6;
2452 Vals.push_back(AlignRecord);
2453 break;
2454 }
2455
2456 case Instruction::Load:
2457 if (cast<LoadInst>(I).isAtomic()) {
2459 pushValueAndType(I.getOperand(0), InstID, Vals);
2460 } else {
2462 if (!pushValueAndType(I.getOperand(0), InstID, Vals)) // ptr
2463 AbbrevToUse = (unsigned)FUNCTION_INST_LOAD_ABBREV;
2464 }
2465 Vals.push_back(getTypeID(I.getType()));
2466 Vals.push_back(Log2(cast<LoadInst>(I).getAlign()) + 1);
2467 Vals.push_back(cast<LoadInst>(I).isVolatile());
2468 if (cast<LoadInst>(I).isAtomic()) {
2469 Vals.push_back(getEncodedOrdering(cast<LoadInst>(I).getOrdering()));
2470 Vals.push_back(getEncodedSyncScopeID(cast<LoadInst>(I).getSyncScopeID()));
2471 }
2472 break;
2473 case Instruction::Store:
2474 if (cast<StoreInst>(I).isAtomic())
2476 else
2478 pushValueAndType(I.getOperand(1), InstID, Vals); // ptrty + ptr
2479 pushValueAndType(I.getOperand(0), InstID, Vals); // valty + val
2480 Vals.push_back(Log2(cast<StoreInst>(I).getAlign()) + 1);
2481 Vals.push_back(cast<StoreInst>(I).isVolatile());
2482 if (cast<StoreInst>(I).isAtomic()) {
2483 Vals.push_back(getEncodedOrdering(cast<StoreInst>(I).getOrdering()));
2484 Vals.push_back(
2485 getEncodedSyncScopeID(cast<StoreInst>(I).getSyncScopeID()));
2486 }
2487 break;
2488 case Instruction::AtomicCmpXchg:
2490 pushValueAndType(I.getOperand(0), InstID, Vals); // ptrty + ptr
2491 pushValueAndType(I.getOperand(1), InstID, Vals); // cmp.
2492 pushValue(I.getOperand(2), InstID, Vals); // newval.
2493 Vals.push_back(cast<AtomicCmpXchgInst>(I).isVolatile());
2494 Vals.push_back(
2495 getEncodedOrdering(cast<AtomicCmpXchgInst>(I).getSuccessOrdering()));
2496 Vals.push_back(
2497 getEncodedSyncScopeID(cast<AtomicCmpXchgInst>(I).getSyncScopeID()));
2498 Vals.push_back(
2499 getEncodedOrdering(cast<AtomicCmpXchgInst>(I).getFailureOrdering()));
2500 Vals.push_back(cast<AtomicCmpXchgInst>(I).isWeak());
2501 break;
2502 case Instruction::AtomicRMW:
2504 pushValueAndType(I.getOperand(0), InstID, Vals); // ptrty + ptr
2505 pushValue(I.getOperand(1), InstID, Vals); // val.
2506 Vals.push_back(
2507 getEncodedRMWOperation(cast<AtomicRMWInst>(I).getOperation()));
2508 Vals.push_back(cast<AtomicRMWInst>(I).isVolatile());
2509 Vals.push_back(getEncodedOrdering(cast<AtomicRMWInst>(I).getOrdering()));
2510 Vals.push_back(
2511 getEncodedSyncScopeID(cast<AtomicRMWInst>(I).getSyncScopeID()));
2512 break;
2513 case Instruction::Fence:
2515 Vals.push_back(getEncodedOrdering(cast<FenceInst>(I).getOrdering()));
2516 Vals.push_back(getEncodedSyncScopeID(cast<FenceInst>(I).getSyncScopeID()));
2517 break;
2518 case Instruction::Call: {
2519 const CallInst &CI = cast<CallInst>(I);
2520 FunctionType *FTy = CI.getFunctionType();
2521
2523
2525 Vals.push_back((CI.getCallingConv() << 1) | unsigned(CI.isTailCall()) |
2526 unsigned(CI.isMustTailCall()) << 14 | 1 << 15);
2527 Vals.push_back(getGlobalObjectValueTypeID(FTy, CI.getCalledFunction()));
2528 pushValueAndType(CI.getCalledOperand(), InstID, Vals); // Callee
2529
2530 // Emit value #'s for the fixed parameters.
2531 for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
2532 // Check for labels (can happen with asm labels).
2533 if (FTy->getParamType(i)->isLabelTy())
2534 Vals.push_back(VE.getValueID(CI.getArgOperand(i)));
2535 else
2536 pushValue(CI.getArgOperand(i), InstID, Vals); // fixed param.
2537 }
2538
2539 // Emit type/value pairs for varargs params.
2540 if (FTy->isVarArg()) {
2541 for (unsigned i = FTy->getNumParams(), e = CI.arg_size(); i != e; ++i)
2542 pushValueAndType(CI.getArgOperand(i), InstID, Vals); // varargs
2543 }
2544 break;
2545 }
2546 case Instruction::VAArg:
2548 Vals.push_back(getTypeID(I.getOperand(0)->getType())); // valistty
2549 pushValue(I.getOperand(0), InstID, Vals); // valist.
2550 Vals.push_back(getTypeID(I.getType())); // restype.
2551 break;
2552 }
2553
2554 Stream.EmitRecord(Code, Vals, AbbrevToUse);
2555 Vals.clear();
2556}
2557
2558// Emit names for globals/functions etc.
2559void DXILBitcodeWriter::writeFunctionLevelValueSymbolTable(
2560 const ValueSymbolTable &VST) {
2561 if (VST.empty())
2562 return;
2564
2566
2567 // HLSL Change
2568 // Read the named values from a sorted list instead of the original list
2569 // to ensure the binary is the same no matter what values ever existed.
2571
2572 for (auto &VI : VST) {
2573 SortedTable.push_back(VI.second->getValueName());
2574 }
2575 // The keys are unique, so there shouldn't be stability issues.
2576 llvm::sort(SortedTable, [](const ValueName *A, const ValueName *B) {
2577 return A->first() < B->first();
2578 });
2579
2580 for (const ValueName *SI : SortedTable) {
2581 auto &Name = *SI;
2582
2583 // Figure out the encoding to use for the name.
2584 bool is7Bit = true;
2585 bool isChar6 = true;
2586 for (const char *C = Name.getKeyData(), *E = C + Name.getKeyLength();
2587 C != E; ++C) {
2588 if (isChar6)
2589 isChar6 = BitCodeAbbrevOp::isChar6(*C);
2590 if ((unsigned char)*C & 128) {
2591 is7Bit = false;
2592 break; // don't bother scanning the rest.
2593 }
2594 }
2595
2596 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
2597
2598 // VST_ENTRY: [valueid, namechar x N]
2599 // VST_BBENTRY: [bbid, namechar x N]
2600 unsigned Code;
2601 if (isa<BasicBlock>(SI->getValue())) {
2603 if (isChar6)
2604 AbbrevToUse = VST_BBENTRY_6_ABBREV;
2605 } else {
2607 if (isChar6)
2608 AbbrevToUse = VST_ENTRY_6_ABBREV;
2609 else if (is7Bit)
2610 AbbrevToUse = VST_ENTRY_7_ABBREV;
2611 }
2612
2613 NameVals.push_back(VE.getValueID(SI->getValue()));
2614 for (const char *P = Name.getKeyData(),
2615 *E = Name.getKeyData() + Name.getKeyLength();
2616 P != E; ++P)
2617 NameVals.push_back((unsigned char)*P);
2618
2619 // Emit the finished record.
2620 Stream.EmitRecord(Code, NameVals, AbbrevToUse);
2621 NameVals.clear();
2622 }
2623 Stream.ExitBlock();
2624}
2625
2626/// Emit a function body to the module stream.
2627void DXILBitcodeWriter::writeFunction(const Function &F) {
2630
2632
2633 // Emit the number of basic blocks, so the reader can create them ahead of
2634 // time.
2635 Vals.push_back(VE.getBasicBlocks().size());
2637 Vals.clear();
2638
2639 // If there are function-local constants, emit them now.
2640 unsigned CstStart, CstEnd;
2641 VE.getFunctionConstantRange(CstStart, CstEnd);
2642 writeConstants(CstStart, CstEnd, false);
2643
2644 // If there is function-local metadata, emit it now.
2645 writeFunctionMetadata(F);
2646
2647 // Keep a running idea of what the instruction ID is.
2648 unsigned InstID = CstEnd;
2649
2650 bool NeedsMetadataAttachment = F.hasMetadata();
2651
2652 DILocation *LastDL = nullptr;
2653
2654 // Finally, emit all the instructions, in order.
2655 for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
2656 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E;
2657 ++I) {
2658 writeInstruction(*I, InstID, Vals);
2659
2660 if (!I->getType()->isVoidTy())
2661 ++InstID;
2662
2663 // If the instruction has metadata, write a metadata attachment later.
2664 NeedsMetadataAttachment |= I->hasMetadataOtherThanDebugLoc();
2665
2666 // If the instruction has a debug location, emit it.
2667 DILocation *DL = I->getDebugLoc();
2668 if (!DL)
2669 continue;
2670
2671 if (DL == LastDL) {
2672 // Just repeat the same debug loc as last time.
2674 continue;
2675 }
2676
2677 Vals.push_back(DL->getLine());
2678 Vals.push_back(DL->getColumn());
2679 Vals.push_back(VE.getMetadataOrNullID(DL->getScope()));
2680 Vals.push_back(VE.getMetadataOrNullID(DL->getInlinedAt()));
2682 Vals.clear();
2683
2684 LastDL = DL;
2685 }
2686
2687 // Emit names for all the instructions etc.
2688 if (auto *Symtab = F.getValueSymbolTable())
2689 writeFunctionLevelValueSymbolTable(*Symtab);
2690
2691 if (NeedsMetadataAttachment)
2692 writeFunctionMetadataAttachment(F);
2693
2694 VE.purgeFunction();
2695 Stream.ExitBlock();
2696}
2697
2698// Emit blockinfo, which defines the standard abbreviations etc.
2699void DXILBitcodeWriter::writeBlockInfo() {
2700 // We only want to emit block info records for blocks that have multiple
2701 // instances: CONSTANTS_BLOCK, FUNCTION_BLOCK and VALUE_SYMTAB_BLOCK.
2702 // Other blocks can define their abbrevs inline.
2703 Stream.EnterBlockInfoBlock();
2704
2705 { // 8-bit fixed-width VST_ENTRY/VST_BBENTRY strings.
2706 auto Abbv = std::make_shared<BitCodeAbbrev>();
2712 std::move(Abbv)) != VST_ENTRY_8_ABBREV)
2713 assert(false && "Unexpected abbrev ordering!");
2714 }
2715
2716 { // 7-bit fixed width VST_ENTRY strings.
2717 auto Abbv = std::make_shared<BitCodeAbbrev>();
2723 std::move(Abbv)) != VST_ENTRY_7_ABBREV)
2724 assert(false && "Unexpected abbrev ordering!");
2725 }
2726 { // 6-bit char6 VST_ENTRY strings.
2727 auto Abbv = std::make_shared<BitCodeAbbrev>();
2733 std::move(Abbv)) != VST_ENTRY_6_ABBREV)
2734 assert(false && "Unexpected abbrev ordering!");
2735 }
2736 { // 6-bit char6 VST_BBENTRY strings.
2737 auto Abbv = std::make_shared<BitCodeAbbrev>();
2743 std::move(Abbv)) != VST_BBENTRY_6_ABBREV)
2744 assert(false && "Unexpected abbrev ordering!");
2745 }
2746
2747 { // SETTYPE abbrev for CONSTANTS_BLOCK.
2748 auto Abbv = std::make_shared<BitCodeAbbrev>();
2752 if (Stream.EmitBlockInfoAbbrev(bitc::CONSTANTS_BLOCK_ID, std::move(Abbv)) !=
2753 CONSTANTS_SETTYPE_ABBREV)
2754 assert(false && "Unexpected abbrev ordering!");
2755 }
2756
2757 { // INTEGER abbrev for CONSTANTS_BLOCK.
2758 auto Abbv = std::make_shared<BitCodeAbbrev>();
2761 if (Stream.EmitBlockInfoAbbrev(bitc::CONSTANTS_BLOCK_ID, std::move(Abbv)) !=
2762 CONSTANTS_INTEGER_ABBREV)
2763 assert(false && "Unexpected abbrev ordering!");
2764 }
2765
2766 { // CE_CAST abbrev for CONSTANTS_BLOCK.
2767 auto Abbv = std::make_shared<BitCodeAbbrev>();
2769 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // cast opc
2770 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, // typeid
2772 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // value id
2773
2774 if (Stream.EmitBlockInfoAbbrev(bitc::CONSTANTS_BLOCK_ID, std::move(Abbv)) !=
2775 CONSTANTS_CE_CAST_Abbrev)
2776 assert(false && "Unexpected abbrev ordering!");
2777 }
2778 { // NULL abbrev for CONSTANTS_BLOCK.
2779 auto Abbv = std::make_shared<BitCodeAbbrev>();
2781 if (Stream.EmitBlockInfoAbbrev(bitc::CONSTANTS_BLOCK_ID, std::move(Abbv)) !=
2782 CONSTANTS_NULL_Abbrev)
2783 assert(false && "Unexpected abbrev ordering!");
2784 }
2785
2786 // FIXME: This should only use space for first class types!
2787
2788 { // INST_LOAD abbrev for FUNCTION_BLOCK.
2789 auto Abbv = std::make_shared<BitCodeAbbrev>();
2791 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Ptr
2792 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, // dest ty
2794 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4)); // Align
2795 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // volatile
2796 if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, std::move(Abbv)) !=
2797 (unsigned)FUNCTION_INST_LOAD_ABBREV)
2798 assert(false && "Unexpected abbrev ordering!");
2799 }
2800 { // INST_BINOP abbrev for FUNCTION_BLOCK.
2801 auto Abbv = std::make_shared<BitCodeAbbrev>();
2803 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LHS
2804 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // RHS
2805 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // opc
2806 if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, std::move(Abbv)) !=
2807 (unsigned)FUNCTION_INST_BINOP_ABBREV)
2808 assert(false && "Unexpected abbrev ordering!");
2809 }
2810 { // INST_BINOP_FLAGS abbrev for FUNCTION_BLOCK.
2811 auto Abbv = std::make_shared<BitCodeAbbrev>();
2813 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LHS
2814 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // RHS
2815 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // opc
2816 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7)); // flags
2817 if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, std::move(Abbv)) !=
2818 (unsigned)FUNCTION_INST_BINOP_FLAGS_ABBREV)
2819 assert(false && "Unexpected abbrev ordering!");
2820 }
2821 { // INST_CAST abbrev for FUNCTION_BLOCK.
2822 auto Abbv = std::make_shared<BitCodeAbbrev>();
2824 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // OpVal
2825 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, // dest ty
2827 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // opc
2828 if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, std::move(Abbv)) !=
2829 (unsigned)FUNCTION_INST_CAST_ABBREV)
2830 assert(false && "Unexpected abbrev ordering!");
2831 }
2832
2833 { // INST_RET abbrev for FUNCTION_BLOCK.
2834 auto Abbv = std::make_shared<BitCodeAbbrev>();
2836 if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, std::move(Abbv)) !=
2837 (unsigned)FUNCTION_INST_RET_VOID_ABBREV)
2838 assert(false && "Unexpected abbrev ordering!");
2839 }
2840 { // INST_RET abbrev for FUNCTION_BLOCK.
2841 auto Abbv = std::make_shared<BitCodeAbbrev>();
2843 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ValID
2844 if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, std::move(Abbv)) !=
2845 (unsigned)FUNCTION_INST_RET_VAL_ABBREV)
2846 assert(false && "Unexpected abbrev ordering!");
2847 }
2848 { // INST_UNREACHABLE abbrev for FUNCTION_BLOCK.
2849 auto Abbv = std::make_shared<BitCodeAbbrev>();
2851 if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, std::move(Abbv)) !=
2852 (unsigned)FUNCTION_INST_UNREACHABLE_ABBREV)
2853 assert(false && "Unexpected abbrev ordering!");
2854 }
2855 {
2856 auto Abbv = std::make_shared<BitCodeAbbrev>();
2859 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, // dest ty
2860 Log2_32_Ceil(VE.getTypes().size() + 1)));
2863 if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, std::move(Abbv)) !=
2864 (unsigned)FUNCTION_INST_GEP_ABBREV)
2865 assert(false && "Unexpected abbrev ordering!");
2866 }
2867
2868 Stream.ExitBlock();
2869}
2870
2871void DXILBitcodeWriter::writeModuleVersion() {
2872 // VERSION: [version#]
2874}
2875
2876/// WriteModule - Emit the specified module to the bitstream.
2878 // The identification block is new since llvm-3.7, but the old bitcode reader
2879 // will skip it.
2880 // writeIdentificationBlock(Stream);
2881
2883
2884 // It is redundant to fully-specify this here, but nice to make it explicit
2885 // so that it is clear the DXIL module version is different.
2886 DXILBitcodeWriter::writeModuleVersion();
2887
2888 // Emit blockinfo, which defines the standard abbreviations etc.
2889 writeBlockInfo();
2890
2891 // Emit information about attribute groups.
2892 writeAttributeGroupTable();
2893
2894 // Emit information about parameter attributes.
2895 writeAttributeTable();
2896
2897 // Emit information describing all of the types in the module.
2898 writeTypeTable();
2899
2900 writeComdats();
2901
2902 // Emit top-level description of module, including target triple, inline asm,
2903 // descriptors for global variables, and function prototype info.
2904 writeModuleInfo();
2905
2906 // Emit constants.
2907 writeModuleConstants();
2908
2909 // Emit metadata.
2910 writeModuleMetadataKinds();
2911
2912 // Emit metadata.
2913 writeModuleMetadata();
2914
2915 // Emit names for globals/functions etc.
2916 // DXIL uses the same format for module-level value symbol table as for the
2917 // function level table.
2918 writeFunctionLevelValueSymbolTable(M.getValueSymbolTable());
2919
2920 // Emit function bodies.
2921 for (const Function &F : M)
2922 if (!F.isDeclaration())
2923 writeFunction(F);
2924
2925 Stream.ExitBlock();
2926}
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)
std::string Name
uint64_t Size
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
#define G(x, y, z)
Definition: MD5.cpp:56
This file contains the declarations for metadata subclasses.
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.
#define P(N)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
static const uint32_t IV[8]
Definition: blake3_impl.h:78
Class for arbitrary precision integers.
Definition: APInt.h:76
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
Definition: APInt.h:547
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1507
an instruction to allocate memory on the stack
Definition: Instructions.h:58
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Definition: Instructions.h:125
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
Definition: Instructions.h:118
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
Definition: Instructions.h:140
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:160
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Definition: Instructions.h:730
@ Add
*p = old + v
Definition: Instructions.h:734
@ FAdd
*p = old + v
Definition: Instructions.h:755
@ Min
*p = old <signed v ? old : v
Definition: Instructions.h:748
@ Or
*p = old | v
Definition: Instructions.h:742
@ Sub
*p = old - v
Definition: Instructions.h:736
@ And
*p = old & v
Definition: Instructions.h:738
@ Xor
*p = old ^ v
Definition: Instructions.h:744
@ FSub
*p = old - v
Definition: Instructions.h:758
@ Max
*p = old >signed v ? old : v
Definition: Instructions.h:746
@ UMin
*p = old <unsigned v ? old : v
Definition: Instructions.h:752
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
Definition: Instructions.h:766
@ UMax
*p = old >unsigned v ? old : v
Definition: Instructions.h:750
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
Definition: Instructions.h:762
@ Nand
*p = ~(old & v)
Definition: Instructions.h:740
bool hasAttributes() const
Return true if attributes exists in this set.
Definition: Attributes.h:357
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition: Attributes.h:84
@ TombstoneKey
Use as Tombstone key for DenseMap of AttrKind.
Definition: Attributes.h:91
@ None
No attributes have been set.
Definition: Attributes.h:86
@ EmptyKey
Use as Empty key for DenseMap of AttrKind.
Definition: Attributes.h:90
@ EndAttrKinds
Sentinal value useful for loops.
Definition: Attributes.h:89
LLVM Basic Block Representation.
Definition: BasicBlock.h:56
InstListType::const_iterator const_iterator
Definition: BasicBlock.h:88
BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
Definition: BitCodes.h:33
static bool isChar6(char C)
isChar6 - Return true if this character is legal in the Char6 encoding.
Definition: BitCodes.h:82
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.
Definition: Constants.h:874
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...
Definition: InstrTypes.h:1190
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Definition: InstrTypes.h:1412
CallingConv::ID getCallingConv() const
Definition: InstrTypes.h:1470
Value * getCalledOperand() const
Definition: InstrTypes.h:1405
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1357
FunctionType * getFunctionType() const
Definition: InstrTypes.h:1270
unsigned arg_size() const
Definition: InstrTypes.h:1355
AttributeList getAttributes() const
Return the parameter attributes for this call.
Definition: InstrTypes.h:1489
This class represents a function call, abstracting a target machine's calling convention.
bool isTailCall() const
bool isMustTailCall() const
@ Largest
The linker will choose the largest COMDAT.
Definition: Comdat.h:38
@ SameSize
The data referenced by the COMDAT must be the same size.
Definition: Comdat.h:40
@ Any
The linker may choose any COMDAT.
Definition: Comdat.h:36
@ NoDeduplicate
No deduplication is performed.
Definition: Comdat.h:39
@ ExactMatch
The data referenced by the COMDAT must be the same.
Definition: Comdat.h:37
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
Definition: Constants.h:568
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:997
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:260
This is the shared class of boolean and integer constants.
Definition: Constants.h:78
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:136
This is an important base class in LLVM.
Definition: Constant.h:41
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
Assignment ID.
Basic type, like 'int' or 'float'.
Enumeration value.
DWARF expression.
A pair of DIGlobalVariable and DIExpression.
An imported module (C++ using directive or similar).
Debug location.
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
String type, Fortran CHARACTER(n)
Subprogram description.
Array subrange.
Type array for a subprogram.
This class represents an Operation in the Expression.
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:155
iterator end()
Definition: DenseMap.h:84
This instruction extracts a struct member or array element value from an aggregate value.
idx_iterator idx_end() const
idx_iterator idx_begin() const
BasicBlockListType::const_iterator const_iterator
Definition: Function.h:66
Generic tagged DWARF-like metadata node.
Function and variable summary information to aid decisions and implementation of importing.
VisibilityTypes getVisibility() const
Definition: GlobalValue.h:244
LinkageTypes getLinkage() const
Definition: GlobalValue.h:541
ThreadLocalMode getThreadLocalMode() const
Definition: GlobalValue.h:267
@ DLLExportStorageClass
Function to be accessible from DLL.
Definition: GlobalValue.h:72
@ DLLImportStorageClass
Function to be imported from DLL.
Definition: GlobalValue.h:71
@ DefaultVisibility
The GV is visible.
Definition: GlobalValue.h:63
@ HiddenVisibility
The GV is hidden.
Definition: GlobalValue.h:64
@ ProtectedVisibility
The GV is protected.
Definition: GlobalValue.h:65
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:47
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition: GlobalValue.h:56
@ CommonLinkage
Tentative definitions.
Definition: GlobalValue.h:58
@ InternalLinkage
Rename collisions when linking (static functions).
Definition: GlobalValue.h:55
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
Definition: GlobalValue.h:50
@ WeakODRLinkage
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:53
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:48
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
Definition: GlobalValue.h:52
@ AppendingLinkage
Special purpose, only applies to global arrays.
Definition: GlobalValue.h:54
@ AvailableExternallyLinkage
Available for inspection, not emission.
Definition: GlobalValue.h:49
@ ExternalWeakLinkage
ExternalWeak linkage description.
Definition: GlobalValue.h:57
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:51
DLLStorageClassTypes getDLLStorageClass() const
Definition: GlobalValue.h:271
This instruction inserts a struct field of array element value into an aggregate value.
idx_iterator idx_end() const
idx_iterator idx_begin() const
bool isCast() const
Definition: Instruction.h:203
Invoke instruction.
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.
Metadata node.
Definition: Metadata.h:950
A single uniqued string.
Definition: Metadata.h:611
const unsigned char * bytes_begin() const
Definition: Metadata.h:640
const unsigned char * bytes_end() const
Definition: Metadata.h:641
Tuple of metadata.
Definition: Metadata.h:1345
bool doesNotAccessMemory() const
Whether this function accesses no memory.
Definition: ModRef.h:192
bool onlyAccessesArgPointees() const
Whether this function only (at most) accesses argument memory.
Definition: ModRef.h:201
bool onlyReadsMemory() const
Whether this function only (at most) reads memory.
Definition: ModRef.h:195
Root of the metadata hierarchy.
Definition: Metadata.h:61
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
A tuple of MDNodes.
Definition: Metadata.h:1604
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.
bool empty() const
Definition: SmallVector.h:94
size_t size() const
Definition: SmallVector.h:91
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
void reserve(size_type N)
Definition: SmallVector.h:667
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:687
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:809
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
iterator begin() const
Definition: StringRef.h:111
iterator end() const
Definition: StringRef.h:113
Utility for building string tables with deduplicated suffixes.
Class to represent struct types.
Definition: DerivedTypes.h:213
Multiway switch.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
bool isX86_FP80Ty() const
Return true if this is x86 long double.
Definition: Type.h:160
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition: Type.h:154
@ X86_MMXTyID
MMX vectors (64 bits, X86 specific)
Definition: Type.h:66
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
Definition: Type.h:67
@ FunctionTyID
Functions.
Definition: Type.h:72
@ ArrayTyID
Arrays.
Definition: Type.h:75
@ TypedPointerTyID
Typed pointer used by some GPU targets.
Definition: Type.h:78
@ HalfTyID
16-bit floating point type
Definition: Type.h:56
@ TargetExtTyID
Target extension type.
Definition: Type.h:79
@ VoidTyID
type with no size
Definition: Type.h:63
@ ScalableVectorTyID
Scalable SIMD vector type.
Definition: Type.h:77
@ LabelTyID
Labels.
Definition: Type.h:64
@ FloatTyID
32-bit floating point type
Definition: Type.h:58
@ StructTyID
Structures.
Definition: Type.h:74
@ IntegerTyID
Arbitrary bit width integers.
Definition: Type.h:71
@ FixedVectorTyID
Fixed width SIMD vector type.
Definition: Type.h:76
@ BFloatTyID
16-bit floating point type (7-bit significand)
Definition: Type.h:57
@ DoubleTyID
64-bit floating point type
Definition: Type.h:59
@ X86_FP80TyID
80-bit floating point type (X87)
Definition: Type.h:60
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
Definition: Type.h:62
@ MetadataTyID
Metadata.
Definition: Type.h:65
@ TokenTyID
Tokens.
Definition: Type.h:68
@ PointerTyID
Pointers.
Definition: Type.h:73
@ FP128TyID
128-bit floating point type (112-bit significand)
Definition: Type.h:61
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
Definition: Type.h:166
bool isFP128Ty() const
Return true if this is 'fp128'.
Definition: Type.h:163
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
Definition: Type.h:143
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition: Type.h:157
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.
Value wrapper in the Metadata hierarchy.
Definition: Metadata.h:344
Value * getValue() const
Definition: Metadata.h:384
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.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
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)
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.
Definition: raw_ostream.h:611
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
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.
Definition: CallingConv.h:34
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
Definition: PPCPredicates.h:87
@ CE
Windows NT (Windows on ARM)
@ TYPE_CODE_METADATA
Definition: LLVMBitCodes.h:162
@ TYPE_CODE_PPC_FP128
Definition: LLVMBitCodes.h:160
@ TYPE_CODE_STRUCT_ANON
Definition: LLVMBitCodes.h:166
@ TYPE_CODE_STRUCT_NAME
Definition: LLVMBitCodes.h:167
@ TYPE_CODE_X86_FP80
Definition: LLVMBitCodes.h:158
@ TYPE_CODE_FUNCTION
Definition: LLVMBitCodes.h:170
@ TYPE_CODE_NUMENTRY
Definition: LLVMBitCodes.h:136
@ TYPE_CODE_STRUCT_NAMED
Definition: LLVMBitCodes.h:168
@ METADATA_NAMESPACE
Definition: LLVMBitCodes.h:348
@ METADATA_TEMPLATE_VALUE
Definition: LLVMBitCodes.h:350
@ METADATA_LEXICAL_BLOCK_FILE
Definition: LLVMBitCodes.h:347
@ METADATA_STRING_OLD
Definition: LLVMBitCodes.h:325
@ METADATA_LEXICAL_BLOCK
Definition: LLVMBitCodes.h:346
@ METADATA_SUBPROGRAM
Definition: LLVMBitCodes.h:345
@ METADATA_SUBROUTINE_TYPE
Definition: LLVMBitCodes.h:343
@ METADATA_LOCAL_VAR
Definition: LLVMBitCodes.h:352
@ METADATA_GLOBAL_VAR
Definition: LLVMBitCodes.h:351
@ METADATA_EXPRESSION
Definition: LLVMBitCodes.h:353
@ METADATA_ATTACHMENT
Definition: LLVMBitCodes.h:335
@ METADATA_NAMED_NODE
Definition: LLVMBitCodes.h:334
@ METADATA_IMPORTED_ENTITY
Definition: LLVMBitCodes.h:355
@ METADATA_COMPILE_UNIT
Definition: LLVMBitCodes.h:344
@ METADATA_COMPOSITE_TYPE
Definition: LLVMBitCodes.h:342
@ METADATA_ENUMERATOR
Definition: LLVMBitCodes.h:338
@ METADATA_DERIVED_TYPE
Definition: LLVMBitCodes.h:341
@ METADATA_TEMPLATE_TYPE
Definition: LLVMBitCodes.h:349
@ METADATA_BASIC_TYPE
Definition: LLVMBitCodes.h:339
@ METADATA_DISTINCT_NODE
Definition: LLVMBitCodes.h:329
@ METADATA_GENERIC_DEBUG
Definition: LLVMBitCodes.h:336
@ CST_CODE_CE_INBOUNDS_GEP
Definition: LLVMBitCodes.h:397
@ CST_CODE_BLOCKADDRESS
Definition: LLVMBitCodes.h:398
@ CST_CODE_CE_SHUFVEC_EX
Definition: LLVMBitCodes.h:396
@ CST_CODE_CE_EXTRACTELT
Definition: LLVMBitCodes.h:390
@ CST_CODE_CE_SHUFFLEVEC
Definition: LLVMBitCodes.h:392
@ CST_CODE_WIDE_INTEGER
Definition: LLVMBitCodes.h:381
@ CST_CODE_AGGREGATE
Definition: LLVMBitCodes.h:383
@ CST_CODE_CE_SELECT
Definition: LLVMBitCodes.h:389
@ CST_CODE_CE_INSERTELT
Definition: LLVMBitCodes.h:391
@ CST_CODE_INLINEASM
Definition: LLVMBitCodes.h:410
@ COMDAT_SELECTION_KIND_LARGEST
Definition: LLVMBitCodes.h:721
@ COMDAT_SELECTION_KIND_ANY
Definition: LLVMBitCodes.h:719
@ COMDAT_SELECTION_KIND_SAME_SIZE
Definition: LLVMBitCodes.h:723
@ COMDAT_SELECTION_KIND_EXACT_MATCH
Definition: LLVMBitCodes.h:720
@ COMDAT_SELECTION_KIND_NO_DUPLICATES
Definition: LLVMBitCodes.h:722
@ ATTR_KIND_STACK_PROTECT
Definition: LLVMBitCodes.h:654
@ ATTR_KIND_NO_UNWIND
Definition: LLVMBitCodes.h:646
@ ATTR_KIND_STACK_PROTECT_STRONG
Definition: LLVMBitCodes.h:656
@ ATTR_KIND_SANITIZE_MEMORY
Definition: LLVMBitCodes.h:660
@ ATTR_KIND_SAFESTACK
Definition: LLVMBitCodes.h:672
@ ATTR_KIND_OPTIMIZE_FOR_SIZE
Definition: LLVMBitCodes.h:647
@ ATTR_KIND_STRUCT_RET
Definition: LLVMBitCodes.h:657
@ ATTR_KIND_MIN_SIZE
Definition: LLVMBitCodes.h:634
@ ATTR_KIND_NO_CAPTURE
Definition: LLVMBitCodes.h:639
@ ATTR_KIND_SANITIZE_ADDRESS
Definition: LLVMBitCodes.h:658
@ ATTR_KIND_NO_IMPLICIT_FLOAT
Definition: LLVMBitCodes.h:641
@ ATTR_KIND_NO_BUILTIN
Definition: LLVMBitCodes.h:638
@ ATTR_KIND_CONVERGENT
Definition: LLVMBitCodes.h:671
@ ATTR_KIND_RETURNED
Definition: LLVMBitCodes.h:650
@ ATTR_KIND_STACK_ALIGNMENT
Definition: LLVMBitCodes.h:653
@ ATTR_KIND_STACK_PROTECT_REQ
Definition: LLVMBitCodes.h:655
@ ATTR_KIND_INLINE_HINT
Definition: LLVMBitCodes.h:632
@ ATTR_KIND_NON_NULL
Definition: LLVMBitCodes.h:667
@ ATTR_KIND_NO_RETURN
Definition: LLVMBitCodes.h:645
@ ATTR_KIND_RETURNS_TWICE
Definition: LLVMBitCodes.h:651
@ ATTR_KIND_ARGMEMONLY
Definition: LLVMBitCodes.h:673
@ ATTR_KIND_NO_DUPLICATE
Definition: LLVMBitCodes.h:640
@ ATTR_KIND_NON_LAZY_BIND
Definition: LLVMBitCodes.h:643
@ ATTR_KIND_DEREFERENCEABLE
Definition: LLVMBitCodes.h:669
@ ATTR_KIND_READ_NONE
Definition: LLVMBitCodes.h:648
@ ATTR_KIND_UW_TABLE
Definition: LLVMBitCodes.h:661
@ ATTR_KIND_OPTIMIZE_NONE
Definition: LLVMBitCodes.h:665
@ ATTR_KIND_NO_RED_ZONE
Definition: LLVMBitCodes.h:644
@ ATTR_KIND_DEREFERENCEABLE_OR_NULL
Definition: LLVMBitCodes.h:670
@ ATTR_KIND_IN_ALLOCA
Definition: LLVMBitCodes.h:666
@ ATTR_KIND_READ_ONLY
Definition: LLVMBitCodes.h:649
@ ATTR_KIND_ALIGNMENT
Definition: LLVMBitCodes.h:629
@ ATTR_KIND_ALWAYS_INLINE
Definition: LLVMBitCodes.h:630
@ ATTR_KIND_NO_ALIAS
Definition: LLVMBitCodes.h:637
@ ATTR_KIND_JUMP_TABLE
Definition: LLVMBitCodes.h:668
@ ATTR_KIND_NO_INLINE
Definition: LLVMBitCodes.h:642
@ ATTR_KIND_SANITIZE_THREAD
Definition: LLVMBitCodes.h:659
@ OBO_NO_SIGNED_WRAP
Definition: LLVMBitCodes.h:491
@ OBO_NO_UNSIGNED_WRAP
Definition: LLVMBitCodes.h:490
@ PARAMATTR_BLOCK_ID
Definition: LLVMBitCodes.h:33
@ TYPE_BLOCK_ID_NEW
Definition: LLVMBitCodes.h:48
@ CONSTANTS_BLOCK_ID
Definition: LLVMBitCodes.h:36
@ PARAMATTR_GROUP_BLOCK_ID
Definition: LLVMBitCodes.h:34
@ METADATA_ATTACHMENT_ID
Definition: LLVMBitCodes.h:46
@ METADATA_BLOCK_ID
Definition: LLVMBitCodes.h:45
@ FUNCTION_BLOCK_ID
Definition: LLVMBitCodes.h:37
@ VALUE_SYMTAB_BLOCK_ID
Definition: LLVMBitCodes.h:44
@ CAST_ADDRSPACECAST
Definition: LLVMBitCodes.h:433
@ MODULE_CODE_FUNCTION
Definition: LLVMBitCodes.h:100
@ MODULE_CODE_VERSION
Definition: LLVMBitCodes.h:85
@ MODULE_CODE_SECTIONNAME
Definition: LLVMBitCodes.h:89
@ MODULE_CODE_TRIPLE
Definition: LLVMBitCodes.h:86
@ MODULE_CODE_DATALAYOUT
Definition: LLVMBitCodes.h:87
@ MODULE_CODE_GLOBALVAR
Definition: LLVMBitCodes.h:96
@ MODULE_CODE_ALIAS_OLD
Definition: LLVMBitCodes.h:103
@ MODULE_CODE_GCNAME
Definition: LLVMBitCodes.h:105
@ MODULE_CODE_COMDAT
Definition: LLVMBitCodes.h:106
@ FUNC_CODE_INST_LANDINGPAD
Definition: LLVMBitCodes.h:602
@ FUNC_CODE_INST_EXTRACTVAL
Definition: LLVMBitCodes.h:567
@ FUNC_CODE_INST_RESUME
Definition: LLVMBitCodes.h:589
@ FUNC_CODE_INST_CMP2
Definition: LLVMBitCodes.h:571
@ FUNC_CODE_INST_FENCE
Definition: LLVMBitCodes.h:582
@ FUNC_CODE_INST_VSELECT
Definition: LLVMBitCodes.h:573
@ FUNC_CODE_INST_GEP
Definition: LLVMBitCodes.h:596
@ FUNC_CODE_INST_LOADATOMIC
Definition: LLVMBitCodes.h:592
@ FUNC_CODE_INST_LOAD
Definition: LLVMBitCodes.h:558
@ FUNC_CODE_INST_STOREATOMIC
Definition: LLVMBitCodes.h:598
@ FUNC_CODE_INST_ATOMICRMW
Definition: LLVMBitCodes.h:616
@ FUNC_CODE_INST_BINOP
Definition: LLVMBitCodes.h:538
@ FUNC_CODE_INST_STORE
Definition: LLVMBitCodes.h:597
@ FUNC_CODE_DEBUG_LOC_AGAIN
Definition: LLVMBitCodes.h:577
@ FUNC_CODE_INST_EXTRACTELT
Definition: LLVMBitCodes.h:542
@ FUNC_CODE_INST_INDIRECTBR
Definition: LLVMBitCodes.h:575
@ FUNC_CODE_INST_INVOKE
Definition: LLVMBitCodes.h:550
@ FUNC_CODE_INST_INSERTVAL
Definition: LLVMBitCodes.h:568
@ FUNC_CODE_DECLAREBLOCKS
Definition: LLVMBitCodes.h:536
@ FUNC_CODE_INST_SWITCH
Definition: LLVMBitCodes.h:549
@ FUNC_CODE_INST_PHI
Definition: LLVMBitCodes.h:554
@ FUNC_CODE_INST_RET
Definition: LLVMBitCodes.h:547
@ FUNC_CODE_INST_CALL
Definition: LLVMBitCodes.h:579
@ FUNC_CODE_INST_ALLOCA
Definition: LLVMBitCodes.h:557
@ FUNC_CODE_INST_INSERTELT
Definition: LLVMBitCodes.h:543
@ FUNC_CODE_INST_SHUFFLEVEC
Definition: LLVMBitCodes.h:544
@ FUNC_CODE_INST_VAARG
Definition: LLVMBitCodes.h:561
@ FUNC_CODE_INST_CMPXCHG
Definition: LLVMBitCodes.h:599
@ FUNC_CODE_INST_UNREACHABLE
Definition: LLVMBitCodes.h:552
@ FUNC_CODE_INST_CAST
Definition: LLVMBitCodes.h:539
@ FUNC_CODE_DEBUG_LOC
Definition: LLVMBitCodes.h:581
@ FIRST_APPLICATION_ABBREV
Definition: BitCodeEnums.h:60
@ PARAMATTR_GRP_CODE_ENTRY
Definition: LLVMBitCodes.h:131
@ PARAMATTR_CODE_ENTRY
Definition: LLVMBitCodes.h:130
@ ORDERING_NOTATOMIC
Definition: LLVMBitCodes.h:514
@ ORDERING_UNORDERED
Definition: LLVMBitCodes.h:515
@ ORDERING_MONOTONIC
Definition: LLVMBitCodes.h:516
void WriteDXILToFile(const Module &M, raw_ostream &Out)
Write the specified module to the specified raw output stream.
constexpr double e
Definition: MathExtras.h:31
NodeAddr< CodeNode * > Code
Definition: RDFGraph.h:388
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
Definition: MathExtras.h:326
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
Definition: Alignment.h:217
AddressSpace
Definition: NVPTXBaseInfo.h:21
bool getAlign(const Function &F, unsigned index, unsigned &align)
@ BWH_HeaderSize
Definition: BitCodeEnums.h:32
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition: MathExtras.h:313
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1652
AtomicOrdering
Atomic ordering for LLVM's memory model.
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition: Alignment.h:208
#define N
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition: Alignment.h:85
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117
ValID - Represents a reference of a definition of some sort with no type.
Definition: LLParser.h:52
Struct that holds a reference to a particular GUID in a global value summary.