1//===- Bitcode/Writer/BitcodeWriter.cpp - Bitcode Writer ------------------===// 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 7//===----------------------------------------------------------------------===// 9// Bitcode writer implementation. 11//===----------------------------------------------------------------------===// 31#include "llvm/Config/llvm-config.h" 91cl::desc(
"Number of metadatas above which we emit an index " 92"to enable lazy-loading"));
95cl::desc(
"The threshold (unit M) for flushing LLVM bitcode."));
99cl::desc(
"Write relative block frequency to function summary "));
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. 113// VALUE_SYMTAB_BLOCK abbrev id's. 117 VST_BBENTRY_6_ABBREV,
119// CONSTANTS_BLOCK abbrev id's. 121 CONSTANTS_INTEGER_ABBREV,
122 CONSTANTS_CE_CAST_Abbrev,
123 CONSTANTS_NULL_Abbrev,
125// FUNCTION_BLOCK abbrev id's. 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,
140/// Abstract class to manage the bitcode writing, subclassed for each bitcode 142classBitcodeWriterBase {
144 /// The stream created and owned by the client. 150 /// Constructs a BitcodeWriterBase object that writes to the provided 153 : Stream(Stream), StrtabBuilder(StrtabBuilder) {}
156void writeModuleVersion();
159void BitcodeWriterBase::writeModuleVersion() {
160// VERSION: [version#] 164/// Base class to manage the module bitcode writing, currently subclassed for 165/// ModuleBitcodeWriter and ThinLinkBitcodeWriter. 166classModuleBitcodeWriterBase :
public BitcodeWriterBase {
168 /// The Module to write to bitcode. 171 /// Enumerates ids for all values in the module. 174 /// Optional per-module index to write for ThinLTO. 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;
182 /// Tracks the last value id recorded in the GUIDToValueMap. 183unsigned GlobalValueId;
185 /// Saves the offset of the VSTOffset record that must eventually be 186 /// backpatched with the offset of the actual VST. 190 /// Constructs a ModuleBitcodeWriterBase object for the given Module, 191 /// writing to the provided \p Buffer. 194bool ShouldPreserveUseListOrder,
196 : BitcodeWriterBase(Stream, StrtabBuilder),
M(
M),
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. 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 214for (
auto &CallEdge :
FS->calls())
215if (!CallEdge.first.haveGVs() || !CallEdge.first.getValue())
216 assignValueId(CallEdge.first.getGUID());
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 222for (
auto &RefEdge :
FS->refs())
223if (!RefEdge.haveGVs() || !RefEdge.getValue())
224 assignValueId(RefEdge.getGUID());
229void writePerModuleGlobalValueSummary();
232void writePerModuleFunctionSummaryRecord(
234unsigned ValueID,
unsigned FSCallsAbbrev,
unsigned FSCallsProfileAbbrev,
235unsigned CallsiteAbbrev,
unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
240unsigned FSModRefsAbbrev,
241unsigned FSModVTableRefsAbbrev);
244 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
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");
256// Helper to get the valueId for the type of value recorded in VI. 258if (!
VI.haveGVs() || !
VI.getValue())
259return getValueId(
VI.getGUID());
263 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
266/// Class to manage the bitcode writing for a module. 267classModuleBitcodeWriter :
public ModuleBitcodeWriterBase {
268 /// True if a module hash record should be written. 271 /// If non-null, when GenerateHash is true, the resulting hash is written 277 /// The start bit of the identification block. 281 /// Constructs a ModuleBitcodeWriter object for the given Module, 282 /// writing to the provided \p Buffer. 287 : ModuleBitcodeWriterBase(
M, StrtabBuilder, Stream,
288 ShouldPreserveUseListOrder,
Index),
289 GenerateHash(GenerateHash), ModHash(ModHash),
290 BitcodeStartBit(Stream.GetCurrentBitNo()) {}
292 /// Emit the current module to the bitstream. 296uint64_t bitcodeStartBit() {
return BitcodeStartBit; }
300void writeAttributeGroupTable();
301void writeAttributeTable();
302void writeTypeTable();
304void writeValueSymbolTableForwardDecl();
305void writeModuleInfo();
310unsigned createDILocationAbbrev();
313unsigned createGenericDINodeAbbrev();
381unsigned createNamedMetadataAbbrev();
383unsigned createMetadataStringsAbbrev();
388 std::vector<unsigned> *MDAbbrevs =
nullptr,
389 std::vector<uint64_t> *IndexPos =
nullptr);
390void writeModuleMetadata();
391void writeFunctionMetadata(
constFunction &
F);
392void writeFunctionMetadataAttachment(
constFunction &
F);
395void writeModuleMetadataKinds();
396void writeOperandBundleTags();
397void writeSyncScopeNames();
398void writeConstants(
unsigned FirstVal,
unsigned LastVal,
bool isGlobal);
399void writeModuleConstants();
400bool pushValueAndType(
constValue *V,
unsigned InstID,
402bool pushValueOrMetadata(
constValue *V,
unsigned InstID,
404void writeOperandBundles(
constCallBase &CB,
unsigned InstID);
405void pushValue(
constValue *V,
unsigned InstID,
407void pushValueSigned(
constValue *V,
unsigned InstID,
409void writeInstruction(
constInstruction &
I,
unsigned InstID,
412void writeGlobalValueSymbolTable(
419void writeBlockInfo();
429/// Class to manage the bitcode writing for a combined index. 430classIndexBitcodeWriter :
public BitcodeWriterBase {
431 /// The combined index to write to bitcode. 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. 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. 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;
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;
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. 456 /// Tracks the last value id recorded in the GUIDToValueMap. 457unsigned GlobalValueId = 0;
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. 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. 475 : BitcodeWriterBase(Stream, StrtabBuilder),
Index(
Index),
476 DecSummaries(DecSummaries),
477 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
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 486 StackIdIndicesToIndex.
insert({StackIdIndex, StackIds.size()});
488 StackIds.push_back(
Index.getStackIdAtIndex(StackIdIndex));
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([&](GVInfo
I,
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). 502auto *
FS = dyn_cast<FunctionSummary>(
I.second);
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 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;
523for (
autoIdx : CI.StackIdIndices)
524 RecordStackIdReference(
Idx);
526for (
auto &AI :
FS->allocs())
527for (
auto &MIB : AI.MIBs)
528for (
autoIdx : MIB.StackIdIndices)
529 RecordStackIdReference(
Idx);
533 /// The below iterator returns the GUID and associated summary. 534usingGVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>;
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);
552for (
auto &Summaries : Index)
553for (
auto &Summary : Summaries.second.SummaryList)
554 Callback({Summaries.first,
Summary.get()},
false);
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);
576// Since StringMap iteration order isn't guaranteed, order by path string 578// FIXME: Make this a vector of StringMapEntry instead to avoid the later 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));
589 /// Main entry point for writing a combined index to bitcode. 593void writeModStrings();
594void writeCombinedGlobalValueSummary();
597auto VMI = GUIDToValueIdMap.find(ValGUID);
598if (VMI == GUIDToValueIdMap.end())
603 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
606}
// end anonymous namespace 637case Instruction::Add:
639case Instruction::Sub:
641case Instruction::Mul:
644case Instruction::FDiv:
647case Instruction::FRem:
704// Code: [strchar x N] 711// Emit the finished record. 717case Attribute::Alignment:
719case Attribute::AllocAlign:
721case Attribute::AllocSize:
723case Attribute::AlwaysInline:
725case Attribute::Builtin:
727case Attribute::ByVal:
729case Attribute::Convergent:
731case Attribute::InAlloca:
735case Attribute::DisableSanitizerInstrumentation:
737case Attribute::FnRetThunkExtern:
741case Attribute::ElementType:
743case Attribute::HybridPatchable:
745case Attribute::InlineHint:
747case Attribute::InReg:
749case Attribute::JumpTable:
751case Attribute::MinSize:
753case Attribute::AllocatedPointer:
755case Attribute::AllocKind:
757case Attribute::Memory:
759case Attribute::NoFPClass:
761case Attribute::Naked:
765case Attribute::NoAlias:
767case Attribute::NoBuiltin:
769case Attribute::NoCallback:
771case Attribute::NoCapture:
773case Attribute::NoDivergenceSource:
775case Attribute::NoDuplicate:
777case Attribute::NoFree:
779case Attribute::NoImplicitFloat:
781case Attribute::NoInline:
783case Attribute::NoRecurse:
785case Attribute::NoMerge:
787case Attribute::NonLazyBind:
789case Attribute::NonNull:
791case Attribute::Dereferenceable:
793case Attribute::DereferenceableOrNull:
795case Attribute::NoRedZone:
797case Attribute::NoReturn:
799case Attribute::NoSync:
801case Attribute::NoCfCheck:
803case Attribute::NoProfile:
805case Attribute::SkipProfile:
807case Attribute::NoUnwind:
809case Attribute::NoSanitizeBounds:
811case Attribute::NoSanitizeCoverage:
813case Attribute::NullPointerIsValid:
815case Attribute::OptimizeForDebugging:
817case Attribute::OptForFuzzing:
819case Attribute::OptimizeForSize:
821case Attribute::OptimizeNone:
823case Attribute::ReadNone:
825case Attribute::ReadOnly:
827case Attribute::Returned:
829case Attribute::ReturnsTwice:
833case Attribute::Speculatable:
835case Attribute::StackAlignment:
837case Attribute::StackProtect:
839case Attribute::StackProtectReq:
841case Attribute::StackProtectStrong:
843case Attribute::SafeStack:
845case Attribute::ShadowCallStack:
847case Attribute::StrictFP:
849case Attribute::StructRet:
851case Attribute::SanitizeAddress:
853case Attribute::SanitizeHWAddress:
855case Attribute::SanitizeThread:
857case Attribute::SanitizeType:
859case Attribute::SanitizeMemory:
861case Attribute::SanitizeNumericalStability:
863case Attribute::SanitizeRealtime:
865case Attribute::SanitizeRealtimeBlocking:
867case Attribute::SpeculativeLoadHardening:
869case Attribute::SwiftError:
871case Attribute::SwiftSelf:
873case Attribute::SwiftAsync:
875case Attribute::UWTable:
877case Attribute::VScaleRange:
879case Attribute::WillReturn:
881case Attribute::WriteOnly:
885case Attribute::ImmArg:
887case Attribute::SanitizeMemTag:
889case Attribute::Preallocated:
891case Attribute::NoUndef:
893case Attribute::ByRef:
895case Attribute::MustProgress:
897case Attribute::PresplitCoroutine:
899case Attribute::Writable:
901case Attribute::CoroDestroyOnlyWhenComplete:
903case Attribute::CoroElideSafe:
905case Attribute::DeadOnUnwind:
907case Attribute::Range:
909case Attribute::Initializes:
911case Attribute::NoExt:
913case Attribute::Captures:
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();
941for (
unsigned i = 0; i < NumWords; i++)
961void ModuleBitcodeWriter::writeAttributeGroupTable() {
962const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
964if (AttrGrps.empty())
return;
970unsigned AttrListIndex = Pair.first;
973Record.push_back(AttrListIndex);
976if (Attr.isEnumAttribute()) {
979 }
elseif (Attr.isIntAttribute()) {
982Record.push_back(Attr.getValueAsInt());
983 }
elseif (Attr.isStringAttribute()) {
994 }
elseif (Attr.isTypeAttribute()) {
995Type *Ty = Attr.getValueAsType();
996Record.push_back(Ty ? 6 : 5);
1000 }
elseif (Attr.isConstantRangeAttribute()) {
1004/*EmitBitWidth=*/true);
1006assert(Attr.isConstantRangeListAttribute());
1024void ModuleBitcodeWriter::writeAttributeTable() {
1026if (
Attrs.empty())
return;
1032for (
unsigned i :
AL.indexes()) {
1045/// WriteTypeTable - Write out the type table for a module. 1046void ModuleBitcodeWriter::writeTypeTable() {
1054// Abbrev for TYPE_CODE_OPAQUE_POINTER. 1055auto Abbv = std::make_shared<BitCodeAbbrev>();
1058unsigned OpaquePtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1060// Abbrev for TYPE_CODE_FUNCTION. 1061 Abbv = std::make_shared<BitCodeAbbrev>();
1066unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1068// Abbrev for TYPE_CODE_STRUCT_ANON. 1069 Abbv = std::make_shared<BitCodeAbbrev>();
1074unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1076// Abbrev for TYPE_CODE_STRUCT_NAME. 1077 Abbv = std::make_shared<BitCodeAbbrev>();
1081unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1083// Abbrev for TYPE_CODE_STRUCT_NAMED. 1084 Abbv = std::make_shared<BitCodeAbbrev>();
1089unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1091// Abbrev for TYPE_CODE_ARRAY. 1092 Abbv = std::make_shared<BitCodeAbbrev>();
1096unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1098// Emit an entry count so the reader can reserve space. 1103// Loop over all of the types, emitting each in turn. 1104for (
Type *
T : TypeList) {
1108switch (
T->getTypeID()) {
1131// OPAQUE_POINTER: [address space] 1135 AbbrevToUse = OpaquePtrAbbrev;
1140// FUNCTION: [isvararg, retty, paramty x N] 1144for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
1146 AbbrevToUse = FunctionAbbrev;
1151// STRUCT: [ispacked, eltty x N] 1153// Output all of the element types. 1154for (
Type *ET :
ST->elements())
1157if (
ST->isLiteral()) {
1159 AbbrevToUse = StructAnonAbbrev;
1161if (
ST->isOpaque()) {
1165 AbbrevToUse = StructNamedAbbrev;
1168// Emit the name if it is present. 1169if (!
ST->getName().empty())
1177// ARRAY: [numelts, eltty] 1179 TypeVals.
push_back(AT->getNumElements());
1181 AbbrevToUse = ArrayAbbrev;
1187// VECTOR [numelts, eltty] or 1188// [numelts, eltty, scalable] 1190 TypeVals.
push_back(VT->getElementCount().getKnownMinValue());
1192if (isa<ScalableVectorType>(VT))
1202for (
Type *InnerTy :
TET->type_params())
1204for (
unsigned IntParam :
TET->int_params())
1212// Emit the finished record. 1213 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
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);
1267// Decode the flags for GlobalValue in the summary. See getDecodedGVSummaryFlags 1268// in BitcodeReader.cpp. 1270bool ImportAsDecl =
false) {
1273 RawFlags |= Flags.NotEligibleToImport;
// bool 1274 RawFlags |= (Flags.Live << 1);
1275 RawFlags |= (Flags.DSOLocal << 2);
1276 RawFlags |= (Flags.CanAutoHide << 3);
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 1283 RawFlags |= (Flags.Visibility << 8);
// 2 bits 1285unsigned ImportType = Flags.ImportType | ImportAsDecl;
1286 RawFlags |= (ImportType << 10);
// 1 bit 1292uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
1293 (Flags.Constant << 2) | Flags.VCallVisibility << 3;
1300 RawFlags |= CI.
Hotness;
// 3 bits 1309 RawFlags |= CI.
RelBlockFreq;
// CalleeInfo::RelBlockFreqBits bits 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;
1345switch (
C.getSelectionKind()) {
1362case GlobalValue::UnnamedAddr::None:
return 0;
1363case GlobalValue::UnnamedAddr::Local:
return 2;
1364case GlobalValue::UnnamedAddr::Global:
return 1;
1369size_t ModuleBitcodeWriter::addToStrtab(
StringRef Str) {
1372return StrtabBuilder.
add(Str);
1375void ModuleBitcodeWriter::writeComdats() {
1378// COMDAT: [strtab offset, strtab size, selection_kind] 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>();
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. 1401unsigned VSTOffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1403// Emit the placeholder 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. 1415/// Determine the encoding to use for the given string name and length. 1421if ((
unsignedchar)
C & 128)
1422// don't bother scanning the rest. 1431"Sanitizer Metadata is too large for naive serialization.");
1434returnMeta.NoAddress | (
Meta.NoHWAddress << 1) |
1435 (
Meta.Memtag << 2) | (
Meta.IsDynInit << 3);
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())
1446const std::string &
DL =
M.getDataLayoutStr();
1449if (!
M.getModuleInlineAsm().empty())
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;
1458unsigned MaxGlobalType = 0;
1459constauto UpdateMaxAlignment = [&MaxAlignment](
constMaybeAlignA) {
1461 MaxAlignment = !MaxAlignment ? *
A : std::max(*MaxAlignment, *
A);
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())];
1472Entry = SectionMap.size();
1477 UpdateMaxAlignment(
F.getAlign());
1478if (
F.hasSection()) {
1479// Give section names unique ID's. 1480unsigned &
Entry = SectionMap[std::string(
F.getSection())];
1484Entry = SectionMap.size();
1488// Same for GC names. 1489unsigned &
Entry = GCMap[
F.getGC()];
1493Entry = GCMap.size();
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>();
1509//| explicitType << 1 1513if (!MaxAlignment)
// Alignment. 1516unsigned MaxEncAlignment = getEncodedAlign(MaxAlignment);
1520if (SectionMap.empty())
// Section. 1525// Don't bother emitting vis + thread local. 1526 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1530// Emit the module's source file name. 1539// MODULE_CODE_SOURCE_FILENAME: [namechar x N] 1540auto Abbv = std::make_shared<BitCodeAbbrev>();
1543 Abbv->Add(AbbrevOpToUse);
1544unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1546for (
constautoP :
M.getSourceFileName())
1549// Emit the finished record. 1554// Emit the global variable information. 1556unsigned AbbrevToUse = 0;
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()));
1565 Vals.
push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1569 Vals.
push_back(getEncodedAlign(GV.getAlign()));
1570 Vals.
push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1572if (GV.isThreadLocal() ||
1574 GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1575 GV.isExternallyInitialized() ||
1577 GV.hasComdat() || GV.hasAttributes() || GV.isDSOLocal() ||
1578 GV.hasPartition() || GV.hasSanitizerMetadata() || GV.getCodeModel()) {
1582 Vals.
push_back(GV.isExternallyInitialized());
1590 Vals.
push_back(addToStrtab(GV.getPartition()));
1591 Vals.
push_back(GV.getPartition().size());
1594 GV.getSanitizerMetadata())
1598 AbbrevToUse = SimpleGVarAbbrev;
1605// Emit the function proto information. 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] 1618 Vals.
push_back(getEncodedAlign(
F.getAlign()));
1619 Vals.
push_back(
F.hasSection() ? SectionMap[std::string(
F.getSection())]
1631F.hasPersonalityFn() ? (VE.
getValueID(
F.getPersonalityFn()) + 1) : 0);
1635 Vals.
push_back(addToStrtab(
F.getPartition()));
1638unsigned AbbrevToUse = 0;
1643// Emit the alias information. 1645// ALIAS: [strtab offset, strtab size, alias type, aliasee val#, linkage, 1646// visibility, dllstorageclass, threadlocal, unnamed_addr, 1651 Vals.
push_back(
A.getType()->getAddressSpace());
1659 Vals.
push_back(addToStrtab(
A.getPartition()));
1662unsigned AbbrevToUse = 0;
1667// Emit the ifunc information. 1669// IFUNC: [strtab offset, strtab size, ifunc type, address space, resolver 1670// val#, linkage, visibility, DSO_Local] 1674 Vals.
push_back(
I.getType()->getAddressSpace());
1679 Vals.
push_back(addToStrtab(
I.getPartition()));
1685 writeValueSymbolTableForwardDecl();
1691if (
constauto *OBO = dyn_cast<OverflowingBinaryOperator>(V)) {
1692if (OBO->hasNoSignedWrap())
1694if (OBO->hasNoUnsignedWrap())
1696 }
elseif (
constauto *PEO = dyn_cast<PossiblyExactOperator>(V)) {
1699 }
elseif (
constauto *PDI = dyn_cast<PossiblyDisjointInst>(V)) {
1700if (PDI->isDisjoint())
1702 }
elseif (
constauto *FPMO = dyn_cast<FPMathOperator>(V)) {
1703if (FPMO->hasAllowReassoc())
1705if (FPMO->hasNoNaNs())
1707if (FPMO->hasNoInfs())
1709if (FPMO->hasNoSignedZeros())
1711if (FPMO->hasAllowReciprocal())
1713if (FPMO->hasAllowContract())
1715if (FPMO->hasApproxFunc())
1717 }
elseif (
constauto *NNI = dyn_cast<PossiblyNonNegInst>(V)) {
1718if (NNI->hasNonNeg())
1720 }
elseif (
constauto *TI = dyn_cast<TruncInst>(V)) {
1721if (TI->hasNoSignedWrap())
1723if (TI->hasNoUnsignedWrap())
1725 }
elseif (
constauto *
GEP = dyn_cast<GEPOperator>(V)) {
1726if (
GEP->isInBounds())
1728if (
GEP->hasNoUnsignedSignedWrap())
1730if (
GEP->hasNoUnsignedWrap())
1732 }
elseif (
constauto *ICmp = dyn_cast<ICmpInst>(V)) {
1733if (ICmp->hasSameSign())
1740void ModuleBitcodeWriter::writeValueAsMetadata(
1742// Mimic an MDNode with a value as one operand. 1750void ModuleBitcodeWriter::writeMDTuple(
constMDTuple *
N,
1755assert(!(MD && isa<LocalAsMetadata>(MD)) &&
1756"Unexpected function-local metadata");
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>();
1779void ModuleBitcodeWriter::writeDILocation(
constDILocation *
N,
1783 Abbrev = createDILocationAbbrev();
1785Record.push_back(
N->isDistinct());
1786Record.push_back(
N->getLine());
1787Record.push_back(
N->getColumn());
1790Record.push_back(
N->isImplicitCode());
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>();
1810void ModuleBitcodeWriter::writeGenericDINode(
constGenericDINode *
N,
1814 Abbrev = createGenericDINodeAbbrev();
1816Record.push_back(
N->isDistinct());
1818Record.push_back(0);
// Per-tag version field; unused for now. 1820for (
auto &
I :
N->operands())
1827void ModuleBitcodeWriter::writeDISubrange(
constDISubrange *
N,
1841void ModuleBitcodeWriter::writeDIGenericSubrange(
1854void ModuleBitcodeWriter::writeDIEnumerator(
constDIEnumerator *
N,
1858Record.push_back(IsBigInt | (
N->isUnsigned() << 1) |
N->isDistinct());
1859Record.push_back(
N->getValue().getBitWidth());
1867void ModuleBitcodeWriter::writeDIBasicType(
constDIBasicType *
N,
1870Record.push_back(
N->isDistinct());
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());
1883void ModuleBitcodeWriter::writeDIStringType(
constDIStringType *
N,
1886Record.push_back(
N->isDistinct());
1892Record.push_back(
N->getSizeInBits());
1893Record.push_back(
N->getAlignInBits());
1894Record.push_back(
N->getEncoding());
1900void ModuleBitcodeWriter::writeDIDerivedType(
constDIDerivedType *
N,
1903Record.push_back(
N->isDistinct());
1907Record.push_back(
N->getLine());
1910Record.push_back(
N->getSizeInBits());
1911Record.push_back(
N->getAlignInBits());
1912Record.push_back(
N->getOffsetInBits());
1913Record.push_back(
N->getFlags());
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);
1925if (
auto PtrAuthData =
N->getPtrAuthData())
1926Record.push_back(PtrAuthData->RawData);
1934void ModuleBitcodeWriter::writeDICompositeType(
1937constunsigned IsNotUsedInOldTypeRef = 0x2;
1938Record.push_back(IsNotUsedInOldTypeRef | (
unsigned)
N->isDistinct());
1942Record.push_back(
N->getLine());
1945Record.push_back(
N->getSizeInBits());
1946Record.push_back(
N->getAlignInBits());
1947Record.push_back(
N->getOffsetInBits());
1948Record.push_back(
N->getFlags());
1950Record.push_back(
N->getRuntimeLang());
1960Record.push_back(
N->getNumExtraInhabitants());
1967void ModuleBitcodeWriter::writeDISubroutineType(
1970constunsigned HasNoOldTypeRefs = 0x2;
1971Record.push_back(HasNoOldTypeRefs | (
unsigned)
N->isDistinct());
1972Record.push_back(
N->getFlags());
1980void ModuleBitcodeWriter::writeDIFile(
constDIFile *
N,
1983Record.push_back(
N->isDistinct());
1986if (
N->getRawChecksum()) {
1987Record.push_back(
N->getRawChecksum()->Kind);
1990// Maintain backwards compatibility with the old internal representation of 1991// CSK_None in ChecksumKind by writing nulls here when Checksum is None. 2003void ModuleBitcodeWriter::writeDICompileUnit(
constDICompileUnit *
N,
2006assert(
N->isDistinct() &&
"Expected distinct compile units");
2007Record.push_back(
/* IsDistinct */true);
2008Record.push_back(
N->getSourceLanguage());
2011Record.push_back(
N->isOptimized());
2013Record.push_back(
N->getRuntimeVersion());
2015Record.push_back(
N->getEmissionKind());
2018Record.push_back(
/* subprograms */ 0);
2021Record.push_back(
N->getDWOId());
2023Record.push_back(
N->getSplitDebugInlining());
2024Record.push_back(
N->getDebugInfoForProfiling());
2025Record.push_back((
unsigned)
N->getNameTableKind());
2026Record.push_back(
N->getRangesBaseAddress());
2034void ModuleBitcodeWriter::writeDISubprogram(
constDISubprogram *
N,
2038constuint64_t HasSPFlagsFlag = 1 << 2;
2039Record.push_back(
uint64_t(
N->isDistinct()) | HasUnitFlag | HasSPFlagsFlag);
2044Record.push_back(
N->getLine());
2046Record.push_back(
N->getScopeLine());
2048Record.push_back(
N->getSPFlags());
2049Record.push_back(
N->getVirtualIndex());
2050Record.push_back(
N->getFlags());
2055Record.push_back(
N->getThisAdjustment());
2067Record.push_back(
N->isDistinct());
2070Record.push_back(
N->getLine());
2071Record.push_back(
N->getColumn());
2077void ModuleBitcodeWriter::writeDILexicalBlockFile(
2080Record.push_back(
N->isDistinct());
2083Record.push_back(
N->getDiscriminator());
2089void ModuleBitcodeWriter::writeDICommonBlock(
constDICommonBlock *
N,
2092Record.push_back(
N->isDistinct());
2097Record.push_back(
N->getLineNo());
2103void ModuleBitcodeWriter::writeDINamespace(
constDINamespace *
N,
2106Record.push_back(
N->isDistinct() |
N->getExportSymbols() << 1);
2114void ModuleBitcodeWriter::writeDIMacro(
constDIMacro *
N,
2117Record.push_back(
N->isDistinct());
2118Record.push_back(
N->getMacinfoType());
2119Record.push_back(
N->getLine());
2127void ModuleBitcodeWriter::writeDIMacroFile(
constDIMacroFile *
N,
2130Record.push_back(
N->isDistinct());
2131Record.push_back(
N->getMacinfoType());
2132Record.push_back(
N->getLine());
2140void ModuleBitcodeWriter::writeDIArgList(
constDIArgList *
N,
2142Record.reserve(
N->getArgs().size());
2150void ModuleBitcodeWriter::writeDIModule(
constDIModule *
N,
2153Record.push_back(
N->isDistinct());
2154for (
auto &
I :
N->operands())
2156Record.push_back(
N->getLineNo());
2157Record.push_back(
N->getIsDecl());
2163void ModuleBitcodeWriter::writeDIAssignID(
constDIAssignID *
N,
2166// There are no arguments for this metadata type. 2167Record.push_back(
N->isDistinct());
2172void ModuleBitcodeWriter::writeDITemplateTypeParameter(
2175Record.push_back(
N->isDistinct());
2178Record.push_back(
N->isDefault());
2184void ModuleBitcodeWriter::writeDITemplateValueParameter(
2187Record.push_back(
N->isDistinct());
2191Record.push_back(
N->isDefault());
2198void ModuleBitcodeWriter::writeDIGlobalVariable(
2207Record.push_back(
N->getLine());
2209Record.push_back(
N->isLocalToUnit());
2210Record.push_back(
N->isDefinition());
2213Record.push_back(
N->getAlignInBits());
2220void ModuleBitcodeWriter::writeDILocalVariable(
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;
2241Record.push_back(
N->getLine());
2244Record.push_back(
N->getFlags());
2245Record.push_back(
N->getAlignInBits());
2252void ModuleBitcodeWriter::writeDILabel(
2259Record.push_back(
N->getLine());
2265void ModuleBitcodeWriter::writeDIExpression(
constDIExpression *
N,
2268Record.reserve(
N->getElements().size() + 1);
2271Record.append(
N->elements_begin(),
N->elements_end());
2277void ModuleBitcodeWriter::writeDIGlobalVariableExpression(
2280Record.push_back(
N->isDistinct());
2291Record.push_back(
N->isDistinct());
2294Record.push_back(
N->getLine());
2297Record.push_back(
N->getAttributes());
2304void ModuleBitcodeWriter::writeDIImportedEntity(
2307Record.push_back(
N->isDistinct());
2311Record.push_back(
N->getLine());
2320unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
2321auto Abbv = std::make_shared<BitCodeAbbrev>();
2328void ModuleBitcodeWriter::writeNamedMetadata(
2330if (
M.named_metadata_empty())
2333unsigned Abbrev = createNamedMetadataAbbrev();
2337Record.append(Str.bytes_begin(), Str.bytes_end());
2341// Write named metadata operands. 2342for (
constMDNode *
N : NMD.operands())
2349unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
2350auto Abbv = std::make_shared<BitCodeAbbrev>();
2358/// Write out a record for MDString. 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(
2367// Start the record with the number of strings. 2369Record.push_back(Strings.size());
2371// Emit the sizes of the strings in the blob. 2376W.EmitVBR(cast<MDString>(MD)->getLength(), 6);
2380// Add the offset to the strings to the record. 2383// Add the strings to the blob. 2385 Blob.
append(cast<MDString>(MD)->getString());
2387// Emit the final record. 2392// Generates an enum to use as an index in the Abbrev array of Metadata record. 2394#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID, 2395#include "llvm/IR/Metadata.def" 2399void ModuleBitcodeWriter::writeMetadataRecords(
2401 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
2405// Initialize MDNode abbreviations. 2406#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0; 2407#include "llvm/IR/Metadata.def" 2412if (
constMDNode *
N = dyn_cast<MDNode>(MD)) {
2413assert(
N->isResolved() &&
"Expected forward references to be resolved");
2415switch (
N->getMetadataID()) {
2418#define HANDLE_MDNODE_LEAF(CLASS) \ 2419 case Metadata::CLASS##Kind: \ 2421 write##CLASS(cast<CLASS>(N), Record, \ 2422 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \ 2424 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \ 2426#include "llvm/IR/Metadata.def" 2429if (
auto *
AL = dyn_cast<DIArgList>(MD)) {
2433 writeValueAsMetadata(cast<ValueAsMetadata>(MD),
Record);
2437void ModuleBitcodeWriter::writeModuleMetadata() {
2438if (!VE.
hasMDs() &&
M.named_metadata_empty())
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;
2449 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
2450 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
2451 createGenericDINodeAbbrev();
2453auto Abbv = std::make_shared<BitCodeAbbrev>();
2457unsigned OffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2459 Abbv = std::make_shared<BitCodeAbbrev>();
2463unsigned IndexAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2465// Emit MDStrings together upfront. 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. 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. 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. 2484// This index will contain the bitpos for each individual record. 2485 std::vector<uint64_t> IndexPos;
2488// Write all the records 2492// Now that we have emitted all the records we will emit the index. But 2494// backpatch the forward reference so that the reader can skip the records 2499// Delta encode the index. 2500uint64_t PreviousValue = IndexOffsetRecordBitPos;
2501for (
auto &Elt : IndexPos) {
2502auto EltDelta = Elt - PreviousValue;
2503 PreviousValue = Elt;
2506// Emit the index record. 2511// Write the named metadata now. 2512 writeNamedMetadata(
Record);
2514auto AddDeclAttachedMetadata = [&](
constGlobalObject &GO) {
2517 pushGlobalMetadataAttachment(
Record, GO);
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). 2526if (GV.hasMetadata())
2527 AddDeclAttachedMetadata(GV);
2532void ModuleBitcodeWriter::writeFunctionMetadata(
constFunction &
F) {
2543void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2545// [n x [id, mdnode]] 2548for (
constauto &
I : MDs) {
2554void ModuleBitcodeWriter::writeFunctionMetadataAttachment(
constFunction &
F) {
2559if (
F.hasMetadata()) {
2560 pushGlobalMetadataAttachment(
Record,
F);
2565// Write metadata attachments 2566// METADATA_ATTACHMENT - [m x [value, [n x [id, mdnode]]] 2571I.getAllMetadataOtherThanDebugLoc(MDs);
2573// If no metadata, ignore instruction. 2574if (MDs.
empty())
continue;
2578for (
unsigned i = 0, e = MDs.
size(); i != e; ++i) {
2579Record.push_back(MDs[i].first);
2589void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2592// Write metadata kinds 2593// METADATA_KIND - [n x [id, name]] 2595M.getMDKindNames(Names);
2597if (Names.
empty())
return;
2601for (
unsigned MDKindID = 0, e = Names.
size(); MDKindID != e; ++MDKindID) {
2602Record.push_back(MDKindID);
2613void ModuleBitcodeWriter::writeOperandBundleTags() {
2614// Write metadata kinds 2616// OPERAND_BUNDLE_TAGS_BLOCK_ID : N x OPERAND_BUNDLE_TAG 2618// OPERAND_BUNDLE_TAG - [strchr x N] 2621M.getOperandBundleTags(Tags);
2630for (
auto Tag : Tags) {
2640void ModuleBitcodeWriter::writeSyncScopeNames() {
2642M.getContext().getSyncScopeNames(SSNs);
2649for (
auto SSN : SSNs) {
2650Record.append(SSN.begin(), SSN.end());
2658void ModuleBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
2660if (FirstVal == LastVal)
return;
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. 2670// Abbrev for CST_CODE_AGGREGATE. 2671auto Abbv = std::make_shared<BitCodeAbbrev>();
2675 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2677// Abbrev for CST_CODE_STRING. 2678 Abbv = std::make_shared<BitCodeAbbrev>();
2682 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2683// Abbrev for CST_CODE_CSTRING. 2684 Abbv = std::make_shared<BitCodeAbbrev>();
2688 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2689// Abbrev for CST_CODE_CSTRING. 2690 Abbv = std::make_shared<BitCodeAbbrev>();
2694 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
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();
2708 CONSTANTS_SETTYPE_ABBREV);
2712if (
constInlineAsm *IA = dyn_cast<InlineAsm>(V)) {
2715unsigned(
IA->hasSideEffects()) |
unsigned(
IA->isAlignStack()) << 1 |
2716unsigned(
IA->getDialect() & 1) << 2 |
unsigned(
IA->canThrow()) << 3);
2718// Add the asm string. 2719const std::string &AsmStr =
IA->getAsmString();
2720Record.push_back(AsmStr.size());
2721Record.append(AsmStr.begin(), AsmStr.end());
2723// Add the constraint string. 2724const std::string &ConstraintStr =
IA->getConstraintString();
2725Record.push_back(ConstraintStr.size());
2726Record.append(ConstraintStr.begin(), ConstraintStr.end());
2733unsigned AbbrevToUse = 0;
2734if (
C->isNullValue()) {
2736 }
elseif (isa<PoisonValue>(
C)) {
2738 }
elseif (isa<UndefValue>(
C)) {
2741if (
IV->getBitWidth() <= 64) {
2745 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2746 }
else {
// Wide integers, > 64 bits in size. 2750 }
elseif (
constConstantFP *CFP = dyn_cast<ConstantFP>(
C)) {
2755Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
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();
2761Record.push_back((p[1] << 48) | (p[0] >> 16));
2762Record.push_back(p[0] & 0xffffLL);
2764APInt api = CFP->getValueAPF().bitcastToAPInt();
2769assert(0 &&
"Unknown FP type!");
2771 }
elseif (isa<ConstantDataSequential>(
C) &&
2772 cast<ConstantDataSequential>(
C)->isString()) {
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()) {
2779 --NumElts;
// Don't encode the null, which isn't allowed by char6. 2782 AbbrevToUse = String8Abbrev;
2786for (
unsigned i = 0; i != NumElts; ++i) {
2787unsignedcharV = Str->getElementAsInteger(i);
2789 isCStr7 &= (
V & 128) == 0;
2795 AbbrevToUse = CString6Abbrev;
2797 AbbrevToUse = CString7Abbrev;
2799 dyn_cast<ConstantDataSequential>(
C)) {
2801Type *EltTy = CDS->getElementType();
2802if (isa<IntegerType>(EltTy)) {
2803for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2804Record.push_back(CDS->getElementAsInteger(i));
2806for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2808 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
2810 }
elseif (isa<ConstantAggregate>(
C)) {
2814 AbbrevToUse = AggregateAbbrev;
2815 }
elseif (
constConstantExpr *CE = dyn_cast<ConstantExpr>(
C)) {
2816switch (
CE->getOpcode()) {
2823 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2825assert(
CE->getNumOperands() == 2 &&
"Unknown constant expr!");
2835case Instruction::FNeg: {
2836assert(
CE->getNumOperands() == 1 &&
"Unknown constant expr!");
2845case Instruction::GetElementPtr: {
2847constauto *GO = cast<GEPOperator>(
C);
2850if (std::optional<ConstantRange>
Range = GO->getInRange()) {
2860case Instruction::ExtractElement:
2867case Instruction::InsertElement:
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()) {
2890 }
elseif (
constBlockAddress *BA = dyn_cast<BlockAddress>(
C)) {
2895 }
elseif (
constauto *Equiv = dyn_cast<DSOLocalEquivalent>(
C)) {
2899 }
elseif (
constauto *
NC = dyn_cast<NoCFIValue>(
C)) {
2903 }
elseif (
constauto *CPA = dyn_cast<ConstantPtrAuth>(
C)) {
2922void ModuleBitcodeWriter::writeModuleConstants() {
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);
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. 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,
2946// Make encoding relative to the InstID. 2948if (
ValID >= InstID) {
2955bool ModuleBitcodeWriter::pushValueOrMetadata(
constValue *V,
unsigned InstID,
2957bool IsMetadata =
V->getType()->isMetadataTy();
2960Metadata *MD = cast<MetadataAsValue>(V)->getMetadata();
2965return pushValueAndType(V, InstID, Vals);
2968void ModuleBitcodeWriter::writeOperandBundles(
constCallBase &CS,
2975Record.push_back(
C.getOperandBundleTagID(Bundle.getTagName()));
2977for (
auto &Input : Bundle.Inputs)
2978 pushValueOrMetadata(Input, InstID,
Record);
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,
2993void ModuleBitcodeWriter::pushValueSigned(
constValue *V,
unsigned InstID,
2996 int64_t diff = ((int32_t)InstID - (int32_t)
ValID);
3000/// WriteInstruction - Emit an instruction to the specified stream. 3001void ModuleBitcodeWriter::writeInstruction(
constInstruction &
I,
3005unsigned AbbrevToUse = 0;
3007switch (
I.getOpcode()) {
3011if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3012 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
3017if (AbbrevToUse == FUNCTION_INST_CAST_ABBREV)
3018 AbbrevToUse = FUNCTION_INST_CAST_FLAGS_ABBREV;
3022assert(isa<BinaryOperator>(
I) &&
"Unknown instruction!");
3024if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3025 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
3026 pushValue(
I.getOperand(1), InstID, Vals);
3030if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
3031 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
3036case Instruction::FNeg: {
3038if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3039 AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
3043if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
3044 AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
3049case Instruction::GetElementPtr: {
3051 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
3052auto &GEPInst = cast<GetElementPtrInst>(
I);
3056 pushValueAndType(
Op, InstID, Vals);
3059case Instruction::ExtractValue: {
3061 pushValueAndType(
I.getOperand(0), InstID, Vals);
3066case Instruction::InsertValue: {
3068 pushValueAndType(
I.getOperand(0), InstID, Vals);
3069 pushValueAndType(
I.getOperand(1), InstID, Vals);
3074case Instruction::Select: {
3076 pushValueAndType(
I.getOperand(1), InstID, Vals);
3077 pushValue(
I.getOperand(2), InstID, Vals);
3078 pushValueAndType(
I.getOperand(0), InstID, Vals);
3084case Instruction::ExtractElement:
3086 pushValueAndType(
I.getOperand(0), InstID, Vals);
3087 pushValueAndType(
I.getOperand(1), InstID, Vals);
3089case Instruction::InsertElement:
3091 pushValueAndType(
I.getOperand(0), InstID, Vals);
3092 pushValue(
I.getOperand(1), InstID, Vals);
3093 pushValueAndType(
I.getOperand(2), InstID, Vals);
3095case Instruction::ShuffleVector:
3097 pushValueAndType(
I.getOperand(0), InstID, Vals);
3098 pushValue(
I.getOperand(1), InstID, Vals);
3099 pushValue(cast<ShuffleVectorInst>(
I).getShuffleMaskForBitcode(), InstID,
3102case Instruction::ICmp:
3103case Instruction::FCmp: {
3104// compare returning Int1Ty or vector of Int1Ty 3106 pushValueAndType(
I.getOperand(0), InstID, Vals);
3107 pushValue(
I.getOperand(1), InstID, Vals);
3115case Instruction::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;
3126 pushValueAndType(
Op, InstID, Vals);
3130case Instruction::Br:
3135if (
II.isConditional()) {
3137 pushValue(
II.getCondition(), InstID, Vals);
3141case Instruction::Switch:
3146 pushValue(
SI.getCondition(), InstID, Vals);
3148for (
auto Case :
SI.cases()) {
3154case Instruction::IndirectBr:
3157// Encode the address operand as relative, but not the basic blocks. 3158 pushValue(
I.getOperand(0), InstID, Vals);
3163case Instruction::Invoke: {
3168if (
II->hasOperandBundles())
3169 writeOperandBundles(*
II, InstID);
3178 pushValueAndType(Callee, InstID, Vals);
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. 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 3191case Instruction::Resume:
3193 pushValueAndType(
I.getOperand(0), InstID, Vals);
3195case Instruction::CleanupRet: {
3197constauto &CRI = cast<CleanupReturnInst>(
I);
3198 pushValue(CRI.getCleanupPad(), InstID, Vals);
3199if (CRI.hasUnwindDest())
3203case Instruction::CatchRet: {
3205constauto &CRI = cast<CatchReturnInst>(
I);
3206 pushValue(CRI.getCatchPad(), InstID, Vals);
3210case Instruction::CleanupPad:
3211case Instruction::CatchPad: {
3212constauto &FuncletPad = cast<FuncletPadInst>(
I);
3215 pushValue(FuncletPad.getParentPad(), InstID, Vals);
3217unsigned NumArgOperands = FuncletPad.arg_size();
3219for (
unsignedOp = 0;
Op != NumArgOperands; ++
Op)
3220 pushValueAndType(FuncletPad.getArgOperand(
Op), InstID, Vals);
3223case Instruction::CatchSwitch: {
3225constauto &CatchSwitch = cast<CatchSwitchInst>(
I);
3227 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
3229unsigned NumHandlers = CatchSwitch.getNumHandlers();
3231for (
constBasicBlock *CatchPadBB : CatchSwitch.handlers())
3234if (CatchSwitch.hasUnwindDest())
3238case Instruction::CallBr: {
3244 writeOperandBundles(*CBI, InstID);
3259 pushValueAndType(Callee, InstID, Vals);
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. 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 3272case Instruction::Unreachable:
3274 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
3277case Instruction::PHI: {
3278constPHINode &PN = cast<PHINode>(
I);
3280// With the newer instruction encoding, forward references could give 3281// negative valued IDs. This is most common for PHIs, so we use 3294// Emit a Vals64 vector and exit. 3295 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
3300case Instruction::LandingPad: {
3311 pushValueAndType(LP.
getClause(
I), InstID, Vals);
3316case Instruction::Alloca: {
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);
3330 Bitfield::set<APV::ExplicitType>(
Record,
true);
3335if (AS !=
M.getDataLayout().getAllocaAddrSpace())
3340case Instruction::Load:
3341if (cast<LoadInst>(
I).isAtomic()) {
3343 pushValueAndType(
I.getOperand(0), InstID, Vals);
3346if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
// ptr 3347 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
3351 Vals.
push_back(cast<LoadInst>(
I).isVolatile());
3352if (cast<LoadInst>(
I).isAtomic()) {
3354 Vals.
push_back(getEncodedSyncScopeID(cast<LoadInst>(
I).getSyncScopeID()));
3357case Instruction::Store:
3358if (cast<StoreInst>(
I).isAtomic())
3362 pushValueAndType(
I.getOperand(1), InstID, Vals);
// ptrty + ptr 3363 pushValueAndType(
I.getOperand(0), InstID, Vals);
// valty + val 3365 Vals.
push_back(cast<StoreInst>(
I).isVolatile());
3366if (cast<StoreInst>(
I).isAtomic()) {
3369 getEncodedSyncScopeID(cast<StoreInst>(
I).getSyncScopeID()));
3372case Instruction::AtomicCmpXchg:
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());
3381 getEncodedSyncScopeID(cast<AtomicCmpXchgInst>(
I).getSyncScopeID()));
3384 Vals.
push_back(cast<AtomicCmpXchgInst>(
I).isWeak());
3387case Instruction::AtomicRMW:
3389 pushValueAndType(
I.getOperand(0), InstID, Vals);
// ptrty + ptr 3390 pushValueAndType(
I.getOperand(1), InstID, Vals);
// valty + val 3393 Vals.
push_back(cast<AtomicRMWInst>(
I).isVolatile());
3396 getEncodedSyncScopeID(cast<AtomicRMWInst>(
I).getSyncScopeID()));
3399case Instruction::Fence:
3402 Vals.
push_back(getEncodedSyncScopeID(cast<FenceInst>(
I).getSyncScopeID()));
3404case Instruction::Call: {
3409 writeOperandBundles(CI, InstID);
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())
3434 pushValue(CI.
getArgOperand(i), InstID, Vals);
// fixed param. 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 3444case Instruction::VAArg:
3447 pushValue(
I.getOperand(0), InstID, Vals);
// valist. 3450case Instruction::Freeze:
3452 pushValueAndType(
I.getOperand(0), InstID, Vals);
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(
3464// Get the offset of the VST we are writing, and backpatch it into 3465// the VST forward declaration record. 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);
3477auto Abbv = std::make_shared<BitCodeAbbrev>();
3481unsigned FnEntryAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3486if (
F.isDeclaration())
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;
3506/// Emit names for arguments, instructions and basic blocks in a function. 3507void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
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. 3519// Figure out the encoding to use for the name. 3522unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
3525// VST_CODE_ENTRY: [valueid, namechar x N] 3526// VST_CODE_BBENTRY: [bbid, namechar x N] 3528if (isa<BasicBlock>(
Name.getValue())) {
3531 AbbrevToUse = VST_BBENTRY_6_ABBREV;
3535 AbbrevToUse = VST_ENTRY_6_ABBREV;
3537 AbbrevToUse = VST_ENTRY_7_ABBREV;
3540for (
constautoP :
Name.getKey())
3543// Emit the finished record. 3544 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
3551void ModuleBitcodeWriter::writeUseList(
UseListOrder &&Order) {
3552assert(Order.Shuffle.size() >= 2 &&
"Shuffle too small");
3554if (isa<BasicBlock>(Order.V))
3564void ModuleBitcodeWriter::writeUseListBlock(
constFunction *
F) {
3566"Expected to be preserving use-list order");
3568auto hasMore = [&]() {
3583/// Emit a function body to the module stream. 3584void ModuleBitcodeWriter::writeFunction(
3587// Save the bitcode index of the start of this function block for recording 3596// Emit the number of basic blocks, so the reader can create them ahead of 3602// If there are function-local constants, emit them now. 3603unsigned CstStart, CstEnd;
3605 writeConstants(CstStart, CstEnd,
false);
3607// If there is function-local metadata, emit it now. 3608 writeFunctionMetadata(
F);
3610// Keep a running idea of what the instruction ID is. 3611unsigned InstID = CstEnd;
3613bool NeedsMetadataAttachment =
F.hasMetadata();
3618// Finally, emit all the instructions, in order. 3621 writeInstruction(
I, InstID, Vals);
3623if (!
I.getType()->isVoidTy())
3626// If the instruction has metadata, write a metadata attachment later. 3627 NeedsMetadataAttachment |=
I.hasMetadataOtherThanDebugLoc();
3629// If the instruction has a debug location, emit it. 3632// Just repeat the same debug loc as last time. 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. 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,
3657"RawLocation unexpectedly null in DbgVariableRecord");
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)) {
3668// The metadata is a DIArgList, or ValueAsMetadata wrapping a 3669// fwd-ref. Push the metadata ID. 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()) {
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) 3692// dbg_declare (FUNC_CODE_DEBUG_RECORD_DECLARE) 3693// ..., LocationMetadata 3694// dbg_assign (FUNC_CODE_DEBUG_RECORD_ASSIGN) 3695// ..., LocationMetadata, DIAssignID, DIExpression, LocationMetadata 3703 FUNCTION_DEBUG_RECORD_VALUE_ABBREV);
3725while (!Worklist.empty()) {
3726Value *
V = Worklist.pop_back_val();
3727for (
User *U :
V->users()) {
3728if (
auto *
I = dyn_cast<Instruction>(U)) {
3732 }
elseif (isa<Constant>(U) && !isa<GlobalValue>(U) &&
3733 Visited.insert(U).second)
3734 Worklist.push_back(U);
3740if (!BlockAddressUsers.
empty()) {
3748// Emit names for all the instructions etc. 3749if (
auto *Symtab =
F.getValueSymbolTable())
3750 writeFunctionLevelValueSymbolTable(*Symtab);
3752if (NeedsMetadataAttachment)
3753 writeFunctionMetadataAttachment(
F);
3755 writeUseListBlock(&
F);
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. 3767 {
// 8-bit fixed-width VST_CODE_ENTRY/VST_CODE_BBENTRY strings. 3768auto Abbv = std::make_shared<BitCodeAbbrev>();
3778 {
// 7-bit fixed width VST_CODE_ENTRY strings. 3779auto Abbv = std::make_shared<BitCodeAbbrev>();
3788 {
// 6-bit char6 VST_CODE_ENTRY strings. 3789auto Abbv = std::make_shared<BitCodeAbbrev>();
3798 {
// 6-bit char6 VST_CODE_BBENTRY strings. 3799auto Abbv = std::make_shared<BitCodeAbbrev>();
3805 VST_BBENTRY_6_ABBREV)
3809 {
// SETTYPE abbrev for CONSTANTS_BLOCK. 3810auto Abbv = std::make_shared<BitCodeAbbrev>();
3815 CONSTANTS_SETTYPE_ABBREV)
3819 {
// INTEGER abbrev for CONSTANTS_BLOCK. 3820auto Abbv = std::make_shared<BitCodeAbbrev>();
3824 CONSTANTS_INTEGER_ABBREV)
3828 {
// CE_CAST abbrev for CONSTANTS_BLOCK. 3829auto Abbv = std::make_shared<BitCodeAbbrev>();
3837 CONSTANTS_CE_CAST_Abbrev)
3840 {
// NULL abbrev for CONSTANTS_BLOCK. 3841auto Abbv = std::make_shared<BitCodeAbbrev>();
3844 CONSTANTS_NULL_Abbrev)
3848// FIXME: This should only use space for first class types! 3850 {
// INST_LOAD abbrev for FUNCTION_BLOCK. 3851auto Abbv = std::make_shared<BitCodeAbbrev>();
3859 FUNCTION_INST_LOAD_ABBREV)
3862 {
// INST_UNOP abbrev for FUNCTION_BLOCK. 3863auto Abbv = std::make_shared<BitCodeAbbrev>();
3868 FUNCTION_INST_UNOP_ABBREV)
3871 {
// INST_UNOP_FLAGS abbrev for FUNCTION_BLOCK. 3872auto Abbv = std::make_shared<BitCodeAbbrev>();
3878 FUNCTION_INST_UNOP_FLAGS_ABBREV)
3881 {
// INST_BINOP abbrev for FUNCTION_BLOCK. 3882auto Abbv = std::make_shared<BitCodeAbbrev>();
3888 FUNCTION_INST_BINOP_ABBREV)
3891 {
// INST_BINOP_FLAGS abbrev for FUNCTION_BLOCK. 3892auto Abbv = std::make_shared<BitCodeAbbrev>();
3899 FUNCTION_INST_BINOP_FLAGS_ABBREV)
3902 {
// INST_CAST abbrev for FUNCTION_BLOCK. 3903auto Abbv = std::make_shared<BitCodeAbbrev>();
3910 FUNCTION_INST_CAST_ABBREV)
3913 {
// INST_CAST_FLAGS abbrev for FUNCTION_BLOCK. 3914auto Abbv = std::make_shared<BitCodeAbbrev>();
3922 FUNCTION_INST_CAST_FLAGS_ABBREV)
3926 {
// INST_RET abbrev for FUNCTION_BLOCK. 3927auto Abbv = std::make_shared<BitCodeAbbrev>();
3930 FUNCTION_INST_RET_VOID_ABBREV)
3933 {
// INST_RET abbrev for FUNCTION_BLOCK. 3934auto Abbv = std::make_shared<BitCodeAbbrev>();
3938 FUNCTION_INST_RET_VAL_ABBREV)
3941 {
// INST_UNREACHABLE abbrev for FUNCTION_BLOCK. 3942auto Abbv = std::make_shared<BitCodeAbbrev>();
3945 FUNCTION_INST_UNREACHABLE_ABBREV)
3949auto Abbv = std::make_shared<BitCodeAbbrev>();
3957 FUNCTION_INST_GEP_ABBREV)
3961auto Abbv = std::make_shared<BitCodeAbbrev>();
3968 FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
3974/// Write the module path strings, currently only used when generating 3975/// a combined index file. 3976void IndexBitcodeWriter::writeModStrings() {
3979// TODO: See which abbrev sizes we actually need to emit 3981// 8-bit fixed-width MST_ENTRY strings. 3982auto Abbv = std::make_shared<BitCodeAbbrev>();
3987unsigned Abbrev8Bit = Stream.
EmitAbbrev(std::move(Abbv));
3989// 7-bit fixed width MST_ENTRY strings. 3990 Abbv = std::make_shared<BitCodeAbbrev>();
3995unsigned Abbrev7Bit = Stream.
EmitAbbrev(std::move(Abbv));
3997// 6-bit char6 MST_ENTRY strings. 3998 Abbv = std::make_shared<BitCodeAbbrev>();
4003unsigned Abbrev6Bit = Stream.
EmitAbbrev(std::move(Abbv));
4005// Module Hash, 160 bits SHA1. Optionally, emitted after each MST_CODE_ENTRY. 4006 Abbv = std::make_shared<BitCodeAbbrev>();
4013unsigned AbbrevHash = Stream.
EmitAbbrev(std::move(Abbv));
4020unsigned AbbrevToUse = Abbrev8Bit;
4022 AbbrevToUse = Abbrev6Bit;
4024 AbbrevToUse = Abbrev7Bit;
4026auto ModuleId = ModuleIdMap.
size();
4027 ModuleIdMap[
Key] = ModuleId;
4031// Emit the finished record. 4034// Emit an optional hash for the module now 4036 Vals.
assign(Hash.begin(), Hash.end());
4037// Emit the hash record. 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>
4052if (!FS->type_tests().empty())
4057auto WriteVFuncIdVec = [&](
uint64_t Ty,
4062for (
auto &VF : VFs) {
4063Record.push_back(VF.GUID);
4064Record.push_back(VF.Offset);
4070 FS->type_test_assume_vcalls());
4072 FS->type_checked_load_vcalls());
4074auto WriteConstVCallVec = [&](
uint64_t Ty,
4076for (
auto &VC : VCs) {
4078Record.push_back(VC.VFunc.GUID);
4079Record.push_back(VC.VFunc.Offset);
4086 FS->type_test_assume_const_vcalls());
4088 FS->type_checked_load_const_vcalls());
4098if (!FS->paramAccesses().empty()) {
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);
4109// If ValueID is unknown we can't drop just this call, we must drop 4114Record.push_back(*ValueID);
4115 WriteRange(Call.Offsets);
4123/// Collect type IDs from type tests used by function. 4126 std::set<GlobalValue::GUID> &ReferencedTypeIds) {
4127if (!FS->type_tests().empty())
4128for (
auto &TT : FS->type_tests())
4129 ReferencedTypeIds.insert(TT);
4131auto GetReferencedTypesFromVFuncIdVec =
4134 ReferencedTypeIds.insert(VF.GUID);
4137 GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls());
4138 GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls());
4140auto GetReferencedTypesFromConstVCallVec =
4143 ReferencedTypeIds.insert(VC.VFunc.GUID);
4146 GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls());
4147 GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls());
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);
4190for (
auto &W : Summary.WPDRes)
4202for (
auto &
P : Summary) {
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. 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) {
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});
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. 4239assert(!CallStacks.empty());
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,
4254unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
bool PerModule,
4255 std::function<
unsigned(
constValueInfo &VI)> GetValueID,
4256 std::function<
unsigned(
unsigned)> GetStackIndex,
4257bool WriteContextSizeInfoIndex,
4262for (
auto &CI : FS->callsites()) {
4264// Per module callsite clones should always have a single entry of 4266assert(!PerModule || (CI.Clones.size() == 1 && CI.Clones[0] == 0));
4267Record.push_back(GetValueID(CI.Callee));
4269Record.push_back(CI.StackIdIndices.size());
4270Record.push_back(CI.Clones.size());
4272for (
auto Id : CI.StackIdIndices)
4273Record.push_back(GetStackIndex(Id));
4275for (
auto V : CI.Clones)
4283for (
auto &AI : FS->allocs()) {
4285// Per module alloc versions should always have a single entry of 4287assert(!PerModule || (AI.Versions.size() == 1 && AI.Versions[0] == 0));
4288Record.push_back(AI.MIBs.size());
4290Record.push_back(AI.Versions.size());
4291for (
auto &MIB : AI.MIBs) {
4293// Record the index into the radix tree array for this context. 4294assert(CallStackCount <= CallStackPos.
size());
4295Record.push_back(CallStackPos[CallStackCount++]);
4298for (
auto V : AI.Versions)
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 4310// At least one context id per ContextSizeInfos entry (MIB), broken into 2 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. 4322Record.push_back(TotalSize);
4325// The context ids are expected by the reader to immediately precede the 4326// associated alloc info record. 4336// Helper to emit a single function summary record. 4337void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
4339unsigned ValueID,
unsigned FSCallsRelBFAbbrev,
4340unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
4341unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
constFunction &
F,
4349 Stream, FS, [&](
constValueInfo &VI) -> std::optional<unsigned> {
4354 Stream, FS, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId,
4356/*GetValueId*/ [&](
constValueInfo &VI) {
return getValueId(VI); },
4357/*GetStackIndex*/ [&](
unsignedI) {
returnI; },
4358/*WriteContextSizeInfoIndex*/true, CallStackPos, CallStackCount);
4360auto SpecialRefCnts =
FS->specialRefCounts();
4365 NameVals.
push_back(SpecialRefCnts.first);
// rorefcnt 4366 NameVals.
push_back(SpecialRefCnts.second);
// worefcnt 4368for (
auto &RI :
FS->refs())
4371constbool UseRelBFRecord =
4374for (
auto &ECI :
FS->calls()) {
4375 NameVals.
push_back(getValueId(ECI.first));
4383 (UseRelBFRecord ? FSCallsRelBFAbbrev : FSCallsProfileAbbrev);
4387// Emit the finished record. 4392// Collect the global value references in the given variable's initializer, 4393// and emit them in a summary record. 4394void ModuleBitcodeWriterBase::writeModuleLevelReferences(
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). 4404auto *
Summary =
VI.getSummaryList()[0].get();
4410auto VTableFuncs =
VS->vTableFuncs();
4411if (!VTableFuncs.empty())
4414unsigned SizeBeforeRefs = NameVals.
size();
4415for (
auto &RI :
VS->refs())
4417// Sort the refs for determinism output, the vector returned by FS->refs() has 4418// been initialized from a DenseSet. 4421if (VTableFuncs.empty())
4425// VTableFuncs pairs should already be sorted by offset. 4426for (
auto &
P : VTableFuncs) {
4432 FSModVTableRefsAbbrev);
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;
4444 mdconst::extract_or_null<ConstantInt>(
M.getModuleFlag(
"ThinLTO")))
4445 IsThinLTO = MD->getZExtValue();
4454// Write the index flags. 4456// Bits 1-3 are set only in the combined index, skip them. 4457if (
Index->enableSplitLTOUnit())
4459if (
Index->hasUnifiedLTO())
4469auto Abbv = std::make_shared<BitCodeAbbrev>();
4472// GUIDS often use up most of 64-bits, so encode as two Fixed 32. 4475unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4477for (
constauto &GVI : valueIds()) {
4480static_cast<uint32_t>(GVI.first >> 32),
4485if (!
Index->stackIds().empty()) {
4486auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
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. 4493unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4496for (
auto Id :
Index->stackIds()) {
4504auto ContextIdAbbv = std::make_shared<BitCodeAbbrev>();
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. 4510unsigned ContextIdAbbvId = Stream.
EmitAbbrev(std::move(ContextIdAbbv));
4512// Abbrev for FS_PERMODULE_PROFILE. 4513 Abbv = std::make_shared<BitCodeAbbrev>();
4522// numrefs x valueid, n x (valueid, hotness+tailcall flags) 4525unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4527// Abbrev for FS_PERMODULE_RELBF. 4528 Abbv = std::make_shared<BitCodeAbbrev>();
4537// numrefs x valueid, n x (valueid, rel_block_freq+tailcall]) 4540unsigned FSCallsRelBFAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4542// Abbrev for FS_PERMODULE_GLOBALVAR_INIT_REFS. 4543 Abbv = std::make_shared<BitCodeAbbrev>();
4549unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4551// Abbrev for FS_PERMODULE_VTABLE_GLOBALVAR_INIT_REFS. 4552 Abbv = std::make_shared<BitCodeAbbrev>();
4557// numrefs x valueid, n x (valueid , offset) 4560unsigned FSModVTableRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4562// Abbrev for FS_ALIAS. 4563 Abbv = std::make_shared<BitCodeAbbrev>();
4568unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4570// Abbrev for FS_TYPE_ID_METADATA 4571 Abbv = std::make_shared<BitCodeAbbrev>();
4575// n x (valueid , offset) 4578unsigned TypeIdCompatibleVtableAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4580 Abbv = std::make_shared<BitCodeAbbrev>();
4586unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4588 Abbv = std::make_shared<BitCodeAbbrev>();
4591// n x (alloc type, context radix tree index) 4592// optional: nummib x (numcontext x total size) 4595unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4597 Abbv = std::make_shared<BitCodeAbbrev>();
4602unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
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. 4611// Summary emission does not support anonymous functions, they have to be 4612// renamed using the anonymous function renaming pass. 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). 4623auto *
Summary =
VI.getSummaryList()[0].get();
4626 FS,
/*GetStackIndex*/ [](
unsignedI) {
returnI; }, CallStacks);
4628// Finalize the radix tree, write it out, and get the map of positions in the 4629// linearized tree array. 4631if (!CallStacks.
empty()) {
4636// Keep track of the current index into the CallStackPos map. 4640// Iterate over the list of functions instead of the Index to 4641// ensure the ordering is stable. 4643// Summary emission does not support anonymous functions, they have to 4644// renamed using the anonymous function renaming pass. 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). 4655auto *
Summary =
VI.getSummaryList()[0].get();
4656 writePerModuleFunctionSummaryRecord(
4657 NameVals, Summary, VE.
getValueID(&
F), FSCallsRelBFAbbrev,
4658 FSCallsProfileAbbrev, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId,
F,
4659 CallStackPos, CallStackCount);
4662// Capture references from GlobalVariable initializers, which are outside 4663// of a function scope. 4665 writeModuleLevelReferences(
G, NameVals, FSModRefsAbbrev,
4666 FSModVTableRefsAbbrev);
4669auto *Aliasee =
A.getAliaseeObject();
4670// Skip ifunc and nameless functions which don't have an entry in the 4672if (!Aliasee->hasName() || isa<GlobalIFunc>(Aliasee))
4685for (
auto &S :
Index->typeIdCompatibleVtableMap()) {
4689 TypeIdCompatibleVtableAbbrev);
4693if (
Index->getBlockCount())
4700/// Emit the combined summary section into the combined index file. 4701void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4707// Write the index flags. 4710auto Abbv = std::make_shared<BitCodeAbbrev>();
4713// GUIDS often use up most of 64-bits, so encode as two Fixed 32. 4716unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4718for (
constauto &GVI : valueIds()) {
4721static_cast<uint32_t>(GVI.first >> 32),
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>();
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. 4736unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4738 Vals.
reserve(StackIds.size() * 2);
4739for (
auto Id : StackIds) {
4746// Abbrev for FS_COMBINED_PROFILE. 4747 Abbv = std::make_shared<BitCodeAbbrev>();
4758// numrefs x valueid, n x (valueid, hotness+tailcall flags) 4761unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4763// Abbrev for FS_COMBINED_GLOBALVAR_INIT_REFS. 4764 Abbv = std::make_shared<BitCodeAbbrev>();
4771unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4773// Abbrev for FS_COMBINED_ALIAS. 4774 Abbv = std::make_shared<BitCodeAbbrev>();
4780unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4782 Abbv = std::make_shared<BitCodeAbbrev>();
4787// numstackindices x stackidindex, numver x version 4790unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4792 Abbv = std::make_shared<BitCodeAbbrev>();
4796// nummib x (alloc type, context radix tree index), 4798// optional: nummib x total size 4801unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4803 Abbv = std::make_shared<BitCodeAbbrev>();
4808unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4811if (DecSummaries ==
nullptr)
4813return DecSummaries->count(GVS);
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. 4820// Save the value id for each summary for alias emission. 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;
4829// For local linkage, we also emit the original name separately 4830// immediately after the record. 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. 4841 NameVals.
push_back(S.getOriginalName());
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. 4852 forEachSummary([&](GVInfo
I,
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. 4860auto *
FS = dyn_cast<FunctionSummary>(S);
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). 4871return StackIdIndicesToIndex[
I];
4875// Finalize the radix tree, write it out, and get the map of positions in the 4876// linearized tree array. 4878if (!CallStacks.
empty()) {
4883// Keep track of the current index into the CallStackPos map. 4887 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
4890 DefOrUseGUIDs.
insert(
I.first);
4892 DefOrUseGUIDs.
insert(
VI.getGUID());
4894auto ValueId = getValueId(
I.first);
4896 SummaryToValueIdMap[S] = *ValueId;
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). 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. 4911if (
auto *VS = dyn_cast<GlobalVarSummary>(S)) {
4914 NameVals.
push_back(ModuleIdMap[
VS->modulePath()]);
4918for (
auto &RI :
VS->refs()) {
4919auto RefValueId = getValueId(RI.getGUID());
4925// Emit the finished record. 4929 MaybeEmitOriginalName(*S);
4933auto GetValueId = [&](
constValueInfo &
VI) -> std::optional<unsigned> {
4936return getValueId(
VI.getGUID());
4939auto *
FS = cast<FunctionSummary>(S);
4944 Stream, FS, CallsiteAbbrev, AllocAbbrev,
/*ContextIdAbbvId*/ 0,
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. 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). 4963return StackIdIndicesToIndex[
I];
4965/*WriteContextSizeInfoIndex*/false, CallStackPos, CallStackCount);
4969 NameVals.
push_back(ModuleIdMap[
FS->modulePath()]);
4974// TODO: Stop writing entry count and bump bitcode version. 4982unsigned Count = 0, RORefCnt = 0, WORefCnt = 0;
4983for (
auto &RI :
FS->refs()) {
4984auto RefValueId = getValueId(RI.getGUID());
4990elseif (RI.isWriteOnly())
4994 NameVals[6] = Count;
4995 NameVals[7] = RORefCnt;
4996 NameVals[8] = WORefCnt;
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);
5008// Emit the finished record. 5010 FSCallsProfileAbbrev);
5012 MaybeEmitOriginalName(*S);
5015for (
auto *AS : Aliases) {
5016auto AliasValueId = SummaryToValueIdMap[AS];
5023auto AliaseeValueId = SummaryToValueIdMap[&AS->
getAliasee()];
5027// Emit the finished record. 5030 MaybeEmitOriginalName(*AS);
5032if (
auto *FS = dyn_cast<FunctionSummary>(&AS->
getAliasee()))
5036if (!
Index.cfiFunctionDefs().empty()) {
5037for (
auto &S :
Index.cfiFunctionDefs()) {
5044if (!NameVals.
empty()) {
5050if (!
Index.cfiFunctionDecls().empty()) {
5051for (
auto &S :
Index.cfiFunctionDecls()) {
5058if (!NameVals.
empty()) {
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)) {
5076if (
Index.getBlockCount())
5083/// Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the 5084/// current llvm version, and a record for the epoch number. 5088// Write the "user readable" string identifying the bitcode producer 5089auto Abbv = std::make_shared<BitCodeAbbrev>();
5093auto StringAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5095"LLVM" LLVM_VERSION_STRING, StringAbbrev);
5097// Write the epoch version 5098 Abbv = std::make_shared<BitCodeAbbrev>();
5101auto EpochAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5107void ModuleBitcodeWriter::writeModuleHash(
StringRef View) {
5108// Emit the module's hash. 5109// MODULE_CODE_HASH: [5*i32] 5114 std::array<uint8_t, 20> Hash = Hasher.result();
5115for (
int Pos = 0; Pos < 20; Pos += 4) {
5119// Emit the finished record. 5123// Save the written hash value. 5128void ModuleBitcodeWriter::write() {
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. 5136 writeModuleVersion();
5138// Emit blockinfo, which defines the standard abbreviations etc. 5141// Emit information describing all of the types in the module. 5144// Emit information about attribute groups. 5145 writeAttributeGroupTable();
5147// Emit information about parameter attributes. 5148 writeAttributeTable();
5152// Emit top-level description of module, including target triple, inline asm, 5153// descriptors for global variables, and function prototype info. 5157 writeModuleConstants();
5159// Emit metadata kind names. 5160 writeModuleMetadataKinds();
5163 writeModuleMetadata();
5165// Emit module-level use-lists. 5167 writeUseListBlock(
nullptr);
5169 writeOperandBundleTags();
5170 writeSyncScopeNames();
5172// Emit function bodies. 5175if (!
F.isDeclaration())
5176 writeFunction(
F, FunctionToBitcodeIndex);
5178// Need to write after the above call to WriteFunction which populates 5179// the summary information in the index. 5181 writePerModuleGlobalValueSummary();
5183 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
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. 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 ... 5211unsigned CPUType = ~0U;
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. 5218 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
5219 DARWIN_CPU_TYPE_X86 = 7,
5220 DARWIN_CPU_TYPE_ARM = 12,
5221 DARWIN_CPU_TYPE_POWERPC = 18
5226 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
5228 CPUType = DARWIN_CPU_TYPE_X86;
5230 CPUType = DARWIN_CPU_TYPE_POWERPC;
5232 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
5234 CPUType = DARWIN_CPU_TYPE_ARM;
5236// Traditional Bitcode starts after header. 5238"Expected header size to be reserved");
5242// Write the magic and version. 5243unsigned Position = 0;
5250// If the file is not a multiple of 16 bytes, insert dummy padding. 5251while (Buffer.
size() & 15)
5255/// Helper to write the header common to all bitcode files. 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);
5281auto Abbv = std::make_shared<BitCodeAbbrev>();
5284auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
5292assert(!WroteStrtab && !WroteSymtab);
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 5298if (M->getModuleInlineAsm().empty())
5302constTriple TT(M->getTargetTriple());
5304if (!
T || !
T->hasMCAsmParser())
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. 5326 std::vector<char> Strtab;
5328 Strtab.resize(StrtabBuilder.
getSize());
5332 {Strtab.data(), Strtab.size()});
5343bool ShouldPreserveUseListOrder,
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));
5355 ModuleBitcodeWriter ModuleWriter(M, StrtabBuilder, *Stream,
5356 ShouldPreserveUseListOrder, Index,
5357 GenerateHash, ModHash);
5358 ModuleWriter.write();
5365 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index, DecSummaries,
5366 ModuleToSummariesForIndex);
5367 IndexWriter.write();
5370/// Write the specified module to the specified output stream. 5372bool ShouldPreserveUseListOrder,
5376 Writer.writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
5378 Writer.writeSymtab();
5379 Writer.writeStrtab();
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 5400void IndexBitcodeWriter::write() {
5403 writeModuleVersion();
5405// Write the module paths in the combined index. 5408// Write the summary combined index records. 5409 writeCombinedGlobalValueSummary();
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. 5426 Writer.
writeIndex(&Index, ModuleToSummariesForIndex, DecSummaries);
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. 5445 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
5446/*ShouldPreserveUseListOrder=*/false, &
Index),
5447 ModHash(&ModHash) {}
5452void writeSimplifiedModuleInfo();
5455}
// end anonymous namespace 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 5462void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
5464// Emit the module's source file name. 5473// MODULE_CODE_SOURCE_FILENAME: [namechar x N] 5474auto Abbv = std::make_shared<BitCodeAbbrev>();
5477 Abbv->Add(AbbrevOpToUse);
5478unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5480for (
constautoP :
M.getSourceFileName())
5487// Emit the global variable information. 5489// GLOBALVAR: [strtab offset, strtab size, 0, 0, 0, linkage] 5501// Emit the function proto information. 5503// FUNCTION: [strtab offset, strtab size, 0, 0, 0, linkage] 5515// Emit the alias information. 5517// ALIAS: [strtab offset, strtab size, 0, 0, 0, linkage] 5529// Emit the ifunc information. 5531// IFUNC: [strtab offset, strtab size, 0, 0, 0, linkage] 5544void ThinLinkBitcodeWriter::write() {
5547 writeModuleVersion();
5549 writeSimplifiedModuleInfo();
5551 writePerModuleGlobalValueSummary();
5553// Write module hash. 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));
5571 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream, Index,
5573 ThinLinkWriter.write();
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. 5594switch (
T.getObjectFormat()) {
5596return"__LLVM,__bitcode";
5621switch (
T.getObjectFormat()) {
5623return"__LLVM,__cmdline";
5649const std::vector<uint8_t> &CmdArgs) {
5650// Save llvm.compiler.used and remove it. 5654Type *UsedElementType = Used ? Used->getValueType()->getArrayElementType()
5656for (
auto *GV : UsedGlobals) {
5657if (GV->getName() !=
"llvm.embedded.module" &&
5658 GV->getName() !=
"llvm.cmdline")
5663 Used->eraseFromParent();
5665// Embed the bitcode for the llvm module. 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. 5681// If the input is LLVM bitcode, write the input byte stream directly. 5691// Set alignment to 1 to prevent padding between two contributions from input 5692// sections after linking. 5697 M.getGlobalVariable(
"llvm.embedded.module",
true)) {
5698assert(Old->hasZeroLiveUses() &&
5699"llvm.embedded.module can only be used once in llvm.compiler.used");
5701 Old->eraseFromParent();
5703 GV->
setName(
"llvm.embedded.module");
5706// Skip if only bitcode needs to be embedded. 5708// Embed command-line options. 5721assert(Old->hasZeroLiveUses() &&
5722"llvm.cmdline can only be used once in llvm.compiler.used");
5724 Old->eraseFromParent();
5730if (UsedArray.
empty())
5733// Recreate llvm.compiler.used. 5738 NewUsed->setSection(
"llvm.metadata");
This file defines the StringMap class.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static void writeDIMacro(raw_ostream &Out, const DIMacro *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariableExpression(raw_ostream &Out, const DIGlobalVariableExpression *N, AsmWriterContext &WriterCtx)
static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, AsmWriterContext &WriterCtx)
static void writeDIStringType(raw_ostream &Out, const DIStringType *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, AsmWriterContext &WriterCtx)
static void writeDIModule(raw_ostream &Out, const DIModule *N, AsmWriterContext &WriterCtx)
static void writeDIFile(raw_ostream &Out, const DIFile *N, AsmWriterContext &)
static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, AsmWriterContext &WriterCtx)
static void writeDILabel(raw_ostream &Out, const DILabel *N, AsmWriterContext &WriterCtx)
static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, AsmWriterContext &WriterCtx)
static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, AsmWriterContext &WriterCtx)
static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N, AsmWriterContext &WriterCtx)
static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N, AsmWriterContext &WriterCtx)
static void writeDILocation(raw_ostream &Out, const DILocation *DL, AsmWriterContext &WriterCtx)
static void writeDINamespace(raw_ostream &Out, const DINamespace *N, AsmWriterContext &WriterCtx)
static void writeDICommonBlock(raw_ostream &Out, const DICommonBlock *N, AsmWriterContext &WriterCtx)
static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N, AsmWriterContext &)
static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N, AsmWriterContext &WriterCtx)
static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N, AsmWriterContext &WriterCtx)
static void writeDITemplateTypeParameter(raw_ostream &Out, const DITemplateTypeParameter *N, AsmWriterContext &WriterCtx)
static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N, AsmWriterContext &WriterCtx)
static void writeDIGenericSubrange(raw_ostream &Out, const DIGenericSubrange *N, AsmWriterContext &WriterCtx)
static void writeDISubrange(raw_ostream &Out, const DISubrange *N, AsmWriterContext &WriterCtx)
static void writeDILexicalBlockFile(raw_ostream &Out, const DILexicalBlockFile *N, AsmWriterContext &WriterCtx)
static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, AsmWriterContext &)
static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, AsmWriterContext &WriterCtx)
static void writeDIExpression(raw_ostream &Out, const DIExpression *N, AsmWriterContext &WriterCtx)
static void writeDIAssignID(raw_ostream &Out, const DIAssignID *DL, AsmWriterContext &WriterCtx)
static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, AsmWriterContext &WriterCtx)
static void writeDIArgList(raw_ostream &Out, const DIArgList *N, AsmWriterContext &WriterCtx, bool FromValue=false)
static void writeDITemplateValueParameter(raw_ostream &Out, const DITemplateValueParameter *N, AsmWriterContext &WriterCtx)
static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, AsmWriterContext &WriterCtx)
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
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)
static unsigned serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta)
static void writeTypeIdCompatibleVtableSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdCompatibleVtableInfo &Summary, ValueEnumerator &VE)
static void getReferencedTypeIds(FunctionSummary *FS, std::set< GlobalValue::GUID > &ReferencedTypeIds)
Collect type IDs from type tests used by function.
static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind)
static void collectMemProfCallStacks(FunctionSummary *FS, std::function< LinearFrameId(unsigned)> GetStackIndex, MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &CallStacks)
static unsigned getEncodedUnaryOpcode(unsigned Opcode)
static void emitSignedInt64(SmallVectorImpl< uint64_t > &Vals, uint64_t V)
static unsigned getEncodedVisibility(const GlobalValue &GV)
static uint64_t getOptimizationFlags(const Value *V)
static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage)
static unsigned getEncodedRMWOperation(AtomicRMWInst::BinOp Op)
static unsigned getEncodedThreadLocalMode(const GlobalValue &GV)
static DenseMap< CallStackId, LinearCallStackId > writeMemoryProfileRadixTree(MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &&CallStacks, BitstreamWriter &Stream, unsigned RadixAbbrev)
static void writeIdentificationBlock(BitstreamWriter &Stream)
Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the current llvm version,...
static unsigned getEncodedCastOpcode(unsigned Opcode)
static cl::opt< bool > WriteRelBFToSummary("write-relbf-to-summary", cl::Hidden, cl::init(false), cl::desc("Write relative block frequency to function summary "))
static cl::opt< uint32_t > FlushThreshold("bitcode-flush-threshold", cl::Hidden, cl::init(512), cl::desc("The threshold (unit M) for flushing LLVM bitcode."))
static unsigned getEncodedOrdering(AtomicOrdering Ordering)
static unsigned getEncodedUnnamedAddr(const GlobalValue &GV)
bool WriteNewDbgInfoFormatToBitcode
static unsigned getEncodedComdatSelectionKind(const Comdat &C)
static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags, bool ImportAsDecl=false)
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...
static void writeBitcodeHeader(BitstreamWriter &Stream)
Helper to write the header common to all bitcode files.
llvm::cl::opt< bool > UseNewDbgInfoFormat
static uint64_t getEncodedRelBFCallEdgeInfo(const CalleeInfo &CI)
static void writeWholeProgramDevirtResolutionByArg(SmallVector< uint64_t, 64 > &NameVals, const std::vector< uint64_t > &args, const WholeProgramDevirtResolution::ByArg &ByArg)
static void emitConstantRange(SmallVectorImpl< uint64_t > &Record, const ConstantRange &CR, bool EmitBitWidth)
static StringEncoding getStringEncoding(StringRef Str)
Determine the encoding to use for the given string name and length.
static uint64_t getEncodedGVarFlags(GlobalVarSummary::GVarFlags Flags)
static const char * getSectionNameForCommandline(const Triple &T)
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"))
static void writeTypeIdSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdSummary &Summary)
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 ...
static uint64_t getEncodedHotnessCallEdgeInfo(const CalleeInfo &CI)
static void emitWideAPInt(SmallVectorImpl< uint64_t > &Vals, const APInt &A)
static void writeStringRecord(BitstreamWriter &Stream, unsigned Code, StringRef Str, unsigned AbbrevToUse)
static void writeWholeProgramDevirtResolution(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, uint64_t Id, const WholeProgramDevirtResolution &Wpd)
static unsigned getEncodedDLLStorageClass(const GlobalValue &GV)
static void writeInt32ToBuffer(uint32_t Value, SmallVectorImpl< char > &Buffer, uint32_t &Position)
static const char * getSectionNameForBitcode(const Triple &T)
static unsigned getEncodedBinaryOpcode(unsigned Opcode)
static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
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
This file defines the DenseMap class.
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
static MaybeAlign getAlign(Value *Ptr)
Module.h This file contains the declarations for the Module class.
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"))
This file contains the declarations for metadata subclasses.
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
static const uint32_t IV[8]
Class for arbitrary precision integers.
unsigned getNumWords() const
Get the number of words.
unsigned getActiveWords() const
Compute the number of active words in the value of this APInt.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
int64_t getSExtValue() const
Get sign extended value.
Alias summary information.
const GlobalValueSummary & getAliasee() const
an instruction to allocate memory on the stack
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
unsigned getAddressSpace() const
Return the address space for the allocation.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
Class to represent array types.
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
BinOp
This enumeration lists the possible modifications atomicrmw can make.
@ USubCond
Subtract only if no unsigned overflow.
@ Min
*p = old <signed v ? old : v
@ USubSat
*p = usub.sat(old, v) usub.sat matches the behavior of llvm.usub.sat.
@ UIncWrap
Increment one up to a maximum value.
@ Max
*p = old >signed v ? old : v
@ UMin
*p = old <unsigned v ? old : v
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
@ UMax
*p = old >unsigned v ? old : v
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
@ UDecWrap
Decrement one until a minimum value or zero.
bool hasAttributes() const
Return true if attributes exists in this set.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ TombstoneKey
Use as Tombstone key for DenseMap of AttrKind.
@ None
No attributes have been set.
@ EmptyKey
Use as Empty key for DenseMap of AttrKind.
@ EndAttrKinds
Sentinel value useful for loops.
LLVM Basic Block Representation.
BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
static bool isChar6(char C)
isChar6 - Return true if this character is legal in the Char6 encoding.
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...
void writeIndex(const ModuleSummaryIndex *Index, const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex, const GVSummaryPtrSet *DecSummaries)
void copyStrtab(StringRef Strtab)
Copy the string table for another module into this bitcode file.
void writeStrtab()
Write the bitcode file's string table.
void writeSymtab()
Attempt to write a symbol table to the bitcode file.
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.
BitcodeWriter(SmallVectorImpl< char > &Buffer)
Create a BitcodeWriter that writes to Buffer.
unsigned EmitAbbrev(std::shared_ptr< BitCodeAbbrev > Abbv)
Emits the abbreviation Abbv to the stream.
void markAndBlockFlushing()
For scenarios where the user wants to access a section of the stream to (for example) compute some ch...
StringRef getMarkedBufferAndResumeFlushing()
resumes flushing, but does not flush, and returns the section in the internal buffer starting from th...
void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev=0)
EmitRecord - Emit the specified record to the stream, using an abbrev if we have one to compress the ...
void Emit(uint32_t Val, unsigned NumBits)
void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals, StringRef Blob)
EmitRecordWithBlob - Emit the specified record to the stream, using an abbrev that includes a blob at...
unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr< BitCodeAbbrev > Abbv)
EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified BlockID.
void EnterBlockInfoBlock()
EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
void BackpatchWord(uint64_t BitNo, unsigned Val)
void BackpatchWord64(uint64_t BitNo, uint64_t Val)
void EnterSubblock(unsigned BlockID, unsigned CodeLen)
uint64_t GetCurrentBitNo() const
Retrieve the current position in the stream, in bits.
void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals)
EmitRecordWithAbbrev - Emit a record with the specified abbreviation.
The address of a basic block.
static BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
Conditional or Unconditional Branch instruction.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
CallingConv::ID getCallingConv() const
Value * getCalledOperand() const
Value * getArgOperand(unsigned i) const
FunctionType * getFunctionType() const
unsigned arg_size() const
AttributeList getAttributes() const
Return the attributes for this call.
bool hasOperandBundles() const
Return true if this User has any operand bundles.
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
BasicBlock * getIndirectDest(unsigned i) const
BasicBlock * getDefaultDest() const
unsigned getNumIndirectDests() const
Return the number of callbr indirect dest labels.
This class represents a function call, abstracting a target machine's calling convention.
bool isNoTailCall() const
bool isMustTailCall() const
@ Largest
The linker will choose the largest COMDAT.
@ SameSize
The data referenced by the COMDAT must be the same size.
@ Any
The linker may choose any COMDAT.
@ NoDeduplicate
No deduplication is performed.
@ ExactMatch
The data referenced by the COMDAT must be the same.
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
A constant value that is initialized with an expression using other constant values.
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
ConstantFP - Floating Point Values [float, double].
This is the shared class of boolean and integer constants.
This class represents a range of values.
const APInt & getLower() const
Return the lower value for this range.
const APInt & getUpper() const
Return the upper value for this range.
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
ConstantRange sextOrTrunc(uint32_t BitWidth) const
Make this range have the bit width given by BitWidth.
This is an important base class in LLVM.
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
Basic type, like 'int' or 'float'.
A pair of DIGlobalVariable and DIExpression.
An imported module (C++ using directive or similar).
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
String type, Fortran CHARACTER(n)
Type array for a subprogram.
This class represents an Operation in the Expression.
Records a position in IR for a source label (DILabel).
Base class for non-instruction debug metadata records that have positions within IR.
DebugLoc getDebugLoc() const
Record of a variable value-assignment, aka a non instruction representation of the dbg....
DIAssignID * getAssignID() const
DIExpression * getExpression() const
DILocalVariable * getVariable() const
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
bool isDbgDeclare() const
Metadata * getRawAddress() const
DIExpression * getAddressExpression() const
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Implements a dense probed hash-table based set.
Lightweight error class with error context and mandatory checking.
This instruction extracts a struct member or array element value from an aggregate value.
idx_iterator idx_end() const
idx_iterator idx_begin() const
Function summary information to aid decisions and implementation of importing.
ForceSummaryHotnessType
Types for -force-summary-edges-cold debugging option.
Generic tagged DWARF-like metadata node.
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
void setSection(StringRef S)
Change the section for this global.
Function and variable summary information to aid decisions and implementation of importing.
GVFlags flags() const
Get the flags for this GlobalValue (see struct GVFlags).
StringRef modulePath() const
Get the path to the module containing this function.
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
VisibilityTypes getVisibility() const
static bool isLocalLinkage(LinkageTypes Linkage)
LinkageTypes getLinkage() const
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
ThreadLocalMode getThreadLocalMode() const
@ DLLExportStorageClass
Function to be accessible from DLL.
@ DLLImportStorageClass
Function to be imported from DLL.
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
@ DefaultVisibility
The GV is visible.
@ HiddenVisibility
The GV is hidden.
@ ProtectedVisibility
The GV is protected.
UnnamedAddr getUnnamedAddr() const
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ CommonLinkage
Tentative definitions.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
@ AppendingLinkage
Special purpose, only applies to global arrays.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
DLLStorageClassTypes getDLLStorageClass() const
Global variable summary information to aid decisions and implementation of importing.
This instruction inserts a struct field of array element value into an aggregate value.
idx_iterator idx_end() const
idx_iterator idx_begin() const
This is an important class for using LLVM in a threaded context.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
Tracking metadata reference owned by Metadata.
This class implements a map that also provides access to all stored values in a deterministic order.
size_t getBufferSize() const
const char * getBufferStart() const
const char * getBufferEnd() const
Root of the metadata hierarchy.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static constexpr uint64_t BitcodeSummaryVersion
A Module instance is used to store all the information related to an LLVM module.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
A class that wrap the SHA1 algorithm.
size_type size() const
Determine the number of elements in the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void append(StringRef RHS)
Append from a StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
const ValueTy & getValue() const
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
Utility for building string tables with deduplicated suffixes.
void finalizeInOrder()
Finalize the string table without reording it.
void write(raw_ostream &OS) const
size_t add(CachedHashStringRef S)
Add a string to the builder.
Class to represent struct types.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isX86_FP80Ty() const
Return true if this is x86 long double.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
@ TypedPointerTyID
Typed pointer used by some GPU targets.
@ HalfTyID
16-bit floating point type
@ TargetExtTyID
Target extension type.
@ VoidTyID
type with no size
@ ScalableVectorTyID
Scalable SIMD vector type.
@ FloatTyID
32-bit floating point type
@ IntegerTyID
Arbitrary bit width integers.
@ FixedVectorTyID
Fixed width SIMD vector type.
@ BFloatTyID
16-bit floating point type (7-bit significand)
@ DoubleTyID
64-bit floating point type
@ X86_FP80TyID
80-bit floating point type (X87)
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
@ FP128TyID
128-bit floating point type (112-bit significand)
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
bool isFP128Ty() const
Return true if this is 'fp128'.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Value wrapper in the Metadata hierarchy.
unsigned getTypeID(Type *T) const
unsigned getMetadataID(const Metadata *MD) const
UseListOrderStack UseListOrders
std::vector< std::pair< const Value *, unsigned > > ValueList
ArrayRef< const Metadata * > getNonMDStrings() const
Get the non-MDString metadata for this block.
unsigned getInstructionID(const Instruction *I) const
unsigned getAttributeListID(AttributeList PAL) const
void incorporateFunction(const Function &F)
incorporateFunction/purgeFunction - If you'd like to deal with a function, use these two methods to g...
void getFunctionConstantRange(unsigned &Start, unsigned &End) const
getFunctionConstantRange - Return the range of values that corresponds to function-local constants.
unsigned getAttributeGroupID(IndexAndAttrSet Group) const
bool hasMDs() const
Check whether the current block has any metadata to emit.
unsigned getComdatID(const Comdat *C) const
uint64_t computeBitsRequiredForTypeIndices() const
unsigned getValueID(const Value *V) const
unsigned getMetadataOrNullID(const Metadata *MD) const
const std::vector< IndexAndAttrSet > & getAttributeGroups() const
const ValueList & getValues() const
unsigned getGlobalBasicBlockID(const BasicBlock *BB) const
getGlobalBasicBlockID - This returns the function-specific ID for the specified basic block.
void setInstructionID(const Instruction *I)
const std::vector< const BasicBlock * > & getBasicBlocks() const
const std::vector< AttributeList > & getAttributeLists() const
bool shouldPreserveUseListOrder() const
const ComdatSetType & getComdats() const
std::vector< Type * > TypeList
ArrayRef< const Metadata * > getMDStrings() const
Get the MDString metadata for this block.
std::pair< unsigned, AttributeSet > IndexAndAttrSet
Attribute groups as encoded in bitcode are almost AttributeSets, but they include the AttributeList i...
const TypeList & getTypes() const
This class provides a symbol table of name/value pairs.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
void setName(const Twine &Name)
Change the name of the value.
LLVMContext & getContext() const
All values hold a context through their type.
void takeName(Value *V)
Transfer the name from V to this value.
std::pair< iterator, bool > insert(const ValueT &V)
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
void build(llvm::MapVector< CallStackId, llvm::SmallVector< FrameIdTy > > &&MemProfCallStackData, const llvm::DenseMap< FrameIdTy, LinearFrameId > *MemProfFrameIndexes, llvm::DenseMap< FrameIdTy, FrameStat > &FrameHistogram)
ArrayRef< LinearFrameId > getRadixArray() const
llvm::DenseMap< CallStackId, LinearCallStackId > takeCallStackPos()
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write(unsigned char C)
A raw_ostream that writes to an std::string.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
@ C
The default llvm calling convention, compatible with C.
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
@ CE
Windows NT (Windows on ARM)
@ TYPE_CODE_OPAQUE_POINTER
@ METADATA_TEMPLATE_VALUE
@ METADATA_LEXICAL_BLOCK_FILE
@ METADATA_SUBROUTINE_TYPE
@ METADATA_GLOBAL_DECL_ATTACHMENT
@ METADATA_IMPORTED_ENTITY
@ METADATA_GENERIC_SUBRANGE
@ METADATA_COMPOSITE_TYPE
@ METADATA_GLOBAL_VAR_EXPR
@ FS_CONTEXT_RADIX_TREE_ARRAY
@ FS_COMBINED_GLOBALVAR_INIT_REFS
@ FS_TYPE_CHECKED_LOAD_VCALLS
@ FS_COMBINED_ORIGINAL_NAME
@ FS_PERMODULE_VTABLE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_CONST_VCALL
@ FS_PERMODULE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_VCALLS
@ FS_COMBINED_CALLSITE_INFO
@ FS_PERMODULE_CALLSITE_INFO
@ FS_PERMODULE_ALLOC_INFO
@ FS_TYPE_CHECKED_LOAD_CONST_VCALL
@ IDENTIFICATION_CODE_EPOCH
@ IDENTIFICATION_CODE_STRING
@ CST_CODE_DSO_LOCAL_EQUIVALENT
@ CST_CODE_CE_GEP_WITH_INRANGE
@ COMDAT_SELECTION_KIND_LARGEST
@ COMDAT_SELECTION_KIND_ANY
@ COMDAT_SELECTION_KIND_SAME_SIZE
@ COMDAT_SELECTION_KIND_EXACT_MATCH
@ COMDAT_SELECTION_KIND_NO_DUPLICATES
@ ATTR_KIND_STACK_PROTECT
@ ATTR_KIND_STACK_PROTECT_STRONG
@ ATTR_KIND_SANITIZE_MEMORY
@ ATTR_KIND_OPTIMIZE_FOR_SIZE
@ ATTR_KIND_FNRETTHUNK_EXTERN
@ ATTR_KIND_NO_DIVERGENCE_SOURCE
@ ATTR_KIND_SANITIZE_ADDRESS
@ ATTR_KIND_NO_IMPLICIT_FLOAT
@ ATTR_KIND_DEAD_ON_UNWIND
@ ATTR_KIND_STACK_ALIGNMENT
@ ATTR_KIND_STACK_PROTECT_REQ
@ ATTR_KIND_NULL_POINTER_IS_VALID
@ ATTR_KIND_SANITIZE_HWADDRESS
@ ATTR_KIND_RETURNS_TWICE
@ ATTR_KIND_SHADOWCALLSTACK
@ ATTR_KIND_OPT_FOR_FUZZING
@ ATTR_KIND_SANITIZE_NUMERICAL_STABILITY
@ ATTR_KIND_ALLOCATED_POINTER
@ ATTR_KIND_DISABLE_SANITIZER_INSTRUMENTATION
@ ATTR_KIND_CORO_ELIDE_SAFE
@ ATTR_KIND_NON_LAZY_BIND
@ ATTR_KIND_DEREFERENCEABLE
@ ATTR_KIND_OPTIMIZE_NONE
@ ATTR_KIND_HYBRID_PATCHABLE
@ ATTR_KIND_DEREFERENCEABLE_OR_NULL
@ ATTR_KIND_SANITIZE_REALTIME
@ ATTR_KIND_SPECULATIVE_LOAD_HARDENING
@ ATTR_KIND_ALWAYS_INLINE
@ ATTR_KIND_SANITIZE_TYPE
@ ATTR_KIND_PRESPLIT_COROUTINE
@ ATTR_KIND_NO_SANITIZE_COVERAGE
@ ATTR_KIND_SANITIZE_REALTIME_BLOCKING
@ ATTR_KIND_NO_SANITIZE_BOUNDS
@ ATTR_KIND_SANITIZE_MEMTAG
@ ATTR_KIND_CORO_ONLY_DESTROY_WHEN_COMPLETE
@ ATTR_KIND_SANITIZE_THREAD
@ ATTR_KIND_OPTIMIZE_FOR_DEBUGGING
@ SYNC_SCOPE_NAMES_BLOCK_ID
@ PARAMATTR_GROUP_BLOCK_ID
@ IDENTIFICATION_BLOCK_ID
@ GLOBALVAL_SUMMARY_BLOCK_ID
@ FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID
@ OPERAND_BUNDLE_TAGS_BLOCK_ID
@ MODULE_CODE_SOURCE_FILENAME
@ MODULE_CODE_SECTIONNAME
@ FUNC_CODE_INST_CATCHRET
@ FUNC_CODE_INST_LANDINGPAD
@ FUNC_CODE_INST_EXTRACTVAL
@ FUNC_CODE_INST_CATCHPAD
@ FUNC_CODE_INST_CATCHSWITCH
@ FUNC_CODE_INST_CLEANUPRET
@ FUNC_CODE_DEBUG_RECORD_VALUE
@ FUNC_CODE_INST_LOADATOMIC
@ FUNC_CODE_DEBUG_RECORD_ASSIGN
@ FUNC_CODE_INST_STOREATOMIC
@ FUNC_CODE_INST_ATOMICRMW
@ FUNC_CODE_DEBUG_LOC_AGAIN
@ FUNC_CODE_INST_EXTRACTELT
@ FUNC_CODE_INST_INDIRECTBR
@ FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE
@ FUNC_CODE_INST_INSERTVAL
@ FUNC_CODE_DECLAREBLOCKS
@ FUNC_CODE_DEBUG_RECORD_LABEL
@ FUNC_CODE_INST_INSERTELT
@ FUNC_CODE_BLOCKADDR_USERS
@ FUNC_CODE_INST_CLEANUPPAD
@ FUNC_CODE_INST_SHUFFLEVEC
@ FUNC_CODE_INST_UNREACHABLE
@ FUNC_CODE_DEBUG_RECORD_DECLARE
@ FUNC_CODE_OPERAND_BUNDLE
@ FIRST_APPLICATION_ABBREV
@ PARAMATTR_GRP_CODE_ENTRY
initializer< Ty > init(const Ty &Val)
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.
template llvm::DenseMap< LinearFrameId, FrameStat > computeFrameHistogram< LinearFrameId >(llvm::MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &MemProfCallStackData)
NodeAddr< CodeNode * > Code
void write32le(void *P, uint32_t V)
uint32_t read32be(const void *P)
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
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.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
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...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
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 ...
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 (....
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue)
void sort(IteratorTy Start, IteratorTy End)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
AtomicOrdering
Atomic ordering for LLVM's memory model.
std::unordered_set< GlobalValueSummary * > GVSummaryPtrSet
A set of global value summary pointers.
DWARFExpression::Operation Op
std::map< std::string, GVSummaryMapTy, std::less<> > ModuleToSummariesForIndexTy
Map of a module name to the GUIDs and summaries we will import from that module.
OutputIt copy(R &&Range, OutputIt Out)
constexpr unsigned BitWidth
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
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,...
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
void consumeError(Error Err)
Consume a Error without doing anything.
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 ...
This struct is a compact representation of a valid (non-zero power of two) alignment.
Class to accumulate and hold information about a callee.
static constexpr unsigned RelBlockFreqBits
The value stored in RelBlockFreq has to be interpreted as the digits of a scaled number with a scale ...
Flags specific to function summaries.
static constexpr uint32_t RangeWidth
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
static const Target * lookupTarget(StringRef Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
Structure to hold a use-list order.
ValID - Represents a reference of a definition of some sort with no type.
Struct that holds a reference to a particular GUID in a global value summary.
uint64_t Info
Additional information for the resolution:
enum llvm::WholeProgramDevirtResolution::ByArg::Kind TheKind
enum llvm::WholeProgramDevirtResolution::Kind TheKind
std::map< std::vector< uint64_t >, ByArg > ResByArg
Resolutions for calls with all constant integer arguments (excluding the first argument,...
std::string SingleImplName