LLVM  14.0.0git
Macros | Enumerations | Functions | Variables
BitcodeWriter.cpp File Reference
#include "llvm/Bitcode/BitcodeWriter.h"
#include "ValueEnumerator.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Bitcode/BitcodeCommon.h"
#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/Bitcode/LLVMBitCodes.h"
#include "llvm/Bitstream/BitCodes.h"
#include "llvm/Bitstream/BitstreamWriter.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Comdat.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/GlobalIFunc.h"
#include "llvm/IR/GlobalObject.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/InlineAsm.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ModuleSummaryIndex.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/UseListOrder.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/ValueSymbolTable.h"
#include "llvm/MC/StringTableBuilder.h"
#include "llvm/Object/IRSymtab.h"
#include "llvm/Support/AtomicOrdering.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/SHA1.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <iterator>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "llvm/IR/Metadata.def"

Go to the source code of this file.

Macros

#define HANDLE_MDNODE_LEAF(CLASS)   CLASS##AbbrevID,
 
#define HANDLE_MDNODE_LEAF(CLASS)   unsigned CLASS##Abbrev = 0;
 
#define HANDLE_MDNODE_LEAF(CLASS)
 

Enumerations

enum  StringEncoding { SE_Char6, SE_Fixed7, SE_Fixed8 }
 
enum  MetadataAbbrev : unsigned { LastPlusOne }
 

Functions

static unsigned getEncodedCastOpcode (unsigned Opcode)
 
static unsigned getEncodedUnaryOpcode (unsigned Opcode)
 
static unsigned getEncodedBinaryOpcode (unsigned Opcode)
 
static unsigned getEncodedRMWOperation (AtomicRMWInst::BinOp Op)
 
static unsigned getEncodedOrdering (AtomicOrdering Ordering)
 
static void writeStringRecord (BitstreamWriter &Stream, unsigned Code, StringRef Str, unsigned AbbrevToUse)
 
static uint64_t getAttrKindEncoding (Attribute::AttrKind Kind)
 
static unsigned getEncodedLinkage (const GlobalValue::LinkageTypes Linkage)
 
static unsigned getEncodedLinkage (const GlobalValue &GV)
 
static uint64_t getEncodedFFlags (FunctionSummary::FFlags Flags)
 
static uint64_t getEncodedGVSummaryFlags (GlobalValueSummary::GVFlags Flags)
 
static uint64_t getEncodedGVarFlags (GlobalVarSummary::GVarFlags Flags)
 
static unsigned getEncodedVisibility (const GlobalValue &GV)
 
static unsigned getEncodedDLLStorageClass (const GlobalValue &GV)
 
static unsigned getEncodedThreadLocalMode (const GlobalValue &GV)
 
static unsigned getEncodedComdatSelectionKind (const Comdat &C)
 
static unsigned getEncodedUnnamedAddr (const GlobalValue &GV)
 
static StringEncoding getStringEncoding (StringRef Str)
 Determine the encoding to use for the given string name and length. More...
 
static uint64_t getOptimizationFlags (const Value *V)
 
static void emitSignedInt64 (SmallVectorImpl< uint64_t > &Vals, uint64_t V)
 
static void emitWideAPInt (SmallVectorImpl< uint64_t > &Vals, const APInt &A)
 
template<typename Fn >
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 (whether per-module or combined). More...
 
static void getReferencedTypeIds (FunctionSummary *FS, std::set< GlobalValue::GUID > &ReferencedTypeIds)
 Collect type IDs from type tests used by function. More...
 
static void writeWholeProgramDevirtResolutionByArg (SmallVector< uint64_t, 64 > &NameVals, const std::vector< uint64_t > &args, const WholeProgramDevirtResolution::ByArg &ByArg)
 
static void writeWholeProgramDevirtResolution (SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, uint64_t Id, const WholeProgramDevirtResolution &Wpd)
 
static void writeTypeIdSummaryRecord (SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, const std::string &Id, const TypeIdSummary &Summary)
 
static void writeTypeIdCompatibleVtableSummaryRecord (SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, const std::string &Id, const TypeIdCompatibleVtableInfo &Summary, ValueEnumerator &VE)
 
static void writeIdentificationBlock (BitstreamWriter &Stream)
 Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the current llvm version, and a record for the epoch number. More...
 
static void writeInt32ToBuffer (uint32_t Value, SmallVectorImpl< char > &Buffer, uint32_t &Position)
 
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 the system archiver. More...
 
static void writeBitcodeHeader (BitstreamWriter &Stream)
 Helper to write the header common to all bitcode files. More...
 
static const char * getSectionNameForBitcode (const Triple &T)
 
static const char * getSectionNameForCommandline (const Triple &T)
 

Variables

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 cl::opt< uint32_tFlushThreshold ("bitcode-flush-threshold", cl::Hidden, cl::init(512), cl::desc("The threshold (unit M) for flushing LLVM bitcode."))
 
static cl::opt< bool > WriteRelBFToSummary ("write-relbf-to-summary", cl::Hidden, cl::init(false), cl::desc("Write relative block frequency to function summary "))
 
FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold
 

Macro Definition Documentation

◆ HANDLE_MDNODE_LEAF [1/3]

#define HANDLE_MDNODE_LEAF (   CLASS)    CLASS##AbbrevID,

Definition at line 2138 of file BitcodeWriter.cpp.

◆ HANDLE_MDNODE_LEAF [2/3]

#define HANDLE_MDNODE_LEAF (   CLASS)    unsigned CLASS##Abbrev = 0;

Definition at line 2138 of file BitcodeWriter.cpp.

◆ HANDLE_MDNODE_LEAF [3/3]

#define HANDLE_MDNODE_LEAF (   CLASS)
Value:
case Metadata::CLASS##Kind: \
if (MDAbbrevs) \
write##CLASS(cast<CLASS>(N), Record, \
(*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
else \
write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
continue;

Definition at line 2138 of file BitcodeWriter.cpp.

Enumeration Type Documentation

◆ MetadataAbbrev

enum MetadataAbbrev : unsigned
Enumerator
LastPlusOne 

Definition at line 2137 of file BitcodeWriter.cpp.

◆ StringEncoding

Enumerator
SE_Char6 
SE_Fixed7 
SE_Fixed8 

Definition at line 1196 of file BitcodeWriter.cpp.

Function Documentation

◆ emitDarwinBCHeaderAndTrailer()

static void emitDarwinBCHeaderAndTrailer ( SmallVectorImpl< char > &  Buffer,
const Triple TT 
)
static

If generating a bc file on darwin, we have to emit a header and trailer to make it compatible with the system archiver.

To do this we emit the following header, and then emit a trailer that pads the file out to be a multiple of 16 bytes.

struct bc_header { uint32_t Magic; // 0x0B17C0DE uint32_t Version; // Version, currently always 0. uint32_t BitcodeOffset; // Offset to traditional bitcode file. uint32_t BitcodeSize; // Size of traditional bitcode file. uint32_t CPUType; // CPU specifier. ... potentially more later ... };

Definition at line 4476 of file BitcodeWriter.cpp.

References llvm::Triple::arm, assert(), llvm::BWH_HeaderSize, llvm::Triple::ppc, llvm::Triple::ppc64, llvm::Triple::thumb, writeInt32ToBuffer(), llvm::Triple::x86, and llvm::Triple::x86_64.

Referenced by llvm::WriteBitcodeToFile().

◆ emitSignedInt64()

static void emitSignedInt64 ( SmallVectorImpl< uint64_t > &  Vals,
uint64_t  V 
)
static

Definition at line 1605 of file BitcodeWriter.cpp.

Referenced by emitWideAPInt(), and writeFunctionTypeMetadataRecords().

◆ emitWideAPInt()

static void emitWideAPInt ( SmallVectorImpl< uint64_t > &  Vals,
const APInt A 
)
static

Definition at line 1612 of file BitcodeWriter.cpp.

References emitSignedInt64(), and i.

◆ getAttrKindEncoding()

static uint64_t getAttrKindEncoding ( Attribute::AttrKind  Kind)
static

Definition at line 611 of file BitcodeWriter.cpp.

References llvm::bitc::ATTR_KIND_ALIGNMENT, llvm::bitc::ATTR_KIND_ALLOC_SIZE, llvm::bitc::ATTR_KIND_ALWAYS_INLINE, llvm::bitc::ATTR_KIND_ARGMEMONLY, llvm::bitc::ATTR_KIND_BUILTIN, llvm::bitc::ATTR_KIND_BY_VAL, llvm::bitc::ATTR_KIND_BYREF, llvm::bitc::ATTR_KIND_COLD, llvm::bitc::ATTR_KIND_CONVERGENT, llvm::bitc::ATTR_KIND_DEREFERENCEABLE, llvm::bitc::ATTR_KIND_DEREFERENCEABLE_OR_NULL, llvm::bitc::ATTR_KIND_ELEMENTTYPE, llvm::bitc::ATTR_KIND_HOT, llvm::bitc::ATTR_KIND_IMMARG, llvm::bitc::ATTR_KIND_IN_ALLOCA, llvm::bitc::ATTR_KIND_IN_REG, llvm::bitc::ATTR_KIND_INACCESSIBLEMEM_ONLY, llvm::bitc::ATTR_KIND_INACCESSIBLEMEM_OR_ARGMEMONLY, llvm::bitc::ATTR_KIND_INLINE_HINT, llvm::bitc::ATTR_KIND_JUMP_TABLE, llvm::bitc::ATTR_KIND_MIN_SIZE, llvm::bitc::ATTR_KIND_MUSTPROGRESS, llvm::bitc::ATTR_KIND_NAKED, llvm::bitc::ATTR_KIND_NEST, llvm::bitc::ATTR_KIND_NO_ALIAS, llvm::bitc::ATTR_KIND_NO_BUILTIN, llvm::bitc::ATTR_KIND_NO_CALLBACK, llvm::bitc::ATTR_KIND_NO_CAPTURE, llvm::bitc::ATTR_KIND_NO_DUPLICATE, llvm::bitc::ATTR_KIND_NO_IMPLICIT_FLOAT, llvm::bitc::ATTR_KIND_NO_INLINE, llvm::bitc::ATTR_KIND_NO_MERGE, llvm::bitc::ATTR_KIND_NO_PROFILE, llvm::bitc::ATTR_KIND_NO_RECURSE, llvm::bitc::ATTR_KIND_NO_RED_ZONE, llvm::bitc::ATTR_KIND_NO_RETURN, llvm::bitc::ATTR_KIND_NO_SANITIZE_COVERAGE, llvm::bitc::ATTR_KIND_NO_UNWIND, llvm::bitc::ATTR_KIND_NOCF_CHECK, llvm::bitc::ATTR_KIND_NOFREE, llvm::bitc::ATTR_KIND_NON_LAZY_BIND, llvm::bitc::ATTR_KIND_NON_NULL, llvm::bitc::ATTR_KIND_NOSYNC, llvm::bitc::ATTR_KIND_NOUNDEF, llvm::bitc::ATTR_KIND_NULL_POINTER_IS_VALID, llvm::bitc::ATTR_KIND_OPT_FOR_FUZZING, llvm::bitc::ATTR_KIND_OPTIMIZE_FOR_SIZE, llvm::bitc::ATTR_KIND_OPTIMIZE_NONE, llvm::bitc::ATTR_KIND_PREALLOCATED, llvm::bitc::ATTR_KIND_READ_NONE, llvm::bitc::ATTR_KIND_READ_ONLY, llvm::bitc::ATTR_KIND_RETURNED, llvm::bitc::ATTR_KIND_RETURNS_TWICE, llvm::bitc::ATTR_KIND_S_EXT, llvm::bitc::ATTR_KIND_SAFESTACK, llvm::bitc::ATTR_KIND_SANITIZE_ADDRESS, llvm::bitc::ATTR_KIND_SANITIZE_HWADDRESS, llvm::bitc::ATTR_KIND_SANITIZE_MEMORY, llvm::bitc::ATTR_KIND_SANITIZE_MEMTAG, llvm::bitc::ATTR_KIND_SANITIZE_THREAD, llvm::bitc::ATTR_KIND_SHADOWCALLSTACK, llvm::bitc::ATTR_KIND_SPECULATABLE, llvm::bitc::ATTR_KIND_SPECULATIVE_LOAD_HARDENING, llvm::bitc::ATTR_KIND_STACK_ALIGNMENT, llvm::bitc::ATTR_KIND_STACK_PROTECT, llvm::bitc::ATTR_KIND_STACK_PROTECT_REQ, llvm::bitc::ATTR_KIND_STACK_PROTECT_STRONG, llvm::bitc::ATTR_KIND_STRICT_FP, llvm::bitc::ATTR_KIND_STRUCT_RET, llvm::bitc::ATTR_KIND_SWIFT_ASYNC, llvm::bitc::ATTR_KIND_SWIFT_ERROR, llvm::bitc::ATTR_KIND_SWIFT_SELF, llvm::bitc::ATTR_KIND_UW_TABLE, llvm::bitc::ATTR_KIND_VSCALE_RANGE, llvm::bitc::ATTR_KIND_WILLRETURN, llvm::bitc::ATTR_KIND_WRITEONLY, llvm::bitc::ATTR_KIND_Z_EXT, llvm::CallingConv::Cold, llvm::MCID::Convergent, llvm::Attribute::EmptyKey, llvm::Attribute::EndAttrKinds, JumpTable, llvm_unreachable, llvm::Attribute::None, llvm::orc::ReadOnly, and llvm::Attribute::TombstoneKey.

◆ getEncodedBinaryOpcode()

static unsigned getEncodedBinaryOpcode ( unsigned  Opcode)
static

◆ getEncodedCastOpcode()

static unsigned getEncodedCastOpcode ( unsigned  Opcode)
static

◆ getEncodedComdatSelectionKind()

static unsigned getEncodedComdatSelectionKind ( const Comdat C)
static

◆ getEncodedDLLStorageClass()

static unsigned getEncodedDLLStorageClass ( const GlobalValue GV)
static

◆ getEncodedFFlags()

static uint64_t getEncodedFFlags ( FunctionSummary::FFlags  Flags)
static

◆ getEncodedGVarFlags()

static uint64_t getEncodedGVarFlags ( GlobalVarSummary::GVarFlags  Flags)
static

◆ getEncodedGVSummaryFlags()

static uint64_t getEncodedGVSummaryFlags ( GlobalValueSummary::GVFlags  Flags)
static

◆ getEncodedLinkage() [1/2]

static unsigned getEncodedLinkage ( const GlobalValue GV)
static

Definition at line 1057 of file BitcodeWriter.cpp.

References getEncodedLinkage(), and llvm::GlobalValue::getLinkage().

◆ getEncodedLinkage() [2/2]

static unsigned getEncodedLinkage ( const GlobalValue::LinkageTypes  Linkage)
static

◆ getEncodedOrdering()

static unsigned getEncodedOrdering ( AtomicOrdering  Ordering)
static

◆ getEncodedRMWOperation()

static unsigned getEncodedRMWOperation ( AtomicRMWInst::BinOp  Op)
static

◆ getEncodedThreadLocalMode()

static unsigned getEncodedThreadLocalMode ( const GlobalValue GV)
static

◆ getEncodedUnaryOpcode()

static unsigned getEncodedUnaryOpcode ( unsigned  Opcode)
static

Definition at line 533 of file BitcodeWriter.cpp.

References llvm_unreachable, and llvm::bitc::UNOP_FNEG.

◆ getEncodedUnnamedAddr()

static unsigned getEncodedUnnamedAddr ( const GlobalValue GV)
static

◆ getEncodedVisibility()

static unsigned getEncodedVisibility ( const GlobalValue GV)
static

◆ getOptimizationFlags()

static uint64_t getOptimizationFlags ( const Value V)
static

◆ getReferencedTypeIds()

static void getReferencedTypeIds ( FunctionSummary FS,
std::set< GlobalValue::GUID > &  ReferencedTypeIds 
)
static

Collect type IDs from type tests used by function.

Definition at line 3724 of file BitcodeWriter.cpp.

References llvm::X86AS::FS, and llvm::AArch64CC::VC.

◆ getSectionNameForBitcode()

static const char* getSectionNameForBitcode ( const Triple T)
static

◆ getSectionNameForCommandline()

static const char* getSectionNameForCommandline ( const Triple T)
static

◆ getStringEncoding()

static StringEncoding getStringEncoding ( StringRef  Str)
static

Determine the encoding to use for the given string name and length.

Definition at line 1199 of file BitcodeWriter.cpp.

References llvm::BitCodeAbbrevOp::isChar6(), SE_Char6, SE_Fixed7, and SE_Fixed8.

◆ writeBitcodeHeader()

static void writeBitcodeHeader ( BitstreamWriter Stream)
static

Helper to write the header common to all bitcode files.

Definition at line 4523 of file BitcodeWriter.cpp.

References llvm::BitstreamWriter::Emit().

Referenced by llvm::BitcodeWriter::BitcodeWriter().

◆ writeFunctionTypeMetadataRecords()

template<typename Fn >
static void writeFunctionTypeMetadataRecords ( BitstreamWriter Stream,
FunctionSummary FS,
Fn  GetValueID 
)
static

◆ writeIdentificationBlock()

static void writeIdentificationBlock ( BitstreamWriter Stream)
static

◆ writeInt32ToBuffer()

static void writeInt32ToBuffer ( uint32_t  Value,
SmallVectorImpl< char > &  Buffer,
uint32_t Position 
)
static

Definition at line 4457 of file BitcodeWriter.cpp.

References llvm::support::endian::write32le().

Referenced by emitDarwinBCHeaderAndTrailer().

◆ writeStringRecord()

static void writeStringRecord ( BitstreamWriter Stream,
unsigned  Code,
StringRef  Str,
unsigned  AbbrevToUse 
)
static

◆ writeTypeIdCompatibleVtableSummaryRecord()

static void writeTypeIdCompatibleVtableSummaryRecord ( SmallVector< uint64_t, 64 > &  NameVals,
StringTableBuilder StrtabBuilder,
const std::string &  Id,
const TypeIdCompatibleVtableInfo Summary,
ValueEnumerator VE 
)
static

◆ writeTypeIdSummaryRecord()

static void writeTypeIdSummaryRecord ( SmallVector< uint64_t, 64 > &  NameVals,
StringTableBuilder StrtabBuilder,
const std::string &  Id,
const TypeIdSummary Summary 
)
static

◆ writeWholeProgramDevirtResolution()

static void writeWholeProgramDevirtResolution ( SmallVector< uint64_t, 64 > &  NameVals,
StringTableBuilder StrtabBuilder,
uint64_t  Id,
const WholeProgramDevirtResolution Wpd 
)
static

◆ writeWholeProgramDevirtResolutionByArg()

static void writeWholeProgramDevirtResolutionByArg ( SmallVector< uint64_t, 64 > &  NameVals,
const std::vector< uint64_t > &  args,
const WholeProgramDevirtResolution::ByArg ByArg 
)
static

Variable Documentation

◆ FlushThreshold

cl::opt<uint32_t> FlushThreshold("bitcode-flush-threshold", cl::Hidden, cl::init(512), cl::desc("The threshold (unit M) for flushing LLVM bitcode."))
static

◆ ForceSummaryEdgesCold

Definition at line 65 of file ModuleSummaryAnalysis.cpp.

Referenced by computeFunctionSummary().

◆ IndexThreshold

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

◆ WriteRelBFToSummary

cl::opt<bool> WriteRelBFToSummary("write-relbf-to-summary", cl::Hidden, cl::init(false), cl::desc("Write relative block frequency to function summary "))
static
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::Record
Definition: Record.h:1472
N
#define N