1 // RUN: mlir-opt -split-input-file -pass-pipeline="builtin.module(mlprogram-pipeline-globals)" --allow-unregistered-dialect %s
3 // CHECK-LABEL: @global_variable
4 ml_program.global private mutable @global_variable(dense<4> : tensor<4xi32>) : tensor<4xi32>
6 // CHECK-LABEL: @global_double_load
7 func.func @global_double_load() {
8 // CHECK: %[[LOAD:.+]] = ml_program.global_load @global_variable
9 // CHECK-NOT: ml_program.global_load @global_variable
10 %0 = ml_program.global_load @global_variable : tensor<4xi32>
11 %1 = ml_program.global_load @global_variable : tensor<4xi32>
13 // CHECK: %[[DUMMY:.+]] = "unregistered.dummy"(%[[LOAD]], %[[LOAD]])
14 %2 = "unregistered.dummy"(%0, %1) : (tensor<4xi32>, tensor<4xi32>) -> (tensor<4xi32>)
16 // CHECK: ml_program.global_store @global_variable %[[DUMMY]]
17 ml_program.global_store @global_variable = %2 : tensor<4xi32>
23 // CHECK-LABEL: @global_variable
24 ml_program.global private mutable @global_variable(dense<4> : tensor<4xi32>) : tensor<4xi32>
26 // CHECK-LABEL: @global_double_store
27 func.func @global_double_store() {
28 // CHECK: %[[LOAD:.+]] = ml_program.global_load @global_variable
29 %0 = ml_program.global_load @global_variable : tensor<4xi32>
31 // CHECK: %[[DUMMY:.+]] = "unregistered.dummy"(%[[LOAD]])
32 %1 = "unregistered.dummy"(%0) : (tensor<4xi32>) -> (tensor<4xi32>)
34 // CHECK: ml_program.global_store @global_variable %[[DUMMY]]
35 ml_program.global_store @global_variable = %1 : tensor<4xi32>
37 // CHECK-NOT: ml_program.global_store
38 ml_program.global_store @global_variable = %1 : tensor<4xi32>
44 // CHECK-LABEL: @global_variable
45 ml_program.global private mutable @global_variable(dense<4> : tensor<4xi32>) : tensor<4xi32>
47 // CHECK-LABEL: @global_store_load
48 func.func @global_store_load() {
49 // CHECK: %[[LOAD:.+]] = ml_program.global_load @global_variable
50 %0 = ml_program.global_load @global_variable : tensor<4xi32>
52 // CHECK: %[[DUMMY:.+]] = "unregistered.dummy"(%[[LOAD]])
53 // CHECK: %[[DUMMY2:.+]] = "unregistered.dummy"(%[[DUMMY2]])
54 %1 = "unregistered.dummy"(%0) : (tensor<4xi32>) -> (tensor<4xi32>)
55 ml_program.global_store @global_variable = %1 : tensor<4xi32>
56 %2 = ml_program.global_load @global_variable : tensor<4xi32>
57 %3 = "unregistered.dummy"(%2) : (tensor<4xi32>) -> (tensor<4xi32>)
59 // CHECK: ml_program.global_store @global_variable %[[DUMMY2]]
60 ml_program.global_store @global_variable = %3 : tensor<4xi32>
66 // CHECK-LABEL: @global_variable
67 ml_program.global private mutable @global_variable(dense<4> : tensor<4xi32>) : tensor<4xi32>
69 // CHECK-LABEL: @global_store_load_region
70 func.func @global_store_load_region() {
71 // CHECK: %[[LOAD:.+]] = ml_program.global_load @global_variable
72 %0 = ml_program.global_load @global_variable : tensor<4xi32>
74 // CHECK: %[[DUMMY:.+]] = "unregistered.dummy"(%[[LOAD]])
75 %1 = "unregistered.dummy"(%0) : (tensor<4xi32>) -> (tensor<4xi32>)
77 // CHECK: ml_program.global_store @global_variable %[[DUMMY]]
78 ml_program.global_store @global_variable = %1 : tensor<4xi32>
80 // CHECK: "unregistered.dummy2"
81 "unregistered.dummy2"() ({
83 %cst = arith.constant dense<0> : tensor<4xi32>
84 // CHECK: ml_program.global_store @global_variable
85 ml_program.global_store @global_variable = %cst : tensor<4xi32>
86 "unregistered.terminator"() : () -> ()
89 // CHECK: %[[LOAD:.+]] ml_program.global_load @global_variable
90 %2 = ml_program.global_load @global_variable : tensor<4xi32>
92 // CHECK: %[[DUMMY2:.+]] = "unregistered.dummy"(%[[LOAD]])
93 %3 = "unregistered.dummy"(%2) : (tensor<4xi32>) -> (tensor<4xi32>)
95 // CHECK: ml_program.global_store @global_variable %[[DUMMY2]]
96 ml_program.global_store @global_variable = %3 : tensor<4xi32>
102 // CHECK-LABEL: @global_variable
103 ml_program.global private mutable @global_variable(dense<4> : tensor<4xi32>) : tensor<4xi32>
105 // CHECK-LABEL: @interrupt
106 func.func @interrupt() {
107 %cst = arith.constant dense<0> : tensor<4xi32>
108 // CHECK: ml_program.global_store
109 ml_program.global_store @global_variable = %cst : tensor<4xi32>
113 // CHECK-LABEL: @call_global_store
114 func.func @call_global_store() {
115 // CHECK: %[[LOAD:.+]] = ml_program.global_load @global_variable
116 %0 = ml_program.global_load @global_variable : tensor<4xi32>
118 // CHECK: %[[DUMMY:.+]] = "unregistered.dummy"(%[[LOAD]])
119 %1 = "unregistered.dummy"(%0) : (tensor<4xi32>) -> (tensor<4xi32>)
121 // CHECK: ml_program.global_store @global_variable %[[DUMMY]]
122 ml_program.global_store @global_variable = %1 : tensor<4xi32>
123 call @interrupt() : () -> ()
125 // CHECK: %[[LOAD:.+]] ml_program.global_load @global_variable
126 %2 = ml_program.global_load @global_variable : tensor<4xi32>
128 // CHECK: %[[DUMMY:.+]] = "unregistered.dummy"(%[[LOAD]])
129 %3 = "unregistered.dummy"(%2) : (tensor<4xi32>) -> (tensor<4xi32>)
131 // CHECK: ml_program.global_store @global_variable %[[DUMMY]]
132 ml_program.global_store @global_variable = %3 : tensor<4xi32>
139 // CHECK-LABEL: @global_variable
140 ml_program.global private mutable @global_variable(dense<4> : tensor<4xi32>) : tensor<4xi32>
142 // CHECK-LABEL: @interrupt_indirect
143 func.func @interrupt_indirect() {
144 %cst = arith.constant dense<0> : tensor<4xi32>
145 // CHECK: ml_program.global_store
146 ml_program.global_store @global_variable = %cst : tensor<4xi32>
150 // CHECK-LABEL: @interrupt
151 func.func @interrupt() {
152 call @interrupt_indirect() : () -> ()
156 // CHECK-LABEL: @call_indirect_store
157 func.func @call_indirect_store() {
158 // CHECK: %[[LOAD:.+]] = ml_program.global_load @global_variable
159 %0 = ml_program.global_load @global_variable : tensor<4xi32>
161 // CHECK: %[[DUMMY:.+]] = "unregistered.dummy"(%[[LOAD]])
162 %1 = "unregistered.dummy"(%0) : (tensor<4xi32>) -> (tensor<4xi32>)
164 // CHECK: ml_program.global_store @global_variable %[[DUMMY]]
165 ml_program.global_store @global_variable = %1 : tensor<4xi32>
166 call @interrupt() : () -> ()
168 // CHECK: %[[LOAD:.+]] ml_program.global_load @global_variable
169 %2 = ml_program.global_load @global_variable : tensor<4xi32>
171 // CHECK: %[[DUMMY:.+]] = "unregistered.dummy"(%[[LOAD]])
172 %3 = "unregistered.dummy"(%2) : (tensor<4xi32>) -> (tensor<4xi32>)
174 // CHECK: ml_program.global_store @global_variable %[[DUMMY]]
175 ml_program.global_store @global_variable = %3 : tensor<4xi32>
182 // CHECK-LABEL: @global_variable
183 ml_program.global private mutable @global_variable(dense<4> : tensor<4xi32>) : tensor<4xi32>
185 // CHECK-LABEL: @interrupt_indirect
186 func.func @interrupt_indirect() -> tensor<4xi32> {
187 // CHECK: ml_program.global_load
188 %0 = ml_program.global_load @global_variable : tensor<4xi32>
189 func.return %0 : tensor<4xi32>
192 // CHECK-LABEL: @interrupt
193 func.func @interrupt() {
194 %0 = call @interrupt_indirect() : () -> (tensor<4xi32>)
195 "unregistered.dummy"(%0) : (tensor<4xi32>) -> ()
199 // CHECK-LABEL: @call_indirect_load
200 func.func @call_indirect_load() {
201 // CHECK: %[[LOAD:.+]] = ml_program.global_load @global_variable
202 %0 = ml_program.global_load @global_variable : tensor<4xi32>
204 // CHECK: %[[DUMMY:.+]] = "unregistered.dummy"(%[[LOAD]])
205 %1 = "unregistered.dummy"(%0) : (tensor<4xi32>) -> (tensor<4xi32>)
207 // CHECK: ml_program.global_store @global_variable %[[DUMMY]]
208 ml_program.global_store @global_variable = %1 : tensor<4xi32>
209 call @interrupt() : () -> ()
211 // CHECK: %[[DUMMY:.+]] = "unregistered.dummy"(%[[LOAD]])
212 %2 = ml_program.global_load @global_variable : tensor<4xi32>
213 %3 = "unregistered.dummy"(%2) : (tensor<4xi32>) -> (tensor<4xi32>)
215 // CHECK: ml_program.global_store @global_variable %[[DUMMY]]
216 ml_program.global_store @global_variable = %3 : tensor<4xi32>
222 // CHECK-LABEL: @global_variable
223 ml_program.global private mutable @global_variable(dense<4> : tensor<4xi32>) : tensor<4xi32>
225 // CHECK-LABEL: @call_recursive
226 func.func @call_recursive() {
227 // CHECK: %[[LOAD:.+]] = ml_program.global_load @global_variable
228 %0 = ml_program.global_load @global_variable : tensor<4xi32>
230 // CHECK: %[[DUMMY:.+]] = "unregistered.dummy"(%[[LOAD]])
231 %1 = "unregistered.dummy"(%0) : (tensor<4xi32>) -> (tensor<4xi32>)
233 // CHECK: ml_program.global_store @global_variable %[[DUMMY]]
234 ml_program.global_store @global_variable = %1 : tensor<4xi32>
235 call @call_recursive() : () -> ()
237 // CHECK: %[[LOAD:.+]] ml_program.global_load @global_variable
238 %2 = ml_program.global_load @global_variable : tensor<4xi32>
240 // CHECK: %[[DUMMY:.+]] = "unregistered.dummy"(%[[LOAD]])
241 %3 = "unregistered.dummy"(%2) : (tensor<4xi32>) -> (tensor<4xi32>)
243 // CHECK: ml_program.global_store @global_variable %[[DUMMY]]
244 ml_program.global_store @global_variable = %3 : tensor<4xi32>