File: sroa.mlir

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (154 lines) | stat: -rw-r--r-- 6,077 bytes parent folder | download | duplicates (2)
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
// 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_bounds
// CHECK-SAME: (%[[ARG0:.*]]: i32, %[[ARG1:.*]]: i32)
func.func @no_out_of_bounds(%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
}