mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-29 21:16:06 +00:00

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. Differential Revision: https://reviews.llvm.org/D140985
36 lines
1.3 KiB
LLVM
36 lines
1.3 KiB
LLVM
; RUN: llvm-as %s -o - | llvm-dis - | FileCheck %s -check-prefixes CHECK,PROG-AS0
|
|
; RUN: llvm-as -data-layout "P200" %s -o - | llvm-dis | FileCheck %s -check-prefixes CHECK,PROG-AS200
|
|
; RUN: not llvm-as -data-layout "P123456789" %s -o /dev/null 2>&1 | FileCheck %s -check-prefix BAD-DATALAYOUT
|
|
; BAD-DATALAYOUT: error: Invalid address space, must be a 24-bit integer
|
|
|
|
; PROG-AS0-NOT: target datalayout
|
|
; PROG-AS200: target datalayout = "P200"
|
|
|
|
; Check that a function declaration without an address space (i.e. AS0) does not
|
|
; have the addrspace() attribute printed if it is address space zero and it is
|
|
; equal to the program address space.
|
|
|
|
; PROG-AS0: define void @no_as() {
|
|
; PROG-AS200: define void @no_as() addrspace(200) {
|
|
define void @no_as() {
|
|
ret void
|
|
}
|
|
|
|
; A function with an explicit addrspace should only have the addrspace printed
|
|
; if it is non-zero or if the module has a nonzero datalayout
|
|
; PROG-AS0: define void @explit_as0() {
|
|
; PROG-AS200: define void @explit_as0() addrspace(0) {
|
|
define void @explit_as0() addrspace(0) {
|
|
ret void
|
|
}
|
|
|
|
; CHECK: define void @explit_as200() addrspace(200) {
|
|
define void @explit_as200() addrspace(200) {
|
|
ret void
|
|
}
|
|
|
|
; CHECK: define void @explicit_as3() addrspace(3) {
|
|
define void @explicit_as3() addrspace(3) {
|
|
ret void
|
|
}
|