1 //===- OptReductionPass.h - Optimization Reduction Pass Wrapper -*- 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 // This file defines the Opt Reduction Pass Wrapper. It creates a MLIR pass to 10 // run any optimization pass within it and only replaces the output module with 11 // the transformed version if it is smaller and interesting. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef MLIR_REDUCER_OPTREDUCTIONPASS_H 16 #define MLIR_REDUCER_OPTREDUCTIONPASS_H 17 18 #include "PassDetail.h" 19 #include "mlir/Pass/Pass.h" 20 #include "mlir/Pass/PassManager.h" 21 #include "mlir/Reducer/ReductionNode.h" 22 #include "mlir/Reducer/ReductionTreePass.h" 23 #include "mlir/Reducer/Tester.h" 24 #include "mlir/Transforms/Passes.h" 25 #include "llvm/Support/Debug.h" 26 27 namespace mlir { 28 29 class OptReductionPass : public OptReductionBase<OptReductionPass> { 30 public: 31 OptReductionPass(const Tester &test, MLIRContext *context, 32 std::unique_ptr<Pass> optPass); 33 34 OptReductionPass(const OptReductionPass &srcPass); 35 36 /// Runs the pass instance in the pass pipeline. 37 void runOnOperation() override; 38 39 private: 40 // Points to the context to be used in the pass manager. 41 MLIRContext *context; 42 43 // This is used to test the interesting behavior of the transformed module. 44 const Tester &test; 45 46 // Points to the mlir-opt pass to be called. 47 std::unique_ptr<Pass> optPass; 48 }; 49 50 } // end namespace mlir 51 52 #endif 53