1 //===- IPO/OpenMPOpt.h - Collection of OpenMP optimizations -----*- 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 #ifndef LLVM_TRANSFORMS_IPO_OPENMPOPT_H 10 #define LLVM_TRANSFORMS_IPO_OPENMPOPT_H 11 12 #include "llvm/Analysis/CGSCCPassManager.h" 13 #include "llvm/Analysis/LazyCallGraph.h" 14 #include "llvm/IR/PassManager.h" 15 16 namespace llvm { 17 18 namespace omp { 19 20 /// Summary of a kernel (=entry point for target offloading). 21 using Kernel = Function *; 22 23 /// Set of kernels in the module 24 using KernelSet = SetVector<Kernel>; 25 26 /// Helper to determine if \p M contains OpenMP. 27 bool containsOpenMP(Module &M); 28 29 /// Helper to determine if \p M is a OpenMP target offloading device module. 30 bool isOpenMPDevice(Module &M); 31 32 /// Get OpenMP device kernels in \p M. 33 KernelSet getDeviceKernels(Module &M); 34 35 } // namespace omp 36 37 /// OpenMP optimizations pass. 38 class OpenMPOptPass : public PassInfoMixin<OpenMPOptPass> { 39 public: OpenMPOptPass()40 OpenMPOptPass() : LTOPhase(ThinOrFullLTOPhase::None) {} OpenMPOptPass(ThinOrFullLTOPhase LTOPhase)41 OpenMPOptPass(ThinOrFullLTOPhase LTOPhase) : LTOPhase(LTOPhase) {} 42 43 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); 44 45 private: 46 const ThinOrFullLTOPhase LTOPhase = ThinOrFullLTOPhase::None; 47 }; 48 49 class OpenMPOptCGSCCPass : public PassInfoMixin<OpenMPOptCGSCCPass> { 50 public: OpenMPOptCGSCCPass()51 OpenMPOptCGSCCPass() : LTOPhase(ThinOrFullLTOPhase::None) {} OpenMPOptCGSCCPass(ThinOrFullLTOPhase LTOPhase)52 OpenMPOptCGSCCPass(ThinOrFullLTOPhase LTOPhase) : LTOPhase(LTOPhase) {} 53 54 PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, 55 LazyCallGraph &CG, CGSCCUpdateResult &UR); 56 57 private: 58 const ThinOrFullLTOPhase LTOPhase = ThinOrFullLTOPhase::None; 59 }; 60 61 } // end namespace llvm 62 63 #endif // LLVM_TRANSFORMS_IPO_OPENMPOPT_H 64