diff options
author | Sebastian Neubauer <Sebastian.Neubauer@amd.com> | 2023-01-18 13:19:59 +0100 |
---|---|---|
committer | Sebastian Neubauer <Sebastian.Neubauer@amd.com> | 2023-01-18 13:20:15 +0100 |
commit | c33b9395b1dfe9f8506062c05c658f6541f6163d (patch) | |
tree | 983297dfb4e3ea52b0f3b5005dc0f3f42d05df1f /llvm/lib/IRReader | |
parent | f615de7e266813518237b7d5b24ac53d1eec6b3c (diff) | |
download | llvm-c33b9395b1dfe9f8506062c05c658f6541f6163d.zip llvm-c33b9395b1dfe9f8506062c05c658f6541f6163d.tar.gz llvm-c33b9395b1dfe9f8506062c05c658f6541f6163d.tar.bz2 |
[BitcodeReader] Allow reading pointer types from old IR
When opaque pointers are enabled and old IR with typed pointers is read,
the BitcodeReader automatically upgrades all typed pointers to opaque
pointers. This is a lossy conversion, i.e. when a function argument is a
pointer and unused, it’s impossible to reconstruct the original type
behind the pointer.
There are cases where the type information of pointers is needed. One is
reading DXIL, which is bitcode of old LLVM IR and makes a lot of use of
pointers in function signatures.
We’d like to keep using up-to-date llvm to read in and process DXIL, so
in the face of opaque pointers, we need some way to access the type
information of pointers from the read bitcode.
This patch allows extracting type information by supplying functions to
parseBitcodeFile that get called for each function signature or metadata
value. The function can access the type information via the reader’s
type IDs and the getTypeByID and getContainedTypeID functions.
The tests exemplarily shows how type info from pointers can be stored in
metadata for use after the BitcodeReader finished.
Differential Revision: https://reviews.llvm.org/D127728
Diffstat (limited to 'llvm/lib/IRReader')
-rw-r--r-- | llvm/lib/IRReader/IRReader.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/llvm/lib/IRReader/IRReader.cpp b/llvm/lib/IRReader/IRReader.cpp index 7765c3f..7885c36 100644 --- a/llvm/lib/IRReader/IRReader.cpp +++ b/llvm/lib/IRReader/IRReader.cpp @@ -68,14 +68,14 @@ std::unique_ptr<Module> llvm::getLazyIRFileModule(StringRef Filename, std::unique_ptr<Module> 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<std::unique_ptr<Module>> 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 @@ std::unique_ptr<Module> llvm::parseIR(MemoryBufferRef Buffer, SMDiagnostic &Err, 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<Module> -llvm::parseIRFile(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, - DataLayoutCallbackTy DataLayoutCallback) { +std::unique_ptr<Module> llvm::parseIRFile(StringRef Filename, SMDiagnostic &Err, + LLVMContext &Context, + ParserCallbacks Callbacks) { ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr = MemoryBuffer::getFileOrSTDIN(Filename, /*IsText=*/true); if (std::error_code EC = FileOrErr.getError()) { @@ -100,8 +102,7 @@ llvm::parseIRFile(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, return nullptr; } - return parseIR(FileOrErr.get()->getMemBufferRef(), Err, Context, - DataLayoutCallback); + return parseIR(FileOrErr.get()->getMemBufferRef(), Err, Context, Callbacks); } //===----------------------------------------------------------------------===// |