|
| 1 | +// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -Wno-sycl-2017-compat -ast-dump %s | FileCheck %s |
| 2 | + |
| 3 | +// Add AST tests for Loop attributes: [[intel::enable_loop_pipelining]], |
| 4 | +// [[intel::max_interleaving()]], [[intel::loop_coalesce]], |
| 5 | +// [[intel::max_concurrency()]], [[intel::initiation_interval()]], |
| 6 | +// and [[intel::speculated_iterations()]]. |
| 7 | + |
| 8 | +#include "sycl.hpp" |
| 9 | + |
| 10 | +using namespace sycl; |
| 11 | +queue q; |
| 12 | + |
| 13 | +void fpga_enable_loop_pipelining() { |
| 14 | + int a1[10], a2[10]; |
| 15 | + // CHECK: AttributedStmt |
| 16 | + // CHECK-NEXT: SYCLIntelEnableLoopPipeliningAttr |
| 17 | + [[intel::enable_loop_pipelining]] for (int p = 0; p < 10; ++p) { |
| 18 | + a1[p] = a2[p] = 0; |
| 19 | + } |
| 20 | + |
| 21 | + // CHECK: AttributedStmt |
| 22 | + // CHECK-NEXT: SYCLIntelEnableLoopPipeliningAttr |
| 23 | + int i = 0; |
| 24 | + [[intel::enable_loop_pipelining]] while (i < 10) { |
| 25 | + a1[i] += 3; |
| 26 | + } |
| 27 | + |
| 28 | + // CHECK: AttributedStmt |
| 29 | + // CHECK-NEXT: SYCLIntelEnableLoopPipeliningAttr |
| 30 | + for (int i = 0; i < 10; ++i) { |
| 31 | + [[intel::enable_loop_pipelining]] for (int j = 0; j < 10; ++j) { |
| 32 | + a1[i] += a1[j]; |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + // CHECK: AttributedStmt |
| 37 | + // CHECK-NEXT: SYCLIntelEnableLoopPipeliningAttr |
| 38 | + int b = 10; |
| 39 | + [[intel::enable_loop_pipelining]] do { |
| 40 | + b = b + 1; |
| 41 | + } while (b < 20); |
| 42 | + |
| 43 | + // CHECK: AttributedStmt |
| 44 | + // CHECK-NEXT: SYCLIntelEnableLoopPipeliningAttr |
| 45 | + int c[] = {0, 1, 2, 3, 4, 5}; |
| 46 | + [[intel::enable_loop_pipelining]] for (int n : c) { n *= 2; } |
| 47 | +} |
| 48 | + |
| 49 | +void fpga_max_concurrency() { |
| 50 | + int a1[10], a2[10]; |
| 51 | + // CHECK: AttributedStmt |
| 52 | + // CHECK-NEXT: SYCLIntelMaxConcurrencyAttr |
| 53 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 54 | + // CHECK-NEXT: value: Int 0 |
| 55 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 0 |
| 56 | + [[intel::max_concurrency(0)]] for (int p = 0; p < 10; ++p) { |
| 57 | + a1[p] = a2[p] = 0; |
| 58 | + } |
| 59 | + |
| 60 | + // CHECK: AttributedStmt |
| 61 | + // CHECK-NEXT: SYCLIntelMaxConcurrencyAttr |
| 62 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 63 | + // CHECK-NEXT: value: Int 4 |
| 64 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 4 |
| 65 | + int i = 0; |
| 66 | + [[intel::max_concurrency(4)]] while (i < 10) { |
| 67 | + a1[i] += 3; |
| 68 | + } |
| 69 | + |
| 70 | + // CHECK: AttributedStmt |
| 71 | + // CHECK-NEXT: SYCLIntelMaxConcurrencyAttr |
| 72 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 73 | + // CHECK-NEXT: value: Int 8 |
| 74 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 8 |
| 75 | + for (int i = 0; i < 10; ++i) { |
| 76 | + [[intel::max_concurrency(8)]] for (int j = 0; j < 10; ++j) { |
| 77 | + a1[i] += a1[j]; |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + // CHECK: AttributedStmt |
| 82 | + // CHECK-NEXT: SYCLIntelMaxConcurrencyAttr |
| 83 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 84 | + // CHECK-NEXT: value: Int 12 |
| 85 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 12 |
| 86 | + int b = 10; |
| 87 | + [[intel::max_concurrency(12)]] do { |
| 88 | + b = b + 1; |
| 89 | + } while (b < 20); |
| 90 | + |
| 91 | + // CHECK: AttributedStmt |
| 92 | + // CHECK-NEXT: SYCLIntelMaxConcurrencyAttr |
| 93 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 94 | + // CHECK-NEXT: value: Int 16 |
| 95 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 16 |
| 96 | + int c[] = {0, 1, 2, 3, 4, 5}; |
| 97 | + [[intel::max_concurrency(16)]] for (int n : c) { n *= 2; } |
| 98 | +} |
| 99 | + |
| 100 | +void fpga_max_interleaving() { |
| 101 | + int a1[10], a2[10]; |
| 102 | + // CHECK: AttributedStmt |
| 103 | + // CHECK-NEXT: SYCLIntelMaxInterleavingAttr |
| 104 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 105 | + // CHECK-NEXT: value: Int 0 |
| 106 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 0 |
| 107 | + [[intel::max_interleaving(0)]] for (int p = 0; p < 10; ++p) { |
| 108 | + a1[p] = a2[p] = 0; |
| 109 | + } |
| 110 | + |
| 111 | + // CHECK: AttributedStmt |
| 112 | + // CHECK-NEXT: SYCLIntelMaxInterleavingAttr |
| 113 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 114 | + // CHECK-NEXT: value: Int 1 |
| 115 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1 |
| 116 | + int i = 0; |
| 117 | + [[intel::max_interleaving(1)]] while (i < 10) { |
| 118 | + a1[i] += 3; |
| 119 | + } |
| 120 | + |
| 121 | + // CHECK: AttributedStmt |
| 122 | + // CHECK-NEXT: SYCLIntelMaxInterleavingAttr |
| 123 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 124 | + // CHECK-NEXT: value: Int 1 |
| 125 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1 |
| 126 | + for (int i = 0; i < 10; ++i) { |
| 127 | + [[intel::max_interleaving(1)]] for (int j = 0; j < 10; ++j) { |
| 128 | + a1[i] += a1[j]; |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + // CHECK: AttributedStmt |
| 133 | + // CHECK-NEXT: SYCLIntelMaxInterleavingAttr |
| 134 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 135 | + // CHECK-NEXT: value: Int 0 |
| 136 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 0 |
| 137 | + int b = 10; |
| 138 | + [[intel::max_interleaving(0)]] do { |
| 139 | + b = b + 1; |
| 140 | + } while (b < 20); |
| 141 | + |
| 142 | + // CHECK: AttributedStmt |
| 143 | + // CHECK-NEXT: SYCLIntelMaxInterleavingAttr |
| 144 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 145 | + // CHECK-NEXT: value: Int 1 |
| 146 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1 |
| 147 | + int c[] = {0, 1, 2, 3, 4, 5}; |
| 148 | + [[intel::max_interleaving(1)]] for (int n : c) { n *= 2; } |
| 149 | +} |
| 150 | + |
| 151 | +void fpga_speculated_iterations() { |
| 152 | + int a1[10], a2[10]; |
| 153 | + // CHECK: AttributedStmt |
| 154 | + // CHECK-NEXT: SYCLIntelSpeculatedIterationsAttr |
| 155 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 156 | + // CHECK-NEXT: value: Int 0 |
| 157 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 0 |
| 158 | + [[intel::speculated_iterations(0)]] for (int p = 0; p < 10; ++p) { |
| 159 | + a1[p] = a2[p] = 0; |
| 160 | + } |
| 161 | + |
| 162 | + // CHECK: AttributedStmt |
| 163 | + // CHECK-NEXT: SYCLIntelSpeculatedIterationsAttr |
| 164 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 165 | + // CHECK-NEXT: value: Int 12 |
| 166 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 12 |
| 167 | + int i = 0; |
| 168 | + [[intel::speculated_iterations(12)]] while (i < 10) { |
| 169 | + a1[i] += 3; |
| 170 | + } |
| 171 | + |
| 172 | + // CHECK: AttributedStmt |
| 173 | + // CHECK-NEXT: SYCLIntelSpeculatedIterationsAttr |
| 174 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 175 | + // CHECK-NEXT: value: Int 16 |
| 176 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 16 |
| 177 | + for (int i = 0; i < 10; ++i) { |
| 178 | + [[intel::speculated_iterations(16)]] for (int j = 0; j < 10; ++j) { |
| 179 | + a1[i] += a1[j]; |
| 180 | + } |
| 181 | + } |
| 182 | + |
| 183 | + // CHECK: AttributedStmt |
| 184 | + // CHECK-NEXT: SYCLIntelSpeculatedIterationsAttr |
| 185 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 186 | + // CHECK-NEXT: value: Int 8 |
| 187 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 8 |
| 188 | + int b = 10; |
| 189 | + [[intel::speculated_iterations(8)]] do { |
| 190 | + b = b + 1; |
| 191 | + } while (b < 20); |
| 192 | + |
| 193 | + // CHECK: AttributedStmt |
| 194 | + // CHECK-NEXT: SYCLIntelSpeculatedIterationsAttr |
| 195 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 196 | + // CHECK-NEXT: value: Int 22 |
| 197 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 22 |
| 198 | + int c[] = {0, 1, 2, 3, 4, 5}; |
| 199 | + [[intel::speculated_iterations(22)]] for (int n : c) { n *= 2; } |
| 200 | +} |
| 201 | + |
| 202 | +void fpga_initiation_interval() { |
| 203 | + int a1[10], a2[10]; |
| 204 | + // CHECK: AttributedStmt |
| 205 | + // CHECK-NEXT: SYCLIntelInitiationIntervalAttr |
| 206 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 207 | + // CHECK-NEXT: value: Int 10 |
| 208 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 10 |
| 209 | + [[intel::initiation_interval(10)]] for (int p = 0; p < 10; ++p) { |
| 210 | + a1[p] = a2[p] = 0; |
| 211 | + } |
| 212 | + |
| 213 | + // CHECK: AttributedStmt |
| 214 | + // CHECK-NEXT: SYCLIntelInitiationIntervalAttr |
| 215 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 216 | + // CHECK-NEXT: value: Int 12 |
| 217 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 12 |
| 218 | + int i = 0; |
| 219 | + [[intel::initiation_interval(12)]] while (i < 10) { |
| 220 | + a1[i] += 3; |
| 221 | + } |
| 222 | + |
| 223 | + // CHECK: AttributedStmt |
| 224 | + // CHECK-NEXT: SYCLIntelInitiationIntervalAttr |
| 225 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 226 | + // CHECK-NEXT: value: Int 16 |
| 227 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 16 |
| 228 | + for (int i = 0; i < 10; ++i) { |
| 229 | + [[intel::initiation_interval(16)]] for (int j = 0; j < 10; ++j) { |
| 230 | + a1[i] += a1[j]; |
| 231 | + } |
| 232 | + } |
| 233 | + |
| 234 | + // CHECK: AttributedStmt |
| 235 | + // CHECK-NEXT: SYCLIntelInitiationIntervalAttr |
| 236 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 237 | + // CHECK-NEXT: value: Int 8 |
| 238 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 8 |
| 239 | + int b = 10; |
| 240 | + [[intel::initiation_interval(8)]] do { |
| 241 | + b = b + 1; |
| 242 | + } while (b < 20); |
| 243 | + |
| 244 | + // CHECK: AttributedStmt |
| 245 | + // CHECK-NEXT: SYCLIntelInitiationIntervalAttr |
| 246 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 247 | + // CHECK-NEXT: value: Int 22 |
| 248 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 22 |
| 249 | + int c[] = {0, 1, 2, 3, 4, 5}; |
| 250 | + [[intel::initiation_interval(22)]] for (int n : c) { n *= 2; } |
| 251 | +} |
| 252 | + |
| 253 | +void fpga_loop_coalesce() { |
| 254 | + int a1[10], a2[10]; |
| 255 | + // CHECK: AttributedStmt |
| 256 | + // CHECK-NEXT: SYCLIntelLoopCoalesceAttr |
| 257 | + [[intel::loop_coalesce]] for (int p = 0; p < 10; ++p) { |
| 258 | + a1[p] = a2[p] = 0; |
| 259 | + } |
| 260 | + |
| 261 | + // CHECK: AttributedStmt |
| 262 | + // CHECK-NEXT: SYCLIntelLoopCoalesceAttr |
| 263 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 264 | + // CHECK-NEXT: value: Int 12 |
| 265 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 12 |
| 266 | + int i = 0; |
| 267 | + [[intel::loop_coalesce(12)]] while (i < 10) { |
| 268 | + a1[i] += 3; |
| 269 | + } |
| 270 | + |
| 271 | + // CHECK: AttributedStmt |
| 272 | + // CHECK-NEXT: SYCLIntelLoopCoalesceAttr |
| 273 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 274 | + // CHECK-NEXT: value: Int 16 |
| 275 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 16 |
| 276 | + for (int i = 0; i < 10; ++i) { |
| 277 | + [[intel::loop_coalesce(16)]] for (int j = 0; j < 10; ++j) { |
| 278 | + a1[i] += a1[j]; |
| 279 | + } |
| 280 | + } |
| 281 | + |
| 282 | + // CHECK: AttributedStmt |
| 283 | + // CHECK-NEXT: SYCLIntelLoopCoalesceAttr |
| 284 | + int b = 10; |
| 285 | + [[intel::loop_coalesce]] do { |
| 286 | + b = b + 1; |
| 287 | + } while (b < 20); |
| 288 | + |
| 289 | + // CHECK: AttributedStmt |
| 290 | + // CHECK-NEXT: SYCLIntelLoopCoalesceAttr |
| 291 | + // CHECK-NEXT: ConstantExpr{{.*}}'int' |
| 292 | + // CHECK-NEXT: value: Int 22 |
| 293 | + // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 22 |
| 294 | + int c[] = {0, 1, 2, 3, 4, 5}; |
| 295 | + [[intel::loop_coalesce(22)]] for (int n : c) { n *= 2; } |
| 296 | +} |
| 297 | + |
| 298 | +void foo() { |
| 299 | + q.submit([&](handler &h) { |
| 300 | + h.single_task<class kernel_function>([]() { |
| 301 | + fpga_enable_loop_pipelining(); |
| 302 | + fpga_max_concurrency(); |
| 303 | + fpga_max_interleaving(); |
| 304 | + fpga_speculated_iterations(); |
| 305 | + fpga_initiation_interval(); |
| 306 | + fpga_loop_coalesce(); |
| 307 | + }); |
| 308 | + }); |
| 309 | +} |
0 commit comments