14
14
#include " mlir/Analysis/NestedMatcher.h"
15
15
#include " mlir/Analysis/SliceAnalysis.h"
16
16
#include " mlir/Dialect/Affine/IR/AffineOps.h"
17
+ #include " mlir/Dialect/Affine/Utils.h"
17
18
#include " mlir/Dialect/Vector/VectorOps.h"
18
19
#include " mlir/Dialect/Vector/VectorUtils.h"
19
20
#include " mlir/IR/Builders.h"
20
21
#include " mlir/IR/Diagnostics.h"
21
22
#include " mlir/IR/StandardTypes.h"
22
23
#include " mlir/Pass/Pass.h"
24
+ #include " mlir/Transforms/LoopUtils.h"
23
25
#include " mlir/Transforms/Passes.h"
24
26
25
27
#include " llvm/ADT/STLExtras.h"
@@ -67,6 +69,12 @@ static llvm::cl::opt<bool> clTestNormalizeMaps(
67
69
" where each AffineAffineApplyOp in the composition is a single output "
68
70
" operation." ),
69
71
llvm::cl::cat(clOptionsCategory));
72
+ static llvm::cl::opt<bool > clTestVecAffineLoopNest (
73
+ " vectorize-affine-loop-nest" ,
74
+ llvm::cl::desc (
75
+ " Enable testing for the 'vectorizeAffineLoopNest' utility by "
76
+ " vectorizing the outermost loops found" ),
77
+ llvm::cl::cat(clOptionsCategory));
70
78
71
79
namespace {
72
80
struct VectorizerTestPass
@@ -84,6 +92,9 @@ struct VectorizerTestPass
84
92
void testSlicing (llvm::raw_ostream &outs);
85
93
void testComposeMaps (llvm::raw_ostream &outs);
86
94
void testNormalizeMaps ();
95
+
96
+ // / Test for 'vectorizeAffineLoopNest' utility.
97
+ void testVecAffineLoopNest ();
87
98
};
88
99
89
100
} // end anonymous namespace
@@ -246,10 +257,26 @@ void VectorizerTestPass::testNormalizeMaps() {
246
257
}
247
258
}
248
259
249
- void VectorizerTestPass::runOnFunction () {
250
- // Thread-safe RAII local context, BumpPtrAllocator freed on exit.
251
- NestedPatternContext mlContext;
260
+ // / Test for 'vectorizeAffineLoopNest' utility.
261
+ void VectorizerTestPass::testVecAffineLoopNest () {
262
+ std::vector<SmallVector<AffineForOp, 2 >> loops;
263
+ gatherLoops (getFunction (), loops);
264
+
265
+ // Expected only one loop nest.
266
+ if (loops.empty () || loops[0 ].size () != 1 )
267
+ return ;
252
268
269
+ // We vectorize the outermost loop found with VF=4.
270
+ AffineForOp outermostLoop = loops[0 ][0 ];
271
+ VectorizationStrategy strategy;
272
+ strategy.vectorSizes .push_back (4 /* vectorization factor*/ );
273
+ strategy.loopToVectorDim [outermostLoop] = 0 ;
274
+ std::vector<SmallVector<AffineForOp, 2 >> loopsToVectorize;
275
+ loopsToVectorize.push_back ({outermostLoop});
276
+ vectorizeAffineLoopNest (loopsToVectorize, strategy);
277
+ }
278
+
279
+ void VectorizerTestPass::runOnFunction () {
253
280
// Only support single block functions at this point.
254
281
FuncOp f = getFunction ();
255
282
if (!llvm::hasSingleElement (f))
@@ -258,23 +285,30 @@ void VectorizerTestPass::runOnFunction() {
258
285
std::string str;
259
286
llvm::raw_string_ostream outs (str);
260
287
261
- if (!clTestVectorShapeRatio. empty ())
262
- testVectorShapeRatio (outs) ;
288
+ { // Tests that expect a NestedPatternContext to be allocated externally.
289
+ NestedPatternContext mlContext ;
263
290
264
- if (clTestForwardSlicingAnalysis )
265
- testForwardSlicing (outs);
291
+ if (!clTestVectorShapeRatio. empty () )
292
+ testVectorShapeRatio (outs);
266
293
267
- if (clTestBackwardSlicingAnalysis )
268
- testBackwardSlicing (outs);
294
+ if (clTestForwardSlicingAnalysis )
295
+ testForwardSlicing (outs);
269
296
270
- if (clTestSlicingAnalysis )
271
- testSlicing (outs);
297
+ if (clTestBackwardSlicingAnalysis )
298
+ testBackwardSlicing (outs);
272
299
273
- if (clTestComposeMaps)
274
- testComposeMaps (outs);
300
+ if (clTestSlicingAnalysis)
301
+ testSlicing (outs);
302
+
303
+ if (clTestComposeMaps)
304
+ testComposeMaps (outs);
305
+
306
+ if (clTestNormalizeMaps)
307
+ testNormalizeMaps ();
308
+ }
275
309
276
- if (clTestNormalizeMaps )
277
- testNormalizeMaps ();
310
+ if (clTestVecAffineLoopNest )
311
+ testVecAffineLoopNest ();
278
312
279
313
if (!outs.str ().empty ()) {
280
314
emitRemark (UnknownLoc::get (&getContext ()), outs.str ());
0 commit comments