1 //===- OptUtils.h - MLIR Execution Engine opt pass utilities ----*- 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 declares the utility functions to trigger LLVM optimizations from 10 // MLIR Execution Engine. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef MLIR_EXECUTIONENGINE_OPTUTILS_H_ 15 #define MLIR_EXECUTIONENGINE_OPTUTILS_H_ 16 17 #include "llvm/Pass.h" 18 19 #include <functional> 20 #include <string> 21 22 namespace llvm { 23 class Module; 24 class Error; 25 class TargetMachine; 26 } // namespace llvm 27 28 namespace mlir { 29 30 /// Initialize LLVM passes that can be used when running MLIR code using 31 /// ExecutionEngine. 32 void initializeLLVMPasses(); 33 34 /// Create a module transformer function for MLIR ExecutionEngine that runs 35 /// LLVM IR passes corresponding to the given speed and size optimization 36 /// levels (e.g. -O2 or -Os). If not null, `targetMachine` is used to 37 /// initialize passes that provide target-specific information to the LLVM 38 /// optimizer. `targetMachine` must outlive the returned std::function. 39 std::function<llvm::Error(llvm::Module *)> 40 makeOptimizingTransformer(unsigned optLevel, unsigned sizeLevel, 41 llvm::TargetMachine *targetMachine); 42 43 /// Create a module transformer function for MLIR ExecutionEngine that runs 44 /// LLVM IR passes explicitly specified, plus an optional optimization level, 45 /// Any optimization passes, if present, will be inserted before the pass at 46 /// position optPassesInsertPos. If not null, `targetMachine` is used to 47 /// initialize passes that provide target-specific information to the LLVM 48 /// optimizer. `targetMachine` must outlive the returned std::function. 49 std::function<llvm::Error(llvm::Module *)> 50 makeLLVMPassesTransformer(llvm::ArrayRef<const llvm::PassInfo *> llvmPasses, 51 llvm::Optional<unsigned> mbOptLevel, 52 llvm::TargetMachine *targetMachine, 53 unsigned optPassesInsertPos = 0); 54 55 } // end namespace mlir 56 57 #endif // LIR_EXECUTIONENGINE_OPTUTILS_H_ 58