diff --git a/llvm/include/llvm/Bitcode/BitcodeReader.h b/llvm/include/llvm/Bitcode/BitcodeReader.h --- a/llvm/include/llvm/Bitcode/BitcodeReader.h +++ b/llvm/include/llvm/Bitcode/BitcodeReader.h @@ -32,27 +32,60 @@ class LLVMContext; class Module; class MemoryBuffer; +class Metadata; class ModuleSummaryIndex; +class Type; +class Value; // Callback to override the data layout string of an imported bitcode module. // The first argument is the target triple, the second argument the data layout // string from the input, or a default string. It will be used if the callback // returns std::nullopt. -typedef llvm::function_ref(StringRef, StringRef)> - DataLayoutCallbackTy; - - // These functions are for converting Expected/Error values to - // ErrorOr/std::error_code for compatibility with legacy clients. FIXME: - // Remove these functions once no longer needed by the C and libLTO APIs. - - std::error_code errorToErrorCodeAndEmitErrors(LLVMContext &Ctx, Error Err); - - template - ErrorOr expectedToErrorOrAndEmitErrors(LLVMContext &Ctx, Expected Val) { - if (!Val) - return errorToErrorCodeAndEmitErrors(Ctx, Val.takeError()); - return std::move(*Val); - } +typedef std::function(StringRef, StringRef)> + DataLayoutCallbackFuncTy; + +typedef std::function GetTypeByIDTy; + +typedef std::function GetContainedTypeIDTy; + +typedef std::function + ValueTypeCallbackTy; + +typedef std::function + MDTypeCallbackTy; + +// These functions are for converting Expected/Error values to +// ErrorOr/std::error_code for compatibility with legacy clients. FIXME: +// Remove these functions once no longer needed by the C and libLTO APIs. + +std::error_code errorToErrorCodeAndEmitErrors(LLVMContext &Ctx, Error Err); + +template +ErrorOr expectedToErrorOrAndEmitErrors(LLVMContext &Ctx, Expected Val) { + if (!Val) + return errorToErrorCodeAndEmitErrors(Ctx, Val.takeError()); + return std::move(*Val); +} + +struct ParserCallbacks { + std::optional DataLayout; + /// The ValueType callback is called for every function definition or + /// declaration and allows accessing the type information, also behind + /// pointers. This can be useful, when the opaque pointer upgrade cleans all + /// type information behind pointers. + /// The second argument to ValueTypeCallback is the type ID of the + /// function, the two passed functions can be used to extract type + /// information. + std::optional ValueType; + /// The MDType callback is called for every value in metadata. + std::optional MDType; + + ParserCallbacks() = default; + explicit ParserCallbacks(DataLayoutCallbackFuncTy DataLayout) + : DataLayout(DataLayout) {} +}; struct BitcodeFileContents; @@ -90,7 +123,7 @@ Expected> getModuleImpl(LLVMContext &Context, bool MaterializeAll, bool ShouldLazyLoadMetadata, bool IsImporting, - DataLayoutCallbackTy DataLayoutCallback); + ParserCallbacks Callbacks = {}); public: StringRef getBuffer() const { @@ -105,18 +138,13 @@ /// bodies. If ShouldLazyLoadMetadata is true, lazily load metadata as well. /// If IsImporting is true, this module is being parsed for ThinLTO /// importing into another module. - Expected> getLazyModule( - LLVMContext &Context, bool ShouldLazyLoadMetadata, bool IsImporting, - DataLayoutCallbackTy DataLayoutCallback = [](StringRef, StringRef) { - return std::nullopt; - }); + Expected> + getLazyModule(LLVMContext &Context, bool ShouldLazyLoadMetadata, + bool IsImporting, ParserCallbacks Callbacks = {}); /// Read the entire bitcode module and return it. - Expected> parseModule( - LLVMContext &Context, - DataLayoutCallbackTy DataLayoutCallback = [](StringRef, StringRef) { - return std::nullopt; - }); + Expected> + parseModule(LLVMContext &Context, ParserCallbacks Callbacks = {}); /// Returns information about the module to be used for LTO: whether to /// compile with ThinLTO, and whether it has a summary. @@ -153,12 +181,11 @@ /// deserialization of function bodies. If ShouldLazyLoadMetadata is true, /// lazily load metadata as well. If IsImporting is true, this module is /// being parsed for ThinLTO importing into another module. - Expected> getLazyBitcodeModule( - MemoryBufferRef Buffer, LLVMContext &Context, - bool ShouldLazyLoadMetadata = false, bool IsImporting = false, - DataLayoutCallbackTy DataLayoutCallback = [](StringRef, StringRef) { - return std::nullopt; - }); + Expected> + getLazyBitcodeModule(MemoryBufferRef Buffer, LLVMContext &Context, + bool ShouldLazyLoadMetadata = false, + bool IsImporting = false, + ParserCallbacks Callbacks = {}); /// Like getLazyBitcodeModule, except that the module takes ownership of /// the memory buffer if successful. If successful, this moves Buffer. On @@ -166,7 +193,8 @@ /// being parsed for ThinLTO importing into another module. Expected> getOwningLazyBitcodeModule( std::unique_ptr &&Buffer, LLVMContext &Context, - bool ShouldLazyLoadMetadata = false, bool IsImporting = false); + bool ShouldLazyLoadMetadata = false, bool IsImporting = false, + ParserCallbacks Callbacks = {}); /// Read the header of the specified bitcode buffer and extract just the /// triple information. If successful, this returns a string. On error, this @@ -183,11 +211,9 @@ Expected getBitcodeProducerString(MemoryBufferRef Buffer); /// Read the specified bitcode file, returning the module. - Expected> parseBitcodeFile( - MemoryBufferRef Buffer, LLVMContext &Context, - DataLayoutCallbackTy DataLayoutCallback = [](StringRef, StringRef) { - return std::nullopt; - }); + Expected> + parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context, + ParserCallbacks Callbacks = {}); /// Returns LTO information for the specified bitcode file. Expected getBitcodeLTOInfo(MemoryBufferRef Buffer); diff --git a/llvm/include/llvm/IRReader/IRReader.h b/llvm/include/llvm/IRReader/IRReader.h --- a/llvm/include/llvm/IRReader/IRReader.h +++ b/llvm/include/llvm/IRReader/IRReader.h @@ -16,6 +16,7 @@ #include "llvm/ADT/STLFunctionalExtras.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Bitcode/BitcodeReader.h" #include #include @@ -27,9 +28,6 @@ class SMDiagnostic; class LLVMContext; -typedef llvm::function_ref(StringRef, StringRef)> - DataLayoutCallbackTy; - /// If the given MemoryBuffer holds a bitcode image, return a Module /// for it which does lazy deserialization of function bodies. Otherwise, /// attempt to parse it as LLVM Assembly and return a fully populated @@ -53,21 +51,17 @@ /// for it. Otherwise, attempt to parse it as LLVM Assembly and return /// a Module for it. /// \param DataLayoutCallback Override datalayout in the llvm assembly. -std::unique_ptr parseIR( - MemoryBufferRef Buffer, SMDiagnostic &Err, LLVMContext &Context, - DataLayoutCallbackTy DataLayoutCallback = [](StringRef, StringRef) { - return std::nullopt; - }); +std::unique_ptr parseIR(MemoryBufferRef Buffer, SMDiagnostic &Err, + LLVMContext &Context, + ParserCallbacks Callbacks = {}); /// If the given file holds a bitcode image, return a Module for it. /// Otherwise, attempt to parse it as LLVM Assembly and return a Module /// for it. /// \param DataLayoutCallback Override datalayout in the llvm assembly. -std::unique_ptr parseIRFile( - StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, - DataLayoutCallbackTy DataLayoutCallback = [](StringRef, StringRef) { - return std::nullopt; - }); +std::unique_ptr parseIRFile(StringRef Filename, SMDiagnostic &Err, + LLVMContext &Context, + ParserCallbacks Callbacks = {}); } #endif diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -674,6 +674,8 @@ std::vector BundleTags; SmallVector SSIDs; + std::optional ValueTypeCallback; + public: BitcodeReader(BitstreamCursor Stream, StringRef Strtab, StringRef ProducerIdentification, LLVMContext &Context); @@ -686,9 +688,8 @@ /// Main interface to parsing a bitcode buffer. /// \returns true if an error occurred. - Error parseBitcodeInto( - Module *M, bool ShouldLazyLoadMetadata, bool IsImporting, - DataLayoutCallbackTy DataLayoutCallback); + Error parseBitcodeInto(Module *M, bool ShouldLazyLoadMetadata, + bool IsImporting, ParserCallbacks Callbacks = {}); static uint64_t decodeSignRotatedValue(uint64_t V); @@ -709,6 +710,7 @@ unsigned getContainedTypeID(unsigned ID, unsigned Idx = 0); unsigned getVirtualTypeID(Type *Ty, ArrayRef ContainedTypeIDs = {}); + void callValueTypeCallback(Value *F, unsigned TypeID); Expected materializeValue(unsigned ValID, BasicBlock *InsertBB); Expected getValueForInitializer(unsigned ID); @@ -819,11 +821,8 @@ /// a corresponding error code. Error parseAlignmentValue(uint64_t Exponent, MaybeAlign &Alignment); Error parseAttrKind(uint64_t Code, Attribute::AttrKind *Kind); - Error parseModule( - uint64_t ResumeBit, bool ShouldLazyLoadMetadata = false, - DataLayoutCallbackTy DataLayoutCallback = [](StringRef, StringRef) { - return std::nullopt; - }); + Error parseModule(uint64_t ResumeBit, bool ShouldLazyLoadMetadata = false, + ParserCallbacks Callbacks = {}); Error parseComdatRecord(ArrayRef Record); Error parseGlobalVarRecord(ArrayRef Record); @@ -3919,6 +3918,14 @@ return Error::success(); } +void BitcodeReader::callValueTypeCallback(Value *F, unsigned TypeID) { + if (ValueTypeCallback) { + (*ValueTypeCallback)( + F, TypeID, [this](unsigned I) { return getTypeByID(I); }, + [this](unsigned I, unsigned J) { return getContainedTypeID(I, J); }); + } +} + Error BitcodeReader::parseFunctionRecord(ArrayRef Record) { // v1: [type, callingconv, isproto, linkage, paramattr, alignment, section, // visibility, gc, unnamed_addr, prologuedata, dllstorageclass, comdat, @@ -3963,6 +3970,7 @@ uint64_t RawLinkage = Record[3]; Func->setLinkage(getDecodedLinkage(RawLinkage)); Func->setAttributes(getAttributes(Record[4])); + callValueTypeCallback(Func, FTyID); // Upgrade any old-style byval or sret without a type by propagating the // argument's pointee type. There should be no opaque pointers where the byval @@ -4180,7 +4188,8 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit, bool ShouldLazyLoadMetadata, - DataLayoutCallbackTy DataLayoutCallback) { + ParserCallbacks Callbacks) { + this->ValueTypeCallback = std::move(Callbacks.ValueType); if (ResumeBit) { if (Error JumpFailed = Stream.JumpToBit(ResumeBit)) return JumpFailed; @@ -4210,9 +4219,11 @@ TentativeDataLayoutStr, TheModule->getTargetTriple()); // Apply override - if (auto LayoutOverride = DataLayoutCallback(TheModule->getTargetTriple(), - TentativeDataLayoutStr)) - TentativeDataLayoutStr = *LayoutOverride; + if (Callbacks.DataLayout) { + if (auto LayoutOverride = (*Callbacks.DataLayout)( + TheModule->getTargetTriple(), TentativeDataLayoutStr)) + TentativeDataLayoutStr = *LayoutOverride; + } // Now the layout string is finalized in TentativeDataLayoutStr. Parse it. Expected MaybeDL = DataLayout::parse(TentativeDataLayoutStr); @@ -4477,16 +4488,22 @@ } Record.clear(); } + this->ValueTypeCallback = std::nullopt; return Error::success(); } Error BitcodeReader::parseBitcodeInto(Module *M, bool ShouldLazyLoadMetadata, bool IsImporting, - DataLayoutCallbackTy DataLayoutCallback) { + ParserCallbacks Callbacks) { TheModule = M; - MDLoader = MetadataLoader(Stream, *M, ValueList, IsImporting, - [&](unsigned ID) { return getTypeByID(ID); }); - return parseModule(0, ShouldLazyLoadMetadata, DataLayoutCallback); + MetadataLoaderCallbacks MDCallbacks; + MDCallbacks.GetTypeByID = [&](unsigned ID) { return getTypeByID(ID); }; + MDCallbacks.GetContainedTypeID = [&](unsigned I, unsigned J) { + return getContainedTypeID(I, J); + }; + MDCallbacks.MDType = Callbacks.MDType; + MDLoader = MetadataLoader(Stream, *M, ValueList, IsImporting, MDCallbacks); + return parseModule(0, ShouldLazyLoadMetadata, Callbacks); } Error BitcodeReader::typeCheckLoadStoreInst(Type *ValType, Type *PtrType) { @@ -7919,7 +7936,7 @@ Expected> BitcodeModule::getModuleImpl(LLVMContext &Context, bool MaterializeAll, bool ShouldLazyLoadMetadata, bool IsImporting, - DataLayoutCallbackTy DataLayoutCallback) { + ParserCallbacks Callbacks) { BitstreamCursor Stream(Buffer); std::string ProducerIdentification; @@ -7942,7 +7959,7 @@ // Delay parsing Metadata if ShouldLazyLoadMetadata is true. if (Error Err = R->parseBitcodeInto(M.get(), ShouldLazyLoadMetadata, - IsImporting, DataLayoutCallback)) + IsImporting, Callbacks)) return std::move(Err); if (MaterializeAll) { @@ -7959,10 +7976,9 @@ Expected> BitcodeModule::getLazyModule(LLVMContext &Context, bool ShouldLazyLoadMetadata, - bool IsImporting, - DataLayoutCallbackTy DataLayoutCallback) { + bool IsImporting, ParserCallbacks Callbacks) { return getModuleImpl(Context, false, ShouldLazyLoadMetadata, IsImporting, - DataLayoutCallback); + Callbacks); } // Parse the specified bitcode buffer and merge the index into CombinedIndex. @@ -8109,41 +8125,40 @@ Expected> llvm::getLazyBitcodeModule(MemoryBufferRef Buffer, LLVMContext &Context, bool ShouldLazyLoadMetadata, bool IsImporting, - DataLayoutCallbackTy DataLayoutCallback) { + ParserCallbacks Callbacks) { Expected BM = getSingleModule(Buffer); if (!BM) return BM.takeError(); return BM->getLazyModule(Context, ShouldLazyLoadMetadata, IsImporting, - DataLayoutCallback); + Callbacks); } Expected> llvm::getOwningLazyBitcodeModule( std::unique_ptr &&Buffer, LLVMContext &Context, - bool ShouldLazyLoadMetadata, bool IsImporting) { + bool ShouldLazyLoadMetadata, bool IsImporting, ParserCallbacks Callbacks) { auto MOrErr = getLazyBitcodeModule(*Buffer, Context, ShouldLazyLoadMetadata, - IsImporting); + IsImporting, Callbacks); if (MOrErr) (*MOrErr)->setOwnedMemoryBuffer(std::move(Buffer)); return MOrErr; } Expected> -BitcodeModule::parseModule(LLVMContext &Context, - DataLayoutCallbackTy DataLayoutCallback) { - return getModuleImpl(Context, true, false, false, DataLayoutCallback); +BitcodeModule::parseModule(LLVMContext &Context, ParserCallbacks Callbacks) { + return getModuleImpl(Context, true, false, false, Callbacks); // TODO: Restore the use-lists to the in-memory state when the bitcode was // written. We must defer until the Module has been fully materialized. } Expected> llvm::parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context, - DataLayoutCallbackTy DataLayoutCallback) { + ParserCallbacks Callbacks) { Expected BM = getSingleModule(Buffer); if (!BM) return BM.takeError(); - return BM->parseModule(Context, DataLayoutCallback); + return BM->parseModule(Context, Callbacks); } Expected llvm::getBitcodeTargetTriple(MemoryBufferRef Buffer) { diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.h b/llvm/lib/Bitcode/Reader/MetadataLoader.h --- a/llvm/lib/Bitcode/Reader/MetadataLoader.h +++ b/llvm/lib/Bitcode/Reader/MetadataLoader.h @@ -29,6 +29,20 @@ class Type; template class ArrayRef; +typedef std::function GetTypeByIDTy; + +typedef std::function GetContainedTypeIDTy; + +typedef std::function + MDTypeCallbackTy; + +struct MetadataLoaderCallbacks { + GetTypeByIDTy GetTypeByID; + GetContainedTypeIDTy GetContainedTypeID; + std::optional MDType; +}; + /// Helper class that handles loading Metadatas and keeping them available. class MetadataLoader { class MetadataLoaderImpl; @@ -39,7 +53,7 @@ ~MetadataLoader(); MetadataLoader(BitstreamCursor &Stream, Module &TheModule, BitcodeReaderValueList &ValueList, bool IsImporting, - std::function getTypeByID); + MetadataLoaderCallbacks Callbacks); MetadataLoader &operator=(MetadataLoader &&); MetadataLoader(MetadataLoader &&); diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp --- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp +++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp @@ -406,7 +406,7 @@ BitstreamCursor &Stream; LLVMContext &Context; Module &TheModule; - std::function getTypeByID; + MetadataLoaderCallbacks Callbacks; /// Cursor associated with the lazy-loading of Metadata. This is the easy way /// to keep around the right "context" (Abbrev list) to be able to jump in @@ -627,14 +627,15 @@ upgradeCUVariables(); } + void callMDTypeCallback(Metadata **Val, unsigned TypeID); + public: MetadataLoaderImpl(BitstreamCursor &Stream, Module &TheModule, BitcodeReaderValueList &ValueList, - std::function getTypeByID, - bool IsImporting) + MetadataLoaderCallbacks Callbacks, bool IsImporting) : MetadataList(TheModule.getContext(), Stream.SizeInBytes()), ValueList(ValueList), Stream(Stream), Context(TheModule.getContext()), - TheModule(TheModule), getTypeByID(std::move(getTypeByID)), + TheModule(TheModule), Callbacks(std::move(Callbacks)), IsImporting(IsImporting) {} Error parseMetadata(bool ModuleLevel); @@ -952,6 +953,14 @@ } } +void MetadataLoader::MetadataLoaderImpl::callMDTypeCallback(Metadata **Val, + unsigned TypeID) { + if (Callbacks.MDType) { + (*Callbacks.MDType)(Val, TypeID, Callbacks.GetTypeByID, + Callbacks.GetContainedTypeID); + } +} + /// Parse a METADATA_BLOCK. If ModuleLevel is true then we are parsing /// module level metadata. Error MetadataLoader::MetadataLoaderImpl::parseMetadata(bool ModuleLevel) { @@ -1221,7 +1230,7 @@ } unsigned TyID = Record[0]; - Type *Ty = getTypeByID(TyID); + Type *Ty = Callbacks.GetTypeByID(TyID); if (Ty->isMetadataTy() || Ty->isVoidTy()) { dropRecord(); break; @@ -1245,7 +1254,7 @@ SmallVector Elts; for (unsigned i = 0; i != Size; i += 2) { unsigned TyID = Record[i]; - Type *Ty = getTypeByID(TyID); + Type *Ty = Callbacks.GetTypeByID(TyID); if (!Ty) return error("Invalid record"); if (Ty->isMetadataTy()) @@ -1255,9 +1264,10 @@ /*ConstExprInsertBB*/ nullptr); if (!V) return error("Invalid value reference from old metadata"); - auto *MD = ValueAsMetadata::get(V); + Metadata *MD = ValueAsMetadata::get(V); assert(isa(MD) && "Expected non-function-local metadata"); + callMDTypeCallback(&MD, TyID); Elts.push_back(MD); } else Elts.push_back(nullptr); @@ -1271,7 +1281,7 @@ return error("Invalid record"); unsigned TyID = Record[0]; - Type *Ty = getTypeByID(TyID); + Type *Ty = Callbacks.GetTypeByID(TyID); if (Ty->isMetadataTy() || Ty->isVoidTy()) return error("Invalid record"); @@ -1280,7 +1290,9 @@ if (!V) return error("Invalid value reference from metadata"); - MetadataList.assignValue(ValueAsMetadata::get(V), NextMetadataNo); + Metadata *MD = ValueAsMetadata::get(V); + callMDTypeCallback(&MD, TyID); + MetadataList.assignValue(MD, NextMetadataNo); NextMetadataNo++; break; } @@ -2359,9 +2371,9 @@ MetadataLoader::MetadataLoader(BitstreamCursor &Stream, Module &TheModule, BitcodeReaderValueList &ValueList, bool IsImporting, - std::function getTypeByID) + MetadataLoaderCallbacks Callbacks) : Pimpl(std::make_unique( - Stream, TheModule, ValueList, std::move(getTypeByID), IsImporting)) {} + Stream, TheModule, ValueList, std::move(Callbacks), IsImporting)) {} Error MetadataLoader::parseMetadata(bool ModuleLevel) { return Pimpl->parseMetadata(ModuleLevel); diff --git a/llvm/lib/IRReader/IRReader.cpp b/llvm/lib/IRReader/IRReader.cpp --- a/llvm/lib/IRReader/IRReader.cpp +++ b/llvm/lib/IRReader/IRReader.cpp @@ -68,14 +68,14 @@ std::unique_ptr llvm::parseIR(MemoryBufferRef Buffer, SMDiagnostic &Err, LLVMContext &Context, - DataLayoutCallbackTy DataLayoutCallback) { + ParserCallbacks Callbacks) { NamedRegionTimer T(TimeIRParsingName, TimeIRParsingDescription, TimeIRParsingGroupName, TimeIRParsingGroupDescription, TimePassesIsEnabled); if (isBitcode((const unsigned char *)Buffer.getBufferStart(), (const unsigned char *)Buffer.getBufferEnd())) { Expected> ModuleOrErr = - parseBitcodeFile(Buffer, Context, DataLayoutCallback); + parseBitcodeFile(Buffer, Context, Callbacks); if (Error E = ModuleOrErr.takeError()) { handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) { Err = SMDiagnostic(Buffer.getBufferIdentifier(), SourceMgr::DK_Error, @@ -86,12 +86,14 @@ return std::move(ModuleOrErr.get()); } - return parseAssembly(Buffer, Err, Context, nullptr, DataLayoutCallback); + return parseAssembly(Buffer, Err, Context, nullptr, + Callbacks.DataLayout.value_or( + [](StringRef, StringRef) { return std::nullopt; })); } -std::unique_ptr -llvm::parseIRFile(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, - DataLayoutCallbackTy DataLayoutCallback) { +std::unique_ptr llvm::parseIRFile(StringRef Filename, SMDiagnostic &Err, + LLVMContext &Context, + ParserCallbacks Callbacks) { ErrorOr> FileOrErr = MemoryBuffer::getFileOrSTDIN(Filename, /*IsText=*/true); if (std::error_code EC = FileOrErr.getError()) { @@ -100,8 +102,7 @@ return nullptr; } - return parseIR(FileOrErr.get()->getMemBufferRef(), Err, Context, - DataLayoutCallback); + return parseIR(FileOrErr.get()->getMemBufferRef(), Err, Context, Callbacks); } //===----------------------------------------------------------------------===// diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp --- a/llvm/tools/llc/llc.cpp +++ b/llvm/tools/llc/llc.cpp @@ -568,7 +568,8 @@ if (MIR) M = MIR->parseIRModule(SetDataLayout); } else { - M = parseIRFile(InputFilename, Err, Context, SetDataLayout); + M = parseIRFile(InputFilename, Err, Context, + ParserCallbacks(SetDataLayout)); } if (!M) { Err.print(argv[0], WithColor::error(errs(), argv[0])); diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp --- a/llvm/tools/opt/opt.cpp +++ b/llvm/tools/opt/opt.cpp @@ -545,7 +545,8 @@ InputFilename, Err, Context, nullptr, SetDataLayout) .Mod; else - M = parseIRFile(InputFilename, Err, Context, SetDataLayout); + M = parseIRFile(InputFilename, Err, Context, + ParserCallbacks(SetDataLayout)); if (!M) { Err.print(argv[0], errs()); diff --git a/llvm/unittests/Bitcode/BitReaderTest.cpp b/llvm/unittests/Bitcode/BitReaderTest.cpp --- a/llvm/unittests/Bitcode/BitReaderTest.cpp +++ b/llvm/unittests/Bitcode/BitReaderTest.cpp @@ -6,11 +6,14 @@ // //===----------------------------------------------------------------------===// +#include "BitReaderTestCode.h" +#include "llvm/ADT/MapVector.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/AsmParser/Parser.h" #include "llvm/Bitcode/BitcodeReader.h" #include "llvm/Bitcode/BitcodeWriter.h" +#include "llvm/IR/Constants.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" @@ -255,4 +258,180 @@ EXPECT_FALSE(verifyModule(*M, &dbgs())); } +// Helper function to convert type metadata to a string for testing +static std::string mdToString(Metadata *MD) { + std::string S; + if (auto *VMD = dyn_cast(MD)) { + if (VMD->getType()->isPointerTy()) { + S += "ptr"; + return S; + } + } + + if (auto *TMD = dyn_cast(MD)) { + S += "!{"; + for (unsigned I = 0; I < TMD->getNumOperands(); I++) { + if (I != 0) + S += ", "; + S += mdToString(TMD->getOperand(I).get()); + } + S += "}"; + } else if (auto *SMD = dyn_cast(MD)) { + S += "!'"; + S += SMD->getString(); + S += "'"; + } else if (auto *I = mdconst::dyn_extract(MD)) { + S += std::to_string(I->getZExtValue()); + } else if (auto *P = mdconst::dyn_extract(MD)) { + auto *Ty = P->getType(); + if (Ty->isIntegerTy()) { + S += "i"; + S += std::to_string(Ty->getIntegerBitWidth()); + } else if (Ty->isStructTy()) { + S += "%"; + S += Ty->getStructName(); + } else { + llvm_unreachable("unhandled poison metadata"); + } + } else { + llvm_unreachable("unhandled metadata"); + } + return S; +} + +// Recursively look into a (pointer) type and the the type. +// For primitive types it's a poison value of the type, for a pointer it's a +// metadata tuple with the addrspace and the referenced type. For a function, +// it's a tuple where the first element is the string "function", the second +// element is the return type or the string "void" and the following elements +// are the argument types. +static Metadata *getTypeMetadataEntry(unsigned TypeID, LLVMContext &Context, + GetTypeByIDTy GetTypeByID, + GetContainedTypeIDTy GetContainedTypeID) { + Type *Ty = GetTypeByID(TypeID); + if (auto *FTy = dyn_cast(Ty)) { + // Save the function signature as metadata + SmallVector SignatureMD; + SignatureMD.push_back(MDString::get(Context, "function")); + // Return type + if (FTy->getReturnType()->isVoidTy()) + SignatureMD.push_back(MDString::get(Context, "void")); + else + SignatureMD.push_back(getTypeMetadataEntry(GetContainedTypeID(TypeID, 0), + Context, GetTypeByID, + GetContainedTypeID)); + // Arguments + for (unsigned I = 0; I != FTy->getNumParams(); ++I) + SignatureMD.push_back( + getTypeMetadataEntry(GetContainedTypeID(TypeID, I + 1), Context, + GetTypeByID, GetContainedTypeID)); + + return MDTuple::get(Context, SignatureMD); + } + + if (!Ty->isPointerTy()) + return ConstantAsMetadata::get(PoisonValue::get(Ty)); + + // Return !{, } for pointer + SmallVector MD; + MD.push_back(ConstantAsMetadata::get(ConstantInt::get( + Type::getInt32Ty(Context), Ty->getPointerAddressSpace()))); + MD.push_back(getTypeMetadataEntry(GetContainedTypeID(TypeID, 0), Context, + GetTypeByID, GetContainedTypeID)); + return MDTuple::get(Context, MD); +} + +// Test that when reading bitcode with typed pointers and upgrading them to +// opaque pointers, the type information of function signatures can be extracted +// and stored in metadata. +TEST(BitReaderTest, AccessFunctionTypeInfo) { + StringRef Bitcode(reinterpret_cast(AccessFunctionTypeInfoBc), + sizeof(AccessFunctionTypeInfoBc)); + + LLVMContext Context; + ParserCallbacks Callbacks; + // Supply a callback that stores the signature of a function into metadata, + // so that the types behind pointers can be accessed. + // Each function gets a !types metadata, which is a tuple with one element + // for a non-void return type and every argument. For primitive types it's + // a poison value of the type, for a pointer it's a metadata tuple with + // the addrspace and the referenced type. + Callbacks.ValueType = [&](Value *V, unsigned TypeID, + GetTypeByIDTy GetTypeByID, + GetContainedTypeIDTy GetContainedTypeID) { + if (auto *F = dyn_cast(V)) { + auto *MD = getTypeMetadataEntry(TypeID, F->getContext(), GetTypeByID, + GetContainedTypeID); + F->setMetadata("types", cast(MD)); + } + }; + + Expected> ModuleOrErr = + parseBitcodeFile(MemoryBufferRef(Bitcode, "test"), Context, Callbacks); + + if (!ModuleOrErr) + report_fatal_error("Could not parse bitcode module"); + std::unique_ptr M = std::move(ModuleOrErr.get()); + + EXPECT_EQ(mdToString(M->getFunction("func")->getMetadata("types")), + "!{!'function', !'void'}"); + EXPECT_EQ(mdToString(M->getFunction("func_header")->getMetadata("types")), + "!{!'function', i32}"); + EXPECT_EQ(mdToString(M->getFunction("ret_ptr")->getMetadata("types")), + "!{!'function', !{0, i8}}"); + EXPECT_EQ(mdToString(M->getFunction("ret_and_arg_ptr")->getMetadata("types")), + "!{!'function', !{0, i8}, !{8, i32}}"); + EXPECT_EQ(mdToString(M->getFunction("double_ptr")->getMetadata("types")), + "!{!'function', !{1, i8}, !{2, !{0, i32}}, !{0, !{0, !{0, i32}}}}"); +} + +// Test that when reading bitcode with typed pointers and upgrading them to +// opaque pointers, the type information of pointers in metadata can be +// extracted and stored in metadata. +TEST(BitReaderTest, AccessMetadataTypeInfo) { + StringRef Bitcode(reinterpret_cast(AccessMetadataTypeInfoBc), + sizeof(AccessFunctionTypeInfoBc)); + + LLVMContext Context; + ParserCallbacks Callbacks; + // Supply a callback that stores types from metadata, + // so that the types behind pointers can be accessed. + // Non-pointer entries are ignored. Values with a pointer type are + // replaced by a metadata tuple with {original value, type md}. We cannot + // save the metadata outside because after conversion to opaque pointers, + // entries are not distinguishable anymore (e.g. i32* and i8* are both + // upgraded to ptr). + Callbacks.MDType = [&](Metadata **Val, unsigned TypeID, + GetTypeByIDTy GetTypeByID, + GetContainedTypeIDTy GetContainedTypeID) { + auto *OrigVal = cast(*Val); + if (OrigVal->getType()->isPointerTy()) { + // Ignore function references, their signature can be saved like + // in the test above + if (!isa(OrigVal->getValue())) { + SmallVector Tuple; + Tuple.push_back(OrigVal); + Tuple.push_back(getTypeMetadataEntry(GetContainedTypeID(TypeID, 0), + OrigVal->getContext(), GetTypeByID, + GetContainedTypeID)); + *Val = MDTuple::get(OrigVal->getContext(), Tuple); + } + } + }; + + Expected> ModuleOrErr = + parseBitcodeFile(MemoryBufferRef(Bitcode, "test"), Context, Callbacks); + + if (!ModuleOrErr) + report_fatal_error("Could not parse bitcode module"); + std::unique_ptr M = std::move(ModuleOrErr.get()); + + EXPECT_EQ( + mdToString(M->getNamedMetadata("md")->getOperand(0)), + "!{2, !{ptr, %dx.types.f32}, ptr, !{ptr, !{!'function', !'void'}}}"); + EXPECT_EQ(mdToString(M->getNamedMetadata("md2")->getOperand(0)), + "!{!{ptr, !{!'function', !{0, i8}, !{2, !{0, i32}}}}, !{ptr, !{0, " + "!{0, i32}}}}"); +} + } // end namespace diff --git a/llvm/unittests/Bitcode/BitReaderTestCode.h b/llvm/unittests/Bitcode/BitReaderTestCode.h new file mode 100644 --- /dev/null +++ b/llvm/unittests/Bitcode/BitReaderTestCode.h @@ -0,0 +1,270 @@ +//===- llvm/unittest/Bitcode/BitReaderTestCode.h - Bitcode for tests ------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_UNITTESTS_BITCODE_BITREADERTESTCODE_H +#define LLVM_UNITTESTS_BITCODE_BITREADERTESTCODE_H + +// define void @func() { +// unreachable +// } +// declare i32 @func_header() +// declare i8* @ret_ptr() +// declare i8* @ret_and_arg_ptr(i32 addrspace(8)*) +// declare i8 addrspace(1)* @double_ptr(i32* addrspace(2)*, i32***) +const unsigned char AccessFunctionTypeInfoBc[] = { + 0x42, 0x43, 0xc0, 0xde, 0x35, 0x14, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x62, 0x0c, 0x30, 0x24, 0x4d, 0x59, 0xbe, 0x66, 0xad, 0xfb, 0xb4, 0x4f, + 0x1b, 0xc8, 0x24, 0x44, 0x01, 0x32, 0x05, 0x00, 0x21, 0x0c, 0x00, 0x00, + 0x3f, 0x01, 0x00, 0x00, 0x0b, 0x02, 0x21, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x16, 0x00, 0x00, 0x00, 0x07, 0x81, 0x23, 0x91, 0x41, 0xc8, 0x04, 0x49, + 0x06, 0x10, 0x32, 0x39, 0x92, 0x01, 0x84, 0x0c, 0x25, 0x05, 0x08, 0x19, + 0x1e, 0x04, 0x8b, 0x62, 0x80, 0x14, 0x45, 0x02, 0x42, 0x92, 0x0b, 0x42, + 0xa4, 0x10, 0x32, 0x14, 0x38, 0x08, 0x18, 0x4b, 0x0a, 0x32, 0x52, 0x88, + 0x48, 0x70, 0xc4, 0x21, 0x23, 0x44, 0x12, 0x87, 0x8c, 0x10, 0x41, 0x92, + 0x02, 0x64, 0xc8, 0x08, 0xb1, 0x14, 0x20, 0x43, 0x46, 0x88, 0x20, 0xc9, + 0x01, 0x32, 0x52, 0x84, 0x18, 0x2a, 0x28, 0x2a, 0x90, 0x31, 0x7c, 0xb0, + 0x5c, 0x91, 0x20, 0xc5, 0xc8, 0x00, 0x00, 0x00, 0x89, 0x20, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x32, 0x22, 0x48, 0x09, 0x20, 0x62, 0x46, 0x00, + 0x21, 0x2b, 0x24, 0x98, 0x14, 0x21, 0x25, 0x24, 0x98, 0x14, 0x19, 0x27, + 0x0c, 0x85, 0xa4, 0x90, 0x60, 0x52, 0x64, 0x5c, 0x20, 0x24, 0x65, 0x82, + 0xa0, 0x1a, 0x01, 0x30, 0x01, 0xa0, 0x30, 0x47, 0x00, 0x06, 0x26, 0x18, + 0x44, 0xe6, 0x08, 0x10, 0x32, 0x26, 0x38, 0x84, 0x06, 0x11, 0x06, 0xc4, + 0x08, 0x47, 0xd1, 0x1a, 0x44, 0x30, 0x02, 0x1a, 0x83, 0x08, 0x8e, 0x40, + 0x8e, 0xa0, 0x19, 0xda, 0x8b, 0x24, 0x07, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x1a, 0x21, 0x4c, 0x0e, 0x0f, 0xde, 0x9c, 0x4e, 0x4e, 0xbb, 0x7d, 0x43, + 0x2a, 0x80, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x60, 0x48, 0x45, 0x2c, 0x04, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0c, 0xa9, + 0x9e, 0x03, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x20, 0x80, 0x21, 0x95, 0xf5, 0x2c, 0x40, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x30, 0xa4, 0x2a, + 0x03, 0x45, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x20, 0x00, 0x89, 0x0d, 0x02, 0x45, 0x87, 0x02, 0x00, 0x00, + 0x62, 0x31, 0x00, 0x00, 0xb9, 0x00, 0x00, 0x00, 0x33, 0x08, 0x80, 0x1c, + 0xc4, 0xe1, 0x1c, 0x66, 0x14, 0x01, 0x3d, 0x88, 0x43, 0x38, 0x84, 0xc3, + 0x8c, 0x42, 0x80, 0x07, 0x79, 0x78, 0x07, 0x73, 0x98, 0x71, 0x0c, 0xe6, + 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x33, 0x0c, 0x42, 0x1e, + 0xc2, 0xc1, 0x1d, 0xce, 0xa1, 0x1c, 0x66, 0x30, 0x05, 0x3d, 0x88, 0x43, + 0x38, 0x84, 0x83, 0x1b, 0xcc, 0x03, 0x3d, 0xc8, 0x43, 0x3d, 0x8c, 0x03, + 0x3d, 0xcc, 0x78, 0x8c, 0x74, 0x70, 0x07, 0x7b, 0x08, 0x07, 0x79, 0x48, + 0x87, 0x70, 0x70, 0x07, 0x7a, 0x70, 0x03, 0x76, 0x78, 0x87, 0x70, 0x20, + 0x87, 0x19, 0xcc, 0x11, 0x0e, 0xec, 0x90, 0x0e, 0xe1, 0x30, 0x0f, 0x6e, + 0x30, 0x0f, 0xe3, 0xf0, 0x0e, 0xf0, 0x50, 0x0e, 0x33, 0x10, 0xc4, 0x1d, + 0xde, 0x21, 0x1c, 0xd8, 0x21, 0x1d, 0xc2, 0x61, 0x1e, 0x66, 0x30, 0x89, + 0x3b, 0xbc, 0x83, 0x3b, 0xd0, 0x43, 0x39, 0xb4, 0x03, 0x3c, 0xbc, 0x83, + 0x3c, 0x84, 0x03, 0x3b, 0xcc, 0xf0, 0x14, 0x76, 0x60, 0x07, 0x7b, 0x68, + 0x07, 0x37, 0x68, 0x87, 0x72, 0x68, 0x07, 0x37, 0x80, 0x87, 0x70, 0x90, + 0x87, 0x70, 0x60, 0x07, 0x76, 0x28, 0x07, 0x76, 0xf8, 0x05, 0x76, 0x78, + 0x87, 0x77, 0x80, 0x87, 0x5f, 0x08, 0x87, 0x71, 0x18, 0x87, 0x72, 0x98, + 0x87, 0x79, 0x98, 0x81, 0x2c, 0xee, 0xf0, 0x0e, 0xee, 0xe0, 0x0e, 0xf5, + 0xc0, 0x0e, 0xec, 0x30, 0x03, 0x62, 0xc8, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, + 0xcc, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xdc, 0x61, 0x1c, 0xca, 0x21, 0x1c, + 0xc4, 0x81, 0x1d, 0xca, 0x61, 0x06, 0xd6, 0x90, 0x43, 0x39, 0xc8, 0x43, + 0x39, 0x98, 0x43, 0x39, 0xc8, 0x43, 0x39, 0xb8, 0xc3, 0x38, 0x94, 0x43, + 0x38, 0x88, 0x03, 0x3b, 0x94, 0xc3, 0x2f, 0xbc, 0x83, 0x3c, 0xfc, 0x82, + 0x3b, 0xd4, 0x03, 0x3b, 0xb0, 0xc3, 0x0c, 0xc7, 0x69, 0x87, 0x70, 0x58, + 0x87, 0x72, 0x70, 0x83, 0x74, 0x68, 0x07, 0x78, 0x60, 0x87, 0x74, 0x18, + 0x87, 0x74, 0xa0, 0x87, 0x19, 0xce, 0x53, 0x0f, 0xee, 0x00, 0x0f, 0xf2, + 0x50, 0x0e, 0xe4, 0x90, 0x0e, 0xe3, 0x40, 0x0f, 0xe1, 0x20, 0x0e, 0xec, + 0x50, 0x0e, 0x33, 0x20, 0x28, 0x1d, 0xdc, 0xc1, 0x1e, 0xc2, 0x41, 0x1e, + 0xd2, 0x21, 0x1c, 0xdc, 0x81, 0x1e, 0xdc, 0xe0, 0x1c, 0xe4, 0xe1, 0x1d, + 0xea, 0x01, 0x1e, 0x66, 0x18, 0x51, 0x38, 0xb0, 0x43, 0x3a, 0x9c, 0x83, + 0x3b, 0xcc, 0x50, 0x24, 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x60, + 0x87, 0x77, 0x78, 0x07, 0x78, 0x98, 0x51, 0x4c, 0xf4, 0x90, 0x0f, 0xf0, + 0x50, 0x0e, 0x33, 0x1e, 0x6a, 0x1e, 0xca, 0x61, 0x1c, 0xe8, 0x21, 0x1d, + 0xde, 0xc1, 0x1d, 0x7e, 0x01, 0x1e, 0xe4, 0xa1, 0x1c, 0xcc, 0x21, 0x1d, + 0xf0, 0x61, 0x06, 0x54, 0x85, 0x83, 0x38, 0xcc, 0xc3, 0x3b, 0xb0, 0x43, + 0x3d, 0xd0, 0x43, 0x39, 0xfc, 0xc2, 0x3c, 0xe4, 0x43, 0x3b, 0x88, 0xc3, + 0x3b, 0xb0, 0xc3, 0x8c, 0xc5, 0x0a, 0x87, 0x79, 0x98, 0x87, 0x77, 0x18, + 0x87, 0x74, 0x08, 0x07, 0x7a, 0x28, 0x07, 0x72, 0x98, 0x81, 0x5c, 0xe3, + 0x10, 0x0e, 0xec, 0xc0, 0x0e, 0xe5, 0x50, 0x0e, 0xf3, 0x30, 0x23, 0xc1, + 0xd2, 0x41, 0x1e, 0xe4, 0xe1, 0x17, 0xd8, 0xe1, 0x1d, 0xde, 0x01, 0x1e, + 0x66, 0x48, 0x19, 0x3b, 0xb0, 0x83, 0x3d, 0xb4, 0x83, 0x1b, 0x84, 0xc3, + 0x38, 0x8c, 0x43, 0x39, 0xcc, 0xc3, 0x3c, 0xb8, 0xc1, 0x39, 0xc8, 0xc3, + 0x3b, 0xd4, 0x03, 0x3c, 0xcc, 0x48, 0xb4, 0x71, 0x08, 0x07, 0x76, 0x60, + 0x07, 0x71, 0x08, 0x87, 0x71, 0x58, 0x87, 0x19, 0xdb, 0xc6, 0x0e, 0xec, + 0x60, 0x0f, 0xed, 0xe0, 0x06, 0xf0, 0x20, 0x0f, 0xe5, 0x30, 0x0f, 0xe5, + 0x20, 0x0f, 0xf6, 0x50, 0x0e, 0x6e, 0x10, 0x0e, 0xe3, 0x30, 0x0e, 0xe5, + 0x30, 0x0f, 0xf3, 0xe0, 0x06, 0xe9, 0xe0, 0x0e, 0xe4, 0x50, 0x0e, 0xf8, + 0x30, 0x23, 0xe2, 0xec, 0x61, 0x1c, 0xc2, 0x81, 0x1d, 0xd8, 0xe1, 0x17, + 0xec, 0x21, 0x1d, 0xe6, 0x21, 0x1d, 0xc4, 0x21, 0x1d, 0xd8, 0x21, 0x1d, + 0xe8, 0x21, 0x1f, 0x66, 0x20, 0x9d, 0x3b, 0xbc, 0x43, 0x3d, 0xb8, 0x03, + 0x39, 0x94, 0x83, 0x39, 0xcc, 0x58, 0xbc, 0x70, 0x70, 0x07, 0x77, 0x78, + 0x07, 0x7a, 0x08, 0x07, 0x7a, 0x48, 0x87, 0x77, 0x70, 0x87, 0x19, 0xcb, + 0xe7, 0x0e, 0xef, 0x30, 0x0f, 0xe1, 0xe0, 0x0e, 0xe9, 0x40, 0x0f, 0xe9, + 0xa0, 0x0f, 0xe5, 0x30, 0xc3, 0x01, 0x03, 0x73, 0xa8, 0x07, 0x77, 0x18, + 0x87, 0x5f, 0x98, 0x87, 0x70, 0x70, 0x87, 0x74, 0xa0, 0x87, 0x74, 0xd0, + 0x87, 0x72, 0x98, 0x81, 0x84, 0x41, 0x39, 0xe0, 0xc3, 0x38, 0xb0, 0x43, + 0x3d, 0x90, 0x43, 0x39, 0xcc, 0x40, 0xc4, 0xa0, 0x1d, 0xca, 0xa1, 0x1d, + 0xe0, 0x41, 0x1e, 0xde, 0xc1, 0x1c, 0x66, 0x24, 0x63, 0x30, 0x0e, 0xe1, + 0xc0, 0x0e, 0xec, 0x30, 0x0f, 0xe9, 0x40, 0x0f, 0xe5, 0x30, 0x43, 0x21, + 0x83, 0x75, 0x18, 0x07, 0x73, 0x48, 0x87, 0x5f, 0xa0, 0x87, 0x7c, 0x80, + 0x87, 0x72, 0x98, 0xb1, 0x94, 0x01, 0x3c, 0x8c, 0xc3, 0x3c, 0x94, 0xc3, + 0x38, 0xd0, 0x43, 0x3a, 0xbc, 0x83, 0x3b, 0xcc, 0xc3, 0x8c, 0xc5, 0x0c, + 0x48, 0x21, 0x15, 0x42, 0x61, 0x1e, 0xe6, 0x21, 0x1d, 0xce, 0xc1, 0x1d, + 0x52, 0x81, 0x14, 0x00, 0xa9, 0x18, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, + 0x0b, 0x0a, 0x72, 0x28, 0x87, 0x77, 0x80, 0x07, 0x7a, 0x58, 0x70, 0x98, + 0x43, 0x3d, 0xb8, 0xc3, 0x38, 0xb0, 0x43, 0x39, 0xd0, 0xc3, 0x82, 0xe6, + 0x1c, 0xc6, 0xa1, 0x0d, 0xe8, 0x41, 0x1e, 0xc2, 0xc1, 0x1d, 0xe6, 0x21, + 0x1d, 0xe8, 0x21, 0x1d, 0xde, 0xc1, 0x1d, 0x16, 0x34, 0xe3, 0x60, 0x0e, + 0xe7, 0x50, 0x0f, 0xe1, 0x20, 0x0f, 0xe4, 0x40, 0x0f, 0xe1, 0x20, 0x0f, + 0xe7, 0x50, 0x0e, 0xf4, 0xb0, 0x80, 0x81, 0x07, 0x79, 0x28, 0x87, 0x70, + 0x60, 0x07, 0x76, 0x78, 0x87, 0x71, 0x08, 0x07, 0x7a, 0x28, 0x07, 0x72, + 0x58, 0x70, 0x9c, 0xc3, 0x38, 0xb4, 0x01, 0x3b, 0xa4, 0x83, 0x3d, 0x94, + 0xc3, 0x02, 0x6b, 0x1c, 0xd8, 0x21, 0x1c, 0xdc, 0xe1, 0x1c, 0xdc, 0x20, + 0x1c, 0xe4, 0x61, 0x1c, 0xdc, 0x20, 0x1c, 0xe8, 0x81, 0x1e, 0xc2, 0x61, + 0x1c, 0xd0, 0xa1, 0x1c, 0xc8, 0x61, 0x1c, 0xc2, 0x81, 0x1d, 0xd8, 0x61, + 0xc1, 0x01, 0x0f, 0xf4, 0x20, 0x0f, 0xe1, 0x50, 0x0f, 0xf4, 0x80, 0x0e, + 0x0b, 0x88, 0x75, 0x18, 0x07, 0x73, 0x48, 0x07, 0x00, 0x00, 0x00, 0x00, + 0xd1, 0x10, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07, 0xcc, 0x3c, 0xa4, + 0x83, 0x3b, 0x9c, 0x03, 0x3b, 0x94, 0x03, 0x3d, 0xa0, 0x83, 0x3c, 0x94, + 0x43, 0x38, 0x90, 0xc3, 0x01, 0x00, 0x00, 0x00, 0x61, 0x20, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x13, 0x04, 0x01, 0x03, 0x71, 0x20, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x32, 0x0e, 0x10, 0x22, 0x84, 0x00, 0xc0, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5d, 0x0c, 0x00, 0x00, + 0x1d, 0x00, 0x00, 0x00, 0x12, 0x03, 0x94, 0xe8, 0x00, 0x00, 0x00, 0x00, + 0x66, 0x75, 0x6e, 0x63, 0x66, 0x75, 0x6e, 0x63, 0x5f, 0x68, 0x65, 0x61, + 0x64, 0x65, 0x72, 0x72, 0x65, 0x74, 0x5f, 0x70, 0x74, 0x72, 0x72, 0x65, + 0x74, 0x5f, 0x61, 0x6e, 0x64, 0x5f, 0x61, 0x72, 0x67, 0x5f, 0x70, 0x74, + 0x72, 0x64, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x5f, 0x70, 0x74, 0x72, 0x31, + 0x36, 0x2e, 0x30, 0x2e, 0x30, 0x67, 0x69, 0x74, 0x20, 0x61, 0x63, 0x37, + 0x38, 0x39, 0x33, 0x66, 0x64, 0x39, 0x63, 0x39, 0x36, 0x35, 0x63, 0x35, + 0x30, 0x36, 0x34, 0x38, 0x63, 0x36, 0x33, 0x63, 0x30, 0x37, 0x35, 0x34, + 0x35, 0x36, 0x31, 0x35, 0x32, 0x65, 0x64, 0x35, 0x31, 0x38, 0x36, 0x39, + 0x30, 0x3c, 0x73, 0x74, 0x64, 0x69, 0x6e, 0x3e, 0x00, 0x00, 0x00, 0x00}; + +// %dx.types.f32 = type { float } +// declare void @main() +// !md = !{!0} +// !md2 = !{!1} +// !0 = !{i32 2, %dx.types.f32 addrspace(1)* undef, void ()* @main, void() +// addrspace(3)* null} +// !1 = !{i8*(i32* addrspace(2)*) addrspace(4)* undef, i32*** undef} +const unsigned char AccessMetadataTypeInfoBc[] = { + 0x42, 0x43, 0xc0, 0xde, 0x35, 0x14, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x62, 0x0c, 0x30, 0x24, 0x4d, 0x59, 0xbe, 0x66, 0xad, 0xfb, 0xb4, 0x4f, + 0x1b, 0xc8, 0x24, 0x44, 0x01, 0x32, 0x05, 0x00, 0x21, 0x0c, 0x00, 0x00, + 0x49, 0x01, 0x00, 0x00, 0x0b, 0x02, 0x21, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x16, 0x00, 0x00, 0x00, 0x07, 0x81, 0x23, 0x91, 0x41, 0xc8, 0x04, 0x49, + 0x06, 0x10, 0x32, 0x39, 0x92, 0x01, 0x84, 0x0c, 0x25, 0x05, 0x08, 0x19, + 0x1e, 0x04, 0x8b, 0x62, 0x80, 0x14, 0x45, 0x02, 0x42, 0x92, 0x0b, 0x42, + 0xa4, 0x10, 0x32, 0x14, 0x38, 0x08, 0x18, 0x4b, 0x0a, 0x32, 0x52, 0x88, + 0x48, 0x70, 0xc4, 0x21, 0x23, 0x44, 0x12, 0x87, 0x8c, 0x10, 0x41, 0x92, + 0x02, 0x64, 0xc8, 0x08, 0xb1, 0x14, 0x20, 0x43, 0x46, 0x88, 0x20, 0xc9, + 0x01, 0x32, 0x52, 0x84, 0x18, 0x2a, 0x28, 0x2a, 0x90, 0x31, 0x7c, 0xb0, + 0x5c, 0x91, 0x20, 0xc5, 0xc8, 0x00, 0x00, 0x00, 0x89, 0x20, 0x00, 0x00, + 0x15, 0x00, 0x00, 0x00, 0x32, 0x22, 0x48, 0x09, 0x20, 0x62, 0x46, 0x00, + 0x21, 0x2b, 0x24, 0x98, 0x14, 0x21, 0x25, 0x24, 0x98, 0x14, 0x19, 0x27, + 0x0c, 0x85, 0xa4, 0x90, 0x60, 0x52, 0x64, 0x5c, 0x20, 0x24, 0x65, 0x82, + 0x20, 0x1a, 0x01, 0x30, 0x01, 0xa0, 0x30, 0x10, 0x30, 0x47, 0x00, 0x06, + 0x33, 0x00, 0xc8, 0x0c, 0x97, 0x3f, 0x61, 0x0f, 0x21, 0xf9, 0xc5, 0x6d, + 0xa7, 0xa0, 0x0c, 0x22, 0x18, 0xc1, 0x20, 0x42, 0x30, 0xcc, 0x11, 0x20, + 0x94, 0x88, 0x0c, 0x22, 0x2c, 0x82, 0x11, 0x14, 0x1b, 0x44, 0x68, 0x08, + 0x5a, 0xf4, 0x00, 0x00, 0x1a, 0x21, 0x4c, 0x0e, 0x0f, 0xde, 0x9c, 0x4e, + 0x4e, 0xbb, 0x7d, 0x43, 0x2a, 0x80, 0x08, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x62, 0x83, 0x40, + 0x51, 0xa7, 0x00, 0x00, 0x80, 0x2c, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x32, 0x1e, 0x98, 0x0c, 0x19, 0x11, 0x4c, 0x90, 0x8c, 0x09, 0x26, 0x47, + 0xc6, 0x04, 0x43, 0x22, 0x45, 0x40, 0x67, 0x06, 0x80, 0xd0, 0x08, 0x00, + 0xb9, 0x19, 0x00, 0x82, 0x33, 0x00, 0x00, 0x00, 0xb1, 0x18, 0x00, 0x00, + 0xb9, 0x00, 0x00, 0x00, 0x33, 0x08, 0x80, 0x1c, 0xc4, 0xe1, 0x1c, 0x66, + 0x14, 0x01, 0x3d, 0x88, 0x43, 0x38, 0x84, 0xc3, 0x8c, 0x42, 0x80, 0x07, + 0x79, 0x78, 0x07, 0x73, 0x98, 0x71, 0x0c, 0xe6, 0x00, 0x0f, 0xed, 0x10, + 0x0e, 0xf4, 0x80, 0x0e, 0x33, 0x0c, 0x42, 0x1e, 0xc2, 0xc1, 0x1d, 0xce, + 0xa1, 0x1c, 0x66, 0x30, 0x05, 0x3d, 0x88, 0x43, 0x38, 0x84, 0x83, 0x1b, + 0xcc, 0x03, 0x3d, 0xc8, 0x43, 0x3d, 0x8c, 0x03, 0x3d, 0xcc, 0x78, 0x8c, + 0x74, 0x70, 0x07, 0x7b, 0x08, 0x07, 0x79, 0x48, 0x87, 0x70, 0x70, 0x07, + 0x7a, 0x70, 0x03, 0x76, 0x78, 0x87, 0x70, 0x20, 0x87, 0x19, 0xcc, 0x11, + 0x0e, 0xec, 0x90, 0x0e, 0xe1, 0x30, 0x0f, 0x6e, 0x30, 0x0f, 0xe3, 0xf0, + 0x0e, 0xf0, 0x50, 0x0e, 0x33, 0x10, 0xc4, 0x1d, 0xde, 0x21, 0x1c, 0xd8, + 0x21, 0x1d, 0xc2, 0x61, 0x1e, 0x66, 0x30, 0x89, 0x3b, 0xbc, 0x83, 0x3b, + 0xd0, 0x43, 0x39, 0xb4, 0x03, 0x3c, 0xbc, 0x83, 0x3c, 0x84, 0x03, 0x3b, + 0xcc, 0xf0, 0x14, 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x68, 0x87, + 0x72, 0x68, 0x07, 0x37, 0x80, 0x87, 0x70, 0x90, 0x87, 0x70, 0x60, 0x07, + 0x76, 0x28, 0x07, 0x76, 0xf8, 0x05, 0x76, 0x78, 0x87, 0x77, 0x80, 0x87, + 0x5f, 0x08, 0x87, 0x71, 0x18, 0x87, 0x72, 0x98, 0x87, 0x79, 0x98, 0x81, + 0x2c, 0xee, 0xf0, 0x0e, 0xee, 0xe0, 0x0e, 0xf5, 0xc0, 0x0e, 0xec, 0x30, + 0x03, 0x62, 0xc8, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xcc, 0xa1, 0x1c, 0xe4, + 0xa1, 0x1c, 0xdc, 0x61, 0x1c, 0xca, 0x21, 0x1c, 0xc4, 0x81, 0x1d, 0xca, + 0x61, 0x06, 0xd6, 0x90, 0x43, 0x39, 0xc8, 0x43, 0x39, 0x98, 0x43, 0x39, + 0xc8, 0x43, 0x39, 0xb8, 0xc3, 0x38, 0x94, 0x43, 0x38, 0x88, 0x03, 0x3b, + 0x94, 0xc3, 0x2f, 0xbc, 0x83, 0x3c, 0xfc, 0x82, 0x3b, 0xd4, 0x03, 0x3b, + 0xb0, 0xc3, 0x0c, 0xc7, 0x69, 0x87, 0x70, 0x58, 0x87, 0x72, 0x70, 0x83, + 0x74, 0x68, 0x07, 0x78, 0x60, 0x87, 0x74, 0x18, 0x87, 0x74, 0xa0, 0x87, + 0x19, 0xce, 0x53, 0x0f, 0xee, 0x00, 0x0f, 0xf2, 0x50, 0x0e, 0xe4, 0x90, + 0x0e, 0xe3, 0x40, 0x0f, 0xe1, 0x20, 0x0e, 0xec, 0x50, 0x0e, 0x33, 0x20, + 0x28, 0x1d, 0xdc, 0xc1, 0x1e, 0xc2, 0x41, 0x1e, 0xd2, 0x21, 0x1c, 0xdc, + 0x81, 0x1e, 0xdc, 0xe0, 0x1c, 0xe4, 0xe1, 0x1d, 0xea, 0x01, 0x1e, 0x66, + 0x18, 0x51, 0x38, 0xb0, 0x43, 0x3a, 0x9c, 0x83, 0x3b, 0xcc, 0x50, 0x24, + 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x60, 0x87, 0x77, 0x78, 0x07, + 0x78, 0x98, 0x51, 0x4c, 0xf4, 0x90, 0x0f, 0xf0, 0x50, 0x0e, 0x33, 0x1e, + 0x6a, 0x1e, 0xca, 0x61, 0x1c, 0xe8, 0x21, 0x1d, 0xde, 0xc1, 0x1d, 0x7e, + 0x01, 0x1e, 0xe4, 0xa1, 0x1c, 0xcc, 0x21, 0x1d, 0xf0, 0x61, 0x06, 0x54, + 0x85, 0x83, 0x38, 0xcc, 0xc3, 0x3b, 0xb0, 0x43, 0x3d, 0xd0, 0x43, 0x39, + 0xfc, 0xc2, 0x3c, 0xe4, 0x43, 0x3b, 0x88, 0xc3, 0x3b, 0xb0, 0xc3, 0x8c, + 0xc5, 0x0a, 0x87, 0x79, 0x98, 0x87, 0x77, 0x18, 0x87, 0x74, 0x08, 0x07, + 0x7a, 0x28, 0x07, 0x72, 0x98, 0x81, 0x5c, 0xe3, 0x10, 0x0e, 0xec, 0xc0, + 0x0e, 0xe5, 0x50, 0x0e, 0xf3, 0x30, 0x23, 0xc1, 0xd2, 0x41, 0x1e, 0xe4, + 0xe1, 0x17, 0xd8, 0xe1, 0x1d, 0xde, 0x01, 0x1e, 0x66, 0x48, 0x19, 0x3b, + 0xb0, 0x83, 0x3d, 0xb4, 0x83, 0x1b, 0x84, 0xc3, 0x38, 0x8c, 0x43, 0x39, + 0xcc, 0xc3, 0x3c, 0xb8, 0xc1, 0x39, 0xc8, 0xc3, 0x3b, 0xd4, 0x03, 0x3c, + 0xcc, 0x48, 0xb4, 0x71, 0x08, 0x07, 0x76, 0x60, 0x07, 0x71, 0x08, 0x87, + 0x71, 0x58, 0x87, 0x19, 0xdb, 0xc6, 0x0e, 0xec, 0x60, 0x0f, 0xed, 0xe0, + 0x06, 0xf0, 0x20, 0x0f, 0xe5, 0x30, 0x0f, 0xe5, 0x20, 0x0f, 0xf6, 0x50, + 0x0e, 0x6e, 0x10, 0x0e, 0xe3, 0x30, 0x0e, 0xe5, 0x30, 0x0f, 0xf3, 0xe0, + 0x06, 0xe9, 0xe0, 0x0e, 0xe4, 0x50, 0x0e, 0xf8, 0x30, 0x23, 0xe2, 0xec, + 0x61, 0x1c, 0xc2, 0x81, 0x1d, 0xd8, 0xe1, 0x17, 0xec, 0x21, 0x1d, 0xe6, + 0x21, 0x1d, 0xc4, 0x21, 0x1d, 0xd8, 0x21, 0x1d, 0xe8, 0x21, 0x1f, 0x66, + 0x20, 0x9d, 0x3b, 0xbc, 0x43, 0x3d, 0xb8, 0x03, 0x39, 0x94, 0x83, 0x39, + 0xcc, 0x58, 0xbc, 0x70, 0x70, 0x07, 0x77, 0x78, 0x07, 0x7a, 0x08, 0x07, + 0x7a, 0x48, 0x87, 0x77, 0x70, 0x87, 0x19, 0xcb, 0xe7, 0x0e, 0xef, 0x30, + 0x0f, 0xe1, 0xe0, 0x0e, 0xe9, 0x40, 0x0f, 0xe9, 0xa0, 0x0f, 0xe5, 0x30, + 0xc3, 0x01, 0x03, 0x73, 0xa8, 0x07, 0x77, 0x18, 0x87, 0x5f, 0x98, 0x87, + 0x70, 0x70, 0x87, 0x74, 0xa0, 0x87, 0x74, 0xd0, 0x87, 0x72, 0x98, 0x81, + 0x84, 0x41, 0x39, 0xe0, 0xc3, 0x38, 0xb0, 0x43, 0x3d, 0x90, 0x43, 0x39, + 0xcc, 0x40, 0xc4, 0xa0, 0x1d, 0xca, 0xa1, 0x1d, 0xe0, 0x41, 0x1e, 0xde, + 0xc1, 0x1c, 0x66, 0x24, 0x63, 0x30, 0x0e, 0xe1, 0xc0, 0x0e, 0xec, 0x30, + 0x0f, 0xe9, 0x40, 0x0f, 0xe5, 0x30, 0x43, 0x21, 0x83, 0x75, 0x18, 0x07, + 0x73, 0x48, 0x87, 0x5f, 0xa0, 0x87, 0x7c, 0x80, 0x87, 0x72, 0x98, 0xb1, + 0x94, 0x01, 0x3c, 0x8c, 0xc3, 0x3c, 0x94, 0xc3, 0x38, 0xd0, 0x43, 0x3a, + 0xbc, 0x83, 0x3b, 0xcc, 0xc3, 0x8c, 0xc5, 0x0c, 0x48, 0x21, 0x15, 0x42, + 0x61, 0x1e, 0xe6, 0x21, 0x1d, 0xce, 0xc1, 0x1d, 0x52, 0x81, 0x14, 0x00, + 0x79, 0x20, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x72, 0x1e, 0x48, 0x20, + 0x43, 0x88, 0x0c, 0x19, 0x09, 0x72, 0x32, 0x48, 0x20, 0x23, 0x81, 0x8c, + 0x91, 0x91, 0xd1, 0x44, 0xa0, 0x10, 0x28, 0x64, 0x3c, 0x31, 0x32, 0x23, + 0x08, 0x44, 0x30, 0x82, 0x70, 0x08, 0x23, 0x08, 0x02, 0x30, 0x82, 0x80, + 0x0c, 0x23, 0x08, 0x0e, 0x31, 0x82, 0x00, 0x15, 0x33, 0x10, 0x81, 0x30, + 0x10, 0x33, 0x08, 0x85, 0x21, 0x23, 0x81, 0x09, 0x42, 0xa1, 0x8d, 0x6c, + 0x94, 0xc0, 0xc0, 0xa1, 0x8d, 0x4c, 0x66, 0x94, 0xe0, 0x00, 0x00, 0x00, + 0xa9, 0x18, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x0b, 0x0a, 0x72, 0x28, + 0x87, 0x77, 0x80, 0x07, 0x7a, 0x58, 0x70, 0x98, 0x43, 0x3d, 0xb8, 0xc3, + 0x38, 0xb0, 0x43, 0x39, 0xd0, 0xc3, 0x82, 0xe6, 0x1c, 0xc6, 0xa1, 0x0d, + 0xe8, 0x41, 0x1e, 0xc2, 0xc1, 0x1d, 0xe6, 0x21, 0x1d, 0xe8, 0x21, 0x1d, + 0xde, 0xc1, 0x1d, 0x16, 0x34, 0xe3, 0x60, 0x0e, 0xe7, 0x50, 0x0f, 0xe1, + 0x20, 0x0f, 0xe4, 0x40, 0x0f, 0xe1, 0x20, 0x0f, 0xe7, 0x50, 0x0e, 0xf4, + 0xb0, 0x80, 0x81, 0x07, 0x79, 0x28, 0x87, 0x70, 0x60, 0x07, 0x76, 0x78, + 0x87, 0x71, 0x08, 0x07, 0x7a, 0x28, 0x07, 0x72, 0x58, 0x70, 0x9c, 0xc3, + 0x38, 0xb4, 0x01, 0x3b, 0xa4, 0x83, 0x3d, 0x94, 0xc3, 0x02, 0x6b, 0x1c, + 0xd8, 0x21, 0x1c, 0xdc, 0xe1, 0x1c, 0xdc, 0x20, 0x1c, 0xe4, 0x61, 0x1c, + 0xdc, 0x20, 0x1c, 0xe8, 0x81, 0x1e, 0xc2, 0x61, 0x1c, 0xd0, 0xa1, 0x1c, + 0xc8, 0x61, 0x1c, 0xc2, 0x81, 0x1d, 0xd8, 0x61, 0xc1, 0x01, 0x0f, 0xf4, + 0x20, 0x0f, 0xe1, 0x50, 0x0f, 0xf4, 0x80, 0x0e, 0x0b, 0x88, 0x75, 0x18, + 0x07, 0x73, 0x48, 0x07, 0x00, 0x00, 0x00, 0x00, 0xd1, 0x10, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x07, 0xcc, 0x3c, 0xa4, 0x83, 0x3b, 0x9c, 0x03, + 0x3b, 0x94, 0x03, 0x3d, 0xa0, 0x83, 0x3c, 0x94, 0x43, 0x38, 0x90, 0xc3, + 0x01, 0x00, 0x00, 0x00, 0x71, 0x20, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x32, 0x0e, 0x10, 0x22, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x5d, 0x0c, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x12, 0x03, 0x94, 0x7d, + 0x00, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x31, 0x36, 0x2e, 0x30, + 0x2e, 0x30, 0x67, 0x69, 0x74, 0x20, 0x61, 0x63, 0x37, 0x38, 0x39, 0x33, + 0x66, 0x64, 0x39, 0x63, 0x39, 0x36, 0x35, 0x63, 0x35, 0x30, 0x36, 0x34, + 0x38, 0x63, 0x36, 0x33, 0x63, 0x30, 0x37, 0x35, 0x34, 0x35, 0x36, 0x31, + 0x35, 0x32, 0x65, 0x64, 0x35, 0x31, 0x38, 0x36, 0x39, 0x30, 0x3c, 0x73, + 0x74, 0x64, 0x69, 0x6e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + +#endif