[all-commits] [llvm/llvm-project] 87ec6f: [OpenMPIRBuilder] Allocate temporary at the correc...

William Moses via All-commits all-commits at lists.llvm.org
Sun Mar 6 15:34:43 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 87ec6f41bba6d72a3408e71cf19ae56feff523bc
      https://github.com/llvm/llvm-project/commit/87ec6f41bba6d72a3408e71cf19ae56feff523bc
  Author: William S. Moses <gh at wsmoses.com>
  Date:   2022-03-06 (Sun, 06 Mar 2022)

  Changed paths:
    M clang/test/OpenMP/irbuilder_nested_openmp_parallel_empty.c
    M clang/test/OpenMP/irbuilder_nested_parallel_for.c
    M llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
    M llvm/include/llvm/Transforms/Utils/CodeExtractor.h
    M llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
    M llvm/lib/Transforms/IPO/HotColdSplitting.cpp
    M llvm/lib/Transforms/IPO/IROutliner.cpp
    M llvm/lib/Transforms/Utils/CodeExtractor.cpp
    A mlir/test/Target/LLVMIR/openmp-nested.mlir

  Log Message:
  -----------
  [OpenMPIRBuilder] Allocate temporary at the correct block in a nested parallel

The OpenMPIRBuilder has a bug. Specifically, suppose you have two nested openmp parallel regions (writing with MLIR for ease)

```
omp.parallel {
  %a = ...
  omp.parallel {
    use(%a)
  }
}
```

As OpenMP only permits pointer-like inputs, the builder will wrap all of the inputs into a stack allocation, and then pass this
allocation to the inner parallel. For example, we would want to get something like the following:

```
omp.parallel {
  %a = ...
  %tmp = alloc
  store %tmp[] = %a
  kmpc_fork(outlined, %tmp)
}
```

However, in practice, this is not what currently occurs in the context of nested parallel regions. Specifically to the OpenMPIRBuilder,
the entirety of the function (at the LLVM level) is currently inlined with blocks marking the corresponding start and end of each
region.

```
entry:
  ...

parallel1:
  %a = ...
  ...

parallel2:
  use(%a)
  ...

endparallel2:
  ...

endparallel1:
  ...
```

When the allocation is inserted, it presently inserted into the parent of the entire function (e.g. entry) rather than the parent
allocation scope to the function being outlined. If we were outlining parallel2, the corresponding alloca location would be parallel1.

This causes a variety of bugs, including https://github.com/llvm/llvm-project/issues/54165 as one example.

This PR allows the stack allocation to be created at the correct allocation block, and thus remedies such issues.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D121061




More information about the All-commits mailing list