1 //===- Bufferize.cpp - scf bufferize pass ---------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "mlir/Transforms/Bufferize.h" 10 #include "PassDetail.h" 11 #include "mlir/Dialect/MemRef/IR/MemRef.h" 12 #include "mlir/Dialect/SCF/Passes.h" 13 #include "mlir/Dialect/SCF/SCF.h" 14 #include "mlir/Dialect/SCF/Transforms.h" 15 #include "mlir/Dialect/StandardOps/IR/Ops.h" 16 #include "mlir/Transforms/DialectConversion.h" 17 18 using namespace mlir; 19 using namespace mlir::scf; 20 21 namespace { 22 struct SCFBufferizePass : public SCFBufferizeBase<SCFBufferizePass> { 23 void runOnFunction() override { 24 auto func = getOperation(); 25 auto *context = &getContext(); 26 27 BufferizeTypeConverter typeConverter; 28 RewritePatternSet patterns(context); 29 ConversionTarget target(*context); 30 31 populateBufferizeMaterializationLegality(target); 32 populateSCFStructuralTypeConversionsAndLegality(typeConverter, patterns, 33 target); 34 if (failed(applyPartialConversion(func, target, std::move(patterns)))) 35 return signalPassFailure(); 36 }; 37 }; 38 } // end anonymous namespace 39 40 std::unique_ptr<Pass> mlir::createSCFBufferizePass() { 41 return std::make_unique<SCFBufferizePass>(); 42 } 43