Changeset View
Changeset View
Standalone View
Standalone View
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
Show First 20 Lines • Show All 1,215 Lines • ▼ Show 20 Lines | if (getExecutionMode() == CGOpenMPRuntimeGPU::EM_SPMD) | ||||
return; | return; | ||||
CGOpenMPRuntime::emitProcBindClause(CGF, ProcBind, Loc); | CGOpenMPRuntime::emitProcBindClause(CGF, ProcBind, Loc); | ||||
} | } | ||||
void CGOpenMPRuntimeGPU::emitNumThreadsClause(CodeGenFunction &CGF, | void CGOpenMPRuntimeGPU::emitNumThreadsClause(CodeGenFunction &CGF, | ||||
llvm::Value *NumThreads, | llvm::Value *NumThreads, | ||||
SourceLocation Loc) { | SourceLocation Loc) { | ||||
// Do nothing in case of SPMD mode and L0 parallel. | // Nothing to do. | ||||
if (getExecutionMode() == CGOpenMPRuntimeGPU::EM_SPMD) | |||||
return; | |||||
CGOpenMPRuntime::emitNumThreadsClause(CGF, NumThreads, Loc); | |||||
} | } | ||||
void CGOpenMPRuntimeGPU::emitNumTeamsClause(CodeGenFunction &CGF, | void CGOpenMPRuntimeGPU::emitNumTeamsClause(CodeGenFunction &CGF, | ||||
const Expr *NumTeams, | const Expr *NumTeams, | ||||
const Expr *ThreadLimit, | const Expr *ThreadLimit, | ||||
SourceLocation Loc) {} | SourceLocation Loc) {} | ||||
llvm::Function *CGOpenMPRuntimeGPU::emitParallelOutlinedFunction( | llvm::Function *CGOpenMPRuntimeGPU::emitParallelOutlinedFunction( | ||||
▲ Show 20 Lines • Show All 268 Lines • ▼ Show 20 Lines | void CGOpenMPRuntimeGPU::emitTeamsCall(CodeGenFunction &CGF, | ||||
OutlinedFnArgs.append(CapturedVars.begin(), CapturedVars.end()); | OutlinedFnArgs.append(CapturedVars.begin(), CapturedVars.end()); | ||||
emitOutlinedFunctionCall(CGF, Loc, OutlinedFn, OutlinedFnArgs); | emitOutlinedFunctionCall(CGF, Loc, OutlinedFn, OutlinedFnArgs); | ||||
} | } | ||||
void CGOpenMPRuntimeGPU::emitParallelCall(CodeGenFunction &CGF, | void CGOpenMPRuntimeGPU::emitParallelCall(CodeGenFunction &CGF, | ||||
SourceLocation Loc, | SourceLocation Loc, | ||||
llvm::Function *OutlinedFn, | llvm::Function *OutlinedFn, | ||||
ArrayRef<llvm::Value *> CapturedVars, | ArrayRef<llvm::Value *> CapturedVars, | ||||
const Expr *IfCond) { | const Expr *IfCond, | ||||
llvm::Value *NumThreads) { | |||||
if (!CGF.HaveInsertPoint()) | if (!CGF.HaveInsertPoint()) | ||||
return; | return; | ||||
auto &&ParallelGen = [this, Loc, OutlinedFn, CapturedVars, | auto &&ParallelGen = [this, Loc, OutlinedFn, CapturedVars, IfCond, | ||||
IfCond](CodeGenFunction &CGF, PrePostActionTy &Action) { | NumThreads](CodeGenFunction &CGF, | ||||
PrePostActionTy &Action) { | |||||
CGBuilderTy &Bld = CGF.Builder; | CGBuilderTy &Bld = CGF.Builder; | ||||
llvm::Value *NumThreadsVal = NumThreads; | |||||
llvm::Function *WFn = WrapperFunctionsMap[OutlinedFn]; | llvm::Function *WFn = WrapperFunctionsMap[OutlinedFn]; | ||||
llvm::Value *ID = llvm::ConstantPointerNull::get(CGM.Int8PtrTy); | llvm::Value *ID = llvm::ConstantPointerNull::get(CGM.Int8PtrTy); | ||||
if (WFn) | if (WFn) | ||||
ID = Bld.CreateBitOrPointerCast(WFn, CGM.Int8PtrTy); | ID = Bld.CreateBitOrPointerCast(WFn, CGM.Int8PtrTy); | ||||
llvm::Value *FnPtr = Bld.CreateBitOrPointerCast(OutlinedFn, CGM.Int8PtrTy); | llvm::Value *FnPtr = Bld.CreateBitOrPointerCast(OutlinedFn, CGM.Int8PtrTy); | ||||
// Create a private scope that will globalize the arguments | // Create a private scope that will globalize the arguments | ||||
// passed from the outside of the target region. | // passed from the outside of the target region. | ||||
Show All 23 Lines | auto &&ParallelGen = [this, Loc, OutlinedFn, CapturedVars, IfCond, | ||||
llvm::Value *IfCondVal = nullptr; | llvm::Value *IfCondVal = nullptr; | ||||
if (IfCond) | if (IfCond) | ||||
IfCondVal = Bld.CreateIntCast(CGF.EvaluateExprAsBool(IfCond), CGF.Int32Ty, | IfCondVal = Bld.CreateIntCast(CGF.EvaluateExprAsBool(IfCond), CGF.Int32Ty, | ||||
/* isSigned */ false); | /* isSigned */ false); | ||||
else | else | ||||
IfCondVal = llvm::ConstantInt::get(CGF.Int32Ty, 1); | IfCondVal = llvm::ConstantInt::get(CGF.Int32Ty, 1); | ||||
if (!NumThreadsVal) | |||||
NumThreadsVal = llvm::ConstantInt::get(CGF.Int32Ty, -1); | |||||
else | |||||
NumThreadsVal = Bld.CreateZExtOrTrunc(NumThreadsVal, CGF.Int32Ty), | |||||
assert(IfCondVal && "Expected a value"); | assert(IfCondVal && "Expected a value"); | ||||
llvm::Value *RTLoc = emitUpdateLocation(CGF, Loc); | llvm::Value *RTLoc = emitUpdateLocation(CGF, Loc); | ||||
llvm::Value *Args[] = { | llvm::Value *Args[] = { | ||||
RTLoc, | RTLoc, | ||||
getThreadID(CGF, Loc), | getThreadID(CGF, Loc), | ||||
IfCondVal, | IfCondVal, | ||||
llvm::ConstantInt::get(CGF.Int32Ty, -1), | NumThreadsVal, | ||||
llvm::ConstantInt::get(CGF.Int32Ty, -1), | llvm::ConstantInt::get(CGF.Int32Ty, -1), | ||||
FnPtr, | FnPtr, | ||||
ID, | ID, | ||||
Bld.CreateBitOrPointerCast(CapturedVarsAddrs.getPointer(), | Bld.CreateBitOrPointerCast(CapturedVarsAddrs.getPointer(), | ||||
CGF.VoidPtrPtrTy), | CGF.VoidPtrPtrTy), | ||||
llvm::ConstantInt::get(CGM.SizeTy, CapturedVars.size())}; | llvm::ConstantInt::get(CGM.SizeTy, CapturedVars.size())}; | ||||
CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction( | CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction( | ||||
CGM.getModule(), OMPRTL___kmpc_parallel_51), | CGM.getModule(), OMPRTL___kmpc_parallel_51), | ||||
▲ Show 20 Lines • Show All 2,402 Lines • Show Last 20 Lines |