Fabian Mora 2b8f887915
[mlir][Ptr] Add the MemorySpaceAttrInterface interface and dependencies. (#86870)
This patch introduces the `MemorySpaceAttrInterface` interface. This
interface is responsible for handling the semantics of `ptr` operations.

For example, this interface can be used to create read-only memory
spaces, making any other operation other than a load a verification
error, see `TestConstMemorySpaceAttr` for a possible implementation of
this concept.

This patch also introduces Enum dependencies `AtomicOrdering`, and
`AtomicBinOp`, both enumerations are clones of the Enums with the same
name in the LLVM Dialect.

Also, see:
- [[RFC] `ptr` dialect & modularizing ptr ops in the LLVM
dialect](https://discourse.llvm.org/t/rfc-ptr-dialect-modularizing-ptr-ops-in-the-llvm-dialect/75142)
for rationale.
- https://github.com/llvm/llvm-project/pull/73057 for a prototype
implementation of the full change.

**Note: Ignore the first commit, that's being reviewed in
https://github.com/llvm/llvm-project/pull/86860 .**
2025-03-19 10:55:24 -04:00

150 lines
5.1 KiB
MLIR

// RUN: mlir-opt --test-data-layout-query --split-input-file --verify-diagnostics %s | FileCheck %s
module attributes { dlti.dl_spec = #dlti.dl_spec<
#dlti.dl_entry<!ptr.ptr<#test.const_memory_space>, #ptr.spec<size = 32, abi = 32, preferred = 64>>,
#dlti.dl_entry<!ptr.ptr<#test.const_memory_space<5>>,#ptr.spec<size = 64, abi = 64, preferred = 64>>,
#dlti.dl_entry<!ptr.ptr<#test.const_memory_space<4>>, #ptr.spec<size = 32, abi = 64, preferred = 64, index = 24>>,
#dlti.dl_entry<"dlti.default_memory_space", #test.const_memory_space<7>>,
#dlti.dl_entry<"dlti.alloca_memory_space", #test.const_memory_space<5>>,
#dlti.dl_entry<"dlti.global_memory_space", #test.const_memory_space<2>>,
#dlti.dl_entry<"dlti.program_memory_space", #test.const_memory_space<3>>,
#dlti.dl_entry<"dlti.stack_alignment", 128 : i64>
>} {
// CHECK-LABEL: @spec
func.func @spec() {
// CHECK: alignment = 4
// CHECK: alloca_memory_space = #test.const_memory_space<5>
// CHECK: bitsize = 32
// CHECK: default_memory_space = #test.const_memory_space<7>
// CHECK: global_memory_space = #test.const_memory_space<2>
// CHECK: index = 32
// CHECK: preferred = 8
// CHECK: program_memory_space = #test.const_memory_space<3>
// CHECK: size = 4
// CHECK: stack_alignment = 128
"test.data_layout_query"() : () -> !ptr.ptr<#test.const_memory_space>
// CHECK: alignment = 1
// CHECK: alloca_memory_space = #test.const_memory_space<5>
// CHECK: bitsize = 64
// CHECK: default_memory_space = #test.const_memory_space<7>
// CHECK: global_memory_space = #test.const_memory_space<2>
// CHECK: index = 64
// CHECK: preferred = 1
// CHECK: program_memory_space = #test.const_memory_space<3>
// CHECK: size = 8
// CHECK: stack_alignment = 128
"test.data_layout_query"() : () -> !ptr.ptr<#test.const_memory_space<3>>
// CHECK: alignment = 8
// CHECK: alloca_memory_space = #test.const_memory_space<5>
// CHECK: bitsize = 64
// CHECK: default_memory_space = #test.const_memory_space<7>
// CHECK: global_memory_space = #test.const_memory_space<2>
// CHECK: index = 64
// CHECK: preferred = 8
// CHECK: program_memory_space = #test.const_memory_space<3>
// CHECK: size = 8
// CHECK: stack_alignment = 128
"test.data_layout_query"() : () -> !ptr.ptr<#test.const_memory_space<5>>
// CHECK: alignment = 8
// CHECK: alloca_memory_space = #test.const_memory_space<5>
// CHECK: bitsize = 32
// CHECK: default_memory_space = #test.const_memory_space<7>
// CHECK: global_memory_space = #test.const_memory_space<2>
// CHECK: index = 24
// CHECK: preferred = 8
// CHECK: program_memory_space = #test.const_memory_space<3>
// CHECK: size = 4
// CHECK: stack_alignment = 128
"test.data_layout_query"() : () -> !ptr.ptr<#test.const_memory_space<4>>
return
}
}
// -----
module attributes { dlti.dl_spec = #dlti.dl_spec<
#dlti.dl_entry<!ptr.ptr<#test.const_memory_space>, #ptr.spec<size = 32, abi = 32, preferred = 32>>,
#dlti.dl_entry<"dlti.default_memory_space", #test.const_memory_space>
>} {
// CHECK-LABEL: @default_memory_space
func.func @default_memory_space() {
// CHECK: alignment = 4
// CHECK: bitsize = 32
// CHECK: index = 32
// CHECK: preferred = 4
// CHECK: size = 4
"test.data_layout_query"() : () -> !ptr.ptr<#test.const_memory_space>
// CHECK: alignment = 4
// CHECK: bitsize = 32
// CHECK: index = 32
// CHECK: preferred = 4
// CHECK: size = 4
"test.data_layout_query"() : () -> !ptr.ptr<#test.const_memory_space<1>>
// CHECK: alignment = 4
// CHECK: bitsize = 32
// CHECK: index = 32
// CHECK: preferred = 4
// CHECK: size = 4
"test.data_layout_query"() : () -> !ptr.ptr<#test.const_memory_space<2>>
return
}
}
// -----
// expected-error@+2 {{preferred alignment is expected to be at least as large as ABI alignment}}
module attributes { dlti.dl_spec = #dlti.dl_spec<
#dlti.dl_entry<!ptr.ptr<#test.const_memory_space>, #ptr.spec<size = 64, abi = 64, preferred = 32>>
>} {
func.func @pointer() {
return
}
}
// -----
// expected-error@+2 {{size entry must be divisible by 8}}
module attributes { dlti.dl_spec = #dlti.dl_spec<
#dlti.dl_entry<!ptr.ptr<#test.const_memory_space>, #ptr.spec<size = 33, abi = 32, preferred = 32>>
>} {
func.func @pointer() {
return
}
}
// -----
// expected-error@+2 {{abi entry must be divisible by 8}}
module attributes { dlti.dl_spec = #dlti.dl_spec<
#dlti.dl_entry<!ptr.ptr<#test.const_memory_space>, #ptr.spec<size = 32, abi = 33, preferred = 64>>
>} {
func.func @pointer() {
return
}
}
// -----
// expected-error@+2 {{preferred entry must be divisible by 8}}
module attributes { dlti.dl_spec = #dlti.dl_spec<
#dlti.dl_entry<!ptr.ptr<#test.const_memory_space>, #ptr.spec<size = 32, abi = 32, preferred = 33>>
>} {
func.func @pointer() {
return
}
}
// -----
// expected-error@+2 {{index entry must be divisible by 8}}
module attributes { dlti.dl_spec = #dlti.dl_spec<
#dlti.dl_entry<!ptr.ptr<#test.const_memory_space>, #ptr.spec<size = 32, abi = 32, preferred = 32, index = 33>>
>} {
func.func @pointer() {
return
}
}