aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-10-11[OpenMPIRBuilder] Add ThreadLimit and NumTeams clauses to teams construct ↵Shraiysh1-0/+210
(#68364) This patch adds support for `thread_limit` and bounds on `num_teams` clause for the teams construct in OpenMP. Added testcases for the same.
2023-10-09[FrontEnd] Fix a warningKazu Hirata1-2/+2
This patch fixes: third-party/unittest/googletest/include/gtest/gtest.h:1379:11: error: comparison of integers of different signs: 'const unsigned int' and 'const int' [-Werror,-Wsign-compare]
2023-10-09[OpenMPIRBuilder] Remove wrapper function in `createTask`, `createTeams` ↵Shraiysh1-37/+41
(#67723) This patch removes the wrapper function in `OpenMPIRBuilder::createTask` and `OpenMPIRBuilder.createTeams`. The outlined function is directly of the form that is expected by the runtime library calls. This patch also adds a utility function to help add fake values and their uses, which will be deleted in finalization callbacks. **Why we needed wrappers earlier?** Before the post outline callbacks are executed, the IR has the following structure: ``` define @func() { ;... call void @outlined_fn(ptr %data) ;... } define void @outlined_fn(ptr %data) ``` OpenMP offloading expects a specific signature for the outlined function in a runtime call. For example, `__kmpc_fork_teams` expects the following signature: ``` define @outlined_fn(ptr %global.tid, ptr %data) ``` As there is no way to change a function's arguments after it has been created, a wrapper function with the expected signature is created that calls the outlined function inside it. **How we are handling it now?** To handle this in the current patch, we create a "fake" global tid and add a "fake" use for it in the to-be-outlined region. We need to create these fake values so the outliner sees it as something it needs to pass to the outlined function. We also tell the outliner to exclude this global tid value from the aggregate `data` argument, so it comes as a separate argument in the beginning. This way, we are able to directly get the outlined function in the expected format. This is inspired by the way `createParallel` handles outlining (using fake values and then deleting them later). Tasks are handled with a similar approach. This simplifies the generated code and the code to do this itself also becomes simpler (because we no longer have to construct a new function).
2023-10-06[OpenMP][OpenMPIRBuilder] Move copyInput to a passed in lambda function and ↵agozillon1-19/+74
re-order kernel argument load/stores (#68124) This patch moves the existing copyInput function into a lambda argument that can be defined by a caller to the function. This allows more flexibility in how the function is defined, allowing Clang and MLIR to utilise their own respective functions and types inside of the lamba without affecting the OMPIRBuilder itself. The idea is to eventually replace/build on the existing copyInput function that's used and moved into OpenMPToLLVMIRTranslation.cpp to a slightly more complex implementation that uses MLIRs map information (primarily ByRef and ByCapture information at the moment). The patch also moves kernel load stores to the top of the kernel, prior to the first openmp runtime invocation. Just makes the IR a little closer to Clang.
2023-10-05[llvm] Replace uses of Type::getPointerTo (NFC)JOE19941-2/+2
opaque pointer clean-up effort (NFC)
2023-09-24[OMPIRBuilder] Added `createTeams` (#66807)Shraiysh1-0/+81
This patch adds basic support for `omp teams` to the OpenMPIRBuilder. The outlined function after code extraction is called from a wrapper function with appropriate arguments. This wrapper function is passed to the runtime calls. This approach is different from the Clang approach - clang directly emits the runtime call to the outlined function. The outlining utility (OutlineInfo) simply outlines the code and generates a function call to the outlined function. After the function has been generated by the outlining utility, there is no easy way to alter the function arguments without meddling with the outlining itself. Hence the wrapper function approach is taken.
2023-09-15[OMPIRBuilder] Fix shared clause for task constructPrabhdeep Singh Soni1-4/+14
This patch fixes the shared clause for the task construct with multiple shared variables. The shareds field in the kmp_task_t is not an inline array in the struct, rather it is a pointer to an array. With an inline array, the pointer dereference to the outlined function body of the task would segmentation fault when accessed by the runtime. Reviewed By: kiranchandramohan, jdoerfert Differential Revision: https://reviews.llvm.org/D158462
2023-09-14[OpenMP][OMPIRBuilder] OpenMPIRBuilder support for requires directiveSergio Afonso1-5/+50
This patch updates the `OpenMPIRBuilderConfig` structure to hold all available 'requires' clauses, and it replicates part of the code generation for the 'requires' registration function from clang in the `OMPIRBuilder`, to be used with flang. Porting the rest of features of the clang implementation to the IRBuilder and sharing it between clang and flang remains for a future patch, due to the complexity of the logic selecting the attributes of the generated registration function. Differential Revision: https://reviews.llvm.org/D147217
2023-08-15[OpenMP][OpenMPIRBuilder] Add kernel launch codegen to emitTargetCallJan Sjodin1-12/+65
This patch adds code emission in emitTargetCall to call the OpenMP runtime to launch an kernel, and to call the fallback host implementation if the launch fails. Reviewed By: TIFitis, kiranchandramohan, jdoerfert Differential Revision: https://reviews.llvm.org/D155633
2023-08-11[OpenMP][IR] Set correct alignment for internal variablesHao Jin1-1/+9
OpenMP runtime functions assume the pointers are aligned to sizeof(pointer), but it is being aligned incorrectly. Fix with the proper alignment in the IR builder. Reviewed By: tianshilei1992 Differential Revision: https://reviews.llvm.org/D157040
2023-08-04[MLIR][OpenMP] Added MLIR translation support for use_device clausesAkash Banerjee1-6/+45
Added MLIR support for translating use_device_ptr and use_device_addr clauses for LLVMIR lowering. - use_device_ptr: The mapped variables marked with use_device_ptr are accessed through a copy of the base pointer mappers. The mapper is copied onto a new temporary pointer variable. - use_device_addr: The mapped variables marked with use_device_addr are accessed directly through the base pointer mappers. - If mapping information is not provided explicitly then default map_type of alloc/release is assumed and the map_size is set to 0. Depends on D152554 Reviewed By: kiranchandramohan, raghavendhra Differential Revision: https://reviews.llvm.org/D146648
2023-08-02Stop using legacy helpers indicating typed pointer types. NFCBjorn Pettersson1-12/+11
Since we no longer support typed LLVM IR pointer types, the code can be simplified into for example using PointerType::get directly instead of using Type::getInt8PtrTy and Type::getInt32PtrTy etc. Differential Revision: https://reviews.llvm.org/D156733
2023-07-26[OpenMP] Introduce kernel environmentShilei Tian1-8/+12
This patch introduces per kernel environment. Previously, flags such as execution mode are set through global variables with name like `__kernel_name_exec_mode`. They are accessible on the host by reading the corresponding global variable, but not from the device. Besides, some assumptions, such as no nested parallelism, are not per kernel basis, preventing us applying per kernel optimization in the device runtime. This is a combination and refinement of patch series D116908, D116909, and D116910. Depend on D155886. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D142569
2023-07-25[OpenMP][OpenMPIRBuilder] Make outlined function parameters i64 or ptrJan Sjodin1-5/+21
This patch ensures that all outlined functions parameters are i64 or ptr when compiling for a target device, which is what the OpenMP runtime expects. The values are then cast to the correct type inside the kernel. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D155628
2023-07-23Revert commits for kernel environmentShilei Tian1-12/+8
This reverts commits for kernel environments as they causes issues in AMD BB.
2023-07-23[LLVM] Remove the module dump introduced mistakenlyShilei Tian1-2/+0
2023-07-23[OpenMP] Introduce kernel environmentShilei Tian1-8/+14
This patch introduces per kernel environment. Previously, flags such as execution mode are set through global variables with name like `__kernel_name_exec_mode`. They are accessible on the host by reading the corresponding global variable, but not from the device. Besides, some assumptions, such as no nested parallelism, are not per kernel basis, preventing us applying per kernel optimization in the device runtime. This is a combination and refinement of patch series D116908, D116909, and D116910. Depend on D155886. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D142569
2023-07-20[unittest] Improve OpenMPIRBuilderTest after D149162Fangrui Song1-9/+10
Make it less sensitive to omp_offload.info operands order and improve the failure diagnostic. Caught by D155789
2023-07-20[MLIR][OpenMP][OMPIRBuilder] Use target triple to initialize `IsGPU` flagSergio Afonso1-0/+42
This patch modifies the construction of the `OpenMPIRBuilder` in MLIR to initialize the `IsGPU` flag using target triple information passed down from the Flang frontend. If not present, it will default to `false`. This replicates the behavior currently implemented in Clang, where the `CodeGenModule::createOpenMPRuntime()` method creates a different `CGOpenMPRuntime` instance depending on the target triple, which in turn has an effect on the `IsGPU` flag of the `OpenMPIRBuilderConfig` object. Differential Revision: https://reviews.llvm.org/D151903
2023-07-18[OpenMPIRBuilderTest] Remove unused variable (NFC)Nikita Popov1-2/+0
2023-07-18[llvm] Remove some uses of isOpaqueOrPointeeTypeEquals() (NFC)Nikita Popov1-9/+0
2023-07-14[llvm] Remove calls to setOpaquePointers() (NFC)Nikita Popov1-1/+0
True is the default (and only possible) value.
2023-07-10[OpenMP][OMPIRBuilder] Rename IsEmbedded and IsTargetCodegen flagsSergio Afonso1-3/+3
This patch renames the `OpenMPIRBuilderConfig` flags to reduce confusion over their meaning. `IsTargetCodegen` becomes `IsGPU`, whereas `IsEmbedded` becomes `IsTargetDevice`. The `-fopenmp-is-device` compiler option is also renamed to `-fopenmp-is-target-device` and the `omp.is_device` MLIR attribute is renamed to `omp.is_target_device`. Getters and setters of all these renamed properties are also updated accordingly. Many unit tests have been updated to use the new names, but an alias for the `-fopenmp-is-device` option is created so that external programs do not stop working after the name change. `IsGPU` is set when the target triple is AMDGCN or NVIDIA PTX, and it is only valid if `IsTargetDevice` is specified as well. `IsTargetDevice` is set by the `-fopenmp-is-target-device` compiler frontend option, which is only added to the OpenMP device invocation for offloading-enabled programs. Differential Revision: https://reviews.llvm.org/D154591
2023-06-19[MLIR][OpenMP] Refactoring createTargetData in OMPIRBuilderAkash Banerjee1-133/+81
Key changes: - Refactor the createTargetData function to make use of the emitOffloadingArrays and emitOffloadingArraysArgument functions to generate code. - Added a new emitIfClause helper function to allow handling if clauses in a similar fashion to Clang. - Updated the MLIR side of code to account for changes to createTargetData. Depends on D149872 Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D146557
2023-06-07[Clang][OpenMP][IRBuilder] Move registerTargetGlobalVariable & ↵Andrew Gozillon1-0/+80
getAddrOfDeclareTargetVar into the OMPIRBuilder This change tries to move registerTargetglobalVariable and getAddrOfDeclareTargetVar out of Clang's CGOpenMPRuntime and into the OMPIRBuilder for shared use with MLIR's OpenMPDialect and Flang (or other languages that may want to utilise it). This primarily does this by trying to hoist the Clang specific types into arguments or callback functions in the form of lambdas, replacing it with LLVM equivelants and utilising shared OMPIRBuilder enumerators for the clauses, rather than Clang's own variation. Reviewers: jsjodin, jdoerfert Differential Revision: https://reviews.llvm.org/D149162
2023-05-18[Flang][OpenMP][OMPIRBuilder] Add lowering of TargetOp for device codegenSergio Afonso1-0/+89
This patch adds support in the `OpenMPIRBuilder` for generating working device code for OpenMP target regions. It generates and handles the result of a call to `__kmpc_target_init()` at the beginning of the function resulting from outlining each target region, and it also generates the matching `__kmpc_target_deinit()` call before returning. It relies on the implementation of target region outlining for host codegen to handle the production of the new function and the lowering of its body based on the contents of the associated target region. Depends on D147172 Differential Revision: https://reviews.llvm.org/D147940
2023-04-26[OpenMP][Flang][MLIR] Add lowering of TargetOp for host codegen to LLVM-IRJan Sjodin1-0/+56
This patch adds lowering of TargetOps for the host. The lowering outlines the target region function and uses the OpenMPIRBuilder support functions to emit the function and call. Code generation for offloading will be done in later patches. Reviewed By: kiranchandramohan, jdoerfert, agozillon Differential Revision: https://reviews.llvm.org/D147172
2023-04-12[MLIR][OpenMP] Update OpenMPIRBuilderTest to use opaque pointersAkash Banerjee1-87/+51
This patch updates all tests to use to use the opaque pointers. Differential Revision: https://reviews.llvm.org/D147599
2023-03-23[OpenMP][OMPIRBuilder] Make OffloadEntriesInfoManager a member of ↵Jan Sjodin1-2/+3
OpenMPIRBuilder This patch adds the OffloadEntriesInfoManager to the OpenMPIRBuilder, and allows the OffloadEntriesInfoManager to access the Configuration in the OpenMPIRBuilder. With the shared Config there is no risk for inconsistencies, and there is no longer the need for clang to have a separate OffloadEntriesInfoManager. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D146549
2023-03-20[MLIR][OpenMP] Added OMPIRBuilder support for Target Data directivesAkash Banerjee1-0/+239
This patch adds OpenMP IRBuilder support for the Target Data directives to allow lowering to LLVM IR. The mlir::Translation is responsible for generating supporting code for processing the map_operands through the processMapOperand function, and also generate code for the r> The OMPIRBuilder is responsible for generating the begin and end mapper function calls. Limitations: - use_device_ptr and use_device_addr clauses are NOT supported for Target Data operation. - nowait clauses are NOT supported for Target Enter and Exit Data operations. - Only LLVMPointerType is supported for map_operands. Differential Revision: https://reviews.llvm.org/D142914
2023-01-20[OMPIRBuilder] Pass dependencies to createTask by valuePrabhdeep Singh Soni1-4/+6
This patch modifies OpenMPIRBuilder::createTask to accept its Dependencies vector by value instead of by reference. This is necessary because the PostOutlineCB lambda that uses this Dependencies vector may outlive the original Dependencies vector. Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D141651
2022-12-12[OpenMP][OMPIRBuilder] Migrate code to emit target region functions from ↵Jan Sjodin1-1/+1
clang to OMPIRBuilder This patch moves some of the logic on how to emit target region functions and adds emitTargetRegionFunction to the OpenMPIRBuilder. Also the OpenMPOffloadMandatory flag is added to the config. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D139634
2022-12-09[openmp][mlir] Lower parallel if to new fork_call_if function.David Truby1-24/+8
This patch adds a new runtime function `fork_call_if` and uses that to lower parallel if statements when going through OpenMPIRBuilder. This fixes an issue where the OpenMPIRBuilder passes all arguments to fork_call as a struct but this struct is not filled corretly in the non-if branch by handling the fork inside the runtime. Differential Revision: https://reviews.llvm.org/D138495
2022-12-04DebugInfoMetadata: convert Optional to std::optionalKrzysztof Parzyszek1-1/+2
2022-12-02[llvm/unittests] Use std::nullopt instead of None (NFC)Kazu Hirata1-4/+5
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-23[NFC] Replaced BB->getInstList().front() with BB->front()Vasileios Porpodas1-1/+1
Differential Revision: https://reviews.llvm.org/D138620
2022-11-22[OpenMP][OMPIRBuilder] Add a configuration class that captures flags that ↵Jan Sjodin1-3/+4
affect codegen This patch introudces the OpenMPIRBuilderConfig class which contains various flags that are needed to lower OMP constructs to LLVM-IR. The purpose is to keep the flags in one place so they do not have to be passed in every time. The flags can be set optionally since some uses cases don't rely on functions that depend on these flags. Reviewed By: jdoerfert, tschuett Differential Revision: https://reviews.llvm.org/D138220
2022-11-04Some uses of the preprocessor can result in multiple target regions on theMike Rice1-2/+2
same line. Cases such as those in the associated lit tests, can now be supported. This adds a 'Count' field to TargetRegionEntryInfo to differentiate regions with the same source position. The OffloadEntriesInfoManager routines are updated to maintain a count of regions seen at a location. The registration of regions proceeds that same as before, but now the next available count is always determined and used in the offload entry. Fixes: https://github.com/llvm/llvm-project/issues/52707 Differential Revision: https://reviews.llvm.org/D134816
2022-10-31[OpenMP] [OMPIRBuilder] Create a new datatype to hold the unique target ↵Jan Sjodin1-3/+4
region info Re-apply of: 3d0e9edd8e53fb72e85084f4170513159212839a Reverted in: 0cb65b0a585c8b3d4a8a2aefe994a8fc907934f8 A function parameter was using the wrong type 'llvm::TargetRegion' instead of 'const llvm:: TargetRegion&', which caused the error in the address sanitizer. The correct type is now used. This patch puts the individual target region information attributes into a struct so that the nested mappings are not needed and passing the information around is simplified. Reviewed By: jdoerfert, mikerice Differential Revision: https://reviews.llvm.org/D136601
2022-10-27Revert "[OpenMP] [OMPIRBuilder] Create a new datatype to hold the unique ↵Kevin Athey1-4/+3
target region info" This reverts commit 3d0e9edd8e53fb72e85084f4170513159212839a. Breaking HWASAN buildbot: https://lab.llvm.org/buildbot/#/builders/236/builds/786 Shown by targetted builds breaking at this patch: Built at this patch: https://lab.llvm.org/buildbot/#/builders/236/builds/803 Built at prior patch: https://lab.llvm.org/buildbot/#/builders/236/builds/804
2022-10-25[OpenMP] [OMPIRBuilder] Create a new datatype to hold the unique target ↵Jan Sjodin1-3/+4
region info This patch puts the individual target region information attributes into a struct so that the nested mappings are not needed and passing the information around is simplified. Reviewed By: jdoerfert, mikerice Differential Revision: https://reviews.llvm.org/D136601
2022-10-19[OMPIRBuilder] Support depend clause for taskPrabhdeep Singh Soni1-0/+75
This patch adds support for the `depend` clause for the `task` construct. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D135695
2022-10-18[OpenMP][OMPIRBuilder] Add generation of SIMD align assumptions to OMPIRBuilderDominik Adamski1-12/+79
Currently generation of align assumptions for OpenMP simd construct is done outside OMPIRBuilder for C code and it is not supported for Fortran. According to OpenMP 5.0 standard (2.9.3) only pointers and arrays can be aligned for C code. If given aligned variable is pointer, then Clang generates the following set of the LLVM IR isntructions to support simd align clause: ; memory allocation for pointer address: %A.addr = alloca ptr, align 8 ; some LLVM IR code ; Alignment instructions (alignment is equal to 32): %0 = load ptr, ptr %A.addr, align 8 call void @llvm.assume(i1 true) [ "align"(ptr %0, i64 32) ] If given aligned variable is array, then Clang generates the following set of the LLVM IR isntructions to support simd align clause: ; memory allocation for array: %B = alloca [10 x i32], align 16 ; some LLVM IR code ; Alignment instructions (alignment is equal to 32): %arraydecay = getelementptr inbounds [10 x i32], ptr %B, i64 0, i64 0 call void @llvm.assume(i1 true) [ "align"(ptr %arraydecay, i64 32) ] OMPIRBuilder was modified to generate aligned assumptions. It generates only llvm.assume calls. Frontend is responsible for generation of aligned pointer and getting the default alignment value if user does not specify it in aligned clause. Unit and regression tests were added to check if aligned clause was handled correctly. Differential Revision: https://reviews.llvm.org/D133578 Reviewed By: jdoerfert
2022-10-16[OpenMP][OpenMPIRBuilder] Migrate OffloadEntriesInfoManager from clang to ↵Jan Sjodin1-0/+15
OMPIRbuilder This patch moves the implementation of the OffloadEntriesInfoManager to the OMPIRbuilder. This class will later be used by flang as well. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D135786
2022-10-07[OpenMP][OMPIRBuilder] Remove calls to dump in testJan Sjodin1-4/+0
This removes the calls to dump tyupes introduced in commit 4627cef1134f99f3802a5ebfe26188d2c66da22f. Differential Revision: https://reviews.llvm.org/D134662
2022-10-07[OpenMP][OMPIRBuilder] Migrate emitOffloadingArraysArgument from clangJan Sjodin1-0/+51
This patch moves the emitOffloadingArraysArgument function and supporting data structures to OpenMPIRBuilder. This will later be used in flang as well. The TargetDataInfo class was split up into generic information and clang-specific data, which remain in clang. Further migration will be done in in the future. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D134662
2022-10-04[OpenMP][OMPIRBuilder] Add support for order(concurrent) to OMPIRBuilder for ↵Dominik Adamski1-5/+43
SIMD directive If 'order(concurrent)' clause is specified, then the iterations of SIMD loop can be executed concurrently. This patch adds support for LLVM IR codegen via OMPIRBuilder for SIMD loop with 'order(concurrent)' clause. The functionality added to OMPIRBuilder is similar to the functionality implemented in 'CodeGenFunction::EmitOMPSimdInit'. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D134046 Signed-off-by: Dominik Adamski <dominik.adamski@amd.com>
2022-09-23[OpenMP][IRBuilder] Added if clause to taskShraiysh Vaishay1-0/+65
This patch adds support for if clause to task construct in OpenMP IRBuilder. Reviewed By: raghavendhra Differential Revision: https://reviews.llvm.org/D130615
2022-08-18[OMPIRBuilder] Add support for safelen clausePrabhdeep Singh Soni1-4/+75
This patch adds OMPIRBuilder support for the safelen clause for the simd directive. Reviewed By: shraiysh, Meinersbur Differential Revision: https://reviews.llvm.org/D131526
2022-08-01Add support for lowering simd if clause to LLVM IRDominik Adamski1-2/+51
Scope of changes: 1) Added new function to generate loop versioning 2) Added support for if clause to applySimd function 2) Added tests which confirm that lowering is successful If ifCond is specified, then collapsed loop is duplicated and if branch is added. Duplicated loop is executed if simd ifCond is evaluated to false. Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D129368 Signed-off-by: Dominik Adamski <dominik.adamski@amd.com>