[PATCH] D140985: [IR] Support importing modules with invalid data layouts.

Jannik Silvanus via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 4 06:39:21 PST 2023


jsilvanus created this revision.
Herald added subscribers: ormris, hiraditya.
Herald added a project: All.
jsilvanus requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Use the existing mechanism to change the data layout using callbacks.

Before this patch, we had a callback type DataLayoutCallbackTy that receives
a single StringRef specifying the target triple, and optionally returns
the data layout string to be used. Module loaders (both IR and BC) then
apply the callback to potentially override the module's data layout,
after first having imported and parsed the data layout from the file.

We can't do the same to fix invalid data layouts, because the import will already
fail, before the callback has a chance to fix it.
Instead, module loaders now tentatively parse the data layout into a string,
wait until the target triple has been parsed, apply the override callback
to the imported string and only then parse the tentative string as a data layout.

Moreover, add the old data layout string S as second argument to the callback,
in addition to the already existing target triple argument.
S is either the default data layout string in case none is specified, or the data
layout string specified in the module, possibly after auto-upgrades (for the BitcodeReader).
This allows callbacks to inspect the old data layout string,
and fix it instead of setting a fixed data layout.

Also allow to pass data layout override callbacks to lazy bitcode module
loader functions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140985

Files:
  llvm/include/llvm/AsmParser/LLParser.h
  llvm/include/llvm/AsmParser/Parser.h
  llvm/include/llvm/Bitcode/BitcodeReader.h
  llvm/include/llvm/CodeGen/MIRParser/MIRParser.h
  llvm/include/llvm/IRReader/IRReader.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/Parser.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/CodeGen/MIRParser/MIRParser.cpp
  llvm/tools/llc/llc.cpp
  llvm/tools/llvm-as/llvm-as.cpp
  llvm/tools/llvm-reduce/ReducerWorkItem.cpp
  llvm/tools/opt/opt.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140985.486268.patch
Type: text/x-patch
Size: 21706 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230104/940f4efd/attachment.bin>


More information about the llvm-commits mailing list