Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
BitcodeWriter.cpp
Go to the documentation of this file.
1//===- Bitcode/Writer/BitcodeWriter.cpp - 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 "llvm/Bitcode/BitcodeWriter.h"
14#include "ValueEnumerator.h"
15#include "llvm/ADT/APFloat.h"
16#include "llvm/ADT/APInt.h"
17#include "llvm/ADT/ArrayRef.h"
18#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/STLExtras.h"
20#include "llvm/ADT/SetVector.h"
21#include "llvm/ADT/SmallPtrSet.h"
22#include "llvm/ADT/SmallString.h"
23#include "llvm/ADT/SmallVector.h"
24#include "llvm/ADT/StringMap.h"
25#include "llvm/ADT/StringRef.h"
26#include "llvm/Bitcode/BitcodeCommon.h"
27#include "llvm/Bitcode/BitcodeReader.h"
28#include "llvm/Bitcode/LLVMBitCodes.h"
29#include "llvm/Bitstream/BitCodes.h"
30#include "llvm/Bitstream/BitstreamWriter.h"
31#include "llvm/Config/llvm-config.h"
32#include "llvm/IR/Attributes.h"
33#include "llvm/IR/BasicBlock.h"
34#include "llvm/IR/Comdat.h"
35#include "llvm/IR/Constant.h"
36#include "llvm/IR/ConstantRangeList.h"
37#include "llvm/IR/Constants.h"
38#include "llvm/IR/DebugInfoMetadata.h"
39#include "llvm/IR/DebugLoc.h"
40#include "llvm/IR/DerivedTypes.h"
41#include "llvm/IR/Function.h"
42#include "llvm/IR/GlobalAlias.h"
43#include "llvm/IR/GlobalIFunc.h"
44#include "llvm/IR/GlobalObject.h"
45#include "llvm/IR/GlobalValue.h"
46#include "llvm/IR/GlobalVariable.h"
47#include "llvm/IR/InlineAsm.h"
48#include "llvm/IR/InstrTypes.h"
49#include "llvm/IR/Instruction.h"
50#include "llvm/IR/Instructions.h"
51#include "llvm/IR/LLVMContext.h"
52#include "llvm/IR/Metadata.h"
53#include "llvm/IR/Module.h"
54#include "llvm/IR/ModuleSummaryIndex.h"
55#include "llvm/IR/Operator.h"
56#include "llvm/IR/Type.h"
57#include "llvm/IR/UseListOrder.h"
58#include "llvm/IR/Value.h"
59#include "llvm/IR/ValueSymbolTable.h"
60#include "llvm/MC/StringTableBuilder.h"
61#include "llvm/MC/TargetRegistry.h"
62#include "llvm/Object/IRSymtab.h"
63#include "llvm/ProfileData/MemProf.h"
64#include "llvm/Support/AtomicOrdering.h"
65#include "llvm/Support/Casting.h"
66#include "llvm/Support/CommandLine.h"
67#include "llvm/Support/Endian.h"
68#include "llvm/Support/Error.h"
69#include "llvm/Support/ErrorHandling.h"
70#include "llvm/Support/MathExtras.h"
71#include "llvm/Support/SHA1.h"
72#include "llvm/Support/raw_ostream.h"
73#include "llvm/TargetParser/Triple.h"
74#include <algorithm>
75#include <cassert>
76#include <cstddef>
77#include <cstdint>
78#include <iterator>
79#include <map>
80#include <memory>
81#include <optional>
82#include <string>
83#include <utility>
84#include <vector>
85
86using namespacellvm;
87using namespacellvm::memprof;
88
89staticcl::opt<unsigned>
90IndexThreshold("bitcode-mdindex-threshold",cl::Hidden,cl::init(25),
91cl::desc("Number of metadatas above which we emit an index "
92"to enable lazy-loading"));
93staticcl::opt<uint32_t>FlushThreshold(
94"bitcode-flush-threshold",cl::Hidden,cl::init(512),
95cl::desc("The threshold (unit M) for flushing LLVM bitcode."));
96
97staticcl::opt<bool>WriteRelBFToSummary(
98"write-relbf-to-summary",cl::Hidden,cl::init(false),
99cl::desc("Write relative block frequency to function summary "));
100
101namespacellvm {
102externFunctionSummary::ForceSummaryHotnessTypeForceSummaryEdgesCold;
103}
104
105externboolWriteNewDbgInfoFormatToBitcode;
106externllvm::cl::opt<bool>UseNewDbgInfoFormat;
107
108namespace{
109
110/// These are manifest constants used by the bitcode writer. They do not need to
111/// be kept in sync with the reader, but need to be consistent within this file.
112enum {
113// VALUE_SYMTAB_BLOCK abbrev id's.
114 VST_ENTRY_8_ABBREV =bitc::FIRST_APPLICATION_ABBREV,
115 VST_ENTRY_7_ABBREV,
116 VST_ENTRY_6_ABBREV,
117 VST_BBENTRY_6_ABBREV,
118
119// CONSTANTS_BLOCK abbrev id's.
120 CONSTANTS_SETTYPE_ABBREV =bitc::FIRST_APPLICATION_ABBREV,
121 CONSTANTS_INTEGER_ABBREV,
122 CONSTANTS_CE_CAST_Abbrev,
123 CONSTANTS_NULL_Abbrev,
124
125// FUNCTION_BLOCK abbrev id's.
126 FUNCTION_INST_LOAD_ABBREV =bitc::FIRST_APPLICATION_ABBREV,
127 FUNCTION_INST_UNOP_ABBREV,
128 FUNCTION_INST_UNOP_FLAGS_ABBREV,
129 FUNCTION_INST_BINOP_ABBREV,
130 FUNCTION_INST_BINOP_FLAGS_ABBREV,
131 FUNCTION_INST_CAST_ABBREV,
132 FUNCTION_INST_CAST_FLAGS_ABBREV,
133 FUNCTION_INST_RET_VOID_ABBREV,
134 FUNCTION_INST_RET_VAL_ABBREV,
135 FUNCTION_INST_UNREACHABLE_ABBREV,
136 FUNCTION_INST_GEP_ABBREV,
137 FUNCTION_DEBUG_RECORD_VALUE_ABBREV,
138};
139
140/// Abstract class to manage the bitcode writing, subclassed for each bitcode
141/// file type.
142classBitcodeWriterBase {
143protected:
144 /// The stream created and owned by the client.
145BitstreamWriter &Stream;
146
147StringTableBuilder &StrtabBuilder;
148
149public:
150 /// Constructs a BitcodeWriterBase object that writes to the provided
151 /// \p Stream.
152 BitcodeWriterBase(BitstreamWriter &Stream,StringTableBuilder &StrtabBuilder)
153 : Stream(Stream), StrtabBuilder(StrtabBuilder) {}
154
155protected:
156void writeModuleVersion();
157};
158
159void BitcodeWriterBase::writeModuleVersion() {
160// VERSION: [version#]
161 Stream.EmitRecord(bitc::MODULE_CODE_VERSION,ArrayRef<uint64_t>{2});
162}
163
164/// Base class to manage the module bitcode writing, currently subclassed for
165/// ModuleBitcodeWriter and ThinLinkBitcodeWriter.
166classModuleBitcodeWriterBase :public BitcodeWriterBase {
167protected:
168 /// The Module to write to bitcode.
169constModule &M;
170
171 /// Enumerates ids for all values in the module.
172ValueEnumerator VE;
173
174 /// Optional per-module index to write for ThinLTO.
175constModuleSummaryIndex *Index;
176
177 /// Map that holds the correspondence between GUIDs in the summary index,
178 /// that came from indirect call profiles, and a value id generated by this
179 /// class to use in the VST and summary block records.
180 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
181
182 /// Tracks the last value id recorded in the GUIDToValueMap.
183unsigned GlobalValueId;
184
185 /// Saves the offset of the VSTOffset record that must eventually be
186 /// backpatched with the offset of the actual VST.
187uint64_t VSTOffsetPlaceholder = 0;
188
189public:
190 /// Constructs a ModuleBitcodeWriterBase object for the given Module,
191 /// writing to the provided \p Buffer.
192 ModuleBitcodeWriterBase(constModule &M,StringTableBuilder &StrtabBuilder,
193BitstreamWriter &Stream,
194bool ShouldPreserveUseListOrder,
195constModuleSummaryIndex *Index)
196 : BitcodeWriterBase(Stream, StrtabBuilder),M(M),
197 VE(M, ShouldPreserveUseListOrder),Index(Index) {
198// Assign ValueIds to any callee values in the index that came from
199// indirect call profiles and were recorded as a GUID not a Value*
200// (which would have been assigned an ID by the ValueEnumerator).
201// The starting ValueId is just after the number of values in the
202// ValueEnumerator, so that they can be emitted in the VST.
203 GlobalValueId = VE.getValues().size();
204if (!Index)
205return;
206for (constauto &GUIDSummaryLists : *Index)
207// Examine all summaries for this GUID.
208for (auto &Summary : GUIDSummaryLists.second.SummaryList)
209if (auto FS = dyn_cast<FunctionSummary>(Summary.get())) {
210// For each call in the function summary, see if the call
211// is to a GUID (which means it is for an indirect call,
212// otherwise we would have a Value for it). If so, synthesize
213// a value id.
214for (auto &CallEdge :FS->calls())
215if (!CallEdge.first.haveGVs() || !CallEdge.first.getValue())
216 assignValueId(CallEdge.first.getGUID());
217
218// For each referenced variables in the function summary, see if the
219// variable is represented by a GUID (as opposed to a symbol to
220// declarations or definitions in the module). If so, synthesize a
221// value id.
222for (auto &RefEdge :FS->refs())
223if (!RefEdge.haveGVs() || !RefEdge.getValue())
224 assignValueId(RefEdge.getGUID());
225 }
226 }
227
228protected:
229void writePerModuleGlobalValueSummary();
230
231private:
232void writePerModuleFunctionSummaryRecord(
233SmallVector<uint64_t, 64> &NameVals,GlobalValueSummary *Summary,
234unsigned ValueID,unsigned FSCallsAbbrev,unsigned FSCallsProfileAbbrev,
235unsigned CallsiteAbbrev,unsigned AllocAbbrev,unsigned ContextIdAbbvId,
236constFunction &F,DenseMap<CallStackId, LinearCallStackId> &CallStackPos,
237CallStackId &CallStackCount);
238void writeModuleLevelReferences(constGlobalVariable &V,
239SmallVector<uint64_t, 64> &NameVals,
240unsigned FSModRefsAbbrev,
241unsigned FSModVTableRefsAbbrev);
242
243void assignValueId(GlobalValue::GUID ValGUID) {
244 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
245 }
246
247unsigned getValueId(GlobalValue::GUID ValGUID) {
248constauto &VMI = GUIDToValueIdMap.find(ValGUID);
249// Expect that any GUID value had a value Id assigned by an
250// earlier call to assignValueId.
251assert(VMI != GUIDToValueIdMap.end() &&
252"GUID does not have assigned value Id");
253return VMI->second;
254 }
255
256// Helper to get the valueId for the type of value recorded in VI.
257unsigned getValueId(ValueInfo VI) {
258if (!VI.haveGVs() || !VI.getValue())
259return getValueId(VI.getGUID());
260return VE.getValueID(VI.getValue());
261 }
262
263 std::map<GlobalValue::GUID, unsigned> &valueIds() {return GUIDToValueIdMap; }
264};
265
266/// Class to manage the bitcode writing for a module.
267classModuleBitcodeWriter :public ModuleBitcodeWriterBase {
268 /// True if a module hash record should be written.
269bool GenerateHash;
270
271 /// If non-null, when GenerateHash is true, the resulting hash is written
272 /// into ModHash.
273ModuleHash *ModHash;
274
275SHA1 Hasher;
276
277 /// The start bit of the identification block.
278uint64_t BitcodeStartBit;
279
280public:
281 /// Constructs a ModuleBitcodeWriter object for the given Module,
282 /// writing to the provided \p Buffer.
283 ModuleBitcodeWriter(constModule &M,StringTableBuilder &StrtabBuilder,
284BitstreamWriter &Stream,bool ShouldPreserveUseListOrder,
285constModuleSummaryIndex *Index,bool GenerateHash,
286ModuleHash *ModHash =nullptr)
287 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
288 ShouldPreserveUseListOrder,Index),
289 GenerateHash(GenerateHash), ModHash(ModHash),
290 BitcodeStartBit(Stream.GetCurrentBitNo()) {}
291
292 /// Emit the current module to the bitstream.
293voidwrite();
294
295private:
296uint64_t bitcodeStartBit() {return BitcodeStartBit; }
297
298size_t addToStrtab(StringRef Str);
299
300void writeAttributeGroupTable();
301void writeAttributeTable();
302void writeTypeTable();
303void writeComdats();
304void writeValueSymbolTableForwardDecl();
305void writeModuleInfo();
306void writeValueAsMetadata(constValueAsMetadata *MD,
307SmallVectorImpl<uint64_t> &Record);
308voidwriteMDTuple(constMDTuple *N,SmallVectorImpl<uint64_t> &Record,
309unsigned Abbrev);
310unsigned createDILocationAbbrev();
311voidwriteDILocation(constDILocation *N,SmallVectorImpl<uint64_t> &Record,
312unsigned &Abbrev);
313unsigned createGenericDINodeAbbrev();
314voidwriteGenericDINode(constGenericDINode *N,
315SmallVectorImpl<uint64_t> &Record,unsigned &Abbrev);
316voidwriteDISubrange(constDISubrange *N,SmallVectorImpl<uint64_t> &Record,
317unsigned Abbrev);
318voidwriteDIGenericSubrange(constDIGenericSubrange *N,
319SmallVectorImpl<uint64_t> &Record,
320unsigned Abbrev);
321voidwriteDIEnumerator(constDIEnumerator *N,
322SmallVectorImpl<uint64_t> &Record,unsigned Abbrev);
323voidwriteDIBasicType(constDIBasicType *N,SmallVectorImpl<uint64_t> &Record,
324unsigned Abbrev);
325voidwriteDIStringType(constDIStringType *N,
326SmallVectorImpl<uint64_t> &Record,unsigned Abbrev);
327voidwriteDIDerivedType(constDIDerivedType *N,
328SmallVectorImpl<uint64_t> &Record,unsigned Abbrev);
329voidwriteDICompositeType(constDICompositeType *N,
330SmallVectorImpl<uint64_t> &Record,unsigned Abbrev);
331voidwriteDISubroutineType(constDISubroutineType *N,
332SmallVectorImpl<uint64_t> &Record,
333unsigned Abbrev);
334voidwriteDIFile(constDIFile *N,SmallVectorImpl<uint64_t> &Record,
335unsigned Abbrev);
336voidwriteDICompileUnit(constDICompileUnit *N,
337SmallVectorImpl<uint64_t> &Record,unsigned Abbrev);
338voidwriteDISubprogram(constDISubprogram *N,
339SmallVectorImpl<uint64_t> &Record,unsigned Abbrev);
340voidwriteDILexicalBlock(constDILexicalBlock *N,
341SmallVectorImpl<uint64_t> &Record,unsigned Abbrev);
342voidwriteDILexicalBlockFile(constDILexicalBlockFile *N,
343SmallVectorImpl<uint64_t> &Record,
344unsigned Abbrev);
345voidwriteDICommonBlock(constDICommonBlock *N,
346SmallVectorImpl<uint64_t> &Record,unsigned Abbrev);
347voidwriteDINamespace(constDINamespace *N,SmallVectorImpl<uint64_t> &Record,
348unsigned Abbrev);
349voidwriteDIMacro(constDIMacro *N,SmallVectorImpl<uint64_t> &Record,
350unsigned Abbrev);
351voidwriteDIMacroFile(constDIMacroFile *N,SmallVectorImpl<uint64_t> &Record,
352unsigned Abbrev);
353voidwriteDIArgList(constDIArgList *N,SmallVectorImpl<uint64_t> &Record);
354voidwriteDIModule(constDIModule *N,SmallVectorImpl<uint64_t> &Record,
355unsigned Abbrev);
356voidwriteDIAssignID(constDIAssignID *N,SmallVectorImpl<uint64_t> &Record,
357unsigned Abbrev);
358voidwriteDITemplateTypeParameter(constDITemplateTypeParameter *N,
359SmallVectorImpl<uint64_t> &Record,
360unsigned Abbrev);
361voidwriteDITemplateValueParameter(constDITemplateValueParameter *N,
362SmallVectorImpl<uint64_t> &Record,
363unsigned Abbrev);
364voidwriteDIGlobalVariable(constDIGlobalVariable *N,
365SmallVectorImpl<uint64_t> &Record,
366unsigned Abbrev);
367voidwriteDILocalVariable(constDILocalVariable *N,
368SmallVectorImpl<uint64_t> &Record,unsigned Abbrev);
369voidwriteDILabel(constDILabel *N,
370SmallVectorImpl<uint64_t> &Record,unsigned Abbrev);
371voidwriteDIExpression(constDIExpression *N,
372SmallVectorImpl<uint64_t> &Record,unsigned Abbrev);
373voidwriteDIGlobalVariableExpression(constDIGlobalVariableExpression *N,
374SmallVectorImpl<uint64_t> &Record,
375unsigned Abbrev);
376voidwriteDIObjCProperty(constDIObjCProperty *N,
377SmallVectorImpl<uint64_t> &Record,unsigned Abbrev);
378voidwriteDIImportedEntity(constDIImportedEntity *N,
379SmallVectorImpl<uint64_t> &Record,
380unsigned Abbrev);
381unsigned createNamedMetadataAbbrev();
382void writeNamedMetadata(SmallVectorImpl<uint64_t> &Record);
383unsigned createMetadataStringsAbbrev();
384void writeMetadataStrings(ArrayRef<const Metadata *> Strings,
385SmallVectorImpl<uint64_t> &Record);
386void writeMetadataRecords(ArrayRef<const Metadata *> MDs,
387SmallVectorImpl<uint64_t> &Record,
388 std::vector<unsigned> *MDAbbrevs =nullptr,
389 std::vector<uint64_t> *IndexPos =nullptr);
390void writeModuleMetadata();
391void writeFunctionMetadata(constFunction &F);
392void writeFunctionMetadataAttachment(constFunction &F);
393void pushGlobalMetadataAttachment(SmallVectorImpl<uint64_t> &Record,
394constGlobalObject &GO);
395void writeModuleMetadataKinds();
396void writeOperandBundleTags();
397void writeSyncScopeNames();
398void writeConstants(unsigned FirstVal,unsigned LastVal,bool isGlobal);
399void writeModuleConstants();
400bool pushValueAndType(constValue *V,unsigned InstID,
401SmallVectorImpl<unsigned> &Vals);
402bool pushValueOrMetadata(constValue *V,unsigned InstID,
403SmallVectorImpl<unsigned> &Vals);
404void writeOperandBundles(constCallBase &CB,unsigned InstID);
405void pushValue(constValue *V,unsigned InstID,
406SmallVectorImpl<unsigned> &Vals);
407void pushValueSigned(constValue *V,unsigned InstID,
408SmallVectorImpl<uint64_t> &Vals);
409void writeInstruction(constInstruction &I,unsigned InstID,
410SmallVectorImpl<unsigned> &Vals);
411void writeFunctionLevelValueSymbolTable(constValueSymbolTable &VST);
412void writeGlobalValueSymbolTable(
413DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
414void writeUseList(UseListOrder &&Order);
415void writeUseListBlock(constFunction *F);
416void
417 writeFunction(constFunction &F,
418DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
419void writeBlockInfo();
420void writeModuleHash(StringRef View);
421
422unsigned getEncodedSyncScopeID(SyncScope::ID SSID) {
423returnunsigned(SSID);
424 }
425
426unsigned getEncodedAlign(MaybeAlign Alignment) {returnencode(Alignment); }
427};
428
429/// Class to manage the bitcode writing for a combined index.
430classIndexBitcodeWriter :public BitcodeWriterBase {
431 /// The combined index to write to bitcode.
432constModuleSummaryIndex &Index;
433
434 /// When writing combined summaries, provides the set of global value
435 /// summaries for which the value (function, function alias, etc) should be
436 /// imported as a declaration.
437constGVSummaryPtrSet *DecSummaries =nullptr;
438
439 /// When writing a subset of the index for distributed backends, client
440 /// provides a map of modules to the corresponding GUIDs/summaries to write.
441constModuleToSummariesForIndexTy *ModuleToSummariesForIndex;
442
443 /// Map that holds the correspondence between the GUID used in the combined
444 /// index and a value id generated by this class to use in references.
445 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
446
447// The stack ids used by this index, which will be a subset of those in
448// the full index in the case of distributed indexes.
449 std::vector<uint64_t> StackIds;
450
451// Keep a map of the stack id indices used by records being written for this
452// index to the index of the corresponding stack id in the above StackIds
453// vector. Ensures we write each referenced stack id once.
454DenseMap<unsigned, unsigned> StackIdIndicesToIndex;
455
456 /// Tracks the last value id recorded in the GUIDToValueMap.
457unsigned GlobalValueId = 0;
458
459 /// Tracks the assignment of module paths in the module path string table to
460 /// an id assigned for use in summary references to the module path.
461DenseMap<StringRef, uint64_t> ModuleIdMap;
462
463public:
464 /// Constructs a IndexBitcodeWriter object for the given combined index,
465 /// writing to the provided \p Buffer. When writing a subset of the index
466 /// for a distributed backend, provide a \p ModuleToSummariesForIndex map.
467 /// If provided, \p DecSummaries specifies the set of summaries for which
468 /// the corresponding functions or aliased functions should be imported as a
469 /// declaration (but not definition) for each module.
470 IndexBitcodeWriter(
471BitstreamWriter &Stream,StringTableBuilder &StrtabBuilder,
472constModuleSummaryIndex &Index,
473constGVSummaryPtrSet *DecSummaries =nullptr,
474constModuleToSummariesForIndexTy *ModuleToSummariesForIndex =nullptr)
475 : BitcodeWriterBase(Stream, StrtabBuilder),Index(Index),
476 DecSummaries(DecSummaries),
477 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
478
479// See if the StackIdIndex was already added to the StackId map and
480// vector. If not, record it.
481auto RecordStackIdReference = [&](unsigned StackIdIndex) {
482// If the StackIdIndex is not yet in the map, the below insert ensures
483// that it will point to the new StackIds vector entry we push to just
484// below.
485autoInserted =
486 StackIdIndicesToIndex.insert({StackIdIndex, StackIds.size()});
487if (Inserted.second)
488 StackIds.push_back(Index.getStackIdAtIndex(StackIdIndex));
489 };
490
491// Assign unique value ids to all summaries to be written, for use
492// in writing out the call graph edges. Save the mapping from GUID
493// to the new global value id to use when writing those edges, which
494// are currently saved in the index in terms of GUID.
495 forEachSummary([&](GVInfoI,bool IsAliasee) {
496 GUIDToValueIdMap[I.first] = ++GlobalValueId;
497// If this is invoked for an aliasee, we want to record the above mapping,
498// but not the information needed for its summary entry (if the aliasee is
499// to be imported, we will invoke this separately with IsAliasee=false).
500if (IsAliasee)
501return;
502auto *FS = dyn_cast<FunctionSummary>(I.second);
503if (!FS)
504return;
505// Record all stack id indices actually used in the summary entries being
506// written, so that we can compact them in the case of distributed ThinLTO
507// indexes.
508for (auto &CI :FS->callsites()) {
509// If the stack id list is empty, this callsite info was synthesized for
510// a missing tail call frame. Ensure that the callee's GUID gets a value
511// id. Normally we only generate these for defined summaries, which in
512// the case of distributed ThinLTO is only the functions already defined
513// in the module or that we want to import. We don't bother to include
514// all the callee symbols as they aren't normally needed in the backend.
515// However, for the synthesized callsite infos we do need the callee
516// GUID in the backend so that we can correlate the identified callee
517// with this callsite info (which for non-tail calls is done by the
518// ordering of the callsite infos and verified via stack ids).
519if (CI.StackIdIndices.empty()) {
520 GUIDToValueIdMap[CI.Callee.getGUID()] = ++GlobalValueId;
521continue;
522 }
523for (autoIdx : CI.StackIdIndices)
524 RecordStackIdReference(Idx);
525 }
526for (auto &AI :FS->allocs())
527for (auto &MIB : AI.MIBs)
528for (autoIdx : MIB.StackIdIndices)
529 RecordStackIdReference(Idx);
530 });
531 }
532
533 /// The below iterator returns the GUID and associated summary.
534usingGVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>;
535
536 /// Calls the callback for each value GUID and summary to be written to
537 /// bitcode. This hides the details of whether they are being pulled from the
538 /// entire index or just those in a provided ModuleToSummariesForIndex map.
539template<typename Functor>
540void forEachSummary(Functor Callback) {
541if (ModuleToSummariesForIndex) {
542for (auto &M : *ModuleToSummariesForIndex)
543for (auto &Summary :M.second) {
544 Callback(Summary,false);
545// Ensure aliasee is handled, e.g. for assigning a valueId,
546// even if we are not importing the aliasee directly (the
547// imported alias will contain a copy of aliasee).
548if (auto *AS = dyn_cast<AliasSummary>(Summary.getSecond()))
549 Callback({AS->getAliaseeGUID(), &AS->getAliasee()},true);
550 }
551 }else {
552for (auto &Summaries : Index)
553for (auto &Summary : Summaries.second.SummaryList)
554 Callback({Summaries.first,Summary.get()},false);
555 }
556 }
557
558 /// Calls the callback for each entry in the modulePaths StringMap that
559 /// should be written to the module path string table. This hides the details
560 /// of whether they are being pulled from the entire index or just those in a
561 /// provided ModuleToSummariesForIndex map.
562template <typename Functor>void forEachModule(Functor Callback) {
563if (ModuleToSummariesForIndex) {
564for (constauto &M : *ModuleToSummariesForIndex) {
565constauto &MPI =Index.modulePaths().find(M.first);
566if (MPI ==Index.modulePaths().end()) {
567// This should only happen if the bitcode file was empty, in which
568// case we shouldn't be importing (the ModuleToSummariesForIndex
569// would only include the module we are writing and index for).
570assert(ModuleToSummariesForIndex->size() == 1);
571continue;
572 }
573 Callback(*MPI);
574 }
575 }else {
576// Since StringMap iteration order isn't guaranteed, order by path string
577// first.
578// FIXME: Make this a vector of StringMapEntry instead to avoid the later
579// map lookup.
580 std::vector<StringRef> ModulePaths;
581for (auto &[ModPath,_] :Index.modulePaths())
582 ModulePaths.push_back(ModPath);
583llvm::sort(ModulePaths.begin(), ModulePaths.end());
584for (auto &ModPath : ModulePaths)
585 Callback(*Index.modulePaths().find(ModPath));
586 }
587 }
588
589 /// Main entry point for writing a combined index to bitcode.
590voidwrite();
591
592private:
593void writeModStrings();
594void writeCombinedGlobalValueSummary();
595
596 std::optional<unsigned> getValueId(GlobalValue::GUID ValGUID) {
597auto VMI = GUIDToValueIdMap.find(ValGUID);
598if (VMI == GUIDToValueIdMap.end())
599return std::nullopt;
600return VMI->second;
601 }
602
603 std::map<GlobalValue::GUID, unsigned> &valueIds() {return GUIDToValueIdMap; }
604};
605
606}// end anonymous namespace
607
608staticunsignedgetEncodedCastOpcode(unsigned Opcode) {
609switch (Opcode) {
610default:llvm_unreachable("Unknown cast instruction!");
611case Instruction::Trunc :returnbitc::CAST_TRUNC;
612case Instruction::ZExt :returnbitc::CAST_ZEXT;
613case Instruction::SExt :returnbitc::CAST_SEXT;
614case Instruction::FPToUI :returnbitc::CAST_FPTOUI;
615case Instruction::FPToSI :returnbitc::CAST_FPTOSI;
616case Instruction::UIToFP :returnbitc::CAST_UITOFP;
617case Instruction::SIToFP :returnbitc::CAST_SITOFP;
618case Instruction::FPTrunc :returnbitc::CAST_FPTRUNC;
619case Instruction::FPExt :returnbitc::CAST_FPEXT;
620case Instruction::PtrToInt:returnbitc::CAST_PTRTOINT;
621case Instruction::IntToPtr:returnbitc::CAST_INTTOPTR;
622case Instruction::BitCast :returnbitc::CAST_BITCAST;
623case Instruction::AddrSpaceCast:returnbitc::CAST_ADDRSPACECAST;
624 }
625}
626
627staticunsignedgetEncodedUnaryOpcode(unsigned Opcode) {
628switch (Opcode) {
629default:llvm_unreachable("Unknown binary instruction!");
630case Instruction::FNeg:returnbitc::UNOP_FNEG;
631 }
632}
633
634staticunsignedgetEncodedBinaryOpcode(unsigned Opcode) {
635switch (Opcode) {
636default:llvm_unreachable("Unknown binary instruction!");
637case Instruction::Add:
638case Instruction::FAdd:returnbitc::BINOP_ADD;
639case Instruction::Sub:
640case Instruction::FSub:returnbitc::BINOP_SUB;
641case Instruction::Mul:
642case Instruction::FMul:returnbitc::BINOP_MUL;
643case Instruction::UDiv:returnbitc::BINOP_UDIV;
644case Instruction::FDiv:
645case Instruction::SDiv:returnbitc::BINOP_SDIV;
646case Instruction::URem:returnbitc::BINOP_UREM;
647case Instruction::FRem:
648case Instruction::SRem:returnbitc::BINOP_SREM;
649case Instruction::Shl:returnbitc::BINOP_SHL;
650case Instruction::LShr:returnbitc::BINOP_LSHR;
651case Instruction::AShr:returnbitc::BINOP_ASHR;
652case Instruction::And:returnbitc::BINOP_AND;
653case Instruction::Or:returnbitc::BINOP_OR;
654case Instruction::Xor:returnbitc::BINOP_XOR;
655 }
656}
657
658staticunsignedgetEncodedRMWOperation(AtomicRMWInst::BinOpOp) {
659switch (Op) {
660default:llvm_unreachable("Unknown RMW operation!");
661caseAtomicRMWInst::Xchg:returnbitc::RMW_XCHG;
662caseAtomicRMWInst::Add:returnbitc::RMW_ADD;
663caseAtomicRMWInst::Sub:returnbitc::RMW_SUB;
664caseAtomicRMWInst::And:returnbitc::RMW_AND;
665caseAtomicRMWInst::Nand:returnbitc::RMW_NAND;
666caseAtomicRMWInst::Or:returnbitc::RMW_OR;
667caseAtomicRMWInst::Xor:returnbitc::RMW_XOR;
668caseAtomicRMWInst::Max:returnbitc::RMW_MAX;
669caseAtomicRMWInst::Min:returnbitc::RMW_MIN;
670caseAtomicRMWInst::UMax:returnbitc::RMW_UMAX;
671caseAtomicRMWInst::UMin:returnbitc::RMW_UMIN;
672caseAtomicRMWInst::FAdd:returnbitc::RMW_FADD;
673caseAtomicRMWInst::FSub:returnbitc::RMW_FSUB;
674caseAtomicRMWInst::FMax:returnbitc::RMW_FMAX;
675caseAtomicRMWInst::FMin:returnbitc::RMW_FMIN;
676caseAtomicRMWInst::UIncWrap:
677returnbitc::RMW_UINC_WRAP;
678caseAtomicRMWInst::UDecWrap:
679returnbitc::RMW_UDEC_WRAP;
680caseAtomicRMWInst::USubCond:
681returnbitc::RMW_USUB_COND;
682caseAtomicRMWInst::USubSat:
683returnbitc::RMW_USUB_SAT;
684 }
685}
686
687staticunsignedgetEncodedOrdering(AtomicOrdering Ordering) {
688switch (Ordering) {
689case AtomicOrdering::NotAtomic:returnbitc::ORDERING_NOTATOMIC;
690case AtomicOrdering::Unordered:returnbitc::ORDERING_UNORDERED;
691case AtomicOrdering::Monotonic:returnbitc::ORDERING_MONOTONIC;
692case AtomicOrdering::Acquire:returnbitc::ORDERING_ACQUIRE;
693case AtomicOrdering::Release:returnbitc::ORDERING_RELEASE;
694case AtomicOrdering::AcquireRelease:returnbitc::ORDERING_ACQREL;
695case AtomicOrdering::SequentiallyConsistent:returnbitc::ORDERING_SEQCST;
696 }
697llvm_unreachable("Invalid ordering");
698}
699
700staticvoidwriteStringRecord(BitstreamWriter &Stream,unsigned Code,
701StringRef Str,unsigned AbbrevToUse) {
702SmallVector<unsigned, 64> Vals;
703
704// Code: [strchar x N]
705for (charC : Str) {
706if (AbbrevToUse && !BitCodeAbbrevOp::isChar6(C))
707 AbbrevToUse = 0;
708 Vals.push_back(C);
709 }
710
711// Emit the finished record.
712 Stream.EmitRecord(Code, Vals, AbbrevToUse);
713}
714
715staticuint64_tgetAttrKindEncoding(Attribute::AttrKind Kind) {
716switch (Kind) {
717case Attribute::Alignment:
718returnbitc::ATTR_KIND_ALIGNMENT;
719case Attribute::AllocAlign:
720returnbitc::ATTR_KIND_ALLOC_ALIGN;
721case Attribute::AllocSize:
722returnbitc::ATTR_KIND_ALLOC_SIZE;
723case Attribute::AlwaysInline:
724returnbitc::ATTR_KIND_ALWAYS_INLINE;
725case Attribute::Builtin:
726returnbitc::ATTR_KIND_BUILTIN;
727case Attribute::ByVal:
728returnbitc::ATTR_KIND_BY_VAL;
729case Attribute::Convergent:
730returnbitc::ATTR_KIND_CONVERGENT;
731case Attribute::InAlloca:
732returnbitc::ATTR_KIND_IN_ALLOCA;
733case Attribute::Cold:
734returnbitc::ATTR_KIND_COLD;
735case Attribute::DisableSanitizerInstrumentation:
736returnbitc::ATTR_KIND_DISABLE_SANITIZER_INSTRUMENTATION;
737case Attribute::FnRetThunkExtern:
738returnbitc::ATTR_KIND_FNRETTHUNK_EXTERN;
739case Attribute::Hot:
740returnbitc::ATTR_KIND_HOT;
741case Attribute::ElementType:
742returnbitc::ATTR_KIND_ELEMENTTYPE;
743case Attribute::HybridPatchable:
744returnbitc::ATTR_KIND_HYBRID_PATCHABLE;
745case Attribute::InlineHint:
746returnbitc::ATTR_KIND_INLINE_HINT;
747case Attribute::InReg:
748returnbitc::ATTR_KIND_IN_REG;
749case Attribute::JumpTable:
750returnbitc::ATTR_KIND_JUMP_TABLE;
751case Attribute::MinSize:
752returnbitc::ATTR_KIND_MIN_SIZE;
753case Attribute::AllocatedPointer:
754returnbitc::ATTR_KIND_ALLOCATED_POINTER;
755case Attribute::AllocKind:
756returnbitc::ATTR_KIND_ALLOC_KIND;
757case Attribute::Memory:
758returnbitc::ATTR_KIND_MEMORY;
759case Attribute::NoFPClass:
760returnbitc::ATTR_KIND_NOFPCLASS;
761case Attribute::Naked:
762returnbitc::ATTR_KIND_NAKED;
763case Attribute::Nest:
764returnbitc::ATTR_KIND_NEST;
765case Attribute::NoAlias:
766returnbitc::ATTR_KIND_NO_ALIAS;
767case Attribute::NoBuiltin:
768returnbitc::ATTR_KIND_NO_BUILTIN;
769case Attribute::NoCallback:
770returnbitc::ATTR_KIND_NO_CALLBACK;
771case Attribute::NoCapture:
772returnbitc::ATTR_KIND_NO_CAPTURE;
773case Attribute::NoDivergenceSource:
774returnbitc::ATTR_KIND_NO_DIVERGENCE_SOURCE;
775case Attribute::NoDuplicate:
776returnbitc::ATTR_KIND_NO_DUPLICATE;
777case Attribute::NoFree:
778returnbitc::ATTR_KIND_NOFREE;
779case Attribute::NoImplicitFloat:
780returnbitc::ATTR_KIND_NO_IMPLICIT_FLOAT;
781case Attribute::NoInline:
782returnbitc::ATTR_KIND_NO_INLINE;
783case Attribute::NoRecurse:
784returnbitc::ATTR_KIND_NO_RECURSE;
785case Attribute::NoMerge:
786returnbitc::ATTR_KIND_NO_MERGE;
787case Attribute::NonLazyBind:
788returnbitc::ATTR_KIND_NON_LAZY_BIND;
789case Attribute::NonNull:
790returnbitc::ATTR_KIND_NON_NULL;
791case Attribute::Dereferenceable:
792returnbitc::ATTR_KIND_DEREFERENCEABLE;
793case Attribute::DereferenceableOrNull:
794returnbitc::ATTR_KIND_DEREFERENCEABLE_OR_NULL;
795case Attribute::NoRedZone:
796returnbitc::ATTR_KIND_NO_RED_ZONE;
797case Attribute::NoReturn:
798returnbitc::ATTR_KIND_NO_RETURN;
799case Attribute::NoSync:
800returnbitc::ATTR_KIND_NOSYNC;
801case Attribute::NoCfCheck:
802returnbitc::ATTR_KIND_NOCF_CHECK;
803case Attribute::NoProfile:
804returnbitc::ATTR_KIND_NO_PROFILE;
805case Attribute::SkipProfile:
806returnbitc::ATTR_KIND_SKIP_PROFILE;
807case Attribute::NoUnwind:
808returnbitc::ATTR_KIND_NO_UNWIND;
809case Attribute::NoSanitizeBounds:
810returnbitc::ATTR_KIND_NO_SANITIZE_BOUNDS;
811case Attribute::NoSanitizeCoverage:
812returnbitc::ATTR_KIND_NO_SANITIZE_COVERAGE;
813case Attribute::NullPointerIsValid:
814returnbitc::ATTR_KIND_NULL_POINTER_IS_VALID;
815case Attribute::OptimizeForDebugging:
816returnbitc::ATTR_KIND_OPTIMIZE_FOR_DEBUGGING;
817case Attribute::OptForFuzzing:
818returnbitc::ATTR_KIND_OPT_FOR_FUZZING;
819case Attribute::OptimizeForSize:
820returnbitc::ATTR_KIND_OPTIMIZE_FOR_SIZE;
821case Attribute::OptimizeNone:
822returnbitc::ATTR_KIND_OPTIMIZE_NONE;
823case Attribute::ReadNone:
824returnbitc::ATTR_KIND_READ_NONE;
825case Attribute::ReadOnly:
826returnbitc::ATTR_KIND_READ_ONLY;
827case Attribute::Returned:
828returnbitc::ATTR_KIND_RETURNED;
829case Attribute::ReturnsTwice:
830returnbitc::ATTR_KIND_RETURNS_TWICE;
831case Attribute::SExt:
832returnbitc::ATTR_KIND_S_EXT;
833case Attribute::Speculatable:
834returnbitc::ATTR_KIND_SPECULATABLE;
835case Attribute::StackAlignment:
836returnbitc::ATTR_KIND_STACK_ALIGNMENT;
837case Attribute::StackProtect:
838returnbitc::ATTR_KIND_STACK_PROTECT;
839case Attribute::StackProtectReq:
840returnbitc::ATTR_KIND_STACK_PROTECT_REQ;
841case Attribute::StackProtectStrong:
842returnbitc::ATTR_KIND_STACK_PROTECT_STRONG;
843case Attribute::SafeStack:
844returnbitc::ATTR_KIND_SAFESTACK;
845case Attribute::ShadowCallStack:
846returnbitc::ATTR_KIND_SHADOWCALLSTACK;
847case Attribute::StrictFP:
848returnbitc::ATTR_KIND_STRICT_FP;
849case Attribute::StructRet:
850returnbitc::ATTR_KIND_STRUCT_RET;
851case Attribute::SanitizeAddress:
852returnbitc::ATTR_KIND_SANITIZE_ADDRESS;
853case Attribute::SanitizeHWAddress:
854returnbitc::ATTR_KIND_SANITIZE_HWADDRESS;
855case Attribute::SanitizeThread:
856returnbitc::ATTR_KIND_SANITIZE_THREAD;
857case Attribute::SanitizeType:
858returnbitc::ATTR_KIND_SANITIZE_TYPE;
859case Attribute::SanitizeMemory:
860returnbitc::ATTR_KIND_SANITIZE_MEMORY;
861case Attribute::SanitizeNumericalStability:
862returnbitc::ATTR_KIND_SANITIZE_NUMERICAL_STABILITY;
863case Attribute::SanitizeRealtime:
864returnbitc::ATTR_KIND_SANITIZE_REALTIME;
865case Attribute::SanitizeRealtimeBlocking:
866returnbitc::ATTR_KIND_SANITIZE_REALTIME_BLOCKING;
867case Attribute::SpeculativeLoadHardening:
868returnbitc::ATTR_KIND_SPECULATIVE_LOAD_HARDENING;
869case Attribute::SwiftError:
870returnbitc::ATTR_KIND_SWIFT_ERROR;
871case Attribute::SwiftSelf:
872returnbitc::ATTR_KIND_SWIFT_SELF;
873case Attribute::SwiftAsync:
874returnbitc::ATTR_KIND_SWIFT_ASYNC;
875case Attribute::UWTable:
876returnbitc::ATTR_KIND_UW_TABLE;
877case Attribute::VScaleRange:
878returnbitc::ATTR_KIND_VSCALE_RANGE;
879case Attribute::WillReturn:
880returnbitc::ATTR_KIND_WILLRETURN;
881case Attribute::WriteOnly:
882returnbitc::ATTR_KIND_WRITEONLY;
883case Attribute::ZExt:
884returnbitc::ATTR_KIND_Z_EXT;
885case Attribute::ImmArg:
886returnbitc::ATTR_KIND_IMMARG;
887case Attribute::SanitizeMemTag:
888returnbitc::ATTR_KIND_SANITIZE_MEMTAG;
889case Attribute::Preallocated:
890returnbitc::ATTR_KIND_PREALLOCATED;
891case Attribute::NoUndef:
892returnbitc::ATTR_KIND_NOUNDEF;
893case Attribute::ByRef:
894returnbitc::ATTR_KIND_BYREF;
895case Attribute::MustProgress:
896returnbitc::ATTR_KIND_MUSTPROGRESS;
897case Attribute::PresplitCoroutine:
898returnbitc::ATTR_KIND_PRESPLIT_COROUTINE;
899case Attribute::Writable:
900returnbitc::ATTR_KIND_WRITABLE;
901case Attribute::CoroDestroyOnlyWhenComplete:
902returnbitc::ATTR_KIND_CORO_ONLY_DESTROY_WHEN_COMPLETE;
903case Attribute::CoroElideSafe:
904returnbitc::ATTR_KIND_CORO_ELIDE_SAFE;
905case Attribute::DeadOnUnwind:
906returnbitc::ATTR_KIND_DEAD_ON_UNWIND;
907case Attribute::Range:
908returnbitc::ATTR_KIND_RANGE;
909case Attribute::Initializes:
910returnbitc::ATTR_KIND_INITIALIZES;
911case Attribute::NoExt:
912returnbitc::ATTR_KIND_NO_EXT;
913case Attribute::Captures:
914returnbitc::ATTR_KIND_CAPTURES;
915caseAttribute::EndAttrKinds:
916llvm_unreachable("Can not encode end-attribute kinds marker.");
917caseAttribute::None:
918llvm_unreachable("Can not encode none-attribute.");
919caseAttribute::EmptyKey:
920caseAttribute::TombstoneKey:
921llvm_unreachable("Trying to encode EmptyKey/TombstoneKey");
922 }
923
924llvm_unreachable("Trying to encode unknown attribute");
925}
926
927staticvoidemitSignedInt64(SmallVectorImpl<uint64_t> &Vals,uint64_t V) {
928if ((int64_t)V >= 0)
929 Vals.push_back(V << 1);
930else
931 Vals.push_back((-V << 1) | 1);
932}
933
934staticvoidemitWideAPInt(SmallVectorImpl<uint64_t> &Vals,constAPInt &A) {
935// We have an arbitrary precision integer value to write whose
936// bit width is > 64. However, in canonical unsigned integer
937// format it is likely that the high bits are going to be zero.
938// So, we only write the number of active words.
939unsigned NumWords =A.getActiveWords();
940constuint64_t *RawData =A.getRawData();
941for (unsigned i = 0; i < NumWords; i++)
942emitSignedInt64(Vals, RawData[i]);
943}
944
945staticvoidemitConstantRange(SmallVectorImpl<uint64_t> &Record,
946constConstantRange &CR,bool EmitBitWidth) {
947unsignedBitWidth = CR.getBitWidth();
948if (EmitBitWidth)
949Record.push_back(BitWidth);
950if (BitWidth > 64) {
951Record.push_back(CR.getLower().getActiveWords() |
952 (uint64_t(CR.getUpper().getActiveWords()) << 32));
953emitWideAPInt(Record, CR.getLower());
954emitWideAPInt(Record, CR.getUpper());
955 }else {
956emitSignedInt64(Record, CR.getLower().getSExtValue());
957emitSignedInt64(Record, CR.getUpper().getSExtValue());
958 }
959}
960
961void ModuleBitcodeWriter::writeAttributeGroupTable() {
962const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
963 VE.getAttributeGroups();
964if (AttrGrps.empty())return;
965
966 Stream.EnterSubblock(bitc::PARAMATTR_GROUP_BLOCK_ID, 3);
967
968SmallVector<uint64_t, 64>Record;
969for (ValueEnumerator::IndexAndAttrSet Pair : AttrGrps) {
970unsigned AttrListIndex = Pair.first;
971AttributeSet AS = Pair.second;
972Record.push_back(VE.getAttributeGroupID(Pair));
973Record.push_back(AttrListIndex);
974
975for (Attribute Attr : AS) {
976if (Attr.isEnumAttribute()) {
977Record.push_back(0);
978Record.push_back(getAttrKindEncoding(Attr.getKindAsEnum()));
979 }elseif (Attr.isIntAttribute()) {
980Record.push_back(1);
981Record.push_back(getAttrKindEncoding(Attr.getKindAsEnum()));
982Record.push_back(Attr.getValueAsInt());
983 }elseif (Attr.isStringAttribute()) {
984StringRefKind = Attr.getKindAsString();
985StringRef Val = Attr.getValueAsString();
986
987Record.push_back(Val.empty() ? 3 : 4);
988Record.append(Kind.begin(),Kind.end());
989Record.push_back(0);
990if (!Val.empty()) {
991Record.append(Val.begin(), Val.end());
992Record.push_back(0);
993 }
994 }elseif (Attr.isTypeAttribute()) {
995Type *Ty = Attr.getValueAsType();
996Record.push_back(Ty ? 6 : 5);
997Record.push_back(getAttrKindEncoding(Attr.getKindAsEnum()));
998if (Ty)
999Record.push_back(VE.getTypeID(Attr.getValueAsType()));
1000 }elseif (Attr.isConstantRangeAttribute()) {
1001Record.push_back(7);
1002Record.push_back(getAttrKindEncoding(Attr.getKindAsEnum()));
1003emitConstantRange(Record, Attr.getValueAsConstantRange(),
1004/*EmitBitWidth=*/true);
1005 }else {
1006assert(Attr.isConstantRangeListAttribute());
1007Record.push_back(8);
1008Record.push_back(getAttrKindEncoding(Attr.getKindAsEnum()));
1009ArrayRef<ConstantRange> Val = Attr.getValueAsConstantRangeList();
1010Record.push_back(Val.size());
1011Record.push_back(Val[0].getBitWidth());
1012for (auto &CR : Val)
1013emitConstantRange(Record, CR,/*EmitBitWidth=*/false);
1014 }
1015 }
1016
1017 Stream.EmitRecord(bitc::PARAMATTR_GRP_CODE_ENTRY,Record);
1018Record.clear();
1019 }
1020
1021 Stream.ExitBlock();
1022}
1023
1024void ModuleBitcodeWriter::writeAttributeTable() {
1025const std::vector<AttributeList> &Attrs = VE.getAttributeLists();
1026if (Attrs.empty())return;
1027
1028 Stream.EnterSubblock(bitc::PARAMATTR_BLOCK_ID, 3);
1029
1030SmallVector<uint64_t, 64>Record;
1031for (constAttributeList &AL : Attrs) {
1032for (unsigned i :AL.indexes()) {
1033AttributeSet AS =AL.getAttributes(i);
1034if (AS.hasAttributes())
1035Record.push_back(VE.getAttributeGroupID({i, AS}));
1036 }
1037
1038 Stream.EmitRecord(bitc::PARAMATTR_CODE_ENTRY,Record);
1039Record.clear();
1040 }
1041
1042 Stream.ExitBlock();
1043}
1044
1045/// WriteTypeTable - Write out the type table for a module.
1046void ModuleBitcodeWriter::writeTypeTable() {
1047constValueEnumerator::TypeList &TypeList = VE.getTypes();
1048
1049 Stream.EnterSubblock(bitc::TYPE_BLOCK_ID_NEW, 4/*count from # abbrevs */);
1050SmallVector<uint64_t, 64> TypeVals;
1051
1052uint64_t NumBits = VE.computeBitsRequiredForTypeIndices();
1053
1054// Abbrev for TYPE_CODE_OPAQUE_POINTER.
1055auto Abbv = std::make_shared<BitCodeAbbrev>();
1056 Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_OPAQUE_POINTER));
1057 Abbv->Add(BitCodeAbbrevOp(0));// Addrspace = 0
1058unsigned OpaquePtrAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1059
1060// Abbrev for TYPE_CODE_FUNCTION.
1061 Abbv = std::make_shared<BitCodeAbbrev>();
1062 Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_FUNCTION));
1063 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));// isvararg
1064 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1065 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits));
1066unsigned FunctionAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1067
1068// Abbrev for TYPE_CODE_STRUCT_ANON.
1069 Abbv = std::make_shared<BitCodeAbbrev>();
1070 Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_STRUCT_ANON));
1071 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));// ispacked
1072 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1073 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits));
1074unsigned StructAnonAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1075
1076// Abbrev for TYPE_CODE_STRUCT_NAME.
1077 Abbv = std::make_shared<BitCodeAbbrev>();
1078 Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_STRUCT_NAME));
1079 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1080 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6));
1081unsigned StructNameAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1082
1083// Abbrev for TYPE_CODE_STRUCT_NAMED.
1084 Abbv = std::make_shared<BitCodeAbbrev>();
1085 Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_STRUCT_NAMED));
1086 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));// ispacked
1087 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1088 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits));
1089unsigned StructNamedAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1090
1091// Abbrev for TYPE_CODE_ARRAY.
1092 Abbv = std::make_shared<BitCodeAbbrev>();
1093 Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_ARRAY));
1094 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// size
1095 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits));
1096unsigned ArrayAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1097
1098// Emit an entry count so the reader can reserve space.
1099 TypeVals.push_back(TypeList.size());
1100 Stream.EmitRecord(bitc::TYPE_CODE_NUMENTRY, TypeVals);
1101 TypeVals.clear();
1102
1103// Loop over all of the types, emitting each in turn.
1104for (Type *T : TypeList) {
1105int AbbrevToUse = 0;
1106unsignedCode = 0;
1107
1108switch (T->getTypeID()) {
1109caseType::VoidTyID:Code =bitc::TYPE_CODE_VOID;break;
1110caseType::HalfTyID:Code =bitc::TYPE_CODE_HALF;break;
1111caseType::BFloatTyID:Code =bitc::TYPE_CODE_BFLOAT;break;
1112caseType::FloatTyID:Code =bitc::TYPE_CODE_FLOAT;break;
1113caseType::DoubleTyID:Code =bitc::TYPE_CODE_DOUBLE;break;
1114caseType::X86_FP80TyID:Code =bitc::TYPE_CODE_X86_FP80;break;
1115caseType::FP128TyID:Code =bitc::TYPE_CODE_FP128;break;
1116caseType::PPC_FP128TyID:Code =bitc::TYPE_CODE_PPC_FP128;break;
1117caseType::LabelTyID:Code =bitc::TYPE_CODE_LABEL;break;
1118caseType::MetadataTyID:
1119Code =bitc::TYPE_CODE_METADATA;
1120break;
1121caseType::X86_AMXTyID:Code =bitc::TYPE_CODE_X86_AMX;break;
1122caseType::TokenTyID:Code =bitc::TYPE_CODE_TOKEN;break;
1123caseType::IntegerTyID:
1124// INTEGER: [width]
1125Code =bitc::TYPE_CODE_INTEGER;
1126 TypeVals.push_back(cast<IntegerType>(T)->getBitWidth());
1127break;
1128caseType::PointerTyID: {
1129PointerType *PTy = cast<PointerType>(T);
1130unsignedAddressSpace = PTy->getAddressSpace();
1131// OPAQUE_POINTER: [address space]
1132Code =bitc::TYPE_CODE_OPAQUE_POINTER;
1133 TypeVals.push_back(AddressSpace);
1134if (AddressSpace == 0)
1135 AbbrevToUse = OpaquePtrAbbrev;
1136break;
1137 }
1138caseType::FunctionTyID: {
1139FunctionType *FT = cast<FunctionType>(T);
1140// FUNCTION: [isvararg, retty, paramty x N]
1141Code =bitc::TYPE_CODE_FUNCTION;
1142 TypeVals.push_back(FT->isVarArg());
1143 TypeVals.push_back(VE.getTypeID(FT->getReturnType()));
1144for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
1145 TypeVals.push_back(VE.getTypeID(FT->getParamType(i)));
1146 AbbrevToUse = FunctionAbbrev;
1147break;
1148 }
1149caseType::StructTyID: {
1150StructType *ST = cast<StructType>(T);
1151// STRUCT: [ispacked, eltty x N]
1152 TypeVals.push_back(ST->isPacked());
1153// Output all of the element types.
1154for (Type *ET :ST->elements())
1155 TypeVals.push_back(VE.getTypeID(ET));
1156
1157if (ST->isLiteral()) {
1158Code =bitc::TYPE_CODE_STRUCT_ANON;
1159 AbbrevToUse = StructAnonAbbrev;
1160 }else {
1161if (ST->isOpaque()) {
1162Code =bitc::TYPE_CODE_OPAQUE;
1163 }else {
1164Code =bitc::TYPE_CODE_STRUCT_NAMED;
1165 AbbrevToUse = StructNamedAbbrev;
1166 }
1167
1168// Emit the name if it is present.
1169if (!ST->getName().empty())
1170writeStringRecord(Stream,bitc::TYPE_CODE_STRUCT_NAME,ST->getName(),
1171 StructNameAbbrev);
1172 }
1173break;
1174 }
1175caseType::ArrayTyID: {
1176ArrayType *AT = cast<ArrayType>(T);
1177// ARRAY: [numelts, eltty]
1178Code =bitc::TYPE_CODE_ARRAY;
1179 TypeVals.push_back(AT->getNumElements());
1180 TypeVals.push_back(VE.getTypeID(AT->getElementType()));
1181 AbbrevToUse = ArrayAbbrev;
1182break;
1183 }
1184caseType::FixedVectorTyID:
1185caseType::ScalableVectorTyID: {
1186VectorType *VT = cast<VectorType>(T);
1187// VECTOR [numelts, eltty] or
1188// [numelts, eltty, scalable]
1189Code =bitc::TYPE_CODE_VECTOR;
1190 TypeVals.push_back(VT->getElementCount().getKnownMinValue());
1191 TypeVals.push_back(VE.getTypeID(VT->getElementType()));
1192if (isa<ScalableVectorType>(VT))
1193 TypeVals.push_back(true);
1194break;
1195 }
1196caseType::TargetExtTyID: {
1197TargetExtType *TET = cast<TargetExtType>(T);
1198Code =bitc::TYPE_CODE_TARGET_TYPE;
1199writeStringRecord(Stream,bitc::TYPE_CODE_STRUCT_NAME,TET->getName(),
1200 StructNameAbbrev);
1201 TypeVals.push_back(TET->getNumTypeParameters());
1202for (Type *InnerTy :TET->type_params())
1203 TypeVals.push_back(VE.getTypeID(InnerTy));
1204for (unsigned IntParam :TET->int_params())
1205 TypeVals.push_back(IntParam);
1206break;
1207 }
1208caseType::TypedPointerTyID:
1209llvm_unreachable("Typed pointers cannot be added to IR modules");
1210 }
1211
1212// Emit the finished record.
1213 Stream.EmitRecord(Code, TypeVals, AbbrevToUse);
1214 TypeVals.clear();
1215 }
1216
1217 Stream.ExitBlock();
1218}
1219
1220staticunsignedgetEncodedLinkage(constGlobalValue::LinkageTypes Linkage) {
1221switch (Linkage) {
1222caseGlobalValue::ExternalLinkage:
1223return 0;
1224caseGlobalValue::WeakAnyLinkage:
1225return 16;
1226caseGlobalValue::AppendingLinkage:
1227return 2;
1228caseGlobalValue::InternalLinkage:
1229return 3;
1230caseGlobalValue::LinkOnceAnyLinkage:
1231return 18;
1232caseGlobalValue::ExternalWeakLinkage:
1233return 7;
1234caseGlobalValue::CommonLinkage:
1235return 8;
1236caseGlobalValue::PrivateLinkage:
1237return 9;
1238caseGlobalValue::WeakODRLinkage:
1239return 17;
1240caseGlobalValue::LinkOnceODRLinkage:
1241return 19;
1242caseGlobalValue::AvailableExternallyLinkage:
1243return 12;
1244 }
1245llvm_unreachable("Invalid linkage");
1246}
1247
1248staticunsignedgetEncodedLinkage(constGlobalValue &GV) {
1249returngetEncodedLinkage(GV.getLinkage());
1250}
1251
1252staticuint64_tgetEncodedFFlags(FunctionSummary::FFlags Flags) {
1253uint64_t RawFlags = 0;
1254 RawFlags |= Flags.ReadNone;
1255 RawFlags |= (Flags.ReadOnly << 1);
1256 RawFlags |= (Flags.NoRecurse << 2);
1257 RawFlags |= (Flags.ReturnDoesNotAlias << 3);
1258 RawFlags |= (Flags.NoInline << 4);
1259 RawFlags |= (Flags.AlwaysInline << 5);
1260 RawFlags |= (Flags.NoUnwind << 6);
1261 RawFlags |= (Flags.MayThrow << 7);
1262 RawFlags |= (Flags.HasUnknownCall << 8);
1263 RawFlags |= (Flags.MustBeUnreachable << 9);
1264return RawFlags;
1265}
1266
1267// Decode the flags for GlobalValue in the summary. See getDecodedGVSummaryFlags
1268// in BitcodeReader.cpp.
1269staticuint64_tgetEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags,
1270bool ImportAsDecl =false) {
1271uint64_t RawFlags = 0;
1272
1273 RawFlags |= Flags.NotEligibleToImport;// bool
1274 RawFlags |= (Flags.Live << 1);
1275 RawFlags |= (Flags.DSOLocal << 2);
1276 RawFlags |= (Flags.CanAutoHide << 3);
1277
1278// Linkage don't need to be remapped at that time for the summary. Any future
1279// change to the getEncodedLinkage() function will need to be taken into
1280// account here as well.
1281 RawFlags = (RawFlags << 4) | Flags.Linkage;// 4 bits
1282
1283 RawFlags |= (Flags.Visibility << 8);// 2 bits
1284
1285unsigned ImportType = Flags.ImportType | ImportAsDecl;
1286 RawFlags |= (ImportType << 10);// 1 bit
1287
1288return RawFlags;
1289}
1290
1291staticuint64_tgetEncodedGVarFlags(GlobalVarSummary::GVarFlags Flags) {
1292uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
1293 (Flags.Constant << 2) | Flags.VCallVisibility << 3;
1294return RawFlags;
1295}
1296
1297staticuint64_tgetEncodedHotnessCallEdgeInfo(constCalleeInfo &CI) {
1298uint64_t RawFlags = 0;
1299
1300 RawFlags |= CI.Hotness;// 3 bits
1301 RawFlags |= (CI.HasTailCall << 3);// 1 bit
1302
1303return RawFlags;
1304}
1305
1306staticuint64_tgetEncodedRelBFCallEdgeInfo(constCalleeInfo &CI) {
1307uint64_t RawFlags = 0;
1308
1309 RawFlags |= CI.RelBlockFreq;// CalleeInfo::RelBlockFreqBits bits
1310 RawFlags |= (CI.HasTailCall <<CalleeInfo::RelBlockFreqBits);// 1 bit
1311
1312return RawFlags;
1313}
1314
1315staticunsignedgetEncodedVisibility(constGlobalValue &GV) {
1316switch (GV.getVisibility()) {
1317caseGlobalValue::DefaultVisibility:return 0;
1318caseGlobalValue::HiddenVisibility:return 1;
1319caseGlobalValue::ProtectedVisibility:return 2;
1320 }
1321llvm_unreachable("Invalid visibility");
1322}
1323
1324staticunsignedgetEncodedDLLStorageClass(constGlobalValue &GV) {
1325switch (GV.getDLLStorageClass()) {
1326caseGlobalValue::DefaultStorageClass:return 0;
1327caseGlobalValue::DLLImportStorageClass:return 1;
1328caseGlobalValue::DLLExportStorageClass:return 2;
1329 }
1330llvm_unreachable("Invalid DLL storage class");
1331}
1332
1333staticunsignedgetEncodedThreadLocalMode(constGlobalValue &GV) {
1334switch (GV.getThreadLocalMode()) {
1335case GlobalVariable::NotThreadLocal:return 0;
1336case GlobalVariable::GeneralDynamicTLSModel:return 1;
1337case GlobalVariable::LocalDynamicTLSModel:return 2;
1338case GlobalVariable::InitialExecTLSModel:return 3;
1339case GlobalVariable::LocalExecTLSModel:return 4;
1340 }
1341llvm_unreachable("Invalid TLS model");
1342}
1343
1344staticunsignedgetEncodedComdatSelectionKind(constComdat &C) {
1345switch (C.getSelectionKind()) {
1346caseComdat::Any:
1347returnbitc::COMDAT_SELECTION_KIND_ANY;
1348caseComdat::ExactMatch:
1349returnbitc::COMDAT_SELECTION_KIND_EXACT_MATCH;
1350caseComdat::Largest:
1351returnbitc::COMDAT_SELECTION_KIND_LARGEST;
1352caseComdat::NoDeduplicate:
1353returnbitc::COMDAT_SELECTION_KIND_NO_DUPLICATES;
1354caseComdat::SameSize:
1355returnbitc::COMDAT_SELECTION_KIND_SAME_SIZE;
1356 }
1357llvm_unreachable("Invalid selection kind");
1358}
1359
1360staticunsignedgetEncodedUnnamedAddr(constGlobalValue &GV) {
1361switch (GV.getUnnamedAddr()) {
1362case GlobalValue::UnnamedAddr::None:return 0;
1363case GlobalValue::UnnamedAddr::Local:return 2;
1364case GlobalValue::UnnamedAddr::Global:return 1;
1365 }
1366llvm_unreachable("Invalid unnamed_addr");
1367}
1368
1369size_t ModuleBitcodeWriter::addToStrtab(StringRef Str) {
1370if (GenerateHash)
1371 Hasher.update(Str);
1372return StrtabBuilder.add(Str);
1373}
1374
1375void ModuleBitcodeWriter::writeComdats() {
1376SmallVector<unsigned, 64> Vals;
1377for (constComdat *C : VE.getComdats()) {
1378// COMDAT: [strtab offset, strtab size, selection_kind]
1379 Vals.push_back(addToStrtab(C->getName()));
1380 Vals.push_back(C->getName().size());
1381 Vals.push_back(getEncodedComdatSelectionKind(*C));
1382 Stream.EmitRecord(bitc::MODULE_CODE_COMDAT, Vals,/*AbbrevToUse=*/0);
1383 Vals.clear();
1384 }
1385}
1386
1387/// Write a record that will eventually hold the word offset of the
1388/// module-level VST. For now the offset is 0, which will be backpatched
1389/// after the real VST is written. Saves the bit offset to backpatch.
1390void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
1391// Write a placeholder value in for the offset of the real VST,
1392// which is written after the function blocks so that it can include
1393// the offset of each function. The placeholder offset will be
1394// updated when the real VST is written.
1395auto Abbv = std::make_shared<BitCodeAbbrev>();
1396 Abbv->Add(BitCodeAbbrevOp(bitc::MODULE_CODE_VSTOFFSET));
1397// Blocks are 32-bit aligned, so we can use a 32-bit word offset to
1398// hold the real VST offset. Must use fixed instead of VBR as we don't
1399// know how many VBR chunks to reserve ahead of time.
1400 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
1401unsigned VSTOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1402
1403// Emit the placeholder
1404uint64_t Vals[] = {bitc::MODULE_CODE_VSTOFFSET, 0};
1405 Stream.EmitRecordWithAbbrev(VSTOffsetAbbrev, Vals);
1406
1407// Compute and save the bit offset to the placeholder, which will be
1408// patched when the real VST is written. We can simply subtract the 32-bit
1409// fixed size from the current bit number to get the location to backpatch.
1410 VSTOffsetPlaceholder = Stream.GetCurrentBitNo() - 32;
1411}
1412
1413enumStringEncoding {SE_Char6,SE_Fixed7,SE_Fixed8 };
1414
1415/// Determine the encoding to use for the given string name and length.
1416staticStringEncodinggetStringEncoding(StringRef Str) {
1417bool isChar6 =true;
1418for (charC : Str) {
1419if (isChar6)
1420 isChar6 =BitCodeAbbrevOp::isChar6(C);
1421if ((unsignedchar)C & 128)
1422// don't bother scanning the rest.
1423returnSE_Fixed8;
1424 }
1425if (isChar6)
1426returnSE_Char6;
1427returnSE_Fixed7;
1428}
1429
1430static_assert(sizeof(GlobalValue::SanitizerMetadata) <=sizeof(unsigned),
1431"Sanitizer Metadata is too large for naive serialization.");
1432staticunsigned
1433serializeSanitizerMetadata(constGlobalValue::SanitizerMetadata &Meta) {
1434returnMeta.NoAddress | (Meta.NoHWAddress << 1) |
1435 (Meta.Memtag << 2) | (Meta.IsDynInit << 3);
1436}
1437
1438/// Emit top-level description of module, including target triple, inline asm,
1439/// descriptors for global variables, and function prototype info.
1440/// Returns the bit offset to backpatch with the location of the real VST.
1441void ModuleBitcodeWriter::writeModuleInfo() {
1442// Emit various pieces of data attached to a module.
1443if (!M.getTargetTriple().empty())
1444writeStringRecord(Stream,bitc::MODULE_CODE_TRIPLE,M.getTargetTriple(),
1445 0/*TODO*/);
1446const std::string &DL =M.getDataLayoutStr();
1447if (!DL.empty())
1448writeStringRecord(Stream,bitc::MODULE_CODE_DATALAYOUT,DL, 0/*TODO*/);
1449if (!M.getModuleInlineAsm().empty())
1450writeStringRecord(Stream,bitc::MODULE_CODE_ASM,M.getModuleInlineAsm(),
1451 0/*TODO*/);
1452
1453// Emit information about sections and GC, computing how many there are. Also
1454// compute the maximum alignment value.
1455 std::map<std::string, unsigned> SectionMap;
1456 std::map<std::string, unsigned> GCMap;
1457MaybeAlign MaxAlignment;
1458unsigned MaxGlobalType = 0;
1459constauto UpdateMaxAlignment = [&MaxAlignment](constMaybeAlignA) {
1460if (A)
1461 MaxAlignment = !MaxAlignment ? *A : std::max(*MaxAlignment, *A);
1462 };
1463for (constGlobalVariable &GV :M.globals()) {
1464 UpdateMaxAlignment(GV.getAlign());
1465 MaxGlobalType = std::max(MaxGlobalType, VE.getTypeID(GV.getValueType()));
1466if (GV.hasSection()) {
1467// Give section names unique ID's.
1468unsigned &Entry = SectionMap[std::string(GV.getSection())];
1469if (!Entry) {
1470writeStringRecord(Stream,bitc::MODULE_CODE_SECTIONNAME, GV.getSection(),
1471 0/*TODO*/);
1472Entry = SectionMap.size();
1473 }
1474 }
1475 }
1476for (constFunction &F : M) {
1477 UpdateMaxAlignment(F.getAlign());
1478if (F.hasSection()) {
1479// Give section names unique ID's.
1480unsigned &Entry = SectionMap[std::string(F.getSection())];
1481if (!Entry) {
1482writeStringRecord(Stream,bitc::MODULE_CODE_SECTIONNAME,F.getSection(),
1483 0/*TODO*/);
1484Entry = SectionMap.size();
1485 }
1486 }
1487if (F.hasGC()) {
1488// Same for GC names.
1489unsigned &Entry = GCMap[F.getGC()];
1490if (!Entry) {
1491writeStringRecord(Stream,bitc::MODULE_CODE_GCNAME,F.getGC(),
1492 0/*TODO*/);
1493Entry = GCMap.size();
1494 }
1495 }
1496 }
1497
1498// Emit abbrev for globals, now that we know # sections and max alignment.
1499unsigned SimpleGVarAbbrev = 0;
1500if (!M.global_empty()) {
1501// Add an abbrev for common globals with no visibility or thread localness.
1502auto Abbv = std::make_shared<BitCodeAbbrev>();
1503 Abbv->Add(BitCodeAbbrevOp(bitc::MODULE_CODE_GLOBALVAR));
1504 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
1505 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
1506 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
1507Log2_32_Ceil(MaxGlobalType+1)));
1508 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// AddrSpace << 2
1509//| explicitType << 1
1510//| constant
1511 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// Initializer.
1512 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5));// Linkage.
1513if (!MaxAlignment)// Alignment.
1514 Abbv->Add(BitCodeAbbrevOp(0));
1515else {
1516unsigned MaxEncAlignment = getEncodedAlign(MaxAlignment);
1517 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
1518Log2_32_Ceil(MaxEncAlignment+1)));
1519 }
1520if (SectionMap.empty())// Section.
1521 Abbv->Add(BitCodeAbbrevOp(0));
1522else
1523 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
1524Log2_32_Ceil(SectionMap.size()+1)));
1525// Don't bother emitting vis + thread local.
1526 SimpleGVarAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1527 }
1528
1529SmallVector<unsigned, 64> Vals;
1530// Emit the module's source file name.
1531 {
1532StringEncodingBits =getStringEncoding(M.getSourceFileName());
1533BitCodeAbbrevOp AbbrevOpToUse =BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8);
1534if (Bits ==SE_Char6)
1535 AbbrevOpToUse =BitCodeAbbrevOp(BitCodeAbbrevOp::Char6);
1536elseif (Bits ==SE_Fixed7)
1537 AbbrevOpToUse =BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7);
1538
1539// MODULE_CODE_SOURCE_FILENAME: [namechar x N]
1540auto Abbv = std::make_shared<BitCodeAbbrev>();
1541 Abbv->Add(BitCodeAbbrevOp(bitc::MODULE_CODE_SOURCE_FILENAME));
1542 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1543 Abbv->Add(AbbrevOpToUse);
1544unsigned FilenameAbbrev = Stream.EmitAbbrev(std::move(Abbv));
1545
1546for (constautoP :M.getSourceFileName())
1547 Vals.push_back((unsignedchar)P);
1548
1549// Emit the finished record.
1550 Stream.EmitRecord(bitc::MODULE_CODE_SOURCE_FILENAME, Vals, FilenameAbbrev);
1551 Vals.clear();
1552 }
1553
1554// Emit the global variable information.
1555for (constGlobalVariable &GV :M.globals()) {
1556unsigned AbbrevToUse = 0;
1557
1558// GLOBALVAR: [strtab offset, strtab size, type, isconst, initid,
1559// linkage, alignment, section, visibility, threadlocal,
1560// unnamed_addr, externally_initialized, dllstorageclass,
1561// comdat, attributes, DSO_Local, GlobalSanitizer, code_model]
1562 Vals.push_back(addToStrtab(GV.getName()));
1563 Vals.push_back(GV.getName().size());
1564 Vals.push_back(VE.getTypeID(GV.getValueType()));
1565 Vals.push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1566 Vals.push_back(GV.isDeclaration() ? 0 :
1567 (VE.getValueID(GV.getInitializer()) + 1));
1568 Vals.push_back(getEncodedLinkage(GV));
1569 Vals.push_back(getEncodedAlign(GV.getAlign()));
1570 Vals.push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1571 : 0);
1572if (GV.isThreadLocal() ||
1573 GV.getVisibility() !=GlobalValue::DefaultVisibility ||
1574 GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1575 GV.isExternallyInitialized() ||
1576 GV.getDLLStorageClass() !=GlobalValue::DefaultStorageClass ||
1577 GV.hasComdat() || GV.hasAttributes() || GV.isDSOLocal() ||
1578 GV.hasPartition() || GV.hasSanitizerMetadata() || GV.getCodeModel()) {
1579 Vals.push_back(getEncodedVisibility(GV));
1580 Vals.push_back(getEncodedThreadLocalMode(GV));
1581 Vals.push_back(getEncodedUnnamedAddr(GV));
1582 Vals.push_back(GV.isExternallyInitialized());
1583 Vals.push_back(getEncodedDLLStorageClass(GV));
1584 Vals.push_back(GV.hasComdat() ? VE.getComdatID(GV.getComdat()) : 0);
1585
1586autoAL = GV.getAttributesAsList(AttributeList::FunctionIndex);
1587 Vals.push_back(VE.getAttributeListID(AL));
1588
1589 Vals.push_back(GV.isDSOLocal());
1590 Vals.push_back(addToStrtab(GV.getPartition()));
1591 Vals.push_back(GV.getPartition().size());
1592
1593 Vals.push_back((GV.hasSanitizerMetadata() ?serializeSanitizerMetadata(
1594 GV.getSanitizerMetadata())
1595 : 0));
1596 Vals.push_back(GV.getCodeModelRaw());
1597 }else {
1598 AbbrevToUse = SimpleGVarAbbrev;
1599 }
1600
1601 Stream.EmitRecord(bitc::MODULE_CODE_GLOBALVAR, Vals, AbbrevToUse);
1602 Vals.clear();
1603 }
1604
1605// Emit the function proto information.
1606for (constFunction &F : M) {
1607// FUNCTION: [strtab offset, strtab size, type, callingconv, isproto,
1608// linkage, paramattrs, alignment, section, visibility, gc,
1609// unnamed_addr, prologuedata, dllstorageclass, comdat,
1610// prefixdata, personalityfn, DSO_Local, addrspace]
1611 Vals.push_back(addToStrtab(F.getName()));
1612 Vals.push_back(F.getName().size());
1613 Vals.push_back(VE.getTypeID(F.getFunctionType()));
1614 Vals.push_back(F.getCallingConv());
1615 Vals.push_back(F.isDeclaration());
1616 Vals.push_back(getEncodedLinkage(F));
1617 Vals.push_back(VE.getAttributeListID(F.getAttributes()));
1618 Vals.push_back(getEncodedAlign(F.getAlign()));
1619 Vals.push_back(F.hasSection() ? SectionMap[std::string(F.getSection())]
1620 : 0);
1621 Vals.push_back(getEncodedVisibility(F));
1622 Vals.push_back(F.hasGC() ? GCMap[F.getGC()] : 0);
1623 Vals.push_back(getEncodedUnnamedAddr(F));
1624 Vals.push_back(F.hasPrologueData() ? (VE.getValueID(F.getPrologueData()) + 1)
1625 : 0);
1626 Vals.push_back(getEncodedDLLStorageClass(F));
1627 Vals.push_back(F.hasComdat() ? VE.getComdatID(F.getComdat()) : 0);
1628 Vals.push_back(F.hasPrefixData() ? (VE.getValueID(F.getPrefixData()) + 1)
1629 : 0);
1630 Vals.push_back(
1631F.hasPersonalityFn() ? (VE.getValueID(F.getPersonalityFn()) + 1) : 0);
1632
1633 Vals.push_back(F.isDSOLocal());
1634 Vals.push_back(F.getAddressSpace());
1635 Vals.push_back(addToStrtab(F.getPartition()));
1636 Vals.push_back(F.getPartition().size());
1637
1638unsigned AbbrevToUse = 0;
1639 Stream.EmitRecord(bitc::MODULE_CODE_FUNCTION, Vals, AbbrevToUse);
1640 Vals.clear();
1641 }
1642
1643// Emit the alias information.
1644for (constGlobalAlias &A :M.aliases()) {
1645// ALIAS: [strtab offset, strtab size, alias type, aliasee val#, linkage,
1646// visibility, dllstorageclass, threadlocal, unnamed_addr,
1647// DSO_Local]
1648 Vals.push_back(addToStrtab(A.getName()));
1649 Vals.push_back(A.getName().size());
1650 Vals.push_back(VE.getTypeID(A.getValueType()));
1651 Vals.push_back(A.getType()->getAddressSpace());
1652 Vals.push_back(VE.getValueID(A.getAliasee()));
1653 Vals.push_back(getEncodedLinkage(A));
1654 Vals.push_back(getEncodedVisibility(A));
1655 Vals.push_back(getEncodedDLLStorageClass(A));
1656 Vals.push_back(getEncodedThreadLocalMode(A));
1657 Vals.push_back(getEncodedUnnamedAddr(A));
1658 Vals.push_back(A.isDSOLocal());
1659 Vals.push_back(addToStrtab(A.getPartition()));
1660 Vals.push_back(A.getPartition().size());
1661
1662unsigned AbbrevToUse = 0;
1663 Stream.EmitRecord(bitc::MODULE_CODE_ALIAS, Vals, AbbrevToUse);
1664 Vals.clear();
1665 }
1666
1667// Emit the ifunc information.
1668for (constGlobalIFunc &I :M.ifuncs()) {
1669// IFUNC: [strtab offset, strtab size, ifunc type, address space, resolver
1670// val#, linkage, visibility, DSO_Local]
1671 Vals.push_back(addToStrtab(I.getName()));
1672 Vals.push_back(I.getName().size());
1673 Vals.push_back(VE.getTypeID(I.getValueType()));
1674 Vals.push_back(I.getType()->getAddressSpace());
1675 Vals.push_back(VE.getValueID(I.getResolver()));
1676 Vals.push_back(getEncodedLinkage(I));
1677 Vals.push_back(getEncodedVisibility(I));
1678 Vals.push_back(I.isDSOLocal());
1679 Vals.push_back(addToStrtab(I.getPartition()));
1680 Vals.push_back(I.getPartition().size());
1681 Stream.EmitRecord(bitc::MODULE_CODE_IFUNC, Vals);
1682 Vals.clear();
1683 }
1684
1685 writeValueSymbolTableForwardDecl();
1686}
1687
1688staticuint64_tgetOptimizationFlags(constValue *V) {
1689uint64_t Flags = 0;
1690
1691if (constauto *OBO = dyn_cast<OverflowingBinaryOperator>(V)) {
1692if (OBO->hasNoSignedWrap())
1693 Flags |= 1 <<bitc::OBO_NO_SIGNED_WRAP;
1694if (OBO->hasNoUnsignedWrap())
1695 Flags |= 1 <<bitc::OBO_NO_UNSIGNED_WRAP;
1696 }elseif (constauto *PEO = dyn_cast<PossiblyExactOperator>(V)) {
1697if (PEO->isExact())
1698 Flags |= 1 <<bitc::PEO_EXACT;
1699 }elseif (constauto *PDI = dyn_cast<PossiblyDisjointInst>(V)) {
1700if (PDI->isDisjoint())
1701 Flags |= 1 <<bitc::PDI_DISJOINT;
1702 }elseif (constauto *FPMO = dyn_cast<FPMathOperator>(V)) {
1703if (FPMO->hasAllowReassoc())
1704 Flags |=bitc::AllowReassoc;
1705if (FPMO->hasNoNaNs())
1706 Flags |=bitc::NoNaNs;
1707if (FPMO->hasNoInfs())
1708 Flags |=bitc::NoInfs;
1709if (FPMO->hasNoSignedZeros())
1710 Flags |=bitc::NoSignedZeros;
1711if (FPMO->hasAllowReciprocal())
1712 Flags |=bitc::AllowReciprocal;
1713if (FPMO->hasAllowContract())
1714 Flags |=bitc::AllowContract;
1715if (FPMO->hasApproxFunc())
1716 Flags |=bitc::ApproxFunc;
1717 }elseif (constauto *NNI = dyn_cast<PossiblyNonNegInst>(V)) {
1718if (NNI->hasNonNeg())
1719 Flags |= 1 <<bitc::PNNI_NON_NEG;
1720 }elseif (constauto *TI = dyn_cast<TruncInst>(V)) {
1721if (TI->hasNoSignedWrap())
1722 Flags |= 1 <<bitc::TIO_NO_SIGNED_WRAP;
1723if (TI->hasNoUnsignedWrap())
1724 Flags |= 1 <<bitc::TIO_NO_UNSIGNED_WRAP;
1725 }elseif (constauto *GEP = dyn_cast<GEPOperator>(V)) {
1726if (GEP->isInBounds())
1727 Flags |= 1 <<bitc::GEP_INBOUNDS;
1728if (GEP->hasNoUnsignedSignedWrap())
1729 Flags |= 1 <<bitc::GEP_NUSW;
1730if (GEP->hasNoUnsignedWrap())
1731 Flags |= 1 <<bitc::GEP_NUW;
1732 }elseif (constauto *ICmp = dyn_cast<ICmpInst>(V)) {
1733if (ICmp->hasSameSign())
1734 Flags |= 1 <<bitc::ICMP_SAME_SIGN;
1735 }
1736
1737return Flags;
1738}
1739
1740void ModuleBitcodeWriter::writeValueAsMetadata(
1741constValueAsMetadata *MD,SmallVectorImpl<uint64_t> &Record) {
1742// Mimic an MDNode with a value as one operand.
1743Value *V = MD->getValue();
1744Record.push_back(VE.getTypeID(V->getType()));
1745Record.push_back(VE.getValueID(V));
1746 Stream.EmitRecord(bitc::METADATA_VALUE,Record, 0);
1747Record.clear();
1748}
1749
1750void ModuleBitcodeWriter::writeMDTuple(constMDTuple *N,
1751SmallVectorImpl<uint64_t> &Record,
1752unsigned Abbrev) {
1753for (constMDOperand &MDO :N->operands()) {
1754Metadata *MD = MDO;
1755assert(!(MD && isa<LocalAsMetadata>(MD)) &&
1756"Unexpected function-local metadata");
1757Record.push_back(VE.getMetadataOrNullID(MD));
1758 }
1759 Stream.EmitRecord(N->isDistinct() ?bitc::METADATA_DISTINCT_NODE
1760 :bitc::METADATA_NODE,
1761Record, Abbrev);
1762Record.clear();
1763}
1764
1765unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1766// Assume the column is usually under 128, and always output the inlined-at
1767// location (it's never more expensive than building an array size 1).
1768auto Abbv = std::make_shared<BitCodeAbbrev>();
1769 Abbv->Add(BitCodeAbbrevOp(bitc::METADATA_LOCATION));
1770 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
1771 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1772 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
1773 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1774 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1775 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
1776return Stream.EmitAbbrev(std::move(Abbv));
1777}
1778
1779void ModuleBitcodeWriter::writeDILocation(constDILocation *N,
1780SmallVectorImpl<uint64_t> &Record,
1781unsigned &Abbrev) {
1782if (!Abbrev)
1783 Abbrev = createDILocationAbbrev();
1784
1785Record.push_back(N->isDistinct());
1786Record.push_back(N->getLine());
1787Record.push_back(N->getColumn());
1788Record.push_back(VE.getMetadataID(N->getScope()));
1789Record.push_back(VE.getMetadataOrNullID(N->getInlinedAt()));
1790Record.push_back(N->isImplicitCode());
1791
1792 Stream.EmitRecord(bitc::METADATA_LOCATION,Record, Abbrev);
1793Record.clear();
1794}
1795
1796unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1797// Assume the column is usually under 128, and always output the inlined-at
1798// location (it's never more expensive than building an array size 1).
1799auto Abbv = std::make_shared<BitCodeAbbrev>();
1800 Abbv->Add(BitCodeAbbrevOp(bitc::METADATA_GENERIC_DEBUG));
1801 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
1802 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1803 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
1804 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1805 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1806 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1807return Stream.EmitAbbrev(std::move(Abbv));
1808}
1809
1810void ModuleBitcodeWriter::writeGenericDINode(constGenericDINode *N,
1811SmallVectorImpl<uint64_t> &Record,
1812unsigned &Abbrev) {
1813if (!Abbrev)
1814 Abbrev = createGenericDINodeAbbrev();
1815
1816Record.push_back(N->isDistinct());
1817Record.push_back(N->getTag());
1818Record.push_back(0);// Per-tag version field; unused for now.
1819
1820for (auto &I :N->operands())
1821Record.push_back(VE.getMetadataOrNullID(I));
1822
1823 Stream.EmitRecord(bitc::METADATA_GENERIC_DEBUG,Record, Abbrev);
1824Record.clear();
1825}
1826
1827void ModuleBitcodeWriter::writeDISubrange(constDISubrange *N,
1828SmallVectorImpl<uint64_t> &Record,
1829unsigned Abbrev) {
1830constuint64_tVersion = 2 << 1;
1831Record.push_back((uint64_t)N->isDistinct() | Version);
1832Record.push_back(VE.getMetadataOrNullID(N->getRawCountNode()));
1833Record.push_back(VE.getMetadataOrNullID(N->getRawLowerBound()));
1834Record.push_back(VE.getMetadataOrNullID(N->getRawUpperBound()));
1835Record.push_back(VE.getMetadataOrNullID(N->getRawStride()));
1836
1837 Stream.EmitRecord(bitc::METADATA_SUBRANGE,Record, Abbrev);
1838Record.clear();
1839}
1840
1841void ModuleBitcodeWriter::writeDIGenericSubrange(
1842constDIGenericSubrange *N,SmallVectorImpl<uint64_t> &Record,
1843unsigned Abbrev) {
1844Record.push_back((uint64_t)N->isDistinct());
1845Record.push_back(VE.getMetadataOrNullID(N->getRawCountNode()));
1846Record.push_back(VE.getMetadataOrNullID(N->getRawLowerBound()));
1847Record.push_back(VE.getMetadataOrNullID(N->getRawUpperBound()));
1848Record.push_back(VE.getMetadataOrNullID(N->getRawStride()));
1849
1850 Stream.EmitRecord(bitc::METADATA_GENERIC_SUBRANGE,Record, Abbrev);
1851Record.clear();
1852}
1853
1854void ModuleBitcodeWriter::writeDIEnumerator(constDIEnumerator *N,
1855SmallVectorImpl<uint64_t> &Record,
1856unsigned Abbrev) {
1857constuint64_t IsBigInt = 1 << 2;
1858Record.push_back(IsBigInt | (N->isUnsigned() << 1) |N->isDistinct());
1859Record.push_back(N->getValue().getBitWidth());
1860Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1861emitWideAPInt(Record,N->getValue());
1862
1863 Stream.EmitRecord(bitc::METADATA_ENUMERATOR,Record, Abbrev);
1864Record.clear();
1865}
1866
1867void ModuleBitcodeWriter::writeDIBasicType(constDIBasicType *N,
1868SmallVectorImpl<uint64_t> &Record,
1869unsigned Abbrev) {
1870Record.push_back(N->isDistinct());
1871Record.push_back(N->getTag());
1872Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1873Record.push_back(N->getSizeInBits());
1874Record.push_back(N->getAlignInBits());
1875Record.push_back(N->getEncoding());
1876Record.push_back(N->getFlags());
1877Record.push_back(N->getNumExtraInhabitants());
1878
1879 Stream.EmitRecord(bitc::METADATA_BASIC_TYPE,Record, Abbrev);
1880Record.clear();
1881}
1882
1883void ModuleBitcodeWriter::writeDIStringType(constDIStringType *N,
1884SmallVectorImpl<uint64_t> &Record,
1885unsigned Abbrev) {
1886Record.push_back(N->isDistinct());
1887Record.push_back(N->getTag());
1888Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1889Record.push_back(VE.getMetadataOrNullID(N->getStringLength()));
1890Record.push_back(VE.getMetadataOrNullID(N->getStringLengthExp()));
1891Record.push_back(VE.getMetadataOrNullID(N->getStringLocationExp()));
1892Record.push_back(N->getSizeInBits());
1893Record.push_back(N->getAlignInBits());
1894Record.push_back(N->getEncoding());
1895
1896 Stream.EmitRecord(bitc::METADATA_STRING_TYPE,Record, Abbrev);
1897Record.clear();
1898}
1899
1900void ModuleBitcodeWriter::writeDIDerivedType(constDIDerivedType *N,
1901SmallVectorImpl<uint64_t> &Record,
1902unsigned Abbrev) {
1903Record.push_back(N->isDistinct());
1904Record.push_back(N->getTag());
1905Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1906Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1907Record.push_back(N->getLine());
1908Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1909Record.push_back(VE.getMetadataOrNullID(N->getBaseType()));
1910Record.push_back(N->getSizeInBits());
1911Record.push_back(N->getAlignInBits());
1912Record.push_back(N->getOffsetInBits());
1913Record.push_back(N->getFlags());
1914Record.push_back(VE.getMetadataOrNullID(N->getExtraData()));
1915
1916// DWARF address space is encoded as N->getDWARFAddressSpace() + 1. 0 means
1917// that there is no DWARF address space associated with DIDerivedType.
1918if (constauto &DWARFAddressSpace =N->getDWARFAddressSpace())
1919Record.push_back(*DWARFAddressSpace + 1);
1920else
1921Record.push_back(0);
1922
1923Record.push_back(VE.getMetadataOrNullID(N->getAnnotations().get()));
1924
1925if (auto PtrAuthData =N->getPtrAuthData())
1926Record.push_back(PtrAuthData->RawData);
1927else
1928Record.push_back(0);
1929
1930 Stream.EmitRecord(bitc::METADATA_DERIVED_TYPE,Record, Abbrev);
1931Record.clear();
1932}
1933
1934void ModuleBitcodeWriter::writeDICompositeType(
1935constDICompositeType *N,SmallVectorImpl<uint64_t> &Record,
1936unsigned Abbrev) {
1937constunsigned IsNotUsedInOldTypeRef = 0x2;
1938Record.push_back(IsNotUsedInOldTypeRef | (unsigned)N->isDistinct());
1939Record.push_back(N->getTag());
1940Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
1941Record.push_back(VE.getMetadataOrNullID(N->getFile()));
1942Record.push_back(N->getLine());
1943Record.push_back(VE.getMetadataOrNullID(N->getScope()));
1944Record.push_back(VE.getMetadataOrNullID(N->getBaseType()));
1945Record.push_back(N->getSizeInBits());
1946Record.push_back(N->getAlignInBits());
1947Record.push_back(N->getOffsetInBits());
1948Record.push_back(N->getFlags());
1949Record.push_back(VE.getMetadataOrNullID(N->getElements().get()));
1950Record.push_back(N->getRuntimeLang());
1951Record.push_back(VE.getMetadataOrNullID(N->getVTableHolder()));
1952Record.push_back(VE.getMetadataOrNullID(N->getTemplateParams().get()));
1953Record.push_back(VE.getMetadataOrNullID(N->getRawIdentifier()));
1954Record.push_back(VE.getMetadataOrNullID(N->getDiscriminator()));
1955Record.push_back(VE.getMetadataOrNullID(N->getRawDataLocation()));
1956Record.push_back(VE.getMetadataOrNullID(N->getRawAssociated()));
1957Record.push_back(VE.getMetadataOrNullID(N->getRawAllocated()));
1958Record.push_back(VE.getMetadataOrNullID(N->getRawRank()));
1959Record.push_back(VE.getMetadataOrNullID(N->getAnnotations().get()));
1960Record.push_back(N->getNumExtraInhabitants());
1961Record.push_back(VE.getMetadataOrNullID(N->getRawSpecification()));
1962
1963 Stream.EmitRecord(bitc::METADATA_COMPOSITE_TYPE,Record, Abbrev);
1964Record.clear();
1965}
1966
1967void ModuleBitcodeWriter::writeDISubroutineType(
1968constDISubroutineType *N,SmallVectorImpl<uint64_t> &Record,
1969unsigned Abbrev) {
1970constunsigned HasNoOldTypeRefs = 0x2;
1971Record.push_back(HasNoOldTypeRefs | (unsigned)N->isDistinct());
1972Record.push_back(N->getFlags());
1973Record.push_back(VE.getMetadataOrNullID(N->getTypeArray().get()));
1974Record.push_back(N->getCC());
1975
1976 Stream.EmitRecord(bitc::METADATA_SUBROUTINE_TYPE,Record, Abbrev);
1977Record.clear();
1978}
1979
1980void ModuleBitcodeWriter::writeDIFile(constDIFile *N,
1981SmallVectorImpl<uint64_t> &Record,
1982unsigned Abbrev) {
1983Record.push_back(N->isDistinct());
1984Record.push_back(VE.getMetadataOrNullID(N->getRawFilename()));
1985Record.push_back(VE.getMetadataOrNullID(N->getRawDirectory()));
1986if (N->getRawChecksum()) {
1987Record.push_back(N->getRawChecksum()->Kind);
1988Record.push_back(VE.getMetadataOrNullID(N->getRawChecksum()->Value));
1989 }else {
1990// Maintain backwards compatibility with the old internal representation of
1991// CSK_None in ChecksumKind by writing nulls here when Checksum is None.
1992Record.push_back(0);
1993Record.push_back(VE.getMetadataOrNullID(nullptr));
1994 }
1995autoSource =N->getRawSource();
1996if (Source)
1997Record.push_back(VE.getMetadataOrNullID(Source));
1998
1999 Stream.EmitRecord(bitc::METADATA_FILE,Record, Abbrev);
2000Record.clear();
2001}
2002
2003void ModuleBitcodeWriter::writeDICompileUnit(constDICompileUnit *N,
2004SmallVectorImpl<uint64_t> &Record,
2005unsigned Abbrev) {
2006assert(N->isDistinct() &&"Expected distinct compile units");
2007Record.push_back(/* IsDistinct */true);
2008Record.push_back(N->getSourceLanguage());
2009Record.push_back(VE.getMetadataOrNullID(N->getFile()));
2010Record.push_back(VE.getMetadataOrNullID(N->getRawProducer()));
2011Record.push_back(N->isOptimized());
2012Record.push_back(VE.getMetadataOrNullID(N->getRawFlags()));
2013Record.push_back(N->getRuntimeVersion());
2014Record.push_back(VE.getMetadataOrNullID(N->getRawSplitDebugFilename()));
2015Record.push_back(N->getEmissionKind());
2016Record.push_back(VE.getMetadataOrNullID(N->getEnumTypes().get()));
2017Record.push_back(VE.getMetadataOrNullID(N->getRetainedTypes().get()));
2018Record.push_back(/* subprograms */ 0);
2019Record.push_back(VE.getMetadataOrNullID(N->getGlobalVariables().get()));
2020Record.push_back(VE.getMetadataOrNullID(N->getImportedEntities().get()));
2021Record.push_back(N->getDWOId());
2022Record.push_back(VE.getMetadataOrNullID(N->getMacros().get()));
2023Record.push_back(N->getSplitDebugInlining());
2024Record.push_back(N->getDebugInfoForProfiling());
2025Record.push_back((unsigned)N->getNameTableKind());
2026Record.push_back(N->getRangesBaseAddress());
2027Record.push_back(VE.getMetadataOrNullID(N->getRawSysRoot()));
2028Record.push_back(VE.getMetadataOrNullID(N->getRawSDK()));
2029
2030 Stream.EmitRecord(bitc::METADATA_COMPILE_UNIT,Record, Abbrev);
2031Record.clear();
2032}
2033
2034void ModuleBitcodeWriter::writeDISubprogram(constDISubprogram *N,
2035SmallVectorImpl<uint64_t> &Record,
2036unsigned Abbrev) {
2037constuint64_t HasUnitFlag = 1 << 1;
2038constuint64_t HasSPFlagsFlag = 1 << 2;
2039Record.push_back(uint64_t(N->isDistinct()) | HasUnitFlag | HasSPFlagsFlag);
2040Record.push_back(VE.getMetadataOrNullID(N->getScope()));
2041Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
2042Record.push_back(VE.getMetadataOrNullID(N->getRawLinkageName()));
2043Record.push_back(VE.getMetadataOrNullID(N->getFile()));
2044Record.push_back(N->getLine());
2045Record.push_back(VE.getMetadataOrNullID(N->getType()));
2046Record.push_back(N->getScopeLine());
2047Record.push_back(VE.getMetadataOrNullID(N->getContainingType()));
2048Record.push_back(N->getSPFlags());
2049Record.push_back(N->getVirtualIndex());
2050Record.push_back(N->getFlags());
2051Record.push_back(VE.getMetadataOrNullID(N->getRawUnit()));
2052Record.push_back(VE.getMetadataOrNullID(N->getTemplateParams().get()));
2053Record.push_back(VE.getMetadataOrNullID(N->getDeclaration()));
2054Record.push_back(VE.getMetadataOrNullID(N->getRetainedNodes().get()));
2055Record.push_back(N->getThisAdjustment());
2056Record.push_back(VE.getMetadataOrNullID(N->getThrownTypes().get()));
2057Record.push_back(VE.getMetadataOrNullID(N->getAnnotations().get()));
2058Record.push_back(VE.getMetadataOrNullID(N->getRawTargetFuncName()));
2059
2060 Stream.EmitRecord(bitc::METADATA_SUBPROGRAM,Record, Abbrev);
2061Record.clear();
2062}
2063
2064void ModuleBitcodeWriter::writeDILexicalBlock(constDILexicalBlock *N,
2065SmallVectorImpl<uint64_t> &Record,
2066unsigned Abbrev) {
2067Record.push_back(N->isDistinct());
2068Record.push_back(VE.getMetadataOrNullID(N->getScope()));
2069Record.push_back(VE.getMetadataOrNullID(N->getFile()));
2070Record.push_back(N->getLine());
2071Record.push_back(N->getColumn());
2072
2073 Stream.EmitRecord(bitc::METADATA_LEXICAL_BLOCK,Record, Abbrev);
2074Record.clear();
2075}
2076
2077void ModuleBitcodeWriter::writeDILexicalBlockFile(
2078constDILexicalBlockFile *N,SmallVectorImpl<uint64_t> &Record,
2079unsigned Abbrev) {
2080Record.push_back(N->isDistinct());
2081Record.push_back(VE.getMetadataOrNullID(N->getScope()));
2082Record.push_back(VE.getMetadataOrNullID(N->getFile()));
2083Record.push_back(N->getDiscriminator());
2084
2085 Stream.EmitRecord(bitc::METADATA_LEXICAL_BLOCK_FILE,Record, Abbrev);
2086Record.clear();
2087}
2088
2089void ModuleBitcodeWriter::writeDICommonBlock(constDICommonBlock *N,
2090SmallVectorImpl<uint64_t> &Record,
2091unsigned Abbrev) {
2092Record.push_back(N->isDistinct());
2093Record.push_back(VE.getMetadataOrNullID(N->getScope()));
2094Record.push_back(VE.getMetadataOrNullID(N->getDecl()));
2095Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
2096Record.push_back(VE.getMetadataOrNullID(N->getFile()));
2097Record.push_back(N->getLineNo());
2098
2099 Stream.EmitRecord(bitc::METADATA_COMMON_BLOCK,Record, Abbrev);
2100Record.clear();
2101}
2102
2103void ModuleBitcodeWriter::writeDINamespace(constDINamespace *N,
2104SmallVectorImpl<uint64_t> &Record,
2105unsigned Abbrev) {
2106Record.push_back(N->isDistinct() |N->getExportSymbols() << 1);
2107Record.push_back(VE.getMetadataOrNullID(N->getScope()));
2108Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
2109
2110 Stream.EmitRecord(bitc::METADATA_NAMESPACE,Record, Abbrev);
2111Record.clear();
2112}
2113
2114void ModuleBitcodeWriter::writeDIMacro(constDIMacro *N,
2115SmallVectorImpl<uint64_t> &Record,
2116unsigned Abbrev) {
2117Record.push_back(N->isDistinct());
2118Record.push_back(N->getMacinfoType());
2119Record.push_back(N->getLine());
2120Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
2121Record.push_back(VE.getMetadataOrNullID(N->getRawValue()));
2122
2123 Stream.EmitRecord(bitc::METADATA_MACRO,Record, Abbrev);
2124Record.clear();
2125}
2126
2127void ModuleBitcodeWriter::writeDIMacroFile(constDIMacroFile *N,
2128SmallVectorImpl<uint64_t> &Record,
2129unsigned Abbrev) {
2130Record.push_back(N->isDistinct());
2131Record.push_back(N->getMacinfoType());
2132Record.push_back(N->getLine());
2133Record.push_back(VE.getMetadataOrNullID(N->getFile()));
2134Record.push_back(VE.getMetadataOrNullID(N->getElements().get()));
2135
2136 Stream.EmitRecord(bitc::METADATA_MACRO_FILE,Record, Abbrev);
2137Record.clear();
2138}
2139
2140void ModuleBitcodeWriter::writeDIArgList(constDIArgList *N,
2141SmallVectorImpl<uint64_t> &Record) {
2142Record.reserve(N->getArgs().size());
2143for (ValueAsMetadata *MD :N->getArgs())
2144Record.push_back(VE.getMetadataID(MD));
2145
2146 Stream.EmitRecord(bitc::METADATA_ARG_LIST,Record);
2147Record.clear();
2148}
2149
2150void ModuleBitcodeWriter::writeDIModule(constDIModule *N,
2151SmallVectorImpl<uint64_t> &Record,
2152unsigned Abbrev) {
2153Record.push_back(N->isDistinct());
2154for (auto &I :N->operands())
2155Record.push_back(VE.getMetadataOrNullID(I));
2156Record.push_back(N->getLineNo());
2157Record.push_back(N->getIsDecl());
2158
2159 Stream.EmitRecord(bitc::METADATA_MODULE,Record, Abbrev);
2160Record.clear();
2161}
2162
2163void ModuleBitcodeWriter::writeDIAssignID(constDIAssignID *N,
2164SmallVectorImpl<uint64_t> &Record,
2165unsigned Abbrev) {
2166// There are no arguments for this metadata type.
2167Record.push_back(N->isDistinct());
2168 Stream.EmitRecord(bitc::METADATA_ASSIGN_ID,Record, Abbrev);
2169Record.clear();
2170}
2171
2172void ModuleBitcodeWriter::writeDITemplateTypeParameter(
2173constDITemplateTypeParameter *N,SmallVectorImpl<uint64_t> &Record,
2174unsigned Abbrev) {
2175Record.push_back(N->isDistinct());
2176Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
2177Record.push_back(VE.getMetadataOrNullID(N->getType()));
2178Record.push_back(N->isDefault());
2179
2180 Stream.EmitRecord(bitc::METADATA_TEMPLATE_TYPE,Record, Abbrev);
2181Record.clear();
2182}
2183
2184void ModuleBitcodeWriter::writeDITemplateValueParameter(
2185constDITemplateValueParameter *N,SmallVectorImpl<uint64_t> &Record,
2186unsigned Abbrev) {
2187Record.push_back(N->isDistinct());
2188Record.push_back(N->getTag());
2189Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
2190Record.push_back(VE.getMetadataOrNullID(N->getType()));
2191Record.push_back(N->isDefault());
2192Record.push_back(VE.getMetadataOrNullID(N->getValue()));
2193
2194 Stream.EmitRecord(bitc::METADATA_TEMPLATE_VALUE,Record, Abbrev);
2195Record.clear();
2196}
2197
2198void ModuleBitcodeWriter::writeDIGlobalVariable(
2199constDIGlobalVariable *N,SmallVectorImpl<uint64_t> &Record,
2200unsigned Abbrev) {
2201constuint64_tVersion = 2 << 1;
2202Record.push_back((uint64_t)N->isDistinct() | Version);
2203Record.push_back(VE.getMetadataOrNullID(N->getScope()));
2204Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
2205Record.push_back(VE.getMetadataOrNullID(N->getRawLinkageName()));
2206Record.push_back(VE.getMetadataOrNullID(N->getFile()));
2207Record.push_back(N->getLine());
2208Record.push_back(VE.getMetadataOrNullID(N->getType()));
2209Record.push_back(N->isLocalToUnit());
2210Record.push_back(N->isDefinition());
2211Record.push_back(VE.getMetadataOrNullID(N->getStaticDataMemberDeclaration()));
2212Record.push_back(VE.getMetadataOrNullID(N->getTemplateParams()));
2213Record.push_back(N->getAlignInBits());
2214Record.push_back(VE.getMetadataOrNullID(N->getAnnotations().get()));
2215
2216 Stream.EmitRecord(bitc::METADATA_GLOBAL_VAR,Record, Abbrev);
2217Record.clear();
2218}
2219
2220void ModuleBitcodeWriter::writeDILocalVariable(
2221constDILocalVariable *N,SmallVectorImpl<uint64_t> &Record,
2222unsigned Abbrev) {
2223// In order to support all possible bitcode formats in BitcodeReader we need
2224// to distinguish the following cases:
2225// 1) Record has no artificial tag (Record[1]),
2226// has no obsolete inlinedAt field (Record[9]).
2227// In this case Record size will be 8, HasAlignment flag is false.
2228// 2) Record has artificial tag (Record[1]),
2229// has no obsolete inlignedAt field (Record[9]).
2230// In this case Record size will be 9, HasAlignment flag is false.
2231// 3) Record has both artificial tag (Record[1]) and
2232// obsolete inlignedAt field (Record[9]).
2233// In this case Record size will be 10, HasAlignment flag is false.
2234// 4) Record has neither artificial tag, nor inlignedAt field, but
2235// HasAlignment flag is true and Record[8] contains alignment value.
2236constuint64_t HasAlignmentFlag = 1 << 1;
2237Record.push_back((uint64_t)N->isDistinct() | HasAlignmentFlag);
2238Record.push_back(VE.getMetadataOrNullID(N->getScope()));
2239Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
2240Record.push_back(VE.getMetadataOrNullID(N->getFile()));
2241Record.push_back(N->getLine());
2242Record.push_back(VE.getMetadataOrNullID(N->getType()));
2243Record.push_back(N->getArg());
2244Record.push_back(N->getFlags());
2245Record.push_back(N->getAlignInBits());
2246Record.push_back(VE.getMetadataOrNullID(N->getAnnotations().get()));
2247
2248 Stream.EmitRecord(bitc::METADATA_LOCAL_VAR,Record, Abbrev);
2249Record.clear();
2250}
2251
2252void ModuleBitcodeWriter::writeDILabel(
2253constDILabel *N,SmallVectorImpl<uint64_t> &Record,
2254unsigned Abbrev) {
2255Record.push_back((uint64_t)N->isDistinct());
2256Record.push_back(VE.getMetadataOrNullID(N->getScope()));
2257Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
2258Record.push_back(VE.getMetadataOrNullID(N->getFile()));
2259Record.push_back(N->getLine());
2260
2261 Stream.EmitRecord(bitc::METADATA_LABEL,Record, Abbrev);
2262Record.clear();
2263}
2264
2265void ModuleBitcodeWriter::writeDIExpression(constDIExpression *N,
2266SmallVectorImpl<uint64_t> &Record,
2267unsigned Abbrev) {
2268Record.reserve(N->getElements().size() + 1);
2269constuint64_tVersion = 3 << 1;
2270Record.push_back((uint64_t)N->isDistinct() | Version);
2271Record.append(N->elements_begin(),N->elements_end());
2272
2273 Stream.EmitRecord(bitc::METADATA_EXPRESSION,Record, Abbrev);
2274Record.clear();
2275}
2276
2277void ModuleBitcodeWriter::writeDIGlobalVariableExpression(
2278constDIGlobalVariableExpression *N,SmallVectorImpl<uint64_t> &Record,
2279unsigned Abbrev) {
2280Record.push_back(N->isDistinct());
2281Record.push_back(VE.getMetadataOrNullID(N->getVariable()));
2282Record.push_back(VE.getMetadataOrNullID(N->getExpression()));
2283
2284 Stream.EmitRecord(bitc::METADATA_GLOBAL_VAR_EXPR,Record, Abbrev);
2285Record.clear();
2286}
2287
2288void ModuleBitcodeWriter::writeDIObjCProperty(constDIObjCProperty *N,
2289SmallVectorImpl<uint64_t> &Record,
2290unsigned Abbrev) {
2291Record.push_back(N->isDistinct());
2292Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
2293Record.push_back(VE.getMetadataOrNullID(N->getFile()));
2294Record.push_back(N->getLine());
2295Record.push_back(VE.getMetadataOrNullID(N->getRawSetterName()));
2296Record.push_back(VE.getMetadataOrNullID(N->getRawGetterName()));
2297Record.push_back(N->getAttributes());
2298Record.push_back(VE.getMetadataOrNullID(N->getType()));
2299
2300 Stream.EmitRecord(bitc::METADATA_OBJC_PROPERTY,Record, Abbrev);
2301Record.clear();
2302}
2303
2304void ModuleBitcodeWriter::writeDIImportedEntity(
2305constDIImportedEntity *N,SmallVectorImpl<uint64_t> &Record,
2306unsigned Abbrev) {
2307Record.push_back(N->isDistinct());
2308Record.push_back(N->getTag());
2309Record.push_back(VE.getMetadataOrNullID(N->getScope()));
2310Record.push_back(VE.getMetadataOrNullID(N->getEntity()));
2311Record.push_back(N->getLine());
2312Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
2313Record.push_back(VE.getMetadataOrNullID(N->getRawFile()));
2314Record.push_back(VE.getMetadataOrNullID(N->getElements().get()));
2315
2316 Stream.EmitRecord(bitc::METADATA_IMPORTED_ENTITY,Record, Abbrev);
2317Record.clear();
2318}
2319
2320unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
2321auto Abbv = std::make_shared<BitCodeAbbrev>();
2322 Abbv->Add(BitCodeAbbrevOp(bitc::METADATA_NAME));
2323 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2324 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8));
2325return Stream.EmitAbbrev(std::move(Abbv));
2326}
2327
2328void ModuleBitcodeWriter::writeNamedMetadata(
2329SmallVectorImpl<uint64_t> &Record) {
2330if (M.named_metadata_empty())
2331return;
2332
2333unsigned Abbrev = createNamedMetadataAbbrev();
2334for (constNamedMDNode &NMD :M.named_metadata()) {
2335// Write name.
2336StringRef Str = NMD.getName();
2337Record.append(Str.bytes_begin(), Str.bytes_end());
2338 Stream.EmitRecord(bitc::METADATA_NAME,Record, Abbrev);
2339Record.clear();
2340
2341// Write named metadata operands.
2342for (constMDNode *N : NMD.operands())
2343Record.push_back(VE.getMetadataID(N));
2344 Stream.EmitRecord(bitc::METADATA_NAMED_NODE,Record, 0);
2345Record.clear();
2346 }
2347}
2348
2349unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
2350auto Abbv = std::make_shared<BitCodeAbbrev>();
2351 Abbv->Add(BitCodeAbbrevOp(bitc::METADATA_STRINGS));
2352 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// # of strings
2353 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// offset to chars
2354 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2355return Stream.EmitAbbrev(std::move(Abbv));
2356}
2357
2358/// Write out a record for MDString.
2359///
2360/// All the metadata strings in a metadata block are emitted in a single
2361/// record. The sizes and strings themselves are shoved into a blob.
2362void ModuleBitcodeWriter::writeMetadataStrings(
2363ArrayRef<const Metadata *> Strings,SmallVectorImpl<uint64_t> &Record) {
2364if (Strings.empty())
2365return;
2366
2367// Start the record with the number of strings.
2368Record.push_back(bitc::METADATA_STRINGS);
2369Record.push_back(Strings.size());
2370
2371// Emit the sizes of the strings in the blob.
2372SmallString<256> Blob;
2373 {
2374BitstreamWriterW(Blob);
2375for (constMetadata *MD : Strings)
2376W.EmitVBR(cast<MDString>(MD)->getLength(), 6);
2377W.FlushToWord();
2378 }
2379
2380// Add the offset to the strings to the record.
2381Record.push_back(Blob.size());
2382
2383// Add the strings to the blob.
2384for (constMetadata *MD : Strings)
2385 Blob.append(cast<MDString>(MD)->getString());
2386
2387// Emit the final record.
2388 Stream.EmitRecordWithBlob(createMetadataStringsAbbrev(),Record, Blob);
2389Record.clear();
2390}
2391
2392// Generates an enum to use as an index in the Abbrev array of Metadata record.
2393enumMetadataAbbrev :unsigned {
2394#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
2395#include "llvm/IR/Metadata.def"
2396LastPlusOne
2397};
2398
2399void ModuleBitcodeWriter::writeMetadataRecords(
2400ArrayRef<const Metadata *> MDs,SmallVectorImpl<uint64_t> &Record,
2401 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
2402if (MDs.empty())
2403return;
2404
2405// Initialize MDNode abbreviations.
2406#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
2407#include "llvm/IR/Metadata.def"
2408
2409for (constMetadata *MD : MDs) {
2410if (IndexPos)
2411 IndexPos->push_back(Stream.GetCurrentBitNo());
2412if (constMDNode *N = dyn_cast<MDNode>(MD)) {
2413assert(N->isResolved() &&"Expected forward references to be resolved");
2414
2415switch (N->getMetadataID()) {
2416default:
2417llvm_unreachable("Invalid MDNode subclass");
2418#define HANDLE_MDNODE_LEAF(CLASS) \
2419 case Metadata::CLASS##Kind: \
2420 if (MDAbbrevs) \
2421 write##CLASS(cast<CLASS>(N), Record, \
2422 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
2423 else \
2424 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
2425 continue;
2426#include "llvm/IR/Metadata.def"
2427 }
2428 }
2429if (auto *AL = dyn_cast<DIArgList>(MD)) {
2430writeDIArgList(AL,Record);
2431continue;
2432 }
2433 writeValueAsMetadata(cast<ValueAsMetadata>(MD),Record);
2434 }
2435}
2436
2437void ModuleBitcodeWriter::writeModuleMetadata() {
2438if (!VE.hasMDs() &&M.named_metadata_empty())
2439return;
2440
2441 Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 4);
2442SmallVector<uint64_t, 64>Record;
2443
2444// Emit all abbrevs upfront, so that the reader can jump in the middle of the
2445// block and load any metadata.
2446 std::vector<unsigned> MDAbbrevs;
2447
2448 MDAbbrevs.resize(MetadataAbbrev::LastPlusOne);
2449 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
2450 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
2451 createGenericDINodeAbbrev();
2452
2453auto Abbv = std::make_shared<BitCodeAbbrev>();
2454 Abbv->Add(BitCodeAbbrevOp(bitc::METADATA_INDEX_OFFSET));
2455 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
2456 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
2457unsigned OffsetAbbrev = Stream.EmitAbbrev(std::move(Abbv));
2458
2459 Abbv = std::make_shared<BitCodeAbbrev>();
2460 Abbv->Add(BitCodeAbbrevOp(bitc::METADATA_INDEX));
2461 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2462 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
2463unsigned IndexAbbrev = Stream.EmitAbbrev(std::move(Abbv));
2464
2465// Emit MDStrings together upfront.
2466 writeMetadataStrings(VE.getMDStrings(),Record);
2467
2468// We only emit an index for the metadata record if we have more than a given
2469// (naive) threshold of metadatas, otherwise it is not worth it.
2470if (VE.getNonMDStrings().size() >IndexThreshold) {
2471// Write a placeholder value in for the offset of the metadata index,
2472// which is written after the records, so that it can include
2473// the offset of each entry. The placeholder offset will be
2474// updated after all records are emitted.
2475uint64_t Vals[] = {0, 0};
2476 Stream.EmitRecord(bitc::METADATA_INDEX_OFFSET, Vals, OffsetAbbrev);
2477 }
2478
2479// Compute and save the bit offset to the current position, which will be
2480// patched when we emit the index later. We can simply subtract the 64-bit
2481// fixed size from the current bit number to get the location to backpatch.
2482uint64_t IndexOffsetRecordBitPos = Stream.GetCurrentBitNo();
2483
2484// This index will contain the bitpos for each individual record.
2485 std::vector<uint64_t> IndexPos;
2486 IndexPos.reserve(VE.getNonMDStrings().size());
2487
2488// Write all the records
2489 writeMetadataRecords(VE.getNonMDStrings(),Record, &MDAbbrevs, &IndexPos);
2490
2491if (VE.getNonMDStrings().size() >IndexThreshold) {
2492// Now that we have emitted all the records we will emit the index. But
2493// first
2494// backpatch the forward reference so that the reader can skip the records
2495// efficiently.
2496 Stream.BackpatchWord64(IndexOffsetRecordBitPos - 64,
2497 Stream.GetCurrentBitNo() - IndexOffsetRecordBitPos);
2498
2499// Delta encode the index.
2500uint64_t PreviousValue = IndexOffsetRecordBitPos;
2501for (auto &Elt : IndexPos) {
2502auto EltDelta = Elt - PreviousValue;
2503 PreviousValue = Elt;
2504 Elt = EltDelta;
2505 }
2506// Emit the index record.
2507 Stream.EmitRecord(bitc::METADATA_INDEX, IndexPos, IndexAbbrev);
2508 IndexPos.clear();
2509 }
2510
2511// Write the named metadata now.
2512 writeNamedMetadata(Record);
2513
2514auto AddDeclAttachedMetadata = [&](constGlobalObject &GO) {
2515SmallVector<uint64_t, 4>Record;
2516Record.push_back(VE.getValueID(&GO));
2517 pushGlobalMetadataAttachment(Record, GO);
2518 Stream.EmitRecord(bitc::METADATA_GLOBAL_DECL_ATTACHMENT,Record);
2519 };
2520for (constFunction &F : M)
2521if (F.isDeclaration() &&F.hasMetadata())
2522 AddDeclAttachedMetadata(F);
2523// FIXME: Only store metadata for declarations here, and move data for global
2524// variable definitions to a separate block (PR28134).
2525for (constGlobalVariable &GV :M.globals())
2526if (GV.hasMetadata())
2527 AddDeclAttachedMetadata(GV);
2528
2529 Stream.ExitBlock();
2530}
2531
2532void ModuleBitcodeWriter::writeFunctionMetadata(constFunction &F) {
2533if (!VE.hasMDs())
2534return;
2535
2536 Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
2537SmallVector<uint64_t, 64>Record;
2538 writeMetadataStrings(VE.getMDStrings(),Record);
2539 writeMetadataRecords(VE.getNonMDStrings(),Record);
2540 Stream.ExitBlock();
2541}
2542
2543void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2544SmallVectorImpl<uint64_t> &Record,constGlobalObject &GO) {
2545// [n x [id, mdnode]]
2546SmallVector<std::pair<unsigned, MDNode *>, 4> MDs;
2547 GO.getAllMetadata(MDs);
2548for (constauto &I : MDs) {
2549Record.push_back(I.first);
2550Record.push_back(VE.getMetadataID(I.second));
2551 }
2552}
2553
2554void ModuleBitcodeWriter::writeFunctionMetadataAttachment(constFunction &F) {
2555 Stream.EnterSubblock(bitc::METADATA_ATTACHMENT_ID, 3);
2556
2557SmallVector<uint64_t, 64>Record;
2558
2559if (F.hasMetadata()) {
2560 pushGlobalMetadataAttachment(Record,F);
2561 Stream.EmitRecord(bitc::METADATA_ATTACHMENT,Record, 0);
2562Record.clear();
2563 }
2564
2565// Write metadata attachments
2566// METADATA_ATTACHMENT - [m x [value, [n x [id, mdnode]]]
2567SmallVector<std::pair<unsigned, MDNode *>, 4> MDs;
2568for (constBasicBlock &BB :F)
2569for (constInstruction &I : BB) {
2570 MDs.clear();
2571I.getAllMetadataOtherThanDebugLoc(MDs);
2572
2573// If no metadata, ignore instruction.
2574if (MDs.empty())continue;
2575
2576Record.push_back(VE.getInstructionID(&I));
2577
2578for (unsigned i = 0, e = MDs.size(); i != e; ++i) {
2579Record.push_back(MDs[i].first);
2580Record.push_back(VE.getMetadataID(MDs[i].second));
2581 }
2582 Stream.EmitRecord(bitc::METADATA_ATTACHMENT,Record, 0);
2583Record.clear();
2584 }
2585
2586 Stream.ExitBlock();
2587}
2588
2589void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2590SmallVector<uint64_t, 64>Record;
2591
2592// Write metadata kinds
2593// METADATA_KIND - [n x [id, name]]
2594SmallVector<StringRef, 8> Names;
2595M.getMDKindNames(Names);
2596
2597if (Names.empty())return;
2598
2599 Stream.EnterSubblock(bitc::METADATA_KIND_BLOCK_ID, 3);
2600
2601for (unsigned MDKindID = 0, e = Names.size(); MDKindID != e; ++MDKindID) {
2602Record.push_back(MDKindID);
2603StringRef KName = Names[MDKindID];
2604Record.append(KName.begin(), KName.end());
2605
2606 Stream.EmitRecord(bitc::METADATA_KIND,Record, 0);
2607Record.clear();
2608 }
2609
2610 Stream.ExitBlock();
2611}
2612
2613void ModuleBitcodeWriter::writeOperandBundleTags() {
2614// Write metadata kinds
2615//
2616// OPERAND_BUNDLE_TAGS_BLOCK_ID : N x OPERAND_BUNDLE_TAG
2617//
2618// OPERAND_BUNDLE_TAG - [strchr x N]
2619
2620SmallVector<StringRef, 8> Tags;
2621M.getOperandBundleTags(Tags);
2622
2623if (Tags.empty())
2624return;
2625
2626 Stream.EnterSubblock(bitc::OPERAND_BUNDLE_TAGS_BLOCK_ID, 3);
2627
2628SmallVector<uint64_t, 64>Record;
2629
2630for (auto Tag : Tags) {
2631Record.append(Tag.begin(),Tag.end());
2632
2633 Stream.EmitRecord(bitc::OPERAND_BUNDLE_TAG,Record, 0);
2634Record.clear();
2635 }
2636
2637 Stream.ExitBlock();
2638}
2639
2640void ModuleBitcodeWriter::writeSyncScopeNames() {
2641SmallVector<StringRef, 8> SSNs;
2642M.getContext().getSyncScopeNames(SSNs);
2643if (SSNs.empty())
2644return;
2645
2646 Stream.EnterSubblock(bitc::SYNC_SCOPE_NAMES_BLOCK_ID, 2);
2647
2648SmallVector<uint64_t, 64>Record;
2649for (auto SSN : SSNs) {
2650Record.append(SSN.begin(), SSN.end());
2651 Stream.EmitRecord(bitc::SYNC_SCOPE_NAME,Record, 0);
2652Record.clear();
2653 }
2654
2655 Stream.ExitBlock();
2656}
2657
2658void ModuleBitcodeWriter::writeConstants(unsigned FirstVal,unsigned LastVal,
2659bool isGlobal) {
2660if (FirstVal == LastVal)return;
2661
2662 Stream.EnterSubblock(bitc::CONSTANTS_BLOCK_ID, 4);
2663
2664unsigned AggregateAbbrev = 0;
2665unsigned String8Abbrev = 0;
2666unsigned CString7Abbrev = 0;
2667unsigned CString6Abbrev = 0;
2668// If this is a constant pool for the module, emit module-specific abbrevs.
2669if (isGlobal) {
2670// Abbrev for CST_CODE_AGGREGATE.
2671auto Abbv = std::make_shared<BitCodeAbbrev>();
2672 Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_AGGREGATE));
2673 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2674 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,Log2_32_Ceil(LastVal+1)));
2675 AggregateAbbrev = Stream.EmitAbbrev(std::move(Abbv));
2676
2677// Abbrev for CST_CODE_STRING.
2678 Abbv = std::make_shared<BitCodeAbbrev>();
2679 Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_STRING));
2680 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2681 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8));
2682 String8Abbrev = Stream.EmitAbbrev(std::move(Abbv));
2683// Abbrev for CST_CODE_CSTRING.
2684 Abbv = std::make_shared<BitCodeAbbrev>();
2685 Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_CSTRING));
2686 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2687 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7));
2688 CString7Abbrev = Stream.EmitAbbrev(std::move(Abbv));
2689// Abbrev for CST_CODE_CSTRING.
2690 Abbv = std::make_shared<BitCodeAbbrev>();
2691 Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_CSTRING));
2692 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2693 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6));
2694 CString6Abbrev = Stream.EmitAbbrev(std::move(Abbv));
2695 }
2696
2697SmallVector<uint64_t, 64>Record;
2698
2699constValueEnumerator::ValueList &Vals = VE.getValues();
2700Type *LastTy =nullptr;
2701for (unsigned i = FirstVal; i != LastVal; ++i) {
2702constValue *V = Vals[i].first;
2703// If we need to switch types, do so now.
2704if (V->getType() != LastTy) {
2705 LastTy =V->getType();
2706Record.push_back(VE.getTypeID(LastTy));
2707 Stream.EmitRecord(bitc::CST_CODE_SETTYPE,Record,
2708 CONSTANTS_SETTYPE_ABBREV);
2709Record.clear();
2710 }
2711
2712if (constInlineAsm *IA = dyn_cast<InlineAsm>(V)) {
2713Record.push_back(VE.getTypeID(IA->getFunctionType()));
2714Record.push_back(
2715unsigned(IA->hasSideEffects()) |unsigned(IA->isAlignStack()) << 1 |
2716unsigned(IA->getDialect() & 1) << 2 |unsigned(IA->canThrow()) << 3);
2717
2718// Add the asm string.
2719const std::string &AsmStr =IA->getAsmString();
2720Record.push_back(AsmStr.size());
2721Record.append(AsmStr.begin(), AsmStr.end());
2722
2723// Add the constraint string.
2724const std::string &ConstraintStr =IA->getConstraintString();
2725Record.push_back(ConstraintStr.size());
2726Record.append(ConstraintStr.begin(), ConstraintStr.end());
2727 Stream.EmitRecord(bitc::CST_CODE_INLINEASM,Record);
2728Record.clear();
2729continue;
2730 }
2731constConstant *C = cast<Constant>(V);
2732unsignedCode = -1U;
2733unsigned AbbrevToUse = 0;
2734if (C->isNullValue()) {
2735Code =bitc::CST_CODE_NULL;
2736 }elseif (isa<PoisonValue>(C)) {
2737Code =bitc::CST_CODE_POISON;
2738 }elseif (isa<UndefValue>(C)) {
2739Code =bitc::CST_CODE_UNDEF;
2740 }elseif (constConstantInt *IV = dyn_cast<ConstantInt>(C)) {
2741if (IV->getBitWidth() <= 64) {
2742uint64_tV =IV->getSExtValue();
2743emitSignedInt64(Record, V);
2744Code =bitc::CST_CODE_INTEGER;
2745 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2746 }else {// Wide integers, > 64 bits in size.
2747emitWideAPInt(Record,IV->getValue());
2748Code =bitc::CST_CODE_WIDE_INTEGER;
2749 }
2750 }elseif (constConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
2751Code =bitc::CST_CODE_FLOAT;
2752Type *Ty = CFP->getType()->getScalarType();
2753if (Ty->isHalfTy() || Ty->isBFloatTy() || Ty->isFloatTy() ||
2754 Ty->isDoubleTy()) {
2755Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2756 }elseif (Ty->isX86_FP80Ty()) {
2757// api needed to prevent premature destruction
2758// bits are not in the same order as a normal i80 APInt, compensate.
2759APInt api = CFP->getValueAPF().bitcastToAPInt();
2760constuint64_t *p = api.getRawData();
2761Record.push_back((p[1] << 48) | (p[0] >> 16));
2762Record.push_back(p[0] & 0xffffLL);
2763 }elseif (Ty->isFP128Ty() || Ty->isPPC_FP128Ty()) {
2764APInt api = CFP->getValueAPF().bitcastToAPInt();
2765constuint64_t *p = api.getRawData();
2766Record.push_back(p[0]);
2767Record.push_back(p[1]);
2768 }else {
2769assert(0 &&"Unknown FP type!");
2770 }
2771 }elseif (isa<ConstantDataSequential>(C) &&
2772 cast<ConstantDataSequential>(C)->isString()) {
2773constConstantDataSequential *Str = cast<ConstantDataSequential>(C);
2774// Emit constant strings specially.
2775unsigned NumElts = Str->getNumElements();
2776// If this is a null-terminated string, use the denser CSTRING encoding.
2777if (Str->isCString()) {
2778Code =bitc::CST_CODE_CSTRING;
2779 --NumElts;// Don't encode the null, which isn't allowed by char6.
2780 }else {
2781Code =bitc::CST_CODE_STRING;
2782 AbbrevToUse = String8Abbrev;
2783 }
2784bool isCStr7 =Code ==bitc::CST_CODE_CSTRING;
2785bool isCStrChar6 =Code ==bitc::CST_CODE_CSTRING;
2786for (unsigned i = 0; i != NumElts; ++i) {
2787unsignedcharV = Str->getElementAsInteger(i);
2788Record.push_back(V);
2789 isCStr7 &= (V & 128) == 0;
2790if (isCStrChar6)
2791 isCStrChar6 =BitCodeAbbrevOp::isChar6(V);
2792 }
2793
2794if (isCStrChar6)
2795 AbbrevToUse = CString6Abbrev;
2796elseif (isCStr7)
2797 AbbrevToUse = CString7Abbrev;
2798 }elseif (constConstantDataSequential *CDS =
2799 dyn_cast<ConstantDataSequential>(C)) {
2800Code =bitc::CST_CODE_DATA;
2801Type *EltTy = CDS->getElementType();
2802if (isa<IntegerType>(EltTy)) {
2803for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2804Record.push_back(CDS->getElementAsInteger(i));
2805 }else {
2806for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2807Record.push_back(
2808 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
2809 }
2810 }elseif (isa<ConstantAggregate>(C)) {
2811Code =bitc::CST_CODE_AGGREGATE;
2812for (constValue *Op :C->operands())
2813Record.push_back(VE.getValueID(Op));
2814 AbbrevToUse = AggregateAbbrev;
2815 }elseif (constConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
2816switch (CE->getOpcode()) {
2817default:
2818if (Instruction::isCast(CE->getOpcode())) {
2819Code =bitc::CST_CODE_CE_CAST;
2820Record.push_back(getEncodedCastOpcode(CE->getOpcode()));
2821Record.push_back(VE.getTypeID(C->getOperand(0)->getType()));
2822Record.push_back(VE.getValueID(C->getOperand(0)));
2823 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2824 }else {
2825assert(CE->getNumOperands() == 2 &&"Unknown constant expr!");
2826Code =bitc::CST_CODE_CE_BINOP;
2827Record.push_back(getEncodedBinaryOpcode(CE->getOpcode()));
2828Record.push_back(VE.getValueID(C->getOperand(0)));
2829Record.push_back(VE.getValueID(C->getOperand(1)));
2830uint64_tFlags =getOptimizationFlags(CE);
2831if (Flags != 0)
2832Record.push_back(Flags);
2833 }
2834break;
2835case Instruction::FNeg: {
2836assert(CE->getNumOperands() == 1 &&"Unknown constant expr!");
2837Code =bitc::CST_CODE_CE_UNOP;
2838Record.push_back(getEncodedUnaryOpcode(CE->getOpcode()));
2839Record.push_back(VE.getValueID(C->getOperand(0)));
2840uint64_tFlags =getOptimizationFlags(CE);
2841if (Flags != 0)
2842Record.push_back(Flags);
2843break;
2844 }
2845case Instruction::GetElementPtr: {
2846Code =bitc::CST_CODE_CE_GEP;
2847constauto *GO = cast<GEPOperator>(C);
2848Record.push_back(VE.getTypeID(GO->getSourceElementType()));
2849Record.push_back(getOptimizationFlags(GO));
2850if (std::optional<ConstantRange>Range = GO->getInRange()) {
2851Code =bitc::CST_CODE_CE_GEP_WITH_INRANGE;
2852emitConstantRange(Record, *Range,/*EmitBitWidth=*/true);
2853 }
2854for (constValue *Op :CE->operands()) {
2855Record.push_back(VE.getTypeID(Op->getType()));
2856Record.push_back(VE.getValueID(Op));
2857 }
2858break;
2859 }
2860case Instruction::ExtractElement:
2861Code =bitc::CST_CODE_CE_EXTRACTELT;
2862Record.push_back(VE.getTypeID(C->getOperand(0)->getType()));
2863Record.push_back(VE.getValueID(C->getOperand(0)));
2864Record.push_back(VE.getTypeID(C->getOperand(1)->getType()));
2865Record.push_back(VE.getValueID(C->getOperand(1)));
2866break;
2867case Instruction::InsertElement:
2868Code =bitc::CST_CODE_CE_INSERTELT;
2869Record.push_back(VE.getValueID(C->getOperand(0)));
2870Record.push_back(VE.getValueID(C->getOperand(1)));
2871Record.push_back(VE.getTypeID(C->getOperand(2)->getType()));
2872Record.push_back(VE.getValueID(C->getOperand(2)));
2873break;
2874case Instruction::ShuffleVector:
2875// If the return type and argument types are the same, this is a
2876// standard shufflevector instruction. If the types are different,
2877// then the shuffle is widening or truncating the input vectors, and
2878// the argument type must also be encoded.
2879if (C->getType() ==C->getOperand(0)->getType()) {
2880Code =bitc::CST_CODE_CE_SHUFFLEVEC;
2881 }else {
2882Code =bitc::CST_CODE_CE_SHUFVEC_EX;
2883Record.push_back(VE.getTypeID(C->getOperand(0)->getType()));
2884 }
2885Record.push_back(VE.getValueID(C->getOperand(0)));
2886Record.push_back(VE.getValueID(C->getOperand(1)));
2887Record.push_back(VE.getValueID(CE->getShuffleMaskForBitcode()));
2888break;
2889 }
2890 }elseif (constBlockAddress *BA = dyn_cast<BlockAddress>(C)) {
2891Code =bitc::CST_CODE_BLOCKADDRESS;
2892Record.push_back(VE.getTypeID(BA->getFunction()->getType()));
2893Record.push_back(VE.getValueID(BA->getFunction()));
2894Record.push_back(VE.getGlobalBasicBlockID(BA->getBasicBlock()));
2895 }elseif (constauto *Equiv = dyn_cast<DSOLocalEquivalent>(C)) {
2896Code =bitc::CST_CODE_DSO_LOCAL_EQUIVALENT;
2897Record.push_back(VE.getTypeID(Equiv->getGlobalValue()->getType()));
2898Record.push_back(VE.getValueID(Equiv->getGlobalValue()));
2899 }elseif (constauto *NC = dyn_cast<NoCFIValue>(C)) {
2900Code =bitc::CST_CODE_NO_CFI_VALUE;
2901Record.push_back(VE.getTypeID(NC->getGlobalValue()->getType()));
2902Record.push_back(VE.getValueID(NC->getGlobalValue()));
2903 }elseif (constauto *CPA = dyn_cast<ConstantPtrAuth>(C)) {
2904Code =bitc::CST_CODE_PTRAUTH;
2905Record.push_back(VE.getValueID(CPA->getPointer()));
2906Record.push_back(VE.getValueID(CPA->getKey()));
2907Record.push_back(VE.getValueID(CPA->getDiscriminator()));
2908Record.push_back(VE.getValueID(CPA->getAddrDiscriminator()));
2909 }else {
2910#ifndef NDEBUG
2911C->dump();
2912#endif
2913llvm_unreachable("Unknown constant!");
2914 }
2915 Stream.EmitRecord(Code,Record, AbbrevToUse);
2916Record.clear();
2917 }
2918
2919 Stream.ExitBlock();
2920}
2921
2922void ModuleBitcodeWriter::writeModuleConstants() {
2923constValueEnumerator::ValueList &Vals = VE.getValues();
2924
2925// Find the first constant to emit, which is the first non-globalvalue value.
2926// We know globalvalues have been emitted by WriteModuleInfo.
2927for (unsigned i = 0, e = Vals.size(); i != e; ++i) {
2928if (!isa<GlobalValue>(Vals[i].first)) {
2929 writeConstants(i, Vals.size(),true);
2930return;
2931 }
2932 }
2933}
2934
2935/// pushValueAndType - The file has to encode both the value and type id for
2936/// many values, because we need to know what type to create for forward
2937/// references. However, most operands are not forward references, so this type
2938/// field is not needed.
2939///
2940/// This function adds V's value ID to Vals. If the value ID is higher than the
2941/// instruction ID, then it is a forward reference, and it also includes the
2942/// type ID. The value ID that is written is encoded relative to the InstID.
2943bool ModuleBitcodeWriter::pushValueAndType(constValue *V,unsigned InstID,
2944SmallVectorImpl<unsigned> &Vals) {
2945unsignedValID = VE.getValueID(V);
2946// Make encoding relative to the InstID.
2947 Vals.push_back(InstID -ValID);
2948if (ValID >= InstID) {
2949 Vals.push_back(VE.getTypeID(V->getType()));
2950returntrue;
2951 }
2952returnfalse;
2953}
2954
2955bool ModuleBitcodeWriter::pushValueOrMetadata(constValue *V,unsigned InstID,
2956SmallVectorImpl<unsigned> &Vals) {
2957bool IsMetadata =V->getType()->isMetadataTy();
2958if (IsMetadata) {
2959 Vals.push_back(bitc::OB_METADATA);
2960Metadata *MD = cast<MetadataAsValue>(V)->getMetadata();
2961unsignedValID = VE.getMetadataID(MD);
2962 Vals.push_back(InstID -ValID);
2963returnfalse;
2964 }
2965return pushValueAndType(V, InstID, Vals);
2966}
2967
2968void ModuleBitcodeWriter::writeOperandBundles(constCallBase &CS,
2969unsigned InstID) {
2970SmallVector<unsigned, 64>Record;
2971LLVMContext &C = CS.getContext();
2972
2973for (unsigned i = 0, e = CS.getNumOperandBundles(); i != e; ++i) {
2974constauto &Bundle = CS.getOperandBundleAt(i);
2975Record.push_back(C.getOperandBundleTagID(Bundle.getTagName()));
2976
2977for (auto &Input : Bundle.Inputs)
2978 pushValueOrMetadata(Input, InstID,Record);
2979
2980 Stream.EmitRecord(bitc::FUNC_CODE_OPERAND_BUNDLE,Record);
2981Record.clear();
2982 }
2983}
2984
2985/// pushValue - Like pushValueAndType, but where the type of the value is
2986/// omitted (perhaps it was already encoded in an earlier operand).
2987void ModuleBitcodeWriter::pushValue(constValue *V,unsigned InstID,
2988SmallVectorImpl<unsigned> &Vals) {
2989unsignedValID = VE.getValueID(V);
2990 Vals.push_back(InstID -ValID);
2991}
2992
2993void ModuleBitcodeWriter::pushValueSigned(constValue *V,unsigned InstID,
2994SmallVectorImpl<uint64_t> &Vals) {
2995unsignedValID = VE.getValueID(V);
2996 int64_t diff = ((int32_t)InstID - (int32_t)ValID);
2997emitSignedInt64(Vals, diff);
2998}
2999
3000/// WriteInstruction - Emit an instruction to the specified stream.
3001void ModuleBitcodeWriter::writeInstruction(constInstruction &I,
3002unsigned InstID,
3003SmallVectorImpl<unsigned> &Vals) {
3004unsignedCode = 0;
3005unsigned AbbrevToUse = 0;
3006 VE.setInstructionID(&I);
3007switch (I.getOpcode()) {
3008default:
3009if (Instruction::isCast(I.getOpcode())) {
3010Code =bitc::FUNC_CODE_INST_CAST;
3011if (!pushValueAndType(I.getOperand(0), InstID, Vals))
3012 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
3013 Vals.push_back(VE.getTypeID(I.getType()));
3014 Vals.push_back(getEncodedCastOpcode(I.getOpcode()));
3015uint64_tFlags =getOptimizationFlags(&I);
3016if (Flags != 0) {
3017if (AbbrevToUse == FUNCTION_INST_CAST_ABBREV)
3018 AbbrevToUse = FUNCTION_INST_CAST_FLAGS_ABBREV;
3019 Vals.push_back(Flags);
3020 }
3021 }else {
3022assert(isa<BinaryOperator>(I) &&"Unknown instruction!");
3023Code =bitc::FUNC_CODE_INST_BINOP;
3024if (!pushValueAndType(I.getOperand(0), InstID, Vals))
3025 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
3026 pushValue(I.getOperand(1), InstID, Vals);
3027 Vals.push_back(getEncodedBinaryOpcode(I.getOpcode()));
3028uint64_tFlags =getOptimizationFlags(&I);
3029if (Flags != 0) {
3030if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
3031 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
3032 Vals.push_back(Flags);
3033 }
3034 }
3035break;
3036case Instruction::FNeg: {
3037Code =bitc::FUNC_CODE_INST_UNOP;
3038if (!pushValueAndType(I.getOperand(0), InstID, Vals))
3039 AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
3040 Vals.push_back(getEncodedUnaryOpcode(I.getOpcode()));
3041uint64_tFlags =getOptimizationFlags(&I);
3042if (Flags != 0) {
3043if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
3044 AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
3045 Vals.push_back(Flags);
3046 }
3047break;
3048 }
3049case Instruction::GetElementPtr: {
3050Code =bitc::FUNC_CODE_INST_GEP;
3051 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
3052auto &GEPInst = cast<GetElementPtrInst>(I);
3053 Vals.push_back(getOptimizationFlags(&I));
3054 Vals.push_back(VE.getTypeID(GEPInst.getSourceElementType()));
3055for (constValue *Op :I.operands())
3056 pushValueAndType(Op, InstID, Vals);
3057break;
3058 }
3059case Instruction::ExtractValue: {
3060Code =bitc::FUNC_CODE_INST_EXTRACTVAL;
3061 pushValueAndType(I.getOperand(0), InstID, Vals);
3062constExtractValueInst *EVI = cast<ExtractValueInst>(&I);
3063 Vals.append(EVI->idx_begin(), EVI->idx_end());
3064break;
3065 }
3066case Instruction::InsertValue: {
3067Code =bitc::FUNC_CODE_INST_INSERTVAL;
3068 pushValueAndType(I.getOperand(0), InstID, Vals);
3069 pushValueAndType(I.getOperand(1), InstID, Vals);
3070constInsertValueInst *IVI = cast<InsertValueInst>(&I);
3071 Vals.append(IVI->idx_begin(), IVI->idx_end());
3072break;
3073 }
3074case Instruction::Select: {
3075Code =bitc::FUNC_CODE_INST_VSELECT;
3076 pushValueAndType(I.getOperand(1), InstID, Vals);
3077 pushValue(I.getOperand(2), InstID, Vals);
3078 pushValueAndType(I.getOperand(0), InstID, Vals);
3079uint64_tFlags =getOptimizationFlags(&I);
3080if (Flags != 0)
3081 Vals.push_back(Flags);
3082break;
3083 }
3084case Instruction::ExtractElement:
3085Code =bitc::FUNC_CODE_INST_EXTRACTELT;
3086 pushValueAndType(I.getOperand(0), InstID, Vals);
3087 pushValueAndType(I.getOperand(1), InstID, Vals);
3088break;
3089case Instruction::InsertElement:
3090Code =bitc::FUNC_CODE_INST_INSERTELT;
3091 pushValueAndType(I.getOperand(0), InstID, Vals);
3092 pushValue(I.getOperand(1), InstID, Vals);
3093 pushValueAndType(I.getOperand(2), InstID, Vals);
3094break;
3095case Instruction::ShuffleVector:
3096Code =bitc::FUNC_CODE_INST_SHUFFLEVEC;
3097 pushValueAndType(I.getOperand(0), InstID, Vals);
3098 pushValue(I.getOperand(1), InstID, Vals);
3099 pushValue(cast<ShuffleVectorInst>(I).getShuffleMaskForBitcode(), InstID,
3100 Vals);
3101break;
3102case Instruction::ICmp:
3103case Instruction::FCmp: {
3104// compare returning Int1Ty or vector of Int1Ty
3105Code =bitc::FUNC_CODE_INST_CMP2;
3106 pushValueAndType(I.getOperand(0), InstID, Vals);
3107 pushValue(I.getOperand(1), InstID, Vals);
3108 Vals.push_back(cast<CmpInst>(I).getPredicate());
3109uint64_tFlags =getOptimizationFlags(&I);
3110if (Flags != 0)
3111 Vals.push_back(Flags);
3112break;
3113 }
3114
3115case Instruction::Ret:
3116 {
3117Code =bitc::FUNC_CODE_INST_RET;
3118unsigned NumOperands =I.getNumOperands();
3119if (NumOperands == 0)
3120 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
3121elseif (NumOperands == 1) {
3122if (!pushValueAndType(I.getOperand(0), InstID, Vals))
3123 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
3124 }else {
3125for (constValue *Op :I.operands())
3126 pushValueAndType(Op, InstID, Vals);
3127 }
3128 }
3129break;
3130case Instruction::Br:
3131 {
3132Code =bitc::FUNC_CODE_INST_BR;
3133constBranchInst &II = cast<BranchInst>(I);
3134 Vals.push_back(VE.getValueID(II.getSuccessor(0)));
3135if (II.isConditional()) {
3136 Vals.push_back(VE.getValueID(II.getSuccessor(1)));
3137 pushValue(II.getCondition(), InstID, Vals);
3138 }
3139 }
3140break;
3141case Instruction::Switch:
3142 {
3143Code =bitc::FUNC_CODE_INST_SWITCH;
3144constSwitchInst &SI = cast<SwitchInst>(I);
3145 Vals.push_back(VE.getTypeID(SI.getCondition()->getType()));
3146 pushValue(SI.getCondition(), InstID, Vals);
3147 Vals.push_back(VE.getValueID(SI.getDefaultDest()));
3148for (auto Case :SI.cases()) {
3149 Vals.push_back(VE.getValueID(Case.getCaseValue()));
3150 Vals.push_back(VE.getValueID(Case.getCaseSuccessor()));
3151 }
3152 }
3153break;
3154case Instruction::IndirectBr:
3155Code =bitc::FUNC_CODE_INST_INDIRECTBR;
3156 Vals.push_back(VE.getTypeID(I.getOperand(0)->getType()));
3157// Encode the address operand as relative, but not the basic blocks.
3158 pushValue(I.getOperand(0), InstID, Vals);
3159for (constValue *Op :drop_begin(I.operands()))
3160 Vals.push_back(VE.getValueID(Op));
3161break;
3162
3163case Instruction::Invoke: {
3164constInvokeInst *II = cast<InvokeInst>(&I);
3165constValue *Callee =II->getCalledOperand();
3166FunctionType *FTy =II->getFunctionType();
3167
3168if (II->hasOperandBundles())
3169 writeOperandBundles(*II, InstID);
3170
3171Code =bitc::FUNC_CODE_INST_INVOKE;
3172
3173 Vals.push_back(VE.getAttributeListID(II->getAttributes()));
3174 Vals.push_back(II->getCallingConv() | 1 << 13);
3175 Vals.push_back(VE.getValueID(II->getNormalDest()));
3176 Vals.push_back(VE.getValueID(II->getUnwindDest()));
3177 Vals.push_back(VE.getTypeID(FTy));
3178 pushValueAndType(Callee, InstID, Vals);
3179
3180// Emit value #'s for the fixed parameters.
3181for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3182 pushValue(I.getOperand(i), InstID, Vals);// fixed param.
3183
3184// Emit type/value pairs for varargs params.
3185if (FTy->isVarArg()) {
3186for (unsigned i = FTy->getNumParams(), e =II->arg_size(); i != e; ++i)
3187 pushValueAndType(I.getOperand(i), InstID, Vals);// vararg
3188 }
3189break;
3190 }
3191case Instruction::Resume:
3192Code =bitc::FUNC_CODE_INST_RESUME;
3193 pushValueAndType(I.getOperand(0), InstID, Vals);
3194break;
3195case Instruction::CleanupRet: {
3196Code =bitc::FUNC_CODE_INST_CLEANUPRET;
3197constauto &CRI = cast<CleanupReturnInst>(I);
3198 pushValue(CRI.getCleanupPad(), InstID, Vals);
3199if (CRI.hasUnwindDest())
3200 Vals.push_back(VE.getValueID(CRI.getUnwindDest()));
3201break;
3202 }
3203case Instruction::CatchRet: {
3204Code =bitc::FUNC_CODE_INST_CATCHRET;
3205constauto &CRI = cast<CatchReturnInst>(I);
3206 pushValue(CRI.getCatchPad(), InstID, Vals);
3207 Vals.push_back(VE.getValueID(CRI.getSuccessor()));
3208break;
3209 }
3210case Instruction::CleanupPad:
3211case Instruction::CatchPad: {
3212constauto &FuncletPad = cast<FuncletPadInst>(I);
3213Code = isa<CatchPadInst>(FuncletPad) ?bitc::FUNC_CODE_INST_CATCHPAD
3214 :bitc::FUNC_CODE_INST_CLEANUPPAD;
3215 pushValue(FuncletPad.getParentPad(), InstID, Vals);
3216
3217unsigned NumArgOperands = FuncletPad.arg_size();
3218 Vals.push_back(NumArgOperands);
3219for (unsignedOp = 0;Op != NumArgOperands; ++Op)
3220 pushValueAndType(FuncletPad.getArgOperand(Op), InstID, Vals);
3221break;
3222 }
3223case Instruction::CatchSwitch: {
3224Code =bitc::FUNC_CODE_INST_CATCHSWITCH;
3225constauto &CatchSwitch = cast<CatchSwitchInst>(I);
3226
3227 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
3228
3229unsigned NumHandlers = CatchSwitch.getNumHandlers();
3230 Vals.push_back(NumHandlers);
3231for (constBasicBlock *CatchPadBB : CatchSwitch.handlers())
3232 Vals.push_back(VE.getValueID(CatchPadBB));
3233
3234if (CatchSwitch.hasUnwindDest())
3235 Vals.push_back(VE.getValueID(CatchSwitch.getUnwindDest()));
3236break;
3237 }
3238case Instruction::CallBr: {
3239constCallBrInst *CBI = cast<CallBrInst>(&I);
3240constValue *Callee = CBI->getCalledOperand();
3241FunctionType *FTy = CBI->getFunctionType();
3242
3243if (CBI->hasOperandBundles())
3244 writeOperandBundles(*CBI, InstID);
3245
3246Code =bitc::FUNC_CODE_INST_CALLBR;
3247
3248 Vals.push_back(VE.getAttributeListID(CBI->getAttributes()));
3249
3250 Vals.push_back(CBI->getCallingConv() <<bitc::CALL_CCONV |
3251 1 <<bitc::CALL_EXPLICIT_TYPE);
3252
3253 Vals.push_back(VE.getValueID(CBI->getDefaultDest()));
3254 Vals.push_back(CBI->getNumIndirectDests());
3255for (unsigned i = 0, e = CBI->getNumIndirectDests(); i != e; ++i)
3256 Vals.push_back(VE.getValueID(CBI->getIndirectDest(i)));
3257
3258 Vals.push_back(VE.getTypeID(FTy));
3259 pushValueAndType(Callee, InstID, Vals);
3260
3261// Emit value #'s for the fixed parameters.
3262for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3263 pushValue(I.getOperand(i), InstID, Vals);// fixed param.
3264
3265// Emit type/value pairs for varargs params.
3266if (FTy->isVarArg()) {
3267for (unsigned i = FTy->getNumParams(), e = CBI->arg_size(); i != e; ++i)
3268 pushValueAndType(I.getOperand(i), InstID, Vals);// vararg
3269 }
3270break;
3271 }
3272case Instruction::Unreachable:
3273Code =bitc::FUNC_CODE_INST_UNREACHABLE;
3274 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
3275break;
3276
3277case Instruction::PHI: {
3278constPHINode &PN = cast<PHINode>(I);
3279Code =bitc::FUNC_CODE_INST_PHI;
3280// With the newer instruction encoding, forward references could give
3281// negative valued IDs. This is most common for PHIs, so we use
3282// signed VBRs.
3283SmallVector<uint64_t, 128> Vals64;
3284 Vals64.push_back(VE.getTypeID(PN.getType()));
3285for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) {
3286 pushValueSigned(PN.getIncomingValue(i), InstID, Vals64);
3287 Vals64.push_back(VE.getValueID(PN.getIncomingBlock(i)));
3288 }
3289
3290uint64_tFlags =getOptimizationFlags(&I);
3291if (Flags != 0)
3292 Vals64.push_back(Flags);
3293
3294// Emit a Vals64 vector and exit.
3295 Stream.EmitRecord(Code, Vals64, AbbrevToUse);
3296 Vals64.clear();
3297return;
3298 }
3299
3300case Instruction::LandingPad: {
3301constLandingPadInst &LP = cast<LandingPadInst>(I);
3302Code =bitc::FUNC_CODE_INST_LANDINGPAD;
3303 Vals.push_back(VE.getTypeID(LP.getType()));
3304 Vals.push_back(LP.isCleanup());
3305 Vals.push_back(LP.getNumClauses());
3306for (unsignedI = 0, E = LP.getNumClauses();I != E; ++I) {
3307if (LP.isCatch(I))
3308 Vals.push_back(LandingPadInst::Catch);
3309else
3310 Vals.push_back(LandingPadInst::Filter);
3311 pushValueAndType(LP.getClause(I), InstID, Vals);
3312 }
3313break;
3314 }
3315
3316case Instruction::Alloca: {
3317Code =bitc::FUNC_CODE_INST_ALLOCA;
3318constAllocaInst &AI = cast<AllocaInst>(I);
3319 Vals.push_back(VE.getTypeID(AI.getAllocatedType()));
3320 Vals.push_back(VE.getTypeID(I.getOperand(0)->getType()));
3321 Vals.push_back(VE.getValueID(I.getOperand(0)));// size.
3322usingAPV =AllocaPackedValues;
3323unsignedRecord = 0;
3324unsigned EncodedAlign = getEncodedAlign(AI.getAlign());
3325 Bitfield::set<APV::AlignLower>(
3326Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1));
3327 Bitfield::set<APV::AlignUpper>(Record,
3328 EncodedAlign >> APV::AlignLower::Bits);
3329 Bitfield::set<APV::UsedWithInAlloca>(Record, AI.isUsedWithInAlloca());
3330 Bitfield::set<APV::ExplicitType>(Record,true);
3331 Bitfield::set<APV::SwiftError>(Record, AI.isSwiftError());
3332 Vals.push_back(Record);
3333
3334unsigned AS = AI.getAddressSpace();
3335if (AS !=M.getDataLayout().getAllocaAddrSpace())
3336 Vals.push_back(AS);
3337break;
3338 }
3339
3340case Instruction::Load:
3341if (cast<LoadInst>(I).isAtomic()) {
3342Code =bitc::FUNC_CODE_INST_LOADATOMIC;
3343 pushValueAndType(I.getOperand(0), InstID, Vals);
3344 }else {
3345Code =bitc::FUNC_CODE_INST_LOAD;
3346if (!pushValueAndType(I.getOperand(0), InstID, Vals))// ptr
3347 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
3348 }
3349 Vals.push_back(VE.getTypeID(I.getType()));
3350 Vals.push_back(getEncodedAlign(cast<LoadInst>(I).getAlign()));
3351 Vals.push_back(cast<LoadInst>(I).isVolatile());
3352if (cast<LoadInst>(I).isAtomic()) {
3353 Vals.push_back(getEncodedOrdering(cast<LoadInst>(I).getOrdering()));
3354 Vals.push_back(getEncodedSyncScopeID(cast<LoadInst>(I).getSyncScopeID()));
3355 }
3356break;
3357case Instruction::Store:
3358if (cast<StoreInst>(I).isAtomic())
3359Code =bitc::FUNC_CODE_INST_STOREATOMIC;
3360else
3361Code =bitc::FUNC_CODE_INST_STORE;
3362 pushValueAndType(I.getOperand(1), InstID, Vals);// ptrty + ptr
3363 pushValueAndType(I.getOperand(0), InstID, Vals);// valty + val
3364 Vals.push_back(getEncodedAlign(cast<StoreInst>(I).getAlign()));
3365 Vals.push_back(cast<StoreInst>(I).isVolatile());
3366if (cast<StoreInst>(I).isAtomic()) {
3367 Vals.push_back(getEncodedOrdering(cast<StoreInst>(I).getOrdering()));
3368 Vals.push_back(
3369 getEncodedSyncScopeID(cast<StoreInst>(I).getSyncScopeID()));
3370 }
3371break;
3372case Instruction::AtomicCmpXchg:
3373Code =bitc::FUNC_CODE_INST_CMPXCHG;
3374 pushValueAndType(I.getOperand(0), InstID, Vals);// ptrty + ptr
3375 pushValueAndType(I.getOperand(1), InstID, Vals);// cmp.
3376 pushValue(I.getOperand(2), InstID, Vals);// newval.
3377 Vals.push_back(cast<AtomicCmpXchgInst>(I).isVolatile());
3378 Vals.push_back(
3379getEncodedOrdering(cast<AtomicCmpXchgInst>(I).getSuccessOrdering()));
3380 Vals.push_back(
3381 getEncodedSyncScopeID(cast<AtomicCmpXchgInst>(I).getSyncScopeID()));
3382 Vals.push_back(
3383getEncodedOrdering(cast<AtomicCmpXchgInst>(I).getFailureOrdering()));
3384 Vals.push_back(cast<AtomicCmpXchgInst>(I).isWeak());
3385 Vals.push_back(getEncodedAlign(cast<AtomicCmpXchgInst>(I).getAlign()));
3386break;
3387case Instruction::AtomicRMW:
3388Code =bitc::FUNC_CODE_INST_ATOMICRMW;
3389 pushValueAndType(I.getOperand(0), InstID, Vals);// ptrty + ptr
3390 pushValueAndType(I.getOperand(1), InstID, Vals);// valty + val
3391 Vals.push_back(
3392getEncodedRMWOperation(cast<AtomicRMWInst>(I).getOperation()));
3393 Vals.push_back(cast<AtomicRMWInst>(I).isVolatile());
3394 Vals.push_back(getEncodedOrdering(cast<AtomicRMWInst>(I).getOrdering()));
3395 Vals.push_back(
3396 getEncodedSyncScopeID(cast<AtomicRMWInst>(I).getSyncScopeID()));
3397 Vals.push_back(getEncodedAlign(cast<AtomicRMWInst>(I).getAlign()));
3398break;
3399case Instruction::Fence:
3400Code =bitc::FUNC_CODE_INST_FENCE;
3401 Vals.push_back(getEncodedOrdering(cast<FenceInst>(I).getOrdering()));
3402 Vals.push_back(getEncodedSyncScopeID(cast<FenceInst>(I).getSyncScopeID()));
3403break;
3404case Instruction::Call: {
3405constCallInst &CI = cast<CallInst>(I);
3406FunctionType *FTy = CI.getFunctionType();
3407
3408if (CI.hasOperandBundles())
3409 writeOperandBundles(CI, InstID);
3410
3411Code =bitc::FUNC_CODE_INST_CALL;
3412
3413 Vals.push_back(VE.getAttributeListID(CI.getAttributes()));
3414
3415unsignedFlags =getOptimizationFlags(&I);
3416 Vals.push_back(CI.getCallingConv() <<bitc::CALL_CCONV |
3417unsigned(CI.isTailCall()) <<bitc::CALL_TAIL |
3418unsigned(CI.isMustTailCall()) <<bitc::CALL_MUSTTAIL |
3419 1 <<bitc::CALL_EXPLICIT_TYPE |
3420unsigned(CI.isNoTailCall()) <<bitc::CALL_NOTAIL |
3421unsigned(Flags != 0) <<bitc::CALL_FMF);
3422if (Flags != 0)
3423 Vals.push_back(Flags);
3424
3425 Vals.push_back(VE.getTypeID(FTy));
3426 pushValueAndType(CI.getCalledOperand(), InstID, Vals);// Callee
3427
3428// Emit value #'s for the fixed parameters.
3429for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
3430// Check for labels (can happen with asm labels).
3431if (FTy->getParamType(i)->isLabelTy())
3432 Vals.push_back(VE.getValueID(CI.getArgOperand(i)));
3433else
3434 pushValue(CI.getArgOperand(i), InstID, Vals);// fixed param.
3435 }
3436
3437// Emit type/value pairs for varargs params.
3438if (FTy->isVarArg()) {
3439for (unsigned i = FTy->getNumParams(), e = CI.arg_size(); i != e; ++i)
3440 pushValueAndType(CI.getArgOperand(i), InstID, Vals);// varargs
3441 }
3442break;
3443 }
3444case Instruction::VAArg:
3445Code =bitc::FUNC_CODE_INST_VAARG;
3446 Vals.push_back(VE.getTypeID(I.getOperand(0)->getType()));// valistty
3447 pushValue(I.getOperand(0), InstID, Vals);// valist.
3448 Vals.push_back(VE.getTypeID(I.getType()));// restype.
3449break;
3450case Instruction::Freeze:
3451Code =bitc::FUNC_CODE_INST_FREEZE;
3452 pushValueAndType(I.getOperand(0), InstID, Vals);
3453break;
3454 }
3455
3456 Stream.EmitRecord(Code, Vals, AbbrevToUse);
3457 Vals.clear();
3458}
3459
3460/// Write a GlobalValue VST to the module. The purpose of this data structure is
3461/// to allow clients to efficiently find the function body.
3462void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
3463DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex) {
3464// Get the offset of the VST we are writing, and backpatch it into
3465// the VST forward declaration record.
3466uint64_t VSTOffset = Stream.GetCurrentBitNo();
3467// The BitcodeStartBit was the stream offset of the identification block.
3468 VSTOffset -= bitcodeStartBit();
3469assert((VSTOffset & 31) == 0 &&"VST block not 32-bit aligned");
3470// Note that we add 1 here because the offset is relative to one word
3471// before the start of the identification block, which was historically
3472// always the start of the regular bitcode header.
3473 Stream.BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
3474
3475 Stream.EnterSubblock(bitc::VALUE_SYMTAB_BLOCK_ID, 4);
3476
3477auto Abbv = std::make_shared<BitCodeAbbrev>();
3478 Abbv->Add(BitCodeAbbrevOp(bitc::VST_CODE_FNENTRY));
3479 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// value id
3480 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// funcoffset
3481unsigned FnEntryAbbrev = Stream.EmitAbbrev(std::move(Abbv));
3482
3483for (constFunction &F : M) {
3484uint64_tRecord[2];
3485
3486if (F.isDeclaration())
3487continue;
3488
3489Record[0] = VE.getValueID(&F);
3490
3491// Save the word offset of the function (from the start of the
3492// actual bitcode written to the stream).
3493uint64_t BitcodeIndex = FunctionToBitcodeIndex[&F] - bitcodeStartBit();
3494assert((BitcodeIndex & 31) == 0 &&"function block not 32-bit aligned");
3495// Note that we add 1 here because the offset is relative to one word
3496// before the start of the identification block, which was historically
3497// always the start of the regular bitcode header.
3498Record[1] = BitcodeIndex / 32 + 1;
3499
3500 Stream.EmitRecord(bitc::VST_CODE_FNENTRY,Record, FnEntryAbbrev);
3501 }
3502
3503 Stream.ExitBlock();
3504}
3505
3506/// Emit names for arguments, instructions and basic blocks in a function.
3507void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
3508constValueSymbolTable &VST) {
3509if (VST.empty())
3510return;
3511
3512 Stream.EnterSubblock(bitc::VALUE_SYMTAB_BLOCK_ID, 4);
3513
3514// FIXME: Set up the abbrev, we know how many values there are!
3515// FIXME: We know if the type names can use 7-bit ascii.
3516SmallVector<uint64_t, 64> NameVals;
3517
3518for (constValueName &Name : VST) {
3519// Figure out the encoding to use for the name.
3520StringEncodingBits =getStringEncoding(Name.getKey());
3521
3522unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
3523 NameVals.push_back(VE.getValueID(Name.getValue()));
3524
3525// VST_CODE_ENTRY: [valueid, namechar x N]
3526// VST_CODE_BBENTRY: [bbid, namechar x N]
3527unsignedCode;
3528if (isa<BasicBlock>(Name.getValue())) {
3529Code =bitc::VST_CODE_BBENTRY;
3530if (Bits ==SE_Char6)
3531 AbbrevToUse = VST_BBENTRY_6_ABBREV;
3532 }else {
3533Code =bitc::VST_CODE_ENTRY;
3534if (Bits ==SE_Char6)
3535 AbbrevToUse = VST_ENTRY_6_ABBREV;
3536elseif (Bits ==SE_Fixed7)
3537 AbbrevToUse = VST_ENTRY_7_ABBREV;
3538 }
3539
3540for (constautoP :Name.getKey())
3541 NameVals.push_back((unsignedchar)P);
3542
3543// Emit the finished record.
3544 Stream.EmitRecord(Code, NameVals, AbbrevToUse);
3545 NameVals.clear();
3546 }
3547
3548 Stream.ExitBlock();
3549}
3550
3551void ModuleBitcodeWriter::writeUseList(UseListOrder &&Order) {
3552assert(Order.Shuffle.size() >= 2 &&"Shuffle too small");
3553unsignedCode;
3554if (isa<BasicBlock>(Order.V))
3555Code =bitc::USELIST_CODE_BB;
3556else
3557Code =bitc::USELIST_CODE_DEFAULT;
3558
3559SmallVector<uint64_t, 64>Record(Order.Shuffle.begin(), Order.Shuffle.end());
3560Record.push_back(VE.getValueID(Order.V));
3561 Stream.EmitRecord(Code,Record);
3562}
3563
3564void ModuleBitcodeWriter::writeUseListBlock(constFunction *F) {
3565assert(VE.shouldPreserveUseListOrder() &&
3566"Expected to be preserving use-list order");
3567
3568auto hasMore = [&]() {
3569return !VE.UseListOrders.empty() && VE.UseListOrders.back().F ==F;
3570 };
3571if (!hasMore())
3572// Nothing to do.
3573return;
3574
3575 Stream.EnterSubblock(bitc::USELIST_BLOCK_ID, 3);
3576while (hasMore()) {
3577 writeUseList(std::move(VE.UseListOrders.back()));
3578 VE.UseListOrders.pop_back();
3579 }
3580 Stream.ExitBlock();
3581}
3582
3583/// Emit a function body to the module stream.
3584void ModuleBitcodeWriter::writeFunction(
3585constFunction &F,
3586DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex) {
3587// Save the bitcode index of the start of this function block for recording
3588// in the VST.
3589 FunctionToBitcodeIndex[&F] = Stream.GetCurrentBitNo();
3590
3591 Stream.EnterSubblock(bitc::FUNCTION_BLOCK_ID, 4);
3592 VE.incorporateFunction(F);
3593
3594SmallVector<unsigned, 64> Vals;
3595
3596// Emit the number of basic blocks, so the reader can create them ahead of
3597// time.
3598 Vals.push_back(VE.getBasicBlocks().size());
3599 Stream.EmitRecord(bitc::FUNC_CODE_DECLAREBLOCKS, Vals);
3600 Vals.clear();
3601
3602// If there are function-local constants, emit them now.
3603unsigned CstStart, CstEnd;
3604 VE.getFunctionConstantRange(CstStart, CstEnd);
3605 writeConstants(CstStart, CstEnd,false);
3606
3607// If there is function-local metadata, emit it now.
3608 writeFunctionMetadata(F);
3609
3610// Keep a running idea of what the instruction ID is.
3611unsigned InstID = CstEnd;
3612
3613bool NeedsMetadataAttachment =F.hasMetadata();
3614
3615DILocation *LastDL =nullptr;
3616SmallSetVector<Function *, 4> BlockAddressUsers;
3617
3618// Finally, emit all the instructions, in order.
3619for (constBasicBlock &BB :F) {
3620for (constInstruction &I : BB) {
3621 writeInstruction(I, InstID, Vals);
3622
3623if (!I.getType()->isVoidTy())
3624 ++InstID;
3625
3626// If the instruction has metadata, write a metadata attachment later.
3627 NeedsMetadataAttachment |=I.hasMetadataOtherThanDebugLoc();
3628
3629// If the instruction has a debug location, emit it.
3630if (DILocation *DL =I.getDebugLoc()) {
3631if (DL == LastDL) {
3632// Just repeat the same debug loc as last time.
3633 Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC_AGAIN, Vals);
3634 }else {
3635 Vals.push_back(DL->getLine());
3636 Vals.push_back(DL->getColumn());
3637 Vals.push_back(VE.getMetadataOrNullID(DL->getScope()));
3638 Vals.push_back(VE.getMetadataOrNullID(DL->getInlinedAt()));
3639 Vals.push_back(DL->isImplicitCode());
3640 Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC, Vals);
3641 Vals.clear();
3642 LastDL =DL;
3643 }
3644 }
3645
3646// If the instruction has DbgRecords attached to it, emit them. Note that
3647// they come after the instruction so that it's easy to attach them again
3648// when reading the bitcode, even though conceptually the debug locations
3649// start "before" the instruction.
3650if (I.hasDbgRecords() &&WriteNewDbgInfoFormatToBitcode) {
3651 /// Try to push the value only (unwrapped), otherwise push the
3652 /// metadata wrapped value. Returns true if the value was pushed
3653 /// without the ValueAsMetadata wrapper.
3654auto PushValueOrMetadata = [&Vals, InstID,
3655this](Metadata *RawLocation) {
3656assert(RawLocation &&
3657"RawLocation unexpectedly null in DbgVariableRecord");
3658if (ValueAsMetadata *VAM = dyn_cast<ValueAsMetadata>(RawLocation)) {
3659SmallVector<unsigned, 2> ValAndType;
3660// If the value is a fwd-ref the type is also pushed. We don't
3661// want the type, so fwd-refs are kept wrapped (pushValueAndType
3662// returns false if the value is pushed without type).
3663if (!pushValueAndType(VAM->getValue(), InstID, ValAndType)) {
3664 Vals.push_back(ValAndType[0]);
3665returntrue;
3666 }
3667 }
3668// The metadata is a DIArgList, or ValueAsMetadata wrapping a
3669// fwd-ref. Push the metadata ID.
3670 Vals.push_back(VE.getMetadataID(RawLocation));
3671returnfalse;
3672 };
3673
3674// Write out non-instruction debug information attached to this
3675// instruction. Write it after the instruction so that it's easy to
3676// re-attach to the instruction reading the records in.
3677for (DbgRecord &DR :I.DebugMarker->getDbgRecordRange()) {
3678if (DbgLabelRecord *DLR = dyn_cast<DbgLabelRecord>(&DR)) {
3679 Vals.push_back(VE.getMetadataID(&*DLR->getDebugLoc()));
3680 Vals.push_back(VE.getMetadataID(DLR->getLabel()));
3681 Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_RECORD_LABEL, Vals);
3682 Vals.clear();
3683continue;
3684 }
3685
3686// First 3 fields are common to all kinds:
3687// DILocation, DILocalVariable, DIExpression
3688// dbg_value (FUNC_CODE_DEBUG_RECORD_VALUE)
3689// ..., LocationMetadata
3690// dbg_value (FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE - abbrev'd)
3691// ..., Value
3692// dbg_declare (FUNC_CODE_DEBUG_RECORD_DECLARE)
3693// ..., LocationMetadata
3694// dbg_assign (FUNC_CODE_DEBUG_RECORD_ASSIGN)
3695// ..., LocationMetadata, DIAssignID, DIExpression, LocationMetadata
3696DbgVariableRecord &DVR = cast<DbgVariableRecord>(DR);
3697 Vals.push_back(VE.getMetadataID(&*DVR.getDebugLoc()));
3698 Vals.push_back(VE.getMetadataID(DVR.getVariable()));
3699 Vals.push_back(VE.getMetadataID(DVR.getExpression()));
3700if (DVR.isDbgValue()) {
3701if (PushValueOrMetadata(DVR.getRawLocation()))
3702 Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE, Vals,
3703 FUNCTION_DEBUG_RECORD_VALUE_ABBREV);
3704else
3705 Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_RECORD_VALUE, Vals);
3706 }elseif (DVR.isDbgDeclare()) {
3707 Vals.push_back(VE.getMetadataID(DVR.getRawLocation()));
3708 Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_RECORD_DECLARE, Vals);
3709 }else {
3710assert(DVR.isDbgAssign() &&"Unexpected DbgRecord kind");
3711 Vals.push_back(VE.getMetadataID(DVR.getRawLocation()));
3712 Vals.push_back(VE.getMetadataID(DVR.getAssignID()));
3713 Vals.push_back(VE.getMetadataID(DVR.getAddressExpression()));
3714 Vals.push_back(VE.getMetadataID(DVR.getRawAddress()));
3715 Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_RECORD_ASSIGN, Vals);
3716 }
3717 Vals.clear();
3718 }
3719 }
3720 }
3721
3722if (BlockAddress *BA =BlockAddress::lookup(&BB)) {
3723SmallVector<Value *> Worklist{BA};
3724SmallPtrSet<Value *, 8> Visited{BA};
3725while (!Worklist.empty()) {
3726Value *V = Worklist.pop_back_val();
3727for (User *U :V->users()) {
3728if (auto *I = dyn_cast<Instruction>(U)) {
3729Function *P =I->getFunction();
3730if (P != &F)
3731 BlockAddressUsers.insert(P);
3732 }elseif (isa<Constant>(U) && !isa<GlobalValue>(U) &&
3733 Visited.insert(U).second)
3734 Worklist.push_back(U);
3735 }
3736 }
3737 }
3738 }
3739
3740if (!BlockAddressUsers.empty()) {
3741 Vals.resize(BlockAddressUsers.size());
3742for (autoI :llvm::enumerate(BlockAddressUsers))
3743 Vals[I.index()] = VE.getValueID(I.value());
3744 Stream.EmitRecord(bitc::FUNC_CODE_BLOCKADDR_USERS, Vals);
3745 Vals.clear();
3746 }
3747
3748// Emit names for all the instructions etc.
3749if (auto *Symtab =F.getValueSymbolTable())
3750 writeFunctionLevelValueSymbolTable(*Symtab);
3751
3752if (NeedsMetadataAttachment)
3753 writeFunctionMetadataAttachment(F);
3754if (VE.shouldPreserveUseListOrder())
3755 writeUseListBlock(&F);
3756 VE.purgeFunction();
3757 Stream.ExitBlock();
3758}
3759
3760// Emit blockinfo, which defines the standard abbreviations etc.
3761void ModuleBitcodeWriter::writeBlockInfo() {
3762// We only want to emit block info records for blocks that have multiple
3763// instances: CONSTANTS_BLOCK, FUNCTION_BLOCK and VALUE_SYMTAB_BLOCK.
3764// Other blocks can define their abbrevs inline.
3765 Stream.EnterBlockInfoBlock();
3766
3767 {// 8-bit fixed-width VST_CODE_ENTRY/VST_CODE_BBENTRY strings.
3768auto Abbv = std::make_shared<BitCodeAbbrev>();
3769 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3));
3770 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
3771 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
3772 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8));
3773if (Stream.EmitBlockInfoAbbrev(bitc::VALUE_SYMTAB_BLOCK_ID, Abbv) !=
3774 VST_ENTRY_8_ABBREV)
3775llvm_unreachable("Unexpected abbrev ordering!");
3776 }
3777
3778 {// 7-bit fixed width VST_CODE_ENTRY strings.
3779auto Abbv = std::make_shared<BitCodeAbbrev>();
3780 Abbv->Add(BitCodeAbbrevOp(bitc::VST_CODE_ENTRY));
3781 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
3782 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
3783 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7));
3784if (Stream.EmitBlockInfoAbbrev(bitc::VALUE_SYMTAB_BLOCK_ID, Abbv) !=
3785 VST_ENTRY_7_ABBREV)
3786llvm_unreachable("Unexpected abbrev ordering!");
3787 }
3788 {// 6-bit char6 VST_CODE_ENTRY strings.
3789auto Abbv = std::make_shared<BitCodeAbbrev>();
3790 Abbv->Add(BitCodeAbbrevOp(bitc::VST_CODE_ENTRY));
3791 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
3792 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
3793 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6));
3794if (Stream.EmitBlockInfoAbbrev(bitc::VALUE_SYMTAB_BLOCK_ID, Abbv) !=
3795 VST_ENTRY_6_ABBREV)
3796llvm_unreachable("Unexpected abbrev ordering!");
3797 }
3798 {// 6-bit char6 VST_CODE_BBENTRY strings.
3799auto Abbv = std::make_shared<BitCodeAbbrev>();
3800 Abbv->Add(BitCodeAbbrevOp(bitc::VST_CODE_BBENTRY));
3801 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
3802 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
3803 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6));
3804if (Stream.EmitBlockInfoAbbrev(bitc::VALUE_SYMTAB_BLOCK_ID, Abbv) !=
3805 VST_BBENTRY_6_ABBREV)
3806llvm_unreachable("Unexpected abbrev ordering!");
3807 }
3808
3809 {// SETTYPE abbrev for CONSTANTS_BLOCK.
3810auto Abbv = std::make_shared<BitCodeAbbrev>();
3811 Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_SETTYPE));
3812 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
3813 VE.computeBitsRequiredForTypeIndices()));
3814if (Stream.EmitBlockInfoAbbrev(bitc::CONSTANTS_BLOCK_ID, Abbv) !=
3815 CONSTANTS_SETTYPE_ABBREV)
3816llvm_unreachable("Unexpected abbrev ordering!");
3817 }
3818
3819 {// INTEGER abbrev for CONSTANTS_BLOCK.
3820auto Abbv = std::make_shared<BitCodeAbbrev>();
3821 Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_INTEGER));
3822 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
3823if (Stream.EmitBlockInfoAbbrev(bitc::CONSTANTS_BLOCK_ID, Abbv) !=
3824 CONSTANTS_INTEGER_ABBREV)
3825llvm_unreachable("Unexpected abbrev ordering!");
3826 }
3827
3828 {// CE_CAST abbrev for CONSTANTS_BLOCK.
3829auto Abbv = std::make_shared<BitCodeAbbrev>();
3830 Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_CE_CAST));
3831 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4));// cast opc
3832 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,// typeid
3833 VE.computeBitsRequiredForTypeIndices()));
3834 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// value id
3835
3836if (Stream.EmitBlockInfoAbbrev(bitc::CONSTANTS_BLOCK_ID, Abbv) !=
3837 CONSTANTS_CE_CAST_Abbrev)
3838llvm_unreachable("Unexpected abbrev ordering!");
3839 }
3840 {// NULL abbrev for CONSTANTS_BLOCK.
3841auto Abbv = std::make_shared<BitCodeAbbrev>();
3842 Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_NULL));
3843if (Stream.EmitBlockInfoAbbrev(bitc::CONSTANTS_BLOCK_ID, Abbv) !=
3844 CONSTANTS_NULL_Abbrev)
3845llvm_unreachable("Unexpected abbrev ordering!");
3846 }
3847
3848// FIXME: This should only use space for first class types!
3849
3850 {// INST_LOAD abbrev for FUNCTION_BLOCK.
3851auto Abbv = std::make_shared<BitCodeAbbrev>();
3852 Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_INST_LOAD));
3853 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// Ptr
3854 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,// dest ty
3855 VE.computeBitsRequiredForTypeIndices()));
3856 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4));// Align
3857 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));// volatile
3858if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
3859 FUNCTION_INST_LOAD_ABBREV)
3860llvm_unreachable("Unexpected abbrev ordering!");
3861 }
3862 {// INST_UNOP abbrev for FUNCTION_BLOCK.
3863auto Abbv = std::make_shared<BitCodeAbbrev>();
3864 Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_INST_UNOP));
3865 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// LHS
3866 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4));// opc
3867if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
3868 FUNCTION_INST_UNOP_ABBREV)
3869llvm_unreachable("Unexpected abbrev ordering!");
3870 }
3871 {// INST_UNOP_FLAGS abbrev for FUNCTION_BLOCK.
3872auto Abbv = std::make_shared<BitCodeAbbrev>();
3873 Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_INST_UNOP));
3874 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// LHS
3875 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4));// opc
3876 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8));// flags
3877if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
3878 FUNCTION_INST_UNOP_FLAGS_ABBREV)
3879llvm_unreachable("Unexpected abbrev ordering!");
3880 }
3881 {// INST_BINOP abbrev for FUNCTION_BLOCK.
3882auto Abbv = std::make_shared<BitCodeAbbrev>();
3883 Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_INST_BINOP));
3884 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// LHS
3885 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// RHS
3886 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4));// opc
3887if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
3888 FUNCTION_INST_BINOP_ABBREV)
3889llvm_unreachable("Unexpected abbrev ordering!");
3890 }
3891 {// INST_BINOP_FLAGS abbrev for FUNCTION_BLOCK.
3892auto Abbv = std::make_shared<BitCodeAbbrev>();
3893 Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_INST_BINOP));
3894 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// LHS
3895 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// RHS
3896 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4));// opc
3897 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8));// flags
3898if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
3899 FUNCTION_INST_BINOP_FLAGS_ABBREV)
3900llvm_unreachable("Unexpected abbrev ordering!");
3901 }
3902 {// INST_CAST abbrev for FUNCTION_BLOCK.
3903auto Abbv = std::make_shared<BitCodeAbbrev>();
3904 Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_INST_CAST));
3905 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// OpVal
3906 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,// dest ty
3907 VE.computeBitsRequiredForTypeIndices()));
3908 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4));// opc
3909if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
3910 FUNCTION_INST_CAST_ABBREV)
3911llvm_unreachable("Unexpected abbrev ordering!");
3912 }
3913 {// INST_CAST_FLAGS abbrev for FUNCTION_BLOCK.
3914auto Abbv = std::make_shared<BitCodeAbbrev>();
3915 Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_INST_CAST));
3916 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// OpVal
3917 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,// dest ty
3918 VE.computeBitsRequiredForTypeIndices()));
3919 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4));// opc
3920 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8));// flags
3921if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
3922 FUNCTION_INST_CAST_FLAGS_ABBREV)
3923llvm_unreachable("Unexpected abbrev ordering!");
3924 }
3925
3926 {// INST_RET abbrev for FUNCTION_BLOCK.
3927auto Abbv = std::make_shared<BitCodeAbbrev>();
3928 Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_INST_RET));
3929if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
3930 FUNCTION_INST_RET_VOID_ABBREV)
3931llvm_unreachable("Unexpected abbrev ordering!");
3932 }
3933 {// INST_RET abbrev for FUNCTION_BLOCK.
3934auto Abbv = std::make_shared<BitCodeAbbrev>();
3935 Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_INST_RET));
3936 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// ValID
3937if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
3938 FUNCTION_INST_RET_VAL_ABBREV)
3939llvm_unreachable("Unexpected abbrev ordering!");
3940 }
3941 {// INST_UNREACHABLE abbrev for FUNCTION_BLOCK.
3942auto Abbv = std::make_shared<BitCodeAbbrev>();
3943 Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_INST_UNREACHABLE));
3944if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
3945 FUNCTION_INST_UNREACHABLE_ABBREV)
3946llvm_unreachable("Unexpected abbrev ordering!");
3947 }
3948 {
3949auto Abbv = std::make_shared<BitCodeAbbrev>();
3950 Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_INST_GEP));
3951 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3));
3952 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,// dest ty
3953Log2_32_Ceil(VE.getTypes().size() + 1)));
3954 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
3955 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
3956if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
3957 FUNCTION_INST_GEP_ABBREV)
3958llvm_unreachable("Unexpected abbrev ordering!");
3959 }
3960 {
3961auto Abbv = std::make_shared<BitCodeAbbrev>();
3962 Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE));
3963 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 7));// dbgloc
3964 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 7));// var
3965 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 7));// expr
3966 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// val
3967if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
3968 FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
3969llvm_unreachable("Unexpected abbrev ordering! 1");
3970 }
3971 Stream.ExitBlock();
3972}
3973
3974/// Write the module path strings, currently only used when generating
3975/// a combined index file.
3976void IndexBitcodeWriter::writeModStrings() {
3977 Stream.EnterSubblock(bitc::MODULE_STRTAB_BLOCK_ID, 3);
3978
3979// TODO: See which abbrev sizes we actually need to emit
3980
3981// 8-bit fixed-width MST_ENTRY strings.
3982auto Abbv = std::make_shared<BitCodeAbbrev>();
3983 Abbv->Add(BitCodeAbbrevOp(bitc::MST_CODE_ENTRY));
3984 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
3985 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
3986 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8));
3987unsigned Abbrev8Bit = Stream.EmitAbbrev(std::move(Abbv));
3988
3989// 7-bit fixed width MST_ENTRY strings.
3990 Abbv = std::make_shared<BitCodeAbbrev>();
3991 Abbv->Add(BitCodeAbbrevOp(bitc::MST_CODE_ENTRY));
3992 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
3993 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
3994 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7));
3995unsigned Abbrev7Bit = Stream.EmitAbbrev(std::move(Abbv));
3996
3997// 6-bit char6 MST_ENTRY strings.
3998 Abbv = std::make_shared<BitCodeAbbrev>();
3999 Abbv->Add(BitCodeAbbrevOp(bitc::MST_CODE_ENTRY));
4000 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
4001 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
4002 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6));
4003unsigned Abbrev6Bit = Stream.EmitAbbrev(std::move(Abbv));
4004
4005// Module Hash, 160 bits SHA1. Optionally, emitted after each MST_CODE_ENTRY.
4006 Abbv = std::make_shared<BitCodeAbbrev>();
4007 Abbv->Add(BitCodeAbbrevOp(bitc::MST_CODE_HASH));
4008 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
4009 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
4010 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
4011 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
4012 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
4013unsigned AbbrevHash = Stream.EmitAbbrev(std::move(Abbv));
4014
4015SmallVector<unsigned, 64> Vals;
4016 forEachModule([&](constStringMapEntry<ModuleHash> &MPSE) {
4017StringRefKey = MPSE.getKey();
4018constauto &Hash = MPSE.getValue();
4019StringEncodingBits =getStringEncoding(Key);
4020unsigned AbbrevToUse = Abbrev8Bit;
4021if (Bits ==SE_Char6)
4022 AbbrevToUse = Abbrev6Bit;
4023elseif (Bits ==SE_Fixed7)
4024 AbbrevToUse = Abbrev7Bit;
4025
4026auto ModuleId = ModuleIdMap.size();
4027 ModuleIdMap[Key] = ModuleId;
4028 Vals.push_back(ModuleId);
4029 Vals.append(Key.begin(),Key.end());
4030
4031// Emit the finished record.
4032 Stream.EmitRecord(bitc::MST_CODE_ENTRY, Vals, AbbrevToUse);
4033
4034// Emit an optional hash for the module now
4035if (llvm::any_of(Hash, [](uint32_tH) {returnH; })) {
4036 Vals.assign(Hash.begin(), Hash.end());
4037// Emit the hash record.
4038 Stream.EmitRecord(bitc::MST_CODE_HASH, Vals, AbbrevHash);
4039 }
4040
4041 Vals.clear();
4042 });
4043 Stream.ExitBlock();
4044}
4045
4046/// Write the function type metadata related records that need to appear before
4047/// a function summary entry (whether per-module or combined).
4048template <typename Fn>
4049staticvoidwriteFunctionTypeMetadataRecords(BitstreamWriter &Stream,
4050FunctionSummary *FS,
4051 Fn GetValueID) {
4052if (!FS->type_tests().empty())
4053 Stream.EmitRecord(bitc::FS_TYPE_TESTS, FS->type_tests());
4054
4055SmallVector<uint64_t, 64>Record;
4056
4057auto WriteVFuncIdVec = [&](uint64_t Ty,
4058ArrayRef<FunctionSummary::VFuncId> VFs) {
4059if (VFs.empty())
4060return;
4061Record.clear();
4062for (auto &VF : VFs) {
4063Record.push_back(VF.GUID);
4064Record.push_back(VF.Offset);
4065 }
4066 Stream.EmitRecord(Ty,Record);
4067 };
4068
4069 WriteVFuncIdVec(bitc::FS_TYPE_TEST_ASSUME_VCALLS,
4070 FS->type_test_assume_vcalls());
4071 WriteVFuncIdVec(bitc::FS_TYPE_CHECKED_LOAD_VCALLS,
4072 FS->type_checked_load_vcalls());
4073
4074auto WriteConstVCallVec = [&](uint64_t Ty,
4075ArrayRef<FunctionSummary::ConstVCall> VCs) {
4076for (auto &VC : VCs) {
4077Record.clear();
4078Record.push_back(VC.VFunc.GUID);
4079Record.push_back(VC.VFunc.Offset);
4080llvm::append_range(Record, VC.Args);
4081 Stream.EmitRecord(Ty,Record);
4082 }
4083 };
4084
4085 WriteConstVCallVec(bitc::FS_TYPE_TEST_ASSUME_CONST_VCALL,
4086 FS->type_test_assume_const_vcalls());
4087 WriteConstVCallVec(bitc::FS_TYPE_CHECKED_LOAD_CONST_VCALL,
4088 FS->type_checked_load_const_vcalls());
4089
4090auto WriteRange = [&](ConstantRangeRange) {
4091Range =Range.sextOrTrunc(FunctionSummary::ParamAccess::RangeWidth);
4092assert(Range.getLower().getNumWords() == 1);
4093assert(Range.getUpper().getNumWords() == 1);
4094emitSignedInt64(Record, *Range.getLower().getRawData());
4095emitSignedInt64(Record, *Range.getUpper().getRawData());
4096 };
4097
4098if (!FS->paramAccesses().empty()) {
4099Record.clear();
4100for (auto &Arg : FS->paramAccesses()) {
4101size_t UndoSize =Record.size();
4102Record.push_back(Arg.ParamNo);
4103 WriteRange(Arg.Use);
4104Record.push_back(Arg.Calls.size());
4105for (auto &Call : Arg.Calls) {
4106Record.push_back(Call.ParamNo);
4107 std::optional<unsigned> ValueID = GetValueID(Call.Callee);
4108if (!ValueID) {
4109// If ValueID is unknown we can't drop just this call, we must drop
4110// entire parameter.
4111Record.resize(UndoSize);
4112break;
4113 }
4114Record.push_back(*ValueID);
4115 WriteRange(Call.Offsets);
4116 }
4117 }
4118if (!Record.empty())
4119 Stream.EmitRecord(bitc::FS_PARAM_ACCESS,Record);
4120 }
4121}
4122
4123/// Collect type IDs from type tests used by function.
4124staticvoid
4125getReferencedTypeIds(FunctionSummary *FS,
4126 std::set<GlobalValue::GUID> &ReferencedTypeIds) {
4127if (!FS->type_tests().empty())
4128for (auto &TT : FS->type_tests())
4129 ReferencedTypeIds.insert(TT);
4130
4131auto GetReferencedTypesFromVFuncIdVec =
4132 [&](ArrayRef<FunctionSummary::VFuncId> VFs) {
4133for (auto &VF : VFs)
4134 ReferencedTypeIds.insert(VF.GUID);
4135 };
4136
4137 GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls());
4138 GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls());
4139
4140auto GetReferencedTypesFromConstVCallVec =
4141 [&](ArrayRef<FunctionSummary::ConstVCall> VCs) {
4142for (auto &VC : VCs)
4143 ReferencedTypeIds.insert(VC.VFunc.GUID);
4144 };
4145
4146 GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls());
4147 GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls());
4148}
4149
4150staticvoidwriteWholeProgramDevirtResolutionByArg(
4151SmallVector<uint64_t, 64> &NameVals,const std::vector<uint64_t> &args,
4152constWholeProgramDevirtResolution::ByArg &ByArg) {
4153 NameVals.push_back(args.size());
4154llvm::append_range(NameVals,args);
4155
4156 NameVals.push_back(ByArg.TheKind);
4157 NameVals.push_back(ByArg.Info);
4158 NameVals.push_back(ByArg.Byte);
4159 NameVals.push_back(ByArg.Bit);
4160}
4161
4162staticvoidwriteWholeProgramDevirtResolution(
4163SmallVector<uint64_t, 64> &NameVals,StringTableBuilder &StrtabBuilder,
4164uint64_t Id,constWholeProgramDevirtResolution &Wpd) {
4165 NameVals.push_back(Id);
4166
4167 NameVals.push_back(Wpd.TheKind);
4168 NameVals.push_back(StrtabBuilder.add(Wpd.SingleImplName));
4169 NameVals.push_back(Wpd.SingleImplName.size());
4170
4171 NameVals.push_back(Wpd.ResByArg.size());
4172for (auto &A : Wpd.ResByArg)
4173writeWholeProgramDevirtResolutionByArg(NameVals,A.first,A.second);
4174}
4175
4176staticvoidwriteTypeIdSummaryRecord(SmallVector<uint64_t, 64> &NameVals,
4177StringTableBuilder &StrtabBuilder,
4178StringRef Id,
4179constTypeIdSummary &Summary) {
4180 NameVals.push_back(StrtabBuilder.add(Id));
4181 NameVals.push_back(Id.size());
4182
4183 NameVals.push_back(Summary.TTRes.TheKind);
4184 NameVals.push_back(Summary.TTRes.SizeM1BitWidth);
4185 NameVals.push_back(Summary.TTRes.AlignLog2);
4186 NameVals.push_back(Summary.TTRes.SizeM1);
4187 NameVals.push_back(Summary.TTRes.BitMask);
4188 NameVals.push_back(Summary.TTRes.InlineBits);
4189
4190for (auto &W : Summary.WPDRes)
4191writeWholeProgramDevirtResolution(NameVals, StrtabBuilder, W.first,
4192 W.second);
4193}
4194
4195staticvoidwriteTypeIdCompatibleVtableSummaryRecord(
4196SmallVector<uint64_t, 64> &NameVals,StringTableBuilder &StrtabBuilder,
4197StringRef Id,constTypeIdCompatibleVtableInfo &Summary,
4198ValueEnumerator &VE) {
4199 NameVals.push_back(StrtabBuilder.add(Id));
4200 NameVals.push_back(Id.size());
4201
4202for (auto &P : Summary) {
4203 NameVals.push_back(P.AddressPointOffset);
4204 NameVals.push_back(VE.getValueID(P.VTableVI.getValue()));
4205 }
4206}
4207
4208// Adds the allocation contexts to the CallStacks map. We simply use the
4209// size at the time the context was added as the CallStackId. This works because
4210// when we look up the call stacks later on we process the function summaries
4211// and their allocation records in the same exact order.
4212staticvoidcollectMemProfCallStacks(
4213FunctionSummary *FS, std::function<LinearFrameId(unsigned)> GetStackIndex,
4214MapVector<CallStackId,llvm::SmallVector<LinearFrameId>> &CallStacks) {
4215// The interfaces in ProfileData/MemProf.h use a type alias for a stack frame
4216// id offset into the index of the full stack frames. The ModuleSummaryIndex
4217// currently uses unsigned. Make sure these stay in sync.
4218static_assert(std::is_same_v<LinearFrameId, unsigned>);
4219for (auto &AI : FS->allocs()) {
4220for (auto &MIB : AI.MIBs) {
4221SmallVector<unsigned> StackIdIndices;
4222 StackIdIndices.reserve(MIB.StackIdIndices.size());
4223for (auto Id : MIB.StackIdIndices)
4224 StackIdIndices.push_back(GetStackIndex(Id));
4225// The CallStackId is the size at the time this context was inserted.
4226 CallStacks.insert({CallStacks.size(), StackIdIndices});
4227 }
4228 }
4229}
4230
4231// Build the radix tree from the accumulated CallStacks, write out the resulting
4232// linearized radix tree array, and return the map of call stack positions into
4233// this array for use when writing the allocation records. The returned map is
4234// indexed by a CallStackId which in this case is implicitly determined by the
4235// order of function summaries and their allocation infos being written.
4236staticDenseMap<CallStackId, LinearCallStackId>writeMemoryProfileRadixTree(
4237MapVector<CallStackId,llvm::SmallVector<LinearFrameId>> &&CallStacks,
4238BitstreamWriter &Stream,unsigned RadixAbbrev) {
4239assert(!CallStacks.empty());
4240DenseMap<unsigned, FrameStat> FrameHistogram =
4241computeFrameHistogram<LinearFrameId>(CallStacks);
4242CallStackRadixTreeBuilder<LinearFrameId> Builder;
4243// We don't need a MemProfFrameIndexes map as we have already converted the
4244// full stack id hash to a linear offset into the StackIds array.
4245 Builder.build(std::move(CallStacks),/*MemProfFrameIndexes=*/nullptr,
4246 FrameHistogram);
4247 Stream.EmitRecord(bitc::FS_CONTEXT_RADIX_TREE_ARRAY, Builder.getRadixArray(),
4248 RadixAbbrev);
4249return Builder.takeCallStackPos();
4250}
4251
4252staticvoidwriteFunctionHeapProfileRecords(
4253BitstreamWriter &Stream,FunctionSummary *FS,unsigned CallsiteAbbrev,
4254unsigned AllocAbbrev,unsigned ContextIdAbbvId,bool PerModule,
4255 std::function<unsigned(constValueInfo &VI)> GetValueID,
4256 std::function<unsigned(unsigned)> GetStackIndex,
4257bool WriteContextSizeInfoIndex,
4258DenseMap<CallStackId, LinearCallStackId> &CallStackPos,
4259CallStackId &CallStackCount) {
4260SmallVector<uint64_t>Record;
4261
4262for (auto &CI : FS->callsites()) {
4263Record.clear();
4264// Per module callsite clones should always have a single entry of
4265// value 0.
4266assert(!PerModule || (CI.Clones.size() == 1 && CI.Clones[0] == 0));
4267Record.push_back(GetValueID(CI.Callee));
4268if (!PerModule) {
4269Record.push_back(CI.StackIdIndices.size());
4270Record.push_back(CI.Clones.size());
4271 }
4272for (auto Id : CI.StackIdIndices)
4273Record.push_back(GetStackIndex(Id));
4274if (!PerModule) {
4275for (auto V : CI.Clones)
4276Record.push_back(V);
4277 }
4278 Stream.EmitRecord(PerModule ?bitc::FS_PERMODULE_CALLSITE_INFO
4279 :bitc::FS_COMBINED_CALLSITE_INFO,
4280Record, CallsiteAbbrev);
4281 }
4282
4283for (auto &AI : FS->allocs()) {
4284Record.clear();
4285// Per module alloc versions should always have a single entry of
4286// value 0.
4287assert(!PerModule || (AI.Versions.size() == 1 && AI.Versions[0] == 0));
4288Record.push_back(AI.MIBs.size());
4289if (!PerModule)
4290Record.push_back(AI.Versions.size());
4291for (auto &MIB : AI.MIBs) {
4292Record.push_back((uint8_t)MIB.AllocType);
4293// Record the index into the radix tree array for this context.
4294assert(CallStackCount <= CallStackPos.size());
4295Record.push_back(CallStackPos[CallStackCount++]);
4296 }
4297if (!PerModule) {
4298for (auto V : AI.Versions)
4299Record.push_back(V);
4300 }
4301assert(AI.ContextSizeInfos.empty() ||
4302 AI.ContextSizeInfos.size() == AI.MIBs.size());
4303// Optionally emit the context size information if it exists.
4304if (WriteContextSizeInfoIndex && !AI.ContextSizeInfos.empty()) {
4305// The abbreviation id for the context ids record should have been created
4306// if we are emitting the per-module index, which is where we write this
4307// info.
4308assert(ContextIdAbbvId);
4309SmallVector<uint32_t> ContextIds;
4310// At least one context id per ContextSizeInfos entry (MIB), broken into 2
4311// halves.
4312 ContextIds.reserve(AI.ContextSizeInfos.size() * 2);
4313for (auto &Infos : AI.ContextSizeInfos) {
4314Record.push_back(Infos.size());
4315for (auto [FullStackId, TotalSize] : Infos) {
4316// The context ids are emitted separately as a fixed width array,
4317// which is more efficient than a VBR given that these hashes are
4318// typically close to 64-bits. The max fixed width entry is 32 bits so
4319// it is split into 2.
4320 ContextIds.push_back(static_cast<uint32_t>(FullStackId >> 32));
4321 ContextIds.push_back(static_cast<uint32_t>(FullStackId));
4322Record.push_back(TotalSize);
4323 }
4324 }
4325// The context ids are expected by the reader to immediately precede the
4326// associated alloc info record.
4327 Stream.EmitRecord(bitc::FS_ALLOC_CONTEXT_IDS, ContextIds,
4328 ContextIdAbbvId);
4329 }
4330 Stream.EmitRecord(PerModule ?bitc::FS_PERMODULE_ALLOC_INFO
4331 :bitc::FS_COMBINED_ALLOC_INFO,
4332Record, AllocAbbrev);
4333 }
4334}
4335
4336// Helper to emit a single function summary record.
4337void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
4338SmallVector<uint64_t, 64> &NameVals,GlobalValueSummary *Summary,
4339unsigned ValueID,unsigned FSCallsRelBFAbbrev,
4340unsigned FSCallsProfileAbbrev,unsigned CallsiteAbbrev,
4341unsigned AllocAbbrev,unsigned ContextIdAbbvId,constFunction &F,
4342DenseMap<CallStackId, LinearCallStackId> &CallStackPos,
4343CallStackId &CallStackCount) {
4344 NameVals.push_back(ValueID);
4345
4346FunctionSummary *FS = cast<FunctionSummary>(Summary);
4347
4348writeFunctionTypeMetadataRecords(
4349 Stream, FS, [&](constValueInfo &VI) -> std::optional<unsigned> {
4350return {VE.getValueID(VI.getValue())};
4351 });
4352
4353writeFunctionHeapProfileRecords(
4354 Stream, FS, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId,
4355/*PerModule*/true,
4356/*GetValueId*/ [&](constValueInfo &VI) {return getValueId(VI); },
4357/*GetStackIndex*/ [&](unsignedI) {returnI; },
4358/*WriteContextSizeInfoIndex*/true, CallStackPos, CallStackCount);
4359
4360auto SpecialRefCnts =FS->specialRefCounts();
4361 NameVals.push_back(getEncodedGVSummaryFlags(FS->flags()));
4362 NameVals.push_back(FS->instCount());
4363 NameVals.push_back(getEncodedFFlags(FS->fflags()));
4364 NameVals.push_back(FS->refs().size());
4365 NameVals.push_back(SpecialRefCnts.first);// rorefcnt
4366 NameVals.push_back(SpecialRefCnts.second);// worefcnt
4367
4368for (auto &RI :FS->refs())
4369 NameVals.push_back(getValueId(RI));
4370
4371constbool UseRelBFRecord =
4372WriteRelBFToSummary && !F.hasProfileData() &&
4373ForceSummaryEdgesCold ==FunctionSummary::FSHT_None;
4374for (auto &ECI :FS->calls()) {
4375 NameVals.push_back(getValueId(ECI.first));
4376if (UseRelBFRecord)
4377 NameVals.push_back(getEncodedRelBFCallEdgeInfo(ECI.second));
4378else
4379 NameVals.push_back(getEncodedHotnessCallEdgeInfo(ECI.second));
4380 }
4381
4382unsigned FSAbbrev =
4383 (UseRelBFRecord ? FSCallsRelBFAbbrev : FSCallsProfileAbbrev);
4384unsignedCode =
4385 (UseRelBFRecord ?bitc::FS_PERMODULE_RELBF :bitc::FS_PERMODULE_PROFILE);
4386
4387// Emit the finished record.
4388 Stream.EmitRecord(Code, NameVals, FSAbbrev);
4389 NameVals.clear();
4390}
4391
4392// Collect the global value references in the given variable's initializer,
4393// and emit them in a summary record.
4394void ModuleBitcodeWriterBase::writeModuleLevelReferences(
4395constGlobalVariable &V,SmallVector<uint64_t, 64> &NameVals,
4396unsigned FSModRefsAbbrev,unsigned FSModVTableRefsAbbrev) {
4397autoVI =Index->getValueInfo(V.getGUID());
4398if (!VI ||VI.getSummaryList().empty()) {
4399// Only declarations should not have a summary (a declaration might however
4400// have a summary if the def was in module level asm).
4401assert(V.isDeclaration());
4402return;
4403 }
4404auto *Summary =VI.getSummaryList()[0].get();
4405 NameVals.push_back(VE.getValueID(&V));
4406GlobalVarSummary *VS = cast<GlobalVarSummary>(Summary);
4407 NameVals.push_back(getEncodedGVSummaryFlags(VS->flags()));
4408 NameVals.push_back(getEncodedGVarFlags(VS->varflags()));
4409
4410auto VTableFuncs =VS->vTableFuncs();
4411if (!VTableFuncs.empty())
4412 NameVals.push_back(VS->refs().size());
4413
4414unsigned SizeBeforeRefs = NameVals.size();
4415for (auto &RI :VS->refs())
4416 NameVals.push_back(VE.getValueID(RI.getValue()));
4417// Sort the refs for determinism output, the vector returned by FS->refs() has
4418// been initialized from a DenseSet.
4419llvm::sort(drop_begin(NameVals, SizeBeforeRefs));
4420
4421if (VTableFuncs.empty())
4422 Stream.EmitRecord(bitc::FS_PERMODULE_GLOBALVAR_INIT_REFS, NameVals,
4423 FSModRefsAbbrev);
4424else {
4425// VTableFuncs pairs should already be sorted by offset.
4426for (auto &P : VTableFuncs) {
4427 NameVals.push_back(VE.getValueID(P.FuncVI.getValue()));
4428 NameVals.push_back(P.VTableOffset);
4429 }
4430
4431 Stream.EmitRecord(bitc::FS_PERMODULE_VTABLE_GLOBALVAR_INIT_REFS, NameVals,
4432 FSModVTableRefsAbbrev);
4433 }
4434 NameVals.clear();
4435}
4436
4437/// Emit the per-module summary section alongside the rest of
4438/// the module's bitcode.
4439void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
4440// By default we compile with ThinLTO if the module has a summary, but the
4441// client can request full LTO with a module flag.
4442bool IsThinLTO =true;
4443if (auto *MD =
4444 mdconst::extract_or_null<ConstantInt>(M.getModuleFlag("ThinLTO")))
4445 IsThinLTO = MD->getZExtValue();
4446 Stream.EnterSubblock(IsThinLTO ?bitc::GLOBALVAL_SUMMARY_BLOCK_ID
4447 :bitc::FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID,
4448 4);
4449
4450 Stream.EmitRecord(
4451bitc::FS_VERSION,
4452ArrayRef<uint64_t>{ModuleSummaryIndex::BitcodeSummaryVersion});
4453
4454// Write the index flags.
4455uint64_tFlags = 0;
4456// Bits 1-3 are set only in the combined index, skip them.
4457if (Index->enableSplitLTOUnit())
4458Flags |= 0x8;
4459if (Index->hasUnifiedLTO())
4460Flags |= 0x200;
4461
4462 Stream.EmitRecord(bitc::FS_FLAGS,ArrayRef<uint64_t>{Flags});
4463
4464if (Index->begin() ==Index->end()) {
4465 Stream.ExitBlock();
4466return;
4467 }
4468
4469auto Abbv = std::make_shared<BitCodeAbbrev>();
4470 Abbv->Add(BitCodeAbbrevOp(bitc::FS_VALUE_GUID));
4471 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
4472// GUIDS often use up most of 64-bits, so encode as two Fixed 32.
4473 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
4474 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
4475unsigned ValueGuidAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4476
4477for (constauto &GVI : valueIds()) {
4478 Stream.EmitRecord(bitc::FS_VALUE_GUID,
4479ArrayRef<uint32_t>{GVI.second,
4480static_cast<uint32_t>(GVI.first >> 32),
4481static_cast<uint32_t>(GVI.first)},
4482 ValueGuidAbbrev);
4483 }
4484
4485if (!Index->stackIds().empty()) {
4486auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4487 StackIdAbbv->Add(BitCodeAbbrevOp(bitc::FS_STACK_IDS));
4488// numids x stackid
4489 StackIdAbbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
4490// The stack ids are hashes that are close to 64 bits in size, so emitting
4491// as a pair of 32-bit fixed-width values is more efficient than a VBR.
4492 StackIdAbbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
4493unsigned StackIdAbbvId = Stream.EmitAbbrev(std::move(StackIdAbbv));
4494SmallVector<uint32_t> Vals;
4495 Vals.reserve(Index->stackIds().size() * 2);
4496for (auto Id :Index->stackIds()) {
4497 Vals.push_back(static_cast<uint32_t>(Id >> 32));
4498 Vals.push_back(static_cast<uint32_t>(Id));
4499 }
4500 Stream.EmitRecord(bitc::FS_STACK_IDS, Vals, StackIdAbbvId);
4501 }
4502
4503// n x context id
4504auto ContextIdAbbv = std::make_shared<BitCodeAbbrev>();
4505 ContextIdAbbv->Add(BitCodeAbbrevOp(bitc::FS_ALLOC_CONTEXT_IDS));
4506 ContextIdAbbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
4507// The context ids are hashes that are close to 64 bits in size, so emitting
4508// as a pair of 32-bit fixed-width values is more efficient than a VBR.
4509 ContextIdAbbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
4510unsigned ContextIdAbbvId = Stream.EmitAbbrev(std::move(ContextIdAbbv));
4511
4512// Abbrev for FS_PERMODULE_PROFILE.
4513 Abbv = std::make_shared<BitCodeAbbrev>();
4514 Abbv->Add(BitCodeAbbrevOp(bitc::FS_PERMODULE_PROFILE));
4515 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// valueid
4516 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// flags
4517 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// instcount
4518 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4));// fflags
4519 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4));// numrefs
4520 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4));// rorefcnt
4521 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4));// worefcnt
4522// numrefs x valueid, n x (valueid, hotness+tailcall flags)
4523 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
4524 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
4525unsigned FSCallsProfileAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4526
4527// Abbrev for FS_PERMODULE_RELBF.
4528 Abbv = std::make_shared<BitCodeAbbrev>();
4529 Abbv->Add(BitCodeAbbrevOp(bitc::FS_PERMODULE_RELBF));
4530 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// valueid
4531 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// flags
4532 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// instcount
4533 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4));// fflags
4534 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4));// numrefs
4535 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4));// rorefcnt
4536 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4));// worefcnt
4537// numrefs x valueid, n x (valueid, rel_block_freq+tailcall])
4538 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
4539 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
4540unsigned FSCallsRelBFAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4541
4542// Abbrev for FS_PERMODULE_GLOBALVAR_INIT_REFS.
4543 Abbv = std::make_shared<BitCodeAbbrev>();
4544 Abbv->Add(BitCodeAbbrevOp(bitc::FS_PERMODULE_GLOBALVAR_INIT_REFS));
4545 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// valueid
4546 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// flags
4547 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));// valueids
4548 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
4549unsigned FSModRefsAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4550
4551// Abbrev for FS_PERMODULE_VTABLE_GLOBALVAR_INIT_REFS.
4552 Abbv = std::make_shared<BitCodeAbbrev>();
4553 Abbv->Add(BitCodeAbbrevOp(bitc::FS_PERMODULE_VTABLE_GLOBALVAR_INIT_REFS));
4554 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// valueid
4555 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// flags
4556 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4));// numrefs
4557// numrefs x valueid, n x (valueid , offset)
4558 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
4559 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
4560unsigned FSModVTableRefsAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4561
4562// Abbrev for FS_ALIAS.
4563 Abbv = std::make_shared<BitCodeAbbrev>();
4564 Abbv->Add(BitCodeAbbrevOp(bitc::FS_ALIAS));
4565 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// valueid
4566 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// flags
4567 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// valueid
4568unsigned FSAliasAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4569
4570// Abbrev for FS_TYPE_ID_METADATA
4571 Abbv = std::make_shared<BitCodeAbbrev>();
4572 Abbv->Add(BitCodeAbbrevOp(bitc::FS_TYPE_ID_METADATA));
4573 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// typeid strtab index
4574 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// typeid length
4575// n x (valueid , offset)
4576 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
4577 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
4578unsigned TypeIdCompatibleVtableAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4579
4580 Abbv = std::make_shared<BitCodeAbbrev>();
4581 Abbv->Add(BitCodeAbbrevOp(bitc::FS_PERMODULE_CALLSITE_INFO));
4582 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// valueid
4583// n x stackidindex
4584 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
4585 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
4586unsigned CallsiteAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4587
4588 Abbv = std::make_shared<BitCodeAbbrev>();
4589 Abbv->Add(BitCodeAbbrevOp(bitc::FS_PERMODULE_ALLOC_INFO));
4590 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4));// nummib
4591// n x (alloc type, context radix tree index)
4592// optional: nummib x (numcontext x total size)
4593 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
4594 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
4595unsigned AllocAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4596
4597 Abbv = std::make_shared<BitCodeAbbrev>();
4598 Abbv->Add(BitCodeAbbrevOp(bitc::FS_CONTEXT_RADIX_TREE_ARRAY));
4599// n x entry
4600 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
4601 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
4602unsigned RadixAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4603
4604// First walk through all the functions and collect the allocation contexts in
4605// their associated summaries, for use in constructing a radix tree of
4606// contexts. Note that we need to do this in the same order as the functions
4607// are processed further below since the call stack positions in the resulting
4608// radix tree array are identified based on this order.
4609MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks;
4610for (constFunction &F : M) {
4611// Summary emission does not support anonymous functions, they have to be
4612// renamed using the anonymous function renaming pass.
4613if (!F.hasName())
4614report_fatal_error("Unexpected anonymous function when writing summary");
4615
4616ValueInfoVI =Index->getValueInfo(F.getGUID());
4617if (!VI ||VI.getSummaryList().empty()) {
4618// Only declarations should not have a summary (a declaration might
4619// however have a summary if the def was in module level asm).
4620assert(F.isDeclaration());
4621continue;
4622 }
4623auto *Summary =VI.getSummaryList()[0].get();
4624FunctionSummary *FS = cast<FunctionSummary>(Summary);
4625collectMemProfCallStacks(
4626 FS,/*GetStackIndex*/ [](unsignedI) {returnI; }, CallStacks);
4627 }
4628// Finalize the radix tree, write it out, and get the map of positions in the
4629// linearized tree array.
4630DenseMap<CallStackId, LinearCallStackId> CallStackPos;
4631if (!CallStacks.empty()) {
4632 CallStackPos =
4633writeMemoryProfileRadixTree(std::move(CallStacks), Stream, RadixAbbrev);
4634 }
4635
4636// Keep track of the current index into the CallStackPos map.
4637CallStackId CallStackCount = 0;
4638
4639SmallVector<uint64_t, 64> NameVals;
4640// Iterate over the list of functions instead of the Index to
4641// ensure the ordering is stable.
4642for (constFunction &F : M) {
4643// Summary emission does not support anonymous functions, they have to
4644// renamed using the anonymous function renaming pass.
4645if (!F.hasName())
4646report_fatal_error("Unexpected anonymous function when writing summary");
4647
4648ValueInfoVI =Index->getValueInfo(F.getGUID());
4649if (!VI ||VI.getSummaryList().empty()) {
4650// Only declarations should not have a summary (a declaration might
4651// however have a summary if the def was in module level asm).
4652assert(F.isDeclaration());
4653continue;
4654 }
4655auto *Summary =VI.getSummaryList()[0].get();
4656 writePerModuleFunctionSummaryRecord(
4657 NameVals, Summary, VE.getValueID(&F), FSCallsRelBFAbbrev,
4658 FSCallsProfileAbbrev, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId,F,
4659 CallStackPos, CallStackCount);
4660 }
4661
4662// Capture references from GlobalVariable initializers, which are outside
4663// of a function scope.
4664for (constGlobalVariable &G :M.globals())
4665 writeModuleLevelReferences(G, NameVals, FSModRefsAbbrev,
4666 FSModVTableRefsAbbrev);
4667
4668for (constGlobalAlias &A :M.aliases()) {
4669auto *Aliasee =A.getAliaseeObject();
4670// Skip ifunc and nameless functions which don't have an entry in the
4671// summary.
4672if (!Aliasee->hasName() || isa<GlobalIFunc>(Aliasee))
4673continue;
4674auto AliasId = VE.getValueID(&A);
4675auto AliaseeId = VE.getValueID(Aliasee);
4676 NameVals.push_back(AliasId);
4677auto *Summary =Index->getGlobalValueSummary(A);
4678AliasSummary *AS = cast<AliasSummary>(Summary);
4679 NameVals.push_back(getEncodedGVSummaryFlags(AS->flags()));
4680 NameVals.push_back(AliaseeId);
4681 Stream.EmitRecord(bitc::FS_ALIAS, NameVals, FSAliasAbbrev);
4682 NameVals.clear();
4683 }
4684
4685for (auto &S :Index->typeIdCompatibleVtableMap()) {
4686writeTypeIdCompatibleVtableSummaryRecord(NameVals, StrtabBuilder, S.first,
4687 S.second, VE);
4688 Stream.EmitRecord(bitc::FS_TYPE_ID_METADATA, NameVals,
4689 TypeIdCompatibleVtableAbbrev);
4690 NameVals.clear();
4691 }
4692
4693if (Index->getBlockCount())
4694 Stream.EmitRecord(bitc::FS_BLOCK_COUNT,
4695ArrayRef<uint64_t>{Index->getBlockCount()});
4696
4697 Stream.ExitBlock();
4698}
4699
4700/// Emit the combined summary section into the combined index file.
4701void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4702 Stream.EnterSubblock(bitc::GLOBALVAL_SUMMARY_BLOCK_ID, 4);
4703 Stream.EmitRecord(
4704bitc::FS_VERSION,
4705ArrayRef<uint64_t>{ModuleSummaryIndex::BitcodeSummaryVersion});
4706
4707// Write the index flags.
4708 Stream.EmitRecord(bitc::FS_FLAGS,ArrayRef<uint64_t>{Index.getFlags()});
4709
4710auto Abbv = std::make_shared<BitCodeAbbrev>();
4711 Abbv->Add(BitCodeAbbrevOp(bitc::FS_VALUE_GUID));
4712 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
4713// GUIDS often use up most of 64-bits, so encode as two Fixed 32.
4714 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
4715 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
4716unsigned ValueGuidAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4717
4718for (constauto &GVI : valueIds()) {
4719 Stream.EmitRecord(bitc::FS_VALUE_GUID,
4720ArrayRef<uint32_t>{GVI.second,
4721static_cast<uint32_t>(GVI.first >> 32),
4722static_cast<uint32_t>(GVI.first)},
4723 ValueGuidAbbrev);
4724 }
4725
4726// Write the stack ids used by this index, which will be a subset of those in
4727// the full index in the case of distributed indexes.
4728if (!StackIds.empty()) {
4729auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4730 StackIdAbbv->Add(BitCodeAbbrevOp(bitc::FS_STACK_IDS));
4731// numids x stackid
4732 StackIdAbbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
4733// The stack ids are hashes that are close to 64 bits in size, so emitting
4734// as a pair of 32-bit fixed-width values is more efficient than a VBR.
4735 StackIdAbbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
4736unsigned StackIdAbbvId = Stream.EmitAbbrev(std::move(StackIdAbbv));
4737SmallVector<uint32_t> Vals;
4738 Vals.reserve(StackIds.size() * 2);
4739for (auto Id : StackIds) {
4740 Vals.push_back(static_cast<uint32_t>(Id >> 32));
4741 Vals.push_back(static_cast<uint32_t>(Id));
4742 }
4743 Stream.EmitRecord(bitc::FS_STACK_IDS, Vals, StackIdAbbvId);
4744 }
4745
4746// Abbrev for FS_COMBINED_PROFILE.
4747 Abbv = std::make_shared<BitCodeAbbrev>();
4748 Abbv->Add(BitCodeAbbrevOp(bitc::FS_COMBINED_PROFILE));
4749 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// valueid
4750 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// modid
4751 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// flags
4752 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// instcount
4753 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4));// fflags
4754 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// entrycount
4755 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4));// numrefs
4756 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4));// rorefcnt
4757 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4));// worefcnt
4758// numrefs x valueid, n x (valueid, hotness+tailcall flags)
4759 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
4760 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
4761unsigned FSCallsProfileAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4762
4763// Abbrev for FS_COMBINED_GLOBALVAR_INIT_REFS.
4764 Abbv = std::make_shared<BitCodeAbbrev>();
4765 Abbv->Add(BitCodeAbbrevOp(bitc::FS_COMBINED_GLOBALVAR_INIT_REFS));
4766 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// valueid
4767 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// modid
4768 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// flags
4769 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));// valueids
4770 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
4771unsigned FSModRefsAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4772
4773// Abbrev for FS_COMBINED_ALIAS.
4774 Abbv = std::make_shared<BitCodeAbbrev>();
4775 Abbv->Add(BitCodeAbbrevOp(bitc::FS_COMBINED_ALIAS));
4776 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// valueid
4777 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// modid
4778 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// flags
4779 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// valueid
4780unsigned FSAliasAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4781
4782 Abbv = std::make_shared<BitCodeAbbrev>();
4783 Abbv->Add(BitCodeAbbrevOp(bitc::FS_COMBINED_CALLSITE_INFO));
4784 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));// valueid
4785 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4));// numstackindices
4786 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4));// numver
4787// numstackindices x stackidindex, numver x version
4788 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
4789 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
4790unsigned CallsiteAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4791
4792 Abbv = std::make_shared<BitCodeAbbrev>();
4793 Abbv->Add(BitCodeAbbrevOp(bitc::FS_COMBINED_ALLOC_INFO));
4794 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4));// nummib
4795 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4));// numver
4796// nummib x (alloc type, context radix tree index),
4797// numver x version
4798// optional: nummib x total size
4799 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
4800 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
4801unsigned AllocAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4802
4803 Abbv = std::make_shared<BitCodeAbbrev>();
4804 Abbv->Add(BitCodeAbbrevOp(bitc::FS_CONTEXT_RADIX_TREE_ARRAY));
4805// n x entry
4806 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
4807 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
4808unsigned RadixAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4809
4810auto shouldImportValueAsDecl = [&](GlobalValueSummary *GVS) ->bool {
4811if (DecSummaries ==nullptr)
4812returnfalse;
4813return DecSummaries->count(GVS);
4814 };
4815
4816// The aliases are emitted as a post-pass, and will point to the value
4817// id of the aliasee. Save them in a vector for post-processing.
4818SmallVector<AliasSummary *, 64> Aliases;
4819
4820// Save the value id for each summary for alias emission.
4821DenseMap<const GlobalValueSummary *, unsigned> SummaryToValueIdMap;
4822
4823SmallVector<uint64_t, 64> NameVals;
4824
4825// Set that will be populated during call to writeFunctionTypeMetadataRecords
4826// with the type ids referenced by this index file.
4827 std::set<GlobalValue::GUID> ReferencedTypeIds;
4828
4829// For local linkage, we also emit the original name separately
4830// immediately after the record.
4831auto MaybeEmitOriginalName = [&](GlobalValueSummary &S) {
4832// We don't need to emit the original name if we are writing the index for
4833// distributed backends (in which case ModuleToSummariesForIndex is
4834// non-null). The original name is only needed during the thin link, since
4835// for SamplePGO the indirect call targets for local functions have
4836// have the original name annotated in profile.
4837// Continue to emit it when writing out the entire combined index, which is
4838// used in testing the thin link via llvm-lto.
4839if (ModuleToSummariesForIndex || !GlobalValue::isLocalLinkage(S.linkage()))
4840return;
4841 NameVals.push_back(S.getOriginalName());
4842 Stream.EmitRecord(bitc::FS_COMBINED_ORIGINAL_NAME, NameVals);
4843 NameVals.clear();
4844 };
4845
4846// First walk through all the functions and collect the allocation contexts in
4847// their associated summaries, for use in constructing a radix tree of
4848// contexts. Note that we need to do this in the same order as the functions
4849// are processed further below since the call stack positions in the resulting
4850// radix tree array are identified based on this order.
4851MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks;
4852 forEachSummary([&](GVInfoI,bool IsAliasee) {
4853// Don't collect this when invoked for an aliasee, as it is not needed for
4854// the alias summary. If the aliasee is to be imported, we will invoke this
4855// separately with IsAliasee=false.
4856if (IsAliasee)
4857return;
4858GlobalValueSummary *S =I.second;
4859assert(S);
4860auto *FS = dyn_cast<FunctionSummary>(S);
4861if (!FS)
4862return;
4863collectMemProfCallStacks(
4864 FS,
4865/*GetStackIndex*/
4866 [&](unsignedI) {
4867// Get the corresponding index into the list of StackIds actually
4868// being written for this combined index (which may be a subset in
4869// the case of distributed indexes).
4870assert(StackIdIndicesToIndex.contains(I));
4871return StackIdIndicesToIndex[I];
4872 },
4873 CallStacks);
4874 });
4875// Finalize the radix tree, write it out, and get the map of positions in the
4876// linearized tree array.
4877DenseMap<CallStackId, LinearCallStackId> CallStackPos;
4878if (!CallStacks.empty()) {
4879 CallStackPos =
4880writeMemoryProfileRadixTree(std::move(CallStacks), Stream, RadixAbbrev);
4881 }
4882
4883// Keep track of the current index into the CallStackPos map.
4884CallStackId CallStackCount = 0;
4885
4886DenseSet<GlobalValue::GUID> DefOrUseGUIDs;
4887 forEachSummary([&](GVInfoI,bool IsAliasee) {
4888GlobalValueSummary *S =I.second;
4889assert(S);
4890 DefOrUseGUIDs.insert(I.first);
4891for (constValueInfo &VI : S->refs())
4892 DefOrUseGUIDs.insert(VI.getGUID());
4893
4894auto ValueId = getValueId(I.first);
4895assert(ValueId);
4896 SummaryToValueIdMap[S] = *ValueId;
4897
4898// If this is invoked for an aliasee, we want to record the above
4899// mapping, but then not emit a summary entry (if the aliasee is
4900// to be imported, we will invoke this separately with IsAliasee=false).
4901if (IsAliasee)
4902return;
4903
4904if (auto *AS = dyn_cast<AliasSummary>(S)) {
4905// Will process aliases as a post-pass because the reader wants all
4906// global to be loaded first.
4907 Aliases.push_back(AS);
4908return;
4909 }
4910
4911if (auto *VS = dyn_cast<GlobalVarSummary>(S)) {
4912 NameVals.push_back(*ValueId);
4913assert(ModuleIdMap.count(VS->modulePath()));
4914 NameVals.push_back(ModuleIdMap[VS->modulePath()]);
4915 NameVals.push_back(
4916getEncodedGVSummaryFlags(VS->flags(), shouldImportValueAsDecl(VS)));
4917 NameVals.push_back(getEncodedGVarFlags(VS->varflags()));
4918for (auto &RI :VS->refs()) {
4919auto RefValueId = getValueId(RI.getGUID());
4920if (!RefValueId)
4921continue;
4922 NameVals.push_back(*RefValueId);
4923 }
4924
4925// Emit the finished record.
4926 Stream.EmitRecord(bitc::FS_COMBINED_GLOBALVAR_INIT_REFS, NameVals,
4927 FSModRefsAbbrev);
4928 NameVals.clear();
4929 MaybeEmitOriginalName(*S);
4930return;
4931 }
4932
4933auto GetValueId = [&](constValueInfo &VI) -> std::optional<unsigned> {
4934if (!VI)
4935return std::nullopt;
4936return getValueId(VI.getGUID());
4937 };
4938
4939auto *FS = cast<FunctionSummary>(S);
4940writeFunctionTypeMetadataRecords(Stream, FS, GetValueId);
4941getReferencedTypeIds(FS, ReferencedTypeIds);
4942
4943writeFunctionHeapProfileRecords(
4944 Stream, FS, CallsiteAbbrev, AllocAbbrev,/*ContextIdAbbvId*/ 0,
4945/*PerModule*/false,
4946/*GetValueId*/
4947 [&](constValueInfo &VI) ->unsigned {
4948 std::optional<unsigned> ValueID = GetValueId(VI);
4949// This can happen in shared index files for distributed ThinLTO if
4950// the callee function summary is not included. Record 0 which we
4951// will have to deal with conservatively when doing any kind of
4952// validation in the ThinLTO backends.
4953if (!ValueID)
4954return 0;
4955return *ValueID;
4956 },
4957/*GetStackIndex*/
4958 [&](unsignedI) {
4959// Get the corresponding index into the list of StackIds actually
4960// being written for this combined index (which may be a subset in
4961// the case of distributed indexes).
4962assert(StackIdIndicesToIndex.contains(I));
4963return StackIdIndicesToIndex[I];
4964 },
4965/*WriteContextSizeInfoIndex*/false, CallStackPos, CallStackCount);
4966
4967 NameVals.push_back(*ValueId);
4968assert(ModuleIdMap.count(FS->modulePath()));
4969 NameVals.push_back(ModuleIdMap[FS->modulePath()]);
4970 NameVals.push_back(
4971getEncodedGVSummaryFlags(FS->flags(), shouldImportValueAsDecl(FS)));
4972 NameVals.push_back(FS->instCount());
4973 NameVals.push_back(getEncodedFFlags(FS->fflags()));
4974// TODO: Stop writing entry count and bump bitcode version.
4975 NameVals.push_back(0/* EntryCount */);
4976
4977// Fill in below
4978 NameVals.push_back(0);// numrefs
4979 NameVals.push_back(0);// rorefcnt
4980 NameVals.push_back(0);// worefcnt
4981
4982unsigned Count = 0, RORefCnt = 0, WORefCnt = 0;
4983for (auto &RI :FS->refs()) {
4984auto RefValueId = getValueId(RI.getGUID());
4985if (!RefValueId)
4986continue;
4987 NameVals.push_back(*RefValueId);
4988if (RI.isReadOnly())
4989 RORefCnt++;
4990elseif (RI.isWriteOnly())
4991 WORefCnt++;
4992 Count++;
4993 }
4994 NameVals[6] = Count;
4995 NameVals[7] = RORefCnt;
4996 NameVals[8] = WORefCnt;
4997
4998for (auto &EI :FS->calls()) {
4999// If this GUID doesn't have a value id, it doesn't have a function
5000// summary and we don't need to record any calls to it.
5001 std::optional<unsigned> CallValueId = GetValueId(EI.first);
5002if (!CallValueId)
5003continue;
5004 NameVals.push_back(*CallValueId);
5005 NameVals.push_back(getEncodedHotnessCallEdgeInfo(EI.second));
5006 }
5007
5008// Emit the finished record.
5009 Stream.EmitRecord(bitc::FS_COMBINED_PROFILE, NameVals,
5010 FSCallsProfileAbbrev);
5011 NameVals.clear();
5012 MaybeEmitOriginalName(*S);
5013 });
5014
5015for (auto *AS : Aliases) {
5016auto AliasValueId = SummaryToValueIdMap[AS];
5017assert(AliasValueId);
5018 NameVals.push_back(AliasValueId);
5019assert(ModuleIdMap.count(AS->modulePath()));
5020 NameVals.push_back(ModuleIdMap[AS->modulePath()]);
5021 NameVals.push_back(
5022getEncodedGVSummaryFlags(AS->flags(), shouldImportValueAsDecl(AS)));
5023auto AliaseeValueId = SummaryToValueIdMap[&AS->getAliasee()];
5024assert(AliaseeValueId);
5025 NameVals.push_back(AliaseeValueId);
5026
5027// Emit the finished record.
5028 Stream.EmitRecord(bitc::FS_COMBINED_ALIAS, NameVals, FSAliasAbbrev);
5029 NameVals.clear();
5030 MaybeEmitOriginalName(*AS);
5031
5032if (auto *FS = dyn_cast<FunctionSummary>(&AS->getAliasee()))
5033getReferencedTypeIds(FS, ReferencedTypeIds);
5034 }
5035
5036if (!Index.cfiFunctionDefs().empty()) {
5037for (auto &S :Index.cfiFunctionDefs()) {
5038if (DefOrUseGUIDs.contains(
5039GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(S)))) {
5040 NameVals.push_back(StrtabBuilder.add(S));
5041 NameVals.push_back(S.size());
5042 }
5043 }
5044if (!NameVals.empty()) {
5045 Stream.EmitRecord(bitc::FS_CFI_FUNCTION_DEFS, NameVals);
5046 NameVals.clear();
5047 }
5048 }
5049
5050if (!Index.cfiFunctionDecls().empty()) {
5051for (auto &S :Index.cfiFunctionDecls()) {
5052if (DefOrUseGUIDs.contains(
5053GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(S)))) {
5054 NameVals.push_back(StrtabBuilder.add(S));
5055 NameVals.push_back(S.size());
5056 }
5057 }
5058if (!NameVals.empty()) {
5059 Stream.EmitRecord(bitc::FS_CFI_FUNCTION_DECLS, NameVals);
5060 NameVals.clear();
5061 }
5062 }
5063
5064// Walk the GUIDs that were referenced, and write the
5065// corresponding type id records.
5066for (auto &T : ReferencedTypeIds) {
5067auto TidIter =Index.typeIds().equal_range(T);
5068for (constauto &[GUID, TypeIdPair] :make_range(TidIter)) {
5069writeTypeIdSummaryRecord(NameVals, StrtabBuilder, TypeIdPair.first,
5070 TypeIdPair.second);
5071 Stream.EmitRecord(bitc::FS_TYPE_ID, NameVals);
5072 NameVals.clear();
5073 }
5074 }
5075
5076if (Index.getBlockCount())
5077 Stream.EmitRecord(bitc::FS_BLOCK_COUNT,
5078ArrayRef<uint64_t>{Index.getBlockCount()});
5079
5080 Stream.ExitBlock();
5081}
5082
5083/// Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the
5084/// current llvm version, and a record for the epoch number.
5085staticvoidwriteIdentificationBlock(BitstreamWriter &Stream) {
5086 Stream.EnterSubblock(bitc::IDENTIFICATION_BLOCK_ID, 5);
5087
5088// Write the "user readable" string identifying the bitcode producer
5089auto Abbv = std::make_shared<BitCodeAbbrev>();
5090 Abbv->Add(BitCodeAbbrevOp(bitc::IDENTIFICATION_CODE_STRING));
5091 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
5092 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6));
5093auto StringAbbrev = Stream.EmitAbbrev(std::move(Abbv));
5094writeStringRecord(Stream,bitc::IDENTIFICATION_CODE_STRING,
5095"LLVM" LLVM_VERSION_STRING, StringAbbrev);
5096
5097// Write the epoch version
5098 Abbv = std::make_shared<BitCodeAbbrev>();
5099 Abbv->Add(BitCodeAbbrevOp(bitc::IDENTIFICATION_CODE_EPOCH));
5100 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
5101auto EpochAbbrev = Stream.EmitAbbrev(std::move(Abbv));
5102constexpr std::array<unsigned, 1> Vals = {{bitc::BITCODE_CURRENT_EPOCH}};
5103 Stream.EmitRecord(bitc::IDENTIFICATION_CODE_EPOCH, Vals, EpochAbbrev);
5104 Stream.ExitBlock();
5105}
5106
5107void ModuleBitcodeWriter::writeModuleHash(StringRef View) {
5108// Emit the module's hash.
5109// MODULE_CODE_HASH: [5*i32]
5110if (GenerateHash) {
5111uint32_t Vals[5];
5112 Hasher.update(ArrayRef<uint8_t>(
5113reinterpret_cast<constuint8_t *>(View.data()),View.size()));
5114 std::array<uint8_t, 20> Hash = Hasher.result();
5115for (int Pos = 0; Pos < 20; Pos += 4) {
5116 Vals[Pos / 4] =support::endian::read32be(Hash.data() + Pos);
5117 }
5118
5119// Emit the finished record.
5120 Stream.EmitRecord(bitc::MODULE_CODE_HASH, Vals);
5121
5122if (ModHash)
5123// Save the written hash value.
5124llvm::copy(Vals, std::begin(*ModHash));
5125 }
5126}
5127
5128void ModuleBitcodeWriter::write() {
5129writeIdentificationBlock(Stream);
5130
5131 Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 3);
5132// We will want to write the module hash at this point. Block any flushing so
5133// we can have access to the whole underlying data later.
5134 Stream.markAndBlockFlushing();
5135
5136 writeModuleVersion();
5137
5138// Emit blockinfo, which defines the standard abbreviations etc.
5139 writeBlockInfo();
5140
5141// Emit information describing all of the types in the module.
5142 writeTypeTable();
5143
5144// Emit information about attribute groups.
5145 writeAttributeGroupTable();
5146
5147// Emit information about parameter attributes.
5148 writeAttributeTable();
5149
5150 writeComdats();
5151
5152// Emit top-level description of module, including target triple, inline asm,
5153// descriptors for global variables, and function prototype info.
5154 writeModuleInfo();
5155
5156// Emit constants.
5157 writeModuleConstants();
5158
5159// Emit metadata kind names.
5160 writeModuleMetadataKinds();
5161
5162// Emit metadata.
5163 writeModuleMetadata();
5164
5165// Emit module-level use-lists.
5166if (VE.shouldPreserveUseListOrder())
5167 writeUseListBlock(nullptr);
5168
5169 writeOperandBundleTags();
5170 writeSyncScopeNames();
5171
5172// Emit function bodies.
5173DenseMap<const Function *, uint64_t> FunctionToBitcodeIndex;
5174for (constFunction &F : M)
5175if (!F.isDeclaration())
5176 writeFunction(F, FunctionToBitcodeIndex);
5177
5178// Need to write after the above call to WriteFunction which populates
5179// the summary information in the index.
5180if (Index)
5181 writePerModuleGlobalValueSummary();
5182
5183 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
5184
5185 writeModuleHash(Stream.getMarkedBufferAndResumeFlushing());
5186
5187 Stream.ExitBlock();
5188}
5189
5190staticvoidwriteInt32ToBuffer(uint32_tValue,SmallVectorImpl<char> &Buffer,
5191uint32_t &Position) {
5192support::endian::write32le(&Buffer[Position],Value);
5193 Position += 4;
5194}
5195
5196/// If generating a bc file on darwin, we have to emit a
5197/// header and trailer to make it compatible with the system archiver. To do
5198/// this we emit the following header, and then emit a trailer that pads the
5199/// file out to be a multiple of 16 bytes.
5200///
5201/// struct bc_header {
5202/// uint32_t Magic; // 0x0B17C0DE
5203/// uint32_t Version; // Version, currently always 0.
5204/// uint32_t BitcodeOffset; // Offset to traditional bitcode file.
5205/// uint32_t BitcodeSize; // Size of traditional bitcode file.
5206/// uint32_t CPUType; // CPU specifier.
5207/// ... potentially more later ...
5208/// };
5209staticvoidemitDarwinBCHeaderAndTrailer(SmallVectorImpl<char> &Buffer,
5210constTriple &TT) {
5211unsigned CPUType = ~0U;
5212
5213// Match x86_64-*, i[3-9]86-*, powerpc-*, powerpc64-*, arm-*, thumb-*,
5214// armv[0-9]-*, thumbv[0-9]-*, armv5te-*, or armv6t2-*. The CPUType is a magic
5215// number from /usr/include/mach/machine.h. It is ok to reproduce the
5216// specific constants here because they are implicitly part of the Darwin ABI.
5217enum {
5218 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
5219 DARWIN_CPU_TYPE_X86 = 7,
5220 DARWIN_CPU_TYPE_ARM = 12,
5221 DARWIN_CPU_TYPE_POWERPC = 18
5222 };
5223
5224Triple::ArchType Arch = TT.getArch();
5225if (Arch ==Triple::x86_64)
5226 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
5227elseif (Arch ==Triple::x86)
5228 CPUType = DARWIN_CPU_TYPE_X86;
5229elseif (Arch ==Triple::ppc)
5230 CPUType = DARWIN_CPU_TYPE_POWERPC;
5231elseif (Arch ==Triple::ppc64)
5232 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
5233elseif (Arch ==Triple::arm || Arch ==Triple::thumb)
5234 CPUType = DARWIN_CPU_TYPE_ARM;
5235
5236// Traditional Bitcode starts after header.
5237assert(Buffer.size() >=BWH_HeaderSize &&
5238"Expected header size to be reserved");
5239unsigned BCOffset =BWH_HeaderSize;
5240unsigned BCSize = Buffer.size() -BWH_HeaderSize;
5241
5242// Write the magic and version.
5243unsigned Position = 0;
5244writeInt32ToBuffer(0x0B17C0DE, Buffer, Position);
5245writeInt32ToBuffer(0, Buffer, Position);// Version.
5246writeInt32ToBuffer(BCOffset, Buffer, Position);
5247writeInt32ToBuffer(BCSize, Buffer, Position);
5248writeInt32ToBuffer(CPUType, Buffer, Position);
5249
5250// If the file is not a multiple of 16 bytes, insert dummy padding.
5251while (Buffer.size() & 15)
5252 Buffer.push_back(0);
5253}
5254
5255/// Helper to write the header common to all bitcode files.
5256staticvoidwriteBitcodeHeader(BitstreamWriter &Stream) {
5257// Emit the file header.
5258 Stream.Emit((unsigned)'B', 8);
5259 Stream.Emit((unsigned)'C', 8);
5260 Stream.Emit(0x0, 4);
5261 Stream.Emit(0xC, 4);
5262 Stream.Emit(0xE, 4);
5263 Stream.Emit(0xD, 4);
5264}
5265
5266BitcodeWriter::BitcodeWriter(SmallVectorImpl<char> &Buffer)
5267 : Stream(newBitstreamWriter(Buffer)) {
5268writeBitcodeHeader(*Stream);
5269}
5270
5271BitcodeWriter::BitcodeWriter(raw_ostream &FS)
5272 : Stream(newBitstreamWriter(FS,FlushThreshold)) {
5273writeBitcodeHeader(*Stream);
5274}
5275
5276BitcodeWriter::~BitcodeWriter() {assert(WroteStrtab); }
5277
5278void BitcodeWriter::writeBlob(unsignedBlock,unsignedRecord,StringRef Blob) {
5279 Stream->EnterSubblock(Block, 3);
5280
5281auto Abbv = std::make_shared<BitCodeAbbrev>();
5282 Abbv->Add(BitCodeAbbrevOp(Record));
5283 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
5284auto AbbrevNo = Stream->EmitAbbrev(std::move(Abbv));
5285
5286 Stream->EmitRecordWithBlob(AbbrevNo,ArrayRef<uint64_t>{Record}, Blob);
5287
5288 Stream->ExitBlock();
5289}
5290
5291voidBitcodeWriter::writeSymtab() {
5292assert(!WroteStrtab && !WroteSymtab);
5293
5294// If any module has module-level inline asm, we will require a registered asm
5295// parser for the target so that we can create an accurate symbol table for
5296// the module.
5297for (Module *M : Mods) {
5298if (M->getModuleInlineAsm().empty())
5299continue;
5300
5301 std::string Err;
5302constTriple TT(M->getTargetTriple());
5303constTarget *T =TargetRegistry::lookupTarget(TT.str(), Err);
5304if (!T || !T->hasMCAsmParser())
5305return;
5306 }
5307
5308 WroteSymtab =true;
5309SmallVector<char, 0> Symtab;
5310// The irsymtab::build function may be unable to create a symbol table if the
5311// module is malformed (e.g. it contains an invalid alias). Writing a symbol
5312// table is not required for correctness, but we still want to be able to
5313// write malformed modules to bitcode files, so swallow the error.
5314if (Error E =irsymtab::build(Mods, Symtab, StrtabBuilder, Alloc)) {
5315consumeError(std::move(E));
5316return;
5317 }
5318
5319 writeBlob(bitc::SYMTAB_BLOCK_ID,bitc::SYMTAB_BLOB,
5320 {Symtab.data(), Symtab.size()});
5321}
5322
5323voidBitcodeWriter::writeStrtab() {
5324assert(!WroteStrtab);
5325
5326 std::vector<char> Strtab;
5327 StrtabBuilder.finalizeInOrder();
5328 Strtab.resize(StrtabBuilder.getSize());
5329 StrtabBuilder.write((uint8_t *)Strtab.data());
5330
5331 writeBlob(bitc::STRTAB_BLOCK_ID,bitc::STRTAB_BLOB,
5332 {Strtab.data(), Strtab.size()});
5333
5334 WroteStrtab =true;
5335}
5336
5337voidBitcodeWriter::copyStrtab(StringRef Strtab) {
5338 writeBlob(bitc::STRTAB_BLOCK_ID,bitc::STRTAB_BLOB, Strtab);
5339 WroteStrtab =true;
5340}
5341
5342voidBitcodeWriter::writeModule(constModule &M,
5343bool ShouldPreserveUseListOrder,
5344constModuleSummaryIndex *Index,
5345bool GenerateHash,ModuleHash *ModHash) {
5346assert(!WroteStrtab);
5347
5348// The Mods vector is used by irsymtab::build, which requires non-const
5349// Modules in case it needs to materialize metadata. But the bitcode writer
5350// requires that the module is materialized, so we can cast to non-const here,
5351// after checking that it is in fact materialized.
5352assert(M.isMaterialized());
5353 Mods.push_back(const_cast<Module *>(&M));
5354
5355 ModuleBitcodeWriter ModuleWriter(M, StrtabBuilder, *Stream,
5356 ShouldPreserveUseListOrder, Index,
5357 GenerateHash, ModHash);
5358 ModuleWriter.write();
5359}
5360
5361voidBitcodeWriter::writeIndex(
5362constModuleSummaryIndex *Index,
5363constModuleToSummariesForIndexTy *ModuleToSummariesForIndex,
5364constGVSummaryPtrSet *DecSummaries) {
5365 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index, DecSummaries,
5366 ModuleToSummariesForIndex);
5367 IndexWriter.write();
5368}
5369
5370/// Write the specified module to the specified output stream.
5371voidllvm::WriteBitcodeToFile(constModule &M,raw_ostream &Out,
5372bool ShouldPreserveUseListOrder,
5373constModuleSummaryIndex *Index,
5374bool GenerateHash,ModuleHash *ModHash) {
5375autoWrite = [&](BitcodeWriter &Writer) {
5376 Writer.writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
5377 ModHash);
5378 Writer.writeSymtab();
5379 Writer.writeStrtab();
5380 };
5381Triple TT(M.getTargetTriple());
5382if (TT.isOSDarwin() || TT.isOSBinFormatMachO()) {
5383// If this is darwin or another generic macho target, reserve space for the
5384// header. Note that the header is computed *after* the output is known, so
5385// we currently explicitly use a buffer, write to it, and then subsequently
5386// flush to Out.
5387SmallVector<char, 0> Buffer;
5388 Buffer.reserve(256 * 1024);
5389 Buffer.insert(Buffer.begin(),BWH_HeaderSize, 0);
5390BitcodeWriter Writer(Buffer);
5391Write(Writer);
5392emitDarwinBCHeaderAndTrailer(Buffer, TT);
5393 Out.write(Buffer.data(), Buffer.size());
5394 }else {
5395BitcodeWriter Writer(Out);
5396Write(Writer);
5397 }
5398}
5399
5400void IndexBitcodeWriter::write() {
5401 Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 3);
5402
5403 writeModuleVersion();
5404
5405// Write the module paths in the combined index.
5406 writeModStrings();
5407
5408// Write the summary combined index records.
5409 writeCombinedGlobalValueSummary();
5410
5411 Stream.ExitBlock();
5412}
5413
5414// Write the specified module summary index to the given raw output stream,
5415// where it will be written in a new bitcode block. This is used when
5416// writing the combined index file for ThinLTO. When writing a subset of the
5417// index for a distributed backend, provide a \p ModuleToSummariesForIndex map.
5418voidllvm::writeIndexToFile(
5419constModuleSummaryIndex &Index,raw_ostream &Out,
5420constModuleToSummariesForIndexTy *ModuleToSummariesForIndex,
5421constGVSummaryPtrSet *DecSummaries) {
5422SmallVector<char, 0> Buffer;
5423 Buffer.reserve(256 * 1024);
5424
5425BitcodeWriter Writer(Buffer);
5426 Writer.writeIndex(&Index, ModuleToSummariesForIndex, DecSummaries);
5427 Writer.writeStrtab();
5428
5429 Out.write((char *)&Buffer.front(), Buffer.size());
5430}
5431
5432namespace{
5433
5434/// Class to manage the bitcode writing for a thin link bitcode file.
5435classThinLinkBitcodeWriter :public ModuleBitcodeWriterBase {
5436 /// ModHash is for use in ThinLTO incremental build, generated while writing
5437 /// the module bitcode file.
5438constModuleHash *ModHash;
5439
5440public:
5441 ThinLinkBitcodeWriter(constModule &M,StringTableBuilder &StrtabBuilder,
5442BitstreamWriter &Stream,
5443constModuleSummaryIndex &Index,
5444constModuleHash &ModHash)
5445 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
5446/*ShouldPreserveUseListOrder=*/false, &Index),
5447 ModHash(&ModHash) {}
5448
5449voidwrite();
5450
5451private:
5452void writeSimplifiedModuleInfo();
5453};
5454
5455}// end anonymous namespace
5456
5457// This function writes a simpilified module info for thin link bitcode file.
5458// It only contains the source file name along with the name(the offset and
5459// size in strtab) and linkage for global values. For the global value info
5460// entry, in order to keep linkage at offset 5, there are three zeros used
5461// as padding.
5462void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
5463SmallVector<unsigned, 64> Vals;
5464// Emit the module's source file name.
5465 {
5466StringEncodingBits =getStringEncoding(M.getSourceFileName());
5467BitCodeAbbrevOp AbbrevOpToUse =BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8);
5468if (Bits ==SE_Char6)
5469 AbbrevOpToUse =BitCodeAbbrevOp(BitCodeAbbrevOp::Char6);
5470elseif (Bits ==SE_Fixed7)
5471 AbbrevOpToUse =BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7);
5472
5473// MODULE_CODE_SOURCE_FILENAME: [namechar x N]
5474auto Abbv = std::make_shared<BitCodeAbbrev>();
5475 Abbv->Add(BitCodeAbbrevOp(bitc::MODULE_CODE_SOURCE_FILENAME));
5476 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
5477 Abbv->Add(AbbrevOpToUse);
5478unsigned FilenameAbbrev = Stream.EmitAbbrev(std::move(Abbv));
5479
5480for (constautoP :M.getSourceFileName())
5481 Vals.push_back((unsignedchar)P);
5482
5483 Stream.EmitRecord(bitc::MODULE_CODE_SOURCE_FILENAME, Vals, FilenameAbbrev);
5484 Vals.clear();
5485 }
5486
5487// Emit the global variable information.
5488for (constGlobalVariable &GV :M.globals()) {
5489// GLOBALVAR: [strtab offset, strtab size, 0, 0, 0, linkage]
5490 Vals.push_back(StrtabBuilder.add(GV.getName()));
5491 Vals.push_back(GV.getName().size());
5492 Vals.push_back(0);
5493 Vals.push_back(0);
5494 Vals.push_back(0);
5495 Vals.push_back(getEncodedLinkage(GV));
5496
5497 Stream.EmitRecord(bitc::MODULE_CODE_GLOBALVAR, Vals);
5498 Vals.clear();
5499 }
5500
5501// Emit the function proto information.
5502for (constFunction &F : M) {
5503// FUNCTION: [strtab offset, strtab size, 0, 0, 0, linkage]
5504 Vals.push_back(StrtabBuilder.add(F.getName()));
5505 Vals.push_back(F.getName().size());
5506 Vals.push_back(0);
5507 Vals.push_back(0);
5508 Vals.push_back(0);
5509 Vals.push_back(getEncodedLinkage(F));
5510
5511 Stream.EmitRecord(bitc::MODULE_CODE_FUNCTION, Vals);
5512 Vals.clear();
5513 }
5514
5515// Emit the alias information.
5516for (constGlobalAlias &A :M.aliases()) {
5517// ALIAS: [strtab offset, strtab size, 0, 0, 0, linkage]
5518 Vals.push_back(StrtabBuilder.add(A.getName()));
5519 Vals.push_back(A.getName().size());
5520 Vals.push_back(0);
5521 Vals.push_back(0);
5522 Vals.push_back(0);
5523 Vals.push_back(getEncodedLinkage(A));
5524
5525 Stream.EmitRecord(bitc::MODULE_CODE_ALIAS, Vals);
5526 Vals.clear();
5527 }
5528
5529// Emit the ifunc information.
5530for (constGlobalIFunc &I :M.ifuncs()) {
5531// IFUNC: [strtab offset, strtab size, 0, 0, 0, linkage]
5532 Vals.push_back(StrtabBuilder.add(I.getName()));
5533 Vals.push_back(I.getName().size());
5534 Vals.push_back(0);
5535 Vals.push_back(0);
5536 Vals.push_back(0);
5537 Vals.push_back(getEncodedLinkage(I));
5538
5539 Stream.EmitRecord(bitc::MODULE_CODE_IFUNC, Vals);
5540 Vals.clear();
5541 }
5542}
5543
5544void ThinLinkBitcodeWriter::write() {
5545 Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 3);
5546
5547 writeModuleVersion();
5548
5549 writeSimplifiedModuleInfo();
5550
5551 writePerModuleGlobalValueSummary();
5552
5553// Write module hash.
5554 Stream.EmitRecord(bitc::MODULE_CODE_HASH,ArrayRef<uint32_t>(*ModHash));
5555
5556 Stream.ExitBlock();
5557}
5558
5559voidBitcodeWriter::writeThinLinkBitcode(constModule &M,
5560constModuleSummaryIndex &Index,
5561constModuleHash &ModHash) {
5562assert(!WroteStrtab);
5563
5564// The Mods vector is used by irsymtab::build, which requires non-const
5565// Modules in case it needs to materialize metadata. But the bitcode writer
5566// requires that the module is materialized, so we can cast to non-const here,
5567// after checking that it is in fact materialized.
5568assert(M.isMaterialized());
5569 Mods.push_back(const_cast<Module *>(&M));
5570
5571 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream, Index,
5572 ModHash);
5573 ThinLinkWriter.write();
5574}
5575
5576// Write the specified thin link bitcode file to the given raw output stream,
5577// where it will be written in a new bitcode block. This is used when
5578// writing the per-module index file for ThinLTO.
5579voidllvm::writeThinLinkBitcodeToFile(constModule &M,raw_ostream &Out,
5580constModuleSummaryIndex &Index,
5581constModuleHash &ModHash) {
5582SmallVector<char, 0> Buffer;
5583 Buffer.reserve(256 * 1024);
5584
5585BitcodeWriter Writer(Buffer);
5586 Writer.writeThinLinkBitcode(M, Index, ModHash);
5587 Writer.writeSymtab();
5588 Writer.writeStrtab();
5589
5590 Out.write((char *)&Buffer.front(), Buffer.size());
5591}
5592
5593staticconstchar *getSectionNameForBitcode(constTriple &T) {
5594switch (T.getObjectFormat()) {
5595caseTriple::MachO:
5596return"__LLVM,__bitcode";
5597caseTriple::COFF:
5598caseTriple::ELF:
5599caseTriple::Wasm:
5600caseTriple::UnknownObjectFormat:
5601return".llvmbc";
5602caseTriple::GOFF:
5603llvm_unreachable("GOFF is not yet implemented");
5604break;
5605caseTriple::SPIRV:
5606if (T.getVendor() ==Triple::AMD)
5607return".llvmbc";
5608llvm_unreachable("SPIRV is not yet implemented");
5609break;
5610caseTriple::XCOFF:
5611llvm_unreachable("XCOFF is not yet implemented");
5612break;
5613caseTriple::DXContainer:
5614llvm_unreachable("DXContainer is not yet implemented");
5615break;
5616 }
5617llvm_unreachable("Unimplemented ObjectFormatType");
5618}
5619
5620staticconstchar *getSectionNameForCommandline(constTriple &T) {
5621switch (T.getObjectFormat()) {
5622caseTriple::MachO:
5623return"__LLVM,__cmdline";
5624caseTriple::COFF:
5625caseTriple::ELF:
5626caseTriple::Wasm:
5627caseTriple::UnknownObjectFormat:
5628return".llvmcmd";
5629caseTriple::GOFF:
5630llvm_unreachable("GOFF is not yet implemented");
5631break;
5632caseTriple::SPIRV:
5633if (T.getVendor() ==Triple::AMD)
5634return".llvmcmd";
5635llvm_unreachable("SPIRV is not yet implemented");
5636break;
5637caseTriple::XCOFF:
5638llvm_unreachable("XCOFF is not yet implemented");
5639break;
5640caseTriple::DXContainer:
5641llvm_unreachable("DXC is not yet implemented");
5642break;
5643 }
5644llvm_unreachable("Unimplemented ObjectFormatType");
5645}
5646
5647voidllvm::embedBitcodeInModule(llvm::Module &M,llvm::MemoryBufferRef Buf,
5648boolEmbedBitcode,bool EmbedCmdline,
5649const std::vector<uint8_t> &CmdArgs) {
5650// Save llvm.compiler.used and remove it.
5651SmallVector<Constant *, 2> UsedArray;
5652SmallVector<GlobalValue *, 4> UsedGlobals;
5653GlobalVariable *Used =collectUsedGlobalVariables(M, UsedGlobals,true);
5654Type *UsedElementType = Used ? Used->getValueType()->getArrayElementType()
5655 :PointerType::getUnqual(M.getContext());
5656for (auto *GV : UsedGlobals) {
5657if (GV->getName() !="llvm.embedded.module" &&
5658 GV->getName() !="llvm.cmdline")
5659 UsedArray.push_back(
5660ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, UsedElementType));
5661 }
5662if (Used)
5663 Used->eraseFromParent();
5664
5665// Embed the bitcode for the llvm module.
5666 std::stringData;
5667ArrayRef<uint8_t> ModuleData;
5668TripleT(M.getTargetTriple());
5669
5670if (EmbedBitcode) {
5671if (Buf.getBufferSize() == 0 ||
5672 !isBitcode((constunsignedchar *)Buf.getBufferStart(),
5673 (constunsignedchar *)Buf.getBufferEnd())) {
5674// If the input is LLVM Assembly, bitcode is produced by serializing
5675// the module. Use-lists order need to be preserved in this case.
5676llvm::raw_string_ostreamOS(Data);
5677llvm::WriteBitcodeToFile(M,OS,/* ShouldPreserveUseListOrder */true);
5678 ModuleData =
5679ArrayRef<uint8_t>((constuint8_t *)OS.str().data(),OS.str().size());
5680 }else
5681// If the input is LLVM bitcode, write the input byte stream directly.
5682 ModuleData =ArrayRef<uint8_t>((constuint8_t *)Buf.getBufferStart(),
5683 Buf.getBufferSize());
5684 }
5685llvm::Constant *ModuleConstant =
5686llvm::ConstantDataArray::get(M.getContext(), ModuleData);
5687llvm::GlobalVariable *GV =newllvm::GlobalVariable(
5688 M, ModuleConstant->getType(),true,llvm::GlobalValue::PrivateLinkage,
5689 ModuleConstant);
5690 GV->setSection(getSectionNameForBitcode(T));
5691// Set alignment to 1 to prevent padding between two contributions from input
5692// sections after linking.
5693 GV->setAlignment(Align(1));
5694 UsedArray.push_back(
5695ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, UsedElementType));
5696if (llvm::GlobalVariable *Old =
5697 M.getGlobalVariable("llvm.embedded.module",true)) {
5698assert(Old->hasZeroLiveUses() &&
5699"llvm.embedded.module can only be used once in llvm.compiler.used");
5700 GV->takeName(Old);
5701 Old->eraseFromParent();
5702 }else {
5703 GV->setName("llvm.embedded.module");
5704 }
5705
5706// Skip if only bitcode needs to be embedded.
5707if (EmbedCmdline) {
5708// Embed command-line options.
5709ArrayRef<uint8_t> CmdData(const_cast<uint8_t *>(CmdArgs.data()),
5710 CmdArgs.size());
5711llvm::Constant *CmdConstant =
5712llvm::ConstantDataArray::get(M.getContext(), CmdData);
5713 GV =newllvm::GlobalVariable(M, CmdConstant->getType(),true,
5714llvm::GlobalValue::PrivateLinkage,
5715 CmdConstant);
5716 GV->setSection(getSectionNameForCommandline(T));
5717 GV->setAlignment(Align(1));
5718 UsedArray.push_back(
5719ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, UsedElementType));
5720if (llvm::GlobalVariable *Old = M.getGlobalVariable("llvm.cmdline",true)) {
5721assert(Old->hasZeroLiveUses() &&
5722"llvm.cmdline can only be used once in llvm.compiler.used");
5723 GV->takeName(Old);
5724 Old->eraseFromParent();
5725 }else {
5726 GV->setName("llvm.cmdline");
5727 }
5728 }
5729
5730if (UsedArray.empty())
5731return;
5732
5733// Recreate llvm.compiler.used.
5734ArrayType *ATy =ArrayType::get(UsedElementType, UsedArray.size());
5735auto *NewUsed =newGlobalVariable(
5736 M, ATy,false,llvm::GlobalValue::AppendingLinkage,
5737llvm::ConstantArray::get(ATy, UsedArray),"llvm.compiler.used");
5738 NewUsed->setSection("llvm.metadata");
5739}
StringMap.h
This file defines the StringMap class.
APFloat.h
This file declares a class to represent arbitrary precision floating point values and provide a varie...
APInt.h
This file implements a class to represent arbitrary precision integral constant values and operations...
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition:ARMSLSHardening.cpp:73
ArrayRef.h
writeDIMacro
static void writeDIMacro(raw_ostream &Out, const DIMacro *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2392
writeDIGlobalVariableExpression
static void writeDIGlobalVariableExpression(raw_ostream &Out, const DIGlobalVariableExpression *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2539
writeDICompositeType
static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2227
writeDIStringType
static void writeDIStringType(raw_ostream &Out, const DIStringType *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2176
writeDIGlobalVariable
static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2453
writeDIModule
static void writeDIModule(raw_ostream &Out, const DIModule *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2413
writeDIFile
static void writeDIFile(raw_ostream &Out, const DIFile *N, AsmWriterContext &)
Definition:AsmWriter.cpp:2274
writeDISubroutineType
static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2263
writeDILabel
static void writeDILabel(raw_ostream &Out, const DILabel *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2488
writeDIDerivedType
static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2194
writeDIImportedEntity
static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2563
writeDIObjCProperty
static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2549
writeDISubprogram
static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2319
writeDILocation
static void writeDILocation(raw_ostream &Out, const DILocation *DL, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2036
writeDINamespace
static void writeDINamespace(raw_ostream &Out, const DINamespace *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2370
writeDICommonBlock
static void writeDICommonBlock(raw_ostream &Out, const DICommonBlock *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2380
writeDIBasicType
static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N, AsmWriterContext &)
Definition:AsmWriter.cpp:2160
writeGenericDINode
static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2018
writeDILocalVariable
static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2472
writeDITemplateTypeParameter
static void writeDITemplateTypeParameter(raw_ostream &Out, const DITemplateTypeParameter *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2428
writeDICompileUnit
static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2289
writeDIGenericSubrange
static void writeDIGenericSubrange(raw_ostream &Out, const DIGenericSubrange *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2097
writeDISubrange
static void writeDISubrange(raw_ostream &Out, const DISubrange *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2056
writeDILexicalBlockFile
static void writeDILexicalBlockFile(raw_ostream &Out, const DILexicalBlockFile *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2358
writeDIEnumerator
static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, AsmWriterContext &)
Definition:AsmWriter.cpp:2148
writeMDTuple
static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:1797
writeDIExpression
static void writeDIExpression(raw_ostream &Out, const DIExpression *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2499
writeDIAssignID
static void writeDIAssignID(raw_ostream &Out, const DIAssignID *DL, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2050
writeDILexicalBlock
static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2347
writeDIArgList
static void writeDIArgList(raw_ostream &Out, const DIArgList *N, AsmWriterContext &WriterCtx, bool FromValue=false)
Definition:AsmWriter.cpp:2524
writeDITemplateValueParameter
static void writeDITemplateValueParameter(raw_ostream &Out, const DITemplateValueParameter *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2439
writeDIMacroFile
static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, AsmWriterContext &WriterCtx)
Definition:AsmWriter.cpp:2403
AtomicOrdering.h
Atomic ordering constants.
Attributes.h
This file contains the simple types necessary to represent the attributes associated with functions a...
BitCodes.h
BitcodeCommon.h
BitcodeReader.h
writeFunctionHeapProfileRecords
static void writeFunctionHeapProfileRecords(BitstreamWriter &Stream, FunctionSummary *FS, unsigned CallsiteAbbrev, unsigned AllocAbbrev, unsigned ContextIdAbbvId, bool PerModule, std::function< unsigned(const ValueInfo &VI)> GetValueID, std::function< unsigned(unsigned)> GetStackIndex, bool WriteContextSizeInfoIndex, DenseMap< CallStackId, LinearCallStackId > &CallStackPos, CallStackId &CallStackCount)
Definition:BitcodeWriter.cpp:4252
serializeSanitizerMetadata
static unsigned serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta)
Definition:BitcodeWriter.cpp:1433
writeTypeIdCompatibleVtableSummaryRecord
static void writeTypeIdCompatibleVtableSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdCompatibleVtableInfo &Summary, ValueEnumerator &VE)
Definition:BitcodeWriter.cpp:4195
getReferencedTypeIds
static void getReferencedTypeIds(FunctionSummary *FS, std::set< GlobalValue::GUID > &ReferencedTypeIds)
Collect type IDs from type tests used by function.
Definition:BitcodeWriter.cpp:4125
getAttrKindEncoding
static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind)
Definition:BitcodeWriter.cpp:715
collectMemProfCallStacks
static void collectMemProfCallStacks(FunctionSummary *FS, std::function< LinearFrameId(unsigned)> GetStackIndex, MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &CallStacks)
Definition:BitcodeWriter.cpp:4212
getEncodedUnaryOpcode
static unsigned getEncodedUnaryOpcode(unsigned Opcode)
Definition:BitcodeWriter.cpp:627
emitSignedInt64
static void emitSignedInt64(SmallVectorImpl< uint64_t > &Vals, uint64_t V)
Definition:BitcodeWriter.cpp:927
StringEncoding
StringEncoding
Definition:BitcodeWriter.cpp:1413
SE_Char6
@ SE_Char6
Definition:BitcodeWriter.cpp:1413
SE_Fixed7
@ SE_Fixed7
Definition:BitcodeWriter.cpp:1413
SE_Fixed8
@ SE_Fixed8
Definition:BitcodeWriter.cpp:1413
getEncodedVisibility
static unsigned getEncodedVisibility(const GlobalValue &GV)
Definition:BitcodeWriter.cpp:1315
getOptimizationFlags
static uint64_t getOptimizationFlags(const Value *V)
Definition:BitcodeWriter.cpp:1688
getEncodedLinkage
static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage)
Definition:BitcodeWriter.cpp:1220
getEncodedRMWOperation
static unsigned getEncodedRMWOperation(AtomicRMWInst::BinOp Op)
Definition:BitcodeWriter.cpp:658
getEncodedThreadLocalMode
static unsigned getEncodedThreadLocalMode(const GlobalValue &GV)
Definition:BitcodeWriter.cpp:1333
writeMemoryProfileRadixTree
static DenseMap< CallStackId, LinearCallStackId > writeMemoryProfileRadixTree(MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &&CallStacks, BitstreamWriter &Stream, unsigned RadixAbbrev)
Definition:BitcodeWriter.cpp:4236
writeIdentificationBlock
static void writeIdentificationBlock(BitstreamWriter &Stream)
Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the current llvm version,...
Definition:BitcodeWriter.cpp:5085
getEncodedCastOpcode
static unsigned getEncodedCastOpcode(unsigned Opcode)
Definition:BitcodeWriter.cpp:608
WriteRelBFToSummary
static cl::opt< bool > WriteRelBFToSummary("write-relbf-to-summary", cl::Hidden, cl::init(false), cl::desc("Write relative block frequency to function summary "))
FlushThreshold
static cl::opt< uint32_t > FlushThreshold("bitcode-flush-threshold", cl::Hidden, cl::init(512), cl::desc("The threshold (unit M) for flushing LLVM bitcode."))
getEncodedOrdering
static unsigned getEncodedOrdering(AtomicOrdering Ordering)
Definition:BitcodeWriter.cpp:687
getEncodedUnnamedAddr
static unsigned getEncodedUnnamedAddr(const GlobalValue &GV)
Definition:BitcodeWriter.cpp:1360
WriteNewDbgInfoFormatToBitcode
bool WriteNewDbgInfoFormatToBitcode
Definition:BasicBlock.cpp:47
getEncodedComdatSelectionKind
static unsigned getEncodedComdatSelectionKind(const Comdat &C)
Definition:BitcodeWriter.cpp:1344
getEncodedGVSummaryFlags
static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags, bool ImportAsDecl=false)
Definition:BitcodeWriter.cpp:1269
emitDarwinBCHeaderAndTrailer
static void emitDarwinBCHeaderAndTrailer(SmallVectorImpl< char > &Buffer, const Triple &TT)
If generating a bc file on darwin, we have to emit a header and trailer to make it compatible with th...
Definition:BitcodeWriter.cpp:5209
writeBitcodeHeader
static void writeBitcodeHeader(BitstreamWriter &Stream)
Helper to write the header common to all bitcode files.
Definition:BitcodeWriter.cpp:5256
UseNewDbgInfoFormat
llvm::cl::opt< bool > UseNewDbgInfoFormat
getEncodedRelBFCallEdgeInfo
static uint64_t getEncodedRelBFCallEdgeInfo(const CalleeInfo &CI)
Definition:BitcodeWriter.cpp:1306
writeWholeProgramDevirtResolutionByArg
static void writeWholeProgramDevirtResolutionByArg(SmallVector< uint64_t, 64 > &NameVals, const std::vector< uint64_t > &args, const WholeProgramDevirtResolution::ByArg &ByArg)
Definition:BitcodeWriter.cpp:4150
emitConstantRange
static void emitConstantRange(SmallVectorImpl< uint64_t > &Record, const ConstantRange &CR, bool EmitBitWidth)
Definition:BitcodeWriter.cpp:945
getStringEncoding
static StringEncoding getStringEncoding(StringRef Str)
Determine the encoding to use for the given string name and length.
Definition:BitcodeWriter.cpp:1416
getEncodedGVarFlags
static uint64_t getEncodedGVarFlags(GlobalVarSummary::GVarFlags Flags)
Definition:BitcodeWriter.cpp:1291
getSectionNameForCommandline
static const char * getSectionNameForCommandline(const Triple &T)
Definition:BitcodeWriter.cpp:5620
IndexThreshold
static cl::opt< unsigned > IndexThreshold("bitcode-mdindex-threshold", cl::Hidden, cl::init(25), cl::desc("Number of metadatas above which we emit an index " "to enable lazy-loading"))
writeTypeIdSummaryRecord
static void writeTypeIdSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdSummary &Summary)
Definition:BitcodeWriter.cpp:4176
writeFunctionTypeMetadataRecords
static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream, FunctionSummary *FS, Fn GetValueID)
Write the function type metadata related records that need to appear before a function summary entry ...
Definition:BitcodeWriter.cpp:4049
getEncodedHotnessCallEdgeInfo
static uint64_t getEncodedHotnessCallEdgeInfo(const CalleeInfo &CI)
Definition:BitcodeWriter.cpp:1297
emitWideAPInt
static void emitWideAPInt(SmallVectorImpl< uint64_t > &Vals, const APInt &A)
Definition:BitcodeWriter.cpp:934
writeStringRecord
static void writeStringRecord(BitstreamWriter &Stream, unsigned Code, StringRef Str, unsigned AbbrevToUse)
Definition:BitcodeWriter.cpp:700
writeWholeProgramDevirtResolution
static void writeWholeProgramDevirtResolution(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, uint64_t Id, const WholeProgramDevirtResolution &Wpd)
Definition:BitcodeWriter.cpp:4162
getEncodedDLLStorageClass
static unsigned getEncodedDLLStorageClass(const GlobalValue &GV)
Definition:BitcodeWriter.cpp:1324
writeInt32ToBuffer
static void writeInt32ToBuffer(uint32_t Value, SmallVectorImpl< char > &Buffer, uint32_t &Position)
Definition:BitcodeWriter.cpp:5190
MetadataAbbrev
MetadataAbbrev
Definition:BitcodeWriter.cpp:2393
LastPlusOne
@ LastPlusOne
Definition:BitcodeWriter.cpp:2396
getSectionNameForBitcode
static const char * getSectionNameForBitcode(const Triple &T)
Definition:BitcodeWriter.cpp:5593
getEncodedBinaryOpcode
static unsigned getEncodedBinaryOpcode(unsigned Opcode)
Definition:BitcodeWriter.cpp:634
getEncodedFFlags
static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags)
Definition:BitcodeWriter.cpp:1252
BitcodeWriter.h
BitstreamWriter.h
A
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Casting.h
CommandLine.h
ConstantRangeList.h
Constants.h
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Idx
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Definition:DeadArgumentElimination.cpp:353
DebugInfoMetadata.h
DebugLoc.h
DenseMap.h
This file defines the DenseMap class.
DerivedTypes.h
Name
std::string Name
Definition:ELFObjHandler.cpp:77
Index
uint32_t Index
Definition:ELFObjHandler.cpp:83
Endian.h
GlobalAlias.h
GlobalIFunc.h
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
GlobalObject.h
GlobalValue.h
GlobalVariable.h
GEP
Hexagon Common GEP
Definition:HexagonCommonGEP.cpp:170
_
#define _
Definition:HexagonMCCodeEmitter.cpp:46
getAlign
static MaybeAlign getAlign(Value *Ptr)
Definition:IRBuilder.cpp:500
IRSymtab.h
BasicBlock.h
Constant.h
Function.h
Instruction.h
Module.h
Module.h This file contains the declarations for the Module class.
Operator.h
Type.h
Value.h
InlineAsm.h
InstrTypes.h
Instructions.h
LLVMBitCodes.h
LLVMContext.h
EmbedBitcode
static cl::opt< LTOBitcodeEmbedding > EmbedBitcode("lto-embed-bitcode", cl::init(LTOBitcodeEmbedding::DoNotEmbed), cl::values(clEnumValN(LTOBitcodeEmbedding::DoNotEmbed, "none", "Do not embed"), clEnumValN(LTOBitcodeEmbedding::EmbedOptimized, "optimized", "Embed after all optimization passes"), clEnumValN(LTOBitcodeEmbedding::EmbedPostMergePreOptimized, "post-merge-pre-opt", "Embed post merge, but before optimizations")), cl::desc("Embed LLVM bitcode in object files produced by LTO"))
F
#define F(x, y, z)
Definition:MD5.cpp:55
I
#define I(x, y, z)
Definition:MD5.cpp:58
G
#define G(x, y, z)
Definition:MD5.cpp:56
H
#define H(x, y, z)
Definition:MD5.cpp:57
MathExtras.h
MemProf.h
Metadata.h
This file contains the declarations for metadata subclasses.
ModuleSummaryIndex.h
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
args
nvptx lower args
Definition:NVPTXLowerArgs.cpp:199
Range
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
II
uint64_t IntrinsicInst * II
Definition:NVVMIntrRange.cpp:51
P
#define P(N)
SHA1.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
STLExtras.h
This file contains some templates that are useful if you are working with the STL at all.
OS
raw_pwrite_stream & OS
Definition:SampleProfWriter.cpp:51
SetVector.h
This file implements a set that has insertion order iteration characteristics.
SmallPtrSet.h
This file defines the SmallPtrSet class.
SmallString.h
This file defines the SmallString class.
SmallVector.h
This file defines the SmallVector class.
StringRef.h
StringTableBuilder.h
TargetRegistry.h
Triple.h
UseListOrder.h
ValueEnumerator.h
ValueSymbolTable.h
getBitWidth
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
Definition:ValueTracking.cpp:93
IV
static const uint32_t IV[8]
Definition:blake3_impl.h:78
ArrayType
Definition:ItaniumDemangle.h:785
FunctionType
Definition:ItaniumDemangle.h:823
PointerType
Definition:ItaniumDemangle.h:627
T
VectorType
Definition:ItaniumDemangle.h:1173
llvm::APInt
Class for arbitrary precision integers.
Definition:APInt.h:78
llvm::APInt::getNumWords
unsigned getNumWords() const
Get the number of words.
Definition:APInt.h:1475
llvm::APInt::getActiveWords
unsigned getActiveWords() const
Compute the number of active words in the value of this APInt.
Definition:APInt.h:1498
llvm::APInt::getRawData
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
Definition:APInt.h:569
llvm::APInt::getSExtValue
int64_t getSExtValue() const
Get sign extended value.
Definition:APInt.h:1542
llvm::AliasSummary
Alias summary information.
Definition:ModuleSummaryIndex.h:657
llvm::AliasSummary::getAliasee
const GlobalValueSummary & getAliasee() const
Definition:ModuleSummaryIndex.h:687
llvm::AllocaInst
an instruction to allocate memory on the stack
Definition:Instructions.h:63
llvm::AllocaInst::isSwiftError
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
Definition:Instructions.h:149
llvm::AllocaInst::getAlign
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Definition:Instructions.h:124
llvm::AllocaInst::getAllocatedType
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
Definition:Instructions.h:117
llvm::AllocaInst::isUsedWithInAlloca
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
Definition:Instructions.h:139
llvm::AllocaInst::getAddressSpace
unsigned getAddressSpace() const
Return the address space for the allocation.
Definition:Instructions.h:104
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition:ArrayRef.h:41
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition:ArrayRef.h:168
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition:ArrayRef.h:163
llvm::ArrayType
Class to represent array types.
Definition:DerivedTypes.h:395
llvm::ArrayType::get
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
llvm::AtomicRMWInst::BinOp
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Definition:Instructions.h:716
llvm::AtomicRMWInst::Add
@ Add
*p = old + v
Definition:Instructions.h:720
llvm::AtomicRMWInst::FAdd
@ FAdd
*p = old + v
Definition:Instructions.h:741
llvm::AtomicRMWInst::USubCond
@ USubCond
Subtract only if no unsigned overflow.
Definition:Instructions.h:764
llvm::AtomicRMWInst::Min
@ Min
*p = old <signed v ? old : v
Definition:Instructions.h:734
llvm::AtomicRMWInst::Or
@ Or
*p = old | v
Definition:Instructions.h:728
llvm::AtomicRMWInst::Sub
@ Sub
*p = old - v
Definition:Instructions.h:722
llvm::AtomicRMWInst::And
@ And
*p = old & v
Definition:Instructions.h:724
llvm::AtomicRMWInst::Xor
@ Xor
*p = old ^ v
Definition:Instructions.h:730
llvm::AtomicRMWInst::USubSat
@ USubSat
*p = usub.sat(old, v) usub.sat matches the behavior of llvm.usub.sat.
Definition:Instructions.h:768
llvm::AtomicRMWInst::FSub
@ FSub
*p = old - v
Definition:Instructions.h:744
llvm::AtomicRMWInst::UIncWrap
@ UIncWrap
Increment one up to a maximum value.
Definition:Instructions.h:756
llvm::AtomicRMWInst::Max
@ Max
*p = old >signed v ? old : v
Definition:Instructions.h:732
llvm::AtomicRMWInst::UMin
@ UMin
*p = old <unsigned v ? old : v
Definition:Instructions.h:738
llvm::AtomicRMWInst::FMin
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
Definition:Instructions.h:752
llvm::AtomicRMWInst::UMax
@ UMax
*p = old >unsigned v ? old : v
Definition:Instructions.h:736
llvm::AtomicRMWInst::FMax
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
Definition:Instructions.h:748
llvm::AtomicRMWInst::UDecWrap
@ UDecWrap
Decrement one until a minimum value or zero.
Definition:Instructions.h:760
llvm::AtomicRMWInst::Xchg
@ Xchg
*p = v
Definition:Instructions.h:718
llvm::AtomicRMWInst::Nand
@ Nand
*p = ~(old & v)
Definition:Instructions.h:726
llvm::AttributeList
Definition:Attributes.h:490
llvm::AttributeList::FunctionIndex
@ FunctionIndex
Definition:Attributes.h:494
llvm::AttributeSet
Definition:Attributes.h:345
llvm::AttributeSet::hasAttributes
bool hasAttributes() const
Return true if attributes exists in this set.
Definition:Attributes.h:411
llvm::Attribute
Definition:Attributes.h:67
llvm::Attribute::AttrKind
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition:Attributes.h:86
llvm::Attribute::TombstoneKey
@ TombstoneKey
Use as Tombstone key for DenseMap of AttrKind.
Definition:Attributes.h:93
llvm::Attribute::None
@ None
No attributes have been set.
Definition:Attributes.h:88
llvm::Attribute::EmptyKey
@ EmptyKey
Use as Empty key for DenseMap of AttrKind.
Definition:Attributes.h:92
llvm::Attribute::EndAttrKinds
@ EndAttrKinds
Sentinel value useful for loops.
Definition:Attributes.h:91
llvm::BasicBlock
LLVM Basic Block Representation.
Definition:BasicBlock.h:61
llvm::BitCodeAbbrevOp
BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
Definition:BitCodes.h:33
llvm::BitCodeAbbrevOp::isChar6
static bool isChar6(char C)
isChar6 - Return true if this character is legal in the Char6 encoding.
Definition:BitCodes.h:82
llvm::BitCodeAbbrevOp::Blob
@ Blob
Definition:BitCodes.h:43
llvm::BitCodeAbbrevOp::Char6
@ Char6
Definition:BitCodes.h:42
llvm::BitCodeAbbrevOp::Fixed
@ Fixed
Definition:BitCodes.h:39
llvm::BitCodeAbbrevOp::Array
@ Array
Definition:BitCodes.h:41
llvm::BitCodeAbbrevOp::VBR
@ VBR
Definition:BitCodes.h:40
llvm::BitcodeWriter
Definition:BitcodeWriter.h:32
llvm::BitcodeWriter::writeThinLinkBitcode
void writeThinLinkBitcode(const Module &M, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the buffer specified...
Definition:BitcodeWriter.cpp:5559
llvm::BitcodeWriter::writeIndex
void writeIndex(const ModuleSummaryIndex *Index, const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex, const GVSummaryPtrSet *DecSummaries)
Definition:BitcodeWriter.cpp:5361
llvm::BitcodeWriter::copyStrtab
void copyStrtab(StringRef Strtab)
Copy the string table for another module into this bitcode file.
Definition:BitcodeWriter.cpp:5337
llvm::BitcodeWriter::writeStrtab
void writeStrtab()
Write the bitcode file's string table.
Definition:BitcodeWriter.cpp:5323
llvm::BitcodeWriter::~BitcodeWriter
~BitcodeWriter()
Definition:BitcodeWriter.cpp:5276
llvm::BitcodeWriter::writeSymtab
void writeSymtab()
Attempt to write a symbol table to the bitcode file.
Definition:BitcodeWriter.cpp:5291
llvm::BitcodeWriter::writeModule
void writeModule(const Module &M, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the buffer specified at construction time.
Definition:BitcodeWriter.cpp:5342
llvm::BitcodeWriter::BitcodeWriter
BitcodeWriter(SmallVectorImpl< char > &Buffer)
Create a BitcodeWriter that writes to Buffer.
Definition:BitcodeWriter.cpp:5266
llvm::BitstreamWriter
Definition:BitstreamWriter.h:31
llvm::BitstreamWriter::EmitAbbrev
unsigned EmitAbbrev(std::shared_ptr< BitCodeAbbrev > Abbv)
Emits the abbreviation Abbv to the stream.
Definition:BitstreamWriter.h:651
llvm::BitstreamWriter::markAndBlockFlushing
void markAndBlockFlushing()
For scenarios where the user wants to access a section of the stream to (for example) compute some ch...
Definition:BitstreamWriter.h:176
llvm::BitstreamWriter::getMarkedBufferAndResumeFlushing
StringRef getMarkedBufferAndResumeFlushing()
resumes flushing, but does not flush, and returns the section in the internal buffer starting from th...
Definition:BitstreamWriter.h:186
llvm::BitstreamWriter::EmitRecord
void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev=0)
EmitRecord - Emit the specified record to the stream, using an abbrev if we have one to compress the ...
Definition:BitstreamWriter.h:571
llvm::BitstreamWriter::Emit
void Emit(uint32_t Val, unsigned NumBits)
Definition:BitstreamWriter.h:282
llvm::BitstreamWriter::ExitBlock
void ExitBlock()
Definition:BitstreamWriter.h:390
llvm::BitstreamWriter::EmitRecordWithBlob
void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals, StringRef Blob)
EmitRecordWithBlob - Emit the specified record to the stream, using an abbrev that includes a blob at...
Definition:BitstreamWriter.h:601
llvm::BitstreamWriter::EmitBlockInfoAbbrev
unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr< BitCodeAbbrev > Abbv)
EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified BlockID.
Definition:BitstreamWriter.h:693
llvm::BitstreamWriter::EnterBlockInfoBlock
void EnterBlockInfoBlock()
EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
Definition:BitstreamWriter.h:663
llvm::BitstreamWriter::BackpatchWord
void BackpatchWord(uint64_t BitNo, unsigned Val)
Definition:BitstreamWriter.h:272
llvm::BitstreamWriter::BackpatchWord64
void BackpatchWord64(uint64_t BitNo, uint64_t Val)
Definition:BitstreamWriter.h:277
llvm::BitstreamWriter::EnterSubblock
void EnterSubblock(unsigned BlockID, unsigned CodeLen)
Definition:BitstreamWriter.h:363
llvm::BitstreamWriter::GetCurrentBitNo
uint64_t GetCurrentBitNo() const
Retrieve the current position in the stream, in bits.
Definition:BitstreamWriter.h:194
llvm::BitstreamWriter::EmitRecordWithAbbrev
void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals)
EmitRecordWithAbbrev - Emit a record with the specified abbreviation.
Definition:BitstreamWriter.h:591
llvm::BlockAddress
The address of a basic block.
Definition:Constants.h:893
llvm::BlockAddress::lookup
static BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
Definition:Constants.cpp:1915
llvm::BranchInst
Conditional or Unconditional Branch instruction.
Definition:Instructions.h:3016
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition:InstrTypes.h:1112
llvm::CallBase::getOperandBundleAt
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
Definition:InstrTypes.h:2022
llvm::CallBase::getNumOperandBundles
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
Definition:InstrTypes.h:1966
llvm::CallBase::getCallingConv
CallingConv::ID getCallingConv() const
Definition:InstrTypes.h:1399
llvm::CallBase::getCalledOperand
Value * getCalledOperand() const
Definition:InstrTypes.h:1334
llvm::CallBase::getArgOperand
Value * getArgOperand(unsigned i) const
Definition:InstrTypes.h:1286
llvm::CallBase::getFunctionType
FunctionType * getFunctionType() const
Definition:InstrTypes.h:1199
llvm::CallBase::arg_size
unsigned arg_size() const
Definition:InstrTypes.h:1284
llvm::CallBase::getAttributes
AttributeList getAttributes() const
Return the attributes for this call.
Definition:InstrTypes.h:1417
llvm::CallBase::hasOperandBundles
bool hasOperandBundles() const
Return true if this User has any operand bundles.
Definition:InstrTypes.h:1971
llvm::CallBrInst
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
Definition:Instructions.h:3830
llvm::CallBrInst::getIndirectDest
BasicBlock * getIndirectDest(unsigned i) const
Definition:Instructions.h:3938
llvm::CallBrInst::getDefaultDest
BasicBlock * getDefaultDest() const
Definition:Instructions.h:3935
llvm::CallBrInst::getNumIndirectDests
unsigned getNumIndirectDests() const
Return the number of callbr indirect dest labels.
Definition:Instructions.h:3920
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition:Instructions.h:1479
llvm::CallInst::isNoTailCall
bool isNoTailCall() const
Definition:Instructions.h:1596
llvm::CallInst::isTailCall
bool isTailCall() const
Definition:Instructions.h:1589
llvm::CallInst::isMustTailCall
bool isMustTailCall() const
Definition:Instructions.h:1594
llvm::Comdat
Definition:Comdat.h:33
llvm::Comdat::Largest
@ Largest
The linker will choose the largest COMDAT.
Definition:Comdat.h:38
llvm::Comdat::SameSize
@ SameSize
The data referenced by the COMDAT must be the same size.
Definition:Comdat.h:40
llvm::Comdat::Any
@ Any
The linker may choose any COMDAT.
Definition:Comdat.h:36
llvm::Comdat::NoDeduplicate
@ NoDeduplicate
No deduplication is performed.
Definition:Comdat.h:39
llvm::Comdat::ExactMatch
@ ExactMatch
The data referenced by the COMDAT must be the same.
Definition:Comdat.h:37
llvm::ConstantArray::get
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
Definition:Constants.cpp:1312
llvm::ConstantDataArray::get
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
Definition:Constants.h:709
llvm::ConstantDataSequential
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
Definition:Constants.h:587
llvm::ConstantExpr
A constant value that is initialized with an expression using other constant values.
Definition:Constants.h:1108
llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
Definition:Constants.cpp:2268
llvm::ConstantFP
ConstantFP - Floating Point Values [float, double].
Definition:Constants.h:271
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition:Constants.h:83
llvm::ConstantRange
This class represents a range of values.
Definition:ConstantRange.h:47
llvm::ConstantRange::getLower
const APInt & getLower() const
Return the lower value for this range.
Definition:ConstantRange.h:203
llvm::ConstantRange::getUpper
const APInt & getUpper() const
Return the upper value for this range.
Definition:ConstantRange.h:206
llvm::ConstantRange::getBitWidth
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
Definition:ConstantRange.h:209
llvm::ConstantRange::sextOrTrunc
ConstantRange sextOrTrunc(uint32_t BitWidth) const
Make this range have the bit width given by BitWidth.
Definition:ConstantRange.cpp:926
llvm::Constant
This is an important base class in LLVM.
Definition:Constant.h:42
llvm::DIArgList
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
Definition:DebugInfoMetadata.h:3976
llvm::DIAssignID
Assignment ID.
Definition:DebugInfoMetadata.h:309
llvm::DIBasicType
Basic type, like 'int' or 'float'.
Definition:DebugInfoMetadata.h:823
llvm::DICommonBlock
Debug common block.
Definition:DebugInfoMetadata.h:3403
llvm::DICompileUnit
Compile unit.
Definition:DebugInfoMetadata.h:1469
llvm::DICompositeType
Composite types.
Definition:DebugInfoMetadata.h:1174
llvm::DIDerivedType
Derived types.
Definition:DebugInfoMetadata.h:997
llvm::DIEnumerator
Enumeration value.
Definition:DebugInfoMetadata.h:459
llvm::DIExpression
DWARF expression.
Definition:DebugInfoMetadata.h:2763
llvm::DIFile
File.
Definition:DebugInfoMetadata.h:573
llvm::DIGenericSubrange
Definition:DebugInfoMetadata.h:411
llvm::DIGlobalVariableExpression
A pair of DIGlobalVariable and DIExpression.
Definition:DebugInfoMetadata.h:3761
llvm::DIGlobalVariable
Global variables.
Definition:DebugInfoMetadata.h:3315
llvm::DIImportedEntity
An imported module (C++ using directive or similar).
Definition:DebugInfoMetadata.h:3696
llvm::DILabel
Label.
Definition:DebugInfoMetadata.h:3551
llvm::DILexicalBlockFile
Definition:DebugInfoMetadata.h:2336
llvm::DILexicalBlock
Debug lexical block.
Definition:DebugInfoMetadata.h:2283
llvm::DILocalVariable
Local variable.
Definition:DebugInfoMetadata.h:3460
llvm::DILocation
Debug location.
Definition:DebugInfoMetadata.h:1988
llvm::DIMacroFile
Macro file.
Definition:DebugInfoMetadata.h:3910
llvm::DIMacro
Macro.
Definition:DebugInfoMetadata.h:3856
llvm::DIModule
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
Definition:DebugInfoMetadata.h:2511
llvm::DINamespace
Debug lexical block.
Definition:DebugInfoMetadata.h:2462
llvm::DIObjCProperty
Definition:DebugInfoMetadata.h:3614
llvm::DIStringType
String type, Fortran CHARACTER(n)
Definition:DebugInfoMetadata.h:905
llvm::DISubprogram
Subprogram description.
Definition:DebugInfoMetadata.h:1710
llvm::DISubrange
Array subrange.
Definition:DebugInfoMetadata.h:348
llvm::DISubroutineType
Type array for a subprogram.
Definition:DebugInfoMetadata.h:1412
llvm::DITemplateTypeParameter
Definition:DebugInfoMetadata.h:2607
llvm::DITemplateValueParameter
Definition:DebugInfoMetadata.h:2646
llvm::DWARFExpression::Operation
This class represents an Operation in the Expression.
Definition:DWARFExpression.h:32
llvm::DbgLabelRecord
Records a position in IR for a source label (DILabel).
Definition:DebugProgramInstruction.h:231
llvm::DbgRecord
Base class for non-instruction debug metadata records that have positions within IR.
Definition:DebugProgramInstruction.h:134
llvm::DbgRecord::getDebugLoc
DebugLoc getDebugLoc() const
Definition:DebugProgramInstruction.h:208
llvm::DbgVariableRecord
Record of a variable value-assignment, aka a non instruction representation of the dbg....
Definition:DebugProgramInstruction.h:270
llvm::DbgVariableRecord::isDbgValue
bool isDbgValue() const
Definition:DebugProgramInstruction.h:410
llvm::DbgVariableRecord::getAssignID
DIAssignID * getAssignID() const
Definition:DebugProgramInstruction.cpp:485
llvm::DbgVariableRecord::isDbgAssign
bool isDbgAssign() const
Definition:DebugProgramInstruction.h:506
llvm::DbgVariableRecord::getExpression
DIExpression * getExpression() const
Definition:DebugProgramInstruction.h:453
llvm::DbgVariableRecord::getVariable
DILocalVariable * getVariable() const
Definition:DebugProgramInstruction.h:449
llvm::DbgVariableRecord::getRawLocation
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
Definition:DebugProgramInstruction.h:460
llvm::DbgVariableRecord::isDbgDeclare
bool isDbgDeclare() const
Definition:DebugProgramInstruction.h:409
llvm::DbgVariableRecord::getRawAddress
Metadata * getRawAddress() const
Definition:DebugProgramInstruction.h:509
llvm::DbgVariableRecord::getAddressExpression
DIExpression * getAddressExpression() const
Definition:DebugProgramInstruction.h:514
llvm::DenseMapBase::size
unsigned size() const
Definition:DenseMap.h:99
llvm::DenseMapBase::count
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition:DenseMap.h:152
llvm::DenseMapBase::contains
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
Definition:DenseMap.h:147
llvm::DenseMapBase::insert
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition:DenseMap.h:211
llvm::DenseMap
Definition:DenseMap.h:727
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition:DenseSet.h:278
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition:Error.h:160
llvm::ExtractValueInst
This instruction extracts a struct member or array element value from an aggregate value.
Definition:Instructions.h:2397
llvm::ExtractValueInst::idx_end
idx_iterator idx_end() const
Definition:Instructions.h:2434
llvm::ExtractValueInst::idx_begin
idx_iterator idx_begin() const
Definition:Instructions.h:2433
llvm::FunctionSummary
Function summary information to aid decisions and implementation of importing.
Definition:ModuleSummaryIndex.h:720
llvm::FunctionSummary::ForceSummaryHotnessType
ForceSummaryHotnessType
Types for -force-summary-edges-cold debugging option.
Definition:ModuleSummaryIndex.h:726
llvm::FunctionSummary::FSHT_None
@ FSHT_None
Definition:ModuleSummaryIndex.h:727
llvm::Function
Definition:Function.h:63
llvm::GenericDINode
Generic tagged DWARF-like metadata node.
Definition:DebugInfoMetadata.h:236
llvm::GlobalAlias
Definition:GlobalAlias.h:28
llvm::GlobalIFunc
Definition:GlobalIFunc.h:34
llvm::GlobalObject
Definition:GlobalObject.h:27
llvm::GlobalObject::getAllMetadata
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
Definition:Metadata.cpp:1521
llvm::GlobalObject::setAlignment
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
Definition:Globals.cpp:143
llvm::GlobalObject::setSection
void setSection(StringRef S)
Change the section for this global.
Definition:Globals.cpp:273
llvm::GlobalValueSummary
Function and variable summary information to aid decisions and implementation of importing.
Definition:ModuleSummaryIndex.h:466
llvm::GlobalValueSummary::flags
GVFlags flags() const
Get the flags for this GlobalValue (see struct GVFlags).
Definition:ModuleSummaryIndex.h:595
llvm::GlobalValueSummary::modulePath
StringRef modulePath() const
Get the path to the module containing this function.
Definition:ModuleSummaryIndex.h:592
llvm::GlobalValueSummary::refs
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
Definition:ModuleSummaryIndex.h:644
llvm::GlobalValue
Definition:GlobalValue.h:48
llvm::GlobalValue::getVisibility
VisibilityTypes getVisibility() const
Definition:GlobalValue.h:249
llvm::GlobalValue::isLocalLinkage
static bool isLocalLinkage(LinkageTypes Linkage)
Definition:GlobalValue.h:410
llvm::GlobalValue::getLinkage
LinkageTypes getLinkage() const
Definition:GlobalValue.h:547
llvm::GlobalValue::dropLLVMManglingEscape
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
Definition:GlobalValue.h:568
llvm::GlobalValue::getThreadLocalMode
ThreadLocalMode getThreadLocalMode() const
Definition:GlobalValue.h:272
llvm::GlobalValue::DefaultStorageClass
@ DefaultStorageClass
Definition:GlobalValue.h:74
llvm::GlobalValue::DLLExportStorageClass
@ DLLExportStorageClass
Function to be accessible from DLL.
Definition:GlobalValue.h:76
llvm::GlobalValue::DLLImportStorageClass
@ DLLImportStorageClass
Function to be imported from DLL.
Definition:GlobalValue.h:75
llvm::GlobalValue::getGUID
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition:GlobalValue.h:596
llvm::GlobalValue::DefaultVisibility
@ DefaultVisibility
The GV is visible.
Definition:GlobalValue.h:67
llvm::GlobalValue::HiddenVisibility
@ HiddenVisibility
The GV is hidden.
Definition:GlobalValue.h:68
llvm::GlobalValue::ProtectedVisibility
@ ProtectedVisibility
The GV is protected.
Definition:GlobalValue.h:69
llvm::GlobalValue::getUnnamedAddr
UnnamedAddr getUnnamedAddr() const
Definition:GlobalValue.h:229
llvm::GlobalValue::LinkageTypes
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition:GlobalValue.h:51
llvm::GlobalValue::PrivateLinkage
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition:GlobalValue.h:60
llvm::GlobalValue::CommonLinkage
@ CommonLinkage
Tentative definitions.
Definition:GlobalValue.h:62
llvm::GlobalValue::InternalLinkage
@ InternalLinkage
Rename collisions when linking (static functions).
Definition:GlobalValue.h:59
llvm::GlobalValue::LinkOnceAnyLinkage
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
Definition:GlobalValue.h:54
llvm::GlobalValue::WeakODRLinkage
@ WeakODRLinkage
Same, but only replaced by something equivalent.
Definition:GlobalValue.h:57
llvm::GlobalValue::ExternalLinkage
@ ExternalLinkage
Externally visible function.
Definition:GlobalValue.h:52
llvm::GlobalValue::WeakAnyLinkage
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
Definition:GlobalValue.h:56
llvm::GlobalValue::AppendingLinkage
@ AppendingLinkage
Special purpose, only applies to global arrays.
Definition:GlobalValue.h:58
llvm::GlobalValue::AvailableExternallyLinkage
@ AvailableExternallyLinkage
Available for inspection, not emission.
Definition:GlobalValue.h:53
llvm::GlobalValue::ExternalWeakLinkage
@ ExternalWeakLinkage
ExternalWeak linkage description.
Definition:GlobalValue.h:61
llvm::GlobalValue::LinkOnceODRLinkage
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
Definition:GlobalValue.h:55
llvm::GlobalValue::getDLLStorageClass
DLLStorageClassTypes getDLLStorageClass() const
Definition:GlobalValue.h:276
llvm::GlobalVarSummary
Global variable summary information to aid decisions and implementation of importing.
Definition:ModuleSummaryIndex.h:1144
llvm::GlobalVariable
Definition:GlobalVariable.h:39
llvm::InlineAsm
Definition:InlineAsm.h:34
llvm::InsertValueInst
This instruction inserts a struct field of array element value into an aggregate value.
Definition:Instructions.h:2485
llvm::InsertValueInst::idx_end
idx_iterator idx_end() const
Definition:Instructions.h:2532
llvm::InsertValueInst::idx_begin
idx_iterator idx_begin() const
Definition:Instructions.h:2531
llvm::Instruction
Definition:Instruction.h:68
llvm::Instruction::isCast
bool isCast() const
Definition:Instruction.h:319
llvm::InvokeInst
Invoke instruction.
Definition:Instructions.h:3670
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition:LLVMContext.h:67
llvm::LandingPadInst
The landingpad instruction holds all of the information necessary to generate correct exception handl...
Definition:Instructions.h:2840
llvm::LandingPadInst::isCleanup
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
Definition:Instructions.h:2885
llvm::LandingPadInst::getNumClauses
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
Definition:Instructions.h:2910
llvm::LandingPadInst::Catch
@ Catch
Definition:Instructions.h:2852
llvm::LandingPadInst::Filter
@ Filter
Definition:Instructions.h:2852
llvm::LandingPadInst::isCatch
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
Definition:Instructions.h:2900
llvm::LandingPadInst::getClause
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
Definition:Instructions.h:2895
llvm::MDNode
Metadata node.
Definition:Metadata.h:1073
llvm::MDOperand
Tracking metadata reference owned by Metadata.
Definition:Metadata.h:895
llvm::MDTuple
Tuple of metadata.
Definition:Metadata.h:1479
llvm::MachineBasicBlock::empty
bool empty() const
Definition:MachineBasicBlock.h:327
llvm::MapVector
This class implements a map that also provides access to all stored values in a deterministic order.
Definition:MapVector.h:36
llvm::MapVector::empty
bool empty() const
Definition:MapVector.h:79
llvm::MemoryBufferRef
Definition:MemoryBufferRef.h:22
llvm::MemoryBufferRef::getBufferSize
size_t getBufferSize() const
Definition:MemoryBufferRef.h:37
llvm::MemoryBufferRef::getBufferStart
const char * getBufferStart() const
Definition:MemoryBufferRef.h:35
llvm::MemoryBufferRef::getBufferEnd
const char * getBufferEnd() const
Definition:MemoryBufferRef.h:36
llvm::Metadata
Root of the metadata hierarchy.
Definition:Metadata.h:62
llvm::ModuleSummaryIndex
Class to hold module path string table and global value map, and encapsulate methods for operating on...
Definition:ModuleSummaryIndex.h:1345
llvm::ModuleSummaryIndex::BitcodeSummaryVersion
static constexpr uint64_t BitcodeSummaryVersion
Definition:ModuleSummaryIndex.h:1470
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition:Module.h:65
llvm::NamedMDNode
A tuple of MDNodes.
Definition:Metadata.h:1737
llvm::PHINode
Definition:Instructions.h:2600
llvm::PHINode::getIncomingBlock
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Definition:Instructions.h:2695
llvm::PHINode::getIncomingValue
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
Definition:Instructions.h:2675
llvm::PHINode::getNumIncomingValues
unsigned getNumIncomingValues() const
Return the number of incoming edges.
Definition:Instructions.h:2671
llvm::PointerType::getUnqual
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
Definition:DerivedTypes.h:686
llvm::Record
Definition:Record.h:1596
llvm::SHA1
A class that wrap the SHA1 algorithm.
Definition:SHA1.h:26
llvm::SetVector::size
size_type size() const
Determine the number of elements in the SetVector.
Definition:SetVector.h:98
llvm::SetVector::empty
bool empty() const
Determine if the SetVector is empty or not.
Definition:SetVector.h:93
llvm::SetVector::insert
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition:SetVector.h:162
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition:SmallPtrSet.h:519
llvm::SmallSetVector
A SetVector that performs no allocations if smaller than a certain size.
Definition:SetVector.h:370
llvm::SmallString
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition:SmallString.h:26
llvm::SmallString::append
void append(StringRef RHS)
Append from a StringRef.
Definition:SmallString.h:68
llvm::SmallVectorBase::empty
bool empty() const
Definition:SmallVector.h:81
llvm::SmallVectorBase::size
size_t size() const
Definition:SmallVector.h:78
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition:SmallVector.h:573
llvm::SmallVectorImpl::assign
void assign(size_type NumElts, ValueParamT Elt)
Definition:SmallVector.h:704
llvm::SmallVectorImpl::reserve
void reserve(size_type N)
Definition:SmallVector.h:663
llvm::SmallVectorImpl::append
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
Definition:SmallVector.h:683
llvm::SmallVectorImpl::insert
iterator insert(iterator I, T &&Elt)
Definition:SmallVector.h:805
llvm::SmallVectorImpl::clear
void clear()
Definition:SmallVector.h:610
llvm::SmallVectorImpl::resize
void resize(size_type N)
Definition:SmallVector.h:638
llvm::SmallVectorTemplateBase::push_back
void push_back(const T &Elt)
Definition:SmallVector.h:413
llvm::SmallVectorTemplateCommon::front
reference front()
Definition:SmallVector.h:299
llvm::SmallVectorTemplateCommon::data
pointer data()
Return a pointer to the vector's buffer, even if empty().
Definition:SmallVector.h:286
llvm::SmallVectorTemplateCommon::begin
iterator begin()
Definition:SmallVector.h:267
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition:SmallVector.h:1196
llvm::StringMapEntryStorage::getValue
const ValueTy & getValue() const
Definition:StringMapEntry.h:81
llvm::StringMapEntry
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition:StringMapEntry.h:102
llvm::StringMapEntry::getKey
StringRef getKey() const
Definition:StringMapEntry.h:108
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::StringRef::empty
constexpr bool empty() const
empty - Check if the string is empty.
Definition:StringRef.h:147
llvm::StringRef::begin
iterator begin() const
Definition:StringRef.h:116
llvm::StringRef::end
iterator end() const
Definition:StringRef.h:118
llvm::StringTableBuilder
Utility for building string tables with deduplicated suffixes.
Definition:StringTableBuilder.h:24
llvm::StringTableBuilder::finalizeInOrder
void finalizeInOrder()
Finalize the string table without reording it.
Definition:StringTableBuilder.cpp:134
llvm::StringTableBuilder::write
void write(raw_ostream &OS) const
Definition:StringTableBuilder.cpp:61
llvm::StringTableBuilder::add
size_t add(CachedHashStringRef S)
Add a string to the builder.
Definition:StringTableBuilder.cpp:202
llvm::StringTableBuilder::getSize
size_t getSize() const
Definition:StringTableBuilder.h:80
llvm::StructType
Class to represent struct types.
Definition:DerivedTypes.h:218
llvm::SwitchInst
Multiway switch.
Definition:Instructions.h:3154
llvm::TargetExtType
Class to represent target extensions types, which are generally unintrospectable from target-independ...
Definition:DerivedTypes.h:744
llvm::Target
Target - Wrapper for Target specific information.
Definition:TargetRegistry.h:144
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition:Triple.h:44
llvm::Triple::ArchType
ArchType
Definition:Triple.h:46
llvm::Triple::x86
@ x86
Definition:Triple.h:85
llvm::Triple::x86_64
@ x86_64
Definition:Triple.h:86
llvm::Triple::arm
@ arm
Definition:Triple.h:49
llvm::Triple::ppc64
@ ppc64
Definition:Triple.h:71
llvm::Triple::ppc
@ ppc
Definition:Triple.h:69
llvm::Triple::thumb
@ thumb
Definition:Triple.h:83
llvm::Triple::XCOFF
@ XCOFF
Definition:Triple.h:317
llvm::Triple::MachO
@ MachO
Definition:Triple.h:314
llvm::Triple::DXContainer
@ DXContainer
Definition:Triple.h:311
llvm::Triple::ELF
@ ELF
Definition:Triple.h:312
llvm::Triple::Wasm
@ Wasm
Definition:Triple.h:316
llvm::Triple::GOFF
@ GOFF
Definition:Triple.h:313
llvm::Triple::COFF
@ COFF
Definition:Triple.h:310
llvm::Triple::SPIRV
@ SPIRV
Definition:Triple.h:315
llvm::Triple::UnknownObjectFormat
@ UnknownObjectFormat
Definition:Triple.h:308
llvm::Triple::AMD
@ AMD
Definition:Triple.h:192
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition:Type.h:45
llvm::Type::isX86_FP80Ty
bool isX86_FP80Ty() const
Return true if this is x86 long double.
Definition:Type.h:159
llvm::Type::isFloatTy
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition:Type.h:153
llvm::Type::isBFloatTy
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
Definition:Type.h:145
llvm::Type::X86_AMXTyID
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
Definition:Type.h:66
llvm::Type::FunctionTyID
@ FunctionTyID
Functions.
Definition:Type.h:71
llvm::Type::ArrayTyID
@ ArrayTyID
Arrays.
Definition:Type.h:74
llvm::Type::TypedPointerTyID
@ TypedPointerTyID
Typed pointer used by some GPU targets.
Definition:Type.h:77
llvm::Type::HalfTyID
@ HalfTyID
16-bit floating point type
Definition:Type.h:56
llvm::Type::TargetExtTyID
@ TargetExtTyID
Target extension type.
Definition:Type.h:78
llvm::Type::VoidTyID
@ VoidTyID
type with no size
Definition:Type.h:63
llvm::Type::ScalableVectorTyID
@ ScalableVectorTyID
Scalable SIMD vector type.
Definition:Type.h:76
llvm::Type::LabelTyID
@ LabelTyID
Labels.
Definition:Type.h:64
llvm::Type::FloatTyID
@ FloatTyID
32-bit floating point type
Definition:Type.h:58
llvm::Type::StructTyID
@ StructTyID
Structures.
Definition:Type.h:73
llvm::Type::IntegerTyID
@ IntegerTyID
Arbitrary bit width integers.
Definition:Type.h:70
llvm::Type::FixedVectorTyID
@ FixedVectorTyID
Fixed width SIMD vector type.
Definition:Type.h:75
llvm::Type::BFloatTyID
@ BFloatTyID
16-bit floating point type (7-bit significand)
Definition:Type.h:57
llvm::Type::DoubleTyID
@ DoubleTyID
64-bit floating point type
Definition:Type.h:59
llvm::Type::X86_FP80TyID
@ X86_FP80TyID
80-bit floating point type (X87)
Definition:Type.h:60
llvm::Type::PPC_FP128TyID
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
Definition:Type.h:62
llvm::Type::MetadataTyID
@ MetadataTyID
Metadata.
Definition:Type.h:65
llvm::Type::TokenTyID
@ TokenTyID
Tokens.
Definition:Type.h:67
llvm::Type::PointerTyID
@ PointerTyID
Pointers.
Definition:Type.h:72
llvm::Type::FP128TyID
@ FP128TyID
128-bit floating point type (112-bit significand)
Definition:Type.h:61
llvm::Type::isPPC_FP128Ty
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
Definition:Type.h:165
llvm::Type::isFP128Ty
bool isFP128Ty() const
Return true if this is 'fp128'.
Definition:Type.h:162
llvm::Type::isHalfTy
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
Definition:Type.h:142
llvm::Type::isDoubleTy
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition:Type.h:156
llvm::Type::getScalarType
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition:Type.h:355
llvm::User
Definition:User.h:44
llvm::ValueAsMetadata
Value wrapper in the Metadata hierarchy.
Definition:Metadata.h:454
llvm::ValueAsMetadata::getValue
Value * getValue() const
Definition:Metadata.h:494
llvm::ValueEnumerator
Definition:ValueEnumerator.h:43
llvm::ValueEnumerator::getTypeID
unsigned getTypeID(Type *T) const
Definition:ValueEnumerator.h:166
llvm::ValueEnumerator::getMetadataID
unsigned getMetadataID(const Metadata *MD) const
Definition:ValueEnumerator.h:152
llvm::ValueEnumerator::UseListOrders
UseListOrderStack UseListOrders
Definition:ValueEnumerator.h:54
llvm::ValueEnumerator::ValueList
std::vector< std::pair< const Value *, unsigned > > ValueList
Definition:ValueEnumerator.h:48
llvm::ValueEnumerator::getNonMDStrings
ArrayRef< const Metadata * > getNonMDStrings() const
Get the non-MDString metadata for this block.
Definition:ValueEnumerator.h:208
llvm::ValueEnumerator::getInstructionID
unsigned getInstructionID(const Instruction *I) const
Definition:ValueEnumerator.cpp:503
llvm::ValueEnumerator::getAttributeListID
unsigned getAttributeListID(AttributeList PAL) const
Definition:ValueEnumerator.h:175
llvm::ValueEnumerator::incorporateFunction
void incorporateFunction(const Function &F)
incorporateFunction/purgeFunction - If you'd like to deal with a function, use these two methods to g...
Definition:ValueEnumerator.cpp:1058
llvm::ValueEnumerator::getFunctionConstantRange
void getFunctionConstantRange(unsigned &Start, unsigned &End) const
getFunctionConstantRange - Return the range of values that corresponds to function-local constants.
Definition:ValueEnumerator.h:192
llvm::ValueEnumerator::getAttributeGroupID
unsigned getAttributeGroupID(IndexAndAttrSet Group) const
Definition:ValueEnumerator.h:182
llvm::ValueEnumerator::hasMDs
bool hasMDs() const
Check whether the current block has any metadata to emit.
Definition:ValueEnumerator.h:200
llvm::ValueEnumerator::getComdatID
unsigned getComdatID(const Comdat *C) const
Definition:ValueEnumerator.cpp:509
llvm::ValueEnumerator::computeBitsRequiredForTypeIndices
uint64_t computeBitsRequiredForTypeIndices() const
Definition:ValueEnumerator.cpp:1193
llvm::ValueEnumerator::getValueID
unsigned getValueID(const Value *V) const
Definition:ValueEnumerator.cpp:519
llvm::ValueEnumerator::getMetadataOrNullID
unsigned getMetadataOrNullID(const Metadata *MD) const
Definition:ValueEnumerator.h:158
llvm::ValueEnumerator::getAttributeGroups
const std::vector< IndexAndAttrSet > & getAttributeGroups() const
Definition:ValueEnumerator.h:220
llvm::ValueEnumerator::getValues
const ValueList & getValues() const
Definition:ValueEnumerator.h:197
llvm::ValueEnumerator::getGlobalBasicBlockID
unsigned getGlobalBasicBlockID(const BasicBlock *BB) const
getGlobalBasicBlockID - This returns the function-specific ID for the specified basic block.
Definition:ValueEnumerator.cpp:1184
llvm::ValueEnumerator::setInstructionID
void setInstructionID(const Instruction *I)
Definition:ValueEnumerator.cpp:515
llvm::ValueEnumerator::getBasicBlocks
const std::vector< const BasicBlock * > & getBasicBlocks() const
Definition:ValueEnumerator.h:214
llvm::ValueEnumerator::getAttributeLists
const std::vector< AttributeList > & getAttributeLists() const
Definition:ValueEnumerator.h:218
llvm::ValueEnumerator::shouldPreserveUseListOrder
bool shouldPreserveUseListOrder() const
Definition:ValueEnumerator.h:164
llvm::ValueEnumerator::purgeFunction
void purgeFunction()
Definition:ValueEnumerator.cpp:1159
llvm::ValueEnumerator::getComdats
const ComdatSetType & getComdats() const
Definition:ValueEnumerator.h:224
llvm::ValueEnumerator::TypeList
std::vector< Type * > TypeList
Definition:ValueEnumerator.h:45
llvm::ValueEnumerator::getMDStrings
ArrayRef< const Metadata * > getMDStrings() const
Get the MDString metadata for this block.
Definition:ValueEnumerator.h:203
llvm::ValueEnumerator::IndexAndAttrSet
std::pair< unsigned, AttributeSet > IndexAndAttrSet
Attribute groups as encoded in bitcode are almost AttributeSets, but they include the AttributeList i...
Definition:ValueEnumerator.h:52
llvm::ValueEnumerator::getTypes
const TypeList & getTypes() const
Definition:ValueEnumerator.h:212
llvm::ValueSymbolTable
This class provides a symbol table of name/value pairs.
Definition:ValueSymbolTable.h:39
llvm::ValueSymbolTable::empty
bool empty() const
Definition:ValueSymbolTable.h:86
llvm::Value
LLVM Value Representation.
Definition:Value.h:74
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition:Value.h:255
llvm::Value::setName
void setName(const Twine &Name)
Change the name of the value.
Definition:Value.cpp:377
llvm::Value::getContext
LLVMContext & getContext() const
All values hold a context through their type.
Definition:Value.cpp:1075
llvm::Value::takeName
void takeName(Value *V)
Transfer the name from V to this value.
Definition:Value.cpp:383
llvm::cl::opt
Definition:CommandLine.h:1423
llvm::detail::DenseSetImpl::insert
std::pair< iterator, bool > insert(const ValueT &V)
Definition:DenseSet.h:213
llvm::detail::DenseSetImpl::contains
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
Definition:DenseSet.h:193
llvm::memprof::CallStackRadixTreeBuilder
Definition:MemProf.h:1122
llvm::memprof::CallStackRadixTreeBuilder::build
void build(llvm::MapVector< CallStackId, llvm::SmallVector< FrameIdTy > > &&MemProfCallStackData, const llvm::DenseMap< FrameIdTy, LinearFrameId > *MemProfFrameIndexes, llvm::DenseMap< FrameIdTy, FrameStat > &FrameHistogram)
Definition:MemProf.cpp:380
llvm::memprof::CallStackRadixTreeBuilder::getRadixArray
ArrayRef< LinearFrameId > getRadixArray() const
Definition:MemProf.h:1168
llvm::memprof::CallStackRadixTreeBuilder::takeCallStackPos
llvm::DenseMap< CallStackId, LinearCallStackId > takeCallStackPos()
Definition:MemProf.h:1170
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition:raw_ostream.h:52
llvm::raw_ostream::write
raw_ostream & write(unsigned char C)
Definition:raw_ostream.cpp:225
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition:raw_ostream.h:661
uint32_t
uint64_t
uint8_t
unsigned
Comdat.h
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
ErrorHandling.h
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition:ErrorHandling.h:143
Error.h
false
Definition:StackSlotColoring.cpp:193
llvm::AArch64CC::VS
@ VS
Definition:AArch64BaseInfo.h:261
llvm::AArch64CC::AL
@ AL
Definition:AArch64BaseInfo.h:269
llvm::AArch64PACKey::IA
@ IA
Definition:AArch64BaseInfo.h:875
llvm::AMDGPU::HSAMD::Kernel::Key::Attrs
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
Definition:AMDGPUMetadata.h:393
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition:AMDGPUMetadata.h:487
llvm::ARM_MB::ST
@ ST
Definition:ARMBaseInfo.h:73
llvm::ARM::PredBlockMask::TET
@ TET
llvm::ARM::ProfileKind::M
@ M
llvm::COFF::Entry
@ Entry
Definition:COFF.h:844
llvm::CallingConv::C
@ C
The default llvm calling convention, compatible with C.
Definition:CallingConv.h:34
llvm::IndexedCGData::Version
const uint64_t Version
Definition:CodeGenData.h:286
llvm::M68k::MemAddrModeKind::V
@ V
llvm::M68k::MemAddrModeKind::p
@ p
llvm::NVPTXAS::AddressSpace
AddressSpace
Definition:NVPTXAddrSpace.h:20
llvm::PPC::getPredicate
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
Definition:PPCPredicates.h:87
llvm::RISCVFenceField::W
@ W
Definition:RISCVBaseInfo.h:374
llvm::SIEncodingFamily::VI
@ VI
Definition:SIDefines.h:37
llvm::SIEncodingFamily::SI
@ SI
Definition:SIDefines.h:36
llvm::Sched::Source
@ Source
Definition:TargetLowering.h:102
llvm::WinEH::EncodingType::CE
@ CE
Windows NT (Windows on ARM)
llvm::X86AS::FS
@ FS
Definition:X86.h:211
llvm::bitc::BITCODE_CURRENT_EPOCH
@ BITCODE_CURRENT_EPOCH
Definition:LLVMBitCodes.h:81
llvm::bitc::TYPE_CODE_BFLOAT
@ TYPE_CODE_BFLOAT
Definition:LLVMBitCodes.h:174
llvm::bitc::TYPE_CODE_OPAQUE
@ TYPE_CODE_OPAQUE
Definition:LLVMBitCodes.h:143
llvm::bitc::TYPE_CODE_LABEL
@ TYPE_CODE_LABEL
Definition:LLVMBitCodes.h:142
llvm::bitc::TYPE_CODE_VOID
@ TYPE_CODE_VOID
Definition:LLVMBitCodes.h:139
llvm::bitc::TYPE_CODE_METADATA
@ TYPE_CODE_METADATA
Definition:LLVMBitCodes.h:162
llvm::bitc::TYPE_CODE_HALF
@ TYPE_CODE_HALF
Definition:LLVMBitCodes.h:150
llvm::bitc::TYPE_CODE_VECTOR
@ TYPE_CODE_VECTOR
Definition:LLVMBitCodes.h:153
llvm::bitc::TYPE_CODE_PPC_FP128
@ TYPE_CODE_PPC_FP128
Definition:LLVMBitCodes.h:160
llvm::bitc::TYPE_CODE_TARGET_TYPE
@ TYPE_CODE_TARGET_TYPE
Definition:LLVMBitCodes.h:179
llvm::bitc::TYPE_CODE_STRUCT_ANON
@ TYPE_CODE_STRUCT_ANON
Definition:LLVMBitCodes.h:166
llvm::bitc::TYPE_CODE_STRUCT_NAME
@ TYPE_CODE_STRUCT_NAME
Definition:LLVMBitCodes.h:167
llvm::bitc::TYPE_CODE_X86_FP80
@ TYPE_CODE_X86_FP80
Definition:LLVMBitCodes.h:158
llvm::bitc::TYPE_CODE_OPAQUE_POINTER
@ TYPE_CODE_OPAQUE_POINTER
Definition:LLVMBitCodes.h:177
llvm::bitc::TYPE_CODE_FLOAT
@ TYPE_CODE_FLOAT
Definition:LLVMBitCodes.h:140
llvm::bitc::TYPE_CODE_FUNCTION
@ TYPE_CODE_FUNCTION
Definition:LLVMBitCodes.h:170
llvm::bitc::TYPE_CODE_INTEGER
@ TYPE_CODE_INTEGER
Definition:LLVMBitCodes.h:144
llvm::bitc::TYPE_CODE_TOKEN
@ TYPE_CODE_TOKEN
Definition:LLVMBitCodes.h:172
llvm::bitc::TYPE_CODE_X86_AMX
@ TYPE_CODE_X86_AMX
Definition:LLVMBitCodes.h:175
llvm::bitc::TYPE_CODE_ARRAY
@ TYPE_CODE_ARRAY
Definition:LLVMBitCodes.h:152
llvm::bitc::TYPE_CODE_DOUBLE
@ TYPE_CODE_DOUBLE
Definition:LLVMBitCodes.h:141
llvm::bitc::TYPE_CODE_FP128
@ TYPE_CODE_FP128
Definition:LLVMBitCodes.h:159
llvm::bitc::TYPE_CODE_NUMENTRY
@ TYPE_CODE_NUMENTRY
Definition:LLVMBitCodes.h:136
llvm::bitc::TYPE_CODE_STRUCT_NAMED
@ TYPE_CODE_STRUCT_NAMED
Definition:LLVMBitCodes.h:168
llvm::bitc::METADATA_NAMESPACE
@ METADATA_NAMESPACE
Definition:LLVMBitCodes.h:364
llvm::bitc::METADATA_COMMON_BLOCK
@ METADATA_COMMON_BLOCK
Definition:LLVMBitCodes.h:384
llvm::bitc::METADATA_STRING_TYPE
@ METADATA_STRING_TYPE
Definition:LLVMBitCodes.h:381
llvm::bitc::METADATA_MACRO_FILE
@ METADATA_MACRO_FILE
Definition:LLVMBitCodes.h:374
llvm::bitc::METADATA_FILE
@ METADATA_FILE
Definition:LLVMBitCodes.h:356
llvm::bitc::METADATA_VALUE
@ METADATA_VALUE
Definition:LLVMBitCodes.h:342
llvm::bitc::METADATA_SUBRANGE
@ METADATA_SUBRANGE
Definition:LLVMBitCodes.h:353
llvm::bitc::METADATA_STRINGS
@ METADATA_STRINGS
Definition:LLVMBitCodes.h:375
llvm::bitc::METADATA_TEMPLATE_VALUE
@ METADATA_TEMPLATE_VALUE
Definition:LLVMBitCodes.h:366
llvm::bitc::METADATA_LEXICAL_BLOCK_FILE
@ METADATA_LEXICAL_BLOCK_FILE
Definition:LLVMBitCodes.h:363
llvm::bitc::METADATA_NAME
@ METADATA_NAME
Definition:LLVMBitCodes.h:344
llvm::bitc::METADATA_INDEX
@ METADATA_INDEX
Definition:LLVMBitCodes.h:379
llvm::bitc::METADATA_INDEX_OFFSET
@ METADATA_INDEX_OFFSET
Definition:LLVMBitCodes.h:378
llvm::bitc::METADATA_LEXICAL_BLOCK
@ METADATA_LEXICAL_BLOCK
Definition:LLVMBitCodes.h:362
llvm::bitc::METADATA_SUBPROGRAM
@ METADATA_SUBPROGRAM
Definition:LLVMBitCodes.h:361
llvm::bitc::METADATA_SUBROUTINE_TYPE
@ METADATA_SUBROUTINE_TYPE
Definition:LLVMBitCodes.h:359
llvm::bitc::METADATA_GLOBAL_DECL_ATTACHMENT
@ METADATA_GLOBAL_DECL_ATTACHMENT
Definition:LLVMBitCodes.h:376
llvm::bitc::METADATA_LOCAL_VAR
@ METADATA_LOCAL_VAR
Definition:LLVMBitCodes.h:368
llvm::bitc::METADATA_GLOBAL_VAR
@ METADATA_GLOBAL_VAR
Definition:LLVMBitCodes.h:367
llvm::bitc::METADATA_EXPRESSION
@ METADATA_EXPRESSION
Definition:LLVMBitCodes.h:369
llvm::bitc::METADATA_ATTACHMENT
@ METADATA_ATTACHMENT
Definition:LLVMBitCodes.h:351
llvm::bitc::METADATA_OBJC_PROPERTY
@ METADATA_OBJC_PROPERTY
Definition:LLVMBitCodes.h:370
llvm::bitc::METADATA_NAMED_NODE
@ METADATA_NAMED_NODE
Definition:LLVMBitCodes.h:350
llvm::bitc::METADATA_NODE
@ METADATA_NODE
Definition:LLVMBitCodes.h:343
llvm::bitc::METADATA_IMPORTED_ENTITY
@ METADATA_IMPORTED_ENTITY
Definition:LLVMBitCodes.h:371
llvm::bitc::METADATA_GENERIC_SUBRANGE
@ METADATA_GENERIC_SUBRANGE
Definition:LLVMBitCodes.h:385
llvm::bitc::METADATA_ASSIGN_ID
@ METADATA_ASSIGN_ID
Definition:LLVMBitCodes.h:387
llvm::bitc::METADATA_COMPILE_UNIT
@ METADATA_COMPILE_UNIT
Definition:LLVMBitCodes.h:360
llvm::bitc::METADATA_COMPOSITE_TYPE
@ METADATA_COMPOSITE_TYPE
Definition:LLVMBitCodes.h:358
llvm::bitc::METADATA_ENUMERATOR
@ METADATA_ENUMERATOR
Definition:LLVMBitCodes.h:354
llvm::bitc::METADATA_DERIVED_TYPE
@ METADATA_DERIVED_TYPE
Definition:LLVMBitCodes.h:357
llvm::bitc::METADATA_KIND
@ METADATA_KIND
Definition:LLVMBitCodes.h:346
llvm::bitc::METADATA_TEMPLATE_TYPE
@ METADATA_TEMPLATE_TYPE
Definition:LLVMBitCodes.h:365
llvm::bitc::METADATA_GLOBAL_VAR_EXPR
@ METADATA_GLOBAL_VAR_EXPR
Definition:LLVMBitCodes.h:377
llvm::bitc::METADATA_ARG_LIST
@ METADATA_ARG_LIST
Definition:LLVMBitCodes.h:386
llvm::bitc::METADATA_BASIC_TYPE
@ METADATA_BASIC_TYPE
Definition:LLVMBitCodes.h:355
llvm::bitc::METADATA_DISTINCT_NODE
@ METADATA_DISTINCT_NODE
Definition:LLVMBitCodes.h:345
llvm::bitc::METADATA_MACRO
@ METADATA_MACRO
Definition:LLVMBitCodes.h:373
llvm::bitc::METADATA_GENERIC_DEBUG
@ METADATA_GENERIC_DEBUG
Definition:LLVMBitCodes.h:352
llvm::bitc::METADATA_MODULE
@ METADATA_MODULE
Definition:LLVMBitCodes.h:372
llvm::bitc::METADATA_LOCATION
@ METADATA_LOCATION
Definition:LLVMBitCodes.h:347
llvm::bitc::METADATA_LABEL
@ METADATA_LABEL
Definition:LLVMBitCodes.h:380
llvm::bitc::RMW_USUB_COND
@ RMW_USUB_COND
Definition:LLVMBitCodes.h:504
llvm::bitc::RMW_MAX
@ RMW_MAX
Definition:LLVMBitCodes.h:494
llvm::bitc::RMW_FMIN
@ RMW_FMIN
Definition:LLVMBitCodes.h:501
llvm::bitc::RMW_XCHG
@ RMW_XCHG
Definition:LLVMBitCodes.h:487
llvm::bitc::RMW_AND
@ RMW_AND
Definition:LLVMBitCodes.h:490
llvm::bitc::RMW_UMIN
@ RMW_UMIN
Definition:LLVMBitCodes.h:497
llvm::bitc::RMW_USUB_SAT
@ RMW_USUB_SAT
Definition:LLVMBitCodes.h:505
llvm::bitc::RMW_FADD
@ RMW_FADD
Definition:LLVMBitCodes.h:498
llvm::bitc::RMW_OR
@ RMW_OR
Definition:LLVMBitCodes.h:492
llvm::bitc::RMW_XOR
@ RMW_XOR
Definition:LLVMBitCodes.h:493
llvm::bitc::RMW_SUB
@ RMW_SUB
Definition:LLVMBitCodes.h:489
llvm::bitc::RMW_UDEC_WRAP
@ RMW_UDEC_WRAP
Definition:LLVMBitCodes.h:503
llvm::bitc::RMW_UMAX
@ RMW_UMAX
Definition:LLVMBitCodes.h:496
llvm::bitc::RMW_FSUB
@ RMW_FSUB
Definition:LLVMBitCodes.h:499
llvm::bitc::RMW_UINC_WRAP
@ RMW_UINC_WRAP
Definition:LLVMBitCodes.h:502
llvm::bitc::RMW_NAND
@ RMW_NAND
Definition:LLVMBitCodes.h:491
llvm::bitc::RMW_ADD
@ RMW_ADD
Definition:LLVMBitCodes.h:488
llvm::bitc::RMW_FMAX
@ RMW_FMAX
Definition:LLVMBitCodes.h:500
llvm::bitc::RMW_MIN
@ RMW_MIN
Definition:LLVMBitCodes.h:495
llvm::bitc::FS_CONTEXT_RADIX_TREE_ARRAY
@ FS_CONTEXT_RADIX_TREE_ARRAY
Definition:LLVMBitCodes.h:337
llvm::bitc::FS_BLOCK_COUNT
@ FS_BLOCK_COUNT
Definition:LLVMBitCodes.h:302
llvm::bitc::FS_CFI_FUNCTION_DEFS
@ FS_CFI_FUNCTION_DEFS
Definition:LLVMBitCodes.h:263
llvm::bitc::FS_VALUE_GUID
@ FS_VALUE_GUID
Definition:LLVMBitCodes.h:259
llvm::bitc::FS_PERMODULE_RELBF
@ FS_PERMODULE_RELBF
Definition:LLVMBitCodes.h:272
llvm::bitc::FS_COMBINED_GLOBALVAR_INIT_REFS
@ FS_COMBINED_GLOBALVAR_INIT_REFS
Definition:LLVMBitCodes.h:225
llvm::bitc::FS_TYPE_CHECKED_LOAD_VCALLS
@ FS_TYPE_CHECKED_LOAD_VCALLS
Definition:LLVMBitCodes.h:247
llvm::bitc::FS_COMBINED_PROFILE
@ FS_COMBINED_PROFILE
Definition:LLVMBitCodes.h:223
llvm::bitc::FS_ALLOC_CONTEXT_IDS
@ FS_ALLOC_CONTEXT_IDS
Definition:LLVMBitCodes.h:333
llvm::bitc::FS_PARAM_ACCESS
@ FS_PARAM_ACCESS
Definition:LLVMBitCodes.h:305
llvm::bitc::FS_COMBINED_ORIGINAL_NAME
@ FS_COMBINED_ORIGINAL_NAME
Definition:LLVMBitCodes.h:231
llvm::bitc::FS_TYPE_ID_METADATA
@ FS_TYPE_ID_METADATA
Definition:LLVMBitCodes.h:294
llvm::bitc::FS_PERMODULE_VTABLE_GLOBALVAR_INIT_REFS
@ FS_PERMODULE_VTABLE_GLOBALVAR_INIT_REFS
Definition:LLVMBitCodes.h:300
llvm::bitc::FS_TYPE_TEST_ASSUME_CONST_VCALL
@ FS_TYPE_TEST_ASSUME_CONST_VCALL
Definition:LLVMBitCodes.h:251
llvm::bitc::FS_ALIAS
@ FS_ALIAS
Definition:LLVMBitCodes.h:227
llvm::bitc::FS_TYPE_ID
@ FS_TYPE_ID
Definition:LLVMBitCodes.h:280
llvm::bitc::FS_PERMODULE_GLOBALVAR_INIT_REFS
@ FS_PERMODULE_GLOBALVAR_INIT_REFS
Definition:LLVMBitCodes.h:216
llvm::bitc::FS_COMBINED_ALIAS
@ FS_COMBINED_ALIAS
Definition:LLVMBitCodes.h:229
llvm::bitc::FS_TYPE_TEST_ASSUME_VCALLS
@ FS_TYPE_TEST_ASSUME_VCALLS
Definition:LLVMBitCodes.h:242
llvm::bitc::FS_CFI_FUNCTION_DECLS
@ FS_CFI_FUNCTION_DECLS
Definition:LLVMBitCodes.h:267
llvm::bitc::FS_TYPE_TESTS
@ FS_TYPE_TESTS
Definition:LLVMBitCodes.h:237
llvm::bitc::FS_COMBINED_CALLSITE_INFO
@ FS_COMBINED_CALLSITE_INFO
Definition:LLVMBitCodes.h:316
llvm::bitc::FS_FLAGS
@ FS_FLAGS
Definition:LLVMBitCodes.h:274
llvm::bitc::FS_COMBINED_ALLOC_INFO
@ FS_COMBINED_ALLOC_INFO
Definition:LLVMBitCodes.h:321
llvm::bitc::FS_STACK_IDS
@ FS_STACK_IDS
Definition:LLVMBitCodes.h:324
llvm::bitc::FS_PERMODULE_PROFILE
@ FS_PERMODULE_PROFILE
Definition:LLVMBitCodes.h:214
llvm::bitc::FS_PERMODULE_CALLSITE_INFO
@ FS_PERMODULE_CALLSITE_INFO
Definition:LLVMBitCodes.h:308
llvm::bitc::FS_PERMODULE_ALLOC_INFO
@ FS_PERMODULE_ALLOC_INFO
Definition:LLVMBitCodes.h:312
llvm::bitc::FS_VERSION
@ FS_VERSION
Definition:LLVMBitCodes.h:233
llvm::bitc::FS_TYPE_CHECKED_LOAD_CONST_VCALL
@ FS_TYPE_CHECKED_LOAD_CONST_VCALL
Definition:LLVMBitCodes.h:255
llvm::bitc::PNNI_NON_NEG
@ PNNI_NON_NEG
Definition:LLVMBitCodes.h:537
llvm::bitc::IDENTIFICATION_CODE_EPOCH
@ IDENTIFICATION_CODE_EPOCH
Definition:LLVMBitCodes.h:72
llvm::bitc::IDENTIFICATION_CODE_STRING
@ IDENTIFICATION_CODE_STRING
Definition:LLVMBitCodes.h:71
llvm::bitc::CST_CODE_BLOCKADDRESS
@ CST_CODE_BLOCKADDRESS
Definition:LLVMBitCodes.h:414
llvm::bitc::CST_CODE_NO_CFI_VALUE
@ CST_CODE_NO_CFI_VALUE
Definition:LLVMBitCodes.h:425
llvm::bitc::CST_CODE_DATA
@ CST_CODE_DATA
Definition:LLVMBitCodes.h:415
llvm::bitc::CST_CODE_CE_SHUFVEC_EX
@ CST_CODE_CE_SHUFVEC_EX
Definition:LLVMBitCodes.h:412
llvm::bitc::CST_CODE_CE_EXTRACTELT
@ CST_CODE_CE_EXTRACTELT
Definition:LLVMBitCodes.h:406
llvm::bitc::CST_CODE_CE_BINOP
@ CST_CODE_CE_BINOP
Definition:LLVMBitCodes.h:402
llvm::bitc::CST_CODE_CE_SHUFFLEVEC
@ CST_CODE_CE_SHUFFLEVEC
Definition:LLVMBitCodes.h:408
llvm::bitc::CST_CODE_STRING
@ CST_CODE_STRING
Definition:LLVMBitCodes.h:400
llvm::bitc::CST_CODE_SETTYPE
@ CST_CODE_SETTYPE
Definition:LLVMBitCodes.h:393
llvm::bitc::CST_CODE_UNDEF
@ CST_CODE_UNDEF
Definition:LLVMBitCodes.h:395
llvm::bitc::CST_CODE_NULL
@ CST_CODE_NULL
Definition:LLVMBitCodes.h:394
llvm::bitc::CST_CODE_WIDE_INTEGER
@ CST_CODE_WIDE_INTEGER
Definition:LLVMBitCodes.h:397
llvm::bitc::CST_CODE_CE_GEP
@ CST_CODE_CE_GEP
Definition:LLVMBitCodes.h:431
llvm::bitc::CST_CODE_DSO_LOCAL_EQUIVALENT
@ CST_CODE_DSO_LOCAL_EQUIVALENT
Definition:LLVMBitCodes.h:421
llvm::bitc::CST_CODE_PTRAUTH
@ CST_CODE_PTRAUTH
Definition:LLVMBitCodes.h:432
llvm::bitc::CST_CODE_AGGREGATE
@ CST_CODE_AGGREGATE
Definition:LLVMBitCodes.h:399
llvm::bitc::CST_CODE_CE_INSERTELT
@ CST_CODE_CE_INSERTELT
Definition:LLVMBitCodes.h:407
llvm::bitc::CST_CODE_CE_UNOP
@ CST_CODE_CE_UNOP
Definition:LLVMBitCodes.h:419
llvm::bitc::CST_CODE_CSTRING
@ CST_CODE_CSTRING
Definition:LLVMBitCodes.h:401
llvm::bitc::CST_CODE_FLOAT
@ CST_CODE_FLOAT
Definition:LLVMBitCodes.h:398
llvm::bitc::CST_CODE_CE_GEP_WITH_INRANGE
@ CST_CODE_CE_GEP_WITH_INRANGE
Definition:LLVMBitCodes.h:430
llvm::bitc::CST_CODE_INTEGER
@ CST_CODE_INTEGER
Definition:LLVMBitCodes.h:396
llvm::bitc::CST_CODE_POISON
@ CST_CODE_POISON
Definition:LLVMBitCodes.h:420
llvm::bitc::CST_CODE_CE_CAST
@ CST_CODE_CE_CAST
Definition:LLVMBitCodes.h:403
llvm::bitc::CST_CODE_INLINEASM
@ CST_CODE_INLINEASM
Definition:LLVMBitCodes.h:426
llvm::bitc::GEP_INBOUNDS
@ GEP_INBOUNDS
Definition:LLVMBitCodes.h:553
llvm::bitc::GEP_NUW
@ GEP_NUW
Definition:LLVMBitCodes.h:555
llvm::bitc::GEP_NUSW
@ GEP_NUSW
Definition:LLVMBitCodes.h:554
llvm::bitc::CALL_EXPLICIT_TYPE
@ CALL_EXPLICIT_TYPE
Definition:LLVMBitCodes.h:578
llvm::bitc::CALL_MUSTTAIL
@ CALL_MUSTTAIL
Definition:LLVMBitCodes.h:577
llvm::bitc::CALL_TAIL
@ CALL_TAIL
Definition:LLVMBitCodes.h:575
llvm::bitc::CALL_CCONV
@ CALL_CCONV
Definition:LLVMBitCodes.h:576
llvm::bitc::CALL_FMF
@ CALL_FMF
Definition:LLVMBitCodes.h:580
llvm::bitc::CALL_NOTAIL
@ CALL_NOTAIL
Definition:LLVMBitCodes.h:579
llvm::bitc::VST_CODE_BBENTRY
@ VST_CODE_BBENTRY
Definition:LLVMBitCodes.h:193
llvm::bitc::VST_CODE_ENTRY
@ VST_CODE_ENTRY
Definition:LLVMBitCodes.h:192
llvm::bitc::VST_CODE_FNENTRY
@ VST_CODE_FNENTRY
Definition:LLVMBitCodes.h:194
llvm::bitc::PEO_EXACT
@ PEO_EXACT
Definition:LLVMBitCodes.h:541
llvm::bitc::COMDAT_SELECTION_KIND_LARGEST
@ COMDAT_SELECTION_KIND_LARGEST
Definition:LLVMBitCodes.h:797
llvm::bitc::COMDAT_SELECTION_KIND_ANY
@ COMDAT_SELECTION_KIND_ANY
Definition:LLVMBitCodes.h:795
llvm::bitc::COMDAT_SELECTION_KIND_SAME_SIZE
@ COMDAT_SELECTION_KIND_SAME_SIZE
Definition:LLVMBitCodes.h:799
llvm::bitc::COMDAT_SELECTION_KIND_EXACT_MATCH
@ COMDAT_SELECTION_KIND_EXACT_MATCH
Definition:LLVMBitCodes.h:796
llvm::bitc::COMDAT_SELECTION_KIND_NO_DUPLICATES
@ COMDAT_SELECTION_KIND_NO_DUPLICATES
Definition:LLVMBitCodes.h:798
llvm::bitc::ATTR_KIND_STACK_PROTECT
@ ATTR_KIND_STACK_PROTECT
Definition:LLVMBitCodes.h:715
llvm::bitc::ATTR_KIND_NO_UNWIND
@ ATTR_KIND_NO_UNWIND
Definition:LLVMBitCodes.h:707
llvm::bitc::ATTR_KIND_STACK_PROTECT_STRONG
@ ATTR_KIND_STACK_PROTECT_STRONG
Definition:LLVMBitCodes.h:717
llvm::bitc::ATTR_KIND_SANITIZE_MEMORY
@ ATTR_KIND_SANITIZE_MEMORY
Definition:LLVMBitCodes.h:721
llvm::bitc::ATTR_KIND_SAFESTACK
@ ATTR_KIND_SAFESTACK
Definition:LLVMBitCodes.h:733
llvm::bitc::ATTR_KIND_OPTIMIZE_FOR_SIZE
@ ATTR_KIND_OPTIMIZE_FOR_SIZE
Definition:LLVMBitCodes.h:708
llvm::bitc::ATTR_KIND_SWIFT_ERROR
@ ATTR_KIND_SWIFT_ERROR
Definition:LLVMBitCodes.h:736
llvm::bitc::ATTR_KIND_BYREF
@ ATTR_KIND_BYREF
Definition:LLVMBitCodes.h:758
llvm::bitc::ATTR_KIND_STRUCT_RET
@ ATTR_KIND_STRUCT_RET
Definition:LLVMBitCodes.h:718
llvm::bitc::ATTR_KIND_MIN_SIZE
@ ATTR_KIND_MIN_SIZE
Definition:LLVMBitCodes.h:695
llvm::bitc::ATTR_KIND_NO_CALLBACK
@ ATTR_KIND_NO_CALLBACK
Definition:LLVMBitCodes.h:760
llvm::bitc::ATTR_KIND_NO_CAPTURE
@ ATTR_KIND_NO_CAPTURE
Definition:LLVMBitCodes.h:700
llvm::bitc::ATTR_KIND_FNRETTHUNK_EXTERN
@ ATTR_KIND_FNRETTHUNK_EXTERN
Definition:LLVMBitCodes.h:773
llvm::bitc::ATTR_KIND_NOFREE
@ ATTR_KIND_NOFREE
Definition:LLVMBitCodes.h:751
llvm::bitc::ATTR_KIND_NO_DIVERGENCE_SOURCE
@ ATTR_KIND_NO_DIVERGENCE_SOURCE
Definition:LLVMBitCodes.h:789
llvm::bitc::ATTR_KIND_SANITIZE_ADDRESS
@ ATTR_KIND_SANITIZE_ADDRESS
Definition:LLVMBitCodes.h:719
llvm::bitc::ATTR_KIND_NO_IMPLICIT_FLOAT
@ ATTR_KIND_NO_IMPLICIT_FLOAT
Definition:LLVMBitCodes.h:702
llvm::bitc::ATTR_KIND_NO_BUILTIN
@ ATTR_KIND_NO_BUILTIN
Definition:LLVMBitCodes.h:699
llvm::bitc::ATTR_KIND_MEMORY
@ ATTR_KIND_MEMORY
Definition:LLVMBitCodes.h:775
llvm::bitc::ATTR_KIND_NO_RECURSE
@ ATTR_KIND_NO_RECURSE
Definition:LLVMBitCodes.h:737
llvm::bitc::ATTR_KIND_DEAD_ON_UNWIND
@ ATTR_KIND_DEAD_ON_UNWIND
Definition:LLVMBitCodes.h:780
llvm::bitc::ATTR_KIND_CONVERGENT
@ ATTR_KIND_CONVERGENT
Definition:LLVMBitCodes.h:732
llvm::bitc::ATTR_KIND_NAKED
@ ATTR_KIND_NAKED
Definition:LLVMBitCodes.h:696
llvm::bitc::ATTR_KIND_RETURNED
@ ATTR_KIND_RETURNED
Definition:LLVMBitCodes.h:711
llvm::bitc::ATTR_KIND_STACK_ALIGNMENT
@ ATTR_KIND_STACK_ALIGNMENT
Definition:LLVMBitCodes.h:714
llvm::bitc::ATTR_KIND_SWIFT_SELF
@ ATTR_KIND_SWIFT_SELF
Definition:LLVMBitCodes.h:735
llvm::bitc::ATTR_KIND_NEST
@ ATTR_KIND_NEST
Definition:LLVMBitCodes.h:697
llvm::bitc::ATTR_KIND_ALLOC_SIZE
@ ATTR_KIND_ALLOC_SIZE
Definition:LLVMBitCodes.h:740
llvm::bitc::ATTR_KIND_STACK_PROTECT_REQ
@ ATTR_KIND_STACK_PROTECT_REQ
Definition:LLVMBitCodes.h:716
llvm::bitc::ATTR_KIND_INLINE_HINT
@ ATTR_KIND_INLINE_HINT
Definition:LLVMBitCodes.h:693
llvm::bitc::ATTR_KIND_NON_NULL
@ ATTR_KIND_NON_NULL
Definition:LLVMBitCodes.h:728
llvm::bitc::ATTR_KIND_NULL_POINTER_IS_VALID
@ ATTR_KIND_NULL_POINTER_IS_VALID
Definition:LLVMBitCodes.h:756
llvm::bitc::ATTR_KIND_SANITIZE_HWADDRESS
@ ATTR_KIND_SANITIZE_HWADDRESS
Definition:LLVMBitCodes.h:744
llvm::bitc::ATTR_KIND_NO_RETURN
@ ATTR_KIND_NO_RETURN
Definition:LLVMBitCodes.h:706
llvm::bitc::ATTR_KIND_MUSTPROGRESS
@ ATTR_KIND_MUSTPROGRESS
Definition:LLVMBitCodes.h:759
llvm::bitc::ATTR_KIND_RETURNS_TWICE
@ ATTR_KIND_RETURNS_TWICE
Definition:LLVMBitCodes.h:712
llvm::bitc::ATTR_KIND_Z_EXT
@ ATTR_KIND_Z_EXT
Definition:LLVMBitCodes.h:723
llvm::bitc::ATTR_KIND_SHADOWCALLSTACK
@ ATTR_KIND_SHADOWCALLSTACK
Definition:LLVMBitCodes.h:747
llvm::bitc::ATTR_KIND_OPT_FOR_FUZZING
@ ATTR_KIND_OPT_FOR_FUZZING
Definition:LLVMBitCodes.h:746
llvm::bitc::ATTR_KIND_COLD
@ ATTR_KIND_COLD
Definition:LLVMBitCodes.h:725
llvm::bitc::ATTR_KIND_WRITABLE
@ ATTR_KIND_WRITABLE
Definition:LLVMBitCodes.h:778
llvm::bitc::ATTR_KIND_SANITIZE_NUMERICAL_STABILITY
@ ATTR_KIND_SANITIZE_NUMERICAL_STABILITY
Definition:LLVMBitCodes.h:782
llvm::bitc::ATTR_KIND_INITIALIZES
@ ATTR_KIND_INITIALIZES
Definition:LLVMBitCodes.h:783
llvm::bitc::ATTR_KIND_ALLOCATED_POINTER
@ ATTR_KIND_ALLOCATED_POINTER
Definition:LLVMBitCodes.h:770
llvm::bitc::ATTR_KIND_DISABLE_SANITIZER_INSTRUMENTATION
@ ATTR_KIND_DISABLE_SANITIZER_INSTRUMENTATION
Definition:LLVMBitCodes.h:767
llvm::bitc::ATTR_KIND_NOUNDEF
@ ATTR_KIND_NOUNDEF
Definition:LLVMBitCodes.h:757
llvm::bitc::ATTR_KIND_SKIP_PROFILE
@ ATTR_KIND_SKIP_PROFILE
Definition:LLVMBitCodes.h:774
llvm::bitc::ATTR_KIND_IMMARG
@ ATTR_KIND_IMMARG
Definition:LLVMBitCodes.h:749
llvm::bitc::ATTR_KIND_ELEMENTTYPE
@ ATTR_KIND_ELEMENTTYPE
Definition:LLVMBitCodes.h:766
llvm::bitc::ATTR_KIND_CORO_ELIDE_SAFE
@ ATTR_KIND_CORO_ELIDE_SAFE
Definition:LLVMBitCodes.h:787
llvm::bitc::ATTR_KIND_ALLOC_KIND
@ ATTR_KIND_ALLOC_KIND
Definition:LLVMBitCodes.h:771
llvm::bitc::ATTR_KIND_BUILTIN
@ ATTR_KIND_BUILTIN
Definition:LLVMBitCodes.h:724
llvm::bitc::ATTR_KIND_NO_MERGE
@ ATTR_KIND_NO_MERGE
Definition:LLVMBitCodes.h:755
llvm::bitc::ATTR_KIND_STRICT_FP
@ ATTR_KIND_STRICT_FP
Definition:LLVMBitCodes.h:743
llvm::bitc::ATTR_KIND_NO_DUPLICATE
@ ATTR_KIND_NO_DUPLICATE
Definition:LLVMBitCodes.h:701
llvm::bitc::ATTR_KIND_ALLOC_ALIGN
@ ATTR_KIND_ALLOC_ALIGN
Definition:LLVMBitCodes.h:769
llvm::bitc::ATTR_KIND_NON_LAZY_BIND
@ ATTR_KIND_NON_LAZY_BIND
Definition:LLVMBitCodes.h:704
llvm::bitc::ATTR_KIND_DEREFERENCEABLE
@ ATTR_KIND_DEREFERENCEABLE
Definition:LLVMBitCodes.h:730
llvm::bitc::ATTR_KIND_READ_NONE
@ ATTR_KIND_READ_NONE
Definition:LLVMBitCodes.h:709
llvm::bitc::ATTR_KIND_S_EXT
@ ATTR_KIND_S_EXT
Definition:LLVMBitCodes.h:713
llvm::bitc::ATTR_KIND_UW_TABLE
@ ATTR_KIND_UW_TABLE
Definition:LLVMBitCodes.h:722
llvm::bitc::ATTR_KIND_BY_VAL
@ ATTR_KIND_BY_VAL
Definition:LLVMBitCodes.h:692
llvm::bitc::ATTR_KIND_OPTIMIZE_NONE
@ ATTR_KIND_OPTIMIZE_NONE
Definition:LLVMBitCodes.h:726
llvm::bitc::ATTR_KIND_NO_EXT
@ ATTR_KIND_NO_EXT
Definition:LLVMBitCodes.h:788
llvm::bitc::ATTR_KIND_WRITEONLY
@ ATTR_KIND_WRITEONLY
Definition:LLVMBitCodes.h:741
llvm::bitc::ATTR_KIND_HYBRID_PATCHABLE
@ ATTR_KIND_HYBRID_PATCHABLE
Definition:LLVMBitCodes.h:784
llvm::bitc::ATTR_KIND_NO_RED_ZONE
@ ATTR_KIND_NO_RED_ZONE
Definition:LLVMBitCodes.h:705
llvm::bitc::ATTR_KIND_NOCF_CHECK
@ ATTR_KIND_NOCF_CHECK
Definition:LLVMBitCodes.h:745
llvm::bitc::ATTR_KIND_NO_PROFILE
@ ATTR_KIND_NO_PROFILE
Definition:LLVMBitCodes.h:762
llvm::bitc::ATTR_KIND_DEREFERENCEABLE_OR_NULL
@ ATTR_KIND_DEREFERENCEABLE_OR_NULL
Definition:LLVMBitCodes.h:731
llvm::bitc::ATTR_KIND_SANITIZE_REALTIME
@ ATTR_KIND_SANITIZE_REALTIME
Definition:LLVMBitCodes.h:785
llvm::bitc::ATTR_KIND_IN_REG
@ ATTR_KIND_IN_REG
Definition:LLVMBitCodes.h:694
llvm::bitc::ATTR_KIND_IN_ALLOCA
@ ATTR_KIND_IN_ALLOCA
Definition:LLVMBitCodes.h:727
llvm::bitc::ATTR_KIND_READ_ONLY
@ ATTR_KIND_READ_ONLY
Definition:LLVMBitCodes.h:710
llvm::bitc::ATTR_KIND_ALIGNMENT
@ ATTR_KIND_ALIGNMENT
Definition:LLVMBitCodes.h:690
llvm::bitc::ATTR_KIND_SPECULATIVE_LOAD_HARDENING
@ ATTR_KIND_SPECULATIVE_LOAD_HARDENING
Definition:LLVMBitCodes.h:748
llvm::bitc::ATTR_KIND_ALWAYS_INLINE
@ ATTR_KIND_ALWAYS_INLINE
Definition:LLVMBitCodes.h:691
llvm::bitc::ATTR_KIND_NOFPCLASS
@ ATTR_KIND_NOFPCLASS
Definition:LLVMBitCodes.h:776
llvm::bitc::ATTR_KIND_WILLRETURN
@ ATTR_KIND_WILLRETURN
Definition:LLVMBitCodes.h:750
llvm::bitc::ATTR_KIND_RANGE
@ ATTR_KIND_RANGE
Definition:LLVMBitCodes.h:781
llvm::bitc::ATTR_KIND_SANITIZE_TYPE
@ ATTR_KIND_SANITIZE_TYPE
Definition:LLVMBitCodes.h:790
llvm::bitc::ATTR_KIND_PRESPLIT_COROUTINE
@ ATTR_KIND_PRESPLIT_COROUTINE
Definition:LLVMBitCodes.h:772
llvm::bitc::ATTR_KIND_NOSYNC
@ ATTR_KIND_NOSYNC
Definition:LLVMBitCodes.h:752
llvm::bitc::ATTR_KIND_NO_ALIAS
@ ATTR_KIND_NO_ALIAS
Definition:LLVMBitCodes.h:698
llvm::bitc::ATTR_KIND_VSCALE_RANGE
@ ATTR_KIND_VSCALE_RANGE
Definition:LLVMBitCodes.h:763
llvm::bitc::ATTR_KIND_NO_SANITIZE_COVERAGE
@ ATTR_KIND_NO_SANITIZE_COVERAGE
Definition:LLVMBitCodes.h:765
llvm::bitc::ATTR_KIND_JUMP_TABLE
@ ATTR_KIND_JUMP_TABLE
Definition:LLVMBitCodes.h:729
llvm::bitc::ATTR_KIND_SPECULATABLE
@ ATTR_KIND_SPECULATABLE
Definition:LLVMBitCodes.h:742
llvm::bitc::ATTR_KIND_NO_INLINE
@ ATTR_KIND_NO_INLINE
Definition:LLVMBitCodes.h:703
llvm::bitc::ATTR_KIND_HOT
@ ATTR_KIND_HOT
Definition:LLVMBitCodes.h:761
llvm::bitc::ATTR_KIND_SANITIZE_REALTIME_BLOCKING
@ ATTR_KIND_SANITIZE_REALTIME_BLOCKING
Definition:LLVMBitCodes.h:786
llvm::bitc::ATTR_KIND_NO_SANITIZE_BOUNDS
@ ATTR_KIND_NO_SANITIZE_BOUNDS
Definition:LLVMBitCodes.h:768
llvm::bitc::ATTR_KIND_SANITIZE_MEMTAG
@ ATTR_KIND_SANITIZE_MEMTAG
Definition:LLVMBitCodes.h:753
llvm::bitc::ATTR_KIND_CORO_ONLY_DESTROY_WHEN_COMPLETE
@ ATTR_KIND_CORO_ONLY_DESTROY_WHEN_COMPLETE
Definition:LLVMBitCodes.h:779
llvm::bitc::ATTR_KIND_CAPTURES
@ ATTR_KIND_CAPTURES
Definition:LLVMBitCodes.h:791
llvm::bitc::ATTR_KIND_SANITIZE_THREAD
@ ATTR_KIND_SANITIZE_THREAD
Definition:LLVMBitCodes.h:720
llvm::bitc::ATTR_KIND_OPTIMIZE_FOR_DEBUGGING
@ ATTR_KIND_OPTIMIZE_FOR_DEBUGGING
Definition:LLVMBitCodes.h:777
llvm::bitc::ATTR_KIND_PREALLOCATED
@ ATTR_KIND_PREALLOCATED
Definition:LLVMBitCodes.h:754
llvm::bitc::ATTR_KIND_SWIFT_ASYNC
@ ATTR_KIND_SWIFT_ASYNC
Definition:LLVMBitCodes.h:764
llvm::bitc::OBO_NO_SIGNED_WRAP
@ OBO_NO_SIGNED_WRAP
Definition:LLVMBitCodes.h:512
llvm::bitc::OBO_NO_UNSIGNED_WRAP
@ OBO_NO_UNSIGNED_WRAP
Definition:LLVMBitCodes.h:511
llvm::bitc::TIO_NO_UNSIGNED_WRAP
@ TIO_NO_UNSIGNED_WRAP
Definition:LLVMBitCodes.h:518
llvm::bitc::TIO_NO_SIGNED_WRAP
@ TIO_NO_SIGNED_WRAP
Definition:LLVMBitCodes.h:519
llvm::bitc::UNOP_FNEG
@ UNOP_FNEG
Definition:LLVMBitCodes.h:460
llvm::bitc::USELIST_CODE_BB
@ USELIST_CODE_BB
Definition:LLVMBitCodes.h:685
llvm::bitc::USELIST_CODE_DEFAULT
@ USELIST_CODE_DEFAULT
Definition:LLVMBitCodes.h:684
llvm::bitc::SYNC_SCOPE_NAMES_BLOCK_ID
@ SYNC_SCOPE_NAMES_BLOCK_ID
Definition:LLVMBitCodes.h:65
llvm::bitc::PARAMATTR_BLOCK_ID
@ PARAMATTR_BLOCK_ID
Definition:LLVMBitCodes.h:33
llvm::bitc::TYPE_BLOCK_ID_NEW
@ TYPE_BLOCK_ID_NEW
Definition:LLVMBitCodes.h:48
llvm::bitc::MODULE_BLOCK_ID
@ MODULE_BLOCK_ID
Definition:LLVMBitCodes.h:30
llvm::bitc::STRTAB_BLOCK_ID
@ STRTAB_BLOCK_ID
Definition:LLVMBitCodes.h:59
llvm::bitc::SYMTAB_BLOCK_ID
@ SYMTAB_BLOCK_ID
Definition:LLVMBitCodes.h:63
llvm::bitc::CONSTANTS_BLOCK_ID
@ CONSTANTS_BLOCK_ID
Definition:LLVMBitCodes.h:36
llvm::bitc::PARAMATTR_GROUP_BLOCK_ID
@ PARAMATTR_GROUP_BLOCK_ID
Definition:LLVMBitCodes.h:34
llvm::bitc::METADATA_KIND_BLOCK_ID
@ METADATA_KIND_BLOCK_ID
Definition:LLVMBitCodes.h:57
llvm::bitc::IDENTIFICATION_BLOCK_ID
@ IDENTIFICATION_BLOCK_ID
Definition:LLVMBitCodes.h:42
llvm::bitc::GLOBALVAL_SUMMARY_BLOCK_ID
@ GLOBALVAL_SUMMARY_BLOCK_ID
Definition:LLVMBitCodes.h:53
llvm::bitc::METADATA_ATTACHMENT_ID
@ METADATA_ATTACHMENT_ID
Definition:LLVMBitCodes.h:46
llvm::bitc::METADATA_BLOCK_ID
@ METADATA_BLOCK_ID
Definition:LLVMBitCodes.h:45
llvm::bitc::FUNCTION_BLOCK_ID
@ FUNCTION_BLOCK_ID
Definition:LLVMBitCodes.h:37
llvm::bitc::FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID
@ FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID
Definition:LLVMBitCodes.h:61
llvm::bitc::MODULE_STRTAB_BLOCK_ID
@ MODULE_STRTAB_BLOCK_ID
Definition:LLVMBitCodes.h:52
llvm::bitc::VALUE_SYMTAB_BLOCK_ID
@ VALUE_SYMTAB_BLOCK_ID
Definition:LLVMBitCodes.h:44
llvm::bitc::OPERAND_BUNDLE_TAGS_BLOCK_ID
@ OPERAND_BUNDLE_TAGS_BLOCK_ID
Definition:LLVMBitCodes.h:55
llvm::bitc::USELIST_BLOCK_ID
@ USELIST_BLOCK_ID
Definition:LLVMBitCodes.h:50
llvm::bitc::OB_METADATA
@ OB_METADATA
Definition:LLVMBitCodes.h:548
llvm::bitc::CAST_BITCAST
@ CAST_BITCAST
Definition:LLVMBitCodes.h:451
llvm::bitc::CAST_UITOFP
@ CAST_UITOFP
Definition:LLVMBitCodes.h:445
llvm::bitc::CAST_FPTOSI
@ CAST_FPTOSI
Definition:LLVMBitCodes.h:444
llvm::bitc::CAST_FPTOUI
@ CAST_FPTOUI
Definition:LLVMBitCodes.h:443
llvm::bitc::CAST_SITOFP
@ CAST_SITOFP
Definition:LLVMBitCodes.h:446
llvm::bitc::CAST_TRUNC
@ CAST_TRUNC
Definition:LLVMBitCodes.h:440
llvm::bitc::CAST_INTTOPTR
@ CAST_INTTOPTR
Definition:LLVMBitCodes.h:450
llvm::bitc::CAST_SEXT
@ CAST_SEXT
Definition:LLVMBitCodes.h:442
llvm::bitc::CAST_ZEXT
@ CAST_ZEXT
Definition:LLVMBitCodes.h:441
llvm::bitc::CAST_FPEXT
@ CAST_FPEXT
Definition:LLVMBitCodes.h:448
llvm::bitc::CAST_ADDRSPACECAST
@ CAST_ADDRSPACECAST
Definition:LLVMBitCodes.h:452
llvm::bitc::CAST_FPTRUNC
@ CAST_FPTRUNC
Definition:LLVMBitCodes.h:447
llvm::bitc::CAST_PTRTOINT
@ CAST_PTRTOINT
Definition:LLVMBitCodes.h:449
llvm::bitc::MODULE_CODE_FUNCTION
@ MODULE_CODE_FUNCTION
Definition:LLVMBitCodes.h:100
llvm::bitc::MODULE_CODE_VERSION
@ MODULE_CODE_VERSION
Definition:LLVMBitCodes.h:85
llvm::bitc::MODULE_CODE_SOURCE_FILENAME
@ MODULE_CODE_SOURCE_FILENAME
Definition:LLVMBitCodes.h:116
llvm::bitc::MODULE_CODE_SECTIONNAME
@ MODULE_CODE_SECTIONNAME
Definition:LLVMBitCodes.h:89
llvm::bitc::MODULE_CODE_TRIPLE
@ MODULE_CODE_TRIPLE
Definition:LLVMBitCodes.h:86
llvm::bitc::MODULE_CODE_DATALAYOUT
@ MODULE_CODE_DATALAYOUT
Definition:LLVMBitCodes.h:87
llvm::bitc::MODULE_CODE_GLOBALVAR
@ MODULE_CODE_GLOBALVAR
Definition:LLVMBitCodes.h:96
llvm::bitc::MODULE_CODE_VSTOFFSET
@ MODULE_CODE_VSTOFFSET
Definition:LLVMBitCodes.h:108
llvm::bitc::MODULE_CODE_IFUNC
@ MODULE_CODE_IFUNC
Definition:LLVMBitCodes.h:122
llvm::bitc::MODULE_CODE_ALIAS
@ MODULE_CODE_ALIAS
Definition:LLVMBitCodes.h:111
llvm::bitc::MODULE_CODE_GCNAME
@ MODULE_CODE_GCNAME
Definition:LLVMBitCodes.h:105
llvm::bitc::MODULE_CODE_ASM
@ MODULE_CODE_ASM
Definition:LLVMBitCodes.h:88
llvm::bitc::MODULE_CODE_HASH
@ MODULE_CODE_HASH
Definition:LLVMBitCodes.h:119
llvm::bitc::MODULE_CODE_COMDAT
@ MODULE_CODE_COMDAT
Definition:LLVMBitCodes.h:106
llvm::bitc::FUNC_CODE_INST_CATCHRET
@ FUNC_CODE_INST_CATCHRET
Definition:LLVMBitCodes.h:654
llvm::bitc::FUNC_CODE_INST_LANDINGPAD
@ FUNC_CODE_INST_LANDINGPAD
Definition:LLVMBitCodes.h:652
llvm::bitc::FUNC_CODE_INST_EXTRACTVAL
@ FUNC_CODE_INST_EXTRACTVAL
Definition:LLVMBitCodes.h:617
llvm::bitc::FUNC_CODE_INST_CATCHPAD
@ FUNC_CODE_INST_CATCHPAD
Definition:LLVMBitCodes.h:655
llvm::bitc::FUNC_CODE_INST_RESUME
@ FUNC_CODE_INST_RESUME
Definition:LLVMBitCodes.h:639
llvm::bitc::FUNC_CODE_INST_CMP2
@ FUNC_CODE_INST_CMP2
Definition:LLVMBitCodes.h:621
llvm::bitc::FUNC_CODE_INST_FENCE
@ FUNC_CODE_INST_FENCE
Definition:LLVMBitCodes.h:632
llvm::bitc::FUNC_CODE_INST_CALLBR
@ FUNC_CODE_INST_CALLBR
Definition:LLVMBitCodes.h:663
llvm::bitc::FUNC_CODE_INST_CATCHSWITCH
@ FUNC_CODE_INST_CATCHSWITCH
Definition:LLVMBitCodes.h:657
llvm::bitc::FUNC_CODE_INST_BR
@ FUNC_CODE_INST_BR
Definition:LLVMBitCodes.h:598
llvm::bitc::FUNC_CODE_INST_VSELECT
@ FUNC_CODE_INST_VSELECT
Definition:LLVMBitCodes.h:623
llvm::bitc::FUNC_CODE_INST_GEP
@ FUNC_CODE_INST_GEP
Definition:LLVMBitCodes.h:646
llvm::bitc::FUNC_CODE_INST_CLEANUPRET
@ FUNC_CODE_INST_CLEANUPRET
Definition:LLVMBitCodes.h:653
llvm::bitc::FUNC_CODE_DEBUG_RECORD_VALUE
@ FUNC_CODE_DEBUG_RECORD_VALUE
Definition:LLVMBitCodes.h:671
llvm::bitc::FUNC_CODE_INST_LOADATOMIC
@ FUNC_CODE_INST_LOADATOMIC
Definition:LLVMBitCodes.h:642
llvm::bitc::FUNC_CODE_DEBUG_RECORD_ASSIGN
@ FUNC_CODE_DEBUG_RECORD_ASSIGN
Definition:LLVMBitCodes.h:675
llvm::bitc::FUNC_CODE_INST_LOAD
@ FUNC_CODE_INST_LOAD
Definition:LLVMBitCodes.h:608
llvm::bitc::FUNC_CODE_INST_STOREATOMIC
@ FUNC_CODE_INST_STOREATOMIC
Definition:LLVMBitCodes.h:648
llvm::bitc::FUNC_CODE_INST_ATOMICRMW
@ FUNC_CODE_INST_ATOMICRMW
Definition:LLVMBitCodes.h:666
llvm::bitc::FUNC_CODE_INST_BINOP
@ FUNC_CODE_INST_BINOP
Definition:LLVMBitCodes.h:588
llvm::bitc::FUNC_CODE_INST_STORE
@ FUNC_CODE_INST_STORE
Definition:LLVMBitCodes.h:647
llvm::bitc::FUNC_CODE_DEBUG_LOC_AGAIN
@ FUNC_CODE_DEBUG_LOC_AGAIN
Definition:LLVMBitCodes.h:627
llvm::bitc::FUNC_CODE_INST_EXTRACTELT
@ FUNC_CODE_INST_EXTRACTELT
Definition:LLVMBitCodes.h:592
llvm::bitc::FUNC_CODE_INST_INDIRECTBR
@ FUNC_CODE_INST_INDIRECTBR
Definition:LLVMBitCodes.h:625
llvm::bitc::FUNC_CODE_INST_INVOKE
@ FUNC_CODE_INST_INVOKE
Definition:LLVMBitCodes.h:600
llvm::bitc::FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE
@ FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE
Definition:LLVMBitCodes.h:678
llvm::bitc::FUNC_CODE_INST_INSERTVAL
@ FUNC_CODE_INST_INSERTVAL
Definition:LLVMBitCodes.h:618
llvm::bitc::FUNC_CODE_DECLAREBLOCKS
@ FUNC_CODE_DECLAREBLOCKS
Definition:LLVMBitCodes.h:586
llvm::bitc::FUNC_CODE_DEBUG_RECORD_LABEL
@ FUNC_CODE_DEBUG_RECORD_LABEL
Definition:LLVMBitCodes.h:680
llvm::bitc::FUNC_CODE_INST_SWITCH
@ FUNC_CODE_INST_SWITCH
Definition:LLVMBitCodes.h:599
llvm::bitc::FUNC_CODE_INST_PHI
@ FUNC_CODE_INST_PHI
Definition:LLVMBitCodes.h:604
llvm::bitc::FUNC_CODE_INST_RET
@ FUNC_CODE_INST_RET
Definition:LLVMBitCodes.h:597
llvm::bitc::FUNC_CODE_INST_CALL
@ FUNC_CODE_INST_CALL
Definition:LLVMBitCodes.h:629
llvm::bitc::FUNC_CODE_INST_ALLOCA
@ FUNC_CODE_INST_ALLOCA
Definition:LLVMBitCodes.h:607
llvm::bitc::FUNC_CODE_INST_INSERTELT
@ FUNC_CODE_INST_INSERTELT
Definition:LLVMBitCodes.h:593
llvm::bitc::FUNC_CODE_BLOCKADDR_USERS
@ FUNC_CODE_BLOCKADDR_USERS
Definition:LLVMBitCodes.h:669
llvm::bitc::FUNC_CODE_INST_CLEANUPPAD
@ FUNC_CODE_INST_CLEANUPPAD
Definition:LLVMBitCodes.h:656
llvm::bitc::FUNC_CODE_INST_SHUFFLEVEC
@ FUNC_CODE_INST_SHUFFLEVEC
Definition:LLVMBitCodes.h:594
llvm::bitc::FUNC_CODE_INST_UNOP
@ FUNC_CODE_INST_UNOP
Definition:LLVMBitCodes.h:662
llvm::bitc::FUNC_CODE_INST_VAARG
@ FUNC_CODE_INST_VAARG
Definition:LLVMBitCodes.h:611
llvm::bitc::FUNC_CODE_INST_FREEZE
@ FUNC_CODE_INST_FREEZE
Definition:LLVMBitCodes.h:665
llvm::bitc::FUNC_CODE_INST_CMPXCHG
@ FUNC_CODE_INST_CMPXCHG
Definition:LLVMBitCodes.h:649
llvm::bitc::FUNC_CODE_INST_UNREACHABLE
@ FUNC_CODE_INST_UNREACHABLE
Definition:LLVMBitCodes.h:602
llvm::bitc::FUNC_CODE_INST_CAST
@ FUNC_CODE_INST_CAST
Definition:LLVMBitCodes.h:589
llvm::bitc::FUNC_CODE_DEBUG_LOC
@ FUNC_CODE_DEBUG_LOC
Definition:LLVMBitCodes.h:631
llvm::bitc::FUNC_CODE_DEBUG_RECORD_DECLARE
@ FUNC_CODE_DEBUG_RECORD_DECLARE
Definition:LLVMBitCodes.h:673
llvm::bitc::FUNC_CODE_OPERAND_BUNDLE
@ FUNC_CODE_OPERAND_BUNDLE
Definition:LLVMBitCodes.h:661
llvm::bitc::STRTAB_BLOB
@ STRTAB_BLOB
Definition:LLVMBitCodes.h:803
llvm::bitc::ICMP_SAME_SIGN
@ ICMP_SAME_SIGN
Definition:LLVMBitCodes.h:560
llvm::bitc::FIRST_APPLICATION_ABBREV
@ FIRST_APPLICATION_ABBREV
Definition:BitCodeEnums.h:60
llvm::bitc::PDI_DISJOINT
@ PDI_DISJOINT
Definition:LLVMBitCodes.h:545
llvm::bitc::NoNaNs
@ NoNaNs
Definition:LLVMBitCodes.h:527
llvm::bitc::ApproxFunc
@ ApproxFunc
Definition:LLVMBitCodes.h:532
llvm::bitc::AllowContract
@ AllowContract
Definition:LLVMBitCodes.h:531
llvm::bitc::NoSignedZeros
@ NoSignedZeros
Definition:LLVMBitCodes.h:529
llvm::bitc::NoInfs
@ NoInfs
Definition:LLVMBitCodes.h:528
llvm::bitc::AllowReassoc
@ AllowReassoc
Definition:LLVMBitCodes.h:533
llvm::bitc::AllowReciprocal
@ AllowReciprocal
Definition:LLVMBitCodes.h:530
llvm::bitc::OPERAND_BUNDLE_TAG
@ OPERAND_BUNDLE_TAG
Definition:LLVMBitCodes.h:183
llvm::bitc::PARAMATTR_GRP_CODE_ENTRY
@ PARAMATTR_GRP_CODE_ENTRY
Definition:LLVMBitCodes.h:131
llvm::bitc::PARAMATTR_CODE_ENTRY
@ PARAMATTR_CODE_ENTRY
Definition:LLVMBitCodes.h:130
llvm::bitc::SYNC_SCOPE_NAME
@ SYNC_SCOPE_NAME
Definition:LLVMBitCodes.h:187
llvm::bitc::SYMTAB_BLOB
@ SYMTAB_BLOB
Definition:LLVMBitCodes.h:807
llvm::bitc::MST_CODE_HASH
@ MST_CODE_HASH
Definition:LLVMBitCodes.h:202
llvm::bitc::MST_CODE_ENTRY
@ MST_CODE_ENTRY
Definition:LLVMBitCodes.h:201
llvm::bitc::BINOP_SHL
@ BINOP_SHL
Definition:LLVMBitCodes.h:475
llvm::bitc::BINOP_UREM
@ BINOP_UREM
Definition:LLVMBitCodes.h:473
llvm::bitc::BINOP_ADD
@ BINOP_ADD
Definition:LLVMBitCodes.h:468
llvm::bitc::BINOP_UDIV
@ BINOP_UDIV
Definition:LLVMBitCodes.h:471
llvm::bitc::BINOP_ASHR
@ BINOP_ASHR
Definition:LLVMBitCodes.h:477
llvm::bitc::BINOP_OR
@ BINOP_OR
Definition:LLVMBitCodes.h:479
llvm::bitc::BINOP_LSHR
@ BINOP_LSHR
Definition:LLVMBitCodes.h:476
llvm::bitc::BINOP_MUL
@ BINOP_MUL
Definition:LLVMBitCodes.h:470
llvm::bitc::BINOP_SDIV
@ BINOP_SDIV
Definition:LLVMBitCodes.h:472
llvm::bitc::BINOP_XOR
@ BINOP_XOR
Definition:LLVMBitCodes.h:480
llvm::bitc::BINOP_SREM
@ BINOP_SREM
Definition:LLVMBitCodes.h:474
llvm::bitc::BINOP_AND
@ BINOP_AND
Definition:LLVMBitCodes.h:478
llvm::bitc::BINOP_SUB
@ BINOP_SUB
Definition:LLVMBitCodes.h:469
llvm::bitc::ORDERING_ACQUIRE
@ ORDERING_ACQUIRE
Definition:LLVMBitCodes.h:567
llvm::bitc::ORDERING_ACQREL
@ ORDERING_ACQREL
Definition:LLVMBitCodes.h:569
llvm::bitc::ORDERING_RELEASE
@ ORDERING_RELEASE
Definition:LLVMBitCodes.h:568
llvm::bitc::ORDERING_NOTATOMIC
@ ORDERING_NOTATOMIC
Definition:LLVMBitCodes.h:564
llvm::bitc::ORDERING_UNORDERED
@ ORDERING_UNORDERED
Definition:LLVMBitCodes.h:565
llvm::bitc::ORDERING_SEQCST
@ ORDERING_SEQCST
Definition:LLVMBitCodes.h:570
llvm::bitc::ORDERING_MONOTONIC
@ ORDERING_MONOTONIC
Definition:LLVMBitCodes.h:566
llvm::cl::Hidden
@ Hidden
Definition:CommandLine.h:137
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition:CommandLine.h:443
llvm::dwarf::Index
Index
Definition:Dwarf.h:882
llvm::dwarf::Tag
Tag
Definition:Dwarf.h:103
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:378
llvm::lltok::Kind
Kind
Definition:LLToken.h:18
llvm::logicalview::LVPrintKind::Summary
@ Summary
llvm::logicalview::LVReportKind::View
@ View
llvm::logicalview::LVAttributeKind::Inserted
@ Inserted
llvm::memprof
Definition:MemoryProfileInfo.h:21
llvm::memprof::Meta
Meta
Definition:MemProf.h:45
llvm::memprof::computeFrameHistogram< LinearFrameId >
template llvm::DenseMap< LinearFrameId, FrameStat > computeFrameHistogram< LinearFrameId >(llvm::MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &MemProfCallStackData)
llvm::memprof::LinearFrameId
uint32_t LinearFrameId
Definition:MemProf.h:215
llvm::omp::RTLDependInfoFields::Flags
@ Flags
llvm::pdb::PDB_SymType::Callee
@ Callee
llvm::rdf::Code
NodeAddr< CodeNode * > Code
Definition:RDFGraph.h:388
llvm::support::endian::write32le
void write32le(void *P, uint32_t V)
Definition:Endian.h:468
llvm::support::endian::read32be
uint32_t read32be(const void *P)
Definition:Endian.h:434
llvm::tgtok::Bits
@ Bits
Definition:TGLexer.h:79
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::drop_begin
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition:STLExtras.h:329
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:354
llvm::PseudoProbeType::Block
@ Block
llvm::encode
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
Definition:Alignment.h:217
llvm::Write
@ Write
Definition:CodeGenData.h:108
llvm::WriteBitcodeToFile
void WriteBitcodeToFile(const Module &M, raw_ostream &Out, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the specified raw output stream.
Definition:BitcodeWriter.cpp:5371
llvm::enumerate
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Definition:STLExtras.h:2448
llvm::writeThinLinkBitcodeToFile
void writeThinLinkBitcodeToFile(const Module &M, raw_ostream &Out, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the given raw output...
Definition:BitcodeWriter.cpp:5579
llvm::make_range
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition:iterator_range.h:77
llvm::BWH_HeaderSize
@ BWH_HeaderSize
Definition:BitCodeEnums.h:32
llvm::ForceSummaryEdgesCold
FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold
Definition:ModuleSummaryAnalysis.cpp:67
llvm::append_range
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition:STLExtras.h:2115
llvm::writeIndexToFile
void writeIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out, const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex=nullptr, const GVSummaryPtrSet *DecSummaries=nullptr)
Write the specified module summary index to the given raw output stream, where it will be written in ...
Definition:BitcodeWriter.cpp:5418
llvm::embedBitcodeInModule
void embedBitcodeInModule(Module &M, MemoryBufferRef Buf, bool EmbedBitcode, bool EmbedCmdline, const std::vector< uint8_t > &CmdArgs)
If EmbedBitcode is set, save a copy of the llvm IR as data in the __LLVM,__bitcode section (....
Definition:BitcodeWriter.cpp:5647
llvm::any_of
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition:STLExtras.h:1746
llvm::write
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue)
Definition:DWP.cpp:625
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition:STLExtras.h:1664
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition:Error.cpp:167
llvm::AtomicOrdering
AtomicOrdering
Atomic ordering for LLVM's memory model.
Definition:AtomicOrdering.h:56
llvm::GVSummaryPtrSet
std::unordered_set< GlobalValueSummary * > GVSummaryPtrSet
A set of global value summary pointers.
Definition:ModuleSummaryIndex.h:1313
llvm::Op
DWARFExpression::Operation Op
Definition:DWARFExpression.cpp:22
llvm::ModuleToSummariesForIndexTy
std::map< std::string, GVSummaryMapTy, std::less<> > ModuleToSummariesForIndexTy
Map of a module name to the GUIDs and summaries we will import from that module.
Definition:ModuleSummaryIndex.h:1310
llvm::copy
OutputIt copy(R &&Range, OutputIt Out)
Definition:STLExtras.h:1841
llvm::BitWidth
constexpr unsigned BitWidth
Definition:BitmaskEnum.h:217
llvm::ModuleHash
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
Definition:ModuleSummaryIndex.h:1293
llvm::isBitcode
bool isBitcode(const unsigned char *BufPtr, const unsigned char *BufEnd)
isBitcode - Return true if the given bytes are the magic bytes for LLVM IR bitcode,...
Definition:BitcodeReader.h:265
llvm::Data
@ Data
Definition:SIMachineScheduler.h:55
llvm::TypeIdCompatibleVtableInfo
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
Definition:ModuleSummaryIndex.h:1341
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition:Error.h:1069
llvm::collectUsedGlobalVariables
GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallVectorImpl< GlobalValue * > &Vec, bool CompilerUsed)
Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...
Definition:Module.cpp:865
raw_ostream.h
N
#define N
NC
#define NC
Definition:regutils.h:42
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition:Alignment.h:39
llvm::AllocaPackedValues
Definition:BitcodeCommon.h:21
llvm::CalleeInfo
Class to accumulate and hold information about a callee.
Definition:ModuleSummaryIndex.h:59
llvm::CalleeInfo::RelBlockFreq
uint32_t RelBlockFreq
Definition:ModuleSummaryIndex.h:78
llvm::CalleeInfo::Hotness
uint32_t Hotness
Definition:ModuleSummaryIndex.h:70
llvm::CalleeInfo::HasTailCall
bool HasTailCall
Definition:ModuleSummaryIndex.h:73
llvm::CalleeInfo::RelBlockFreqBits
static constexpr unsigned RelBlockFreqBits
The value stored in RelBlockFreq has to be interpreted as the digits of a scaled number with a scale ...
Definition:ModuleSummaryIndex.h:77
llvm::FunctionSummary::FFlags
Flags specific to function summaries.
Definition:ModuleSummaryIndex.h:770
llvm::FunctionSummary::ParamAccess::RangeWidth
static constexpr uint32_t RangeWidth
Definition:ModuleSummaryIndex.h:840
llvm::GlobalValueSummary::GVFlags
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
Definition:ModuleSummaryIndex.h:484
llvm::GlobalValue::SanitizerMetadata
Definition:GlobalValue.h:318
llvm::GlobalVarSummary::GVarFlags
Definition:ModuleSummaryIndex.h:1151
llvm::MaybeAlign
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition:Alignment.h:117
llvm::TargetRegistry::lookupTarget
static const Target * lookupTarget(StringRef Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
Definition:TargetRegistry.cpp:154
llvm::TypeIdSummary
Definition:ModuleSummaryIndex.h:1284
llvm::UseListOrder
Structure to hold a use-list order.
Definition:UseListOrder.h:26
llvm::ValID
ValID - Represents a reference of a definition of some sort with no type.
Definition:LLParser.h:53
llvm::ValueInfo
Struct that holds a reference to a particular GUID in a global value summary.
Definition:ModuleSummaryIndex.h:180
llvm::WholeProgramDevirtResolution::ByArg
Definition:ModuleSummaryIndex.h:1258
llvm::WholeProgramDevirtResolution::ByArg::Bit
uint32_t Bit
Definition:ModuleSummaryIndex.h:1276
llvm::WholeProgramDevirtResolution::ByArg::Info
uint64_t Info
Additional information for the resolution:
Definition:ModuleSummaryIndex.h:1270
llvm::WholeProgramDevirtResolution::ByArg::TheKind
enum llvm::WholeProgramDevirtResolution::ByArg::Kind TheKind
llvm::WholeProgramDevirtResolution::ByArg::Byte
uint32_t Byte
Definition:ModuleSummaryIndex.h:1275
llvm::WholeProgramDevirtResolution
Definition:ModuleSummaryIndex.h:1247
llvm::WholeProgramDevirtResolution::TheKind
enum llvm::WholeProgramDevirtResolution::Kind TheKind
llvm::WholeProgramDevirtResolution::ResByArg
std::map< std::vector< uint64_t >, ByArg > ResByArg
Resolutions for calls with all constant integer arguments (excluding the first argument,...
Definition:ModuleSummaryIndex.h:1281
llvm::WholeProgramDevirtResolution::SingleImplName
std::string SingleImplName
Definition:ModuleSummaryIndex.h:1256
llvm::cl::desc
Definition:CommandLine.h:409

Generated on Fri Jul 18 2025 10:25:26 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp