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;
33 Type *Params[] = {PointerType::getUnqual(FunctionType::get(
41 FunctionType *Ty = FunctionType::get(
Builder.getVoidTy(), Params,
false);
42 F = Function::Create(Ty, Linkage, Name,
M);
48 CallInst *Call =
Builder.CreateCall(F, Args);
58 CallInst *Call =
Builder.CreateCall(SubFn, SubFnParam);
65 FunctionType::get(
Builder.getVoidTy(), {Builder.getPtrTy()},
false);
66 Function *SubFn = Function::Create(FT, Function::InternalLinkage,
67 F->getName() +
"_polly_subfn",
M);
69 SubFn->arg_begin()->setName(
"polly.par.userContext");
93std::tuple<Value *, Function *>
95 SetVector<Value *> Data,
99 errs() <<
"warning: Polly's GNU OpenMP backend solely "
100 "supports the scheduling type 'runtime'.\n";
105 errs() <<
"warning: Polly's GNU OpenMP backend solely "
106 "supports the default chunk size.\n";
110 LLVMContext &Context = SubFn->getContext();
113 BasicBlock *HeaderBB = BasicBlock::Create(Context,
"polly.par.setup", SubFn);
114 SubFnDT = std::make_unique<DominatorTree>(*SubFn);
117 BasicBlock *ExitBB = BasicBlock::Create(Context,
"polly.par.exit", SubFn);
118 BasicBlock *CheckNextBB =
119 BasicBlock::Create(Context,
"polly.par.checkNext", SubFn);
120 BasicBlock *PreHeaderBB =
121 BasicBlock::Create(Context,
"polly.par.loadIVBounds", SubFn);
123 SubFnDT->addNewBlock(ExitBB, HeaderBB);
124 SubFnDT->addNewBlock(CheckNextBB, HeaderBB);
125 SubFnDT->addNewBlock(PreHeaderBB, HeaderBB);
128 Builder.SetInsertPoint(HeaderBB);
131 Value *UserContext = &*SubFn->arg_begin();
138 Builder.SetInsertPoint(CheckNextBB);
141 Next,
Builder.getInt1Ty(),
"polly.par.hasNextScheduleBlock");
142 Builder.CreateCondBr(HasNextSchedule, PreHeaderBB, ExitBB);
145 Builder.SetInsertPoint(PreHeaderBB);
152 "polly.par.UBAdjusted");
159 ICmpInst::ICMP_SLE,
nullptr,
true,
false);
161 BasicBlock::iterator LoopBody =
Builder.GetInsertPoint();
164 Builder.SetInsertPoint(ExitBB);
168 Builder.SetInsertPoint(&*LoopBody);
174 return std::make_tuple(IV, SubFn);
179 const std::string Name =
"GOMP_loop_runtime_next";
185 GlobalValue::LinkageTypes Linkage = Function::ExternalLinkage;
187 FunctionType *Ty = FunctionType::get(
Builder.getInt8Ty(), Params,
false);
188 F = Function::Create(Ty, Linkage, Name,
M);
191 Value *Args[] = {LBPtr, UBPtr};
192 CallInst *Call =
Builder.CreateCall(F, Args);
200 const std::string Name =
"GOMP_parallel_end";
206 GlobalValue::LinkageTypes Linkage = Function::ExternalLinkage;
208 FunctionType *Ty = FunctionType::get(
Builder.getVoidTy(),
false);
209 F = Function::Create(Ty, Linkage, Name,
M);
212 CallInst *Call =
Builder.CreateCall(F, {});
217 const std::string Name =
"GOMP_loop_end_nowait";
223 GlobalValue::LinkageTypes Linkage = Function::ExternalLinkage;
225 FunctionType *Ty = FunctionType::get(
Builder.getVoidTy(),
false);
226 F = Function::Create(Ty, Linkage, Name,
M);
229 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.