-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WebAssembly] Move register stackification and coloring to a late phase.
Move the register stackification and coloring passes to run very late, after PEI, tail duplication, and most other passes. This means that all code emitted and expanded by those passes is now exposed to these passes. This also eliminates the need for prologue/epilogue code to be manually stackified, which significantly simplifies the code. This does require running LiveIntervals a second time. It's useful to think of these late passes not as late optimization passes, but as a domain-specific compression algorithm based on knowledge of liveness information. It's used to compress the code after all conventional optimizations are complete, which is why it uses LiveIntervals at a phase when actual optimization passes don't typically need it. Differential Revision: http://reviews.llvm.org/D20075 llvm-svn: 269012
- Loading branch information
Dan Gohman
committed
May 10, 2016
1 parent
31d19d4
commit 0cfb5f8
Showing
22 changed files
with
751 additions
and
401 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
llvm/lib/Target/WebAssembly/WebAssemblyOptimizeLiveIntervals.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| //===--- WebAssemblyOptimizeLiveIntervals.cpp - LiveInterval processing ---===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| /// | ||
| /// \file | ||
| /// \brief Optimize LiveIntervals for use in a post-RA context. | ||
| // | ||
| /// LiveIntervals normally runs before register allocation when the code is | ||
| /// only recently lowered out of SSA form, so it's uncommon for registers to | ||
| /// have multiple defs, and then they do, the defs are usually closely related. | ||
| /// Later, after coalescing, tail duplication, and other optimizations, it's | ||
| /// more common to see registers with multiple unrelated defs. This pass | ||
| /// updates LiveIntervalAnalysis to distribute the value numbers across separate | ||
| /// LiveIntervals. | ||
| /// | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "WebAssembly.h" | ||
| #include "WebAssemblySubtarget.h" | ||
| #include "llvm/CodeGen/LiveIntervalAnalysis.h" | ||
| #include "llvm/CodeGen/MachineBlockFrequencyInfo.h" | ||
| #include "llvm/CodeGen/MachineRegisterInfo.h" | ||
| #include "llvm/CodeGen/Passes.h" | ||
| #include "llvm/Support/Debug.h" | ||
| #include "llvm/Support/raw_ostream.h" | ||
| using namespace llvm; | ||
|
|
||
| #define DEBUG_TYPE "wasm-optimize-live-intervals" | ||
|
|
||
| namespace { | ||
| class WebAssemblyOptimizeLiveIntervals final : public MachineFunctionPass { | ||
| const char *getPassName() const override { | ||
| return "WebAssembly Optimize Live Intervals"; | ||
| } | ||
|
|
||
| void getAnalysisUsage(AnalysisUsage &AU) const override { | ||
| AU.setPreservesCFG(); | ||
| AU.addRequired<LiveIntervals>(); | ||
| AU.addPreserved<MachineBlockFrequencyInfo>(); | ||
| AU.addPreserved<SlotIndexes>(); | ||
| AU.addPreserved<LiveIntervals>(); | ||
| AU.addPreservedID(LiveVariablesID); | ||
| AU.addPreservedID(MachineDominatorsID); | ||
| MachineFunctionPass::getAnalysisUsage(AU); | ||
| } | ||
|
|
||
| bool runOnMachineFunction(MachineFunction &MF) override; | ||
|
|
||
| public: | ||
| static char ID; // Pass identification, replacement for typeid | ||
| WebAssemblyOptimizeLiveIntervals() : MachineFunctionPass(ID) {} | ||
| }; | ||
| } // end anonymous namespace | ||
|
|
||
| char WebAssemblyOptimizeLiveIntervals::ID = 0; | ||
| FunctionPass *llvm::createWebAssemblyOptimizeLiveIntervals() { | ||
| return new WebAssemblyOptimizeLiveIntervals(); | ||
| } | ||
|
|
||
| bool WebAssemblyOptimizeLiveIntervals::runOnMachineFunction(MachineFunction &MF) { | ||
| DEBUG(dbgs() << "********** Optimize LiveIntervals **********\n" | ||
| "********** Function: " | ||
| << MF.getName() << '\n'); | ||
|
|
||
| MachineRegisterInfo &MRI = MF.getRegInfo(); | ||
| LiveIntervals &LIS = getAnalysis<LiveIntervals>(); | ||
|
|
||
| // We don't preserve SSA form. | ||
| MRI.leaveSSA(); | ||
|
|
||
| assert(MRI.tracksLiveness() && | ||
| "OptimizeLiveIntervals expects liveness"); | ||
|
|
||
| // Split multiple-VN LiveIntervals into multiple LiveIntervals. | ||
| SmallVector<LiveInterval*, 4> SplitLIs; | ||
| for (unsigned i = 0, e = MRI.getNumVirtRegs(); i < e; ++i) { | ||
| unsigned Reg = TargetRegisterInfo::index2VirtReg(i); | ||
| if (MRI.reg_nodbg_empty(Reg)) | ||
| continue; | ||
|
|
||
| LIS.splitSeparateComponents(LIS.getInterval(Reg), SplitLIs); | ||
| SplitLIs.clear(); | ||
| } | ||
|
|
||
| // In PrepareForLiveIntervals, we conservatively inserted IMPLICIT_DEF | ||
| // instructions to satisfy LiveIntervals' requirement that all uses be | ||
| // dominated by defs. Now that LiveIntervals has computed which of these | ||
| // defs are actually needed and which are dead, remove the dead ones. | ||
| for (auto MII = MF.begin()->begin(), MIE = MF.begin()->end(); MII != MIE; ) { | ||
| MachineInstr *MI = &*MII++; | ||
| if (MI->isImplicitDef() && MI->getOperand(0).isDead()) { | ||
| LiveInterval &LI = LIS.getInterval(MI->getOperand(0).getReg()); | ||
| LIS.removeVRegDefAt(LI, LIS.getInstructionIndex(*MI).getRegSlot()); | ||
| LIS.RemoveMachineInstrFromMaps(*MI); | ||
| MI->eraseFromParent(); | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.