Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 1 | //===- LoopGeneratorsGOMP.h - IR helper to create loops ---------*- 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 contains functions to create scalar and OpenMP parallel loops |
| 10 | // as LLVM-IR. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | #ifndef POLLY_LOOP_GENERATORS_GOMP_H |
| 14 | #define POLLY_LOOP_GENERATORS_GOMP_H |
| 15 | |
| 16 | #include "polly/CodeGen/IRBuilder.h" |
| 17 | #include "polly/CodeGen/LoopGenerators.h" |
| 18 | #include "polly/Support/ScopHelper.h" |
| 19 | #include "llvm/ADT/SetVector.h" |
| 20 | |
| 21 | namespace polly { |
| 22 | using namespace llvm; |
| 23 | |
| 24 | /// This ParallelLoopGenerator subclass handles the generation of parallelized |
| 25 | /// code, utilizing the GNU OpenMP library. |
| 26 | class ParallelLoopGeneratorGOMP : public ParallelLoopGenerator { |
| 27 | public: |
| 28 | /// Create a parallel loop generator for the current function. |
| 29 | ParallelLoopGeneratorGOMP(PollyIRBuilder &Builder, LoopInfo &LI, |
| 30 | DominatorTree &DT, const DataLayout &DL) |
| 31 | : ParallelLoopGenerator(Builder, LI, DT, DL) {} |
| 32 | |
| 33 | // The functions below may be used if one does not want to generate a |
| 34 | // specific OpenMP parallel loop, but generate individual parts of it |
| 35 | // (e.g. the subfunction definition). |
| 36 | |
| 37 | /// Create a runtime library call to spawn the worker threads. |
| 38 | /// |
| 39 | /// @param SubFn The subfunction which holds the loop body. |
| 40 | /// @param SubFnParam The parameter for the subfunction (basically the struct |
| 41 | /// filled with the outside values). |
| 42 | /// @param LB The lower bound for the loop we parallelize. |
| 43 | /// @param UB The upper bound for the loop we parallelize. |
| 44 | /// @param Stride The stride of the loop we parallelize. |
| 45 | void createCallSpawnThreads(Value *SubFn, Value *SubFnParam, Value *LB, |
| 46 | Value *UB, Value *Stride); |
| 47 | |
| 48 | void deployParallelExecution(Function *SubFn, Value *SubFnParam, Value *LB, |
| 49 | Value *UB, Value *Stride) override; |
| 50 | |
| 51 | virtual Function *prepareSubFnDefinition(Function *F) const override; |
| 52 | |
| 53 | std::tuple<Value *, Function *> createSubFn(Value *Stride, AllocaInst *Struct, |
| 54 | SetVector<Value *> UsedValues, |
| 55 | ValueMapT &VMap) override; |
| 56 | |
| 57 | /// Create a runtime library call to join the worker threads. |
| 58 | void createCallJoinThreads(); |
| 59 | |
| 60 | /// Create a runtime library call to get the next work item. |
| 61 | /// |
| 62 | /// @param LBPtr A pointer value to store the work item begin in. |
| 63 | /// @param UBPtr A pointer value to store the work item end in. |
| 64 | /// |
| 65 | /// @returns A true value if the work item is not empty. |
| 66 | Value *createCallGetWorkItem(Value *LBPtr, Value *UBPtr); |
| 67 | |
| 68 | /// Create a runtime library call to allow cleanup of the thread. |
| 69 | /// |
| 70 | /// @note This function is called right before the thread will exit the |
| 71 | /// subfunction and only if the runtime system depends on it. |
| 72 | void createCallCleanupThread(); |
| 73 | }; |
| 74 | } // end namespace polly |
| 75 | #endif |