diff options
author | Pranav Bhandarkar <pranav.bhandarkar@amd.com> | 2024-07-25 16:28:11 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-25 16:28:11 -0500 |
commit | 5b4e5f8ac6c6f7e25f7c87a26f2d2eaa0ebba8e3 (patch) | |
tree | 8f36720773f0ca0445ae203416fd12b5cafb4d6d /llvm | |
parent | c9e5af3944e85c5f1272c48522b4e9eda398b462 (diff) | |
download | llvm-5b4e5f8ac6c6f7e25f7c87a26f2d2eaa0ebba8e3.zip llvm-5b4e5f8ac6c6f7e25f7c87a26f2d2eaa0ebba8e3.tar.gz llvm-5b4e5f8ac6c6f7e25f7c87a26f2d2eaa0ebba8e3.tar.bz2 |
[OpenMPIRBuilder][Clang][NFC] - Combine `emitOffloadingArrays` and `emitOffloadingArraysArgument` in OpenMPIRBuilder (#97088)
This patch introduces a new interface in `OpenMPIRBuilder` that combines
the creation of the so-called offloading pointer arrays and their
subsequent preparation as arguments to the OpenMP runtime library. We
then use this in Clang.
This is intended to be used in the near future
by other frontends such as Flang when lowering MLIR to LLVMIR.
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h | 20 | ||||
-rw-r--r-- | llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 33 | ||||
-rw-r--r-- | llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp | 4 |
3 files changed, 41 insertions, 16 deletions
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h index a699588..1614d57 100644 --- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h +++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h @@ -2231,6 +2231,8 @@ public: /// The total number of pointers passed to the runtime library. unsigned NumberOfPtrs = 0u; + bool EmitDebug = false; + explicit TargetDataInfo() {} explicit TargetDataInfo(bool RequiresDevicePointerInfo, bool SeparateBeginEndCalls) @@ -2349,7 +2351,6 @@ public: void emitOffloadingArraysArgument(IRBuilderBase &Builder, OpenMPIRBuilder::TargetDataRTArgs &RTArgs, OpenMPIRBuilder::TargetDataInfo &Info, - bool EmitDebug = false, bool ForEndCall = false); /// Emit an array of struct descriptors to be assigned to the offload args. @@ -2360,13 +2361,28 @@ public: /// Emit the arrays used to pass the captures and map information to the /// offloading runtime library. If there is no map or capture information, - /// return nullptr by reference. + /// return nullptr by reference. Accepts a reference to a MapInfosTy object + /// that contains information generated for mappable clauses, + /// including base pointers, pointers, sizes, map types, user-defined mappers. void emitOffloadingArrays( InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo, TargetDataInfo &Info, bool IsNonContiguous = false, function_ref<void(unsigned int, Value *)> DeviceAddrCB = nullptr, function_ref<Value *(unsigned int)> CustomMapperCB = nullptr); + /// Allocates memory for and populates the arrays required for offloading + /// (offload_{baseptrs|ptrs|mappers|sizes|maptypes|mapnames}). Then, it + /// emits their base addresses as arguments to be passed to the runtime + /// library. In essence, this function is a combination of + /// emitOffloadingArrays and emitOffloadingArraysArgument and should arguably + /// be preferred by clients of OpenMPIRBuilder. + void emitOffloadingArraysAndArgs( + InsertPointTy AllocaIP, InsertPointTy CodeGenIP, TargetDataInfo &Info, + TargetDataRTArgs &RTArgs, MapInfosTy &CombinedInfo, + bool IsNonContiguous = false, bool ForEndCall = false, + function_ref<void(unsigned int, Value *)> DeviceAddrCB = nullptr, + function_ref<Value *(unsigned int)> CustomMapperCB = nullptr); + /// Creates offloading entry for the provided entry ID \a ID, address \a /// Addr, size \a Size, and flags \a Flags. void createOffloadEntry(Constant *ID, Constant *Addr, uint64_t Size, diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp index 45b568a..77e350e 100644 --- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -6368,8 +6368,7 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createTargetData( CustomMapperCB); TargetDataRTArgs RTArgs; - emitOffloadingArraysArgument(Builder, RTArgs, Info, - !MapInfo->Names.empty()); + emitOffloadingArraysArgument(Builder, RTArgs, Info); // Emit the number of elements in the offloading arrays. Value *PointerNum = Builder.getInt32(Info.NumberOfPtrs); @@ -6422,8 +6421,8 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createTargetData( // Generate code for the closing of the data region. auto EndThenGen = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP) { TargetDataRTArgs RTArgs; - emitOffloadingArraysArgument(Builder, RTArgs, Info, !MapInfo->Names.empty(), - /*ForEndCall=*/true); + Info.EmitDebug = !MapInfo->Names.empty(); + emitOffloadingArraysArgument(Builder, RTArgs, Info, /*ForEndCall=*/true); // Emit the number of elements in the offloading arrays. Value *PointerNum = Builder.getInt32(Info.NumberOfPtrs); @@ -7053,6 +7052,16 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::emitTargetTask( << "\n"); return Builder.saveIP(); } +void OpenMPIRBuilder::emitOffloadingArraysAndArgs( + InsertPointTy AllocaIP, InsertPointTy CodeGenIP, TargetDataInfo &Info, + TargetDataRTArgs &RTArgs, MapInfosTy &CombinedInfo, bool IsNonContiguous, + bool ForEndCall, function_ref<void(unsigned int, Value *)> DeviceAddrCB, + function_ref<Value *(unsigned int)> CustomMapperCB) { + emitOffloadingArrays(AllocaIP, CodeGenIP, CombinedInfo, Info, IsNonContiguous, + DeviceAddrCB, CustomMapperCB); + emitOffloadingArraysArgument(Builder, RTArgs, Info, ForEndCall); +} + static void emitTargetCall( OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder, OpenMPIRBuilder::InsertPointTy AllocaIP, Function *OutlinedFn, @@ -7066,12 +7075,11 @@ static void emitTargetCall( /*SeparateBeginEndCalls=*/true); OpenMPIRBuilder::MapInfosTy &MapInfo = GenMapInfoCB(Builder.saveIP()); - OMPBuilder.emitOffloadingArrays(AllocaIP, Builder.saveIP(), MapInfo, Info, - /*IsNonContiguous=*/true); - OpenMPIRBuilder::TargetDataRTArgs RTArgs; - OMPBuilder.emitOffloadingArraysArgument(Builder, RTArgs, Info, - !MapInfo.Names.empty()); + OMPBuilder.emitOffloadingArraysAndArgs(AllocaIP, Builder.saveIP(), Info, + RTArgs, MapInfo, + /*IsNonContiguous=*/true, + /*ForEndCall=*/false); // emitKernelLaunch auto &&EmitTargetCallFallbackCB = @@ -7081,7 +7089,7 @@ static void emitTargetCall( return Builder.saveIP(); }; - unsigned NumTargetItems = MapInfo.BasePointers.size(); + unsigned NumTargetItems = Info.NumberOfPtrs; // TODO: Use correct device ID Value *DeviceID = Builder.getInt64(OMP_DEVICEID_UNDEF); Value *NumTeamsVal = Builder.getInt32(NumTeams); @@ -7275,7 +7283,6 @@ void OpenMPIRBuilder::emitMapperCall(const LocationDescription &Loc, void OpenMPIRBuilder::emitOffloadingArraysArgument(IRBuilderBase &Builder, TargetDataRTArgs &RTArgs, TargetDataInfo &Info, - bool EmitDebug, bool ForEndCall) { assert((!ForEndCall || Info.separateBeginEndCalls()) && "expected region end call to runtime only when end call is separate"); @@ -7315,7 +7322,7 @@ void OpenMPIRBuilder::emitOffloadingArraysArgument(IRBuilderBase &Builder, // Only emit the mapper information arrays if debug information is // requested. - if (!EmitDebug) + if (!Info.EmitDebug) RTArgs.MapNamesArray = ConstantPointerNull::get(VoidPtrPtrTy); else RTArgs.MapNamesArray = Builder.CreateConstInBoundsGEP2_32( @@ -7504,9 +7511,11 @@ void OpenMPIRBuilder::emitOffloadingArrays( auto *MapNamesArrayGbl = createOffloadMapnames(CombinedInfo.Names, MapnamesName); Info.RTArgs.MapNamesArray = MapNamesArrayGbl; + Info.EmitDebug = true; } else { Info.RTArgs.MapNamesArray = Constant::getNullValue(PointerType::getUnqual(Builder.getContext())); + Info.EmitDebug = false; } // If there's a present map type modifier, it must not be applied to the end diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp index 8653bbd..cb4c289 100644 --- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp +++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp @@ -6902,8 +6902,8 @@ TEST_F(OpenMPIRBuilderTest, EmitOffloadingArraysArguments) { Info.RTArgs.MappersArray = ConstantPointerNull::get(Array4VoidPtrTy->getPointerTo()); Info.NumberOfPtrs = 4; - - OMPBuilder.emitOffloadingArraysArgument(Builder, RTArgs, Info, false, false); + Info.EmitDebug = false; + OMPBuilder.emitOffloadingArraysArgument(Builder, RTArgs, Info, false); EXPECT_NE(RTArgs.BasePointersArray, nullptr); EXPECT_NE(RTArgs.PointersArray, nullptr); |