[all-commits] [llvm/llvm-project] 1ed65f: [SPIR-V] Add SPIR-V structurizer (#107408)

Nathan Gauër via All-commits all-commits at lists.llvm.org
Fri Sep 20 02:37:04 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 1ed65febd996eaa018164e880c87a9e9afc6f68d
      https://github.com/llvm/llvm-project/commit/1ed65febd996eaa018164e880c87a9e9afc6f68d
  Author: Nathan Gauër <brioche at google.com>
  Date:   2024-09-20 (Fri, 20 Sep 2024)

  Changed paths:
    A clang/test/CodeGenHLSL/convergence/cf.for.plain.hlsl
    M llvm/include/llvm/IR/IntrinsicsSPIRV.td
    M llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp
    M llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.h
    M llvm/lib/Target/SPIRV/CMakeLists.txt
    M llvm/lib/Target/SPIRV/SPIRV.h
    M llvm/lib/Target/SPIRV/SPIRVInstrInfo.td
    M llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
    M llvm/lib/Target/SPIRV/SPIRVMergeRegionExitTargets.cpp
    M llvm/lib/Target/SPIRV/SPIRVPostLegalizer.cpp
    M llvm/lib/Target/SPIRV/SPIRVPreLegalizer.cpp
    M llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp
    A llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp
    M llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
    M llvm/lib/Target/SPIRV/SPIRVUtils.cpp
    M llvm/lib/Target/SPIRV/SPIRVUtils.h
    M llvm/test/CMakeLists.txt
    M llvm/test/CodeGen/SPIRV/branching/OpSwitchBranches.ll
    M llvm/test/CodeGen/SPIRV/branching/OpSwitchUnreachable.ll
    M llvm/test/CodeGen/SPIRV/branching/Two_OpSwitch_same_register.ll
    M llvm/test/CodeGen/SPIRV/branching/if-merging.ll
    M llvm/test/CodeGen/SPIRV/branching/if-non-merging.ll
    M llvm/test/CodeGen/SPIRV/branching/switch-range-check.ll
    M llvm/test/CodeGen/SPIRV/instructions/ret-type.ll
    M llvm/test/CodeGen/SPIRV/lit.local.cfg
    M llvm/test/CodeGen/SPIRV/phi-ptrcast-dominate.ll
    R llvm/test/CodeGen/SPIRV/scfg-add-pre-headers.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.cond-op.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.do.break.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.do.continue.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.do.nested.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.for.break.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.for.continue.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.for.nested.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.for.plain.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.for.short-circuited-cond.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.if.const-cond.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.if.for.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.if.nested.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.if.plain.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.logical-and.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.logical-or.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.return.early.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.return.early.simple.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.return.void.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.switch.ifstmt.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.switch.ifstmt.simple.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.switch.ifstmt.simple2.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.switch.opswitch.literal.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.switch.opswitch.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.switch.opswitch.simple.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.while.break.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.while.continue.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.while.nested.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.while.plain.ll
    A llvm/test/CodeGen/SPIRV/structurizer/cf.while.short-circuited-cond.ll
    A llvm/test/CodeGen/SPIRV/structurizer/condition-linear.ll
    A llvm/test/CodeGen/SPIRV/structurizer/do-break.ll
    A llvm/test/CodeGen/SPIRV/structurizer/do-continue.ll
    A llvm/test/CodeGen/SPIRV/structurizer/do-nested.ll
    A llvm/test/CodeGen/SPIRV/structurizer/do-plain.ll
    A llvm/test/CodeGen/SPIRV/structurizer/logical-or.ll
    M llvm/test/CodeGen/SPIRV/structurizer/merge-exit-break.ll
    M llvm/test/CodeGen/SPIRV/structurizer/merge-exit-convergence-in-break.ll
    M llvm/test/CodeGen/SPIRV/structurizer/merge-exit-multiple-break.ll
    M llvm/test/CodeGen/SPIRV/structurizer/merge-exit-simple-while-identity.ll
    A llvm/test/CodeGen/SPIRV/structurizer/return-early.ll
    M llvm/tools/spirv-tools/CMakeLists.txt

  Log Message:
  -----------
  [SPIR-V] Add SPIR-V structurizer (#107408)

This commit adds an initial SPIR-V structurizer.
It leverages the previously merged passes, and the convergence region
analysis to determine the correct merge and continue blocks for SPIR-V.

The first part does a branch cleanup (simplifying switches, and
legalizing them), then merge instructions are added to cycles,
convergent and later divergent blocks.
Then comes the important part: splitting critical edges, and making sure
the divergent construct boundaries don't cross.

- we split blocks with multiple headers into 2 blocks.
- we split blocks that are a merge blocks for 2 or more constructs:
SPIR-V spec disallow a merge block to be shared by 2
loop/switch/condition construct.
- we split merge & continue blocks: SPIR-V spec disallow a basic block
to be both a continue block, and a merge block.
- we remove superfluous headers: when a header doesn't bring more info
than the parent on the divergence state, it must be removed.

This PR leverages the merged SPIR-V simulator for testing, as long as
spirv-val. For now, most DXC structurization tests are passing. The
unsupported ones are either caused by unsupported features like switches
on boolean types, or switches in region exits, because the MergeExit
pass doesn't support those yet (there is a FIXME).

This PR is quite large, and the addition not trivial, so I tried to keep
it simple. E.G: as soon as the CFG changes, I recompute the dominator
trees and other structures instead of updating them.

---------

Signed-off-by: Nathan Gauër <brioche at google.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list