xref: /llvm-project/mlir/test/Target/LLVMIR/attribute-alias-scopes.mlir (revision 29441e4f5fa5f5c7709f7cf180815ba97f611297)
1// RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
2
3llvm.func @foo(%arg0: !llvm.ptr)
4
5#alias_scope_domain = #llvm.alias_scope_domain<id = distinct[0]<>, description = "The domain">
6#alias_scope1 = #llvm.alias_scope<id = distinct[1]<>, domain = #alias_scope_domain, description = "The first scope">
7#alias_scope2 = #llvm.alias_scope<id = distinct[2]<>, domain = #alias_scope_domain>
8#alias_scope3 = #llvm.alias_scope<id = distinct[3]<>, domain = #alias_scope_domain>
9
10// CHECK-LABEL: @alias_scopes
11llvm.func @alias_scopes(%arg1 : !llvm.ptr) {
12  %0 = llvm.mlir.constant(0 : i32) : i32
13  // CHECK:  call void @llvm.experimental.noalias.scope.decl(metadata ![[SCOPES1:[0-9]+]])
14  llvm.intr.experimental.noalias.scope.decl #alias_scope1
15  // CHECK:  store {{.*}}, !alias.scope ![[SCOPES1]], !noalias ![[SCOPES23:[0-9]+]]
16  llvm.store %0, %arg1 {alias_scopes = [#alias_scope1], noalias_scopes = [#alias_scope2, #alias_scope3]} : i32, !llvm.ptr
17  // CHECK:  load {{.*}}, !alias.scope ![[SCOPES2:[0-9]+]], !noalias ![[SCOPES13:[0-9]+]]
18  %1 = llvm.load %arg1 {alias_scopes = [#alias_scope2], noalias_scopes = [#alias_scope1, #alias_scope3]} : !llvm.ptr -> i32
19  // CHECK:  atomicrmw {{.*}}, !alias.scope ![[SCOPES3:[0-9]+]], !noalias ![[SCOPES12:[0-9]+]]
20  %2 = llvm.atomicrmw add %arg1, %0 monotonic {alias_scopes = [#alias_scope3], noalias_scopes = [#alias_scope1, #alias_scope2]} : !llvm.ptr, i32
21  // CHECK:  cmpxchg {{.*}}, !alias.scope ![[SCOPES3]]
22  %3 = llvm.cmpxchg %arg1, %1, %2 acq_rel monotonic {alias_scopes = [#alias_scope3]} : !llvm.ptr, i32
23  %5 = llvm.mlir.constant(42 : i8) : i8
24  // CHECK:  llvm.memcpy{{.*}}, !alias.scope ![[SCOPES3]]
25  "llvm.intr.memcpy"(%arg1, %arg1, %0) <{isVolatile = false}> {alias_scopes = [#alias_scope3]} : (!llvm.ptr, !llvm.ptr, i32) -> ()
26  // CHECK:  llvm.memset{{.*}}, !noalias ![[SCOPES3]]
27  "llvm.intr.memset"(%arg1, %5, %0) <{isVolatile = false}> {noalias_scopes = [#alias_scope3]} : (!llvm.ptr, i8, i32) -> ()
28  // CHECK: call void @foo({{.*}} !alias.scope ![[SCOPES3]]
29  llvm.call @foo(%arg1) {alias_scopes = [#alias_scope3]} : (!llvm.ptr) -> ()
30  // CHECK: call void @foo({{.*}} !noalias ![[SCOPES3]]
31  llvm.call @foo(%arg1) {noalias_scopes = [#alias_scope3]} : (!llvm.ptr) -> ()
32  llvm.return
33}
34
35// Check the intrinsic declarations.
36// CHECK-DAG: declare void @llvm.experimental.noalias.scope.decl(metadata)
37// CHECK-DAG: declare void @llvm.memcpy.p0.p0.i32(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i32, i1 immarg)
38// CHECK-DAG: declare void @llvm.memset.p0.i32(ptr writeonly captures(none), i8, i32, i1 immarg)
39
40// Check the translated metadata.
41// CHECK-DAG: ![[DOMAIN:[0-9]+]] = distinct !{![[DOMAIN]], !"The domain"}
42// CHECK-DAG: ![[SCOPE1:[0-9]+]] = distinct !{![[SCOPE1]], ![[DOMAIN]], !"The first scope"}
43// CHECK-DAG: ![[SCOPE2:[0-9]+]] = distinct !{![[SCOPE2]], ![[DOMAIN]]}
44// CHECK-DAG: ![[SCOPE3:[0-9]+]] = distinct !{![[SCOPE3]], ![[DOMAIN]]}
45// CHECK-DAG: ![[SCOPES1]] = !{![[SCOPE1]]}
46// CHECK-DAG: ![[SCOPES2]] = !{![[SCOPE2]]}
47// CHECK-DAG: ![[SCOPES3]] = !{![[SCOPE3]]}
48// CHECK-DAG: ![[SCOPES12]] = !{![[SCOPE1]], ![[SCOPE2]]}
49// CHECK-DAG: ![[SCOPES13]] = !{![[SCOPE1]], ![[SCOPE3]]}
50// CHECK-DAG: ![[SCOPES23]] = !{![[SCOPE2]], ![[SCOPE3]]}
51
52// -----
53
54// This test verifies the noalias scope intrinsice can be translated in
55// isolation. It is the only operation using alias scopes attributes without
56// implementing AliasAnalysisOpInterface.
57
58#alias_scope_domain = #llvm.alias_scope_domain<id = distinct[0]<>, description = "The domain">
59#alias_scope1 = #llvm.alias_scope<id = distinct[1]<>, domain = #alias_scope_domain>
60
61// CHECK-LABEL: @noalias_intr_only
62llvm.func @noalias_intr_only() {
63  // CHECK: call void @llvm.experimental.noalias.scope.decl(metadata ![[SCOPES:[0-9]+]])
64  llvm.intr.experimental.noalias.scope.decl #alias_scope1
65  llvm.return
66}
67
68// Check the translated metadata.
69// CHECK-DAG: ![[DOMAIN:[0-9]+]] = distinct !{![[DOMAIN]], !"The domain"}
70// CHECK-DAG: ![[SCOPE:[0-9]+]] = distinct !{![[SCOPE]], ![[DOMAIN]]}
71// CHECK-DAG: ![[SCOPES]] = !{![[SCOPE]]}
72
73// -----
74
75// This test ensures the alias scope translation creates a temporary metadata
76// node as a placeholder for self-references. Without this, the debug info
77// translation of a type list with a null entry could inadvertently reference
78// access group metadata. This occurs when both translations generate a metadata
79// list with a null entry, which are then uniqued to the same metadata node.
80// The access group translation subsequently updates the null entry to a
81// self-reference, which causes the type list to reference the access
82// group node as well. The use of a temporary placeholder node avoids the issue.
83
84#alias_scope_domain = #llvm.alias_scope_domain<id = distinct[0]<>>
85#alias_scope = #llvm.alias_scope<id = distinct[1]<>, domain = #alias_scope_domain>
86
87#di_null_type = #llvm.di_null_type
88#di_subroutine_type = #llvm.di_subroutine_type<types = #di_null_type>
89#di_file = #llvm.di_file<"attribute-alias-scope.mlir" in "">
90#di_compile_unit = #llvm.di_compile_unit<id = distinct[3]<>, sourceLanguage = DW_LANG_C11, file = #di_file, isOptimized = true, emissionKind = Full>
91#di_subprogram = #llvm.di_subprogram<id = distinct[2]<>, compileUnit = #di_compile_unit, scope = #di_file, file = #di_file, subprogramFlags = "Definition", type = #di_subroutine_type>
92
93// CHECK-LABEL: @self_reference
94llvm.func @self_reference() {
95  // CHECK: call void @llvm.experimental.noalias.scope.decl(metadata ![[SCOPES:[0-9]+]])
96  llvm.intr.experimental.noalias.scope.decl #alias_scope
97  llvm.return
98} loc(fused<#di_subprogram>[unknown])
99
100// Check that the translated subroutine types do not reference the access group
101// domain since both of them are created as metadata list with a null entry.
102// CHECK-DAG: ![[DOMAIN:[0-9]+]] = distinct !{![[DOMAIN]]}
103// CHECK-DAG: ![[SCOPE:[0-9]+]] = distinct !{![[SCOPE]], ![[DOMAIN]]}
104// CHECK-DAG: ![[SCOPES]] = !{![[SCOPE]]}
105// CHECK-DAG: = !DISubroutineType(types: ![[TYPES:[0-9]+]])
106// CHECK-DAG: ![[TYPES]] = !{null}
107
108// -----
109
110llvm.func @foo(%arg0: !llvm.ptr)
111
112#alias_scope_domain = #llvm.alias_scope_domain<id = "domain1", description = "The domain">
113#alias_scope1 = #llvm.alias_scope<id = "scope1", domain = #alias_scope_domain, description = "The first scope">
114#alias_scope2 = #llvm.alias_scope<id = "scope2", domain = #alias_scope_domain>
115#alias_scope3 = #llvm.alias_scope<id = "scope3", domain = #alias_scope_domain>
116
117// CHECK-LABEL: @alias_scopes
118llvm.func @alias_scopes(%arg1 : !llvm.ptr) {
119  %0 = llvm.mlir.constant(0 : i32) : i32
120  // CHECK:  call void @llvm.experimental.noalias.scope.decl(metadata ![[SCOPES1:[0-9]+]])
121  llvm.intr.experimental.noalias.scope.decl #alias_scope1
122  // CHECK:  store {{.*}}, !alias.scope ![[SCOPES1]], !noalias ![[SCOPES23:[0-9]+]]
123  llvm.store %0, %arg1 {alias_scopes = [#alias_scope1], noalias_scopes = [#alias_scope2, #alias_scope3]} : i32, !llvm.ptr
124  // CHECK:  load {{.*}}, !alias.scope ![[SCOPES2:[0-9]+]], !noalias ![[SCOPES13:[0-9]+]]
125  %1 = llvm.load %arg1 {alias_scopes = [#alias_scope2], noalias_scopes = [#alias_scope1, #alias_scope3]} : !llvm.ptr -> i32
126  // CHECK:  atomicrmw {{.*}}, !alias.scope ![[SCOPES3:[0-9]+]], !noalias ![[SCOPES12:[0-9]+]]
127  %2 = llvm.atomicrmw add %arg1, %0 monotonic {alias_scopes = [#alias_scope3], noalias_scopes = [#alias_scope1, #alias_scope2]} : !llvm.ptr, i32
128  // CHECK:  cmpxchg {{.*}}, !alias.scope ![[SCOPES3]]
129  %3 = llvm.cmpxchg %arg1, %1, %2 acq_rel monotonic {alias_scopes = [#alias_scope3]} : !llvm.ptr, i32
130  %5 = llvm.mlir.constant(42 : i8) : i8
131  // CHECK:  llvm.memcpy{{.*}}, !alias.scope ![[SCOPES3]]
132  "llvm.intr.memcpy"(%arg1, %arg1, %0) <{isVolatile = false}> {alias_scopes = [#alias_scope3]} : (!llvm.ptr, !llvm.ptr, i32) -> ()
133  // CHECK:  llvm.memset{{.*}}, !noalias ![[SCOPES3]]
134  "llvm.intr.memset"(%arg1, %5, %0) <{isVolatile = false}> {noalias_scopes = [#alias_scope3]} : (!llvm.ptr, i8, i32) -> ()
135  // CHECK: call void @foo({{.*}} !alias.scope ![[SCOPES3]]
136  llvm.call @foo(%arg1) {alias_scopes = [#alias_scope3]} : (!llvm.ptr) -> ()
137  // CHECK: call void @foo({{.*}} !noalias ![[SCOPES3]]
138  llvm.call @foo(%arg1) {noalias_scopes = [#alias_scope3]} : (!llvm.ptr) -> ()
139  llvm.return
140}
141
142// Check the intrinsic declarations.
143// CHECK-DAG: declare void @llvm.experimental.noalias.scope.decl(metadata)
144// CHECK-DAG: declare void @llvm.memcpy.p0.p0.i32(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i32, i1 immarg)
145// CHECK-DAG: declare void @llvm.memset.p0.i32(ptr writeonly captures(none), i8, i32, i1 immarg)
146
147// Check the translated metadata.
148// CHECK-DAG: ![[DOMAIN:[0-9]+]] = !{!"domain1", !"The domain"}
149// CHECK-DAG: ![[SCOPE1:[0-9]+]] = !{!"scope1", ![[DOMAIN]], !"The first scope"}
150// CHECK-DAG: ![[SCOPE2:[0-9]+]] = !{!"scope2", ![[DOMAIN]]}
151// CHECK-DAG: ![[SCOPE3:[0-9]+]] = !{!"scope3", ![[DOMAIN]]}
152// CHECK-DAG: ![[SCOPES1]] = !{![[SCOPE1]]}
153// CHECK-DAG: ![[SCOPES2]] = !{![[SCOPE2]]}
154// CHECK-DAG: ![[SCOPES3]] = !{![[SCOPE3]]}
155// CHECK-DAG: ![[SCOPES12]] = !{![[SCOPE1]], ![[SCOPE2]]}
156// CHECK-DAG: ![[SCOPES13]] = !{![[SCOPE1]], ![[SCOPE3]]}
157// CHECK-DAG: ![[SCOPES23]] = !{![[SCOPE2]], ![[SCOPE3]]}
158