1b1357fe6SThomas Raoux //===- TestComposeSubView.cpp - Test composed subviews --------------------===//
2b1357fe6SThomas Raoux //
3b1357fe6SThomas Raoux // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4b1357fe6SThomas Raoux // See https://llvm.org/LICENSE.txt for license information.
5b1357fe6SThomas Raoux // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6b1357fe6SThomas Raoux //
7b1357fe6SThomas Raoux //===----------------------------------------------------------------------===//
8b1357fe6SThomas Raoux 
9b1357fe6SThomas Raoux #include "mlir/Dialect/Affine/IR/AffineOps.h"
10b1357fe6SThomas Raoux #include "mlir/Dialect/MemRef/Transforms/Passes.h"
11b1357fe6SThomas Raoux 
12b1357fe6SThomas Raoux #include "mlir/Dialect/MemRef/IR/MemRef.h"
13b1357fe6SThomas Raoux #include "mlir/Pass/Pass.h"
14b1357fe6SThomas Raoux 
15b1357fe6SThomas Raoux using namespace mlir;
16b1357fe6SThomas Raoux 
17b1357fe6SThomas Raoux namespace {
18b1357fe6SThomas Raoux struct TestMultiBufferingPass
1987d6bf37SRiver Riddle     : public PassWrapper<TestMultiBufferingPass, OperationPass<>> {
20*5e50dd04SRiver Riddle   MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestMultiBufferingPass)
21*5e50dd04SRiver Riddle 
22b1357fe6SThomas Raoux   TestMultiBufferingPass() = default;
TestMultiBufferingPass__anon483ac33d0111::TestMultiBufferingPass23b1357fe6SThomas Raoux   TestMultiBufferingPass(const TestMultiBufferingPass &pass)
24b1357fe6SThomas Raoux       : PassWrapper(pass) {}
getDependentDialects__anon483ac33d0111::TestMultiBufferingPass25b1357fe6SThomas Raoux   void getDependentDialects(DialectRegistry &registry) const override {
26b1357fe6SThomas Raoux     registry.insert<AffineDialect>();
27b1357fe6SThomas Raoux   }
getArgument__anon483ac33d0111::TestMultiBufferingPass28b1357fe6SThomas Raoux   StringRef getArgument() const final { return "test-multi-buffering"; }
getDescription__anon483ac33d0111::TestMultiBufferingPass29b1357fe6SThomas Raoux   StringRef getDescription() const final {
30b1357fe6SThomas Raoux     return "Test multi buffering transformation";
31b1357fe6SThomas Raoux   }
32b1357fe6SThomas Raoux   void runOnOperation() override;
33b1357fe6SThomas Raoux   Option<unsigned> multiplier{
34b1357fe6SThomas Raoux       *this, "multiplier",
35b1357fe6SThomas Raoux       llvm::cl::desc(
36b1357fe6SThomas Raoux           "Decide how many versions of the buffer should be created,"),
37b1357fe6SThomas Raoux       llvm::cl::init(2)};
38b1357fe6SThomas Raoux };
39b1357fe6SThomas Raoux 
runOnOperation()40b1357fe6SThomas Raoux void TestMultiBufferingPass::runOnOperation() {
41b1357fe6SThomas Raoux   SmallVector<memref::AllocOp> allocs;
4287d6bf37SRiver Riddle   getOperation()->walk(
43b1357fe6SThomas Raoux       [&allocs](memref::AllocOp alloc) { allocs.push_back(alloc); });
44b1357fe6SThomas Raoux   for (memref::AllocOp alloc : allocs)
45b1357fe6SThomas Raoux     (void)multiBuffer(alloc, multiplier);
46b1357fe6SThomas Raoux }
47b1357fe6SThomas Raoux } // namespace
48b1357fe6SThomas Raoux 
49b1357fe6SThomas Raoux namespace mlir {
50b1357fe6SThomas Raoux namespace test {
registerTestMultiBuffering()51b1357fe6SThomas Raoux void registerTestMultiBuffering() {
52b1357fe6SThomas Raoux   PassRegistration<TestMultiBufferingPass>();
53b1357fe6SThomas Raoux }
54b1357fe6SThomas Raoux } // namespace test
55b1357fe6SThomas Raoux } // namespace mlir
56