Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 14 | pmbaty | 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 | |||
| 23 | /// This ParallelLoopGenerator subclass handles the generation of parallelized |
||
| 24 | /// code, utilizing the GNU OpenMP library. |
||
| 25 | class ParallelLoopGeneratorGOMP final : public ParallelLoopGenerator { |
||
| 26 | public: |
||
| 27 | /// Create a parallel loop generator for the current function. |
||
| 28 | ParallelLoopGeneratorGOMP(PollyIRBuilder &Builder, LoopInfo &LI, |
||
| 29 | DominatorTree &DT, const DataLayout &DL) |
||
| 30 | : ParallelLoopGenerator(Builder, LI, DT, DL) {} |
||
| 31 | |||
| 32 | // The functions below may be used if one does not want to generate a |
||
| 33 | // specific OpenMP parallel loop, but generate individual parts of it |
||
| 34 | // (e.g. the subfunction definition). |
||
| 35 | |||
| 36 | /// Create a runtime library call to spawn the worker threads. |
||
| 37 | /// |
||
| 38 | /// @param SubFn The subfunction which holds the loop body. |
||
| 39 | /// @param SubFnParam The parameter for the subfunction (basically the struct |
||
| 40 | /// filled with the outside values). |
||
| 41 | /// @param LB The lower bound for the loop we parallelize. |
||
| 42 | /// @param UB The upper bound for the loop we parallelize. |
||
| 43 | /// @param Stride The stride of the loop we parallelize. |
||
| 44 | void createCallSpawnThreads(Value *SubFn, Value *SubFnParam, Value *LB, |
||
| 45 | Value *UB, Value *Stride); |
||
| 46 | |||
| 47 | void deployParallelExecution(Function *SubFn, Value *SubFnParam, Value *LB, |
||
| 48 | Value *UB, Value *Stride) override; |
||
| 49 | |||
| 50 | Function *prepareSubFnDefinition(Function *F) const override; |
||
| 51 | |||
| 52 | std::tuple<Value *, Function *> createSubFn(Value *Stride, AllocaInst *Struct, |
||
| 53 | SetVector<Value *> UsedValues, |
||
| 54 | ValueMapT &VMap) override; |
||
| 55 | |||
| 56 | /// Create a runtime library call to join the worker threads. |
||
| 57 | void createCallJoinThreads(); |
||
| 58 | |||
| 59 | /// Create a runtime library call to get the next work item. |
||
| 60 | /// |
||
| 61 | /// @param LBPtr A pointer value to store the work item begin in. |
||
| 62 | /// @param UBPtr A pointer value to store the work item end in. |
||
| 63 | /// |
||
| 64 | /// @returns A true value if the work item is not empty. |
||
| 65 | Value *createCallGetWorkItem(Value *LBPtr, Value *UBPtr); |
||
| 66 | |||
| 67 | /// Create a runtime library call to allow cleanup of the thread. |
||
| 68 | /// |
||
| 69 | /// @note This function is called right before the thread will exit the |
||
| 70 | /// subfunction and only if the runtime system depends on it. |
||
| 71 | void createCallCleanupThread(); |
||
| 72 | }; |
||
| 73 | } // end namespace polly |
||
| 74 | #endif |