[PATCH] D105246: [AbstractAttributor] Fold function calls to `__kmpc_is_spmd_exec_mode` if possible

Shilei Tian via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 30 16:35:39 PDT 2021


tianshilei1992 created this revision.
tianshilei1992 added reviewers: jdoerfert, JonChesterfield, ggeorgakoudis, jhuber6.
Herald added subscribers: ormris, okura, uenoku, hiraditya.
Herald added a reviewer: uenoku.
tianshilei1992 requested review of this revision.
Herald added a reviewer: sstefan1.
Herald added subscribers: llvm-commits, bbn, sstefan1.
Herald added a reviewer: baziotis.
Herald added a project: LLVM.

In the device runtime there are many function calls to `__kmpc_is_spmd_exec_mode`
to query the execution mode of current kernels. In many cases, user programs
only contain target region executing in one mode. As a consequence, those runtime
function calls will only return one value. If we can get rid of these function
calls during compliation, it can potentially improve performance.

In this patch, we use `AAKernelInfo` to analyze kernel execution. Basically, for
each kernel (device) function `F`, we collect all kernel entries `K` that can
reach `F`. In each iteration, we go through all reaching kernel entries and check
their execution mode. If `F` can only be reached by kernel entries with same mode,
we update a map from `CallBase *` to `Constant *` to corresponding value. In
`manifest` stage, if any entry of the map is not `nullptr`, which means the function
call can be folded to the `Constant *`, we replace all uses of the function call
and remove it.

Later we will also add more foldable functions, such as `isMainThread`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105246

Files:
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105246.355721.patch
Type: text/x-patch
Size: 10284 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210630/c41e6b47/attachment-0001.bin>


More information about the llvm-commits mailing list