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