diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.h b/clang/lib/CodeGen/CGOpenMPRuntime.h --- a/clang/lib/CodeGen/CGOpenMPRuntime.h +++ b/clang/lib/CodeGen/CGOpenMPRuntime.h @@ -527,28 +527,6 @@ /// Returns pointer to kmpc_micro type. llvm::Type *getKmpc_MicroPointerTy(); - /// Returns __kmpc_for_static_init_* runtime function for the specified - /// size \a IVSize and sign \a IVSigned. Will create a distribute call - /// __kmpc_distribute_static_init* if \a IsGPUDistribute is set. - llvm::FunctionCallee createForStaticInitFunction(unsigned IVSize, - bool IVSigned, - bool IsGPUDistribute); - - /// Returns __kmpc_dispatch_init_* runtime function for the specified - /// size \a IVSize and sign \a IVSigned. - llvm::FunctionCallee createDispatchInitFunction(unsigned IVSize, - bool IVSigned); - - /// Returns __kmpc_dispatch_next_* runtime function for the specified - /// size \a IVSize and sign \a IVSigned. - llvm::FunctionCallee createDispatchNextFunction(unsigned IVSize, - bool IVSigned); - - /// Returns __kmpc_dispatch_fini_* runtime function for the specified - /// size \a IVSize and sign \a IVSigned. - llvm::FunctionCallee createDispatchFiniFunction(unsigned IVSize, - bool IVSigned); - /// If the specified mangled name is not in the module, create and /// return threadprivate cache object. This object is a pointer's worth of /// storage that's reserved for use by the OpenMP runtime. diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1502,103 +1502,6 @@ return llvm::PointerType::getUnqual(Kmpc_MicroTy); } -llvm::FunctionCallee -CGOpenMPRuntime::createForStaticInitFunction(unsigned IVSize, bool IVSigned, - bool IsGPUDistribute) { - assert((IVSize == 32 || IVSize == 64) && - "IV size is not compatible with the omp runtime"); - StringRef Name; - if (IsGPUDistribute) - Name = IVSize == 32 ? (IVSigned ? "__kmpc_distribute_static_init_4" - : "__kmpc_distribute_static_init_4u") - : (IVSigned ? "__kmpc_distribute_static_init_8" - : "__kmpc_distribute_static_init_8u"); - else - Name = IVSize == 32 ? (IVSigned ? "__kmpc_for_static_init_4" - : "__kmpc_for_static_init_4u") - : (IVSigned ? "__kmpc_for_static_init_8" - : "__kmpc_for_static_init_8u"); - - llvm::Type *ITy = IVSize == 32 ? CGM.Int32Ty : CGM.Int64Ty; - auto *PtrTy = llvm::PointerType::getUnqual(ITy); - llvm::Type *TypeParams[] = { - getIdentTyPointerTy(), // loc - CGM.Int32Ty, // tid - CGM.Int32Ty, // schedtype - llvm::PointerType::getUnqual(CGM.Int32Ty), // p_lastiter - PtrTy, // p_lower - PtrTy, // p_upper - PtrTy, // p_stride - ITy, // incr - ITy // chunk - }; - auto *FnTy = - llvm::FunctionType::get(CGM.VoidTy, TypeParams, /*isVarArg*/ false); - return CGM.CreateRuntimeFunction(FnTy, Name); -} - -llvm::FunctionCallee -CGOpenMPRuntime::createDispatchInitFunction(unsigned IVSize, bool IVSigned) { - assert((IVSize == 32 || IVSize == 64) && - "IV size is not compatible with the omp runtime"); - StringRef Name = - IVSize == 32 - ? (IVSigned ? "__kmpc_dispatch_init_4" : "__kmpc_dispatch_init_4u") - : (IVSigned ? "__kmpc_dispatch_init_8" : "__kmpc_dispatch_init_8u"); - llvm::Type *ITy = IVSize == 32 ? CGM.Int32Ty : CGM.Int64Ty; - llvm::Type *TypeParams[] = { getIdentTyPointerTy(), // loc - CGM.Int32Ty, // tid - CGM.Int32Ty, // schedtype - ITy, // lower - ITy, // upper - ITy, // stride - ITy // chunk - }; - auto *FnTy = - llvm::FunctionType::get(CGM.VoidTy, TypeParams, /*isVarArg*/ false); - return CGM.CreateRuntimeFunction(FnTy, Name); -} - -llvm::FunctionCallee -CGOpenMPRuntime::createDispatchFiniFunction(unsigned IVSize, bool IVSigned) { - assert((IVSize == 32 || IVSize == 64) && - "IV size is not compatible with the omp runtime"); - StringRef Name = - IVSize == 32 - ? (IVSigned ? "__kmpc_dispatch_fini_4" : "__kmpc_dispatch_fini_4u") - : (IVSigned ? "__kmpc_dispatch_fini_8" : "__kmpc_dispatch_fini_8u"); - llvm::Type *TypeParams[] = { - getIdentTyPointerTy(), // loc - CGM.Int32Ty, // tid - }; - auto *FnTy = - llvm::FunctionType::get(CGM.VoidTy, TypeParams, /*isVarArg=*/false); - return CGM.CreateRuntimeFunction(FnTy, Name); -} - -llvm::FunctionCallee -CGOpenMPRuntime::createDispatchNextFunction(unsigned IVSize, bool IVSigned) { - assert((IVSize == 32 || IVSize == 64) && - "IV size is not compatible with the omp runtime"); - StringRef Name = - IVSize == 32 - ? (IVSigned ? "__kmpc_dispatch_next_4" : "__kmpc_dispatch_next_4u") - : (IVSigned ? "__kmpc_dispatch_next_8" : "__kmpc_dispatch_next_8u"); - llvm::Type *ITy = IVSize == 32 ? CGM.Int32Ty : CGM.Int64Ty; - auto *PtrTy = llvm::PointerType::getUnqual(ITy); - llvm::Type *TypeParams[] = { - getIdentTyPointerTy(), // loc - CGM.Int32Ty, // tid - llvm::PointerType::getUnqual(CGM.Int32Ty), // p_lastiter - PtrTy, // p_lower - PtrTy, // p_upper - PtrTy // p_stride - }; - auto *FnTy = - llvm::FunctionType::get(CGM.Int32Ty, TypeParams, /*isVarArg*/ false); - return CGM.CreateRuntimeFunction(FnTy, Name); -} - llvm::OffloadEntriesInfoManager::OMPTargetDeviceClauseKind convertDeviceClause(const VarDecl *VD) { std::optional DevTy = @@ -2749,7 +2652,8 @@ CGF.Builder.getIntN(IVSize, 1), // Stride Chunk // Chunk }; - CGF.EmitRuntimeCall(createDispatchInitFunction(IVSize, IVSigned), Args); + CGF.EmitRuntimeCall(OMPBuilder.createDispatchInitFunction(IVSize, IVSigned), + Args); } static void emitForStaticInitCall( @@ -2816,7 +2720,8 @@ : OMP_IDENT_WORK_SECTIONS); llvm::Value *ThreadId = getThreadID(CGF, Loc); llvm::FunctionCallee StaticInitFunction = - createForStaticInitFunction(Values.IVSize, Values.IVSigned, false); + OMPBuilder.createForStaticInitFunction(Values.IVSize, Values.IVSigned, + false); auto DL = ApplyDebugLocation::CreateDefaultArtificial(CGF, Loc); emitForStaticInitCall(CGF, UpdatedLocation, ThreadId, StaticInitFunction, ScheduleNum, ScheduleKind.M1, ScheduleKind.M2, Values); @@ -2835,7 +2740,7 @@ bool isGPUDistribute = CGM.getLangOpts().OpenMPIsTargetDevice && (CGM.getTriple().isAMDGCN() || CGM.getTriple().isNVPTX()); - StaticInitFunction = createForStaticInitFunction( + StaticInitFunction = OMPBuilder.createForStaticInitFunction( Values.IVSize, Values.IVSigned, isGPUDistribute); emitForStaticInitCall(CGF, UpdatedLocation, ThreadId, StaticInitFunction, @@ -2879,7 +2784,8 @@ return; // Call __kmpc_for_dynamic_fini_(4|8)[u](ident_t *loc, kmp_int32 tid); llvm::Value *Args[] = {emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc)}; - CGF.EmitRuntimeCall(createDispatchFiniFunction(IVSize, IVSigned), Args); + CGF.EmitRuntimeCall(OMPBuilder.createDispatchFiniFunction(IVSize, IVSigned), + Args); } llvm::Value *CGOpenMPRuntime::emitForNext(CodeGenFunction &CGF, @@ -2899,8 +2805,8 @@ UB.getPointer(), // &Upper ST.getPointer() // &Stride }; - llvm::Value *Call = - CGF.EmitRuntimeCall(createDispatchNextFunction(IVSize, IVSigned), Args); + llvm::Value *Call = CGF.EmitRuntimeCall( + OMPBuilder.createDispatchNextFunction(IVSize, IVSigned), Args); return CGF.EmitScalarConversion( Call, CGF.getContext().getIntTypeForBitwidth(32, /*Signed=*/1), CGF.getContext().BoolTy, Loc); diff --git a/clang/test/OpenMP/ordered_codegen.cpp b/clang/test/OpenMP/ordered_codegen.cpp --- a/clang/test/OpenMP/ordered_codegen.cpp +++ b/clang/test/OpenMP/ordered_codegen.cpp @@ -521,7 +521,7 @@ // // // CHECK1-LABEL: define {{[^@]+}}@_Z8foo_simdii -// CHECK1-SAME: (i32 noundef [[LOW:%.*]], i32 noundef [[UP:%.*]]) #[[ATTR0]] { +// CHECK1-SAME: (i32 noundef [[LOW:%.*]], i32 noundef [[UP:%.*]]) #[[ATTR0:[0-9]+]] { // CHECK1-NEXT: entry: // CHECK1-NEXT: [[LOW_ADDR:%.*]] = alloca i32, align 4 // CHECK1-NEXT: [[UP_ADDR:%.*]] = alloca i32, align 4 @@ -1142,7 +1142,7 @@ // // // CHECK1-IRBUILDER-LABEL: define {{[^@]+}}@_Z8foo_simdii -// CHECK1-IRBUILDER-SAME: (i32 noundef [[LOW:%.*]], i32 noundef [[UP:%.*]]) #[[ATTR0]] { +// CHECK1-IRBUILDER-SAME: (i32 noundef [[LOW:%.*]], i32 noundef [[UP:%.*]]) #[[ATTR0:[0-9]+]] { // CHECK1-IRBUILDER-NEXT: entry: // CHECK1-IRBUILDER-NEXT: [[LOW_ADDR:%.*]] = alloca i32, align 4 // CHECK1-IRBUILDER-NEXT: [[UP_ADDR:%.*]] = alloca i32, align 4 @@ -1746,7 +1746,7 @@ // // // CHECK3-LABEL: define {{[^@]+}}@_Z8foo_simdii -// CHECK3-SAME: (i32 noundef [[LOW:%.*]], i32 noundef [[UP:%.*]]) #[[ATTR0]] { +// CHECK3-SAME: (i32 noundef [[LOW:%.*]], i32 noundef [[UP:%.*]]) #[[ATTR0:[0-9]+]] { // CHECK3-NEXT: entry: // CHECK3-NEXT: [[LOW_ADDR:%.*]] = alloca i32, align 4 // CHECK3-NEXT: [[UP_ADDR:%.*]] = alloca i32, align 4 @@ -2367,7 +2367,7 @@ // // // CHECK3-IRBUILDER-LABEL: define {{[^@]+}}@_Z8foo_simdii -// CHECK3-IRBUILDER-SAME: (i32 noundef [[LOW:%.*]], i32 noundef [[UP:%.*]]) #[[ATTR0]] { +// CHECK3-IRBUILDER-SAME: (i32 noundef [[LOW:%.*]], i32 noundef [[UP:%.*]]) #[[ATTR0:[0-9]+]] { // CHECK3-IRBUILDER-NEXT: entry: // CHECK3-IRBUILDER-NEXT: [[LOW_ADDR:%.*]] = alloca i32, align 4 // CHECK3-IRBUILDER-NEXT: [[UP_ADDR:%.*]] = alloca i32, align 4 diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h --- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h +++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h @@ -2146,6 +2146,24 @@ GenMapInfoCallbackTy GenMapInfoCB, TargetBodyGenCallbackTy BodyGenCB); + /// Returns __kmpc_for_static_init_* runtime function for the specified + /// size \a IVSize and sign \a IVSigned. Will create a distribute call + /// __kmpc_distribute_static_init* if \a IsGPUDistribute is set. + FunctionCallee createForStaticInitFunction(unsigned IVSize, bool IVSigned, + bool IsGPUDistribute); + + /// Returns __kmpc_dispatch_init_* runtime function for the specified + /// size \a IVSize and sign \a IVSigned. + FunctionCallee createDispatchInitFunction(unsigned IVSize, bool IVSigned); + + /// Returns __kmpc_dispatch_next_* runtime function for the specified + /// size \a IVSize and sign \a IVSigned. + FunctionCallee createDispatchNextFunction(unsigned IVSize, bool IVSigned); + + /// Returns __kmpc_dispatch_fini_* runtime function for the specified + /// size \a IVSize and sign \a IVSigned. + FunctionCallee createDispatchFiniFunction(unsigned IVSize, bool IVSigned); + /// Declarations for LLVM-IR types (simple, array, function and structure) are /// generated below. Their names are defined and used in OpenMPKinds.def. Here /// we provide the declarations, the initializeTypes function will provide the diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp --- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -4337,6 +4337,66 @@ return Builder.saveIP(); } +FunctionCallee +OpenMPIRBuilder::createForStaticInitFunction(unsigned IVSize, bool IVSigned, + bool IsGPUDistribute) { + assert((IVSize == 32 || IVSize == 64) && + "IV size is not compatible with the omp runtime"); + RuntimeFunction Name; + if (IsGPUDistribute) + Name = IVSize == 32 + ? (IVSigned ? omp::OMPRTL___kmpc_distribute_static_init_4 + : omp::OMPRTL___kmpc_distribute_static_init_4u) + : (IVSigned ? omp::OMPRTL___kmpc_distribute_static_init_8 + : omp::OMPRTL___kmpc_distribute_static_init_8u); + else + Name = IVSize == 32 ? (IVSigned ? omp::OMPRTL___kmpc_for_static_init_4 + : omp::OMPRTL___kmpc_for_static_init_4u) + : (IVSigned ? omp::OMPRTL___kmpc_for_static_init_8 + : omp::OMPRTL___kmpc_for_static_init_8u); + + return getOrCreateRuntimeFunction(M, Name); +} + +FunctionCallee OpenMPIRBuilder::createDispatchInitFunction(unsigned IVSize, + bool IVSigned) { + assert((IVSize == 32 || IVSize == 64) && + "IV size is not compatible with the omp runtime"); + RuntimeFunction Name = IVSize == 32 + ? (IVSigned ? omp::OMPRTL___kmpc_dispatch_init_4 + : omp::OMPRTL___kmpc_dispatch_init_4u) + : (IVSigned ? omp::OMPRTL___kmpc_dispatch_init_8 + : omp::OMPRTL___kmpc_dispatch_init_8u); + + return getOrCreateRuntimeFunction(M, Name); +} + +FunctionCallee OpenMPIRBuilder::createDispatchNextFunction(unsigned IVSize, + bool IVSigned) { + assert((IVSize == 32 || IVSize == 64) && + "IV size is not compatible with the omp runtime"); + RuntimeFunction Name = IVSize == 32 + ? (IVSigned ? omp::OMPRTL___kmpc_dispatch_next_4 + : omp::OMPRTL___kmpc_dispatch_next_4u) + : (IVSigned ? omp::OMPRTL___kmpc_dispatch_next_8 + : omp::OMPRTL___kmpc_dispatch_next_8u); + + return getOrCreateRuntimeFunction(M, Name); +} + +FunctionCallee OpenMPIRBuilder::createDispatchFiniFunction(unsigned IVSize, + bool IVSigned) { + assert((IVSize == 32 || IVSize == 64) && + "IV size is not compatible with the omp runtime"); + RuntimeFunction Name = IVSize == 32 + ? (IVSigned ? omp::OMPRTL___kmpc_dispatch_fini_4 + : omp::OMPRTL___kmpc_dispatch_fini_4u) + : (IVSigned ? omp::OMPRTL___kmpc_dispatch_fini_8 + : omp::OMPRTL___kmpc_dispatch_fini_8u); + + return getOrCreateRuntimeFunction(M, Name); +} + // Copy input from pointer or i64 to the expected argument type. static Value *copyInput(IRBuilderBase &Builder, unsigned AddrSpace, Value *Input, Argument &Arg) {