diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index 1224fa681cdc0..a8255ac74cfcf 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1039,6 +1039,7 @@ CGOpenMPRuntime::CGOpenMPRuntime(CodeGenModule &CGM) hasRequiresUnifiedSharedMemory(), /*HasRequiresDynamicAllocators*/ false); Config.setDefaultTargetAS( CGM.getContext().getTargetInfo().getTargetAddressSpace(LangAS::Default)); + Config.setRuntimeCC(CGM.getRuntimeCC()); OMPBuilder.setConfig(Config); OMPBuilder.initialize(); diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp index fddeba98adccc..2f69a53787f0c 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp @@ -871,6 +871,8 @@ CGOpenMPRuntimeGPU::CGOpenMPRuntimeGPU(CodeGenModule &CGM) hasRequiresUnifiedSharedMemory(), /*HasRequiresDynamicAllocators*/ false); Config.setDefaultTargetAS( CGM.getContext().getTargetInfo().getTargetAddressSpace(LangAS::Default)); + Config.setRuntimeCC(CGM.getRuntimeCC()); + OMPBuilder.setConfig(Config); if (!CGM.getLangOpts().OpenMPIsTargetDevice) diff --git a/clang/test/OpenMP/spirv_target_codegen_basic.cpp b/clang/test/OpenMP/spirv_target_codegen_basic.cpp index 6e029fb93644d..ad0e110c0532a 100644 --- a/clang/test/OpenMP/spirv_target_codegen_basic.cpp +++ b/clang/test/OpenMP/spirv_target_codegen_basic.cpp @@ -9,9 +9,10 @@ // CHECK: @"_gomp_critical_user_$var" = common addrspace(1) global [8 x i32] zeroinitializer, align 8 // CHECK: define weak_odr protected spir_kernel void @__omp_offloading_{{.*}} - +// CHECK: call spir_func addrspace(9) i32 @__kmpc_target_init( // CHECK: call spir_func addrspace(9) void @__kmpc_critical(ptr addrspace(4) addrspacecast (ptr addrspace(1) @{{.*}} to ptr addrspace(4)), i32 %{{.*}}, ptr addrspace(4) addrspacecast (ptr addrspace(1) @"_gomp_critical_user_$var" to ptr addrspace(4))) // CHECK: call spir_func addrspace(9) void @__kmpc_end_critical(ptr addrspace(4) addrspacecast (ptr addrspace(1) @{{.*}} to ptr addrspace(4)), i32 %{{.*}}, ptr addrspace(4) addrspacecast (ptr addrspace(1) @"_gomp_critical_user_$var" to ptr addrspace(4))) +// CHECK: call spir_func addrspace(9) void @__kmpc_target_deinit( int main() { int ret = 0; diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h index 9f77c24d0b27b..f864a895a1259 100644 --- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h +++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h @@ -17,6 +17,7 @@ #include "llvm/Frontend/Atomic/Atomic.h" #include "llvm/Frontend/OpenMP/OMPConstants.h" #include "llvm/Frontend/OpenMP/OMPGridValues.h" +#include "llvm/IR/CallingConv.h" #include "llvm/IR/DebugLoc.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Module.h" @@ -138,6 +139,8 @@ class OpenMPIRBuilderConfig { // Default address space for the target. unsigned DefaultTargetAS = 0; + CallingConv::ID RuntimeCC = llvm::CallingConv::C; + LLVM_ABI OpenMPIRBuilderConfig(); LLVM_ABI OpenMPIRBuilderConfig(bool IsTargetDevice, bool IsGPU, bool OpenMPOffloadMandatory, @@ -170,6 +173,8 @@ class OpenMPIRBuilderConfig { unsigned getDefaultTargetAS() const { return DefaultTargetAS; } + CallingConv::ID getRuntimeCC() const { return RuntimeCC; } + bool hasRequiresFlags() const { return RequiresFlags; } LLVM_ABI bool hasRequiresReverseOffload() const; LLVM_ABI bool hasRequiresUnifiedAddress() const; @@ -208,6 +213,7 @@ class OpenMPIRBuilderConfig { void setSeparator(StringRef S) { Separator = S; } void setGridValue(omp::GV G) { GridValue = G; } void setDefaultTargetAS(unsigned AS) { DefaultTargetAS = AS; } + void setRuntimeCC(CallingConv::ID CC) { RuntimeCC = CC; } LLVM_ABI void setHasRequiresReverseOffload(bool Value); LLVM_ABI void setHasRequiresUnifiedAddress(bool Value); @@ -2132,6 +2138,10 @@ class OpenMPIRBuilder { LLVM_ABI Function *getOrCreateRuntimeFunctionPtr(omp::RuntimeFunction FnID); + CallInst *createRuntimeFunctionCall(FunctionCallee Callee, + ArrayRef Args, + StringRef Name = ""); + /// Return the (LLVM-IR) string describing the source location \p LocStr. LLVM_ABI Constant *getOrCreateSrcLocStr(StringRef LocStr, uint32_t &SrcLocStrSize); diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp index ac86fa859967e..5101717526263 100644 --- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -643,7 +643,7 @@ OpenMPIRBuilder::getOrCreateRuntimeFunction(Module &M, RuntimeFunction FnID) { break; #include "llvm/Frontend/OpenMP/OMPKinds.def" } - + Fn->setCallingConv(Config.getRuntimeCC()); // Add information if the runtime function takes a callback function if (FnID == OMPRTL___kmpc_fork_call || FnID == OMPRTL___kmpc_fork_teams) { if (!Fn->hasMetadata(LLVMContext::MD_callback)) { @@ -682,6 +682,14 @@ Function *OpenMPIRBuilder::getOrCreateRuntimeFunctionPtr(RuntimeFunction FnID) { return Fn; } +CallInst *OpenMPIRBuilder::createRuntimeFunctionCall(FunctionCallee Callee, + ArrayRef Args, + StringRef Name) { + CallInst *Call = Builder.CreateCall(Callee, Args, Name); + Call->setCallingConv(Config.getRuntimeCC()); + return Call; +} + void OpenMPIRBuilder::initialize() { initializeTypes(M); } static void raiseUserConstantDataAllocasToEntryBlock(IRBuilderBase &Builder, @@ -1024,7 +1032,7 @@ Constant *OpenMPIRBuilder::getOrCreateSrcLocStr(const LocationDescription &Loc, } Value *OpenMPIRBuilder::getOrCreateThreadID(Value *Ident) { - return Builder.CreateCall( + return createRuntimeFunctionCall( getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_global_thread_num), Ident, "omp_global_thread_num"); } @@ -1069,11 +1077,11 @@ OpenMPIRBuilder::createBarrier(const LocationDescription &Loc, Directive Kind, bool UseCancelBarrier = !ForceSimpleCall && isLastFinalizationInfoCancellable(OMPD_parallel); - Value *Result = - Builder.CreateCall(getOrCreateRuntimeFunctionPtr( - UseCancelBarrier ? OMPRTL___kmpc_cancel_barrier - : OMPRTL___kmpc_barrier), - Args); + Value *Result = createRuntimeFunctionCall( + getOrCreateRuntimeFunctionPtr(UseCancelBarrier + ? OMPRTL___kmpc_cancel_barrier + : OMPRTL___kmpc_barrier), + Args); if (UseCancelBarrier && CheckCancelFlag) if (Error Err = emitCancelationCheckImpl(Result, OMPD_parallel)) @@ -1112,7 +1120,7 @@ OpenMPIRBuilder::createCancel(const LocationDescription &Loc, Constant *SrcLocStr = getOrCreateSrcLocStr(Loc, SrcLocStrSize); Value *Ident = getOrCreateIdent(SrcLocStr, SrcLocStrSize); Value *Args[] = {Ident, getOrCreateThreadID(Ident), CancelKind}; - Value *Result = Builder.CreateCall( + Value *Result = createRuntimeFunctionCall( getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_cancel), Args); auto ExitCB = [this, CanceledDirective, Loc](InsertPointTy IP) -> Error { if (CanceledDirective == OMPD_parallel) { @@ -1163,7 +1171,7 @@ OpenMPIRBuilder::createCancellationPoint(const LocationDescription &Loc, Constant *SrcLocStr = getOrCreateSrcLocStr(Loc, SrcLocStrSize); Value *Ident = getOrCreateIdent(SrcLocStr, SrcLocStrSize); Value *Args[] = {Ident, getOrCreateThreadID(Ident), CancelKind}; - Value *Result = Builder.CreateCall( + Value *Result = createRuntimeFunctionCall( getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_cancellationpoint), Args); auto ExitCB = [this, CanceledDirective, Loc](InsertPointTy IP) -> Error { if (CanceledDirective == OMPD_parallel) { @@ -1212,7 +1220,7 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::emitTargetKernel( SmallVector OffloadingArgs{Ident, DeviceID, NumTeams, NumThreads, HostPtr, KernelArgsPtr}; - Return = Builder.CreateCall( + Return = createRuntimeFunctionCall( getOrCreateRuntimeFunction(M, OMPRTL___tgt_target_kernel), OffloadingArgs); @@ -1392,7 +1400,7 @@ static void targetParallelCallback( FunctionCallee RTLFn = OMPIRBuilder->getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_parallel_51); - Builder.CreateCall(RTLFn, Parallel51CallArgs); + OMPIRBuilder->createRuntimeFunctionCall(RTLFn, Parallel51CallArgs); LLVM_DEBUG(dbgs() << "With kmpc_parallel_51 placed: " << *Builder.GetInsertBlock()->getParent() << "\n"); @@ -1477,7 +1485,7 @@ hostParallelCallback(OpenMPIRBuilder *OMPIRBuilder, Function &OutlinedFn, RealArgs.push_back(NullPtrValue); } - Builder.CreateCall(RTLFn, RealArgs); + OMPIRBuilder->createRuntimeFunctionCall(RTLFn, RealArgs); LLVM_DEBUG(dbgs() << "With fork_call placed: " << *Builder.GetInsertBlock()->getParent() << "\n"); @@ -1523,7 +1531,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createParallel( Value *Args[] = { Ident, ThreadID, Builder.CreateIntCast(NumThreads, Int32, /*isSigned*/ false)}; - Builder.CreateCall( + createRuntimeFunctionCall( getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_push_num_threads), Args); } @@ -1532,7 +1540,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createParallel( Value *Args[] = { Ident, ThreadID, ConstantInt::get(Int32, unsigned(ProcBind), /*isSigned=*/true)}; - Builder.CreateCall( + createRuntimeFunctionCall( getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_push_proc_bind), Args); } @@ -1824,7 +1832,8 @@ void OpenMPIRBuilder::emitFlush(const LocationDescription &Loc) { Constant *SrcLocStr = getOrCreateSrcLocStr(Loc, SrcLocStrSize); Value *Args[] = {getOrCreateIdent(SrcLocStr, SrcLocStrSize)}; - Builder.CreateCall(getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_flush), Args); + createRuntimeFunctionCall(getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_flush), + Args); } void OpenMPIRBuilder::createFlush(const LocationDescription &Loc) { @@ -1842,8 +1851,8 @@ void OpenMPIRBuilder::emitTaskwaitImpl(const LocationDescription &Loc) { Value *Args[] = {Ident, getOrCreateThreadID(Ident)}; // Ignore return result until untied tasks are supported. - Builder.CreateCall(getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_omp_taskwait), - Args); + createRuntimeFunctionCall( + getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_omp_taskwait), Args); } void OpenMPIRBuilder::createTaskwait(const LocationDescription &Loc) { @@ -1860,8 +1869,8 @@ void OpenMPIRBuilder::emitTaskyieldImpl(const LocationDescription &Loc) { Constant *I32Null = ConstantInt::getNullValue(Int32); Value *Args[] = {Ident, getOrCreateThreadID(Ident), I32Null}; - Builder.CreateCall(getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_omp_taskyield), - Args); + createRuntimeFunctionCall( + getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_omp_taskyield), Args); } void OpenMPIRBuilder::createTaskyield(const LocationDescription &Loc) { @@ -2059,7 +2068,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTask( // Emit the @__kmpc_omp_task_alloc runtime call // The runtime call returns a pointer to an area where the task captured // variables must be copied before the task is run (TaskData) - CallInst *TaskData = Builder.CreateCall( + CallInst *TaskData = createRuntimeFunctionCall( TaskAllocFn, {/*loc_ref=*/Ident, /*gtid=*/ThreadID, /*flags=*/Flags, /*sizeof_task=*/TaskSize, /*sizeof_shared=*/SharedsSize, /*task_func=*/&OutlinedFn}); @@ -2071,7 +2080,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTask( Function *TaskDetachFn = getOrCreateRuntimeFunctionPtr( OMPRTL___kmpc_task_allow_completion_event); llvm::Value *EventVal = - Builder.CreateCall(TaskDetachFn, {Ident, ThreadID, TaskData}); + createRuntimeFunctionCall(TaskDetachFn, {Ident, ThreadID, TaskData}); llvm::Value *EventHandleAddr = Builder.CreatePointerBitCastOrAddrSpaceCast(EventHandle, Builder.getPtrTy(0)); @@ -2148,7 +2157,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTask( if (Dependencies.size()) { Function *TaskWaitFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_omp_wait_deps); - Builder.CreateCall( + createRuntimeFunctionCall( TaskWaitFn, {Ident, ThreadID, Builder.getInt32(Dependencies.size()), DepArray, ConstantInt::get(Builder.getInt32Ty(), 0), @@ -2158,21 +2167,21 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTask( getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_omp_task_begin_if0); Function *TaskCompleteFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_omp_task_complete_if0); - Builder.CreateCall(TaskBeginFn, {Ident, ThreadID, TaskData}); + createRuntimeFunctionCall(TaskBeginFn, {Ident, ThreadID, TaskData}); CallInst *CI = nullptr; if (HasShareds) - CI = Builder.CreateCall(&OutlinedFn, {ThreadID, TaskData}); + CI = createRuntimeFunctionCall(&OutlinedFn, {ThreadID, TaskData}); else - CI = Builder.CreateCall(&OutlinedFn, {ThreadID}); + CI = createRuntimeFunctionCall(&OutlinedFn, {ThreadID}); CI->setDebugLoc(StaleCI->getDebugLoc()); - Builder.CreateCall(TaskCompleteFn, {Ident, ThreadID, TaskData}); + createRuntimeFunctionCall(TaskCompleteFn, {Ident, ThreadID, TaskData}); Builder.SetInsertPoint(ThenTI); } if (Dependencies.size()) { Function *TaskFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_omp_task_with_deps); - Builder.CreateCall( + createRuntimeFunctionCall( TaskFn, {Ident, ThreadID, TaskData, Builder.getInt32(Dependencies.size()), DepArray, ConstantInt::get(Builder.getInt32Ty(), 0), @@ -2181,7 +2190,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTask( } else { // Emit the @__kmpc_omp_task runtime call to spawn the task Function *TaskFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_omp_task); - Builder.CreateCall(TaskFn, {Ident, ThreadID, TaskData}); + createRuntimeFunctionCall(TaskFn, {Ident, ThreadID, TaskData}); } StaleCI->eraseFromParent(); @@ -2218,7 +2227,7 @@ OpenMPIRBuilder::createTaskgroup(const LocationDescription &Loc, // Emit the @__kmpc_taskgroup runtime call to start the taskgroup Function *TaskgroupFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_taskgroup); - Builder.CreateCall(TaskgroupFn, {Ident, ThreadID}); + createRuntimeFunctionCall(TaskgroupFn, {Ident, ThreadID}); BasicBlock *TaskgroupExitBB = splitBB(Builder, true, "taskgroup.exit"); if (Error Err = BodyGenCB(AllocaIP, Builder.saveIP())) @@ -2228,7 +2237,7 @@ OpenMPIRBuilder::createTaskgroup(const LocationDescription &Loc, // Emit the @__kmpc_end_taskgroup runtime call to end the taskgroup Function *EndTaskgroupFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_end_taskgroup); - Builder.CreateCall(EndTaskgroupFn, {Ident, ThreadID}); + createRuntimeFunctionCall(EndTaskgroupFn, {Ident, ThreadID}); return Builder.saveIP(); } @@ -2384,14 +2393,14 @@ static OpenMPIRBuilder::InsertPointTy getInsertPointAfterInstr(Instruction *I) { } Value *OpenMPIRBuilder::getGPUThreadID() { - return Builder.CreateCall( + return createRuntimeFunctionCall( getOrCreateRuntimeFunction(M, OMPRTL___kmpc_get_hardware_thread_id_in_block), {}); } Value *OpenMPIRBuilder::getGPUWarpSize() { - return Builder.CreateCall( + return createRuntimeFunctionCall( getOrCreateRuntimeFunction(M, OMPRTL___kmpc_get_warp_size), {}); } @@ -2450,7 +2459,7 @@ Value *OpenMPIRBuilder::createRuntimeShuffleFunction(InsertPointTy AllocaIP, Value *WarpSizeCast = Builder.CreateIntCast(WarpSize, Builder.getInt16Ty(), /*isSigned=*/true); Value *ShuffleCall = - Builder.CreateCall(ShuffleFunc, {ElemCast, Offset, WarpSizeCast}); + createRuntimeFunctionCall(ShuffleFunc, {ElemCast, Offset, WarpSizeCast}); return castValueToType(AllocaIP, ShuffleCall, CastTy); } @@ -3016,7 +3025,7 @@ Function *OpenMPIRBuilder::emitShuffleAndReduceFunction( ReduceList, Builder.getPtrTy()); Value *RemoteReduceListPtr = Builder.CreatePointerBitCastOrAddrSpaceCast( RemoteListAddrCast, Builder.getPtrTy()); - Builder.CreateCall(ReduceFn, {LocalReduceListPtr, RemoteReduceListPtr}) + createRuntimeFunctionCall(ReduceFn, {LocalReduceListPtr, RemoteReduceListPtr}) ->addFnAttr(Attribute::NoUnwind); Builder.CreateBr(MergeBB); @@ -3237,7 +3246,7 @@ Function *OpenMPIRBuilder::emitListToGlobalReduceFunction( // Call reduce_function(GlobalReduceList, ReduceList) Value *ReduceList = Builder.CreateLoad(Builder.getPtrTy(), ReduceListArgAddrCast); - Builder.CreateCall(ReduceFn, {LocalReduceListAddrCast, ReduceList}) + createRuntimeFunctionCall(ReduceFn, {LocalReduceListAddrCast, ReduceList}) ->addFnAttr(Attribute::NoUnwind); Builder.CreateRetVoid(); Builder.restoreIP(OldIP); @@ -3428,7 +3437,7 @@ Function *OpenMPIRBuilder::emitGlobalToListReduceFunction( // Call reduce_function(ReduceList, GlobalReduceList) Value *ReduceList = Builder.CreateLoad(Builder.getPtrTy(), ReduceListArgAddrCast); - Builder.CreateCall(ReduceFn, {ReduceList, ReductionList}) + createRuntimeFunctionCall(ReduceFn, {ReduceList, ReductionList}) ->addFnAttr(Attribute::NoUnwind); Builder.CreateRetVoid(); Builder.restoreIP(OldIP); @@ -3682,7 +3691,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createReductionsGPU( WcFuncCast}; Function *Pv2Ptr = getOrCreateRuntimeFunctionPtr( RuntimeFunction::OMPRTL___kmpc_nvptx_parallel_reduce_nowait_v2); - Res = Builder.CreateCall(Pv2Ptr, Args); + Res = createRuntimeFunctionCall(Pv2Ptr, Args); } else { CodeGenIP = Builder.saveIP(); StructType *ReductionsBufferTy = StructType::create( @@ -3699,7 +3708,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createReductionsGPU( ReductionInfos, ReductionFunc, ReductionsBufferTy, FuncAttrs); Builder.restoreIP(CodeGenIP); - Value *KernelTeamsReductionPtr = Builder.CreateCall( + Value *KernelTeamsReductionPtr = createRuntimeFunctionCall( RedFixedBuferFn, {}, "_openmp_teams_reductions_buffer_$_$ptr"); Value *Args3[] = {SrcLocInfo, @@ -3716,7 +3725,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createReductionsGPU( Function *TeamsReduceFn = getOrCreateRuntimeFunctionPtr( RuntimeFunction::OMPRTL___kmpc_nvptx_teams_reduce_nowait_v2); - Res = Builder.CreateCall(TeamsReduceFn, Args3); + Res = createRuntimeFunctionCall(TeamsReduceFn, Args3); } // 5. Build if (res == 1) @@ -3921,10 +3930,10 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createReductions( IsNoWait ? RuntimeFunction::OMPRTL___kmpc_reduce_nowait : RuntimeFunction::OMPRTL___kmpc_reduce); CallInst *ReduceCall = - Builder.CreateCall(ReduceFunc, - {Ident, ThreadId, NumVariables, RedArraySize, RedArray, - ReductionFunc, Lock}, - "reduce"); + createRuntimeFunctionCall(ReduceFunc, + {Ident, ThreadId, NumVariables, RedArraySize, + RedArray, ReductionFunc, Lock}, + "reduce"); // Create final reduction entry blocks for the atomic and non-atomic case. // Emit IR that dispatches control flow to one of the blocks based on the @@ -3971,7 +3980,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createReductions( Function *EndReduceFunc = getOrCreateRuntimeFunctionPtr( IsNoWait ? RuntimeFunction::OMPRTL___kmpc_end_reduce_nowait : RuntimeFunction::OMPRTL___kmpc_end_reduce); - Builder.CreateCall(EndReduceFunc, {Ident, ThreadId, Lock}); + createRuntimeFunctionCall(EndReduceFunc, {Ident, ThreadId, Lock}); Builder.CreateBr(ContinuationBlock); // Populate the atomic reduction using the atomic elementwise reduction @@ -4023,10 +4032,10 @@ OpenMPIRBuilder::createMaster(const LocationDescription &Loc, Value *Args[] = {Ident, ThreadId}; Function *EntryRTLFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_master); - Instruction *EntryCall = Builder.CreateCall(EntryRTLFn, Args); + Instruction *EntryCall = createRuntimeFunctionCall(EntryRTLFn, Args); Function *ExitRTLFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_end_master); - Instruction *ExitCall = Builder.CreateCall(ExitRTLFn, Args); + Instruction *ExitCall = createRuntimeFunctionCall(ExitRTLFn, Args); return EmitOMPInlinedRegion(OMPD, EntryCall, ExitCall, BodyGenCB, FiniCB, /*Conditional*/ true, /*hasFinalize*/ true); @@ -4048,10 +4057,10 @@ OpenMPIRBuilder::createMasked(const LocationDescription &Loc, Value *ArgsEnd[] = {Ident, ThreadId}; Function *EntryRTLFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_masked); - Instruction *EntryCall = Builder.CreateCall(EntryRTLFn, Args); + Instruction *EntryCall = createRuntimeFunctionCall(EntryRTLFn, Args); Function *ExitRTLFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_end_masked); - Instruction *ExitCall = Builder.CreateCall(ExitRTLFn, ArgsEnd); + Instruction *ExitCall = createRuntimeFunctionCall(ExitRTLFn, ArgsEnd); return EmitOMPInlinedRegion(OMPD, EntryCall, ExitCall, BodyGenCB, FiniCB, /*Conditional*/ true, /*hasFinalize*/ true); @@ -4744,7 +4753,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::applyStaticWorkshareLoop( Args.push_back(PDistUpperBound); } Args.append({PStride, One, Zero}); - Builder.CreateCall(StaticInit, Args); + createRuntimeFunctionCall(StaticInit, Args); Value *LowerBound = Builder.CreateLoad(IVTy, PLowerBound); Value *InclusiveUpperBound = Builder.CreateLoad(IVTy, PUpperBound); Value *TripCountMinusOne = Builder.CreateSub(InclusiveUpperBound, LowerBound); @@ -4765,7 +4774,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::applyStaticWorkshareLoop( // In the "exit" block, call the "fini" function. Builder.SetInsertPoint(CLI->getExit(), CLI->getExit()->getTerminator()->getIterator()); - Builder.CreateCall(StaticFini, {SrcLoc, ThreadNum}); + createRuntimeFunctionCall(StaticFini, {SrcLoc, ThreadNum}); // Add the barrier if requested. if (NeedsBarrier) { @@ -4844,12 +4853,12 @@ OpenMPIRBuilder::applyStaticChunkedWorkshareLoop(DebugLoc DL, Constant *SrcLocStr = getOrCreateSrcLocStr(DL, SrcLocStrSize); Value *SrcLoc = getOrCreateIdent(SrcLocStr, SrcLocStrSize); Value *ThreadNum = getOrCreateThreadID(SrcLoc); - Builder.CreateCall(StaticInit, - {/*loc=*/SrcLoc, /*global_tid=*/ThreadNum, - /*schedtype=*/SchedulingType, /*plastiter=*/PLastIter, - /*plower=*/PLowerBound, /*pupper=*/PUpperBound, - /*pstride=*/PStride, /*incr=*/One, - /*chunk=*/CastedChunkSize}); + createRuntimeFunctionCall( + StaticInit, {/*loc=*/SrcLoc, /*global_tid=*/ThreadNum, + /*schedtype=*/SchedulingType, /*plastiter=*/PLastIter, + /*plower=*/PLowerBound, /*pupper=*/PUpperBound, + /*pstride=*/PStride, /*incr=*/One, + /*chunk=*/CastedChunkSize}); // Load values written by the "init" function. Value *FirstChunkStart = @@ -4921,7 +4930,7 @@ OpenMPIRBuilder::applyStaticChunkedWorkshareLoop(DebugLoc DL, // In the "exit" block, call the "fini" function. Builder.SetInsertPoint(DispatchExit, DispatchExit->getFirstInsertionPt()); - Builder.CreateCall(StaticFini, {SrcLoc, ThreadNum}); + createRuntimeFunctionCall(StaticFini, {SrcLoc, ThreadNum}); // Add the barrier if requested. if (NeedsBarrier) { @@ -5002,13 +5011,13 @@ static void createTargetLoopWorkshareCall(OpenMPIRBuilder *OMPBuilder, RealArgs.push_back(ConstantInt::get(TripCountTy, 0)); RealArgs.push_back(ConstantInt::get(Builder.getInt8Ty(), 0)); Builder.restoreIP({InsertBlock, std::prev(InsertBlock->end())}); - Builder.CreateCall(RTLFn, RealArgs); + OMPBuilder->createRuntimeFunctionCall(RTLFn, RealArgs); return; } FunctionCallee RTLNumThreads = OMPBuilder->getOrCreateRuntimeFunction( M, omp::RuntimeFunction::OMPRTL_omp_get_num_threads); Builder.restoreIP({InsertBlock, std::prev(InsertBlock->end())}); - Value *NumThreads = Builder.CreateCall(RTLNumThreads, {}); + Value *NumThreads = OMPBuilder->createRuntimeFunctionCall(RTLNumThreads, {}); RealArgs.push_back( Builder.CreateZExtOrTrunc(NumThreads, TripCountTy, "num.threads.cast")); @@ -5020,7 +5029,7 @@ static void createTargetLoopWorkshareCall(OpenMPIRBuilder *OMPBuilder, RealArgs.push_back(ConstantInt::get(Builder.getInt8Ty(), 0)); } - Builder.CreateCall(RTLFn, RealArgs); + OMPBuilder->createRuntimeFunctionCall(RTLFn, RealArgs); } static void workshareLoopTargetCallback( @@ -5338,9 +5347,9 @@ OpenMPIRBuilder::applyDynamicWorkshareLoop(DebugLoc DL, CanonicalLoopInfo *CLI, ConstantInt::get(I32Type, static_cast(SchedType)); // Call the "init" function. - Builder.CreateCall(DynamicInit, - {SrcLoc, ThreadNum, SchedulingType, /* LowerBound */ One, - UpperBound, /* step */ One, Chunk}); + createRuntimeFunctionCall(DynamicInit, {SrcLoc, ThreadNum, SchedulingType, + /* LowerBound */ One, UpperBound, + /* step */ One, Chunk}); // An outer loop around the existing one. BasicBlock *OuterCond = BasicBlock::Create( @@ -5348,9 +5357,9 @@ OpenMPIRBuilder::applyDynamicWorkshareLoop(DebugLoc DL, CanonicalLoopInfo *CLI, PreHeader->getParent()); // This needs to be 32-bit always, so can't use the IVTy Zero above. Builder.SetInsertPoint(OuterCond, OuterCond->getFirstInsertionPt()); - Value *Res = - Builder.CreateCall(DynamicNext, {SrcLoc, ThreadNum, PLastIter, - PLowerBound, PUpperBound, PStride}); + Value *Res = createRuntimeFunctionCall( + DynamicNext, + {SrcLoc, ThreadNum, PLastIter, PLowerBound, PUpperBound, PStride}); Constant *Zero32 = ConstantInt::get(I32Type, 0); Value *MoreWork = Builder.CreateCmp(CmpInst::ICMP_NE, Res, Zero32); Value *LowerBound = @@ -5387,7 +5396,7 @@ OpenMPIRBuilder::applyDynamicWorkshareLoop(DebugLoc DL, CanonicalLoopInfo *CLI, if (Ordered) { Builder.SetInsertPoint(&Latch->back()); FunctionCallee DynamicFini = getKmpcForDynamicFiniForType(IVTy, M, *this); - Builder.CreateCall(DynamicFini, {SrcLoc, ThreadNum}); + createRuntimeFunctionCall(DynamicFini, {SrcLoc, ThreadNum}); } // Add the barrier if requested. @@ -6276,7 +6285,7 @@ OpenMPIRBuilder::createCopyPrivate(const LocationDescription &Loc, Value *Args[] = {Ident, ThreadId, BufSize, CpyBuf, CpyFn, DidItLD}; Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_copyprivate); - Builder.CreateCall(Fn, Args); + createRuntimeFunctionCall(Fn, Args); return Builder.saveIP(); } @@ -6305,10 +6314,10 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createSingle( Value *Args[] = {Ident, ThreadId}; Function *EntryRTLFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_single); - Instruction *EntryCall = Builder.CreateCall(EntryRTLFn, Args); + Instruction *EntryCall = createRuntimeFunctionCall(EntryRTLFn, Args); Function *ExitRTLFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_end_single); - Instruction *ExitCall = Builder.CreateCall(ExitRTLFn, Args); + Instruction *ExitCall = createRuntimeFunctionCall(ExitRTLFn, Args); auto FiniCBWrapper = [&](InsertPointTy IP) -> Error { if (Error Err = FiniCB(IP)) @@ -6380,11 +6389,11 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createCritical( } else { RTFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_critical); } - Instruction *EntryCall = Builder.CreateCall(RTFn, EnterArgs); + Instruction *EntryCall = createRuntimeFunctionCall(RTFn, EnterArgs); Function *ExitRTLFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_end_critical); - Instruction *ExitCall = Builder.CreateCall(ExitRTLFn, Args); + Instruction *ExitCall = createRuntimeFunctionCall(ExitRTLFn, Args); return EmitOMPInlinedRegion(OMPD, EntryCall, ExitCall, BodyGenCB, FiniCB, /*Conditional*/ false, /*hasFinalize*/ true); @@ -6432,7 +6441,7 @@ OpenMPIRBuilder::createOrderedDepend(const LocationDescription &Loc, RTLFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_doacross_post); else RTLFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_doacross_wait); - Builder.CreateCall(RTLFn, Args); + createRuntimeFunctionCall(RTLFn, Args); return Builder.saveIP(); } @@ -6455,11 +6464,11 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createOrderedThreadsSimd( Value *Args[] = {Ident, ThreadId}; Function *EntryRTLFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_ordered); - EntryCall = Builder.CreateCall(EntryRTLFn, Args); + EntryCall = createRuntimeFunctionCall(EntryRTLFn, Args); Function *ExitRTLFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_end_ordered); - ExitCall = Builder.CreateCall(ExitRTLFn, Args); + ExitCall = createRuntimeFunctionCall(ExitRTLFn, Args); } return EmitOMPInlinedRegion(OMPD, EntryCall, ExitCall, BodyGenCB, FiniCB, @@ -6648,7 +6657,7 @@ CallInst *OpenMPIRBuilder::createOMPAlloc(const LocationDescription &Loc, Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_alloc); - return Builder.CreateCall(Fn, Args, Name); + return createRuntimeFunctionCall(Fn, Args, Name); } CallInst *OpenMPIRBuilder::createOMPFree(const LocationDescription &Loc, @@ -6663,7 +6672,7 @@ CallInst *OpenMPIRBuilder::createOMPFree(const LocationDescription &Loc, Value *ThreadId = getOrCreateThreadID(Ident); Value *Args[] = {ThreadId, Addr, Allocator}; Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_free); - return Builder.CreateCall(Fn, Args, Name); + return createRuntimeFunctionCall(Fn, Args, Name); } CallInst *OpenMPIRBuilder::createOMPInteropInit( @@ -6692,7 +6701,7 @@ CallInst *OpenMPIRBuilder::createOMPInteropInit( Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___tgt_interop_init); - return Builder.CreateCall(Fn, Args); + return createRuntimeFunctionCall(Fn, Args); } CallInst *OpenMPIRBuilder::createOMPInteropDestroy( @@ -6719,7 +6728,7 @@ CallInst *OpenMPIRBuilder::createOMPInteropDestroy( Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___tgt_interop_destroy); - return Builder.CreateCall(Fn, Args); + return createRuntimeFunctionCall(Fn, Args); } CallInst *OpenMPIRBuilder::createOMPInteropUse(const LocationDescription &Loc, @@ -6747,7 +6756,7 @@ CallInst *OpenMPIRBuilder::createOMPInteropUse(const LocationDescription &Loc, Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___tgt_interop_use); - return Builder.CreateCall(Fn, Args); + return createRuntimeFunctionCall(Fn, Args); } CallInst *OpenMPIRBuilder::createCachedThreadPrivate( @@ -6767,7 +6776,7 @@ CallInst *OpenMPIRBuilder::createCachedThreadPrivate( Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_threadprivate_cached); - return Builder.CreateCall(Fn, Args); + return createRuntimeFunctionCall(Fn, Args); } OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createTargetInit( @@ -6883,8 +6892,8 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createTargetInit( ? KernelLaunchEnvironment : Builder.CreateAddrSpaceCast(KernelLaunchEnvironment, KernelLaunchEnvParamTy); - CallInst *ThreadKind = - Builder.CreateCall(Fn, {KernelEnvironment, KernelLaunchEnvironment}); + CallInst *ThreadKind = createRuntimeFunctionCall( + Fn, {KernelEnvironment, KernelLaunchEnvironment}); Value *ExecUserCode = Builder.CreateICmpEQ( ThreadKind, Constant::getAllOnesValue(ThreadKind->getType()), @@ -6926,7 +6935,7 @@ void OpenMPIRBuilder::createTargetDeinit(const LocationDescription &Loc, Function *Fn = getOrCreateRuntimeFunctionPtr( omp::RuntimeFunction::OMPRTL___kmpc_target_deinit); - Builder.CreateCall(Fn, {}); + createRuntimeFunctionCall(Fn, {}); if (!TeamsReductionBufferLength || !TeamsReductionDataSize) return; @@ -7172,8 +7181,8 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTargetData( llvm::Constant::getNullValue(VoidPtr)}); } - Builder.CreateCall(getOrCreateRuntimeFunctionPtr(*MapperFunc), - OffloadingArgs); + createRuntimeFunctionCall(getOrCreateRuntimeFunctionPtr(*MapperFunc), + OffloadingArgs); if (Info.HasNoWait) { BasicBlock *OffloadContBlock = @@ -7196,7 +7205,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTargetData( Function *BeginMapperFunc = getOrCreateRuntimeFunctionPtr( omp::OMPRTL___tgt_target_data_begin_mapper); - Builder.CreateCall(BeginMapperFunc, OffloadingArgs); + createRuntimeFunctionCall(BeginMapperFunc, OffloadingArgs); for (auto DeviceMap : Info.DevicePtrInfoMap) { if (isa(DeviceMap.second.second)) { @@ -7255,7 +7264,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTargetData( Function *EndMapperFunc = getOrCreateRuntimeFunctionPtr(omp::OMPRTL___tgt_target_data_end_mapper); - Builder.CreateCall(EndMapperFunc, OffloadingArgs); + createRuntimeFunctionCall(EndMapperFunc, OffloadingArgs); return Error::success(); }; @@ -7751,7 +7760,7 @@ static Function *emitTargetTaskProxyFunction( LoadShared->getPointerAlignment(M.getDataLayout()), SharedsSize); KernelLaunchArgs.push_back(NewArgStructAlloca); } - Builder.CreateCall(KernelLaunchFunction, KernelLaunchArgs); + OMPBuilder.createRuntimeFunctionCall(KernelLaunchFunction, KernelLaunchArgs); Builder.CreateRetVoid(); return ProxyFn; } @@ -8112,7 +8121,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::emitTargetTask( TaskAllocArgs.push_back(DeviceID); } - TaskData = Builder.CreateCall(TaskAllocFn, TaskAllocArgs); + TaskData = createRuntimeFunctionCall(TaskAllocFn, TaskAllocArgs); Align Alignment = TaskData->getPointerAlignment(M.getDataLayout()); if (HasShareds) { @@ -8157,7 +8166,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::emitTargetTask( if (DepArray) { Function *TaskWaitFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_omp_wait_deps); - Builder.CreateCall( + createRuntimeFunctionCall( TaskWaitFn, {/*loc_ref=*/Ident, /*gtid=*/ThreadID, /*ndeps=*/Builder.getInt32(Dependencies.size()), @@ -8171,17 +8180,17 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::emitTargetTask( getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_omp_task_begin_if0); Function *TaskCompleteFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_omp_task_complete_if0); - Builder.CreateCall(TaskBeginFn, {Ident, ThreadID, TaskData}); - CallInst *CI = Builder.CreateCall(ProxyFn, {ThreadID, TaskData}); + createRuntimeFunctionCall(TaskBeginFn, {Ident, ThreadID, TaskData}); + CallInst *CI = createRuntimeFunctionCall(ProxyFn, {ThreadID, TaskData}); CI->setDebugLoc(StaleCI->getDebugLoc()); - Builder.CreateCall(TaskCompleteFn, {Ident, ThreadID, TaskData}); + createRuntimeFunctionCall(TaskCompleteFn, {Ident, ThreadID, TaskData}); } else if (DepArray) { // HasNoWait - meaning the task may be deferred. Call // __kmpc_omp_task_with_deps if there are dependencies, // else call __kmpc_omp_task Function *TaskFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_omp_task_with_deps); - Builder.CreateCall( + createRuntimeFunctionCall( TaskFn, {Ident, ThreadID, TaskData, Builder.getInt32(Dependencies.size()), DepArray, ConstantInt::get(Builder.getInt32Ty(), 0), @@ -8189,7 +8198,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::emitTargetTask( } else { // Emit the @__kmpc_omp_task runtime call to spawn the task Function *TaskFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_omp_task); - Builder.CreateCall(TaskFn, {Ident, ThreadID, TaskData}); + createRuntimeFunctionCall(TaskFn, {Ident, ThreadID, TaskData}); } StaleCI->eraseFromParent(); @@ -8238,7 +8247,7 @@ static void emitTargetCall( auto &&EmitTargetCallFallbackCB = [&](OpenMPIRBuilder::InsertPointTy IP) -> OpenMPIRBuilder::InsertPointOrErrorTy { Builder.restoreIP(IP); - Builder.CreateCall(OutlinedFn, Args); + OMPBuilder.createRuntimeFunctionCall(OutlinedFn, Args); return Builder.saveIP(); }; @@ -8579,10 +8588,10 @@ void OpenMPIRBuilder::emitMapperCall(const LocationDescription &Loc, {Builder.getInt32(0), Builder.getInt32(0)}); Value *NullPtr = Constant::getNullValue(PointerType::getUnqual(Int8Ptr->getContext())); - Builder.CreateCall(MapperFunc, - {SrcLocInfo, Builder.getInt64(DeviceID), - Builder.getInt32(NumOperands), ArgsBaseGEP, ArgsGEP, - ArgSizesGEP, MaptypesArg, MapnamesArg, NullPtr}); + createRuntimeFunctionCall(MapperFunc, {SrcLocInfo, Builder.getInt64(DeviceID), + Builder.getInt32(NumOperands), + ArgsBaseGEP, ArgsGEP, ArgSizesGEP, + MaptypesArg, MapnamesArg, NullPtr}); } void OpenMPIRBuilder::emitOffloadingArraysArgument(IRBuilderBase &Builder, @@ -8775,7 +8784,7 @@ void OpenMPIRBuilder::emitUDMapperArrayInitOrDel( // data structure. Value *OffloadingArgs[] = {MapperHandle, Base, Begin, ArraySize, MapTypeArg, MapName}; - Builder.CreateCall( + createRuntimeFunctionCall( getOrCreateRuntimeFunction(M, OMPRTL___tgt_push_mapper_component), OffloadingArgs); } @@ -8862,7 +8871,7 @@ Expected OpenMPIRBuilder::emitUserDefinedMapper( // Call the runtime API __tgt_mapper_num_components to get the number of // pre-existing components. Value *OffloadingArgs[] = {MapperHandle}; - Value *PreviousSize = Builder.CreateCall( + Value *PreviousSize = createRuntimeFunctionCall( getOrCreateRuntimeFunction(M, OMPRTL___tgt_mapper_num_components), OffloadingArgs); Value *ShiftedPreviousSize = @@ -8968,11 +8977,12 @@ Expected OpenMPIRBuilder::emitUserDefinedMapper( return ChildMapperFn.takeError(); if (*ChildMapperFn) { // Call the corresponding mapper function. - Builder.CreateCall(*ChildMapperFn, OffloadingArgs)->setDoesNotThrow(); + createRuntimeFunctionCall(*ChildMapperFn, OffloadingArgs) + ->setDoesNotThrow(); } else { // Call the runtime API __tgt_push_mapper_component to fill up the runtime // data structure. - Builder.CreateCall( + createRuntimeFunctionCall( getOrCreateRuntimeFunction(M, OMPRTL___tgt_push_mapper_component), OffloadingArgs); } @@ -9960,7 +9970,7 @@ OpenMPIRBuilder::createTeams(const LocationDescription &Loc, ThreadLimit = Builder.getInt32(0); Value *ThreadNum = getOrCreateThreadID(Ident); - Builder.CreateCall( + createRuntimeFunctionCall( getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_push_num_teams_51), {Ident, ThreadNum, NumTeamsLower, NumTeamsUpper, ThreadLimit}); } @@ -10011,9 +10021,10 @@ OpenMPIRBuilder::createTeams(const LocationDescription &Loc, Ident, Builder.getInt32(StaleCI->arg_size() - 2), &OutlinedFn}; if (HasShared) Args.push_back(StaleCI->getArgOperand(2)); - Builder.CreateCall(getOrCreateRuntimeFunctionPtr( - omp::RuntimeFunction::OMPRTL___kmpc_fork_teams), - Args); + createRuntimeFunctionCall( + getOrCreateRuntimeFunctionPtr( + omp::RuntimeFunction::OMPRTL___kmpc_fork_teams), + Args); for (Instruction *I : llvm::reverse(ToBeDeleted)) I->eraseFromParent(); diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp index 64e3c5f085bb3..5d9f0623f11a8 100644 --- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -2254,8 +2254,11 @@ llvm::OpenMPIRBuilder *ModuleTranslation::getOpenMPBuilder() { /* HasRequiresUnifiedSharedMemory = */ false, /* HasRequiresDynamicAllocators = */ false); unsigned int defaultAS = - getLLVMModule()->getDataLayout().getProgramAddressSpace(); + llvmModule->getDataLayout().getProgramAddressSpace(); config.setDefaultTargetAS(defaultAS); + config.setRuntimeCC(llvmModule->getTargetTriple().isSPIRV() + ? llvm::CallingConv::SPIR_FUNC + : llvm::CallingConv::C); ompBuilder->setConfig(std::move(config)); ompBuilder->initialize(); } diff --git a/mlir/test/Target/LLVMIR/omptarget-runtimecc.mlir b/mlir/test/Target/LLVMIR/omptarget-runtimecc.mlir new file mode 100644 index 0000000000000..a232bd7f91d1c --- /dev/null +++ b/mlir/test/Target/LLVMIR/omptarget-runtimecc.mlir @@ -0,0 +1,12 @@ +// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s + +module attributes {omp.is_target_device = true, omp.is_gpu = true, omp.target_triples = ["spirv64-intel"], llvm.target_triple = "spirv64-intel"} { +// CHECK: call spir_func i32 @__kmpc_target_init +// CHECK: call spir_func void @__kmpc_target_deinit + llvm.func @target_if_variable(%x : i1) { + omp.target if(%x) { + omp.terminator + } + llvm.return + } + }