1 //====----- Bufferize.cpp - Bufferization of shape ops ---------*- C++-*--===// 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/Shape/Transforms/Passes.h" 13 #include "mlir/Pass/Pass.h" 14 15 using namespace mlir; 16 17 namespace { 18 struct ShapeBufferizePass : public ShapeBufferizeBase<ShapeBufferizePass> { 19 void runOnFunction() override { 20 MLIRContext &ctx = getContext(); 21 22 RewritePatternSet patterns(&ctx); 23 BufferizeTypeConverter typeConverter; 24 ConversionTarget target(ctx); 25 26 populateBufferizeMaterializationLegality(target); 27 populateShapeStructuralTypeConversionsAndLegality(typeConverter, patterns, 28 target); 29 30 if (failed( 31 applyPartialConversion(getFunction(), target, std::move(patterns)))) 32 signalPassFailure(); 33 } 34 }; 35 } // namespace 36 37 std::unique_ptr<FunctionPass> mlir::createShapeBufferizePass() { 38 return std::make_unique<ShapeBufferizePass>(); 39 } 40