Commit 3db2c56
committed
[OpenMP][OMPIRBuilder] Collect users of a value before replacing them in target outlined function
This PR fixes a crash that curently happens given the following input:
```fortran
subroutine caller()
real :: x, y, z
integer :: i
!$omp target
x = i
call callee(x,x)
!$omp end target
endsubroutine caller
subroutine callee(x1,x2)
real :: x1, x2
endsubroutine callee
```
The crash happens because the following sequence of events is taken by
the `OMPIRBuilder`:
1. ....
n. An outlined function for the target region is created. At first the
outlined function still refers to the SSA values from the original
function of the target region.
n+1. The builder then iterates over the users of SSA values used in the
target region to replace them with the corresponding function arguments
of outlined function.
n+2. If the same instruction references the SSA value more than once (say m),
all uses of that SSA value are replaced in the instruction.
Deleting all m uses of the value.
n+3. The next m-1 iterations will still iterate over the same
instruction dropping the last m-1 actual users of the value.
Hence, we call all users first before modifying them.1 parent 5b8664f commit 3db2c56
File tree
2 files changed
+42
-1
lines changed- llvm/lib/Frontend/OpenMP
- mlir/test/Target/LLVMIR
2 files changed
+42
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7035 | 7035 | | |
7036 | 7036 | | |
7037 | 7037 | | |
| 7038 | + | |
| 7039 | + | |
| 7040 | + | |
| 7041 | + | |
7038 | 7042 | | |
7039 | | - | |
| 7043 | + | |
7040 | 7044 | | |
7041 | 7045 | | |
7042 | 7046 | | |
| |||
Lines changed: 37 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
0 commit comments