Polly 19.0.0git
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
polly::ParallelLoopGeneratorKMP Class Referencefinal

This ParallelLoopGenerator subclass handles the generation of parallelized code, utilizing the LLVM OpenMP library. More...

#include <LoopGeneratorsKMP.h>

Inheritance diagram for polly::ParallelLoopGeneratorKMP:
Inheritance graph
[legend]

Public Member Functions

 ParallelLoopGeneratorKMP (PollyIRBuilder &Builder, LoopInfo &LI, DominatorTree &DT, const DataLayout &DL)
 Create a parallel loop generator for the current function.
 
void createCallSpawnThreads (Value *SubFn, Value *SubFnParam, Value *LB, Value *UB, Value *Stride)
 Create a runtime library call to spawn the worker threads.
 
void deployParallelExecution (Function *SubFn, Value *SubFnParam, Value *LB, Value *UB, Value *Stride) override
 Create the runtime library calls for spawn and join of the worker threads.
 
Function * prepareSubFnDefinition (Function *F) const override
 Prepare the definition of the parallel subfunction.
 
std::tuple< Value *, Function * > createSubFn (Value *Stride, AllocaInst *Struct, SetVector< Value * > UsedValues, ValueMapT &VMap) override
 Create the parallel subfunction.
 
Value * createCallGlobalThreadNum ()
 Create a runtime library call to get the current global thread number.
 
void createCallPushNumThreads (Value *GlobalThreadID, Value *NumThreads)
 Create a runtime library call to request a number of threads.
 
void createCallDispatchInit (Value *GlobalThreadID, Value *LB, Value *UB, Value *Inc, Value *ChunkSize)
 Create a runtime library call to prepare the OpenMP runtime.
 
Value * createCallDispatchNext (Value *GlobalThreadID, Value *IsLastPtr, Value *LBPtr, Value *UBPtr, Value *StridePtr)
 Create a runtime library call to retrieve the next (dynamically) allocated chunk of work for this thread.
 
void createCallStaticInit (Value *GlobalThreadID, Value *IsLastPtr, Value *LBPtr, Value *UBPtr, Value *StridePtr, Value *ChunkSize)
 Create a runtime library call to prepare the OpenMP runtime.
 
void createCallStaticFini (Value *GlobalThreadID)
 Create a runtime library call to mark the end of a statically scheduled loop.
 
GlobalVariable * createSourceLocation ()
 Create the current source location.
 
- Public Member Functions inherited from polly::ParallelLoopGenerator
 ParallelLoopGenerator (PollyIRBuilder &Builder, LoopInfo &LI, DominatorTree &DT, const DataLayout &DL)
 Create a parallel loop generator for the current function.
 
virtual ~ParallelLoopGenerator ()
 
Value * createParallelLoop (Value *LB, Value *UB, Value *Stride, SetVector< Value * > &Values, ValueMapT &VMap, BasicBlock::iterator *LoopBody)
 Create a parallel loop.
 
AllocaInst * storeValuesIntoStruct (SetVector< Value * > &Values)
 Create a struct for all Values and store them in there.
 
void extractValuesFromStruct (SetVector< Value * > Values, Type *Ty, Value *Struct, ValueMapT &VMap)
 Extract all values from the Struct and construct the mapping.
 
Function * createSubFnDefinition ()
 Create the definition of the parallel subfunction.
 
virtual void deployParallelExecution (Function *SubFn, Value *SubFnParam, Value *LB, Value *UB, Value *Stride)=0
 Create the runtime library calls for spawn and join of the worker threads.
 
virtual Function * prepareSubFnDefinition (Function *F) const =0
 Prepare the definition of the parallel subfunction.
 
virtual std::tuple< Value *, Function * > createSubFn (Value *Stride, AllocaInst *Struct, SetVector< Value * > UsedValues, ValueMapT &VMap)=0
 Create the parallel subfunction.
 

Protected Member Functions

OMPGeneralSchedulingType getSchedType (int ChunkSize, OMPGeneralSchedulingType Scheduling) const
 Convert the combination of given chunk size and scheduling type (which might have been set via the command line) into the corresponding scheduling type.
 
bool is64BitArch ()
 Returns True if 'LongType' is 64bit wide, otherwise: False.
 

Protected Attributes

GlobalValue * SourceLocationInfo
 The source location struct of this loop.
 
- Protected Attributes inherited from polly::ParallelLoopGenerator
PollyIRBuilderBuilder
 The IR builder we use to create instructions.
 
LoopInfo & LI
 The loop info of the current function we need to update.
 
DominatorTree & DT
 The dominance tree of the current function we need to update.
 
Type * LongType
 The type of a "long" on this hardware used for backend calls.
 
Module * M
 The current module.
 
llvm::DebugLoc DLGenerated
 Debug location for generated code without direct link to any specific line.
 

Detailed Description

This ParallelLoopGenerator subclass handles the generation of parallelized code, utilizing the LLVM OpenMP library.

Definition at line 27 of file LoopGeneratorsKMP.h.

Constructor & Destructor Documentation

◆ ParallelLoopGeneratorKMP()

polly::ParallelLoopGeneratorKMP::ParallelLoopGeneratorKMP ( PollyIRBuilder Builder,
LoopInfo &  LI,
DominatorTree &  DT,
const DataLayout &  DL 
)
inline

Create a parallel loop generator for the current function.

Definition at line 30 of file LoopGeneratorsKMP.h.

References createSourceLocation(), and SourceLocationInfo.

Member Function Documentation

◆ createCallDispatchInit()

void ParallelLoopGeneratorKMP::createCallDispatchInit ( Value *  GlobalThreadID,
Value *  LB,
Value *  UB,
Value *  Inc,
Value *  ChunkSize 
)

Create a runtime library call to prepare the OpenMP runtime.

For dynamically scheduled loops, saving the loop arguments.

Parameters
GlobalThreadIDThe global thread ID.
LBThe loop's lower bound.
UBThe loop's upper bound.
IncThe loop increment.
ChunkSizeThe chunk size of the parallel loop.

Definition at line 424 of file LoopGeneratorsKMP.cpp.

References polly::ParallelLoopGenerator::Builder, polly::ParallelLoopGenerator::DLGenerated, Function, getSchedType(), is64BitArch(), polly::ParallelLoopGenerator::LongType, polly::ParallelLoopGenerator::M, polly::PollyChunkSize, polly::PollyScheduling, SourceLocationInfo, and polly::Value.

Referenced by createSubFn().

◆ createCallDispatchNext()

Value * ParallelLoopGeneratorKMP::createCallDispatchNext ( Value *  GlobalThreadID,
Value *  IsLastPtr,
Value *  LBPtr,
Value *  UBPtr,
Value *  StridePtr 
)

Create a runtime library call to retrieve the next (dynamically) allocated chunk of work for this thread.

Parameters
GlobalThreadIDThe global thread ID.
IsLastPtrPointer to a flag, which is set to 1 if this is the last chunk of work, or 0 otherwise.
LBPtrPointer to the lower bound for the next chunk.
UBPtrPointer to the upper bound for the next chunk.
StridePtrPointer to the stride for the next chunk.
Returns
A Value which holds 1 if there is work to be done, 0 otherwise.

Definition at line 465 of file LoopGeneratorsKMP.cpp.

References polly::ParallelLoopGenerator::Builder, polly::ParallelLoopGenerator::DLGenerated, Function, is64BitArch(), polly::ParallelLoopGenerator::LongType, polly::ParallelLoopGenerator::M, SourceLocationInfo, and polly::Value.

Referenced by createSubFn().

◆ createCallGlobalThreadNum()

Value * ParallelLoopGeneratorKMP::createCallGlobalThreadNum ( )

Create a runtime library call to get the current global thread number.

Returns
A Value ref which holds the current global thread number.

Definition at line 313 of file LoopGeneratorsKMP.cpp.

References polly::ParallelLoopGenerator::Builder, polly::ParallelLoopGenerator::DLGenerated, Function, polly::ParallelLoopGenerator::M, SourceLocationInfo, and polly::Value.

Referenced by deployParallelExecution().

◆ createCallPushNumThreads()

void ParallelLoopGeneratorKMP::createCallPushNumThreads ( Value *  GlobalThreadID,
Value *  NumThreads 
)

Create a runtime library call to request a number of threads.

Which will be used in the next OpenMP section (by the next fork).

Parameters
GlobalThreadIDThe global thread ID.
NumThreadsThe number of threads to use.

Definition at line 334 of file LoopGeneratorsKMP.cpp.

References polly::ParallelLoopGenerator::Builder, polly::ParallelLoopGenerator::DLGenerated, Function, polly::ParallelLoopGenerator::M, SourceLocationInfo, and polly::Value.

Referenced by deployParallelExecution().

◆ createCallSpawnThreads()

void ParallelLoopGeneratorKMP::createCallSpawnThreads ( Value *  SubFn,
Value *  SubFnParam,
Value *  LB,
Value *  UB,
Value *  Stride 
)

Create a runtime library call to spawn the worker threads.

Parameters
SubFnThe subfunction which holds the loop body.
SubFnParamThe parameter for the subfunction (basically the struct filled with the outside values).
LBThe lower bound for the loop we parallelize.
UBThe upper bound for the loop we parallelize.
StrideThe stride of the loop we parallelize.

Definition at line 20 of file LoopGeneratorsKMP.cpp.

References polly::ParallelLoopGenerator::Builder, polly::ParallelLoopGenerator::DLGenerated, Function, polly::ParallelLoopGenerator::M, SourceLocationInfo, and polly::Value.

Referenced by deployParallelExecution().

◆ createCallStaticFini()

void ParallelLoopGeneratorKMP::createCallStaticFini ( Value *  GlobalThreadID)

Create a runtime library call to mark the end of a statically scheduled loop.

Parameters
GlobalThreadIDThe global thread ID.

Definition at line 404 of file LoopGeneratorsKMP.cpp.

References polly::ParallelLoopGenerator::Builder, polly::ParallelLoopGenerator::DLGenerated, Function, polly::ParallelLoopGenerator::M, SourceLocationInfo, and polly::Value.

Referenced by createSubFn().

◆ createCallStaticInit()

void ParallelLoopGeneratorKMP::createCallStaticInit ( Value *  GlobalThreadID,
Value *  IsLastPtr,
Value *  LBPtr,
Value *  UBPtr,
Value *  StridePtr,
Value *  ChunkSize 
)

Create a runtime library call to prepare the OpenMP runtime.

For statically scheduled loops, saving the loop arguments.

Parameters
GlobalThreadIDThe global thread ID.
IsLastPtrPointer to a flag, which is set to 1 if this is the last chunk of work, or 0 otherwise.
LBPtrPointer to the lower bound for the next chunk.
UBPtrPointer to the upper bound for the next chunk.
StridePtrPointer to the stride for the next chunk.
ChunkSizeThe chunk size of the parallel loop.

Definition at line 358 of file LoopGeneratorsKMP.cpp.

References polly::ParallelLoopGenerator::Builder, polly::ParallelLoopGenerator::DLGenerated, Function, getSchedType(), is64BitArch(), polly::ParallelLoopGenerator::LongType, polly::ParallelLoopGenerator::M, polly::PollyChunkSize, polly::PollyScheduling, SourceLocationInfo, and polly::Value.

Referenced by createSubFn().

◆ createSourceLocation()

GlobalVariable * ParallelLoopGeneratorKMP::createSourceLocation ( )

Create the current source location.

TODO: Generates only(!) dummy values.

Definition at line 501 of file LoopGeneratorsKMP.cpp.

References polly::ParallelLoopGenerator::Builder, and polly::ParallelLoopGenerator::M.

Referenced by ParallelLoopGeneratorKMP().

◆ createSubFn()

std::tuple< Value *, Function * > ParallelLoopGeneratorKMP::createSubFn ( Value *  Stride,
AllocaInst *  Struct,
SetVector< Value * >  UsedValues,
ValueMapT VMap 
)
overridevirtual

Create the parallel subfunction.

Parameters
StrideThe induction variable increment.
StructA struct holding all values in Values.
ValuesA set of LLVM-IR Values that should be available in the new loop body.
VMapA map to allow outside access to the new versions of the values in Values.
SubFnThe newly created subfunction is returned here.
Returns
The newly created induction variable.

Implements polly::ParallelLoopGenerator.

Definition at line 132 of file LoopGeneratorsKMP.cpp.

References polly::ParallelLoopGenerator::Builder, createCallDispatchInit(), createCallDispatchNext(), createCallStaticFini(), createCallStaticInit(), polly::createLoop(), polly::ParallelLoopGenerator::createSubFnDefinition(), polly::ParallelLoopGenerator::DT, polly::Dynamic, polly::ParallelLoopGenerator::extractValuesFromStruct(), Function, getSchedType(), polly::Guided, is64BitArch(), polly::ParallelLoopGenerator::LI, polly::ParallelLoopGenerator::LongType, polly::PollyChunkSize, polly::PollyScheduling, polly::Runtime, polly::StaticChunked, polly::StaticNonChunked, and polly::Value.

◆ deployParallelExecution()

void ParallelLoopGeneratorKMP::deployParallelExecution ( Function *  SubFn,
Value *  SubFnParam,
Value *  LB,
Value *  UB,
Value *  Stride 
)
overridevirtual

Create the runtime library calls for spawn and join of the worker threads.

Additionally, places a call to the specified subfunction.

Parameters
SubFnThe subfunction which holds the loop body.
SubFnParamThe parameter for the subfunction (basically the struct filled with the outside values).
LBThe lower bound for the loop we parallelize.
UBThe upper bound for the loop we parallelize.
StrideThe stride of the loop we parallelize.

Implements polly::ParallelLoopGenerator.

Definition at line 64 of file LoopGeneratorsKMP.cpp.

References polly::ParallelLoopGenerator::Builder, createCallGlobalThreadNum(), createCallPushNumThreads(), createCallSpawnThreads(), polly::PollyNumThreads, and polly::Value.

◆ getSchedType()

OMPGeneralSchedulingType ParallelLoopGeneratorKMP::getSchedType ( int  ChunkSize,
OMPGeneralSchedulingType  Scheduling 
) const
protected

Convert the combination of given chunk size and scheduling type (which might have been set via the command line) into the corresponding scheduling type.

This may result (e.g.) in a 'change' from "static chunked" scheduling to "static non-chunked" (regarding the provided and returned scheduling types).

Parameters
ChunkSizeThe chunk size, set via command line or its default.
SchedulingThe scheduling, set via command line or its default.
Returns
The corresponding OMPGeneralSchedulingType.

Definition at line 557 of file LoopGeneratorsKMP.cpp.

References polly::StaticChunked, and polly::StaticNonChunked.

Referenced by createCallDispatchInit(), createCallStaticInit(), and createSubFn().

◆ is64BitArch()

bool ParallelLoopGeneratorKMP::is64BitArch ( )
protected

Returns True if 'LongType' is 64bit wide, otherwise: False.

Definition at line 553 of file LoopGeneratorsKMP.cpp.

References polly::ParallelLoopGenerator::LongType.

Referenced by createCallDispatchInit(), createCallDispatchNext(), createCallStaticInit(), and createSubFn().

◆ prepareSubFnDefinition()

Function * ParallelLoopGeneratorKMP::prepareSubFnDefinition ( Function *  F) const
overridevirtual

Prepare the definition of the parallel subfunction.

Creates the argument list and names them (as well as the subfunction).

Parameters
FA pointer to the (parallel) subfunction's parent function.
Returns
The pointer to the (parallel) subfunction.

Implements polly::ParallelLoopGenerator.

Definition at line 78 of file LoopGeneratorsKMP.cpp.

References polly::ParallelLoopGenerator::Builder, Function, polly::ParallelLoopGenerator::LongType, and polly::ParallelLoopGenerator::M.

Member Data Documentation

◆ SourceLocationInfo

GlobalValue* polly::ParallelLoopGeneratorKMP::SourceLocationInfo
protected

The source location struct of this loop.

ident_t = type { i32, i32, i32, i32, i8* }

Definition at line 39 of file LoopGeneratorsKMP.h.

Referenced by createCallDispatchInit(), createCallDispatchNext(), createCallGlobalThreadNum(), createCallPushNumThreads(), createCallSpawnThreads(), createCallStaticFini(), createCallStaticInit(), and ParallelLoopGeneratorKMP().


The documentation for this class was generated from the following files: