LLVM  15.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"
15 #include "PointerTypeAnalysis.h"
16 #include "llvm/ADT/Triple.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"
29 #include "llvm/IR/DerivedTypes.h"
30 #include "llvm/IR/Function.h"
31 #include "llvm/IR/GlobalAlias.h"
32 #include "llvm/IR/GlobalIFunc.h"
33 #include "llvm/IR/GlobalObject.h"
34 #include "llvm/IR/GlobalValue.h"
35 #include "llvm/IR/GlobalVariable.h"
36 #include "llvm/IR/InlineAsm.h"
37 #include "llvm/IR/InstrTypes.h"
38 #include "llvm/IR/Instruction.h"
39 #include "llvm/IR/Instructions.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"
46 #include "llvm/IR/UseListOrder.h"
47 #include "llvm/IR/Value.h"
49 #include "llvm/Object/IRSymtab.h"
51 #include "llvm/Support/SHA1.h"
52 
53 namespace llvm {
54 namespace dxil {
55 
56 // Generates an enum to use as an index in the Abbrev array of Metadata record.
57 enum MetadataAbbrev : unsigned {
58 #define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
59 #include "llvm/IR/Metadata.def"
61 };
62 
64 
65  /// These are manifest constants used by the bitcode writer. They do not need
66  /// to be kept in sync with the reader, but need to be consistent within this
67  /// file.
68  enum {
69  // VALUE_SYMTAB_BLOCK abbrev id's.
70  VST_ENTRY_8_ABBREV = bitc::FIRST_APPLICATION_ABBREV,
71  VST_ENTRY_7_ABBREV,
72  VST_ENTRY_6_ABBREV,
73  VST_BBENTRY_6_ABBREV,
74 
75  // CONSTANTS_BLOCK abbrev id's.
76  CONSTANTS_SETTYPE_ABBREV = bitc::FIRST_APPLICATION_ABBREV,
77  CONSTANTS_INTEGER_ABBREV,
78  CONSTANTS_CE_CAST_Abbrev,
79  CONSTANTS_NULL_Abbrev,
80 
81  // FUNCTION_BLOCK abbrev id's.
82  FUNCTION_INST_LOAD_ABBREV = bitc::FIRST_APPLICATION_ABBREV,
83  FUNCTION_INST_BINOP_ABBREV,
84  FUNCTION_INST_BINOP_FLAGS_ABBREV,
85  FUNCTION_INST_CAST_ABBREV,
86  FUNCTION_INST_RET_VOID_ABBREV,
87  FUNCTION_INST_RET_VAL_ABBREV,
88  FUNCTION_INST_UNREACHABLE_ABBREV,
89  FUNCTION_INST_GEP_ABBREV,
90  };
91 
92  // Cache some types
93  Type *I8Ty;
94  Type *I8PtrTy;
95 
96  /// The stream created and owned by the client.
97  BitstreamWriter &Stream;
98 
99  StringTableBuilder &StrtabBuilder;
100 
101  /// The Module to write to bitcode.
102  const Module &M;
103 
104  /// Enumerates ids for all values in the module.
105  ValueEnumerator VE;
106 
107  /// Map that holds the correspondence between GUIDs in the summary index,
108  /// that came from indirect call profiles, and a value id generated by this
109  /// class to use in the VST and summary block records.
110  std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
111 
112  /// Tracks the last value id recorded in the GUIDToValueMap.
113  unsigned GlobalValueId;
114 
115  /// Saves the offset of the VSTOffset record that must eventually be
116  /// backpatched with the offset of the actual VST.
117  uint64_t VSTOffsetPlaceholder = 0;
118 
119  /// Pointer to the buffer allocated by caller for bitcode writing.
120  const SmallVectorImpl<char> &Buffer;
121 
122  /// The start bit of the identification block.
123  uint64_t BitcodeStartBit;
124 
125  /// This maps values to their typed pointers
126  PointerTypeMap PointerMap;
127 
128 public:
129  /// Constructs a ModuleBitcodeWriter object for the given Module,
130  /// writing to the provided \p Buffer.
132  StringTableBuilder &StrtabBuilder, BitstreamWriter &Stream)
133  : I8Ty(Type::getInt8Ty(M.getContext())),
134  I8PtrTy(TypedPointerType::get(I8Ty, 0)), Stream(Stream),
135  StrtabBuilder(StrtabBuilder), M(M), VE(M, I8PtrTy), Buffer(Buffer),
136  BitcodeStartBit(Stream.GetCurrentBitNo()),
137  PointerMap(PointerTypeAnalysis::run(M)) {
138  GlobalValueId = VE.getValues().size();
139  // Enumerate the typed pointers
140  for (auto El : PointerMap)
141  VE.EnumerateType(El.second);
142  }
143 
144  /// Emit the current module to the bitstream.
145  void write();
146 
148  static void writeStringRecord(BitstreamWriter &Stream, unsigned Code,
149  StringRef Str, unsigned AbbrevToUse);
150  static void writeIdentificationBlock(BitstreamWriter &Stream);
151  static void emitSignedInt64(SmallVectorImpl<uint64_t> &Vals, uint64_t V);
152  static void emitWideAPInt(SmallVectorImpl<uint64_t> &Vals, const APInt &A);
153 
154  static unsigned getEncodedComdatSelectionKind(const Comdat &C);
155  static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage);
156  static unsigned getEncodedLinkage(const GlobalValue &GV);
157  static unsigned getEncodedVisibility(const GlobalValue &GV);
158  static unsigned getEncodedThreadLocalMode(const GlobalValue &GV);
159  static unsigned getEncodedDLLStorageClass(const GlobalValue &GV);
160  static unsigned getEncodedCastOpcode(unsigned Opcode);
161  static unsigned getEncodedUnaryOpcode(unsigned Opcode);
162  static unsigned getEncodedBinaryOpcode(unsigned Opcode);
164  static unsigned getEncodedOrdering(AtomicOrdering Ordering);
165  static uint64_t getOptimizationFlags(const Value *V);
166 
167 private:
168  void writeModuleVersion();
169  void writePerModuleGlobalValueSummary();
170 
171  void writePerModuleFunctionSummaryRecord(SmallVector<uint64_t, 64> &NameVals,
172  GlobalValueSummary *Summary,
173  unsigned ValueID,
174  unsigned FSCallsAbbrev,
175  unsigned FSCallsProfileAbbrev,
176  const Function &F);
177  void writeModuleLevelReferences(const GlobalVariable &V,
178  SmallVector<uint64_t, 64> &NameVals,
179  unsigned FSModRefsAbbrev,
180  unsigned FSModVTableRefsAbbrev);
181 
182  void assignValueId(GlobalValue::GUID ValGUID) {
183  GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
184  }
185 
186  unsigned getValueId(GlobalValue::GUID ValGUID) {
187  const auto &VMI = GUIDToValueIdMap.find(ValGUID);
188  // Expect that any GUID value had a value Id assigned by an
189  // earlier call to assignValueId.
190  assert(VMI != GUIDToValueIdMap.end() &&
191  "GUID does not have assigned value Id");
192  return VMI->second;
193  }
194 
195  // Helper to get the valueId for the type of value recorded in VI.
196  unsigned getValueId(ValueInfo VI) {
197  if (!VI.haveGVs() || !VI.getValue())
198  return getValueId(VI.getGUID());
199  return VE.getValueID(VI.getValue());
200  }
201 
202  std::map<GlobalValue::GUID, unsigned> &valueIds() { return GUIDToValueIdMap; }
203 
204  uint64_t bitcodeStartBit() { return BitcodeStartBit; }
205 
206  size_t addToStrtab(StringRef Str);
207 
208  unsigned createDILocationAbbrev();
209  unsigned createGenericDINodeAbbrev();
210 
211  void writeAttributeGroupTable();
212  void writeAttributeTable();
213  void writeTypeTable();
214  void writeComdats();
215  void writeValueSymbolTableForwardDecl();
216  void writeModuleInfo();
217  void writeValueAsMetadata(const ValueAsMetadata *MD,
219  void writeMDTuple(const MDTuple *N, SmallVectorImpl<uint64_t> &Record,
220  unsigned Abbrev);
221  void writeDILocation(const DILocation *N, SmallVectorImpl<uint64_t> &Record,
222  unsigned &Abbrev);
223  void writeGenericDINode(const GenericDINode *N,
224  SmallVectorImpl<uint64_t> &Record, unsigned &Abbrev) {
225  llvm_unreachable("DXIL cannot contain GenericDI Nodes");
226  }
227  void writeDISubrange(const DISubrange *N, SmallVectorImpl<uint64_t> &Record,
228  unsigned Abbrev);
229  void writeDIGenericSubrange(const DIGenericSubrange *N,
231  unsigned Abbrev) {
232  llvm_unreachable("DXIL cannot contain DIGenericSubrange Nodes");
233  }
234  void writeDIEnumerator(const DIEnumerator *N,
235  SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
236  void writeDIBasicType(const DIBasicType *N, SmallVectorImpl<uint64_t> &Record,
237  unsigned Abbrev);
238  void writeDIStringType(const DIStringType *N,
239  SmallVectorImpl<uint64_t> &Record, unsigned Abbrev) {
240  llvm_unreachable("DXIL cannot contain DIStringType Nodes");
241  }
242  void writeDIDerivedType(const DIDerivedType *N,
243  SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
244  void writeDICompositeType(const DICompositeType *N,
245  SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
246  void writeDISubroutineType(const DISubroutineType *N,
248  unsigned Abbrev);
249  void writeDIFile(const DIFile *N, SmallVectorImpl<uint64_t> &Record,
250  unsigned Abbrev);
251  void writeDICompileUnit(const DICompileUnit *N,
252  SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
253  void writeDISubprogram(const DISubprogram *N,
254  SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
255  void writeDILexicalBlock(const DILexicalBlock *N,
256  SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
257  void writeDILexicalBlockFile(const DILexicalBlockFile *N,
259  unsigned Abbrev);
260  void writeDICommonBlock(const DICommonBlock *N,
261  SmallVectorImpl<uint64_t> &Record, unsigned Abbrev) {
262  llvm_unreachable("DXIL cannot contain DICommonBlock Nodes");
263  }
264  void writeDINamespace(const DINamespace *N, SmallVectorImpl<uint64_t> &Record,
265  unsigned Abbrev);
266  void writeDIMacro(const DIMacro *N, SmallVectorImpl<uint64_t> &Record,
267  unsigned Abbrev) {
268  llvm_unreachable("DXIL cannot contain DIMacro Nodes");
269  }
270  void writeDIMacroFile(const DIMacroFile *N, SmallVectorImpl<uint64_t> &Record,
271  unsigned Abbrev) {
272  llvm_unreachable("DXIL cannot contain DIMacroFile Nodes");
273  }
274  void writeDIArgList(const DIArgList *N, SmallVectorImpl<uint64_t> &Record,
275  unsigned Abbrev) {
276  llvm_unreachable("DXIL cannot contain DIArgList Nodes");
277  }
278  void writeDIModule(const DIModule *N, SmallVectorImpl<uint64_t> &Record,
279  unsigned Abbrev);
280  void writeDITemplateTypeParameter(const DITemplateTypeParameter *N,
282  unsigned Abbrev);
283  void writeDITemplateValueParameter(const DITemplateValueParameter *N,
285  unsigned Abbrev);
286  void writeDIGlobalVariable(const DIGlobalVariable *N,
288  unsigned Abbrev);
289  void writeDILocalVariable(const DILocalVariable *N,
290  SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
291  void writeDILabel(const DILabel *N, SmallVectorImpl<uint64_t> &Record,
292  unsigned Abbrev) {
293  llvm_unreachable("DXIL cannot contain DILabel Nodes");
294  }
295  void writeDIExpression(const DIExpression *N,
296  SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
297  void writeDIGlobalVariableExpression(const DIGlobalVariableExpression *N,
299  unsigned Abbrev) {
300  llvm_unreachable("DXIL cannot contain GlobalVariableExpression Nodes");
301  }
302  void writeDIObjCProperty(const DIObjCProperty *N,
303  SmallVectorImpl<uint64_t> &Record, unsigned Abbrev);
304  void writeDIImportedEntity(const DIImportedEntity *N,
306  unsigned Abbrev);
307  unsigned createNamedMetadataAbbrev();
308  void writeNamedMetadata(SmallVectorImpl<uint64_t> &Record);
309  unsigned createMetadataStringsAbbrev();
310  void writeMetadataStrings(ArrayRef<const Metadata *> Strings,
312  void writeMetadataRecords(ArrayRef<const Metadata *> MDs,
314  std::vector<unsigned> *MDAbbrevs = nullptr,
315  std::vector<uint64_t> *IndexPos = nullptr);
316  void writeModuleMetadata();
317  void writeFunctionMetadata(const Function &F);
318  void writeFunctionMetadataAttachment(const Function &F);
319  void pushGlobalMetadataAttachment(SmallVectorImpl<uint64_t> &Record,
320  const GlobalObject &GO);
321  void writeModuleMetadataKinds();
322  void writeOperandBundleTags();
323  void writeSyncScopeNames();
324  void writeConstants(unsigned FirstVal, unsigned LastVal, bool isGlobal);
325  void writeModuleConstants();
326  bool pushValueAndType(const Value *V, unsigned InstID,
328  void writeOperandBundles(const CallBase &CB, unsigned InstID);
329  void pushValue(const Value *V, unsigned InstID,
331  void pushValueSigned(const Value *V, unsigned InstID,
333  void writeInstruction(const Instruction &I, unsigned InstID,
335  void writeFunctionLevelValueSymbolTable(const ValueSymbolTable &VST);
336  void writeGlobalValueSymbolTable(
337  DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
338  void writeUseList(UseListOrder &&Order);
339  void writeUseListBlock(const Function *F);
340  void writeFunction(const Function &F);
341  void writeBlockInfo();
342 
343  unsigned getEncodedSyncScopeID(SyncScope::ID SSID) { return unsigned(SSID); }
344 
345  unsigned getEncodedAlign(MaybeAlign Alignment) { return encode(Alignment); }
346 
347  unsigned getTypeID(Type *T, const Value *V = nullptr);
348  unsigned getTypeID(Type *T, const Function *F);
349 };
350 
351 } // namespace dxil
352 } // namespace llvm
353 
354 using namespace llvm;
355 using namespace llvm::dxil;
356 
357 ////////////////////////////////////////////////////////////////////////////////
358 /// Begin dxil::BitcodeWriter Implementation
359 ////////////////////////////////////////////////////////////////////////////////
360 
362  raw_fd_stream *FS)
363  : Buffer(Buffer), Stream(new BitstreamWriter(Buffer, FS, 512)) {
364  // Emit the file header.
365  Stream->Emit((unsigned)'B', 8);
366  Stream->Emit((unsigned)'C', 8);
367  Stream->Emit(0x0, 4);
368  Stream->Emit(0xC, 4);
369  Stream->Emit(0xE, 4);
370  Stream->Emit(0xD, 4);
371 }
372 
374 
375 /// Write the specified module to the specified output stream.
377  SmallVector<char, 0> Buffer;
378  Buffer.reserve(256 * 1024);
379 
380  // If this is darwin or another generic macho target, reserve space for the
381  // header.
382  Triple TT(M.getTargetTriple());
383  if (TT.isOSDarwin() || TT.isOSBinFormatMachO())
384  Buffer.insert(Buffer.begin(), BWH_HeaderSize, 0);
385 
386  BitcodeWriter Writer(Buffer, dyn_cast<raw_fd_stream>(&Out));
387  Writer.writeModule(M);
388  Writer.writeSymtab();
389  Writer.writeStrtab();
390 
391  // Write the generated bitstream to "Out".
392  if (!Buffer.empty())
393  Out.write((char *)&Buffer.front(), Buffer.size());
394 }
395 
396 void BitcodeWriter::writeBlob(unsigned Block, unsigned Record, StringRef Blob) {
397  Stream->EnterSubblock(Block, 3);
398 
399  auto Abbv = std::make_shared<BitCodeAbbrev>();
400  Abbv->Add(BitCodeAbbrevOp(Record));
402  auto AbbrevNo = Stream->EmitAbbrev(std::move(Abbv));
403 
404  Stream->EmitRecordWithBlob(AbbrevNo, ArrayRef<uint64_t>{Record}, Blob);
405 
406  Stream->ExitBlock();
407 }
408 
410  assert(!WroteStrtab && !WroteSymtab);
411 
412  // If any module has module-level inline asm, we will require a registered asm
413  // parser for the target so that we can create an accurate symbol table for
414  // the module.
415  for (Module *M : Mods) {
416  if (M->getModuleInlineAsm().empty())
417  continue;
418  }
419 
420  WroteSymtab = true;
421  SmallVector<char, 0> Symtab;
422  // The irsymtab::build function may be unable to create a symbol table if the
423  // module is malformed (e.g. it contains an invalid alias). Writing a symbol
424  // table is not required for correctness, but we still want to be able to
425  // write malformed modules to bitcode files, so swallow the error.
426  if (Error E = irsymtab::build(Mods, Symtab, StrtabBuilder, Alloc)) {
428  return;
429  }
430 
432  {Symtab.data(), Symtab.size()});
433 }
434 
436  assert(!WroteStrtab);
437 
438  std::vector<char> Strtab;
439  StrtabBuilder.finalizeInOrder();
440  Strtab.resize(StrtabBuilder.getSize());
441  StrtabBuilder.write((uint8_t *)Strtab.data());
442 
444  {Strtab.data(), Strtab.size()});
445 
446  WroteStrtab = true;
447 }
448 
450  writeBlob(bitc::STRTAB_BLOCK_ID, bitc::STRTAB_BLOB, Strtab);
451  WroteStrtab = true;
452 }
453 
455  assert(!WroteStrtab);
456 
457  // The Mods vector is used by irsymtab::build, which requires non-const
458  // Modules in case it needs to materialize metadata. But the bitcode writer
459  // requires that the module is materialized, so we can cast to non-const here,
460  // after checking that it is in fact materialized.
461  assert(M.isMaterialized());
462  Mods.push_back(const_cast<Module *>(&M));
463 
464  DXILBitcodeWriter ModuleWriter(M, Buffer, StrtabBuilder, *Stream);
465  ModuleWriter.write();
466 }
467 
468 ////////////////////////////////////////////////////////////////////////////////
469 /// Begin dxil::BitcodeWriterBase Implementation
470 ////////////////////////////////////////////////////////////////////////////////
471 
472 unsigned DXILBitcodeWriter::getEncodedCastOpcode(unsigned Opcode) {
473  switch (Opcode) {
474  default:
475  llvm_unreachable("Unknown cast instruction!");
476  case Instruction::Trunc:
477  return bitc::CAST_TRUNC;
478  case Instruction::ZExt:
479  return bitc::CAST_ZEXT;
480  case Instruction::SExt:
481  return bitc::CAST_SEXT;
482  case Instruction::FPToUI:
483  return bitc::CAST_FPTOUI;
484  case Instruction::FPToSI:
485  return bitc::CAST_FPTOSI;
486  case Instruction::UIToFP:
487  return bitc::CAST_UITOFP;
488  case Instruction::SIToFP:
489  return bitc::CAST_SITOFP;
490  case Instruction::FPTrunc:
491  return bitc::CAST_FPTRUNC;
492  case Instruction::FPExt:
493  return bitc::CAST_FPEXT;
494  case Instruction::PtrToInt:
495  return bitc::CAST_PTRTOINT;
496  case Instruction::IntToPtr:
497  return bitc::CAST_INTTOPTR;
498  case Instruction::BitCast:
499  return bitc::CAST_BITCAST;
500  case Instruction::AddrSpaceCast:
502  }
503 }
504 
505 unsigned DXILBitcodeWriter::getEncodedUnaryOpcode(unsigned Opcode) {
506  switch (Opcode) {
507  default:
508  llvm_unreachable("Unknown binary instruction!");
509  case Instruction::FNeg:
510  return bitc::UNOP_FNEG;
511  }
512 }
513 
514 unsigned DXILBitcodeWriter::getEncodedBinaryOpcode(unsigned Opcode) {
515  switch (Opcode) {
516  default:
517  llvm_unreachable("Unknown binary instruction!");
518  case Instruction::Add:
519  case Instruction::FAdd:
520  return bitc::BINOP_ADD;
521  case Instruction::Sub:
522  case Instruction::FSub:
523  return bitc::BINOP_SUB;
524  case Instruction::Mul:
525  case Instruction::FMul:
526  return bitc::BINOP_MUL;
527  case Instruction::UDiv:
528  return bitc::BINOP_UDIV;
529  case Instruction::FDiv:
530  case Instruction::SDiv:
531  return bitc::BINOP_SDIV;
532  case Instruction::URem:
533  return bitc::BINOP_UREM;
534  case Instruction::FRem:
535  case Instruction::SRem:
536  return bitc::BINOP_SREM;
537  case Instruction::Shl:
538  return bitc::BINOP_SHL;
539  case Instruction::LShr:
540  return bitc::BINOP_LSHR;
541  case Instruction::AShr:
542  return bitc::BINOP_ASHR;
543  case Instruction::And:
544  return bitc::BINOP_AND;
545  case Instruction::Or:
546  return bitc::BINOP_OR;
547  case Instruction::Xor:
548  return bitc::BINOP_XOR;
549  }
550 }
551 
552 unsigned DXILBitcodeWriter::getTypeID(Type *T, const Value *V) {
553  if (!T->isOpaquePointerTy())
554  return VE.getTypeID(T);
555  auto It = PointerMap.find(V);
556  if (It != PointerMap.end())
557  return VE.getTypeID(It->second);
558  return VE.getTypeID(I8PtrTy);
559 }
560 
561 unsigned DXILBitcodeWriter::getTypeID(Type *T, const Function *F) {
562  auto It = PointerMap.find(F);
563  if (It != PointerMap.end())
564  return VE.getTypeID(It->second);
565  return VE.getTypeID(T);
566 }
567 
569  switch (Op) {
570  default:
571  llvm_unreachable("Unknown RMW operation!");
572  case AtomicRMWInst::Xchg:
573  return bitc::RMW_XCHG;
574  case AtomicRMWInst::Add:
575  return bitc::RMW_ADD;
576  case AtomicRMWInst::Sub:
577  return bitc::RMW_SUB;
578  case AtomicRMWInst::And:
579  return bitc::RMW_AND;
580  case AtomicRMWInst::Nand:
581  return bitc::RMW_NAND;
582  case AtomicRMWInst::Or:
583  return bitc::RMW_OR;
584  case AtomicRMWInst::Xor:
585  return bitc::RMW_XOR;
586  case AtomicRMWInst::Max:
587  return bitc::RMW_MAX;
588  case AtomicRMWInst::Min:
589  return bitc::RMW_MIN;
590  case AtomicRMWInst::UMax:
591  return bitc::RMW_UMAX;
592  case AtomicRMWInst::UMin:
593  return bitc::RMW_UMIN;
594  case AtomicRMWInst::FAdd:
595  return bitc::RMW_FADD;
596  case AtomicRMWInst::FSub:
597  return bitc::RMW_FSUB;
598  }
599 }
600 
602  switch (Ordering) {
610  return bitc::ORDERING_ACQUIRE;
612  return bitc::ORDERING_RELEASE;
614  return bitc::ORDERING_ACQREL;
616  return bitc::ORDERING_SEQCST;
617  }
618  llvm_unreachable("Invalid ordering");
619 }
620 
622  unsigned Code, StringRef Str,
623  unsigned AbbrevToUse) {
625 
626  // Code: [strchar x N]
627  for (char C : Str) {
628  if (AbbrevToUse && !BitCodeAbbrevOp::isChar6(C))
629  AbbrevToUse = 0;
630  Vals.push_back(C);
631  }
632 
633  // Emit the finished record.
634  Stream.EmitRecord(Code, Vals, AbbrevToUse);
635 }
636 
638  switch (Kind) {
639  case Attribute::Alignment:
641  case Attribute::AlwaysInline:
643  case Attribute::ArgMemOnly:
645  case Attribute::Builtin:
647  case Attribute::ByVal:
648  return bitc::ATTR_KIND_BY_VAL;
651  case Attribute::InAlloca:
653  case Attribute::Cold:
654  return bitc::ATTR_KIND_COLD;
655  case Attribute::InlineHint:
657  case Attribute::InReg:
658  return bitc::ATTR_KIND_IN_REG;
661  case Attribute::MinSize:
663  case Attribute::Naked:
664  return bitc::ATTR_KIND_NAKED;
665  case Attribute::Nest:
666  return bitc::ATTR_KIND_NEST;
667  case Attribute::NoAlias:
669  case Attribute::NoBuiltin:
671  case Attribute::NoCapture:
673  case Attribute::NoDuplicate:
675  case Attribute::NoImplicitFloat:
677  case Attribute::NoInline:
679  case Attribute::NonLazyBind:
681  case Attribute::NonNull:
683  case Attribute::Dereferenceable:
685  case Attribute::DereferenceableOrNull:
687  case Attribute::NoRedZone:
689  case Attribute::NoReturn:
691  case Attribute::NoUnwind:
693  case Attribute::OptimizeForSize:
695  case Attribute::OptimizeNone:
697  case Attribute::ReadNone:
699  case Attribute::ReadOnly:
701  case Attribute::Returned:
703  case Attribute::ReturnsTwice:
705  case Attribute::SExt:
706  return bitc::ATTR_KIND_S_EXT;
707  case Attribute::StackAlignment:
709  case Attribute::StackProtect:
711  case Attribute::StackProtectReq:
713  case Attribute::StackProtectStrong:
715  case Attribute::SafeStack:
717  case Attribute::StructRet:
719  case Attribute::SanitizeAddress:
721  case Attribute::SanitizeThread:
723  case Attribute::SanitizeMemory:
725  case Attribute::UWTable:
727  case Attribute::ZExt:
728  return bitc::ATTR_KIND_Z_EXT;
730  llvm_unreachable("Can not encode end-attribute kinds marker.");
731  case Attribute::None:
732  llvm_unreachable("Can not encode none-attribute.");
733  case Attribute::EmptyKey:
735  llvm_unreachable("Trying to encode EmptyKey/TombstoneKey");
736  default:
737  llvm_unreachable("Trying to encode attribute not supported by DXIL. These "
738  "should be stripped in DXILPrepare");
739  }
740 
741  llvm_unreachable("Trying to encode unknown attribute");
742 }
743 
745  uint64_t V) {
746  if ((int64_t)V >= 0)
747  Vals.push_back(V << 1);
748  else
749  Vals.push_back((-V << 1) | 1);
750 }
751 
753  const APInt &A) {
754  // We have an arbitrary precision integer value to write whose
755  // bit width is > 64. However, in canonical unsigned integer
756  // format it is likely that the high bits are going to be zero.
757  // So, we only write the number of active words.
758  unsigned NumWords = A.getActiveWords();
759  const uint64_t *RawData = A.getRawData();
760  for (unsigned i = 0; i < NumWords; i++)
761  emitSignedInt64(Vals, RawData[i]);
762 }
763 
765  uint64_t Flags = 0;
766 
767  if (const auto *OBO = dyn_cast<OverflowingBinaryOperator>(V)) {
768  if (OBO->hasNoSignedWrap())
769  Flags |= 1 << bitc::OBO_NO_SIGNED_WRAP;
770  if (OBO->hasNoUnsignedWrap())
771  Flags |= 1 << bitc::OBO_NO_UNSIGNED_WRAP;
772  } else if (const auto *PEO = dyn_cast<PossiblyExactOperator>(V)) {
773  if (PEO->isExact())
774  Flags |= 1 << bitc::PEO_EXACT;
775  } else if (const auto *FPMO = dyn_cast<FPMathOperator>(V)) {
776  if (FPMO->hasAllowReassoc())
777  Flags |= bitc::AllowReassoc;
778  if (FPMO->hasNoNaNs())
779  Flags |= bitc::NoNaNs;
780  if (FPMO->hasNoInfs())
781  Flags |= bitc::NoInfs;
782  if (FPMO->hasNoSignedZeros())
783  Flags |= bitc::NoSignedZeros;
784  if (FPMO->hasAllowReciprocal())
785  Flags |= bitc::AllowReciprocal;
786  if (FPMO->hasAllowContract())
787  Flags |= bitc::AllowContract;
788  if (FPMO->hasApproxFunc())
789  Flags |= bitc::ApproxFunc;
790  }
791 
792  return Flags;
793 }
794 
795 unsigned
797  switch (Linkage) {
799  return 0;
801  return 16;
803  return 2;
805  return 3;
807  return 18;
809  return 7;
811  return 8;
813  return 9;
815  return 17;
817  return 19;
819  return 12;
820  }
821  llvm_unreachable("Invalid linkage");
822 }
823 
825  return getEncodedLinkage(GV.getLinkage());
826 }
827 
829  switch (GV.getVisibility()) {
831  return 0;
833  return 1;
835  return 2;
836  }
837  llvm_unreachable("Invalid visibility");
838 }
839 
841  switch (GV.getDLLStorageClass()) {
843  return 0;
845  return 1;
847  return 2;
848  }
849  llvm_unreachable("Invalid DLL storage class");
850 }
851 
853  switch (GV.getThreadLocalMode()) {
855  return 0;
857  return 1;
859  return 2;
861  return 3;
863  return 4;
864  }
865  llvm_unreachable("Invalid TLS model");
866 }
867 
869  switch (C.getSelectionKind()) {
870  case Comdat::Any:
872  case Comdat::ExactMatch:
874  case Comdat::Largest:
878  case Comdat::SameSize:
880  }
881  llvm_unreachable("Invalid selection kind");
882 }
883 
884 ////////////////////////////////////////////////////////////////////////////////
885 /// Begin DXILBitcodeWriter Implementation
886 ////////////////////////////////////////////////////////////////////////////////
887 
888 void DXILBitcodeWriter::writeAttributeGroupTable() {
889  const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
890  VE.getAttributeGroups();
891  if (AttrGrps.empty())
892  return;
893 
894  Stream.EnterSubblock(bitc::PARAMATTR_GROUP_BLOCK_ID, 3);
895 
897  for (ValueEnumerator::IndexAndAttrSet Pair : AttrGrps) {
898  unsigned AttrListIndex = Pair.first;
899  AttributeSet AS = Pair.second;
900  Record.push_back(VE.getAttributeGroupID(Pair));
901  Record.push_back(AttrListIndex);
902 
903  for (Attribute Attr : AS) {
904  if (Attr.isEnumAttribute()) {
905  uint64_t Val = getAttrKindEncoding(Attr.getKindAsEnum());
907  "DXIL does not support attributes above ATTR_KIND_ARGMEMONLY");
908  Record.push_back(0);
909  Record.push_back(Val);
910  } else if (Attr.isIntAttribute()) {
911  uint64_t Val = getAttrKindEncoding(Attr.getKindAsEnum());
913  "DXIL does not support attributes above ATTR_KIND_ARGMEMONLY");
914  Record.push_back(1);
915  Record.push_back(Val);
916  Record.push_back(Attr.getValueAsInt());
917  } else {
918  StringRef Kind = Attr.getKindAsString();
919  StringRef Val = Attr.getValueAsString();
920 
921  Record.push_back(Val.empty() ? 3 : 4);
922  Record.append(Kind.begin(), Kind.end());
923  Record.push_back(0);
924  if (!Val.empty()) {
925  Record.append(Val.begin(), Val.end());
926  Record.push_back(0);
927  }
928  }
929  }
930 
932  Record.clear();
933  }
934 
935  Stream.ExitBlock();
936 }
937 
938 void DXILBitcodeWriter::writeAttributeTable() {
939  const std::vector<AttributeList> &Attrs = VE.getAttributeLists();
940  if (Attrs.empty())
941  return;
942 
943  Stream.EnterSubblock(bitc::PARAMATTR_BLOCK_ID, 3);
944 
946  for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
947  AttributeList AL = Attrs[i];
948  for (unsigned i : AL.indexes()) {
949  AttributeSet AS = AL.getAttributes(i);
950  if (AS.hasAttributes())
951  Record.push_back(VE.getAttributeGroupID({i, AS}));
952  }
953 
955  Record.clear();
956  }
957 
958  Stream.ExitBlock();
959 }
960 
961 /// WriteTypeTable - Write out the type table for a module.
962 void DXILBitcodeWriter::writeTypeTable() {
963  const ValueEnumerator::TypeList &TypeList = VE.getTypes();
964 
965  Stream.EnterSubblock(bitc::TYPE_BLOCK_ID_NEW, 4 /*count from # abbrevs */);
966  SmallVector<uint64_t, 64> TypeVals;
967 
969 
970  // Abbrev for TYPE_CODE_POINTER.
971  auto Abbv = std::make_shared<BitCodeAbbrev>();
973  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits));
974  Abbv->Add(BitCodeAbbrevOp(0)); // Addrspace = 0
975  unsigned PtrAbbrev = Stream.EmitAbbrev(std::move(Abbv));
976 
977  // Abbrev for TYPE_CODE_FUNCTION.
978  Abbv = std::make_shared<BitCodeAbbrev>();
980  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isvararg
982  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits));
983  unsigned FunctionAbbrev = Stream.EmitAbbrev(std::move(Abbv));
984 
985  // Abbrev for TYPE_CODE_STRUCT_ANON.
986  Abbv = std::make_shared<BitCodeAbbrev>();
988  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ispacked
990  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits));
991  unsigned StructAnonAbbrev = Stream.EmitAbbrev(std::move(Abbv));
992 
993  // Abbrev for TYPE_CODE_STRUCT_NAME.
994  Abbv = std::make_shared<BitCodeAbbrev>();
998  unsigned StructNameAbbrev = Stream.EmitAbbrev(std::move(Abbv));
999 
1000  // Abbrev for TYPE_CODE_STRUCT_NAMED.
1001  Abbv = std::make_shared<BitCodeAbbrev>();
1003  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ispacked
1005  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits));
1006  unsigned StructNamedAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1007 
1008  // Abbrev for TYPE_CODE_ARRAY.
1009  Abbv = std::make_shared<BitCodeAbbrev>();
1011  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // size
1012  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits));
1013  unsigned ArrayAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1014 
1015  // Emit an entry count so the reader can reserve space.
1016  TypeVals.push_back(TypeList.size());
1017  Stream.EmitRecord(bitc::TYPE_CODE_NUMENTRY, TypeVals);
1018  TypeVals.clear();
1019 
1020  // Loop over all of the types, emitting each in turn.
1021  for (Type *T : TypeList) {
1022  int AbbrevToUse = 0;
1023  unsigned Code = 0;
1024 
1025  switch (T->getTypeID()) {
1026  case Type::BFloatTyID:
1027  case Type::X86_AMXTyID:
1028  case Type::TokenTyID:
1029  llvm_unreachable("These should never be used!!!");
1030  break;
1031  case Type::VoidTyID:
1033  break;
1034  case Type::HalfTyID:
1036  break;
1037  case Type::FloatTyID:
1039  break;
1040  case Type::DoubleTyID:
1042  break;
1043  case Type::X86_FP80TyID:
1045  break;
1046  case Type::FP128TyID:
1048  break;
1049  case Type::PPC_FP128TyID:
1051  break;
1052  case Type::LabelTyID:
1054  break;
1055  case Type::MetadataTyID:
1057  break;
1058  case Type::X86_MMXTyID:
1060  break;
1061  case Type::IntegerTyID:
1062  // INTEGER: [width]
1064  TypeVals.push_back(cast<IntegerType>(T)->getBitWidth());
1065  break;
1066  case Type::DXILPointerTyID: {
1067  TypedPointerType *PTy = cast<TypedPointerType>(T);
1068  // POINTER: [pointee type, address space]
1070  TypeVals.push_back(getTypeID(PTy->getElementType()));
1071  unsigned AddressSpace = PTy->getAddressSpace();
1072  TypeVals.push_back(AddressSpace);
1073  if (AddressSpace == 0)
1074  AbbrevToUse = PtrAbbrev;
1075  break;
1076  }
1077  case Type::PointerTyID: {
1078  PointerType *PTy = cast<PointerType>(T);
1079  // POINTER: [pointee type, address space]
1081  // Emitting an empty struct type for the opaque pointer's type allows
1082  // this to be order-independent. Non-struct types must be emitted in
1083  // bitcode before they can be referenced.
1084  if (PTy->isOpaquePointerTy()) {
1085  TypeVals.push_back(false);
1088  "dxilOpaquePtrReservedName", StructNameAbbrev);
1089  } else {
1090  TypeVals.push_back(getTypeID(PTy->getNonOpaquePointerElementType()));
1091  unsigned AddressSpace = PTy->getAddressSpace();
1092  TypeVals.push_back(AddressSpace);
1093  if (AddressSpace == 0)
1094  AbbrevToUse = PtrAbbrev;
1095  }
1096  break;
1097  }
1098  case Type::FunctionTyID: {
1099  FunctionType *FT = cast<FunctionType>(T);
1100  // FUNCTION: [isvararg, retty, paramty x N]
1102  TypeVals.push_back(FT->isVarArg());
1103  TypeVals.push_back(getTypeID(FT->getReturnType()));
1104  for (Type *PTy : FT->params())
1105  TypeVals.push_back(getTypeID(PTy));
1106  AbbrevToUse = FunctionAbbrev;
1107  break;
1108  }
1109  case Type::StructTyID: {
1110  StructType *ST = cast<StructType>(T);
1111  // STRUCT: [ispacked, eltty x N]
1112  TypeVals.push_back(ST->isPacked());
1113  // Output all of the element types.
1114  for (Type *ElTy : ST->elements())
1115  TypeVals.push_back(getTypeID(ElTy));
1116 
1117  if (ST->isLiteral()) {
1119  AbbrevToUse = StructAnonAbbrev;
1120  } else {
1121  if (ST->isOpaque()) {
1123  } else {
1125  AbbrevToUse = StructNamedAbbrev;
1126  }
1127 
1128  // Emit the name if it is present.
1129  if (!ST->getName().empty())
1130  writeStringRecord(Stream, bitc::TYPE_CODE_STRUCT_NAME, ST->getName(),
1131  StructNameAbbrev);
1132  }
1133  break;
1134  }
1135  case Type::ArrayTyID: {
1136  ArrayType *AT = cast<ArrayType>(T);
1137  // ARRAY: [numelts, eltty]
1139  TypeVals.push_back(AT->getNumElements());
1140  TypeVals.push_back(getTypeID(AT->getElementType()));
1141  AbbrevToUse = ArrayAbbrev;
1142  break;
1143  }
1144  case Type::FixedVectorTyID:
1145  case Type::ScalableVectorTyID: {
1146  VectorType *VT = cast<VectorType>(T);
1147  // VECTOR [numelts, eltty]
1149  TypeVals.push_back(VT->getElementCount().getKnownMinValue());
1150  TypeVals.push_back(getTypeID(VT->getElementType()));
1151  break;
1152  }
1153  }
1154 
1155  // Emit the finished record.
1156  Stream.EmitRecord(Code, TypeVals, AbbrevToUse);
1157  TypeVals.clear();
1158  }
1159 
1160  Stream.ExitBlock();
1161 }
1162 
1163 void DXILBitcodeWriter::writeComdats() {
1165  for (const Comdat *C : VE.getComdats()) {
1166  // COMDAT: [selection_kind, name]
1167  Vals.push_back(getEncodedComdatSelectionKind(*C));
1168  size_t Size = C->getName().size();
1169  assert(isUInt<16>(Size));
1170  Vals.push_back(Size);
1171  for (char Chr : C->getName())
1172  Vals.push_back((unsigned char)Chr);
1173  Stream.EmitRecord(bitc::MODULE_CODE_COMDAT, Vals, /*AbbrevToUse=*/0);
1174  Vals.clear();
1175  }
1176 }
1177 
1178 void DXILBitcodeWriter::writeValueSymbolTableForwardDecl() {}
1179 
1180 /// Emit top-level description of module, including target triple, inline asm,
1181 /// descriptors for global variables, and function prototype info.
1182 /// Returns the bit offset to backpatch with the location of the real VST.
1183 void DXILBitcodeWriter::writeModuleInfo() {
1184  // Emit various pieces of data attached to a module.
1185  if (!M.getTargetTriple().empty())
1186  writeStringRecord(Stream, bitc::MODULE_CODE_TRIPLE, M.getTargetTriple(),
1187  0 /*TODO*/);
1188  const std::string &DL = M.getDataLayoutStr();
1189  if (!DL.empty())
1190  writeStringRecord(Stream, bitc::MODULE_CODE_DATALAYOUT, DL, 0 /*TODO*/);
1191  if (!M.getModuleInlineAsm().empty())
1192  writeStringRecord(Stream, bitc::MODULE_CODE_ASM, M.getModuleInlineAsm(),
1193  0 /*TODO*/);
1194 
1195  // Emit information about sections and GC, computing how many there are. Also
1196  // compute the maximum alignment value.
1197  std::map<std::string, unsigned> SectionMap;
1198  std::map<std::string, unsigned> GCMap;
1199  MaybeAlign MaxAlignment;
1200  unsigned MaxGlobalType = 0;
1201  const auto UpdateMaxAlignment = [&MaxAlignment](const MaybeAlign A) {
1202  if (A)
1203  MaxAlignment = !MaxAlignment ? *A : std::max(*MaxAlignment, *A);
1204  };
1205  for (const GlobalVariable &GV : M.globals()) {
1206  UpdateMaxAlignment(GV.getAlign());
1207  MaxGlobalType = std::max(MaxGlobalType, getTypeID(GV.getValueType(), &GV));
1208  if (GV.hasSection()) {
1209  // Give section names unique ID's.
1210  unsigned &Entry = SectionMap[std::string(GV.getSection())];
1211  if (!Entry) {
1213  GV.getSection(), 0 /*TODO*/);
1214  Entry = SectionMap.size();
1215  }
1216  }
1217  }
1218  for (const Function &F : M) {
1219  UpdateMaxAlignment(F.getAlign());
1220  if (F.hasSection()) {
1221  // Give section names unique ID's.
1222  unsigned &Entry = SectionMap[std::string(F.getSection())];
1223  if (!Entry) {
1224  writeStringRecord(Stream, bitc::MODULE_CODE_SECTIONNAME, F.getSection(),
1225  0 /*TODO*/);
1226  Entry = SectionMap.size();
1227  }
1228  }
1229  if (F.hasGC()) {
1230  // Same for GC names.
1231  unsigned &Entry = GCMap[F.getGC()];
1232  if (!Entry) {
1233  writeStringRecord(Stream, bitc::MODULE_CODE_GCNAME, F.getGC(),
1234  0 /*TODO*/);
1235  Entry = GCMap.size();
1236  }
1237  }
1238  }
1239 
1240  // Emit abbrev for globals, now that we know # sections and max alignment.
1241  unsigned SimpleGVarAbbrev = 0;
1242  if (!M.global_empty()) {
1243  // Add an abbrev for common globals with no visibility or thread
1244  // localness.
1245  auto Abbv = std::make_shared<BitCodeAbbrev>();
1248  Log2_32_Ceil(MaxGlobalType + 1)));
1249  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddrSpace << 2
1250  //| explicitType << 1
1251  //| constant
1252  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Initializer.
1253  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); // Linkage.
1254  if (!MaxAlignment) // Alignment.
1255  Abbv->Add(BitCodeAbbrevOp(0));
1256  else {
1257  unsigned MaxEncAlignment = getEncodedAlign(MaxAlignment);
1259  Log2_32_Ceil(MaxEncAlignment + 1)));
1260  }
1261  if (SectionMap.empty()) // Section.
1262  Abbv->Add(BitCodeAbbrevOp(0));
1263  else
1265  Log2_32_Ceil(SectionMap.size() + 1)));
1266  // Don't bother emitting vis + thread local.
1267  SimpleGVarAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1268  }
1269 
1270  // Emit the global variable information.
1272  for (const GlobalVariable &GV : M.globals()) {
1273  unsigned AbbrevToUse = 0;
1274 
1275  // GLOBALVAR: [type, isconst, initid,
1276  // linkage, alignment, section, visibility, threadlocal,
1277  // unnamed_addr, externally_initialized, dllstorageclass,
1278  // comdat]
1279  Vals.push_back(getTypeID(GV.getValueType(), &GV));
1280  Vals.push_back(
1281  GV.getType()->getAddressSpace() << 2 | 2 |
1282  (GV.isConstant() ? 1 : 0)); // HLSL Change - bitwise | was used with
1283  // unsigned int and bool
1284  Vals.push_back(
1285  GV.isDeclaration() ? 0 : (VE.getValueID(GV.getInitializer()) + 1));
1286  Vals.push_back(getEncodedLinkage(GV));
1287  Vals.push_back(getEncodedAlign(GV.getAlign()));
1288  Vals.push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1289  : 0);
1290  if (GV.isThreadLocal() ||
1291  GV.getVisibility() != GlobalValue::DefaultVisibility ||
1292  GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1293  GV.isExternallyInitialized() ||
1294  GV.getDLLStorageClass() != GlobalValue::DefaultStorageClass ||
1295  GV.hasComdat()) {
1296  Vals.push_back(getEncodedVisibility(GV));
1297  Vals.push_back(getEncodedThreadLocalMode(GV));
1298  Vals.push_back(GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None);
1299  Vals.push_back(GV.isExternallyInitialized());
1300  Vals.push_back(getEncodedDLLStorageClass(GV));
1301  Vals.push_back(GV.hasComdat() ? VE.getComdatID(GV.getComdat()) : 0);
1302  } else {
1303  AbbrevToUse = SimpleGVarAbbrev;
1304  }
1305 
1306  Stream.EmitRecord(bitc::MODULE_CODE_GLOBALVAR, Vals, AbbrevToUse);
1307  Vals.clear();
1308  }
1309 
1310  // Emit the function proto information.
1311  for (const Function &F : M) {
1312  // FUNCTION: [type, callingconv, isproto, linkage, paramattrs, alignment,
1313  // section, visibility, gc, unnamed_addr, prologuedata,
1314  // dllstorageclass, comdat, prefixdata, personalityfn]
1315  Vals.push_back(getTypeID(F.getFunctionType(), &F));
1316  Vals.push_back(F.getCallingConv());
1317  Vals.push_back(F.isDeclaration());
1318  Vals.push_back(getEncodedLinkage(F));
1319  Vals.push_back(VE.getAttributeListID(F.getAttributes()));
1320  Vals.push_back(getEncodedAlign(F.getAlign()));
1321  Vals.push_back(F.hasSection() ? SectionMap[std::string(F.getSection())]
1322  : 0);
1323  Vals.push_back(getEncodedVisibility(F));
1324  Vals.push_back(F.hasGC() ? GCMap[F.getGC()] : 0);
1325  Vals.push_back(F.getUnnamedAddr() != GlobalValue::UnnamedAddr::None);
1326  Vals.push_back(
1327  F.hasPrologueData() ? (VE.getValueID(F.getPrologueData()) + 1) : 0);
1328  Vals.push_back(getEncodedDLLStorageClass(F));
1329  Vals.push_back(F.hasComdat() ? VE.getComdatID(F.getComdat()) : 0);
1330  Vals.push_back(F.hasPrefixData() ? (VE.getValueID(F.getPrefixData()) + 1)
1331  : 0);
1332  Vals.push_back(
1333  F.hasPersonalityFn() ? (VE.getValueID(F.getPersonalityFn()) + 1) : 0);
1334 
1335  unsigned AbbrevToUse = 0;
1336  Stream.EmitRecord(bitc::MODULE_CODE_FUNCTION, Vals, AbbrevToUse);
1337  Vals.clear();
1338  }
1339 
1340  // Emit the alias information.
1341  for (const GlobalAlias &A : M.aliases()) {
1342  // ALIAS: [alias type, aliasee val#, linkage, visibility]
1343  Vals.push_back(getTypeID(A.getValueType(), &A));
1344  Vals.push_back(VE.getValueID(A.getAliasee()));
1345  Vals.push_back(getEncodedLinkage(A));
1346  Vals.push_back(getEncodedVisibility(A));
1347  Vals.push_back(getEncodedDLLStorageClass(A));
1348  Vals.push_back(getEncodedThreadLocalMode(A));
1349  Vals.push_back(A.getUnnamedAddr() != GlobalValue::UnnamedAddr::None);
1350  unsigned AbbrevToUse = 0;
1351  Stream.EmitRecord(bitc::MODULE_CODE_ALIAS_OLD, Vals, AbbrevToUse);
1352  Vals.clear();
1353  }
1354 }
1355 
1356 void DXILBitcodeWriter::writeValueAsMetadata(
1358  // Mimic an MDNode with a value as one operand.
1359  Value *V = MD->getValue();
1360  Type *Ty = V->getType();
1361  if (Function *F = dyn_cast<Function>(V))
1362  Ty = TypedPointerType::get(F->getFunctionType(), F->getAddressSpace());
1363  else if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
1364  Ty = TypedPointerType::get(GV->getValueType(), GV->getAddressSpace());
1365  Record.push_back(getTypeID(Ty));
1366  Record.push_back(VE.getValueID(V));
1367  Stream.EmitRecord(bitc::METADATA_VALUE, Record, 0);
1368  Record.clear();
1369 }
1370 
1371 void DXILBitcodeWriter::writeMDTuple(const MDTuple *N,
1373  unsigned Abbrev) {
1374  for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
1375  Metadata *MD = N->getOperand(i);
1376  assert(!(MD && isa<LocalAsMetadata>(MD)) &&
1377  "Unexpected function-local metadata");
1378  Record.push_back(VE.getMetadataOrNullID(MD));
1379  }
1380  Stream.EmitRecord(N->isDistinct() ? bitc::METADATA_DISTINCT_NODE
1382  Record, Abbrev);
1383  Record.clear();
1384 }
1385 
1386 void DXILBitcodeWriter::writeDILocation(const DILocation *N,
1388  unsigned &Abbrev) {
1389  if (!Abbrev)
1390  Abbrev = createDILocationAbbrev();
1391  Record.push_back(N->isDistinct());
1392  Record.push_back(N->getLine());
1393  Record.push_back(N->getColumn());
1394  Record.push_back(VE.getMetadataID(N->getScope()));
1395  Record.push_back(VE.getMetadataOrNullID(N->getInlinedAt()));
1396 
1397  Stream.EmitRecord(bitc::METADATA_LOCATION, Record, Abbrev);
1398  Record.clear();
1399 }
1400 
1402  int64_t I = Val.getSExtValue();
1403  uint64_t U = I;
1404  return I < 0 ? ~(U << 1) : U << 1;
1405 }
1406 
1407 static uint64_t rotateSign(DISubrange::BoundType Val) {
1408  return rotateSign(Val.get<ConstantInt *>()->getValue());
1409 }
1410 
1411 void DXILBitcodeWriter::writeDISubrange(const DISubrange *N,
1413  unsigned Abbrev) {
1414  Record.push_back(N->isDistinct());
1415  Record.push_back(
1416  N->getCount().get<ConstantInt *>()->getValue().getSExtValue());
1417  Record.push_back(rotateSign(N->getLowerBound()));
1418 
1419  Stream.EmitRecord(bitc::METADATA_SUBRANGE, Record, Abbrev);
1420  Record.clear();
1421 }
1422 
1423 void DXILBitcodeWriter::writeDIEnumerator(const DIEnumerator *N,
1425  unsigned Abbrev) {
1426  Record.push_back(N->isDistinct());
1427  Record.push_back(rotateSign(N->getValue()));
1428  Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1429 
1430  Stream.EmitRecord(bitc::METADATA_ENUMERATOR, Record, Abbrev);
1431  Record.clear();
1432 }
1433 
1434 void DXILBitcodeWriter::writeDIBasicType(const DIBasicType *N,
1436  unsigned Abbrev) {
1437  Record.push_back(N->isDistinct());
1438  Record.push_back(N->getTag());
1439  Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1440  Record.push_back(N->getSizeInBits());
1441  Record.push_back(N->getAlignInBits());
1442  Record.push_back(N->getEncoding());
1443 
1444  Stream.EmitRecord(bitc::METADATA_BASIC_TYPE, Record, Abbrev);
1445  Record.clear();
1446 }
1447 
1448 void DXILBitcodeWriter::writeDIDerivedType(const DIDerivedType *N,
1450  unsigned Abbrev) {
1451  Record.push_back(N->isDistinct());
1452  Record.push_back(N->getTag());
1453  Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1454  Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1455  Record.push_back(N->getLine());
1456  Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1457  Record.push_back(VE.getMetadataOrNullID(N->getBaseType()));
1458  Record.push_back(N->getSizeInBits());
1459  Record.push_back(N->getAlignInBits());
1460  Record.push_back(N->getOffsetInBits());
1461  Record.push_back(N->getFlags());
1462  Record.push_back(VE.getMetadataOrNullID(N->getExtraData()));
1463 
1464  Stream.EmitRecord(bitc::METADATA_DERIVED_TYPE, Record, Abbrev);
1465  Record.clear();
1466 }
1467 
1468 void DXILBitcodeWriter::writeDICompositeType(const DICompositeType *N,
1470  unsigned Abbrev) {
1471  Record.push_back(N->isDistinct());
1472  Record.push_back(N->getTag());
1473  Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1474  Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1475  Record.push_back(N->getLine());
1476  Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1477  Record.push_back(VE.getMetadataOrNullID(N->getBaseType()));
1478  Record.push_back(N->getSizeInBits());
1479  Record.push_back(N->getAlignInBits());
1480  Record.push_back(N->getOffsetInBits());
1481  Record.push_back(N->getFlags());
1482  Record.push_back(VE.getMetadataOrNullID(N->getElements().get()));
1483  Record.push_back(N->getRuntimeLang());
1484  Record.push_back(VE.getMetadataOrNullID(N->getVTableHolder()));
1485  Record.push_back(VE.getMetadataOrNullID(N->getTemplateParams().get()));
1486  Record.push_back(VE.getMetadataOrNullID(N->getRawIdentifier()));
1487 
1488  Stream.EmitRecord(bitc::METADATA_COMPOSITE_TYPE, Record, Abbrev);
1489  Record.clear();
1490 }
1491 
1492 void DXILBitcodeWriter::writeDISubroutineType(const DISubroutineType *N,
1494  unsigned Abbrev) {
1495  Record.push_back(N->isDistinct());
1496  Record.push_back(N->getFlags());
1497  Record.push_back(VE.getMetadataOrNullID(N->getTypeArray().get()));
1498 
1499  Stream.EmitRecord(bitc::METADATA_SUBROUTINE_TYPE, Record, Abbrev);
1500  Record.clear();
1501 }
1502 
1503 void DXILBitcodeWriter::writeDIFile(const DIFile *N,
1505  unsigned Abbrev) {
1506  Record.push_back(N->isDistinct());
1507  Record.push_back(VE.getMetadataOrNullID(N->getRawFilename()));
1508  Record.push_back(VE.getMetadataOrNullID(N->getRawDirectory()));
1509 
1510  Stream.EmitRecord(bitc::METADATA_FILE, Record, Abbrev);
1511  Record.clear();
1512 }
1513 
1514 void DXILBitcodeWriter::writeDICompileUnit(const DICompileUnit *N,
1516  unsigned Abbrev) {
1517  Record.push_back(N->isDistinct());
1518  Record.push_back(N->getSourceLanguage());
1519  Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1520  Record.push_back(VE.getMetadataOrNullID(N->getRawProducer()));
1521  Record.push_back(N->isOptimized());
1522  Record.push_back(VE.getMetadataOrNullID(N->getRawFlags()));
1523  Record.push_back(N->getRuntimeVersion());
1524  Record.push_back(VE.getMetadataOrNullID(N->getRawSplitDebugFilename()));
1525  Record.push_back(N->getEmissionKind());
1526  Record.push_back(VE.getMetadataOrNullID(N->getEnumTypes().get()));
1527  Record.push_back(VE.getMetadataOrNullID(N->getRetainedTypes().get()));
1528  Record.push_back(/* subprograms */ 0);
1529  Record.push_back(VE.getMetadataOrNullID(N->getGlobalVariables().get()));
1530  Record.push_back(VE.getMetadataOrNullID(N->getImportedEntities().get()));
1531  Record.push_back(N->getDWOId());
1532 
1533  Stream.EmitRecord(bitc::METADATA_COMPILE_UNIT, Record, Abbrev);
1534  Record.clear();
1535 }
1536 
1537 void DXILBitcodeWriter::writeDISubprogram(const DISubprogram *N,
1539  unsigned Abbrev) {
1540  Record.push_back(N->isDistinct());
1541  Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1542  Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1543  Record.push_back(VE.getMetadataOrNullID(N->getRawLinkageName()));
1544  Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1545  Record.push_back(N->getLine());
1546  Record.push_back(VE.getMetadataOrNullID(N->getType()));
1547  Record.push_back(N->isLocalToUnit());
1548  Record.push_back(N->isDefinition());
1549  Record.push_back(N->getScopeLine());
1550  Record.push_back(VE.getMetadataOrNullID(N->getContainingType()));
1551  Record.push_back(N->getVirtuality());
1552  Record.push_back(N->getVirtualIndex());
1553  Record.push_back(N->getFlags());
1554  Record.push_back(N->isOptimized());
1555  Record.push_back(VE.getMetadataOrNullID(N->getRawUnit()));
1556  Record.push_back(VE.getMetadataOrNullID(N->getTemplateParams().get()));
1557  Record.push_back(VE.getMetadataOrNullID(N->getDeclaration()));
1558  Record.push_back(VE.getMetadataOrNullID(N->getRetainedNodes().get()));
1559 
1560  Stream.EmitRecord(bitc::METADATA_SUBPROGRAM, Record, Abbrev);
1561  Record.clear();
1562 }
1563 
1564 void DXILBitcodeWriter::writeDILexicalBlock(const DILexicalBlock *N,
1566  unsigned Abbrev) {
1567  Record.push_back(N->isDistinct());
1568  Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1569  Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1570  Record.push_back(N->getLine());
1571  Record.push_back(N->getColumn());
1572 
1573  Stream.EmitRecord(bitc::METADATA_LEXICAL_BLOCK, Record, Abbrev);
1574  Record.clear();
1575 }
1576 
1577 void DXILBitcodeWriter::writeDILexicalBlockFile(
1579  unsigned Abbrev) {
1580  Record.push_back(N->isDistinct());
1581  Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1582  Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1583  Record.push_back(N->getDiscriminator());
1584 
1585  Stream.EmitRecord(bitc::METADATA_LEXICAL_BLOCK_FILE, Record, Abbrev);
1586  Record.clear();
1587 }
1588 
1589 void DXILBitcodeWriter::writeDINamespace(const DINamespace *N,
1591  unsigned Abbrev) {
1592  Record.push_back(N->isDistinct());
1593  Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1594  Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1595  Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1596  Record.push_back(/* line number */ 0);
1597 
1598  Stream.EmitRecord(bitc::METADATA_NAMESPACE, Record, Abbrev);
1599  Record.clear();
1600 }
1601 
1602 void DXILBitcodeWriter::writeDIModule(const DIModule *N,
1604  unsigned Abbrev) {
1605  Record.push_back(N->isDistinct());
1606  for (auto &I : N->operands())
1607  Record.push_back(VE.getMetadataOrNullID(I));
1608 
1609  Stream.EmitRecord(bitc::METADATA_MODULE, Record, Abbrev);
1610  Record.clear();
1611 }
1612 
1613 void DXILBitcodeWriter::writeDITemplateTypeParameter(
1615  unsigned Abbrev) {
1616  Record.push_back(N->isDistinct());
1617  Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1618  Record.push_back(VE.getMetadataOrNullID(N->getType()));
1619 
1620  Stream.EmitRecord(bitc::METADATA_TEMPLATE_TYPE, Record, Abbrev);
1621  Record.clear();
1622 }
1623 
1624 void DXILBitcodeWriter::writeDITemplateValueParameter(
1626  unsigned Abbrev) {
1627  Record.push_back(N->isDistinct());
1628  Record.push_back(N->getTag());
1629  Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1630  Record.push_back(VE.getMetadataOrNullID(N->getType()));
1631  Record.push_back(VE.getMetadataOrNullID(N->getValue()));
1632 
1633  Stream.EmitRecord(bitc::METADATA_TEMPLATE_VALUE, Record, Abbrev);
1634  Record.clear();
1635 }
1636 
1637 void DXILBitcodeWriter::writeDIGlobalVariable(const DIGlobalVariable *N,
1639  unsigned Abbrev) {
1640  Record.push_back(N->isDistinct());
1641  Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1642  Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1643  Record.push_back(VE.getMetadataOrNullID(N->getRawLinkageName()));
1644  Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1645  Record.push_back(N->getLine());
1646  Record.push_back(VE.getMetadataOrNullID(N->getType()));
1647  Record.push_back(N->isLocalToUnit());
1648  Record.push_back(N->isDefinition());
1649  Record.push_back(/* N->getRawVariable() */ 0);
1650  Record.push_back(VE.getMetadataOrNullID(N->getStaticDataMemberDeclaration()));
1651 
1652  Stream.EmitRecord(bitc::METADATA_GLOBAL_VAR, Record, Abbrev);
1653  Record.clear();
1654 }
1655 
1656 void DXILBitcodeWriter::writeDILocalVariable(const DILocalVariable *N,
1658  unsigned Abbrev) {
1659  Record.push_back(N->isDistinct());
1660  Record.push_back(N->getTag());
1661  Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1662  Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1663  Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1664  Record.push_back(N->getLine());
1665  Record.push_back(VE.getMetadataOrNullID(N->getType()));
1666  Record.push_back(N->getArg());
1667  Record.push_back(N->getFlags());
1668 
1669  Stream.EmitRecord(bitc::METADATA_LOCAL_VAR, Record, Abbrev);
1670  Record.clear();
1671 }
1672 
1673 void DXILBitcodeWriter::writeDIExpression(const DIExpression *N,
1675  unsigned Abbrev) {
1676  Record.reserve(N->getElements().size() + 1);
1677 
1678  Record.push_back(N->isDistinct());
1679  Record.append(N->elements_begin(), N->elements_end());
1680 
1681  Stream.EmitRecord(bitc::METADATA_EXPRESSION, Record, Abbrev);
1682  Record.clear();
1683 }
1684 
1685 void DXILBitcodeWriter::writeDIObjCProperty(const DIObjCProperty *N,
1687  unsigned Abbrev) {
1688  llvm_unreachable("DXIL does not support objc!!!");
1689 }
1690 
1691 void DXILBitcodeWriter::writeDIImportedEntity(const DIImportedEntity *N,
1693  unsigned Abbrev) {
1694  Record.push_back(N->isDistinct());
1695  Record.push_back(N->getTag());
1696  Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1697  Record.push_back(VE.getMetadataOrNullID(N->getEntity()));
1698  Record.push_back(N->getLine());
1699  Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1700 
1701  Stream.EmitRecord(bitc::METADATA_IMPORTED_ENTITY, Record, Abbrev);
1702  Record.clear();
1703 }
1704 
1705 unsigned DXILBitcodeWriter::createDILocationAbbrev() {
1706  // Abbrev for METADATA_LOCATION.
1707  //
1708  // Assume the column is usually under 128, and always output the inlined-at
1709  // location (it's never more expensive than building an array size 1).
1710  std::shared_ptr<BitCodeAbbrev> Abbv = std::make_shared<BitCodeAbbrev>();
1712  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
1713  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1714  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
1715  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1716  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1717  return Stream.EmitAbbrev(std::move(Abbv));
1718 }
1719 
1720 unsigned DXILBitcodeWriter::createGenericDINodeAbbrev() {
1721  // Abbrev for METADATA_GENERIC_DEBUG.
1722  //
1723  // Assume the column is usually under 128, and always output the inlined-at
1724  // location (it's never more expensive than building an array size 1).
1725  std::shared_ptr<BitCodeAbbrev> Abbv = std::make_shared<BitCodeAbbrev>();
1727  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
1728  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1729  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
1730  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1732  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1733  return Stream.EmitAbbrev(std::move(Abbv));
1734 }
1735 
1736 void DXILBitcodeWriter::writeMetadataRecords(ArrayRef<const Metadata *> MDs,
1738  std::vector<unsigned> *MDAbbrevs,
1739  std::vector<uint64_t> *IndexPos) {
1740  if (MDs.empty())
1741  return;
1742 
1743  // Initialize MDNode abbreviations.
1744 #define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
1745 #include "llvm/IR/Metadata.def"
1746 
1747  for (const Metadata *MD : MDs) {
1748  if (IndexPos)
1749  IndexPos->push_back(Stream.GetCurrentBitNo());
1750  if (const MDNode *N = dyn_cast<MDNode>(MD)) {
1751  assert(N->isResolved() && "Expected forward references to be resolved");
1752 
1753  switch (N->getMetadataID()) {
1754  default:
1755  llvm_unreachable("Invalid MDNode subclass");
1756 #define HANDLE_MDNODE_LEAF(CLASS) \
1757  case Metadata::CLASS##Kind: \
1758  if (MDAbbrevs) \
1759  write##CLASS(cast<CLASS>(N), Record, \
1760  (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
1761  else \
1762  write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
1763  continue;
1764 #include "llvm/IR/Metadata.def"
1765  }
1766  }
1767  writeValueAsMetadata(cast<ValueAsMetadata>(MD), Record);
1768  }
1769 }
1770 
1771 unsigned DXILBitcodeWriter::createMetadataStringsAbbrev() {
1772  auto Abbv = std::make_shared<BitCodeAbbrev>();
1775  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8));
1776  return Stream.EmitAbbrev(std::move(Abbv));
1777 }
1778 
1779 void DXILBitcodeWriter::writeMetadataStrings(
1781  for (const Metadata *MD : Strings) {
1782  const MDString *MDS = cast<MDString>(MD);
1783  // Code: [strchar x N]
1784  Record.append(MDS->bytes_begin(), MDS->bytes_end());
1785 
1786  // Emit the finished record.
1788  createMetadataStringsAbbrev());
1789  Record.clear();
1790  }
1791 }
1792 
1793 void DXILBitcodeWriter::writeModuleMetadata() {
1794  if (!VE.hasMDs() && M.named_metadata_empty())
1795  return;
1796 
1797  Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 5);
1798 
1799  // Emit all abbrevs upfront, so that the reader can jump in the middle of the
1800  // block and load any metadata.
1801  std::vector<unsigned> MDAbbrevs;
1802 
1803  MDAbbrevs.resize(MetadataAbbrev::LastPlusOne);
1804  MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
1805  MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
1806  createGenericDINodeAbbrev();
1807 
1808  unsigned NameAbbrev = 0;
1809  if (!M.named_metadata_empty()) {
1810  // Abbrev for METADATA_NAME.
1811  std::shared_ptr<BitCodeAbbrev> Abbv = std::make_shared<BitCodeAbbrev>();
1814  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8));
1815  NameAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1816  }
1817 
1819  writeMetadataStrings(VE.getMDStrings(), Record);
1820 
1821  std::vector<uint64_t> IndexPos;
1822  IndexPos.reserve(VE.getNonMDStrings().size());
1823  writeMetadataRecords(VE.getNonMDStrings(), Record, &MDAbbrevs, &IndexPos);
1824 
1825  // Write named metadata.
1826  for (const NamedMDNode &NMD : M.named_metadata()) {
1827  // Write name.
1828  StringRef Str = NMD.getName();
1829  Record.append(Str.bytes_begin(), Str.bytes_end());
1830  Stream.EmitRecord(bitc::METADATA_NAME, Record, NameAbbrev);
1831  Record.clear();
1832 
1833  // Write named metadata operands.
1834  for (const MDNode *N : NMD.operands())
1835  Record.push_back(VE.getMetadataID(N));
1836  Stream.EmitRecord(bitc::METADATA_NAMED_NODE, Record, 0);
1837  Record.clear();
1838  }
1839 
1840  Stream.ExitBlock();
1841 }
1842 
1843 void DXILBitcodeWriter::writeFunctionMetadata(const Function &F) {
1844  if (!VE.hasMDs())
1845  return;
1846 
1847  Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 4);
1849  writeMetadataStrings(VE.getMDStrings(), Record);
1850  writeMetadataRecords(VE.getNonMDStrings(), Record);
1851  Stream.ExitBlock();
1852 }
1853 
1854 void DXILBitcodeWriter::writeFunctionMetadataAttachment(const Function &F) {
1855  Stream.EnterSubblock(bitc::METADATA_ATTACHMENT_ID, 3);
1856 
1858 
1859  // Write metadata attachments
1860  // METADATA_ATTACHMENT - [m x [value, [n x [id, mdnode]]]
1862  F.getAllMetadata(MDs);
1863  if (!MDs.empty()) {
1864  for (const auto &I : MDs) {
1865  Record.push_back(I.first);
1866  Record.push_back(VE.getMetadataID(I.second));
1867  }
1868  Stream.EmitRecord(bitc::METADATA_ATTACHMENT, Record, 0);
1869  Record.clear();
1870  }
1871 
1872  for (const BasicBlock &BB : F)
1873  for (const Instruction &I : BB) {
1874  MDs.clear();
1875  I.getAllMetadataOtherThanDebugLoc(MDs);
1876 
1877  // If no metadata, ignore instruction.
1878  if (MDs.empty())
1879  continue;
1880 
1881  Record.push_back(VE.getInstructionID(&I));
1882 
1883  for (unsigned i = 0, e = MDs.size(); i != e; ++i) {
1884  Record.push_back(MDs[i].first);
1885  Record.push_back(VE.getMetadataID(MDs[i].second));
1886  }
1887  Stream.EmitRecord(bitc::METADATA_ATTACHMENT, Record, 0);
1888  Record.clear();
1889  }
1890 
1891  Stream.ExitBlock();
1892 }
1893 
1894 void DXILBitcodeWriter::writeModuleMetadataKinds() {
1896 
1897  // Write metadata kinds
1898  // METADATA_KIND - [n x [id, name]]
1900  M.getMDKindNames(Names);
1901 
1902  if (Names.empty())
1903  return;
1904 
1905  Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
1906 
1907  for (unsigned MDKindID = 0, e = Names.size(); MDKindID != e; ++MDKindID) {
1908  Record.push_back(MDKindID);
1909  StringRef KName = Names[MDKindID];
1910  Record.append(KName.begin(), KName.end());
1911 
1912  Stream.EmitRecord(bitc::METADATA_KIND, Record, 0);
1913  Record.clear();
1914  }
1915 
1916  Stream.ExitBlock();
1917 }
1918 
1919 void DXILBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal,
1920  bool isGlobal) {
1921  if (FirstVal == LastVal)
1922  return;
1923 
1924  Stream.EnterSubblock(bitc::CONSTANTS_BLOCK_ID, 4);
1925 
1926  unsigned AggregateAbbrev = 0;
1927  unsigned String8Abbrev = 0;
1928  unsigned CString7Abbrev = 0;
1929  unsigned CString6Abbrev = 0;
1930  // If this is a constant pool for the module, emit module-specific abbrevs.
1931  if (isGlobal) {
1932  // Abbrev for CST_CODE_AGGREGATE.
1933  auto Abbv = std::make_shared<BitCodeAbbrev>();
1936  Abbv->Add(
1938  AggregateAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1939 
1940  // Abbrev for CST_CODE_STRING.
1941  Abbv = std::make_shared<BitCodeAbbrev>();
1944  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8));
1945  String8Abbrev = Stream.EmitAbbrev(std::move(Abbv));
1946  // Abbrev for CST_CODE_CSTRING.
1947  Abbv = std::make_shared<BitCodeAbbrev>();
1950  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7));
1951  CString7Abbrev = Stream.EmitAbbrev(std::move(Abbv));
1952  // Abbrev for CST_CODE_CSTRING.
1953  Abbv = std::make_shared<BitCodeAbbrev>();
1957  CString6Abbrev = Stream.EmitAbbrev(std::move(Abbv));
1958  }
1959 
1961 
1962  const ValueEnumerator::ValueList &Vals = VE.getValues();
1963  Type *LastTy = nullptr;
1964  for (unsigned i = FirstVal; i != LastVal; ++i) {
1965  const Value *V = Vals[i].first;
1966  // If we need to switch types, do so now.
1967  if (V->getType() != LastTy) {
1968  LastTy = V->getType();
1969  Record.push_back(getTypeID(LastTy));
1970  Stream.EmitRecord(bitc::CST_CODE_SETTYPE, Record,
1971  CONSTANTS_SETTYPE_ABBREV);
1972  Record.clear();
1973  }
1974 
1975  if (const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
1976  Record.push_back(unsigned(IA->hasSideEffects()) |
1977  unsigned(IA->isAlignStack()) << 1 |
1978  unsigned(IA->getDialect() & 1) << 2);
1979 
1980  // Add the asm string.
1981  const std::string &AsmStr = IA->getAsmString();
1982  Record.push_back(AsmStr.size());
1983  Record.append(AsmStr.begin(), AsmStr.end());
1984 
1985  // Add the constraint string.
1986  const std::string &ConstraintStr = IA->getConstraintString();
1987  Record.push_back(ConstraintStr.size());
1988  Record.append(ConstraintStr.begin(), ConstraintStr.end());
1989  Stream.EmitRecord(bitc::CST_CODE_INLINEASM, Record);
1990  Record.clear();
1991  continue;
1992  }
1993  const Constant *C = cast<Constant>(V);
1994  unsigned Code = -1U;
1995  unsigned AbbrevToUse = 0;
1996  if (C->isNullValue()) {
1998  } else if (isa<UndefValue>(C)) {
2000  } else if (const ConstantInt *IV = dyn_cast<ConstantInt>(C)) {
2001  if (IV->getBitWidth() <= 64) {
2002  uint64_t V = IV->getSExtValue();
2003  emitSignedInt64(Record, V);
2005  AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2006  } else { // Wide integers, > 64 bits in size.
2007  // We have an arbitrary precision integer value to write whose
2008  // bit width is > 64. However, in canonical unsigned integer
2009  // format it is likely that the high bits are going to be zero.
2010  // So, we only write the number of active words.
2011  unsigned NWords = IV->getValue().getActiveWords();
2012  const uint64_t *RawWords = IV->getValue().getRawData();
2013  for (unsigned i = 0; i != NWords; ++i) {
2014  emitSignedInt64(Record, RawWords[i]);
2015  }
2017  }
2018  } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
2020  Type *Ty = CFP->getType();
2021  if (Ty->isHalfTy() || Ty->isFloatTy() || Ty->isDoubleTy()) {
2022  Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2023  } else if (Ty->isX86_FP80Ty()) {
2024  // api needed to prevent premature destruction
2025  // bits are not in the same order as a normal i80 APInt, compensate.
2026  APInt api = CFP->getValueAPF().bitcastToAPInt();
2027  const uint64_t *p = api.getRawData();
2028  Record.push_back((p[1] << 48) | (p[0] >> 16));
2029  Record.push_back(p[0] & 0xffffLL);
2030  } else if (Ty->isFP128Ty() || Ty->isPPC_FP128Ty()) {
2031  APInt api = CFP->getValueAPF().bitcastToAPInt();
2032  const uint64_t *p = api.getRawData();
2033  Record.push_back(p[0]);
2034  Record.push_back(p[1]);
2035  } else {
2036  assert(0 && "Unknown FP type!");
2037  }
2038  } else if (isa<ConstantDataSequential>(C) &&
2039  cast<ConstantDataSequential>(C)->isString()) {
2040  const ConstantDataSequential *Str = cast<ConstantDataSequential>(C);
2041  // Emit constant strings specially.
2042  unsigned NumElts = Str->getNumElements();
2043  // If this is a null-terminated string, use the denser CSTRING encoding.
2044  if (Str->isCString()) {
2046  --NumElts; // Don't encode the null, which isn't allowed by char6.
2047  } else {
2049  AbbrevToUse = String8Abbrev;
2050  }
2051  bool isCStr7 = Code == bitc::CST_CODE_CSTRING;
2052  bool isCStrChar6 = Code == bitc::CST_CODE_CSTRING;
2053  for (unsigned i = 0; i != NumElts; ++i) {
2054  unsigned char V = Str->getElementAsInteger(i);
2055  Record.push_back(V);
2056  isCStr7 &= (V & 128) == 0;
2057  if (isCStrChar6)
2058  isCStrChar6 = BitCodeAbbrevOp::isChar6(V);
2059  }
2060 
2061  if (isCStrChar6)
2062  AbbrevToUse = CString6Abbrev;
2063  else if (isCStr7)
2064  AbbrevToUse = CString7Abbrev;
2065  } else if (const ConstantDataSequential *CDS =
2066  dyn_cast<ConstantDataSequential>(C)) {
2068  Type *EltTy = CDS->getType()->getArrayElementType();
2069  if (isa<IntegerType>(EltTy)) {
2070  for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2071  Record.push_back(CDS->getElementAsInteger(i));
2072  } else if (EltTy->isFloatTy()) {
2073  for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
2074  union {
2075  float F;
2076  uint32_t I;
2077  };
2078  F = CDS->getElementAsFloat(i);
2079  Record.push_back(I);
2080  }
2081  } else {
2082  assert(EltTy->isDoubleTy() && "Unknown ConstantData element type");
2083  for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
2084  union {
2085  double F;
2086  uint64_t I;
2087  };
2088  F = CDS->getElementAsDouble(i);
2089  Record.push_back(I);
2090  }
2091  }
2092  } else if (isa<ConstantArray>(C) || isa<ConstantStruct>(C) ||
2093  isa<ConstantVector>(C)) {
2095  for (const Value *Op : C->operands())
2096  Record.push_back(VE.getValueID(Op));
2097  AbbrevToUse = AggregateAbbrev;
2098  } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
2099  switch (CE->getOpcode()) {
2100  default:
2101  if (Instruction::isCast(CE->getOpcode())) {
2103  Record.push_back(getEncodedCastOpcode(CE->getOpcode()));
2104  Record.push_back(getTypeID(C->getOperand(0)->getType()));
2105  Record.push_back(VE.getValueID(C->getOperand(0)));
2106  AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2107  } else {
2108  assert(CE->getNumOperands() == 2 && "Unknown constant expr!");
2110  Record.push_back(getEncodedBinaryOpcode(CE->getOpcode()));
2111  Record.push_back(VE.getValueID(C->getOperand(0)));
2112  Record.push_back(VE.getValueID(C->getOperand(1)));
2113  uint64_t Flags = getOptimizationFlags(CE);
2114  if (Flags != 0)
2115  Record.push_back(Flags);
2116  }
2117  break;
2118  case Instruction::GetElementPtr: {
2120  const auto *GO = cast<GEPOperator>(C);
2121  if (GO->isInBounds())
2123  Record.push_back(getTypeID(GO->getSourceElementType()));
2124  for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i) {
2125  Record.push_back(getTypeID(C->getOperand(i)->getType()));
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 
2192 void 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.
2213 bool DXILBitcodeWriter::pushValueAndType(const Value *V, unsigned InstID,
2214  SmallVectorImpl<unsigned> &Vals) {
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).
2227 void DXILBitcodeWriter::pushValue(const Value *V, unsigned InstID,
2228  SmallVectorImpl<unsigned> &Vals) {
2229  unsigned ValID = VE.getValueID(V);
2230  Vals.push_back(InstID - ValID);
2231 }
2232 
2233 void DXILBitcodeWriter::pushValueSigned(const Value *V, unsigned InstID,
2234  SmallVectorImpl<uint64_t> &Vals) {
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
2241 void DXILBitcodeWriter::writeInstruction(const Instruction &I, unsigned InstID,
2242  SmallVectorImpl<unsigned> &Vals) {
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()));
2261  uint64_t Flags = getOptimizationFlags(&I);
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(I.getOperand(2), InstID, Vals);
2317  break;
2318  case Instruction::ICmp:
2319  case Instruction::FCmp: {
2320  // compare returning Int1Ty or vector of Int1Ty
2322  pushValueAndType(I.getOperand(0), InstID, Vals);
2323  pushValue(I.getOperand(1), InstID, Vals);
2324  Vals.push_back(cast<CmpInst>(I).getPredicate());
2325  uint64_t Flags = getOptimizationFlags(&I);
2326  if (Flags != 0)
2327  Vals.push_back(Flags);
2328  break;
2329  }
2330 
2331  case Instruction::Ret: {
2333  unsigned NumOperands = I.getNumOperands();
2334  if (NumOperands == 0)
2335  AbbrevToUse = (unsigned)FUNCTION_INST_RET_VOID_ABBREV;
2336  else if (NumOperands == 1) {
2337  if (!pushValueAndType(I.getOperand(0), InstID, Vals))
2338  AbbrevToUse = (unsigned)FUNCTION_INST_RET_VAL_ABBREV;
2339  } else {
2340  for (unsigned i = 0, e = NumOperands; i != e; ++i)
2341  pushValueAndType(I.getOperand(i), InstID, Vals);
2342  }
2343  } break;
2344  case Instruction::Br: {
2346  const BranchInst &II = cast<BranchInst>(I);
2347  Vals.push_back(VE.getValueID(II.getSuccessor(0)));
2348  if (II.isConditional()) {
2349  Vals.push_back(VE.getValueID(II.getSuccessor(1)));
2350  pushValue(II.getCondition(), InstID, Vals);
2351  }
2352  } break;
2353  case Instruction::Switch: {
2355  const SwitchInst &SI = cast<SwitchInst>(I);
2356  Vals.push_back(getTypeID(SI.getCondition()->getType()));
2357  pushValue(SI.getCondition(), InstID, Vals);
2358  Vals.push_back(VE.getValueID(SI.getDefaultDest()));
2359  for (auto Case : SI.cases()) {
2360  Vals.push_back(VE.getValueID(Case.getCaseValue()));
2361  Vals.push_back(VE.getValueID(Case.getCaseSuccessor()));
2362  }
2363  } break;
2364  case Instruction::IndirectBr:
2366  Vals.push_back(getTypeID(I.getOperand(0)->getType()));
2367  // Encode the address operand as relative, but not the basic blocks.
2368  pushValue(I.getOperand(0), InstID, Vals);
2369  for (unsigned i = 1, e = I.getNumOperands(); i != e; ++i)
2370  Vals.push_back(VE.getValueID(I.getOperand(i)));
2371  break;
2372 
2373  case Instruction::Invoke: {
2374  const InvokeInst *II = cast<InvokeInst>(&I);
2375  const Value *Callee = II->getCalledOperand();
2376  FunctionType *FTy = II->getFunctionType();
2378 
2379  Vals.push_back(VE.getAttributeListID(II->getAttributes()));
2380  Vals.push_back(II->getCallingConv() | 1 << 13);
2381  Vals.push_back(VE.getValueID(II->getNormalDest()));
2382  Vals.push_back(VE.getValueID(II->getUnwindDest()));
2383  Vals.push_back(getTypeID(FTy));
2384  pushValueAndType(Callee, InstID, Vals);
2385 
2386  // Emit value #'s for the fixed parameters.
2387  for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
2388  pushValue(I.getOperand(i), InstID, Vals); // fixed param.
2389 
2390  // Emit type/value pairs for varargs params.
2391  if (FTy->isVarArg()) {
2392  for (unsigned i = FTy->getNumParams(), e = I.getNumOperands() - 3; i != e;
2393  ++i)
2394  pushValueAndType(I.getOperand(i), InstID, Vals); // vararg
2395  }
2396  break;
2397  }
2398  case Instruction::Resume:
2400  pushValueAndType(I.getOperand(0), InstID, Vals);
2401  break;
2402  case Instruction::Unreachable:
2404  AbbrevToUse = (unsigned)FUNCTION_INST_UNREACHABLE_ABBREV;
2405  break;
2406 
2407  case Instruction::PHI: {
2408  const PHINode &PN = cast<PHINode>(I);
2410  // With the newer instruction encoding, forward references could give
2411  // negative valued IDs. This is most common for PHIs, so we use
2412  // signed VBRs.
2414  Vals64.push_back(getTypeID(PN.getType()));
2415  for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) {
2416  pushValueSigned(PN.getIncomingValue(i), InstID, Vals64);
2417  Vals64.push_back(VE.getValueID(PN.getIncomingBlock(i)));
2418  }
2419  // Emit a Vals64 vector and exit.
2420  Stream.EmitRecord(Code, Vals64, AbbrevToUse);
2421  Vals64.clear();
2422  return;
2423  }
2424 
2425  case Instruction::LandingPad: {
2426  const LandingPadInst &LP = cast<LandingPadInst>(I);
2428  Vals.push_back(getTypeID(LP.getType()));
2429  Vals.push_back(LP.isCleanup());
2430  Vals.push_back(LP.getNumClauses());
2431  for (unsigned I = 0, E = LP.getNumClauses(); I != E; ++I) {
2432  if (LP.isCatch(I))
2433  Vals.push_back(LandingPadInst::Catch);
2434  else
2435  Vals.push_back(LandingPadInst::Filter);
2436  pushValueAndType(LP.getClause(I), InstID, Vals);
2437  }
2438  break;
2439  }
2440 
2441  case Instruction::Alloca: {
2443  const AllocaInst &AI = cast<AllocaInst>(I);
2444  Vals.push_back(getTypeID(AI.getAllocatedType()));
2445  Vals.push_back(getTypeID(I.getOperand(0)->getType()));
2446  Vals.push_back(VE.getValueID(I.getOperand(0))); // size.
2447  using APV = AllocaPackedValues;
2448  unsigned Record = 0;
2449  unsigned EncodedAlign = getEncodedAlign(AI.getAlign());
2450  Bitfield::set<APV::AlignLower>(
2451  Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1));
2452  Bitfield::set<APV::AlignUpper>(Record,
2453  EncodedAlign >> APV::AlignLower::Bits);
2454  Bitfield::set<APV::UsedWithInAlloca>(Record, AI.isUsedWithInAlloca());
2455  Vals.push_back(Record);
2456  break;
2457  }
2458 
2459  case Instruction::Load:
2460  if (cast<LoadInst>(I).isAtomic()) {
2462  pushValueAndType(I.getOperand(0), InstID, Vals);
2463  } else {
2465  if (!pushValueAndType(I.getOperand(0), InstID, Vals)) // ptr
2466  AbbrevToUse = (unsigned)FUNCTION_INST_LOAD_ABBREV;
2467  }
2468  Vals.push_back(getTypeID(I.getType()));
2469  Vals.push_back(Log2(cast<LoadInst>(I).getAlign()) + 1);
2470  Vals.push_back(cast<LoadInst>(I).isVolatile());
2471  if (cast<LoadInst>(I).isAtomic()) {
2472  Vals.push_back(getEncodedOrdering(cast<LoadInst>(I).getOrdering()));
2473  Vals.push_back(getEncodedSyncScopeID(cast<LoadInst>(I).getSyncScopeID()));
2474  }
2475  break;
2476  case Instruction::Store:
2477  if (cast<StoreInst>(I).isAtomic())
2479  else
2481  pushValueAndType(I.getOperand(1), InstID, Vals); // ptrty + ptr
2482  pushValueAndType(I.getOperand(0), InstID, Vals); // valty + val
2483  Vals.push_back(Log2(cast<StoreInst>(I).getAlign()) + 1);
2484  Vals.push_back(cast<StoreInst>(I).isVolatile());
2485  if (cast<StoreInst>(I).isAtomic()) {
2486  Vals.push_back(getEncodedOrdering(cast<StoreInst>(I).getOrdering()));
2487  Vals.push_back(
2488  getEncodedSyncScopeID(cast<StoreInst>(I).getSyncScopeID()));
2489  }
2490  break;
2491  case Instruction::AtomicCmpXchg:
2493  pushValueAndType(I.getOperand(0), InstID, Vals); // ptrty + ptr
2494  pushValueAndType(I.getOperand(1), InstID, Vals); // cmp.
2495  pushValue(I.getOperand(2), InstID, Vals); // newval.
2496  Vals.push_back(cast<AtomicCmpXchgInst>(I).isVolatile());
2497  Vals.push_back(
2498  getEncodedOrdering(cast<AtomicCmpXchgInst>(I).getSuccessOrdering()));
2499  Vals.push_back(
2500  getEncodedSyncScopeID(cast<AtomicCmpXchgInst>(I).getSyncScopeID()));
2501  Vals.push_back(
2502  getEncodedOrdering(cast<AtomicCmpXchgInst>(I).getFailureOrdering()));
2503  Vals.push_back(cast<AtomicCmpXchgInst>(I).isWeak());
2504  break;
2505  case Instruction::AtomicRMW:
2507  pushValueAndType(I.getOperand(0), InstID, Vals); // ptrty + ptr
2508  pushValue(I.getOperand(1), InstID, Vals); // val.
2509  Vals.push_back(
2510  getEncodedRMWOperation(cast<AtomicRMWInst>(I).getOperation()));
2511  Vals.push_back(cast<AtomicRMWInst>(I).isVolatile());
2512  Vals.push_back(getEncodedOrdering(cast<AtomicRMWInst>(I).getOrdering()));
2513  Vals.push_back(
2514  getEncodedSyncScopeID(cast<AtomicRMWInst>(I).getSyncScopeID()));
2515  break;
2516  case Instruction::Fence:
2518  Vals.push_back(getEncodedOrdering(cast<FenceInst>(I).getOrdering()));
2519  Vals.push_back(getEncodedSyncScopeID(cast<FenceInst>(I).getSyncScopeID()));
2520  break;
2521  case Instruction::Call: {
2522  const CallInst &CI = cast<CallInst>(I);
2523  FunctionType *FTy = CI.getFunctionType();
2524 
2526 
2527  Vals.push_back(VE.getAttributeListID(CI.getAttributes()));
2528  Vals.push_back((CI.getCallingConv() << 1) | unsigned(CI.isTailCall()) |
2529  unsigned(CI.isMustTailCall()) << 14 | 1 << 15);
2530  Vals.push_back(getTypeID(FTy, CI.getCalledFunction()));
2531  pushValueAndType(CI.getCalledOperand(), InstID, Vals); // Callee
2532 
2533  // Emit value #'s for the fixed parameters.
2534  for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
2535  // Check for labels (can happen with asm labels).
2536  if (FTy->getParamType(i)->isLabelTy())
2537  Vals.push_back(VE.getValueID(CI.getArgOperand(i)));
2538  else
2539  pushValue(CI.getArgOperand(i), InstID, Vals); // fixed param.
2540  }
2541 
2542  // Emit type/value pairs for varargs params.
2543  if (FTy->isVarArg()) {
2544  for (unsigned i = FTy->getNumParams(), e = CI.arg_size(); i != e; ++i)
2545  pushValueAndType(CI.getArgOperand(i), InstID, Vals); // varargs
2546  }
2547  break;
2548  }
2549  case Instruction::VAArg:
2551  Vals.push_back(getTypeID(I.getOperand(0)->getType())); // valistty
2552  pushValue(I.getOperand(0), InstID, Vals); // valist.
2553  Vals.push_back(getTypeID(I.getType())); // restype.
2554  break;
2555  }
2556 
2557  Stream.EmitRecord(Code, Vals, AbbrevToUse);
2558  Vals.clear();
2559 }
2560 
2561 // Emit names for globals/functions etc.
2562 void DXILBitcodeWriter::writeFunctionLevelValueSymbolTable(
2563  const ValueSymbolTable &VST) {
2564  if (VST.empty())
2565  return;
2566  Stream.EnterSubblock(bitc::VALUE_SYMTAB_BLOCK_ID, 4);
2567 
2568  SmallVector<unsigned, 64> NameVals;
2569 
2570  // HLSL Change
2571  // Read the named values from a sorted list instead of the original list
2572  // to ensure the binary is the same no matter what values ever existed.
2574 
2575  for (auto &VI : VST) {
2576  SortedTable.push_back(VI.second->getValueName());
2577  }
2578  // The keys are unique, so there shouldn't be stability issues.
2579  std::sort(SortedTable.begin(), SortedTable.end(),
2580  [](const ValueName *A, const ValueName *B) {
2581  return A->first() < B->first();
2582  });
2583 
2584  for (const ValueName *SI : SortedTable) {
2585  auto &Name = *SI;
2586 
2587  // Figure out the encoding to use for the name.
2588  bool is7Bit = true;
2589  bool isChar6 = true;
2590  for (const char *C = Name.getKeyData(), *E = C + Name.getKeyLength();
2591  C != E; ++C) {
2592  if (isChar6)
2593  isChar6 = BitCodeAbbrevOp::isChar6(*C);
2594  if ((unsigned char)*C & 128) {
2595  is7Bit = false;
2596  break; // don't bother scanning the rest.
2597  }
2598  }
2599 
2600  unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
2601 
2602  // VST_ENTRY: [valueid, namechar x N]
2603  // VST_BBENTRY: [bbid, namechar x N]
2604  unsigned Code;
2605  if (isa<BasicBlock>(SI->getValue())) {
2607  if (isChar6)
2608  AbbrevToUse = VST_BBENTRY_6_ABBREV;
2609  } else {
2611  if (isChar6)
2612  AbbrevToUse = VST_ENTRY_6_ABBREV;
2613  else if (is7Bit)
2614  AbbrevToUse = VST_ENTRY_7_ABBREV;
2615  }
2616 
2617  NameVals.push_back(VE.getValueID(SI->getValue()));
2618  for (const char *P = Name.getKeyData(),
2619  *E = Name.getKeyData() + Name.getKeyLength();
2620  P != E; ++P)
2621  NameVals.push_back((unsigned char)*P);
2622 
2623  // Emit the finished record.
2624  Stream.EmitRecord(Code, NameVals, AbbrevToUse);
2625  NameVals.clear();
2626  }
2627  Stream.ExitBlock();
2628 }
2629 
2630 void DXILBitcodeWriter::writeUseList(UseListOrder &&Order) {
2631  assert(Order.Shuffle.size() >= 2 && "Shuffle too small");
2632  unsigned Code;
2633  if (isa<BasicBlock>(Order.V))
2635  else
2637 
2638  SmallVector<uint64_t, 64> Record(Order.Shuffle.begin(), Order.Shuffle.end());
2639  Record.push_back(VE.getValueID(Order.V));
2640  Stream.EmitRecord(Code, Record);
2641 }
2642 
2643 void DXILBitcodeWriter::writeUseListBlock(const Function *F) {
2644  auto hasMore = [&]() {
2645  return !VE.UseListOrders.empty() && VE.UseListOrders.back().F == F;
2646  };
2647  if (!hasMore())
2648  // Nothing to do.
2649  return;
2650 
2651  Stream.EnterSubblock(bitc::USELIST_BLOCK_ID, 3);
2652  while (hasMore()) {
2653  writeUseList(std::move(VE.UseListOrders.back()));
2654  VE.UseListOrders.pop_back();
2655  }
2656  Stream.ExitBlock();
2657 }
2658 
2659 /// Emit a function body to the module stream.
2660 void DXILBitcodeWriter::writeFunction(const Function &F) {
2661  Stream.EnterSubblock(bitc::FUNCTION_BLOCK_ID, 4);
2662  VE.incorporateFunction(F);
2663 
2665 
2666  // Emit the number of basic blocks, so the reader can create them ahead of
2667  // time.
2668  Vals.push_back(VE.getBasicBlocks().size());
2669  Stream.EmitRecord(bitc::FUNC_CODE_DECLAREBLOCKS, Vals);
2670  Vals.clear();
2671 
2672  // If there are function-local constants, emit them now.
2673  unsigned CstStart, CstEnd;
2674  VE.getFunctionConstantRange(CstStart, CstEnd);
2675  writeConstants(CstStart, CstEnd, false);
2676 
2677  // If there is function-local metadata, emit it now.
2678  writeFunctionMetadata(F);
2679 
2680  // Keep a running idea of what the instruction ID is.
2681  unsigned InstID = CstEnd;
2682 
2683  bool NeedsMetadataAttachment = F.hasMetadata();
2684 
2685  DILocation *LastDL = nullptr;
2686 
2687  // Finally, emit all the instructions, in order.
2688  for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
2689  for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E;
2690  ++I) {
2691  writeInstruction(*I, InstID, Vals);
2692 
2693  if (!I->getType()->isVoidTy())
2694  ++InstID;
2695 
2696  // If the instruction has metadata, write a metadata attachment later.
2697  NeedsMetadataAttachment |= I->hasMetadataOtherThanDebugLoc();
2698 
2699  // If the instruction has a debug location, emit it.
2700  DILocation *DL = I->getDebugLoc();
2701  if (!DL)
2702  continue;
2703 
2704  if (DL == LastDL) {
2705  // Just repeat the same debug loc as last time.
2706  Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC_AGAIN, Vals);
2707  continue;
2708  }
2709 
2710  Vals.push_back(DL->getLine());
2711  Vals.push_back(DL->getColumn());
2712  Vals.push_back(VE.getMetadataOrNullID(DL->getScope()));
2713  Vals.push_back(VE.getMetadataOrNullID(DL->getInlinedAt()));
2714  Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC, Vals);
2715  Vals.clear();
2716 
2717  LastDL = DL;
2718  }
2719 
2720  // Emit names for all the instructions etc.
2721  if (auto *Symtab = F.getValueSymbolTable())
2722  writeFunctionLevelValueSymbolTable(*Symtab);
2723 
2724  if (NeedsMetadataAttachment)
2725  writeFunctionMetadataAttachment(F);
2726 
2727  writeUseListBlock(&F);
2728  VE.purgeFunction();
2729  Stream.ExitBlock();
2730 }
2731 
2732 // Emit blockinfo, which defines the standard abbreviations etc.
2733 void DXILBitcodeWriter::writeBlockInfo() {
2734  // We only want to emit block info records for blocks that have multiple
2735  // instances: CONSTANTS_BLOCK, FUNCTION_BLOCK and VALUE_SYMTAB_BLOCK.
2736  // Other blocks can define their abbrevs inline.
2737  Stream.EnterBlockInfoBlock();
2738 
2739  { // 8-bit fixed-width VST_ENTRY/VST_BBENTRY strings.
2740  auto Abbv = std::make_shared<BitCodeAbbrev>();
2741  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3));
2742  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
2744  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8));
2745  if (Stream.EmitBlockInfoAbbrev(bitc::VALUE_SYMTAB_BLOCK_ID,
2746  std::move(Abbv)) != VST_ENTRY_8_ABBREV)
2747  assert(false && "Unexpected abbrev ordering!");
2748  }
2749 
2750  { // 7-bit fixed width VST_ENTRY strings.
2751  auto Abbv = std::make_shared<BitCodeAbbrev>();
2753  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
2755  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7));
2756  if (Stream.EmitBlockInfoAbbrev(bitc::VALUE_SYMTAB_BLOCK_ID,
2757  std::move(Abbv)) != VST_ENTRY_7_ABBREV)
2758  assert(false && "Unexpected abbrev ordering!");
2759  }
2760  { // 6-bit char6 VST_ENTRY strings.
2761  auto Abbv = std::make_shared<BitCodeAbbrev>();
2763  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
2766  if (Stream.EmitBlockInfoAbbrev(bitc::VALUE_SYMTAB_BLOCK_ID,
2767  std::move(Abbv)) != VST_ENTRY_6_ABBREV)
2768  assert(false && "Unexpected abbrev ordering!");
2769  }
2770  { // 6-bit char6 VST_BBENTRY strings.
2771  auto Abbv = std::make_shared<BitCodeAbbrev>();
2773  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
2776  if (Stream.EmitBlockInfoAbbrev(bitc::VALUE_SYMTAB_BLOCK_ID,
2777  std::move(Abbv)) != VST_BBENTRY_6_ABBREV)
2778  assert(false && "Unexpected abbrev ordering!");
2779  }
2780 
2781  { // SETTYPE abbrev for CONSTANTS_BLOCK.
2782  auto Abbv = std::make_shared<BitCodeAbbrev>();
2786  if (Stream.EmitBlockInfoAbbrev(bitc::CONSTANTS_BLOCK_ID, std::move(Abbv)) !=
2787  CONSTANTS_SETTYPE_ABBREV)
2788  assert(false && "Unexpected abbrev ordering!");
2789  }
2790 
2791  { // INTEGER abbrev for CONSTANTS_BLOCK.
2792  auto Abbv = std::make_shared<BitCodeAbbrev>();
2794  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
2795  if (Stream.EmitBlockInfoAbbrev(bitc::CONSTANTS_BLOCK_ID, std::move(Abbv)) !=
2796  CONSTANTS_INTEGER_ABBREV)
2797  assert(false && "Unexpected abbrev ordering!");
2798  }
2799 
2800  { // CE_CAST abbrev for CONSTANTS_BLOCK.
2801  auto Abbv = std::make_shared<BitCodeAbbrev>();
2803  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // cast opc
2804  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, // typeid
2806  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // value id
2807 
2808  if (Stream.EmitBlockInfoAbbrev(bitc::CONSTANTS_BLOCK_ID, std::move(Abbv)) !=
2809  CONSTANTS_CE_CAST_Abbrev)
2810  assert(false && "Unexpected abbrev ordering!");
2811  }
2812  { // NULL abbrev for CONSTANTS_BLOCK.
2813  auto Abbv = std::make_shared<BitCodeAbbrev>();
2815  if (Stream.EmitBlockInfoAbbrev(bitc::CONSTANTS_BLOCK_ID, std::move(Abbv)) !=
2816  CONSTANTS_NULL_Abbrev)
2817  assert(false && "Unexpected abbrev ordering!");
2818  }
2819 
2820  // FIXME: This should only use space for first class types!
2821 
2822  { // INST_LOAD abbrev for FUNCTION_BLOCK.
2823  auto Abbv = std::make_shared<BitCodeAbbrev>();
2825  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Ptr
2826  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, // dest ty
2828  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4)); // Align
2829  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // volatile
2830  if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, std::move(Abbv)) !=
2831  (unsigned)FUNCTION_INST_LOAD_ABBREV)
2832  assert(false && "Unexpected abbrev ordering!");
2833  }
2834  { // INST_BINOP abbrev for FUNCTION_BLOCK.
2835  auto Abbv = std::make_shared<BitCodeAbbrev>();
2837  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LHS
2838  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // RHS
2839  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // opc
2840  if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, std::move(Abbv)) !=
2841  (unsigned)FUNCTION_INST_BINOP_ABBREV)
2842  assert(false && "Unexpected abbrev ordering!");
2843  }
2844  { // INST_BINOP_FLAGS abbrev for FUNCTION_BLOCK.
2845  auto Abbv = std::make_shared<BitCodeAbbrev>();
2847  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LHS
2848  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // RHS
2849  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // opc
2850  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7)); // flags
2851  if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, std::move(Abbv)) !=
2852  (unsigned)FUNCTION_INST_BINOP_FLAGS_ABBREV)
2853  assert(false && "Unexpected abbrev ordering!");
2854  }
2855  { // INST_CAST abbrev for FUNCTION_BLOCK.
2856  auto Abbv = std::make_shared<BitCodeAbbrev>();
2858  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // OpVal
2859  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, // dest ty
2861  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // opc
2862  if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, std::move(Abbv)) !=
2863  (unsigned)FUNCTION_INST_CAST_ABBREV)
2864  assert(false && "Unexpected abbrev ordering!");
2865  }
2866 
2867  { // INST_RET abbrev for FUNCTION_BLOCK.
2868  auto Abbv = std::make_shared<BitCodeAbbrev>();
2870  if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, std::move(Abbv)) !=
2871  (unsigned)FUNCTION_INST_RET_VOID_ABBREV)
2872  assert(false && "Unexpected abbrev ordering!");
2873  }
2874  { // INST_RET abbrev for FUNCTION_BLOCK.
2875  auto Abbv = std::make_shared<BitCodeAbbrev>();
2877  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ValID
2878  if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, std::move(Abbv)) !=
2879  (unsigned)FUNCTION_INST_RET_VAL_ABBREV)
2880  assert(false && "Unexpected abbrev ordering!");
2881  }
2882  { // INST_UNREACHABLE abbrev for FUNCTION_BLOCK.
2883  auto Abbv = std::make_shared<BitCodeAbbrev>();
2885  if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, std::move(Abbv)) !=
2886  (unsigned)FUNCTION_INST_UNREACHABLE_ABBREV)
2887  assert(false && "Unexpected abbrev ordering!");
2888  }
2889  {
2890  auto Abbv = std::make_shared<BitCodeAbbrev>();
2892  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
2893  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, // dest ty
2894  Log2_32_Ceil(VE.getTypes().size() + 1)));
2896  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
2897  if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, std::move(Abbv)) !=
2898  (unsigned)FUNCTION_INST_GEP_ABBREV)
2899  assert(false && "Unexpected abbrev ordering!");
2900  }
2901 
2902  Stream.ExitBlock();
2903 }
2904 
2905 void DXILBitcodeWriter::writeModuleVersion() {
2906  // VERSION: [version#]
2908 }
2909 
2910 /// WriteModule - Emit the specified module to the bitstream.
2912  // The identification block is new since llvm-3.7, but the old bitcode reader
2913  // will skip it.
2914  // writeIdentificationBlock(Stream);
2915 
2916  Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 3);
2917 
2918  // It is redundant to fully-specify this here, but nice to make it explicit
2919  // so that it is clear the DXIL module version is different.
2920  DXILBitcodeWriter::writeModuleVersion();
2921 
2922  // Emit blockinfo, which defines the standard abbreviations etc.
2923  writeBlockInfo();
2924 
2925  // Emit information about attribute groups.
2926  writeAttributeGroupTable();
2927 
2928  // Emit information about parameter attributes.
2929  writeAttributeTable();
2930 
2931  // Emit information describing all of the types in the module.
2932  writeTypeTable();
2933 
2934  writeComdats();
2935 
2936  // Emit top-level description of module, including target triple, inline asm,
2937  // descriptors for global variables, and function prototype info.
2938  writeModuleInfo();
2939 
2940  // Emit constants.
2941  writeModuleConstants();
2942 
2943  // Emit metadata.
2944  writeModuleMetadataKinds();
2945 
2946  // Emit metadata.
2947  writeModuleMetadata();
2948 
2949  // Emit names for globals/functions etc.
2950  // DXIL uses the same format for module-level value symbol table as for the
2951  // function level table.
2952  writeFunctionLevelValueSymbolTable(M.getValueSymbolTable());
2953 
2954  // Emit module-level use-lists.
2955  writeUseListBlock(nullptr);
2956 
2957  // Emit function bodies.
2958  for (const Function &F : M)
2959  if (!F.isDeclaration())
2960  writeFunction(F);
2961 
2962  Stream.ExitBlock();
2963 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:77
llvm::bitc::CST_CODE_CE_SHUFFLEVEC
@ CST_CODE_CE_SHUFFLEVEC
Definition: LLVMBitCodes.h:373
i
i
Definition: README.txt:29
llvm::InvokeInst::getNormalDest
BasicBlock * getNormalDest() const
Definition: Instructions.h:3895
llvm::bitc::CST_CODE_BLOCKADDRESS
@ CST_CODE_BLOCKADDRESS
Definition: LLVMBitCodes.h:379
llvm::bitc::CST_CODE_NULL
@ CST_CODE_NULL
Definition: LLVMBitCodes.h:359
llvm::Attribute::EndAttrKinds
@ EndAttrKinds
Sentinal value useful for loops.
Definition: Attributes.h:89
llvm::Type::ArrayTyID
@ ArrayTyID
Arrays.
Definition: Type.h:75
llvm::bitc::FUNC_CODE_INST_LANDINGPAD
@ FUNC_CODE_INST_LANDINGPAD
Definition: LLVMBitCodes.h:579
llvm::AtomicOrdering::AcquireRelease
@ AcquireRelease
llvm::Type::FloatTyID
@ FloatTyID
32-bit floating point type
Definition: Type.h:58
Attrs
Function Attrs
Definition: README_ALTIVEC.txt:215
llvm::dxil::DXILBitcodeWriter::DXILBitcodeWriter
DXILBitcodeWriter(const Module &M, SmallVectorImpl< char > &Buffer, StringTableBuilder &StrtabBuilder, BitstreamWriter &Stream)
Constructs a ModuleBitcodeWriter object for the given Module, writing to the provided Buffer.
Definition: DXILBitcodeWriter.cpp:131
llvm::bitc::ATTR_KIND_SANITIZE_MEMORY
@ ATTR_KIND_SANITIZE_MEMORY
Definition: LLVMBitCodes.h:637
llvm::DIArgList
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
Definition: DebugInfoMetadata.h:3565
llvm::Type::DoubleTyID
@ DoubleTyID
64-bit floating point type
Definition: Type.h:59
GlobalIFunc.h
llvm::ValueSymbolTable::empty
bool empty() const
Definition: ValueSymbolTable.h:83
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::bitc::ATTR_KIND_BY_VAL
@ ATTR_KIND_BY_VAL
Definition: LLVMBitCodes.h:608
llvm::LandingPadInst::isCleanup
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
Definition: Instructions.h:2950
llvm::bitc::NoInfs
@ NoInfs
Definition: LLVMBitCodes.h:477
llvm::bitc::FUNC_CODE_INST_RET
@ FUNC_CODE_INST_RET
Definition: LLVMBitCodes.h:524
llvm::bitc::CST_CODE_CE_SHUFVEC_EX
@ CST_CODE_CE_SHUFVEC_EX
Definition: LLVMBitCodes.h:377
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::AttributeSet::hasAttributes
bool hasAttributes() const
Return true if attributes exists in this set.
Definition: Attributes.h:350
llvm::AArch64CC::AL
@ AL
Definition: AArch64BaseInfo.h:269
llvm::bitc::FUNC_CODE_INST_STOREATOMIC
@ FUNC_CODE_INST_STOREATOMIC
Definition: LLVMBitCodes.h:575
Comdat.h
llvm::NamedMDNode
A tuple of MDNodes.
Definition: Metadata.h:1572
llvm::StringMapEntry
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMapEntry.h:101
llvm::dxil::BitcodeWriter::BitcodeWriter
BitcodeWriter(SmallVectorImpl< char > &Buffer, raw_fd_stream *FS=nullptr)
Create a BitcodeWriter that writes to Buffer.
Definition: DXILBitcodeWriter.cpp:361
llvm::GlobalValue::LinkOnceAnyLinkage
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
Definition: GlobalValue.h:50
Metadata.h
llvm::bitc::BINOP_AND
@ BINOP_AND
Definition: LLVMBitCodes.h:440
llvm::Comdat::ExactMatch
@ ExactMatch
The data referenced by the COMDAT must be the same.
Definition: Comdat.h:37
llvm::dxil::ValueEnumerator::getAttributeGroupID
unsigned getAttributeGroupID(IndexAndAttrSet Group) const
Definition: DXILValueEnumerator.h:182
llvm::AllocaInst::getAlign
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Definition: Instructions.h:121
llvm::bitc::PARAMATTR_GROUP_BLOCK_ID
@ PARAMATTR_GROUP_BLOCK_ID
Definition: LLVMBitCodes.h:34
DebugInfoMetadata.h
llvm::MDString::bytes_begin
const unsigned char * bytes_begin() const
Definition: Metadata.h:641
llvm::Function::empty
bool empty() const
Definition: Function.h:732
llvm::GlobalValue::LocalDynamicTLSModel
@ LocalDynamicTLSModel
Definition: GlobalValue.h:186
llvm::bitc::RMW_OR
@ RMW_OR
Definition: LLVMBitCodes.h:454
llvm::GlobalValue::getLinkage
LinkageTypes getLinkage() const
Definition: GlobalValue.h:509
llvm::DIGenericSubrange
Definition: DebugInfoMetadata.h:363
llvm::GlobalValue::HiddenVisibility
@ HiddenVisibility
The GV is hidden.
Definition: GlobalValue.h:64
T
llvm::bitc::METADATA_DISTINCT_NODE
@ METADATA_DISTINCT_NODE
Definition: LLVMBitCodes.h:311
llvm::bitc::FUNC_CODE_INST_INSERTELT
@ FUNC_CODE_INST_INSERTELT
Definition: LLVMBitCodes.h:520
llvm::Function
Definition: Function.h:60
llvm::Attribute
Definition: Attributes.h:65
llvm::bitc::ATTR_KIND_READ_ONLY
@ ATTR_KIND_READ_ONLY
Definition: LLVMBitCodes.h:626
llvm::Instruction::isCast
bool isCast() const
Definition: Instruction.h:165
llvm::Type::VoidTyID
@ VoidTyID
type with no size
Definition: Type.h:63
llvm::BitCodeAbbrevOp::isChar6
static bool isChar6(char C)
isChar6 - Return true if this character is legal in the Char6 encoding.
Definition: BitCodes.h:82
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::dxil::ValueEnumerator::purgeFunction
void purgeFunction()
llvm::bitc::ATTR_KIND_NO_RETURN
@ ATTR_KIND_NO_RETURN
Definition: LLVMBitCodes.h:622
llvm::bitc::TYPE_CODE_LABEL
@ TYPE_CODE_LABEL
Definition: LLVMBitCodes.h:142
llvm::bitc::ATTR_KIND_OPTIMIZE_FOR_SIZE
@ ATTR_KIND_OPTIMIZE_FOR_SIZE
Definition: LLVMBitCodes.h:624
llvm::AtomicRMWInst::Xor
@ Xor
*p = old ^ v
Definition: Instructions.h:740
llvm::bitc::ATTR_KIND_ARGMEMONLY
@ ATTR_KIND_ARGMEMONLY
Definition: LLVMBitCodes.h:650
llvm::bitc::RMW_XCHG
@ RMW_XCHG
Definition: LLVMBitCodes.h:449
llvm::bitc::MODULE_CODE_COMDAT
@ MODULE_CODE_COMDAT
Definition: LLVMBitCodes.h:106
llvm::bitc::CST_CODE_CE_INSERTELT
@ CST_CODE_CE_INSERTELT
Definition: LLVMBitCodes.h:372
llvm::bitc::FUNC_CODE_INST_VSELECT
@ FUNC_CODE_INST_VSELECT
Definition: LLVMBitCodes.h:550
llvm::Attribute::TombstoneKey
@ TombstoneKey
Use as Tombstone key for DenseMap of AttrKind.
Definition: Attributes.h:91
llvm::bitc::ATTR_KIND_STACK_PROTECT
@ ATTR_KIND_STACK_PROTECT
Definition: LLVMBitCodes.h:631
rotateSign
static uint64_t rotateSign(APInt Val)
Definition: DXILBitcodeWriter.cpp:1401
llvm::bitc::ATTR_KIND_IN_ALLOCA
@ ATTR_KIND_IN_ALLOCA
Definition: LLVMBitCodes.h:643
llvm::bitc::MODULE_BLOCK_ID
@ MODULE_BLOCK_ID
Definition: LLVMBitCodes.h:30
llvm::bitc::CST_CODE_CE_CAST
@ CST_CODE_CE_CAST
Definition: LLVMBitCodes.h:368
llvm::GlobalValue::NotThreadLocal
@ NotThreadLocal
Definition: GlobalValue.h:184
llvm::BitCodeAbbrevOp::Fixed
@ Fixed
Definition: BitCodes.h:39
llvm::ConstantInt::getValue
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:133
llvm::Comdat::NoDeduplicate
@ NoDeduplicate
No deduplication is performed.
Definition: Comdat.h:39
llvm::AtomicRMWInst::BinOp
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Definition: Instructions.h:726
llvm::DILexicalBlockFile
Definition: DebugInfoMetadata.h:2140
llvm::SmallVector< uint64_t, 64 >
llvm::tgtok::Code
@ Code
Definition: TGLexer.h:50
InlineAsm.h
llvm::bitc::METADATA_SUBRANGE
@ METADATA_SUBRANGE
Definition: LLVMBitCodes.h:319
llvm::LandingPadInst
The landingpad instruction holds all of the information necessary to generate correct exception handl...
Definition: Instructions.h:2903
llvm::bitc::ATTR_KIND_CONVERGENT
@ ATTR_KIND_CONVERGENT
Definition: LLVMBitCodes.h:648
llvm::DIStringType
String type, Fortran CHARACTER(n)
Definition: DebugInfoMetadata.h:832
llvm::APInt::getSExtValue
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1478
llvm::bitc::CAST_TRUNC
@ CAST_TRUNC
Definition: LLVMBitCodes.h:402
ErrorHandling.h
llvm::GlobalValue::UnnamedAddr::None
@ None
DXILValueEnumerator.h
llvm::bitc::ATTR_KIND_S_EXT
@ ATTR_KIND_S_EXT
Definition: LLVMBitCodes.h:629
llvm::bitc::SYMTAB_BLOB
@ SYMTAB_BLOB
Definition: LLVMBitCodes.h:704
llvm::StringTableBuilder::finalizeInOrder
void finalizeInOrder()
Finalize the string table without reording it.
Definition: StringTableBuilder.cpp:133
llvm::bitc::FUNC_CODE_INST_ATOMICRMW
@ FUNC_CODE_INST_ATOMICRMW
Definition: LLVMBitCodes.h:593
llvm::GlobalVariable
Definition: GlobalVariable.h:39
llvm::PointerType::getAddressSpace
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:682
llvm::Type::X86_AMXTyID
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
Definition: Type.h:67
llvm::GlobalAlias
Definition: GlobalAlias.h:28
llvm::bitc::RMW_NAND
@ RMW_NAND
Definition: LLVMBitCodes.h:453
llvm::dxil::DXILBitcodeWriter::getAttrKindEncoding
static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind)
Definition: DXILBitcodeWriter.cpp:637
llvm::AtomicOrdering::SequentiallyConsistent
@ SequentiallyConsistent
llvm::Attribute::EmptyKey
@ EmptyKey
Use as Empty key for DenseMap of AttrKind.
Definition: Attributes.h:90
llvm::bitc::ATTR_KIND_NO_BUILTIN
@ ATTR_KIND_NO_BUILTIN
Definition: LLVMBitCodes.h:615
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
llvm::bitc::COMDAT_SELECTION_KIND_NO_DUPLICATES
@ COMDAT_SELECTION_KIND_NO_DUPLICATES
Definition: LLVMBitCodes.h:695
llvm::dxil::DXILBitcodeWriter::getEncodedBinaryOpcode
static unsigned getEncodedBinaryOpcode(unsigned Opcode)
Definition: DXILBitcodeWriter.cpp:514
llvm::bitc::CST_CODE_INTEGER
@ CST_CODE_INTEGER
Definition: LLVMBitCodes.h:361
llvm::bitc::METADATA_BASIC_TYPE
@ METADATA_BASIC_TYPE
Definition: LLVMBitCodes.h:321
llvm::DILocation
Debug location.
Definition: DebugInfoMetadata.h:1557
llvm::bitc::ATTR_KIND_NON_LAZY_BIND
@ ATTR_KIND_NON_LAZY_BIND
Definition: LLVMBitCodes.h:620
llvm::bitc::CST_CODE_CE_EXTRACTELT
@ CST_CODE_CE_EXTRACTELT
Definition: LLVMBitCodes.h:371
llvm::dxil::ValueEnumerator::getInstructionID
unsigned getInstructionID(const Instruction *I) const
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::dxil::DXILBitcodeWriter::getEncodedDLLStorageClass
static unsigned getEncodedDLLStorageClass(const GlobalValue &GV)
Definition: DXILBitcodeWriter.cpp:840
Module.h
llvm::AttributeList
Definition: Attributes.h:425
llvm::tgtok::Bits
@ Bits
Definition: TGLexer.h:50
llvm::CallBase::getAttributes
AttributeList getAttributes() const
Return the parameter attributes for this call.
Definition: InstrTypes.h:1474
llvm::bitc::ATTR_KIND_NEST
@ ATTR_KIND_NEST
Definition: LLVMBitCodes.h:613
BitcodeCommon.h
llvm::bitc::BINOP_XOR
@ BINOP_XOR
Definition: LLVMBitCodes.h:442
llvm::CallBase::getFunctionType
FunctionType * getFunctionType() const
Definition: InstrTypes.h:1254
llvm::bitc::PARAMATTR_CODE_ENTRY
@ PARAMATTR_CODE_ENTRY
Definition: LLVMBitCodes.h:130
llvm::bitc::BINOP_SDIV
@ BINOP_SDIV
Definition: LLVMBitCodes.h:434
llvm::GlobalValue::DefaultStorageClass
@ DefaultStorageClass
Definition: GlobalValue.h:70
llvm::bitc::TYPE_CODE_HALF
@ TYPE_CODE_HALF
Definition: LLVMBitCodes.h:150
llvm::bitc::TYPE_CODE_VOID
@ TYPE_CODE_VOID
Definition: LLVMBitCodes.h:139
llvm::bitc::ORDERING_ACQUIRE
@ ORDERING_ACQUIRE
Definition: LLVMBitCodes.h:494
llvm::bitc::FUNC_CODE_INST_ALLOCA
@ FUNC_CODE_INST_ALLOCA
Definition: LLVMBitCodes.h:534
llvm::bitc::RMW_UMIN
@ RMW_UMIN
Definition: LLVMBitCodes.h:459
llvm::bitc::MODULE_CODE_GLOBALVAR
@ MODULE_CODE_GLOBALVAR
Definition: LLVMBitCodes.h:96
llvm::bitc::TYPE_CODE_DOUBLE
@ TYPE_CODE_DOUBLE
Definition: LLVMBitCodes.h:141
llvm::Type::isX86_FP80Ty
bool isX86_FP80Ty() const
Return true if this is x86 long double.
Definition: Type.h:154
llvm::GlobalValue::DefaultVisibility
@ DefaultVisibility
The GV is visible.
Definition: GlobalValue.h:63
GlobalObject.h
llvm::MCID::Convergent
@ Convergent
Definition: MCInstrDesc.h:184
llvm::Comdat::Largest
@ Largest
The linker will choose the largest COMDAT.
Definition: Comdat.h:38
Operator.h
llvm::VectorType::getElementType
Type * getElementType() const
Definition: DerivedTypes.h:422
llvm::bitc::CAST_ZEXT
@ CAST_ZEXT
Definition: LLVMBitCodes.h:403
getBitWidth
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
Definition: ValueTracking.cpp:98
llvm::max
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:337
llvm::bitc::METADATA_EXPRESSION
@ METADATA_EXPRESSION
Definition: LLVMBitCodes.h:335
llvm::bitc::CST_CODE_FLOAT
@ CST_CODE_FLOAT
Definition: LLVMBitCodes.h:363
llvm::FunctionType::getNumParams
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Definition: DerivedTypes.h:139
llvm::bitc::USELIST_CODE_BB
@ USELIST_CODE_BB
Definition: LLVMBitCodes.h:601
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:119
llvm::dxil::DXILBitcodeWriter::emitWideAPInt
static void emitWideAPInt(SmallVectorImpl< uint64_t > &Vals, const APInt &A)
Definition: DXILBitcodeWriter.cpp:752
llvm::dxil::ValueEnumerator::UseListOrders
UseListOrderStack UseListOrders
Definition: DXILValueEnumerator.h:57
llvm::DIExpression
DWARF expression.
Definition: DebugInfoMetadata.h:2558
llvm::GlobalValue::LinkageTypes
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:47
llvm::ArrayType
Class to represent array types.
Definition: DerivedTypes.h:357
llvm::bitc::ATTR_KIND_DEREFERENCEABLE_OR_NULL
@ ATTR_KIND_DEREFERENCEABLE_OR_NULL
Definition: LLVMBitCodes.h:647
llvm::dxil::LastPlusOne
@ LastPlusOne
Definition: DXILBitcodeWriter.cpp:60
llvm::bitc::TYPE_CODE_X86_MMX
@ TYPE_CODE_X86_MMX
Definition: LLVMBitCodes.h:164
llvm::bitc::CAST_SEXT
@ CAST_SEXT
Definition: LLVMBitCodes.h:404
llvm::dxil::ValueEnumerator::setInstructionID
void setInstructionID(const Instruction *I)
llvm::GlobalValue::DLLImportStorageClass
@ DLLImportStorageClass
Function to be imported from DLL.
Definition: GlobalValue.h:71
llvm::Type::getNonOpaquePointerElementType
Type * getNonOpaquePointerElementType() const
Only use this method in code that is not reachable with opaque pointers, or part of deprecated method...
Definition: Type.h:382
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1043
llvm::bitc::BINOP_ASHR
@ BINOP_ASHR
Definition: LLVMBitCodes.h:439
p
the resulting code requires compare and branches when and if * p
Definition: README.txt:396
llvm::DINamespace
Definition: DebugInfoMetadata.h:2258
ModuleSummaryIndex.h
llvm::bitc::SYMTAB_BLOCK_ID
@ SYMTAB_BLOCK_ID
Definition: LLVMBitCodes.h:63
llvm::DILexicalBlock
Definition: DebugInfoMetadata.h:2087
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:159
llvm::bitc::ATTR_KIND_NO_CAPTURE
@ ATTR_KIND_NO_CAPTURE
Definition: LLVMBitCodes.h:616
llvm::bitc::CST_CODE_WIDE_INTEGER
@ CST_CODE_WIDE_INTEGER
Definition: LLVMBitCodes.h:362
llvm::bitc::ATTR_KIND_STRUCT_RET
@ ATTR_KIND_STRUCT_RET
Definition: LLVMBitCodes.h:634
llvm::bitc::ATTR_KIND_OPTIMIZE_NONE
@ ATTR_KIND_OPTIMIZE_NONE
Definition: LLVMBitCodes.h:642
new
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM ID Predecessors according to mbb< bb27, 0x8b0a7c0 > Note ADDri is not a two address instruction its result reg1037 is an operand of the PHI node in bb76 and its operand reg1039 is the result of the PHI node We should treat it as a two address code and make sure the ADDri is scheduled after any node that reads reg1039 Use info(i.e. register scavenger) to assign it a free register to allow reuse the collector could move the objects and invalidate the derived pointer This is bad enough in the first but safe points can crop up unpredictably **array_addr i32 n y store obj * new
Definition: README.txt:125
llvm::dxil::ValueEnumerator::getValueID
unsigned getValueID(const Value *V) const
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::bitc::ATTR_KIND_JUMP_TABLE
@ ATTR_KIND_JUMP_TABLE
Definition: LLVMBitCodes.h:645
llvm::bitc::METADATA_FILE
@ METADATA_FILE
Definition: LLVMBitCodes.h:322
llvm::FunctionType::isVarArg
bool isVarArg() const
Definition: DerivedTypes.h:123
llvm::AtomicOrdering::Monotonic
@ Monotonic
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:55
PointerTypeAnalysis.h
llvm::bitc::FUNC_CODE_INST_CAST
@ FUNC_CODE_INST_CAST
Definition: LLVMBitCodes.h:516
llvm::bitc::METADATA_NAMESPACE
@ METADATA_NAMESPACE
Definition: LLVMBitCodes.h:330
llvm::dxil::ValueEnumerator::getTypeID
unsigned getTypeID(Type *T) const
Definition: DXILValueEnumerator.h:165
llvm::bitc::ORDERING_NOTATOMIC
@ ORDERING_NOTATOMIC
Definition: LLVMBitCodes.h:491
Instruction.h
llvm::bitc::VALUE_SYMTAB_BLOCK_ID
@ VALUE_SYMTAB_BLOCK_ID
Definition: LLVMBitCodes.h:44
llvm::SPII::Load
@ Load
Definition: SparcInstrInfo.h:32
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition: Constants.h:79
llvm::DIObjCProperty
Definition: DebugInfoMetadata.h:3213
llvm::GlobalValueSummary
Function and variable summary information to aid decisions and implementation of importing.
Definition: ModuleSummaryIndex.h:289
llvm::Type::MetadataTyID
@ MetadataTyID
Metadata.
Definition: Type.h:65
GlobalValue.h
llvm::ConstantDataSequential
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
Definition: Constants.h:570
llvm::Type::FunctionTyID
@ FunctionTyID
Functions.
Definition: Type.h:72
llvm::ArrayType::getNumElements
uint64_t getNumElements() const
Definition: DerivedTypes.h:369
Constants.h
llvm::BitCodeAbbrevOp::Char6
@ Char6
Definition: BitCodes.h:42
llvm::PHINode::getIncomingValue
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
Definition: Instructions.h:2747
llvm::bitc::TYPE_CODE_INTEGER
@ TYPE_CODE_INTEGER
Definition: LLVMBitCodes.h:144
llvm::AllocaInst::getAllocatedType
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
Definition: Instructions.h:114
llvm::DILocalVariable
Local variable.
Definition: DebugInfoMetadata.h:3058
llvm::dxil::ValueEnumerator
Definition: DXILValueEnumerator.h:46
llvm::bitc::ATTR_KIND_NO_DUPLICATE
@ ATTR_KIND_NO_DUPLICATE
Definition: LLVMBitCodes.h:617
llvm::bitc::FUNC_CODE_INST_SHUFFLEVEC
@ FUNC_CODE_INST_SHUFFLEVEC
Definition: LLVMBitCodes.h:521
llvm::DIMacro
Definition: DebugInfoMetadata.h:3448
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::bitc::TYPE_CODE_VECTOR
@ TYPE_CODE_VECTOR
Definition: LLVMBitCodes.h:153
llvm::bitc::CST_CODE_SETTYPE
@ CST_CODE_SETTYPE
Definition: LLVMBitCodes.h:358
llvm::SmallVectorImpl::append
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:667
llvm::bitc::FUNC_CODE_INST_BINOP
@ FUNC_CODE_INST_BINOP
Definition: LLVMBitCodes.h:515
llvm::bitc::ATTR_KIND_UW_TABLE
@ ATTR_KIND_UW_TABLE
Definition: LLVMBitCodes.h:638
llvm::dxil::ValueEnumerator::getAttributeGroups
const std::vector< IndexAndAttrSet > & getAttributeGroups() const
Definition: DXILValueEnumerator.h:222
llvm::bitc::TYPE_CODE_OPAQUE
@ TYPE_CODE_OPAQUE
Definition: LLVMBitCodes.h:143
llvm::dxil::ValueEnumerator::getFunctionConstantRange
void getFunctionConstantRange(unsigned &Start, unsigned &End) const
getFunctionConstantRange - Return the range of values that corresponds to function-local constants.
Definition: DXILValueEnumerator.h:192
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::ARM_PROC::A
@ A
Definition: ARMBaseInfo.h:34
llvm::bitc::CAST_FPTOSI
@ CAST_FPTOSI
Definition: LLVMBitCodes.h:406
llvm::bitc::BINOP_SHL
@ BINOP_SHL
Definition: LLVMBitCodes.h:437
llvm::bitc::UNOP_FNEG
@ UNOP_FNEG
Definition: LLVMBitCodes.h:422
llvm::GlobalValue::getThreadLocalMode
ThreadLocalMode getThreadLocalMode() const
Definition: GlobalValue.h:257
llvm::LandingPadInst::getNumClauses
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
Definition: Instructions.h:2975
InstrTypes.h
llvm::Log2
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition: Alignment.h:209
llvm::CallBase::getCalledFunction
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Definition: InstrTypes.h:1396
llvm::GlobalObject
Definition: GlobalObject.h:27
llvm::bitc::METADATA_COMPILE_UNIT
@ METADATA_COMPILE_UNIT
Definition: LLVMBitCodes.h:326
llvm::dxil::DXILBitcodeWriter::writeStringRecord
static void writeStringRecord(BitstreamWriter &Stream, unsigned Code, StringRef Str, unsigned AbbrevToUse)
Definition: DXILBitcodeWriter.cpp:621
llvm::bitc::OBO_NO_SIGNED_WRAP
@ OBO_NO_SIGNED_WRAP
Definition: LLVMBitCodes.h:468
llvm::MDTuple
Tuple of metadata.
Definition: Metadata.h:1315
llvm::bitc::ATTR_KIND_ALIGNMENT
@ ATTR_KIND_ALIGNMENT
Definition: LLVMBitCodes.h:606
llvm::dxil::DXILBitcodeWriter::getEncodedUnaryOpcode
static unsigned getEncodedUnaryOpcode(unsigned Opcode)
Definition: DXILBitcodeWriter.cpp:505
llvm::dxil::ValueEnumerator::getComdatID
unsigned getComdatID(const Comdat *C) const
llvm::bitc::BINOP_OR
@ BINOP_OR
Definition: LLVMBitCodes.h:441
llvm::dxil::ValueEnumerator::getMDStrings
ArrayRef< const Metadata * > getMDStrings() const
Get the MDString metadata for this block.
Definition: DXILValueEnumerator.h:203
llvm::Comdat::Any
@ Any
The linker may choose any COMDAT.
Definition: Comdat.h:36
llvm::DISubrange
Array subrange.
Definition: DebugInfoMetadata.h:300
llvm::bitc::METADATA_ENUMERATOR
@ METADATA_ENUMERATOR
Definition: LLVMBitCodes.h:320
llvm::VectorType::getElementCount
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
Definition: DerivedTypes.h:627
llvm::dxil::BitcodeWriter::writeStrtab
void writeStrtab()
Write the bitcode file's string table.
llvm::DITemplateTypeParameter
Definition: DebugInfoMetadata.h:2403
llvm::MaybeAlign
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::dxil::DXILBitcodeWriter::emitSignedInt64
static void emitSignedInt64(SmallVectorImpl< uint64_t > &Vals, uint64_t V)
Definition: DXILBitcodeWriter.cpp:744
llvm::bitc::METADATA_LEXICAL_BLOCK
@ METADATA_LEXICAL_BLOCK
Definition: LLVMBitCodes.h:328
llvm::bitc::METADATA_MODULE
@ METADATA_MODULE
Definition: LLVMBitCodes.h:338
llvm::BitstreamWriter
Definition: BitstreamWriter.h:30
llvm::Instruction
Definition: Instruction.h:42
llvm::StringTableBuilder::getSize
size_t getSize() const
Definition: StringTableBuilder.h:82
llvm::bitc::MODULE_CODE_GCNAME
@ MODULE_CODE_GCNAME
Definition: LLVMBitCodes.h:105
llvm::ExtractValueInst::idx_end
idx_iterator idx_end() const
Definition: Instructions.h:2448
llvm::raw_ostream::write
raw_ostream & write(unsigned char C)
Definition: raw_ostream.cpp:219
llvm::dxil::ValueEnumerator::getBasicBlocks
const std::vector< const BasicBlock * > & getBasicBlocks() const
Definition: DXILValueEnumerator.h:214
llvm::dxil::ValueEnumerator::getAttributeListID
unsigned getAttributeListID(AttributeList PAL) const
Definition: DXILValueEnumerator.h:174
llvm::AtomicOrdering::Acquire
@ Acquire
llvm::AtomicRMWInst::Nand
@ Nand
*p = ~(old & v)
Definition: Instructions.h:736
llvm::bitc::CAST_PTRTOINT
@ CAST_PTRTOINT
Definition: LLVMBitCodes.h:411
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::ConstantFP
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:257
llvm::bitc::BINOP_SREM
@ BINOP_SREM
Definition: LLVMBitCodes.h:436
llvm::bitc::METADATA_LOCATION
@ METADATA_LOCATION
Definition: LLVMBitCodes.h:313
llvm::bitc::NoNaNs
@ NoNaNs
Definition: LLVMBitCodes.h:476
llvm::Comdat::SameSize
@ SameSize
The data referenced by the COMDAT must be the same size.
Definition: Comdat.h:40
llvm::FunctionType::params
ArrayRef< Type * > params() const
Definition: DerivedTypes.h:130
llvm::dxil::ValueEnumerator::getNonMDStrings
ArrayRef< const Metadata * > getNonMDStrings() const
Get the non-MDString metadata for this block.
Definition: DXILValueEnumerator.h:208
llvm::encode
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
Definition: Alignment.h:218
DebugLoc.h
llvm::bitc::METADATA_NAME
@ METADATA_NAME
Definition: LLVMBitCodes.h:310
llvm::bitc::FUNC_CODE_INST_PHI
@ FUNC_CODE_INST_PHI
Definition: LLVMBitCodes.h:531
llvm::bitc::ATTR_KIND_STACK_PROTECT_REQ
@ ATTR_KIND_STACK_PROTECT_REQ
Definition: LLVMBitCodes.h:632
llvm::Type::PointerTyID
@ PointerTyID
Pointers.
Definition: Type.h:73
llvm::dxil::TypedPointerType
Definition: DXILPointerType.h:22
llvm::dxil::DXILBitcodeWriter::getEncodedCastOpcode
static unsigned getEncodedCastOpcode(unsigned Opcode)
Begin dxil::BitcodeWriterBase Implementation.
Definition: DXILBitcodeWriter.cpp:472
llvm::CallInst::isTailCall
bool isTailCall() const
Definition: Instructions.h:1655
llvm::GlobalValue::InternalLinkage
@ InternalLinkage
Rename collisions when linking (static functions).
Definition: GlobalValue.h:55
llvm::MCID::Call
@ Call
Definition: MCInstrDesc.h:155
llvm::Comdat
Definition: Comdat.h:33
llvm::Metadata
Root of the metadata hierarchy.
Definition: Metadata.h:62
llvm::bitc::METADATA_COMPOSITE_TYPE
@ METADATA_COMPOSITE_TYPE
Definition: LLVMBitCodes.h:324
llvm::SPII::Store
@ Store
Definition: SparcInstrInfo.h:33
llvm::bitc::ATTR_KIND_INLINE_HINT
@ ATTR_KIND_INLINE_HINT
Definition: LLVMBitCodes.h:609
llvm::AtomicRMWInst::Xchg
@ Xchg
*p = v
Definition: Instructions.h:728
llvm::AddressSpace
AddressSpace
Definition: NVPTXBaseInfo.h:21
llvm::CallBase::getCallingConv
CallingConv::ID getCallingConv() const
Definition: InstrTypes.h:1455
llvm::Type::BFloatTyID
@ BFloatTyID
16-bit floating point type (7-bit significand)
Definition: Type.h:57
llvm::bitc::MODULE_CODE_FUNCTION
@ MODULE_CODE_FUNCTION
Definition: LLVMBitCodes.h:100
llvm::bitc::TYPE_CODE_STRUCT_ANON
@ TYPE_CODE_STRUCT_ANON
Definition: LLVMBitCodes.h:166
llvm::PHINode::getNumIncomingValues
unsigned getNumIncomingValues() const
Return the number of incoming edges.
Definition: Instructions.h:2743
llvm::BitCodeAbbrevOp::Blob
@ Blob
Definition: BitCodes.h:43
llvm::AtomicRMWInst::Add
@ Add
*p = old + v
Definition: Instructions.h:730
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::BWH_HeaderSize
@ BWH_HeaderSize
Definition: BitCodeEnums.h:32
Type.h
llvm::bitc::TYPE_CODE_ARRAY
@ TYPE_CODE_ARRAY
Definition: LLVMBitCodes.h:152
llvm::Log2_32_Ceil
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:636
llvm::ValueInfo
Struct that holds a reference to a particular GUID in a global value summary.
Definition: ModuleSummaryIndex.h:167
llvm::bitc::FUNC_CODE_INST_STORE
@ FUNC_CODE_INST_STORE
Definition: LLVMBitCodes.h:574
llvm::Record::dump
void dump() const
Definition: Record.cpp:2544
llvm::dxil::PointerTypeAnalysis::run
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
Definition: PointerTypeAnalysis.cpp:101
llvm::dxil::ValueEnumerator::IndexAndAttrSet
std::pair< unsigned, AttributeSet > IndexAndAttrSet
Attribute groups as encoded in bitcode are almost AttributeSets, but they include the AttributeList i...
Definition: DXILValueEnumerator.h:55
llvm::BranchInst::getCondition
Value * getCondition() const
Definition: Instructions.h:3167
ValueSymbolTable.h
llvm::Type::DXILPointerTyID
@ DXILPointerTyID
DXIL typed pointer used by DirectX target.
Definition: Type.h:78
llvm::InvokeInst
Invoke instruction.
Definition: Instructions.h:3763
llvm::bitc::FUNC_CODE_INST_INSERTVAL
@ FUNC_CODE_INST_INSERTVAL
Definition: LLVMBitCodes.h:545
llvm::GlobalValue::DLLExportStorageClass
@ DLLExportStorageClass
Function to be accessible from DLL.
Definition: GlobalValue.h:72
llvm::DICommonBlock
Definition: DebugInfoMetadata.h:2999
llvm::InlineAsm
Definition: InlineAsm.h:31
llvm::VectorType
Base class of all SIMD vector types.
Definition: DerivedTypes.h:389
llvm::bitc::TYPE_CODE_X86_FP80
@ TYPE_CODE_X86_FP80
Definition: LLVMBitCodes.h:158
llvm::bitc::CAST_FPEXT
@ CAST_FPEXT
Definition: LLVMBitCodes.h:410
llvm::bitc::FUNC_CODE_INST_INVOKE
@ FUNC_CODE_INST_INVOKE
Definition: LLVMBitCodes.h:527
llvm::bitc::METADATA_KIND
@ METADATA_KIND
Definition: LLVMBitCodes.h:312
llvm::Type::getArrayElementType
Type * getArrayElementType() const
Definition: Type.h:365
llvm::AtomicOrdering
AtomicOrdering
Atomic ordering for LLVM's memory model.
Definition: AtomicOrdering.h:56
llvm::bitc::FUNC_CODE_INST_CMP2
@ FUNC_CODE_INST_CMP2
Definition: LLVMBitCodes.h:548
llvm::AtomicRMWInst::UMin
@ UMin
*p = old <unsigned v ? old : v
Definition: Instructions.h:748
BasicBlock.h
IRSymtab.h
llvm::MDString::bytes_end
const unsigned char * bytes_end() const
Definition: Metadata.h:642
llvm::GlobalValue
Definition: GlobalValue.h:44
VI
@ VI
Definition: SIInstrInfo.cpp:7845
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::dxil::ValueEnumerator::getValues
const ValueList & getValues() const
Definition: DXILValueEnumerator.h:197
llvm::dxil
Definition: DXILPointerType.h:18
llvm::bitc::ATTR_KIND_NO_ALIAS
@ ATTR_KIND_NO_ALIAS
Definition: LLVMBitCodes.h:614
llvm::dxil::ValueEnumerator::computeBitsRequiredForTypeIndicies
uint64_t computeBitsRequiredForTypeIndicies() const
llvm::bitc::TYPE_CODE_POINTER
@ TYPE_CODE_POINTER
Definition: LLVMBitCodes.h:145
llvm::dxil::ValueEnumerator::getTypes
const TypeList & getTypes() const
Definition: DXILValueEnumerator.h:212
llvm::DIEnumerator
Enumeration value.
Definition: DebugInfoMetadata.h:411
llvm::isUInt< 16 >
constexpr bool isUInt< 16 >(uint64_t x)
Definition: MathExtras.h:408
llvm::AtomicRMWInst::Sub
@ Sub
*p = old - v
Definition: Instructions.h:732
llvm::StringRef::empty
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
llvm::bitc::ATTR_KIND_COLD
@ ATTR_KIND_COLD
Definition: LLVMBitCodes.h:641
llvm::bitc::TYPE_CODE_FLOAT
@ TYPE_CODE_FLOAT
Definition: LLVMBitCodes.h:140
llvm::bitc::PARAMATTR_BLOCK_ID
@ PARAMATTR_BLOCK_ID
Definition: LLVMBitCodes.h:33
uint64_t
llvm::bitc::CST_CODE_CE_CMP
@ CST_CODE_CE_CMP
Definition: LLVMBitCodes.h:374
llvm::APInt::getRawData
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
Definition: APInt.h:550
llvm::GlobalValue::getVisibility
VisibilityTypes getVisibility() const
Definition: GlobalValue.h:234
llvm::StringRef::end
iterator end() const
Definition: StringRef.h:130
llvm::Attribute::None
@ None
No attributes have been set.
Definition: Attributes.h:86
llvm::bitc::CST_CODE_CE_BINOP
@ CST_CODE_CE_BINOP
Definition: LLVMBitCodes.h:367
llvm::GlobalValue::GeneralDynamicTLSModel
@ GeneralDynamicTLSModel
Definition: GlobalValue.h:185
llvm::Type::X86_MMXTyID
@ X86_MMXTyID
MMX vectors (64 bits, X86 specific)
Definition: Type.h:66
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
llvm::bitc::USELIST_CODE_DEFAULT
@ USELIST_CODE_DEFAULT
Definition: LLVMBitCodes.h:600
llvm::bitc::METADATA_DERIVED_TYPE
@ METADATA_DERIVED_TYPE
Definition: LLVMBitCodes.h:323
llvm::bitc::ATTR_KIND_NAKED
@ ATTR_KIND_NAKED
Definition: LLVMBitCodes.h:612
llvm::GlobalValue::WeakAnyLinkage
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
Definition: GlobalValue.h:52
llvm::bitc::RMW_FSUB
@ RMW_FSUB
Definition: LLVMBitCodes.h:461
llvm::dxil::BitcodeWriter::writeSymtab
void writeSymtab()
Attempt to write a symbol table to the bitcode file.
llvm::DIGlobalVariable
Global variables.
Definition: DebugInfoMetadata.h:2914
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::bitc::RMW_XOR
@ RMW_XOR
Definition: LLVMBitCodes.h:455
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
llvm::dxil::DXILBitcodeWriter::write
void write()
Emit the current module to the bitstream.
Definition: DXILBitcodeWriter.cpp:2911
llvm::bitc::FUNC_CODE_INST_LOADATOMIC
@ FUNC_CODE_INST_LOADATOMIC
Definition: LLVMBitCodes.h:569
llvm::DenseMap< const Value *, Type * >
llvm::SyncScope::ID
uint8_t ID
Definition: LLVMContext.h:47
llvm::GlobalValue::getDLLStorageClass
DLLStorageClassTypes getDLLStorageClass() const
Definition: GlobalValue.h:261
llvm::bitc::FUNC_CODE_INST_CALL
@ FUNC_CODE_INST_CALL
Definition: LLVMBitCodes.h:556
llvm::ExtractValueInst::idx_begin
idx_iterator idx_begin() const
Definition: Instructions.h:2447
llvm::AtomicOrdering::Unordered
@ Unordered
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::bitc::BINOP_UDIV
@ BINOP_UDIV
Definition: LLVMBitCodes.h:433
llvm::FunctionType::getParamType
Type * getParamType(unsigned i) const
Parameter type accessors.
Definition: DerivedTypes.h:135
llvm::bitc::CST_CODE_CE_GEP
@ CST_CODE_CE_GEP
Definition: LLVMBitCodes.h:369
llvm::bitc::RMW_MIN
@ RMW_MIN
Definition: LLVMBitCodes.h:457
llvm::AtomicRMWInst::Min
@ Min
*p = old <signed v ? old : v
Definition: Instructions.h:744
llvm::Attribute::AttrKind
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition: Attributes.h:84
llvm::bitc::METADATA_STRING_OLD
@ METADATA_STRING_OLD
Definition: LLVMBitCodes.h:307
llvm::DICompileUnit
Compile unit.
Definition: DebugInfoMetadata.h:1322
llvm::DIImportedEntity
An imported module (C++ using directive or similar).
Definition: DebugInfoMetadata.h:3293
llvm::bitc::CAST_INTTOPTR
@ CAST_INTTOPTR
Definition: LLVMBitCodes.h:412
llvm::PointerType
Class to represent pointers.
Definition: DerivedTypes.h:632
llvm::AtomicRMWInst::Or
@ Or
*p = old | v
Definition: Instructions.h:738
llvm::bitc::METADATA_NAMED_NODE
@ METADATA_NAMED_NODE
Definition: LLVMBitCodes.h:316
llvm::bitc::BINOP_UREM
@ BINOP_UREM
Definition: LLVMBitCodes.h:435
llvm::bitc::CAST_ADDRSPACECAST
@ CAST_ADDRSPACECAST
Definition: LLVMBitCodes.h:414
llvm::bitc::MODULE_CODE_SECTIONNAME
@ MODULE_CODE_SECTIONNAME
Definition: LLVMBitCodes.h:89
llvm::bitc::ATTR_KIND_MIN_SIZE
@ ATTR_KIND_MIN_SIZE
Definition: LLVMBitCodes.h:611
llvm::LandingPadInst::getClause
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
Definition: Instructions.h:2960
llvm::Type::isHalfTy
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
Definition: Type.h:142
llvm::BitCodeAbbrevOp::VBR
@ VBR
Definition: BitCodes.h:40
llvm::BitCodeAbbrevOp::Array
@ Array
Definition: BitCodes.h:41
llvm::bitc::METADATA_SUBROUTINE_TYPE
@ METADATA_SUBROUTINE_TYPE
Definition: LLVMBitCodes.h:325
llvm::bitc::RMW_MAX
@ RMW_MAX
Definition: LLVMBitCodes.h:456
llvm::bitc::MODULE_CODE_DATALAYOUT
@ MODULE_CODE_DATALAYOUT
Definition: LLVMBitCodes.h:87
llvm::DenseMapBase::find
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:152
llvm::DIMacroFile
Definition: DebugInfoMetadata.h:3499
llvm::InsertValueInst::idx_begin
idx_iterator idx_begin() const
Definition: Instructions.h:2567
llvm::dxil::BitcodeWriter::writeModule
void writeModule(const Module &M)
Write the specified module to the buffer specified at construction time.
Definition: DXILBitcodeWriter.cpp:454
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::X86AS::FS
@ FS
Definition: X86.h:192
llvm::bitc::METADATA_NODE
@ METADATA_NODE
Definition: LLVMBitCodes.h:309
llvm::SPIRV::Decoration::Stream
@ Stream
SI
StandardInstrumentations SI(Debug, VerifyEach)
llvm::bitc::BINOP_SUB
@ BINOP_SUB
Definition: LLVMBitCodes.h:431
llvm::InsertValueInst::idx_end
idx_iterator idx_end() const
Definition: Instructions.h:2568
llvm::bitc::MODULE_CODE_ASM
@ MODULE_CODE_ASM
Definition: LLVMBitCodes.h:88
llvm::bitc::PARAMATTR_GRP_CODE_ENTRY
@ PARAMATTR_GRP_CODE_ENTRY
Definition: LLVMBitCodes.h:131
llvm::WinEH::EncodingType::CE
@ CE
Windows NT (Windows on ARM)
llvm::bitc::CST_CODE_CE_SELECT
@ CST_CODE_CE_SELECT
Definition: LLVMBitCodes.h:370
llvm::Record
Definition: Record.h:1543
llvm::dxil::DXILBitcodeWriter::getEncodedOrdering
static unsigned getEncodedOrdering(AtomicOrdering Ordering)
Definition: DXILBitcodeWriter.cpp:601
llvm::ValueAsMetadata::getValue
Value * getValue() const
Definition: Metadata.h:385
llvm::ValID
ValID - Represents a reference of a definition of some sort with no type.
Definition: LLParser.h:51
llvm::bitc::NoSignedZeros
@ NoSignedZeros
Definition: LLVMBitCodes.h:478
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::MDNode
Metadata node.
Definition: Metadata.h:944
llvm::bitc::TYPE_CODE_STRUCT_NAME
@ TYPE_CODE_STRUCT_NAME
Definition: LLVMBitCodes.h:167
llvm::LinearPolySize::getKnownMinValue
ScalarTy getKnownMinValue() const
Returns the minimum value this size can represent.
Definition: TypeSize.h:296
llvm::bitc::ATTR_KIND_Z_EXT
@ ATTR_KIND_Z_EXT
Definition: LLVMBitCodes.h:639
llvm::dxil::BitcodeWriter::copyStrtab
void copyStrtab(StringRef Strtab)
Copy the string table for another module into this bitcode file.
llvm::StringTableBuilder::write
void write(raw_ostream &OS) const
Definition: StringTableBuilder.cpp:60
llvm::DIBasicType
Basic type, like 'int' or 'float'.
Definition: DebugInfoMetadata.h:764
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:75
llvm::bitc::TYPE_CODE_STRUCT_NAMED
@ TYPE_CODE_STRUCT_NAMED
Definition: LLVMBitCodes.h:168
llvm::dxil::ValueEnumerator::getAttributeLists
const std::vector< AttributeList > & getAttributeLists() const
Definition: DXILValueEnumerator.h:218
llvm::GlobalValue::AppendingLinkage
@ AppendingLinkage
Special purpose, only applies to global arrays.
Definition: GlobalValue.h:54
Triple.h
llvm::Type::FP128TyID
@ FP128TyID
128-bit floating point type (112-bit significand)
Definition: Type.h:61
llvm::DISubroutineType
Type array for a subprogram.
Definition: DebugInfoMetadata.h:1265
llvm::bitc::ORDERING_UNORDERED
@ ORDERING_UNORDERED
Definition: LLVMBitCodes.h:492
llvm::DICompositeType
Composite types.
Definition: DebugInfoMetadata.h:1042
llvm::bitc::MODULE_CODE_VERSION
@ MODULE_CODE_VERSION
Definition: LLVMBitCodes.h:85
llvm::BlockAddress
The address of a basic block.
Definition: Constants.h:849
llvm::bitc::AllowReassoc
@ AllowReassoc
Definition: LLVMBitCodes.h:482
llvm::dxil::ValueEnumerator::getMetadataID
unsigned getMetadataID(const Metadata *MD) const
Definition: DXILValueEnumerator.h:153
llvm::bitc::METADATA_TEMPLATE_VALUE
@ METADATA_TEMPLATE_VALUE
Definition: LLVMBitCodes.h:332
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::bitc::VST_CODE_ENTRY
@ VST_CODE_ENTRY
Definition: LLVMBitCodes.h:190
llvm::bitc::TYPE_CODE_PPC_FP128
@ TYPE_CODE_PPC_FP128
Definition: LLVMBitCodes.h:160
BitCodes.h
llvm::bitc::STRTAB_BLOCK_ID
@ STRTAB_BLOCK_ID
Definition: LLVMBitCodes.h:59
Mul
BinaryOperator * Mul
Definition: X86PartialReduction.cpp:70
DXILBitcodeWriter.h
llvm::StructType
Class to represent struct types.
Definition: DerivedTypes.h:213
llvm::bitc::TYPE_CODE_FUNCTION
@ TYPE_CODE_FUNCTION
Definition: LLVMBitCodes.h:170
llvm::dxil::DXILBitcodeWriter::getEncodedRMWOperation
static unsigned getEncodedRMWOperation(AtomicRMWInst::BinOp Op)
Definition: DXILBitcodeWriter.cpp:568
llvm::Type::PPC_FP128TyID
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
Definition: Type.h:62
llvm::UseListOrder
Structure to hold a use-list order.
Definition: UseListOrder.h:26
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::bitc::METADATA_LEXICAL_BLOCK_FILE
@ METADATA_LEXICAL_BLOCK_FILE
Definition: LLVMBitCodes.h:329
llvm::bitc::ORDERING_MONOTONIC
@ ORDERING_MONOTONIC
Definition: LLVMBitCodes.h:493
llvm::bitc::RMW_SUB
@ RMW_SUB
Definition: LLVMBitCodes.h:451
llvm::bitc::ATTR_KIND_SANITIZE_THREAD
@ ATTR_KIND_SANITIZE_THREAD
Definition: LLVMBitCodes.h:636
llvm::bitc::CST_CODE_CE_INBOUNDS_GEP
@ CST_CODE_CE_INBOUNDS_GEP
Definition: LLVMBitCodes.h:378
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
llvm::GlobalValue::WeakODRLinkage
@ WeakODRLinkage
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:53
uint32_t
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::bitc::ATTR_KIND_NO_RED_ZONE
@ ATTR_KIND_NO_RED_ZONE
Definition: LLVMBitCodes.h:621
llvm::bitc::ATTR_KIND_DEREFERENCEABLE
@ ATTR_KIND_DEREFERENCEABLE
Definition: LLVMBitCodes.h:646
llvm::dxil::ValueEnumerator::getComdats
const ComdatSetType & getComdats() const
Definition: DXILValueEnumerator.h:226
llvm::bitc::OBO_NO_UNSIGNED_WRAP
@ OBO_NO_UNSIGNED_WRAP
Definition: LLVMBitCodes.h:467
llvm::bitc::FUNC_CODE_INST_BR
@ FUNC_CODE_INST_BR
Definition: LLVMBitCodes.h:525
llvm::dxil::DXILBitcodeWriter
Definition: DXILBitcodeWriter.cpp:63
llvm::GenericDINode
Generic tagged DWARF-like metadata node.
Definition: DebugInfoMetadata.h:227
llvm::dxil::ValueEnumerator::getGlobalBasicBlockID
unsigned getGlobalBasicBlockID(const BasicBlock *BB) const
getGlobalBasicBlockID - This returns the function-specific ID for the specified basic block.
llvm::Type::isLabelTy
bool isLabelTy() const
Return true if this is 'label'.
Definition: Type.h:182
llvm::bitc::CONSTANTS_BLOCK_ID
@ CONSTANTS_BLOCK_ID
Definition: LLVMBitCodes.h:36
llvm::bitc::MODULE_CODE_TRIPLE
@ MODULE_CODE_TRIPLE
Definition: LLVMBitCodes.h:86
llvm::LandingPadInst::Catch
@ Catch
Definition: Instructions.h:2913
llvm::CallInst::isMustTailCall
bool isMustTailCall() const
Definition: Instructions.h:1660
llvm::bitc::BINOP_ADD
@ BINOP_ADD
Definition: LLVMBitCodes.h:430
llvm::bitc::VST_CODE_BBENTRY
@ VST_CODE_BBENTRY
Definition: LLVMBitCodes.h:191
llvm::bitc::RMW_ADD
@ RMW_ADD
Definition: LLVMBitCodes.h:450
llvm::GlobalValue::AvailableExternallyLinkage
@ AvailableExternallyLinkage
Available for inspection, not emission.
Definition: GlobalValue.h:49
llvm::bitc::PEO_EXACT
@ PEO_EXACT
Definition: LLVMBitCodes.h:487
llvm::bitc::FUNC_CODE_DEBUG_LOC_AGAIN
@ FUNC_CODE_DEBUG_LOC_AGAIN
Definition: LLVMBitCodes.h:554
llvm::GlobalValue::CommonLinkage
@ CommonLinkage
Tentative definitions.
Definition: GlobalValue.h:58
llvm::bitc::FUNC_CODE_INST_VAARG
@ FUNC_CODE_INST_VAARG
Definition: LLVMBitCodes.h:538
llvm::GlobalValue::LocalExecTLSModel
@ LocalExecTLSModel
Definition: GlobalValue.h:188
llvm::Type::IntegerTyID
@ IntegerTyID
Arbitrary bit width integers.
Definition: Type.h:71
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:186
llvm::bitc::COMDAT_SELECTION_KIND_ANY
@ COMDAT_SELECTION_KIND_ANY
Definition: LLVMBitCodes.h:692
llvm::AtomicOrdering::Release
@ Release
llvm::bitc::ATTR_KIND_NON_NULL
@ ATTR_KIND_NON_NULL
Definition: LLVMBitCodes.h:644
llvm::MCID::Select
@ Select
Definition: MCInstrDesc.h:164
Attributes.h
llvm::bitc::RMW_UMAX
@ RMW_UMAX
Definition: LLVMBitCodes.h:458
llvm::bitc::FUNC_CODE_INST_GEP
@ FUNC_CODE_INST_GEP
Definition: LLVMBitCodes.h:573
llvm::bitc::TYPE_BLOCK_ID_NEW
@ TYPE_BLOCK_ID_NEW
Definition: LLVMBitCodes.h:48
llvm::bitc::ATTR_KIND_ALWAYS_INLINE
@ ATTR_KIND_ALWAYS_INLINE
Definition: LLVMBitCodes.h:607
llvm::bitc::ATTR_KIND_STACK_PROTECT_STRONG
@ ATTR_KIND_STACK_PROTECT_STRONG
Definition: LLVMBitCodes.h:633
llvm::bitc::FUNC_CODE_INST_INDIRECTBR
@ FUNC_CODE_INST_INDIRECTBR
Definition: LLVMBitCodes.h:552
llvm::bitc::CST_CODE_AGGREGATE
@ CST_CODE_AGGREGATE
Definition: LLVMBitCodes.h:364
Constant.h
LLVMBitCodes.h
llvm::bitc::ATTR_KIND_READ_NONE
@ ATTR_KIND_READ_NONE
Definition: LLVMBitCodes.h:625
LastPlusOne
@ LastPlusOne
Definition: BitcodeWriter.cpp:2174
llvm::ConstantExpr
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:972
llvm::dxil::ValueEnumerator::EnumerateType
void EnumerateType(Type *T)
llvm::bitc::CAST_UITOFP
@ CAST_UITOFP
Definition: LLVMBitCodes.h:407
llvm::PPC::getPredicate
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
Definition: PPCPredicates.h:87
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::bitc::FUNC_CODE_INST_CMPXCHG
@ FUNC_CODE_INST_CMPXCHG
Definition: LLVMBitCodes.h:576
llvm::Type::isFloatTy
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition: Type.h:148
llvm::bitc::ORDERING_ACQREL
@ ORDERING_ACQREL
Definition: LLVMBitCodes.h:496
get
Should compile to something r4 addze r3 instead we get
Definition: README.txt:24
llvm::bitc::FIRST_APPLICATION_ABBREV
@ FIRST_APPLICATION_ABBREV
Definition: BitCodeEnums.h:60
llvm::AtomicRMWInst::FSub
@ FSub
*p = old - v
Definition: Instructions.h:754
llvm::DenseMapBase::end
iterator end()
Definition: DenseMap.h:84
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:348
llvm::bitc::CAST_FPTOUI
@ CAST_FPTOUI
Definition: LLVMBitCodes.h:405
llvm::Type::FixedVectorTyID
@ FixedVectorTyID
Fixed width SIMD vector type.
Definition: Type.h:76
JumpTable
MIPS Relocation Principles In there are several elements of the llvm::ISD::NodeType enum that deal with addresses and or relocations These are defined in include llvm Target TargetSelectionDAG td JumpTable
Definition: Relocation.txt:6
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::CallBase::arg_size
unsigned arg_size() const
Definition: InstrTypes.h:1339
llvm::bitc::FUNC_CODE_INST_LOAD
@ FUNC_CODE_INST_LOAD
Definition: LLVMBitCodes.h:535
GlobalVariable.h
llvm::bitc::FUNC_CODE_INST_EXTRACTVAL
@ FUNC_CODE_INST_EXTRACTVAL
Definition: LLVMBitCodes.h:544
llvm::ExtractValueInst
This instruction extracts a struct member or array element value from an aggregate value.
Definition: Instructions.h:2398
llvm::AtomicRMWInst::And
@ And
*p = old & v
Definition: Instructions.h:734
llvm::bitc::CAST_SITOFP
@ CAST_SITOFP
Definition: LLVMBitCodes.h:408
llvm::bitc::FUNCTION_BLOCK_ID
@ FUNCTION_BLOCK_ID
Definition: LLVMBitCodes.h:37
llvm::bitc::FUNC_CODE_INST_FENCE
@ FUNC_CODE_INST_FENCE
Definition: LLVMBitCodes.h:559
llvm::bitc::TYPE_CODE_NUMENTRY
@ TYPE_CODE_NUMENTRY
Definition: LLVMBitCodes.h:136
Function.h
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1562
llvm::Type::TokenTyID
@ TokenTyID
Tokens.
Definition: Type.h:68
llvm::Type::isDoubleTy
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition: Type.h:151
llvm::GlobalValue::ProtectedVisibility
@ ProtectedVisibility
The GV is protected.
Definition: GlobalValue.h:65
llvm::bitc::METADATA_ATTACHMENT_ID
@ METADATA_ATTACHMENT_ID
Definition: LLVMBitCodes.h:46
llvm::Type::isPPC_FP128Ty
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
Definition: Type.h:160
llvm::bitc::BINOP_LSHR
@ BINOP_LSHR
Definition: LLVMBitCodes.h:438
llvm::StringTableBuilder
Utility for building string tables with deduplicated suffixes.
Definition: StringTableBuilder.h:23
llvm::dxil::TypedPointerType::getElementType
Type * getElementType() const
Definition: DXILPointerType.h:41
llvm::SmallVectorImpl::clear
void clear()
Definition: SmallVector.h:591
llvm::bitc::CST_CODE_UNDEF
@ CST_CODE_UNDEF
Definition: LLVMBitCodes.h:360
llvm::MCID::Add
@ Add
Definition: MCInstrDesc.h:185
llvm::bitc::METADATA_ATTACHMENT
@ METADATA_ATTACHMENT
Definition: LLVMBitCodes.h:317
llvm::CallBase::getCalledOperand
Value * getCalledOperand() const
Definition: InstrTypes.h:1389
llvm::DIDerivedType
Derived types.
Definition: DebugInfoMetadata.h:924
llvm::DIGlobalVariableExpression
A pair of DIGlobalVariable and DIExpression.
Definition: DebugInfoMetadata.h:3358
llvm::bitc::CST_CODE_CSTRING
@ CST_CODE_CSTRING
Definition: LLVMBitCodes.h:366
GlobalAlias.h
llvm::dxil::BitcodeWriter
Definition: DXILBitcodeWriter.h:31
llvm::getAlign
bool getAlign(const Function &F, unsigned index, unsigned &align)
Definition: NVPTXUtilities.cpp:284
llvm::bitc::TYPE_CODE_FP128
@ TYPE_CODE_FP128
Definition: LLVMBitCodes.h:159
llvm::bitc::CAST_FPTRUNC
@ CAST_FPTRUNC
Definition: LLVMBitCodes.h:409
SHA1.h
llvm::dxil::BitcodeWriter::~BitcodeWriter
~BitcodeWriter()
Definition: DXILBitcodeWriter.cpp:373
llvm::BitCodeAbbrevOp
BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
Definition: BitCodes.h:33
llvm::GlobalValue::ExternalLinkage
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:48
llvm::Type::LabelTyID
@ LabelTyID
Labels.
Definition: Type.h:64
llvm::ValueEnumerator::ValueList
std::vector< std::pair< const Value *, unsigned > > ValueList
Definition: ValueEnumerator.h:48
llvm::DITemplateValueParameter
Definition: DebugInfoMetadata.h:2442
llvm::bitc::METADATA_GLOBAL_VAR
@ METADATA_GLOBAL_VAR
Definition: LLVMBitCodes.h:333
llvm::Type::StructTyID
@ StructTyID
Structures.
Definition: Type.h:74
llvm::bitc::METADATA_BLOCK_ID
@ METADATA_BLOCK_ID
Definition: LLVMBitCodes.h:45
llvm::Type::isOpaquePointerTy
bool isOpaquePointerTy() const
True if this is an instance of an opaque PointerType.
Definition: Type.cpp:61
llvm::bitc::BINOP_MUL
@ BINOP_MUL
Definition: LLVMBitCodes.h:432
llvm::GlobalValue::PrivateLinkage
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition: GlobalValue.h:56
llvm::bitc::TYPE_CODE_METADATA
@ TYPE_CODE_METADATA
Definition: LLVMBitCodes.h:162
Instructions.h
llvm::dxil::ValueEnumerator::hasMDs
bool hasMDs() const
Check whether the current block has any metadata to emit.
Definition: DXILValueEnumerator.h:200
llvm::bitc::METADATA_LOCAL_VAR
@ METADATA_LOCAL_VAR
Definition: LLVMBitCodes.h:334
llvm::bitc::ATTR_KIND_SANITIZE_ADDRESS
@ ATTR_KIND_SANITIZE_ADDRESS
Definition: LLVMBitCodes.h:635
llvm::AllocaInst::isUsedWithInAlloca
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
Definition: Instructions.h:136
llvm::AttributeSet
Definition: Attributes.h:290
llvm::bitc::RMW_AND
@ RMW_AND
Definition: LLVMBitCodes.h:452
llvm::dxil::DXILBitcodeWriter::getEncodedComdatSelectionKind
static unsigned getEncodedComdatSelectionKind(const Comdat &C)
Definition: DXILBitcodeWriter.cpp:868
llvm::ValueSymbolTable
This class provides a symbol table of name/value pairs.
Definition: ValueSymbolTable.h:37
llvm::bitc::ATTR_KIND_NO_INLINE
@ ATTR_KIND_NO_INLINE
Definition: LLVMBitCodes.h:619
llvm::bitc::ATTR_KIND_STACK_ALIGNMENT
@ ATTR_KIND_STACK_ALIGNMENT
Definition: LLVMBitCodes.h:630
llvm::bitc::COMDAT_SELECTION_KIND_LARGEST
@ COMDAT_SELECTION_KIND_LARGEST
Definition: LLVMBitCodes.h:694
llvm::raw_fd_stream
A raw_ostream of a file for reading/writing/seeking.
Definition: raw_ostream.h:601
llvm::LandingPadInst::Filter
@ Filter
Definition: Instructions.h:2913
llvm::bitc::ATTR_KIND_NO_IMPLICIT_FLOAT
@ ATTR_KIND_NO_IMPLICIT_FLOAT
Definition: LLVMBitCodes.h:618
llvm::bitc::ORDERING_RELEASE
@ ORDERING_RELEASE
Definition: LLVMBitCodes.h:495
llvm::CallBase::getArgOperand
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1341
N
#define N
llvm::LandingPadInst::isCatch
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
Definition: Instructions.h:2965
llvm::bitc::ATTR_KIND_BUILTIN
@ ATTR_KIND_BUILTIN
Definition: LLVMBitCodes.h:640
llvm::bitc::FUNC_CODE_INST_RESUME
@ FUNC_CODE_INST_RESUME
Definition: LLVMBitCodes.h:566
llvm::bitc::STRTAB_BLOB
@ STRTAB_BLOB
Definition: LLVMBitCodes.h:700
llvm::bitc::METADATA_VALUE
@ METADATA_VALUE
Definition: LLVMBitCodes.h:308
llvm::PHINode::getIncomingBlock
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Definition: Instructions.h:2767
llvm::AtomicRMWInst::FAdd
@ FAdd
*p = old + v
Definition: Instructions.h:751
llvm::MachineBasicBlock::empty
bool empty() const
Definition: MachineBasicBlock.h:250
llvm::PHINode
Definition: Instructions.h:2651
llvm::bitc::RMW_FADD
@ RMW_FADD
Definition: LLVMBitCodes.h:460
IV
static const uint32_t IV[8]
Definition: blake3_impl.h:85
llvm::DISubprogram
Subprogram description.
Definition: DebugInfoMetadata.h:1803
llvm::SmallVectorImpl< char >
llvm::dxil::DXILBitcodeWriter::getOptimizationFlags
static uint64_t getOptimizationFlags(const Value *V)
Definition: DXILBitcodeWriter.cpp:764
llvm::dxil::MetadataAbbrev
MetadataAbbrev
Definition: DXILBitcodeWriter.cpp:57
llvm::ValueAsMetadata
Value wrapper in the Metadata hierarchy.
Definition: Metadata.h:345
llvm::DIModule
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
Definition: DebugInfoMetadata.h:2307
llvm::AllocaPackedValues
Definition: BitcodeCommon.h:21
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1174
llvm::Type::ScalableVectorTyID
@ ScalableVectorTyID
Scalable SIMD vector type.
Definition: Type.h:77
DerivedTypes.h
llvm::bitc::CAST_BITCAST
@ CAST_BITCAST
Definition: LLVMBitCodes.h:413
llvm::bitc::METADATA_SUBPROGRAM
@ METADATA_SUBPROGRAM
Definition: LLVMBitCodes.h:327
llvm::bitc::USELIST_BLOCK_ID
@ USELIST_BLOCK_ID
Definition: LLVMBitCodes.h:50
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1461
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::bitc::METADATA_GENERIC_DEBUG
@ METADATA_GENERIC_DEBUG
Definition: LLVMBitCodes.h:318
llvm::DILabel
Label.
Definition: DebugInfoMetadata.h:3148
llvm::dxil::WriteDXILToFile
void WriteDXILToFile(const Module &M, raw_ostream &Out)
Write the specified module to the specified raw output stream.
Definition: DXILBitcodeWriter.cpp:376
UseListOrder.h
llvm::bitc::FUNC_CODE_INST_UNREACHABLE
@ FUNC_CODE_INST_UNREACHABLE
Definition: LLVMBitCodes.h:529
llvm::bitc::FUNC_CODE_DEBUG_LOC
@ FUNC_CODE_DEBUG_LOC
Definition: LLVMBitCodes.h:558
LLVMContext.h
llvm::SwitchInst
Multiway switch.
Definition: Instructions.h:3230
llvm::bitc::ATTR_KIND_RETURNS_TWICE
@ ATTR_KIND_RETURNS_TWICE
Definition: LLVMBitCodes.h:628
llvm::AllocaInst
an instruction to allocate memory on the stack
Definition: Instructions.h:58
BitcodeReader.h
llvm::GlobalValue::ExternalWeakLinkage
@ ExternalWeakLinkage
ExternalWeak linkage description.
Definition: GlobalValue.h:57
llvm::dxil::ValueEnumerator::getMetadataOrNullID
unsigned getMetadataOrNullID(const Metadata *MD) const
Definition: DXILValueEnumerator.h:159
llvm::bitc::ORDERING_SEQCST
@ ORDERING_SEQCST
Definition: LLVMBitCodes.h:497
llvm::BranchInst
Conditional or Unconditional Branch instruction.
Definition: Instructions.h:3086
llvm::AtomicRMWInst::UMax
@ UMax
*p = old >unsigned v ? old : v
Definition: Instructions.h:746
llvm::bitc::AllowContract
@ AllowContract
Definition: LLVMBitCodes.h:480
llvm::dxil::ValueEnumerator::incorporateFunction
void incorporateFunction(const Function &F)
incorporateFunction/purgeFunction - If you'd like to deal with a function, use these two methods to g...
llvm::bitc::MODULE_CODE_ALIAS_OLD
@ MODULE_CODE_ALIAS_OLD
Definition: LLVMBitCodes.h:103
llvm::GlobalValue::InitialExecTLSModel
@ InitialExecTLSModel
Definition: GlobalValue.h:187
llvm::bitc::METADATA_TEMPLATE_TYPE
@ METADATA_TEMPLATE_TYPE
Definition: LLVMBitCodes.h:331
llvm::SmallVectorImpl::reserve
void reserve(size_type N)
Definition: SmallVector.h:644
llvm::InsertValueInst
This instruction inserts a struct field of array element value into an aggregate value.
Definition: Instructions.h:2509
llvm::dxil::DXILBitcodeWriter::getEncodedVisibility
static unsigned getEncodedVisibility(const GlobalValue &GV)
Definition: DXILBitcodeWriter.cpp:828
llvm::MDString
A single uniqued string.
Definition: Metadata.h:612
llvm::GlobalValue::LinkOnceODRLinkage
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:51
llvm::StringRef::begin
iterator begin() const
Definition: StringRef.h:128
llvm::bitc::CST_CODE_STRING
@ CST_CODE_STRING
Definition: LLVMBitCodes.h:365
Value.h
llvm::InvokeInst::getUnwindDest
BasicBlock * getUnwindDest() const
Definition: Instructions.h:3898
llvm::bitc::COMDAT_SELECTION_KIND_EXACT_MATCH
@ COMDAT_SELECTION_KIND_EXACT_MATCH
Definition: LLVMBitCodes.h:693
llvm::bitc::FUNC_CODE_INST_SWITCH
@ FUNC_CODE_INST_SWITCH
Definition: LLVMBitCodes.h:526
llvm::FunctionType::getReturnType
Type * getReturnType() const
Definition: DerivedTypes.h:124
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::bitc::COMDAT_SELECTION_KIND_SAME_SIZE
@ COMDAT_SELECTION_KIND_SAME_SIZE
Definition: LLVMBitCodes.h:696
llvm::Type::isFP128Ty
bool isFP128Ty() const
Return true if this is 'fp128'.
Definition: Type.h:157
llvm::ValueEnumerator::TypeList
std::vector< Type * > TypeList
Definition: ValueEnumerator.h:45
llvm::Type::HalfTyID
@ HalfTyID
16-bit floating point type
Definition: Type.h:56
llvm::Type::X86_FP80TyID
@ X86_FP80TyID
80-bit floating point type (X87)
Definition: Type.h:60
llvm::bitc::ApproxFunc
@ ApproxFunc
Definition: LLVMBitCodes.h:481
BitstreamWriter.h
llvm::dxil::DXILBitcodeWriter::writeIdentificationBlock
static void writeIdentificationBlock(BitstreamWriter &Stream)
llvm::bitc::CST_CODE_DATA
@ CST_CODE_DATA
Definition: LLVMBitCodes.h:380
llvm::BranchInst::isConditional
bool isConditional() const
Definition: Instructions.h:3165
llvm::ArrayType::getElementType
Type * getElementType() const
Definition: DerivedTypes.h:370
llvm::dxil::TypedPointerType::getAddressSpace
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DXILPointerType.h:39
llvm::AtomicOrdering::NotAtomic
@ NotAtomic
llvm::BranchInst::getSuccessor
BasicBlock * getSuccessor(unsigned i) const
Definition: Instructions.h:3179
llvm::bitc::ATTR_KIND_IN_REG
@ ATTR_KIND_IN_REG
Definition: LLVMBitCodes.h:610
llvm::bitc::ATTR_KIND_NO_UNWIND
@ ATTR_KIND_NO_UNWIND
Definition: LLVMBitCodes.h:623
llvm::bitc::FUNC_CODE_INST_EXTRACTELT
@ FUNC_CODE_INST_EXTRACTELT
Definition: LLVMBitCodes.h:519
llvm::Function::const_iterator
BasicBlockListType::const_iterator const_iterator
Definition: Function.h:67
llvm::BasicBlock::const_iterator
InstListType::const_iterator const_iterator
Definition: BasicBlock.h:88
llvm::bitc::CST_CODE_INLINEASM
@ CST_CODE_INLINEASM
Definition: LLVMBitCodes.h:391
llvm::bitc::ATTR_KIND_RETURNED
@ ATTR_KIND_RETURNED
Definition: LLVMBitCodes.h:627
llvm::bitc::AllowReciprocal
@ AllowReciprocal
Definition: LLVMBitCodes.h:479
llvm::DIFile
File.
Definition: DebugInfoMetadata.h:525
llvm::CallingConv::Cold
@ Cold
Definition: CallingConv.h:48
llvm::bitc::FUNC_CODE_DECLAREBLOCKS
@ FUNC_CODE_DECLAREBLOCKS
Definition: LLVMBitCodes.h:513
llvm::FunctionType
Class to represent function types.
Definition: DerivedTypes.h:103
llvm::dxil::DXILBitcodeWriter::getEncodedThreadLocalMode
static unsigned getEncodedThreadLocalMode(const GlobalValue &GV)
Definition: DXILBitcodeWriter.cpp:852
llvm::Function::size
size_t size() const
Definition: Function.h:731
llvm::dxil::DXILBitcodeWriter::getEncodedLinkage
static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage)
Definition: DXILBitcodeWriter.cpp:796
llvm::irsymtab::build
Error build(ArrayRef< Module * > Mods, SmallVector< char, 0 > &Symtab, StringTableBuilder &StrtabBuilder, BumpPtrAllocator &Alloc)
Fills in Symtab and StrtabBuilder with a valid symbol and string table for Mods.
Definition: IRSymtab.cpp:365
llvm::SmallVectorImpl::insert
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:792
llvm::AtomicRMWInst::Max
@ Max
*p = old >signed v ? old : v
Definition: Instructions.h:742
llvm::dxil::TypedPointerType::get
static TypedPointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
Definition: DXILPointerType.cpp:29
llvm::bitc::METADATA_IMPORTED_ENTITY
@ METADATA_IMPORTED_ENTITY
Definition: LLVMBitCodes.h:337
llvm::bitc::ATTR_KIND_SAFESTACK
@ ATTR_KIND_SAFESTACK
Definition: LLVMBitCodes.h:649