File: sroa.mlir

package info (click to toggle)
swiftlang 6.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,604 kB
  • sloc: cpp: 9,901,740; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (175 lines) | stat: -rw-r--r-- 6,889 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// RUN: mlir-opt %s --pass-pipeline="builtin.module(func.func(sroa))" --split-input-file | FileCheck %s

// CHECK-LABEL: func.func @basic
// CHECK-SAME: (%[[ARG0:.*]]: i32, %[[ARG1:.*]]: i32)
func.func @basic(%arg0: i32, %arg1: i32) -> i32 {
  %c0 = arith.constant 0 : index
  %c1 = arith.constant 1 : index
  // CHECK-NOT: = memref.alloca()
  // CHECK-COUNT-2: = memref.alloca() : memref<i32>
  // CHECK-NOT: = memref.alloca()
  %alloca = memref.alloca() : memref<2xi32>
  // CHECK: memref.store %[[ARG0]], %[[ALLOCA0:.*]][]
  memref.store %arg0, %alloca[%c0] : memref<2xi32>
  // CHECK: memref.store %[[ARG1]], %[[ALLOCA1:.*]][]
  memref.store %arg1, %alloca[%c1] : memref<2xi32>
  // CHECK: %[[RES:.*]] = memref.load %[[ALLOCA0]][]
  %res = memref.load %alloca[%c0] : memref<2xi32>
  // CHECK: return %[[RES]] : i32
  return %res : i32
}

// -----

// CHECK-LABEL: func.func @basic_high_dimensions
// CHECK-SAME: (%[[ARG0:.*]]: i32, %[[ARG1:.*]]: i32, %[[ARG2:.*]]: i32)
func.func @basic_high_dimensions(%arg0: i32, %arg1: i32, %arg2: i32) -> i32 {
  %c0 = arith.constant 0 : index
  %c1 = arith.constant 1 : index
  // CHECK-NOT: = memref.alloca()
  // CHECK-COUNT-3: = memref.alloca() : memref<i32>
  // CHECK-NOT: = memref.alloca()
  %alloca = memref.alloca() : memref<2x2xi32>
  // CHECK: memref.store %[[ARG0]], %[[ALLOCA0:.*]][]
  memref.store %arg0, %alloca[%c0, %c0] : memref<2x2xi32>
  // CHECK: memref.store %[[ARG1]], %[[ALLOCA1:.*]][]
  memref.store %arg1, %alloca[%c0, %c1] : memref<2x2xi32>
  // CHECK: memref.store %[[ARG2]], %[[ALLOCA2:.*]][]
  memref.store %arg2, %alloca[%c1, %c0] : memref<2x2xi32>
  // CHECK: %[[RES:.*]] = memref.load %[[ALLOCA1]][]
  %res = memref.load %alloca[%c0, %c1] : memref<2x2xi32>
  // CHECK: return %[[RES]] : i32
  return %res : i32
}

// -----

// CHECK-LABEL: func.func @resolve_alias
// CHECK-SAME: (%[[ARG0:.*]]: i32, %[[ARG1:.*]]: i32)
func.func @resolve_alias(%arg0: i32, %arg1: i32) -> i32 {
  %c0 = arith.constant 0 : index
  // CHECK-NOT: = memref.alloca()
  // CHECK: %[[ALLOCA:.*]] = memref.alloca() : memref<i32>
  // CHECK-NOT: = memref.alloca()
  %alloca = memref.alloca() : memref<2xi32>
  // CHECK: memref.store %[[ARG0]], %[[ALLOCA]][]
  memref.store %arg0, %alloca[%c0] : memref<2xi32>
  // CHECK: memref.store %[[ARG1]], %[[ALLOCA]][]
  memref.store %arg1, %alloca[%c0] : memref<2xi32>
  // CHECK: %[[RES:.*]] = memref.load %[[ALLOCA]][]
  %res = memref.load %alloca[%c0] : memref<2xi32>
  // CHECK: return %[[RES]] : i32
  return %res : i32
}

// -----

// CHECK-LABEL: func.func @no_direct_use
// CHECK-SAME: (%[[ARG0:.*]]: i32, %[[ARG1:.*]]: i32)
func.func @no_direct_use(%arg0: i32, %arg1: i32) -> i32 {
  // CHECK: %[[C0:.*]] = arith.constant 0 : index
  %c0 = arith.constant 0 : index
  // CHECK: %[[C1:.*]] = arith.constant 1 : index
  %c1 = arith.constant 1 : index
  // CHECK-NOT: = memref.alloca()
  // CHECK: %[[ALLOCA:.*]] = memref.alloca() : memref<2xi32>
  // CHECK-NOT: = memref.alloca()
  %alloca = memref.alloca() : memref<2xi32>
  // CHECK: memref.store %[[ARG0]], %[[ALLOCA]][%[[C0]]]
  memref.store %arg0, %alloca[%c0] : memref<2xi32>
  // CHECK: memref.store %[[ARG1]], %[[ALLOCA]][%[[C1]]]
  memref.store %arg1, %alloca[%c1] : memref<2xi32>
  // CHECK: %[[RES:.*]] = memref.load %[[ALLOCA]][%[[C0]]]
  %res = memref.load %alloca[%c0] : memref<2xi32>
  call @use(%alloca) : (memref<2xi32>) -> ()
  // CHECK: return %[[RES]] : i32
  return %res : i32
}

func.func @use(%foo: memref<2xi32>) { return }

// -----

// CHECK-LABEL: func.func @no_dynamic_indexing
// CHECK-SAME: (%[[ARG0:.*]]: i32, %[[ARG1:.*]]: i32, %[[INDEX:.*]]: index)
func.func @no_dynamic_indexing(%arg0: i32, %arg1: i32, %index: index) -> i32 {
  // CHECK: %[[C0:.*]] = arith.constant 0 : index
  %c0 = arith.constant 0 : index
  // CHECK-NOT: = memref.alloca()
  // CHECK: %[[ALLOCA:.*]] = memref.alloca() : memref<2xi32>
  // CHECK-NOT: = memref.alloca()
  %alloca = memref.alloca() : memref<2xi32>
  // CHECK: memref.store %[[ARG0]], %[[ALLOCA]][%[[C0]]]
  memref.store %arg0, %alloca[%c0] : memref<2xi32>
  // CHECK: memref.store %[[ARG1]], %[[ALLOCA]][%[[INDEX]]]
  memref.store %arg1, %alloca[%index] : memref<2xi32>
  // CHECK: %[[RES:.*]] = memref.load %[[ALLOCA]][%[[C0]]]
  %res = memref.load %alloca[%c0] : memref<2xi32>
  // CHECK: return %[[RES]] : i32
  return %res : i32
}

// -----

// CHECK-LABEL: func.func @no_dynamic_shape
// CHECK-SAME: (%[[ARG0:.*]]: i32, %[[ARG1:.*]]: i32)
func.func @no_dynamic_shape(%arg0: i32, %arg1: i32) -> i32 {
  // CHECK: %[[C0:.*]] = arith.constant 0 : index
  %c0 = arith.constant 0 : index
  // CHECK: %[[C1:.*]] = arith.constant 1 : index
  %c1 = arith.constant 1 : index
  // CHECK-NOT: = memref.alloca()
  // CHECK: %[[ALLOCA:.*]] = memref.alloca(%[[C1]]) : memref<?x2xi32>
  // CHECK-NOT: = memref.alloca()
  %alloca = memref.alloca(%c1) : memref<?x2xi32>
  // CHECK: memref.store %[[ARG0]], %[[ALLOCA]][%[[C0]], %[[C0]]]
  memref.store %arg0, %alloca[%c0, %c0] : memref<?x2xi32>
  // CHECK: %[[RES:.*]] = memref.load %[[ALLOCA]][%[[C0]], %[[C0]]]
  %res = memref.load %alloca[%c0, %c0] : memref<?x2xi32>
  // CHECK: return %[[RES]] : i32
  return %res : i32
}

// -----

// CHECK-LABEL: func.func @no_out_of_bound_write
// CHECK-SAME: (%[[ARG0:.*]]: i32, %[[ARG1:.*]]: i32)
func.func @no_out_of_bound_write(%arg0: i32, %arg1: i32) -> i32 {
  // CHECK: %[[C0:.*]] = arith.constant 0 : index
  %c0 = arith.constant 0 : index
  // CHECK: %[[C100:.*]] = arith.constant 100 : index
  %c100 = arith.constant 100 : index
  // CHECK-NOT: = memref.alloca()
  // CHECK: %[[ALLOCA:.*]] = memref.alloca() : memref<2xi32>
  // CHECK-NOT: = memref.alloca()
  %alloca = memref.alloca() : memref<2xi32>
  // CHECK: memref.store %[[ARG0]], %[[ALLOCA]][%[[C0]]]
  memref.store %arg0, %alloca[%c0] : memref<2xi32>
  // CHECK: memref.store %[[ARG1]], %[[ALLOCA]][%[[C100]]]
  memref.store %arg1, %alloca[%c100] : memref<2xi32>
  // CHECK: %[[RES:.*]] = memref.load %[[ALLOCA]][%[[C0]]]
  %res = memref.load %alloca[%c0] : memref<2xi32>
  // CHECK: return %[[RES]] : i32
  return %res : i32
}

// -----

// CHECK-LABEL: func.func @no_out_of_bound_load
// CHECK-SAME: (%[[ARG0:.*]]: i32, %[[ARG1:.*]]: i32)
func.func @no_out_of_bound_load(%arg0: i32, %arg1: i32) -> i32 {
  // CHECK: %[[C0:.*]] = arith.constant 0 : index
  %c0 = arith.constant 0 : index
  // CHECK: %[[C100:.*]] = arith.constant 100 : index
  %c100 = arith.constant 100 : index
  // CHECK-NOT: = memref.alloca()
  // CHECK: %[[ALLOCA:.*]] = memref.alloca() : memref<2xi32>
  // CHECK-NOT: = memref.alloca()
  %alloca = memref.alloca() : memref<2xi32>
  // CHECK: memref.store %[[ARG0]], %[[ALLOCA]][%[[C0]]]
  memref.store %arg0, %alloca[%c0] : memref<2xi32>
  // CHECK: %[[RES:.*]] = memref.load %[[ALLOCA]][%[[C100]]]
  %res = memref.load %alloca[%c100] : memref<2xi32>
  // CHECK: return %[[RES]] : i32
  return %res : i32
}