LLVM 19.0.0git
Functions | Variables
BitcodeReader.cpp File Reference
#include "llvm/Bitcode/BitcodeReader.h"
#include "MetadataLoader.h"
#include "ValueList.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Bitcode/BitcodeCommon.h"
#include "llvm/Bitcode/LLVMBitCodes.h"
#include "llvm/Bitstream/BitstreamReader.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/AttributeMask.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/AutoUpgrade.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/Comdat.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GVMaterializer.h"
#include "llvm/IR/GetElementPtrTypeIterator.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/InstIterator.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/IntrinsicsAArch64.h"
#include "llvm/IR/IntrinsicsARM.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/Value.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/AtomicOrdering.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/ModRef.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Triple.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <deque>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <system_error>
#include <tuple>
#include <utility>
#include <vector>

Go to the source code of this file.

Functions

static Error error (const Twine &Message)
 
static Error hasInvalidBitcodeHeader (BitstreamCursor &Stream)
 
static Expected< BitstreamCursorinitStream (MemoryBufferRef Buffer)
 
template<typename StrTy >
static bool convertToString (ArrayRef< uint64_t > Record, unsigned Idx, StrTy &Result)
 Convert a string from a record into an std::string, return true on failure.
 
static void stripTBAA (Module *M)
 
static Expected< std::string > readIdentificationBlock (BitstreamCursor &Stream)
 Read the "IDENTIFICATION_BLOCK_ID" block, do some basic enforcement on the "epoch" encoded in the bitcode, and return the producer name if any.
 
static Expected< std::string > readIdentificationCode (BitstreamCursor &Stream)
 
static Expected< boolhasObjCCategoryInModule (BitstreamCursor &Stream)
 
static Expected< boolhasObjCCategory (BitstreamCursor &Stream)
 
static Expected< std::string > readModuleTriple (BitstreamCursor &Stream)
 
static Expected< std::string > readTriple (BitstreamCursor &Stream)
 
static bool hasImplicitComdat (size_t Val)
 
static GlobalValue::LinkageTypes getDecodedLinkage (unsigned Val)
 
static FunctionSummary::FFlags getDecodedFFlags (uint64_t RawFlags)
 
static GlobalValueSummary::GVFlags getDecodedGVSummaryFlags (uint64_t RawFlags, uint64_t Version)
 
static GlobalVarSummary::GVarFlags getDecodedGVarFlags (uint64_t RawFlags)
 
static std::pair< CalleeInfo::HotnessType, boolgetDecodedHotnessCallEdgeInfo (uint64_t RawFlags)
 
static void getDecodedRelBFCallEdgeInfo (uint64_t RawFlags, uint64_t &RelBF, bool &HasTailCall)
 
static GlobalValue::VisibilityTypes getDecodedVisibility (unsigned Val)
 
static GlobalValue::DLLStorageClassTypes getDecodedDLLStorageClass (unsigned Val)
 
static bool getDecodedDSOLocal (unsigned Val)
 
static std::optional< CodeModel::ModelgetDecodedCodeModel (unsigned Val)
 
static GlobalVariable::ThreadLocalMode getDecodedThreadLocalMode (unsigned Val)
 
static GlobalVariable::UnnamedAddr getDecodedUnnamedAddrType (unsigned Val)
 
static int getDecodedCastOpcode (unsigned Val)
 
static int getDecodedUnaryOpcode (unsigned Val, Type *Ty)
 
static int getDecodedBinaryOpcode (unsigned Val, Type *Ty)
 
static AtomicRMWInst::BinOp getDecodedRMWOperation (unsigned Val)
 
static AtomicOrdering getDecodedOrdering (unsigned Val)
 
static Comdat::SelectionKind getDecodedComdatSelectionKind (unsigned Val)
 
static FastMathFlags getDecodedFastMathFlags (unsigned Val)
 
static void upgradeDLLImportExportLinkage (GlobalValue *GV, unsigned Val)
 
static bool isConstExprSupported (const BitcodeConstant *BC)
 
static uint64_t getRawAttributeMask (Attribute::AttrKind Val)
 
static void addRawAttributeValue (AttrBuilder &B, uint64_t Val)
 
static void decodeLLVMAttributesForBitcode (AttrBuilder &B, uint64_t EncodedAttrs, uint64_t AttrIdx)
 This fills an AttrBuilder object with the LLVM attributes that have been decoded from the given integer.
 
static Attribute::AttrKind getAttrFromCode (uint64_t Code)
 
static bool upgradeOldMemoryAttribute (MemoryEffects &ME, uint64_t EncodedKind)
 
static Expected< uint64_tjumpToValueSymbolTable (uint64_t Offset, BitstreamCursor &Stream)
 Helper to note and return the current location, and jump to the given offset.
 
static void inferDSOLocal (GlobalValue *GV)
 
GlobalValue::SanitizerMetadata deserializeSanitizerMetadata (unsigned V)
 
static void parseWholeProgramDevirtResolutionByArg (ArrayRef< uint64_t > Record, size_t &Slot, WholeProgramDevirtResolution &Wpd)
 
static void parseWholeProgramDevirtResolution (ArrayRef< uint64_t > Record, StringRef Strtab, size_t &Slot, TypeIdSummary &TypeId)
 
static void parseTypeIdSummaryRecord (ArrayRef< uint64_t > Record, StringRef Strtab, ModuleSummaryIndex &TheIndex)
 
static void setSpecialRefs (std::vector< ValueInfo > &Refs, unsigned ROCnt, unsigned WOCnt)
 
static Expected< StringRefreadBlobInRecord (BitstreamCursor &Stream, unsigned Block, unsigned RecordID)
 
static Expected< std::pair< bool, bool > > getEnableSplitLTOUnitAndUnifiedFlag (BitstreamCursor &Stream, unsigned ID, BitcodeLTOInfo &LTOInfo)
 
static Expected< BitcodeModulegetSingleModule (MemoryBufferRef Buffer)
 

Variables

static cl::opt< boolPrintSummaryGUIDs ("print-summary-global-ids", cl::init(false), cl::Hidden, cl::desc("Print the global id for each value when reading the module summary"))
 
static cl::opt< boolExpandConstantExprs ("expand-constant-exprs", cl::Hidden, cl::desc("Expand constant expressions to instructions for testing purposes"))
 
cl::opt< cl::boolOrDefaultLoadBitcodeIntoNewDbgInfoFormat ("load-bitcode-into-experimental-debuginfo-iterators", cl::Hidden, cl::desc("Load bitcode directly into the new debug info format (regardless " "of input format)"))
 Load bitcode directly into RemoveDIs format (use debug records instead of debug intrinsics).
 

Function Documentation

◆ addRawAttributeValue()

static void addRawAttributeValue ( AttrBuilder B,
uint64_t  Val 
)
static

◆ convertToString()

template<typename StrTy >
static bool convertToString ( ArrayRef< uint64_t Record,
unsigned  Idx,
StrTy &  Result 
)
static

Convert a string from a record into an std::string, return true on failure.

Definition at line 168 of file BitcodeReader.cpp.

References Idx.

Referenced by hasObjCCategoryInModule(), readIdentificationBlock(), and readModuleTriple().

◆ decodeLLVMAttributesForBitcode()

static void decodeLLVMAttributesForBitcode ( AttrBuilder B,
uint64_t  EncodedAttrs,
uint64_t  AttrIdx 
)
static

◆ deserializeSanitizerMetadata()

GlobalValue::SanitizerMetadata deserializeSanitizerMetadata ( unsigned  V)

Definition at line 3890 of file BitcodeReader.cpp.

◆ error()

static Error error ( const Twine Message)
static

Definition at line 120 of file BitcodeReader.cpp.

References llvm::make_error_code().

◆ getAttrFromCode()

static Attribute::AttrKind getAttrFromCode ( uint64_t  Code)
static

Definition at line 1960 of file BitcodeReader.cpp.

References llvm::bitc::ATTR_KIND_ALIGNMENT, llvm::bitc::ATTR_KIND_ALLOC_ALIGN, llvm::bitc::ATTR_KIND_ALLOC_KIND, llvm::bitc::ATTR_KIND_ALLOC_SIZE, llvm::bitc::ATTR_KIND_ALLOCATED_POINTER, llvm::bitc::ATTR_KIND_ALWAYS_INLINE, 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_CORO_ONLY_DESTROY_WHEN_COMPLETE, llvm::bitc::ATTR_KIND_DEAD_ON_UNWIND, llvm::bitc::ATTR_KIND_DEREFERENCEABLE, llvm::bitc::ATTR_KIND_DEREFERENCEABLE_OR_NULL, llvm::bitc::ATTR_KIND_DISABLE_SANITIZER_INSTRUMENTATION, llvm::bitc::ATTR_KIND_ELEMENTTYPE, llvm::bitc::ATTR_KIND_FNRETTHUNK_EXTERN, 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_INLINE_HINT, llvm::bitc::ATTR_KIND_JUMP_TABLE, llvm::bitc::ATTR_KIND_MEMORY, 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_BOUNDS, llvm::bitc::ATTR_KIND_NO_SANITIZE_COVERAGE, llvm::bitc::ATTR_KIND_NO_UNWIND, llvm::bitc::ATTR_KIND_NOCF_CHECK, llvm::bitc::ATTR_KIND_NOFPCLASS, 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_DEBUGGING, llvm::bitc::ATTR_KIND_OPTIMIZE_FOR_SIZE, llvm::bitc::ATTR_KIND_OPTIMIZE_NONE, llvm::bitc::ATTR_KIND_PREALLOCATED, llvm::bitc::ATTR_KIND_PRESPLIT_COROUTINE, llvm::bitc::ATTR_KIND_RANGE, 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_SKIP_PROFILE, 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_WRITABLE, llvm::bitc::ATTR_KIND_WRITEONLY, llvm::bitc::ATTR_KIND_Z_EXT, and llvm::Attribute::None.

◆ getDecodedBinaryOpcode()

static int getDecodedBinaryOpcode ( unsigned  Val,
Type Ty 
)
static

◆ getDecodedCastOpcode()

static int getDecodedCastOpcode ( unsigned  Val)
static

◆ getDecodedCodeModel()

static std::optional< CodeModel::Model > getDecodedCodeModel ( unsigned  Val)
static

◆ getDecodedComdatSelectionKind()

static Comdat::SelectionKind getDecodedComdatSelectionKind ( unsigned  Val)
static

◆ getDecodedDLLStorageClass()

static GlobalValue::DLLStorageClassTypes getDecodedDLLStorageClass ( unsigned  Val)
static

◆ getDecodedDSOLocal()

static bool getDecodedDSOLocal ( unsigned  Val)
static

Definition at line 1192 of file BitcodeReader.cpp.

◆ getDecodedFastMathFlags()

static FastMathFlags getDecodedFastMathFlags ( unsigned  Val)
static

◆ getDecodedFFlags()

static FunctionSummary::FFlags getDecodedFFlags ( uint64_t  RawFlags)
static

Definition at line 1110 of file BitcodeReader.cpp.

◆ getDecodedGVarFlags()

static GlobalVarSummary::GVarFlags getDecodedGVarFlags ( uint64_t  RawFlags)
static

Definition at line 1150 of file BitcodeReader.cpp.

◆ getDecodedGVSummaryFlags()

static GlobalValueSummary::GVFlags getDecodedGVSummaryFlags ( uint64_t  RawFlags,
uint64_t  Version 
)
static

Definition at line 1129 of file BitcodeReader.cpp.

References Live.

◆ getDecodedHotnessCallEdgeInfo()

static std::pair< CalleeInfo::HotnessType, bool > getDecodedHotnessCallEdgeInfo ( uint64_t  RawFlags)
static

Definition at line 1158 of file BitcodeReader.cpp.

◆ getDecodedLinkage()

static GlobalValue::LinkageTypes getDecodedLinkage ( unsigned  Val)
static

◆ getDecodedOrdering()

static AtomicOrdering getDecodedOrdering ( unsigned  Val)
static

◆ getDecodedRelBFCallEdgeInfo()

static void getDecodedRelBFCallEdgeInfo ( uint64_t  RawFlags,
uint64_t RelBF,
bool HasTailCall 
)
static

Definition at line 1165 of file BitcodeReader.cpp.

References llvm::CalleeInfo::RelBlockFreqBits.

◆ getDecodedRMWOperation()

static AtomicRMWInst::BinOp getDecodedRMWOperation ( unsigned  Val)
static

◆ getDecodedThreadLocalMode()

static GlobalVariable::ThreadLocalMode getDecodedThreadLocalMode ( unsigned  Val)
static

Definition at line 1217 of file BitcodeReader.cpp.

◆ getDecodedUnaryOpcode()

static int getDecodedUnaryOpcode ( unsigned  Val,
Type Ty 
)
static

◆ getDecodedUnnamedAddrType()

static GlobalVariable::UnnamedAddr getDecodedUnnamedAddrType ( unsigned  Val)
static

Definition at line 1228 of file BitcodeReader.cpp.

◆ getDecodedVisibility()

static GlobalValue::VisibilityTypes getDecodedVisibility ( unsigned  Val)
static

◆ getEnableSplitLTOUnitAndUnifiedFlag()

static Expected< std::pair< bool, bool > > getEnableSplitLTOUnitAndUnifiedFlag ( BitstreamCursor Stream,
unsigned  ID,
BitcodeLTOInfo LTOInfo 
)
static

◆ getRawAttributeMask()

static uint64_t getRawAttributeMask ( Attribute::AttrKind  Val)
static

◆ getSingleModule()

static Expected< BitcodeModule > getSingleModule ( MemoryBufferRef  Buffer)
static

◆ hasImplicitComdat()

static bool hasImplicitComdat ( size_t  Val)
static

Definition at line 1056 of file BitcodeReader.cpp.

◆ hasInvalidBitcodeHeader()

static Error hasInvalidBitcodeHeader ( BitstreamCursor Stream)
static

◆ hasObjCCategory()

static Expected< bool > hasObjCCategory ( BitstreamCursor Stream)
static

◆ hasObjCCategoryInModule()

static Expected< bool > hasObjCCategoryInModule ( BitstreamCursor Stream)
static

◆ inferDSOLocal()

static void inferDSOLocal ( GlobalValue GV)
static

◆ initStream()

static Expected< BitstreamCursor > initStream ( MemoryBufferRef  Buffer)
static

◆ isConstExprSupported()

static bool isConstExprSupported ( const BitcodeConstant *  BC)
static

◆ jumpToValueSymbolTable()

static Expected< uint64_t > jumpToValueSymbolTable ( uint64_t  Offset,
BitstreamCursor Stream 
)
static

◆ parseTypeIdSummaryRecord()

static void parseTypeIdSummaryRecord ( ArrayRef< uint64_t Record,
StringRef  Strtab,
ModuleSummaryIndex TheIndex 
)
static

◆ parseWholeProgramDevirtResolution()

static void parseWholeProgramDevirtResolution ( ArrayRef< uint64_t Record,
StringRef  Strtab,
size_t &  Slot,
TypeIdSummary TypeId 
)
static

◆ parseWholeProgramDevirtResolutionByArg()

static void parseWholeProgramDevirtResolutionByArg ( ArrayRef< uint64_t Record,
size_t &  Slot,
WholeProgramDevirtResolution Wpd 
)
static

◆ readBlobInRecord()

static Expected< StringRef > readBlobInRecord ( BitstreamCursor Stream,
unsigned  Block,
unsigned  RecordID 
)
static

◆ readIdentificationBlock()

static Expected< std::string > readIdentificationBlock ( BitstreamCursor Stream)
static

◆ readIdentificationCode()

static Expected< std::string > readIdentificationCode ( BitstreamCursor Stream)
static

◆ readModuleTriple()

static Expected< std::string > readModuleTriple ( BitstreamCursor Stream)
static

◆ readTriple()

static Expected< std::string > readTriple ( BitstreamCursor Stream)
static

◆ setSpecialRefs()

static void setSpecialRefs ( std::vector< ValueInfo > &  Refs,
unsigned  ROCnt,
unsigned  WOCnt 
)
static

Definition at line 7362 of file BitcodeReader.cpp.

References assert().

◆ stripTBAA()

static void stripTBAA ( Module M)
static

Definition at line 178 of file BitcodeReader.cpp.

References F, I, and instructions.

◆ upgradeDLLImportExportLinkage()

static void upgradeDLLImportExportLinkage ( GlobalValue GV,
unsigned  Val 
)
static

◆ upgradeOldMemoryAttribute()

static bool upgradeOldMemoryAttribute ( MemoryEffects ME,
uint64_t  EncodedKind 
)
static

Variable Documentation

◆ ExpandConstantExprs

cl::opt< bool > ExpandConstantExprs("expand-constant-exprs", cl::Hidden, cl::desc( "Expand constant expressions to instructions for testing purposes")) ( "expand-constant-exprs"  ,
cl::Hidden  ,
cl::desc( "Expand constant expressions to instructions for testing purposes")   
)
static

Referenced by isConstExprSupported().

◆ LoadBitcodeIntoNewDbgInfoFormat

cl::opt< cl::boolOrDefault > LoadBitcodeIntoNewDbgInfoFormat("load-bitcode-into-experimental-debuginfo-iterators", cl::Hidden, cl::desc("Load bitcode directly into the new debug info format (regardless " "of input format)")) ( "load-bitcode-into-experimental-debuginfo-iterators"  ,
cl::Hidden  ,
cl::desc("Load bitcode directly into the new debug info format (regardless " "of input format)")   
)

Load bitcode directly into RemoveDIs format (use debug records instead of debug intrinsics).

UNSET is treated as FALSE, so the default action is to do nothing. Individual tools can override this to incrementally add support for the RemoveDIs format.

◆ PrintSummaryGUIDs

cl::opt< bool > PrintSummaryGUIDs("print-summary-global-ids", cl::init(false), cl::Hidden, cl::desc( "Print the global id for each value when reading the module summary")) ( "print-summary-global-ids"  ,
cl::init(false)  ,
cl::Hidden  ,
cl::desc( "Print the global id for each value when reading the module summary")   
)
static