Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:48:11

0001 //===- LoopGeneratorsGOMP.h - IR helper to create loops ---------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file contains functions to create scalar and OpenMP parallel loops
0010 // as LLVM-IR.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 #ifndef POLLY_LOOP_GENERATORS_GOMP_H
0014 #define POLLY_LOOP_GENERATORS_GOMP_H
0015 
0016 #include "polly/CodeGen/IRBuilder.h"
0017 #include "polly/CodeGen/LoopGenerators.h"
0018 #include "polly/Support/ScopHelper.h"
0019 #include "llvm/ADT/SetVector.h"
0020 
0021 namespace polly {
0022 
0023 /// This ParallelLoopGenerator subclass handles the generation of parallelized
0024 /// code, utilizing the GNU OpenMP library.
0025 class ParallelLoopGeneratorGOMP final : public ParallelLoopGenerator {
0026 public:
0027   /// Create a parallel loop generator for the current function.
0028   ParallelLoopGeneratorGOMP(PollyIRBuilder &Builder, const DataLayout &DL)
0029       : ParallelLoopGenerator(Builder, DL) {}
0030 
0031   // The functions below may be used if one does not want to generate a
0032   // specific OpenMP parallel loop, but generate individual parts of it
0033   // (e.g. the subfunction definition).
0034 
0035   /// Create a runtime library call to spawn the worker threads.
0036   ///
0037   /// @param SubFn      The subfunction which holds the loop body.
0038   /// @param SubFnParam The parameter for the subfunction (basically the struct
0039   ///                   filled with the outside values).
0040   /// @param LB         The lower bound for the loop we parallelize.
0041   /// @param UB         The upper bound for the loop we parallelize.
0042   /// @param Stride     The stride of the loop we parallelize.
0043   void createCallSpawnThreads(Value *SubFn, Value *SubFnParam, Value *LB,
0044                               Value *UB, Value *Stride);
0045 
0046   void deployParallelExecution(Function *SubFn, Value *SubFnParam, Value *LB,
0047                                Value *UB, Value *Stride) override;
0048 
0049   Function *prepareSubFnDefinition(Function *F) const override;
0050 
0051   std::tuple<Value *, Function *> createSubFn(Value *Stride, AllocaInst *Struct,
0052                                               SetVector<Value *> UsedValues,
0053                                               ValueMapT &VMap) override;
0054 
0055   /// Create a runtime library call to join the worker threads.
0056   void createCallJoinThreads();
0057 
0058   /// Create a runtime library call to get the next work item.
0059   ///
0060   /// @param LBPtr A pointer value to store the work item begin in.
0061   /// @param UBPtr A pointer value to store the work item end in.
0062   ///
0063   /// @returns A true value if the work item is not empty.
0064   Value *createCallGetWorkItem(Value *LBPtr, Value *UBPtr);
0065 
0066   /// Create a runtime library call to allow cleanup of the thread.
0067   ///
0068   /// @note This function is called right before the thread will exit the
0069   ///       subfunction and only if the runtime system depends on it.
0070   void createCallCleanupThread();
0071 };
0072 } // end namespace polly
0073 #endif