[ModuloSchedule] Peel out prologs and epilogs, generate actual code
authorJames Molloy <jmolloy@google.com>
Wed, 2 Oct 2019 12:46:44 +0000 (12:46 +0000)
committerJames Molloy <jmolloy@google.com>
Wed, 2 Oct 2019 12:46:44 +0000 (12:46 +0000)
commit9026518e7398eeced1f07f5f6003ba047209c033
tree003cd7a5581a310d3f737ef01cf107b5d92ef5a3
parent671fb3435862899db32ed20e680ded2ee665effd
[ModuloSchedule] Peel out prologs and epilogs, generate actual code

Summary:
This extends the PeelingModuloScheduleExpander to generate prolog and epilog code,
and correctly stitch uses through the prolog, kernel, epilog DAG.

The key concept in this patch is to ensure that all transforms are *local*; only a
function of a block and its immediate predecessor and successor. By defining the problem in this way
we can inductively rewrite the entire DAG using only local knowledge that is easy to
reason about.

For example, we assume that all prologs and epilogs are near-perfect clones of the
steady-state kernel. This means that if a block has an instruction that is predicated out,
we can redirect all users of that instruction to that equivalent instruction in our
immediate predecessor. As all blocks are clones, every instruction must have an equivalent in
every other block.

Similarly we can make the assumption by construction that if a value defined in a block is used
outside that block, the only possible user is its immediate successors. We maintain this
even for values that are used outside the loop by creating a limited form of LCSSA.

This code isn't small, but it isn't complex.

Enabled a bunch of testing from Hexagon. There are a couple of tests not enabled yet;
I'm about 80% sure there isn't buggy codegen but the tests are checking for patterns
that we don't produce. Those still need a bit more investigation. In the meantime we
(Google) are happy with the code produced by this on our downstream SMS implementation,
and believe it generates correct code.

Subscribers: mgorny, hiraditya, jsji, llvm-commits

Tags: #llvm

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

llvm-svn: 373462
61 files changed:
llvm/include/llvm/CodeGen/MachineLoopUtils.h [new file with mode: 0644]
llvm/include/llvm/CodeGen/ModuloSchedule.h
llvm/lib/CodeGen/CMakeLists.txt
llvm/lib/CodeGen/MachineLoopUtils.cpp [new file with mode: 0644]
llvm/lib/CodeGen/MachinePipeliner.cpp
llvm/lib/CodeGen/ModuloSchedule.cpp
llvm/test/CodeGen/Hexagon/pipeliner/swp-phi-start.mir
llvm/test/CodeGen/Hexagon/swp-art-deps-rec.ll
llvm/test/CodeGen/Hexagon/swp-bad-sched.ll
llvm/test/CodeGen/Hexagon/swp-carried-1.ll
llvm/test/CodeGen/Hexagon/swp-carried-dep1.mir
llvm/test/CodeGen/Hexagon/swp-carried-dep2.mir
llvm/test/CodeGen/Hexagon/swp-chain-refs.ll
llvm/test/CodeGen/Hexagon/swp-change-dep1.ll
llvm/test/CodeGen/Hexagon/swp-change-deps.ll
llvm/test/CodeGen/Hexagon/swp-check-offset.ll
llvm/test/CodeGen/Hexagon/swp-const-tc1.ll
llvm/test/CodeGen/Hexagon/swp-const-tc2.ll
llvm/test/CodeGen/Hexagon/swp-const-tc3.ll
llvm/test/CodeGen/Hexagon/swp-conv3x3-nested.ll
llvm/test/CodeGen/Hexagon/swp-copytophi-dag.ll
llvm/test/CodeGen/Hexagon/swp-dep-neg-offset.ll
llvm/test/CodeGen/Hexagon/swp-disable-Os.ll
llvm/test/CodeGen/Hexagon/swp-epilog-numphis.ll
llvm/test/CodeGen/Hexagon/swp-epilog-phi2.ll
llvm/test/CodeGen/Hexagon/swp-epilog-phi4.ll
llvm/test/CodeGen/Hexagon/swp-epilog-phi5.ll
llvm/test/CodeGen/Hexagon/swp-epilog-phi8.ll
llvm/test/CodeGen/Hexagon/swp-kernel-phi1.ll
llvm/test/CodeGen/Hexagon/swp-large-rec.ll
llvm/test/CodeGen/Hexagon/swp-listen-loop3.ll
llvm/test/CodeGen/Hexagon/swp-loop-carried-unknown.ll
llvm/test/CodeGen/Hexagon/swp-lots-deps.ll
llvm/test/CodeGen/Hexagon/swp-max.ll
llvm/test/CodeGen/Hexagon/swp-maxstart.ll
llvm/test/CodeGen/Hexagon/swp-memrefs-epilog.ll
llvm/test/CodeGen/Hexagon/swp-multi-loops.ll
llvm/test/CodeGen/Hexagon/swp-new-phi.ll
llvm/test/CodeGen/Hexagon/swp-order-copies.ll
llvm/test/CodeGen/Hexagon/swp-order-deps7.ll
llvm/test/CodeGen/Hexagon/swp-order.ll
llvm/test/CodeGen/Hexagon/swp-phi-ch-offset.ll
llvm/test/CodeGen/Hexagon/swp-phi-chains.ll
llvm/test/CodeGen/Hexagon/swp-phi-dep.ll
llvm/test/CodeGen/Hexagon/swp-phi-ref.ll
llvm/test/CodeGen/Hexagon/swp-pragma-disable.ii
llvm/test/CodeGen/Hexagon/swp-pragma-initiation-interval.ii
llvm/test/CodeGen/Hexagon/swp-prolog-phi.ll
llvm/test/CodeGen/Hexagon/swp-rename.ll
llvm/test/CodeGen/Hexagon/swp-resmii-1.ll
llvm/test/CodeGen/Hexagon/swp-resmii.ll
llvm/test/CodeGen/Hexagon/swp-reuse-phi-6.ll
llvm/test/CodeGen/Hexagon/swp-sigma.ll
llvm/test/CodeGen/Hexagon/swp-stages4.ll
llvm/test/CodeGen/Hexagon/swp-stages5.ll
llvm/test/CodeGen/Hexagon/swp-subreg.ll
llvm/test/CodeGen/Hexagon/swp-swap.ll
llvm/test/CodeGen/Hexagon/swp-tfri.ll
llvm/test/CodeGen/Hexagon/swp-vect-dotprod.ll
llvm/test/CodeGen/Hexagon/swp-vmult.ll
llvm/test/CodeGen/Hexagon/swp-vsum.ll