[OpenMPIRBuilder] Detect and fix ambiguous InsertPoints for createParallel.
authorMichael Kruse <llvm-project@meinersbur.de>
Thu, 20 Jan 2022 14:18:08 +0000 (08:18 -0600)
committerMichael Kruse <llvm-project@meinersbur.de>
Thu, 20 Jan 2022 16:13:44 +0000 (10:13 -0600)
commit616f77172f0a48ef02c1700882ca0ba2215066d1
tree63bffb2228e66199e6ffa72cd039ce489330be72
parent91eca967b9eb115afda52e3a7d158a97a24bfe7f
[OpenMPIRBuilder] Detect and fix ambiguous InsertPoints for createParallel.

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
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp