#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/ConstantRangeList.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/ProfDataUtils.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>
usingnamespacellvm;
static 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"));
static cl::opt<bool> ExpandConstantExprs(
"expand-constant-exprs", cl::Hidden,
cl::desc(
"Expand constant expressions to instructions for testing purposes"));
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)"));
extern cl::opt<bool> UseNewDbgInfoFormat;
extern cl::opt<cl::boolOrDefault> PreserveInputDbgFormat;
extern bool WriteNewDbgInfoFormatToBitcode;
extern cl::opt<bool> WriteNewDbgInfoFormat;
namespace {
enum { … };
}
static Error error(const Twine &Message) { … }
static Error hasInvalidBitcodeHeader(BitstreamCursor &Stream) { … }
static Expected<BitstreamCursor> initStream(MemoryBufferRef Buffer) { … }
template <typename StrTy>
static bool convertToString(ArrayRef<uint64_t> Record, unsigned Idx,
StrTy &Result) { … }
static void stripTBAA(Module *M) { … }
static Expected<std::string> readIdentificationBlock(BitstreamCursor &Stream) { … }
static Expected<std::string> readIdentificationCode(BitstreamCursor &Stream) { … }
static Expected<bool> hasObjCCategoryInModule(BitstreamCursor &Stream) { … }
static Expected<bool> hasObjCCategory(BitstreamCursor &Stream) { … }
static Expected<std::string> readModuleTriple(BitstreamCursor &Stream) { … }
static Expected<std::string> readTriple(BitstreamCursor &Stream) { … }
namespace {
class BitcodeReaderBase { … };
}
Error BitcodeReaderBase::error(const Twine &Message) { … }
Expected<unsigned>
BitcodeReaderBase::parseVersionRecord(ArrayRef<uint64_t> Record) { … }
std::pair<StringRef, ArrayRef<uint64_t>>
BitcodeReaderBase::readNameFromStrtab(ArrayRef<uint64_t> Record) { … }
namespace {
class BitcodeConstant final : public Value,
TrailingObjects<BitcodeConstant, unsigned> { … };
class BitcodeReader : public BitcodeReaderBase, public GVMaterializer { … };
class ModuleSummaryIndexBitcodeReader : public BitcodeReaderBase { … };
}
std::error_code llvm::errorToErrorCodeAndEmitErrors(LLVMContext &Ctx,
Error Err) { … }
BitcodeReader::BitcodeReader(BitstreamCursor Stream, StringRef Strtab,
StringRef ProducerIdentification,
LLVMContext &Context)
: … { … }
Error BitcodeReader::materializeForwardReferencedFunctions() { … }
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, bool>
getDecodedHotnessCallEdgeInfo(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::Model> getDecodedCodeModel(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) { … }
Type *BitcodeReader::getTypeByID(unsigned ID) { … }
unsigned BitcodeReader::getContainedTypeID(unsigned ID, unsigned Idx) { … }
Type *BitcodeReader::getPtrElementTypeByID(unsigned ID) { … }
unsigned BitcodeReader::getVirtualTypeID(Type *Ty,
ArrayRef<unsigned> ChildTypeIDs) { … }
static GEPNoWrapFlags toGEPNoWrapFlags(uint64_t Flags) { … }
static bool isConstExprSupported(const BitcodeConstant *BC) { … }
Expected<Value *> BitcodeReader::materializeValue(unsigned StartValID,
BasicBlock *InsertBB) { … }
Expected<Constant *> BitcodeReader::getValueForInitializer(unsigned ID) { … }
StructType *BitcodeReader::createIdentifiedStructType(LLVMContext &Context,
StringRef Name) { … }
StructType *BitcodeReader::createIdentifiedStructType(LLVMContext &Context) { … }
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) { … }
Error BitcodeReader::parseAttributeBlock() { … }
static Attribute::AttrKind getAttrFromCode(uint64_t Code) { … }
Error BitcodeReader::parseAlignmentValue(uint64_t Exponent,
MaybeAlign &Alignment) { … }
Error BitcodeReader::parseAttrKind(uint64_t Code, Attribute::AttrKind *Kind) { … }
static bool upgradeOldMemoryAttribute(MemoryEffects &ME, uint64_t EncodedKind) { … }
Error BitcodeReader::parseAttributeGroupBlock() { … }
Error BitcodeReader::parseTypeTable() { … }
Error BitcodeReader::parseTypeTableBody() { … }
Error BitcodeReader::parseOperandBundleTags() { … }
Error BitcodeReader::parseSyncScopeNames() { … }
Expected<Value *> BitcodeReader::recordValue(SmallVectorImpl<uint64_t> &Record,
unsigned NameIndex, Triple &TT) { … }
static Expected<uint64_t> jumpToValueSymbolTable(uint64_t Offset,
BitstreamCursor &Stream) { … }
void BitcodeReader::setDeferredFunctionInfo(unsigned FuncBitcodeOffsetDelta,
Function *F,
ArrayRef<uint64_t> Record) { … }
Error BitcodeReader::parseGlobalValueSymbolTable() { … }
Error BitcodeReader::parseValueSymbolTable(uint64_t Offset) { … }
uint64_t BitcodeReader::decodeSignRotatedValue(uint64_t V) { … }
Error BitcodeReader::resolveGlobalAndIndirectSymbolInits() { … }
APInt llvm::readWideAPInt(ArrayRef<uint64_t> Vals, unsigned TypeBits) { … }
Error BitcodeReader::parseConstants() { … }
Error BitcodeReader::parseUseLists() { … }
Error BitcodeReader::rememberAndSkipMetadata() { … }
Error BitcodeReader::materializeMetadata() { … }
void BitcodeReader::setStripDebugInfo() { … }
Error BitcodeReader::rememberAndSkipFunctionBody() { … }
Error BitcodeReader::globalCleanup() { … }
Error BitcodeReader::rememberAndSkipFunctionBodies() { … }
Error BitcodeReaderBase::readBlockInfo() { … }
Error BitcodeReader::parseComdatRecord(ArrayRef<uint64_t> Record) { … }
static void inferDSOLocal(GlobalValue *GV) { … }
GlobalValue::SanitizerMetadata deserializeSanitizerMetadata(unsigned V) { … }
Error BitcodeReader::parseGlobalVarRecord(ArrayRef<uint64_t> Record) { … }
void BitcodeReader::callValueTypeCallback(Value *F, unsigned TypeID) { … }
Error BitcodeReader::parseFunctionRecord(ArrayRef<uint64_t> Record) { … }
Error BitcodeReader::parseGlobalIndirectSymbolRecord(
unsigned BitCode, ArrayRef<uint64_t> Record) { … }
Error BitcodeReader::parseModule(uint64_t ResumeBit,
bool ShouldLazyLoadMetadata,
ParserCallbacks Callbacks) { … }
Error BitcodeReader::parseBitcodeInto(Module *M, bool ShouldLazyLoadMetadata,
bool IsImporting,
ParserCallbacks Callbacks) { … }
Error BitcodeReader::typeCheckLoadStoreInst(Type *ValType, Type *PtrType) { … }
Error BitcodeReader::propagateAttributeTypes(CallBase *CB,
ArrayRef<unsigned> ArgTyIDs) { … }
Error BitcodeReader::parseFunctionBody(Function *F) { … }
Error BitcodeReader::findFunctionInStream(
Function *F,
DenseMap<Function *, uint64_t>::iterator DeferredFunctionInfoIterator) { … }
SyncScope::ID BitcodeReader::getDecodedSyncScopeID(unsigned Val) { … }
Error BitcodeReader::materialize(GlobalValue *GV) { … }
Error BitcodeReader::materializeModule() { … }
std::vector<StructType *> BitcodeReader::getIdentifiedStructTypes() const { … }
ModuleSummaryIndexBitcodeReader::ModuleSummaryIndexBitcodeReader(
BitstreamCursor Cursor, StringRef Strtab, ModuleSummaryIndex &TheIndex,
StringRef ModulePath, std::function<bool(GlobalValue::GUID)> IsPrevailing)
: … { … }
void ModuleSummaryIndexBitcodeReader::addThisModule() { … }
ModuleSummaryIndex::ModuleInfo *
ModuleSummaryIndexBitcodeReader::getThisModule() { … }
template <bool AllowNullValueInfo>
std::pair<ValueInfo, GlobalValue::GUID>
ModuleSummaryIndexBitcodeReader::getValueInfoFromValueId(unsigned ValueId) { … }
void ModuleSummaryIndexBitcodeReader::setValueGUID(
uint64_t ValueID, StringRef ValueName, GlobalValue::LinkageTypes Linkage,
StringRef SourceFileName) { … }
Error ModuleSummaryIndexBitcodeReader::parseValueSymbolTable(
uint64_t Offset,
DenseMap<unsigned, GlobalValue::LinkageTypes> &ValueIdToLinkageMap) { … }
Error ModuleSummaryIndexBitcodeReader::parseModule() { … }
SmallVector<ValueInfo, 0>
ModuleSummaryIndexBitcodeReader::makeRefList(ArrayRef<uint64_t> Record) { … }
SmallVector<FunctionSummary::EdgeTy, 0>
ModuleSummaryIndexBitcodeReader::makeCallList(ArrayRef<uint64_t> Record,
bool IsOldProfileFormat,
bool HasProfile, bool HasRelBF) { … }
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) { … }
std::vector<FunctionSummary::ParamAccess>
ModuleSummaryIndexBitcodeReader::parseParamAccesses(ArrayRef<uint64_t> Record) { … }
void ModuleSummaryIndexBitcodeReader::parseTypeIdCompatibleVtableInfo(
ArrayRef<uint64_t> Record, size_t &Slot,
TypeIdCompatibleVtableInfo &TypeId) { … }
void ModuleSummaryIndexBitcodeReader::parseTypeIdCompatibleVtableSummaryRecord(
ArrayRef<uint64_t> Record) { … }
static void setSpecialRefs(SmallVectorImpl<ValueInfo> &Refs, unsigned ROCnt,
unsigned WOCnt) { … }
Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { … }
Error ModuleSummaryIndexBitcodeReader::parseModuleStringTable() { … }
namespace {
class BitcodeErrorCategoryType : public std::error_category { … };
}
const std::error_category &llvm::BitcodeErrorCategory() { … }
static Expected<StringRef> readBlobInRecord(BitstreamCursor &Stream,
unsigned Block, unsigned RecordID) { … }
Expected<std::vector<BitcodeModule>>
llvm::getBitcodeModuleList(MemoryBufferRef Buffer) { … }
Expected<BitcodeFileContents>
llvm::getBitcodeFileContents(MemoryBufferRef Buffer) { … }
Expected<std::unique_ptr<Module>>
BitcodeModule::getModuleImpl(LLVMContext &Context, bool MaterializeAll,
bool ShouldLazyLoadMetadata, bool IsImporting,
ParserCallbacks Callbacks) { … }
Expected<std::unique_ptr<Module>>
BitcodeModule::getLazyModule(LLVMContext &Context, bool ShouldLazyLoadMetadata,
bool IsImporting, ParserCallbacks Callbacks) { … }
Error BitcodeModule::readSummary(
ModuleSummaryIndex &CombinedIndex, StringRef ModulePath,
std::function<bool(GlobalValue::GUID)> IsPrevailing) { … }
Expected<std::unique_ptr<ModuleSummaryIndex>> BitcodeModule::getSummary() { … }
static Expected<std::pair<bool, bool>>
getEnableSplitLTOUnitAndUnifiedFlag(BitstreamCursor &Stream,
unsigned ID,
BitcodeLTOInfo <OInfo) { … }
Expected<BitcodeLTOInfo> BitcodeModule::getLTOInfo() { … }
static Expected<BitcodeModule> getSingleModule(MemoryBufferRef Buffer) { … }
Expected<std::unique_ptr<Module>>
llvm::getLazyBitcodeModule(MemoryBufferRef Buffer, LLVMContext &Context,
bool ShouldLazyLoadMetadata, bool IsImporting,
ParserCallbacks Callbacks) { … }
Expected<std::unique_ptr<Module>> llvm::getOwningLazyBitcodeModule(
std::unique_ptr<MemoryBuffer> &&Buffer, LLVMContext &Context,
bool ShouldLazyLoadMetadata, bool IsImporting, ParserCallbacks Callbacks) { … }
Expected<std::unique_ptr<Module>>
BitcodeModule::parseModule(LLVMContext &Context, ParserCallbacks Callbacks) { … }
Expected<std::unique_ptr<Module>>
llvm::parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context,
ParserCallbacks Callbacks) { … }
Expected<std::string> llvm::getBitcodeTargetTriple(MemoryBufferRef Buffer) { … }
Expected<bool> llvm::isBitcodeContainingObjCCategory(MemoryBufferRef Buffer) { … }
Expected<std::string> llvm::getBitcodeProducerString(MemoryBufferRef Buffer) { … }
Error llvm::readModuleSummaryIndex(MemoryBufferRef Buffer,
ModuleSummaryIndex &CombinedIndex) { … }
Expected<std::unique_ptr<ModuleSummaryIndex>>
llvm::getModuleSummaryIndex(MemoryBufferRef Buffer) { … }
Expected<BitcodeLTOInfo> llvm::getBitcodeLTOInfo(MemoryBufferRef Buffer) { … }
Expected<std::unique_ptr<ModuleSummaryIndex>>
llvm::getModuleSummaryIndexForFile(StringRef Path,
bool IgnoreEmptyThinLTOIndexFile) { … }