aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
AgeCommit message (Collapse)AuthorFilesLines
2022-07-19Fix signed/unsigned comparison mismatch warningSimon Pilgrim1-1/+1
2022-07-19[OpenMP][IRBuilder] Add support for taskgroupShraiysh Vaishay1-0/+171
This patch adds support for generating taskgroup construct. Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D128203
2022-07-11[OMPIRBuilder] Add support for simdlen clausePrabhdeep Singh Soni1-1/+33
This patch adds OMPIRBuilder support for the simdlen clause for the simd directive. It uses the simdlen support in OpenMPIRBuilder when it is enabled in Clang. Simdlen is lowered by OpenMPIRBuilder by generating the loop.vectorize.width metadata. Reviewed By: jdoerfert, Meinersbur Differential Revision: https://reviews.llvm.org/D129149
2022-06-16Add braces to silence a gcc 9.4 -Wdangling-else warning [nfc]Philip Reames1-1/+2
2022-06-13[NFC][Alignment] Use proper type in testsGuillaume Chatelet1-2/+2
2022-06-11[OpenMP][IRBuilder] Add final clause to taskShraiysh Vaishay1-0/+53
This patch adds final clause to OpenMP IR Builder. Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D126626
2022-06-02[IR] Enable opaque pointers by defaultNikita Popov1-0/+1
This enabled opaque pointers by default in LLVM. The effect of this is twofold: * If IR that contains *neither* explicit ptr nor %T* types is passed to tools, we will now use opaque pointer mode, unless -opaque-pointers=0 has been explicitly passed. * Users of LLVM as a library will now default to opaque pointers. It is possible to opt-out by calling setOpaquePointers(false) on LLVMContext. A cmake option to toggle this default will not be provided. Frontends or other tools that want to (temporarily) keep using typed pointers should disable opaque pointers via LLVMContext. Differential Revision: https://reviews.llvm.org/D126689
2022-06-01[OMPIRBuilder] Add the support for compare captureShilei Tian1-6/+260
This patch adds the support for `compare capture` in `OMPIRBuilder`. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D120007
2022-05-24[OpenMP][IRBuilder] `omp task` supportShraiysh Vaishay1-0/+165
This patch adds basic support for `omp task` 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 for task allocation. 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. Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D71989
2022-04-26[OpenMPIRBuilder] Remove ContinuationBB argument from Body callback.Michael Kruse1-94/+30
The callback is expected to create a branch to the ContinuationBB (sometimes called FiniBB in some lambdas) argument when finishing. This creates problems: 1. The InsertPoint used for CodeGenIP does not need to be the end of a block. If it is not, a naive callback will insert a branch instruction into the middle of the block. 2. The BasicBlock the CodeGenIP is pointing to may or may not have a terminator. There is an conflict where to branch to if the block already has a terminator. 3. Some API functions work only with block having a terminator. Some workarounds have been used to insert a temporary terminator that is removed again. 4. Some callbacks are sensitive to whether the BasicBlock has a terminator or not. This creates a callback ordering problem where different callback may have different behaviour depending on whether a previous callback created a terminator or not. The problem also exists for FinalizeCallbackTy where some callbacks do create branch to another "continue" block, but unlike BodyGenCallbackTy does not receive the target as argument. This is not addressed in this patch. With this patch, the callback receives an CodeGenIP into a BasicBlock where to insert instructions. If it has to insert control flow, it can split the block at that position as needed but otherwise no separate ContinuationBB is needed. In particular, a callback can be empty without breaking the emitted IR. If the caller needs the control flow to branch to a specific target, it can insert the branch instruction itself and pass an InsertPoint before the terminator to the callback. Certain frontends such as Clang may expect the current IRBuilder position to be at the end of a basic block. In this case its callbacks must split the block at CodeGenIP before setting the IRBuilder position such that the instructions after CodeGenIP are moved to another basic block and before returning create a new branch instruction to the split block. Some utility functions such as `splitBB` are supporting correct splitting of BasicBlocks, independent of whether they have a terminator or not, returning/setting the InsertPoint of an IRBuilder to the end of split predecessor block, and optionally omitting creating a branch to the split successor block to be added later. Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D118409
2022-04-25[OpenMP][IRBuilder] Handle unexcuted EXPECT_FALSEShraiysh Vaishay1-3/+8
This patch addresses the comment about unexecuted test in D122371. Reviewed By: probinson Differential Revision: https://reviews.llvm.org/D123920
2022-04-18Reapply "[OpenMP] Refactor OMPScheduleType enum."Michael Kruse1-29/+63
This reverts commit af0285122f306573d9bcc4c4ad7f904cfdd4d869. The test "libomp::loop_dispatch.c" on builder openmp-gcc-x86_64-linux-debian fails from time-to-time. See #54969. This patch is unrelated.
2022-04-18Revert "[OpenMP] Refactor OMPScheduleType enum."Michael Kruse1-63/+29
This reverts commit 9ec501da76fc1559cadd6d6dac32766bf4376a3d. It may have caused the openmp-gcc-x86_64-linux-debian buildbot to fail. https://lab.llvm.org/buildbot/#/builders/4/builds/20377
2022-04-18[OpenMP] Refactor OMPScheduleType enum.Michael Kruse1-29/+63
The OMPScheduleType enum stores the constants from libomp's internal sched_type in kmp.h and are used by several kmp API functions. The enum values have an internal structure, namely each scheduling algorithm (e.g.) exists in four variants: unordered, orderend, normerge unordered, and nomerge ordered. This patch (basically a followup to D114940) splits the "ordered" and "nomerge" bits into separate flags, as was already done for the "monotonic" and "nonmonotonic", so we can apply bit flags operations on them. It also now contains all possible combinations according to kmp's sched_type. Deriving of the OMPScheduleType enum from clause parameters has been moved form MLIR's OpenMPToLLVMIRTranslation.cpp to OpenMPIRBuilder to make available for clang as well. Since the primary purpose of the flag is the binary interface to libomp, it has been made more private to LLVMFrontend. The primary interface for generating worksharing-loop using OpenMPIRBuilder code becomes `applyWorkshareLoop` which derives the OMPScheduleType automatically and calls the appropriate emitter function. While this is mostly a NFC refactor, it still applies the following functional changes: * The logic from OpenMPToLLVMIRTranslation to derive the OMPScheduleType also applies to clang. Most notably, it now applies the nonmonotonic flag for non-static schedules by default. * In OpenMPToLLVMIRTranslation, the nonmonotonic default flag was previously not applied if the simd modifier was used. I assume this was a bug, since the effect was due to `loop.schedule_modifier()` returning `mlir::omp::ScheduleModifier::none` instead of `llvm::Optional::None`. * In OpenMPToLLVMIRTranslation, the nonmonotonic default flag was set even if ordered was specified, in breach to what the comment before citing the OpenMP specification says. I assume this was an oversight. The ordered flag with parameter was not considered in this patch. Changes will need to be made (e.g. adding/modifying function parameters) when support for it is added. The lengthy names of the enum values can be discussed, for the moment this is avoiding reusing previously existing enum value names such as `StaticChunked` to avoid confusion. Reviewed By: peixin Differential Revision: https://reviews.llvm.org/D123403
2022-04-05[OpenMPIRBuilder] Detect and fix ambiguous InsertPoints for createSections.Michael Kruse1-0/+9
Follow-up on D117226 for createSections. Reviewed By: shraiysh Differential Revision: https://reviews.llvm.org/D117835
2022-04-01[OMPIRBuilder] Remove unused variable in test (NFC)Adrian Kuegel1-1/+0
2022-04-01[OMPIRBuilder] Support ordered clause specified without parameterPeixin-Qiao1-1/+84
This patch supports ordered clause specified without parameter in worksharing-loop directive in the OpenMPIRBuilder and lowering MLIR to LLVM IR. Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D114940
2022-03-24[mlir][OpenMP][IRBuilder] Add support for nowait on single constructShraiysh Vaishay1-2/+102
This patch adds the nowait parameter to `createSingle` in OpenMPIRBuilder and handling for IR generation from OpenMP Dialect. Also added tests for the same. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D122371
2022-03-21[OpenMP][IRBuilder] Fix emitAtomicUpdate conditionsShraiysh Vaishay1-0/+67
This patch fixes the condition for emitting atomic update using `atomicrmw` instruction or compare-exchange loop. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D121546
2022-02-28[test] Silence compiler warning.Michael Kruse1-1/+1
signed/unsigned comparison in gtest macro. Also fix buidlbots: https://lab.llvm.org/buildbot#builders/36/builds/18337 https://lab.llvm.org/buildbot#builders/57/builds/15594
2022-02-28[OpenMPIRBuilder] Implement static-chunked workshare-loop schedules.Michael Kruse1-23/+120
Add applyStaticChunkedWorkshareLoop method implementing static schedule when chunk-size is specified. Unlike a static schedule without chunk-size (where chunk-size is chosen by the runtime such that each thread receives one chunk), we need two nested loops: one for looping over the iterations of a chunk, and a second for looping over all chunks assigned to the threads. This patch includes the following related changes: * Adapt applyWorkshareLoop to triage between the schedule types, now possible since all schedules have been implemented. The default schedule is assumed to be non-chunked static, as without OpenMPIRBuilder. * Remove the chunk parameter from applyStaticWorkshareLoop, it is ignored by the runtime. Change the value for the value passed to the init function to 0, as without OpenMPIRBuilder. * Refactor CanonicalLoopInfo::setTripCount and CanonicalLoopInfo::mapIndVar as used by both, applyStaticWorkshareLoop and applyStaticChunkedWorkshareLoop. * Enable Clang to use the OpenMPIRBuilder in the presence of the schedule clause. Differential Revision: https://reviews.llvm.org/D114413
2022-02-10[OpenMP][IRBuilder] Handle floats for atomic update and fix AllocaIP for ↵Shraiysh Vaishay1-4/+78
update/capture This patch fixes `createAtomicUpdate` for lowering with float types. Test added for the same. This patch also changes the alloca argument for createAtomicUpdate and createAtomicCapture from `Instruction*` to `InsertPointTy`. This is in line with the other functions of the OpenMPIRBuilder class which take AllocaIP as an `InsertPointTy`. Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D118227
2022-02-08[OpenMPIRBuilderTest] Remove getPointerElementType() uses (NFC)Nikita Popov1-4/+4
Use the type of the stored value instead.
2022-02-02[OMPIRBuilder] Add support for atomic compareShilei Tian1-0/+57
This patch adds the support for `atomic compare` in `OMPIRBuilder`. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D118547
2022-01-28[OpenMPIRBuilder] Store element type in AtomicOpValueNikita Popov1-9/+9
With opaque pointers, we can no longer derive this from the pointer type, so we need to explicitly provide the element type the atomic operation should work with. Differential Revision: https://reviews.llvm.org/D118359
2022-01-26[OpenMPIRBuilderTest] Avoid pointer element type accessNikita Popov1-1/+2
This was reintroduced by D110114.
2022-01-25[OMPIRBuilder] Generate aggregate argument for parallel region outlined ↵Giorgis Georgakoudis1-22/+72
functions Summary: This patch modifies code generation in OpenMPIRBuilder to pass arguments to the parallel region outlined function in an aggregate (struct), besides the global_tid and bound_tid arguments. It depends on the updated CodeExtractor (see D96854) for support. It mirrors functionality of Clang codegen (see D102107). Differential Revision: https://reviews.llvm.org/D110114
2022-01-25[OpenMPIRBuilderTest] Avoid some pointer element type accesses (NFC)Nikita Popov1-10/+10
Use isOpaqueOrPointeeTypeMatches() instead, where possible.
2022-01-20[OpenMPIRBuilder] Detect and fix ambiguous InsertPoints for createParallel.Michael Kruse1-0/+23
When a Builder methods accepts multiple InsertPoints, when both point to the same position, inserting instructions at one position will "move" the other after the inserted position since the InsertPoint is pegged to the instruction following the intended InsertPoint. For instance, when creating a parallel region at Loc and passing the same position as AllocaIP, creating instructions at Loc will "move" the AllocIP behind the Loc position. To avoid this ambiguity, add an assertion checking this condition and fix the unittests. In case of AllocaIP, an alternative solution could be to implicitly split BasicBlock at InsertPoint, using the first as AllocaIP, the second for inserting the instructions themselves. However, this solution is specific to AllocaIP since AllocaIP will always have to be first. Hence, this is an argument to generally handling ambiguous InsertPoints as API sage error. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D117226
2022-01-19[OMPIRBuilder] Add support for simd (loop) directive.Arnamoy Bhattacharyya1-0/+31
This patch adds OMPIRBuilder support for the simd directive (without any clause). This will be a first step towards lowering simd directive in LLVM_Flang. The patch uses existing CanonicalLoop infrastructure of IRBuilder to add the support. Also adds necessary code to add llvm.access.group and llvm.loop metadata wherever needed. Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D114379
2022-01-14[NFC] Apply the fix for different signedness warning in OpenMPIRBuilderTest.cppPeixin-Qiao1-2/+2
Differential Revision: https://reviews.llvm.org/D116300
2022-01-14[OMPIRBuilder] Fix store inst alignment for ordered depend directivePeixin-Qiao1-0/+2
OpenMP runtime requires depend vec with i64 type and the alignment of store instruction should be set as 8. Reviewed By: kiranchandramohan, shraiysh Differential Revision: https://reviews.llvm.org/D116300
2021-12-29Reapply "[OpenMP][NFCI] Embed the source location string size in the ident_t"Johannes Doerfert1-37/+46
This reverts commit 73ece231ee0cf048d56841f47915beb1db6afc26 and reapplies 7bfcdbcbf368cea14a5236080af975d5878a46eb with mlir changes. Also reverts commit 423ba12971bac8397c87fcf975ba6a4b7530ed28 and includes the unit test changes of 16da2140045808b2aea1d28366ca7d326eb3c809.
2021-12-29Revert "[OpenMP][FIX] Also update unit test after API change"Mehdi Amini1-46/+37
This reverts commit 16da2140045808b2aea1d28366ca7d326eb3c809. Revert unit-test API update after previous revert of the API change.
2021-12-29[OpenMP][FIX] Also update unit test after API changeJohannes Doerfert1-37/+46
2021-12-15[mlir][OpenMP] omp.sections and omp.section lowering to LLVM IRShraiysh Vaishay1-0/+28
This patch adds lowering from omp.sections and omp.section (simple lowering along with the nowait clause) to LLVM IR. Tests for the same are also added. Reviewed By: ftynse, kiranchandramohan Differential Revision: https://reviews.llvm.org/D115030
2021-12-14[OpenMPIRBuilder] Support opaque pointers in reduction handlingNikita Popov1-26/+22
Make the reduction handling in OpenMPIRBuilder compatible with opaque pointers by explicitly storing the element type in ReductionInfo, and also passing it to the atomic reduction callback, as at least the ones in the test need the type there. This doesn't make things fully compatible yet, there are other uses of element types in this class. I also left one getPointerElementType() call in mlir, because I'm not familiar with that area. Differential Revison: https://reviews.llvm.org/D115638
2021-12-01[OpenMP][IRBuilder] Fix createSectionsShraiysh Vaishay1-0/+32
Fix for the case when there are no instructions in the entry basic block before the call to `createSections` Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D114143
2021-10-05[llvm] Migrate from getNumArgOperands to arg_size (NFC)Kazu Hirata1-33/+33
Note that getNumArgOperands is considered a legacy name. See llvm/include/llvm/IR/InstrTypes.h for details.
2021-09-04[OpenMP][OpenMPIRBuilder] Implement loop unrolling.Michael Kruse1-22/+118
Recommit of 707ce34b06190e275572c3c46843036db1bab6d1. Don't introduce a dependency to the LLVMPasses component, instead register the required passes individually. Add methods for loop unrolling to the OpenMPIRBuilder class and use them in Clang if `-fopenmp-enable-irbuilder` is enabled. The unrolling methods are: * `unrollLoopFull` * `unrollLoopPartial` * `unrollLoopHeuristic` `unrollLoopPartial` and `unrollLoopHeuristic` can use compiler heuristics to automatically determine the unroll factor. If possible, that is if no CanonicalLoopInfo is required to pass to another method, metadata for LLVM's LoopUnrollPass is added. Otherwise the unroll factor is determined using the same heurstics as user by LoopUnrollPass. Not requiring a CanonicalLoopInfo, especially with `unrollLoopHeuristic` allows greater flexibility. With full unrolling and partial unrolling with known unroll factor, instead of duplicating instructions by the OpenMPIRBuilder, the full unroll is still delegated to the LoopUnrollPass. In case of partial unrolling the loop is first tiled using the existing `tileLoops` methods, then the inner loop fully unrolled using the same mechanism. Reviewed By: jdoerfert, kiranchandramohan Differential Revision: https://reviews.llvm.org/D107764
2021-09-03[OMPIRBuilder] Add ordered directive to OMPBuilderPeixinQiao1-0/+314
Add support for ordered directive in the OpenMPIRBuilder. This patch also modidies clang to use the ordered directive when the option -fopenmp-enable-irbuilder is enabled. Also fix one ICE when parsing one canonical for loop with the relational operator LE or GE in openmp region by replacing unary increment operation of the expression of the variable "Expr A" minus the variable "Expr B" (++(Expr A - Expr B)) with binary addition operation of the experssion of the variable "Expr A" minus the variable "Expr B" and the expression with constant value "1" (Expr A - Expr B + "1"). Reviewed By: Meinersbur, kiranchandramohan Differential Revision: https://reviews.llvm.org/D107430
2021-09-02Revert "[OpenMP][OpenMPIRBuilder] Implement loop unrolling."Roman Lebedev1-118/+22
Breaks build with -DBUILD_SHARED_LIBS=ON ``` CMake Error: The inter-target dependency graph contains the following strongly connected component (cycle): "LLVMFrontendOpenMP" of type SHARED_LIBRARY depends on "LLVMPasses" (weak) "LLVMipo" of type SHARED_LIBRARY depends on "LLVMFrontendOpenMP" (weak) "LLVMCoroutines" of type SHARED_LIBRARY depends on "LLVMipo" (weak) "LLVMPasses" of type SHARED_LIBRARY depends on "LLVMCoroutines" (weak) depends on "LLVMipo" (weak) At least one of these targets is not a STATIC_LIBRARY. Cyclic dependencies are allowed only among static libraries. CMake Generate step failed. Build files cannot be regenerated correctly. ``` This reverts commit 707ce34b06190e275572c3c46843036db1bab6d1.
2021-09-02[OpenMP][OpenMPIRBuilder] Implement loop unrolling.Michael Kruse1-22/+118
Add methods for loop unrolling to the OpenMPIRBuilder class and use them in Clang if `-fopenmp-enable-irbuilder` is enabled. The unrolling methods are: * `unrollLoopFull` * `unrollLoopPartial` * `unrollLoopHeuristic` `unrollLoopPartial` and `unrollLoopHeuristic` can use compiler heuristics to automatically determine the unroll factor. If possible, that is if no CanonicalLoopInfo is required to pass to another method, metadata for LLVM's LoopUnrollPass is added. Otherwise the unroll factor is determined using the same heurstics as user by LoopUnrollPass. Not requiring a CanonicalLoopInfo, especially with `unrollLoopHeuristic` allows greater flexibility. With full unrolling and partial unrolling with known unroll factor, instead of duplicating instructions by the OpenMPIRBuilder, the full unroll is still delegated to the LoopUnrollPass. In case of partial unrolling the loop is first tiled using the existing `tileLoops` methods, then the inner loop fully unrolled using the same mechanism. Reviewed By: jdoerfert, kiranchandramohan Differential Revision: https://reviews.llvm.org/D107764
2021-08-12[OMPIRBuilder] Clarify CanonicalLoopInfo. NFC.Michael Kruse1-14/+19
Add in-source documentation on how CanonicalLoopInfo is intended to be used. In particular, clarify what parts of a CanonicalLoopInfo is considered part of the loop, that those parts must be side-effect free, and that InsertPoints to instructions outside those parts can be expected to be preserved after method calls implementing loop-associated directives. CanonicalLoopInfo are now invalidated after it does not describe canonical loop anymore and asserts when trying to use it afterwards. In addition, rename `createXYZWorkshareLoop` to `applyXYZWorkshareLoop` and remove the update location to avoid that the impression that they insert something from scratch at that location where in reality its InsertPoint is ignored. createStaticWorkshareLoop does not return a CanonicalLoopInfo anymore. First, it was not a canonical loop in the clarified sense (containing side-effects in form of calls to the OpenMP runtime). Second, it is ambiguous which of the two possible canonical loops it should actually return. It will not be needed before a feature expected to be introduced in OpenMP 6.0 Also see discussion in D105706. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D107540
2021-07-30[OMPIRBuilder] add minimalist reduction supportAlex Zinenko1-9/+564
This introduces a builder function for emitting IR performing reductions in OpenMP. Reduction variable privatization and initialization to the reduction-neutral value is expected to be handled separately. The caller provides the reduction functions. Further commits can provide implementation of reduction functions for the reduction operators defined in the OpenMP specification. This implementation was tested on an MLIR fork targeting OpenMP from C and produced correct executable code. Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D104928
2021-07-27[mlir][openacc] Initial translation for DataOp to LLVM IRValentin Clement1-0/+106
Add basic translation of acc.data to LLVM IR with runtime calls. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D104301
2021-06-04[OPENMP]Fix PR50129: omp cancel parallel not working as expected.Alexey Bataev1-4/+30
Need to emit a call for __kmpc_cancel_barrier in the exit block for __kmpc_cancel function call if cancellation of the parallel block is requested. Differential Revision: https://reviews.llvm.org/D103646
2021-05-27[OpenMP]Add support for workshare loop modifier in loweringMats Petersson1-9/+21
When lowering the dynamic, guided, auto and runtime types of scheduling, there is an optional monotonic or non-monotonic modifier. This patch adds support in the OMP IR Builder to pass this down to the runtime functions. Also implements tests for the variants. Differential Revision: https://reviews.llvm.org/D102008
2021-05-27Revert "[OpenMP]Add support for workshare loop modifier in lowering"Mats Petersson1-21/+9
This reverts commit ea4c5fb04c6d9618d451fb2d2c360dc95c6d9131.
2021-05-27[OpenMP]Add support for workshare loop modifier in loweringMats Petersson1-9/+21
When lowering the dynamic, guided, auto and runtime types of scheduling, there is an optional monotonic or non-monotonic modifier. This patch adds support in the OMP IR Builder to pass this down to the runtime functions. Also implements tests for the variants. Differential Revision: https://reviews.llvm.org/D102008