14#include "llvm/Analysis/LoopInfo.h"
15#include "llvm/IR/Dominators.h"
16#include "llvm/IR/Module.h"
25 const std::string Name =
"GOMP_parallel_loop_runtime_start";
31 GlobalValue::LinkageTypes Linkage = Function::ExternalLinkage;
37 FunctionType *Ty = FunctionType::get(
Builder.getVoidTy(), Params,
false);
38 F = Function::Create(Ty, Linkage, Name,
M);
44 CallInst *Call =
Builder.CreateCall(F, Args);
54 CallInst *Call =
Builder.CreateCall(SubFn, SubFnParam);
61 FunctionType::get(
Builder.getVoidTy(), {Builder.getPtrTy()},
false);
62 Function *SubFn = Function::Create(FT, Function::InternalLinkage,
63 F->getName() +
"_polly_subfn",
M);
65 SubFn->arg_begin()->setName(
"polly.par.userContext");
89std::tuple<Value *, Function *>
91 SetVector<Value *> Data,
95 errs() <<
"warning: Polly's GNU OpenMP backend solely "
96 "supports the scheduling type 'runtime'.\n";
101 errs() <<
"warning: Polly's GNU OpenMP backend solely "
102 "supports the default chunk size.\n";
106 LLVMContext &Context = SubFn->getContext();
109 BasicBlock *HeaderBB = BasicBlock::Create(Context,
"polly.par.setup", SubFn);
110 SubFnDT = std::make_unique<DominatorTree>(*SubFn);
113 BasicBlock *ExitBB = BasicBlock::Create(Context,
"polly.par.exit", SubFn);
114 BasicBlock *CheckNextBB =
115 BasicBlock::Create(Context,
"polly.par.checkNext", SubFn);
116 BasicBlock *PreHeaderBB =
117 BasicBlock::Create(Context,
"polly.par.loadIVBounds", SubFn);
119 SubFnDT->addNewBlock(ExitBB, HeaderBB);
120 SubFnDT->addNewBlock(CheckNextBB, HeaderBB);
121 SubFnDT->addNewBlock(PreHeaderBB, HeaderBB);
124 Builder.SetInsertPoint(HeaderBB);
127 Value *UserContext = &*SubFn->arg_begin();
134 Builder.SetInsertPoint(CheckNextBB);
137 Next,
Builder.getInt1Ty(),
"polly.par.hasNextScheduleBlock");
138 Builder.CreateCondBr(HasNextSchedule, PreHeaderBB, ExitBB);
141 Builder.SetInsertPoint(PreHeaderBB);
148 "polly.par.UBAdjusted");
155 ICmpInst::ICMP_SLE,
nullptr,
true,
false);
157 BasicBlock::iterator LoopBody =
Builder.GetInsertPoint();
160 Builder.SetInsertPoint(ExitBB);
164 Builder.SetInsertPoint(LoopBody);
170 return std::make_tuple(IV, SubFn);
175 const std::string Name =
"GOMP_loop_runtime_next";
181 GlobalValue::LinkageTypes Linkage = Function::ExternalLinkage;
183 FunctionType *Ty = FunctionType::get(
Builder.getInt8Ty(), Params,
false);
184 F = Function::Create(Ty, Linkage, Name,
M);
187 Value *Args[] = {LBPtr, UBPtr};
188 CallInst *Call =
Builder.CreateCall(F, Args);
196 const std::string Name =
"GOMP_parallel_end";
202 GlobalValue::LinkageTypes Linkage = Function::ExternalLinkage;
204 FunctionType *Ty = FunctionType::get(
Builder.getVoidTy(),
false);
205 F = Function::Create(Ty, Linkage, Name,
M);
208 CallInst *Call =
Builder.CreateCall(F, {});
213 const std::string Name =
"GOMP_loop_end_nowait";
219 GlobalValue::LinkageTypes Linkage = Function::ExternalLinkage;
221 FunctionType *Ty = FunctionType::get(
Builder.getVoidTy(),
false);
222 F = Function::Create(Ty, Linkage, Name,
M);
225 CallInst *Call =
Builder.CreateCall(F, {});
polly dump Polly Dump Function
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.
Value * createCallGetWorkItem(Value *LBPtr, Value *UBPtr)
Create a runtime library call to get the next work item.
std::tuple< Value *, Function * > createSubFn(Value *Stride, AllocaInst *Struct, SetVector< Value * > UsedValues, ValueMapT &VMap) override
Create the parallel subfunction.
void createCallSpawnThreads(Value *SubFn, Value *SubFnParam, Value *LB, Value *UB, Value *Stride)
Create a runtime library call to spawn the worker threads.
void createCallJoinThreads()
Create a runtime library call to join the worker threads.
void createCallCleanupThread()
Create a runtime library call to allow cleanup of the thread.
Function * prepareSubFnDefinition(Function *F) const override
Prepare the definition of the parallel subfunction.
PollyIRBuilder & Builder
The IR builder we use to create instructions.
Function * createSubFnDefinition()
Create the definition of the parallel subfunction.
std::unique_ptr< DominatorTree > SubFnDT
The dominance tree for the generated subfunction.
Module * M
The current module.
llvm::DebugLoc DLGenerated
Debug location for generated code without direct link to any specific line.
Type * LongType
The type of a "long" on this hardware used for backend calls.
void extractValuesFromStruct(SetVector< Value * > Values, Type *Ty, Value *Struct, ValueMapT &VMap)
Extract all values from the Struct and construct the mapping.
std::unique_ptr< LoopInfo > SubFnLI
The loop info for the generated subfunction.
This file contains the declaration of the PolyhedralInfo class, which will provide an interface to ex...
OMPGeneralSchedulingType PollyScheduling
@ Value
MemoryKind::Value: Models an llvm::Value.
Value * createLoop(Value *LowerBound, Value *UpperBound, Value *Stride, PollyIRBuilder &Builder, LoopInfo &LI, DominatorTree &DT, BasicBlock *&ExitBlock, ICmpInst::Predicate Predicate, ScopAnnotator *Annotator=nullptr, bool Parallel=false, bool UseGuard=true, bool LoopVectDisabled=false)
Create a scalar do/for-style loop.
llvm::DenseMap< llvm::AssertingVH< llvm::Value >, llvm::AssertingVH< llvm::Value > > ValueMapT
Type to remap values.