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 /// Return true iff \p Fn is a GPU kernel; \p Fn has the "kernel" attribute. 33 bool isKernel(Function &Fn); 34 35 /// Get OpenMP device kernels in \p M. 36 KernelSet getDeviceKernels(Module &M); 37 38 } // namespace omp 39 40 /// OpenMP optimizations pass. 41 class OpenMPOptPass : public PassInfoMixin<OpenMPOptPass> { 42 public: 43 OpenMPOptPass() = default; 44 OpenMPOptPass(ThinOrFullLTOPhase LTOPhase) : LTOPhase(LTOPhase) {} 45 46 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); 47 48 private: 49 const ThinOrFullLTOPhase LTOPhase = ThinOrFullLTOPhase::None; 50 }; 51 52 class OpenMPOptCGSCCPass : public PassInfoMixin<OpenMPOptCGSCCPass> { 53 public: 54 OpenMPOptCGSCCPass() = default; 55 OpenMPOptCGSCCPass(ThinOrFullLTOPhase LTOPhase) : LTOPhase(LTOPhase) {} 56 57 PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, 58 LazyCallGraph &CG, CGSCCUpdateResult &UR); 59 60 private: 61 const ThinOrFullLTOPhase LTOPhase = ThinOrFullLTOPhase::None; 62 }; 63 64 } // end namespace llvm 65 66 #endif // LLVM_TRANSFORMS_IPO_OPENMPOPT_H 67