2010-10-07 20:41:20 +02:00
|
|
|
//===-- CodeGen.cpp -------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the common initialization routines for the
|
|
|
|
// CodeGen library.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/InitializePasses.h"
|
|
|
|
#include "llvm-c/Initialization.h"
|
2014-01-07 12:48:04 +01:00
|
|
|
#include "llvm/PassRegistry.h"
|
2010-10-07 20:41:20 +02:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
/// initializeCodeGen - Initialize all passes linked into the CodeGen library.
|
|
|
|
void llvm::initializeCodeGen(PassRegistry &Registry) {
|
2014-08-21 23:50:01 +02:00
|
|
|
initializeAtomicExpandPass(Registry);
|
2012-02-08 22:22:48 +01:00
|
|
|
initializeBranchFolderPassPass(Registry);
|
2014-02-22 01:07:45 +01:00
|
|
|
initializeCodeGenPreparePass(Registry);
|
2010-10-07 20:41:20 +02:00
|
|
|
initializeDeadMachineInstructionElimPass(Registry);
|
2015-03-09 23:45:16 +01:00
|
|
|
initializeDwarfEHPreparePass(Registry);
|
2012-07-04 02:09:54 +02:00
|
|
|
initializeEarlyIfConverterPass(Registry);
|
2015-02-20 03:15:36 +01:00
|
|
|
initializeExpandISelPseudosPass(Registry);
|
2015-03-09 23:45:16 +01:00
|
|
|
initializeExpandPostRAPass(Registry);
|
2012-02-08 22:23:13 +01:00
|
|
|
initializeFinalizeMachineBundlesPass(Registry);
|
2015-09-17 22:45:18 +02:00
|
|
|
initializeFuncletLayoutPass(Registry);
|
2012-02-08 22:23:13 +01:00
|
|
|
initializeGCMachineCodeAnalysisPass(Registry);
|
2010-10-07 20:41:20 +02:00
|
|
|
initializeGCModuleInfoPass(Registry);
|
|
|
|
initializeIfConverterPass(Registry);
|
2010-11-30 03:17:10 +01:00
|
|
|
initializeLiveDebugVariablesPass(Registry);
|
2010-10-07 20:41:20 +02:00
|
|
|
initializeLiveIntervalsPass(Registry);
|
|
|
|
initializeLiveStacksPass(Registry);
|
|
|
|
initializeLiveVariablesPass(Registry);
|
2012-02-08 22:23:13 +01:00
|
|
|
initializeLocalStackSlotPassPass(Registry);
|
2015-03-09 23:45:16 +01:00
|
|
|
initializeLowerIntrinsicsPass(Registry);
|
2011-07-25 21:25:40 +02:00
|
|
|
initializeMachineBlockFrequencyInfoPass(Registry);
|
Implement a block placement pass based on the branch probability and
block frequency analyses. This differs substantially from the existing
block-placement pass in LLVM:
1) It operates on the Machine-IR in the CodeGen layer. This exposes much
more (and more precise) information and opportunities. Also, the
results are more stable due to fewer transforms ocurring after the
pass runs.
2) It uses the generalized probability and frequency analyses. These can
model static heuristics, code annotation derived heuristics as well
as eventual profile loading. By basing the optimization on the
analysis interface it can work from any (or a combination) of these
inputs.
3) It uses a more aggressive algorithm, both building chains from tho
bottom up to maximize benefit, and using an SCC-based walk to layout
chains of blocks in a profitable ordering without O(N^2) iterations
which the old pass involves.
The pass is currently gated behind a flag, and not enabled by default
because it still needs to grow some important features. Most notably, it
needs to support loop aligning and careful layout of loop structures
much as done by hand currently in CodePlacementOpt. Once it supports
these, and has sufficient testing and quality tuning, it should replace
both of these passes.
Thanks to Nick Lewycky and Richard Smith for help authoring & debugging
this, and to Jakob, Andy, Eric, Jim, and probably a few others I'm
forgetting for reviewing and answering all my questions. Writing
a backend pass is *sooo* much better now than it used to be. =D
llvm-svn: 142641
2011-10-21 08:46:38 +02:00
|
|
|
initializeMachineBlockPlacementPass(Registry);
|
2011-11-02 08:17:12 +01:00
|
|
|
initializeMachineBlockPlacementStatsPass(Registry);
|
2015-02-20 03:15:36 +01:00
|
|
|
initializeMachineCSEPass(Registry);
|
2015-06-15 20:44:27 +02:00
|
|
|
initializeImplicitNullChecksPass(Registry);
|
2015-03-09 23:45:16 +01:00
|
|
|
initializeMachineCombinerPass(Registry);
|
|
|
|
initializeMachineCopyPropagationPass(Registry);
|
2010-10-07 20:41:20 +02:00
|
|
|
initializeMachineDominatorTreePass(Registry);
|
2015-03-09 23:45:16 +01:00
|
|
|
initializeMachineFunctionPrinterPassPass(Registry);
|
2010-10-07 20:41:20 +02:00
|
|
|
initializeMachineLICMPass(Registry);
|
|
|
|
initializeMachineLoopInfoPass(Registry);
|
|
|
|
initializeMachineModuleInfoPass(Registry);
|
2015-03-09 23:45:16 +01:00
|
|
|
initializeMachinePostDominatorTreePass(Registry);
|
2012-02-08 22:23:13 +01:00
|
|
|
initializeMachineSchedulerPass(Registry);
|
2010-10-07 20:41:20 +02:00
|
|
|
initializeMachineSinkingPass(Registry);
|
|
|
|
initializeMachineVerifierPassPass(Registry);
|
|
|
|
initializeOptimizePHIsPass(Registry);
|
2015-03-09 23:45:16 +01:00
|
|
|
initializePEIPass(Registry);
|
2010-10-07 20:41:20 +02:00
|
|
|
initializePHIEliminationPass(Registry);
|
|
|
|
initializePeepholeOptimizerPass(Registry);
|
2013-12-28 22:56:51 +01:00
|
|
|
initializePostMachineSchedulerPass(Registry);
|
2012-02-08 22:23:13 +01:00
|
|
|
initializePostRASchedulerPass(Registry);
|
2010-10-07 20:41:20 +02:00
|
|
|
initializeProcessImplicitDefsPass(Registry);
|
2011-06-27 00:34:10 +02:00
|
|
|
initializeRegisterCoalescerPass(Registry);
|
[ShrinkWrap] Add (a simplified version) of shrink-wrapping.
This patch introduces a new pass that computes the safe point to insert the
prologue and epilogue of the function.
The interest is to find safe points that are cheaper than the entry and exits
blocks.
As an example and to avoid regressions to be introduce, this patch also
implements the required bits to enable the shrink-wrapping pass for AArch64.
** Context **
Currently we insert the prologue and epilogue of the method/function in the
entry and exits blocks. Although this is correct, we can do a better job when
those are not immediately required and insert them at less frequently executed
places.
The job of the shrink-wrapping pass is to identify such places.
** Motivating example **
Let us consider the following function that perform a call only in one branch of
a if:
define i32 @f(i32 %a, i32 %b) {
%tmp = alloca i32, align 4
%tmp2 = icmp slt i32 %a, %b
br i1 %tmp2, label %true, label %false
true:
store i32 %a, i32* %tmp, align 4
%tmp4 = call i32 @doSomething(i32 0, i32* %tmp)
br label %false
false:
%tmp.0 = phi i32 [ %tmp4, %true ], [ %a, %0 ]
ret i32 %tmp.0
}
On AArch64 this code generates (removing the cfi directives to ease
readabilities):
_f: ; @f
; BB#0:
stp x29, x30, [sp, #-16]!
mov x29, sp
sub sp, sp, #16 ; =16
cmp w0, w1
b.ge LBB0_2
; BB#1: ; %true
stur w0, [x29, #-4]
sub x1, x29, #4 ; =4
mov w0, wzr
bl _doSomething
LBB0_2: ; %false
mov sp, x29
ldp x29, x30, [sp], #16
ret
With shrink-wrapping we could generate:
_f: ; @f
; BB#0:
cmp w0, w1
b.ge LBB0_2
; BB#1: ; %true
stp x29, x30, [sp, #-16]!
mov x29, sp
sub sp, sp, #16 ; =16
stur w0, [x29, #-4]
sub x1, x29, #4 ; =4
mov w0, wzr
bl _doSomething
add sp, x29, #16 ; =16
ldp x29, x30, [sp], #16
LBB0_2: ; %false
ret
Therefore, we would pay the overhead of setting up/destroying the frame only if
we actually do the call.
** Proposed Solution **
This patch introduces a new machine pass that perform the shrink-wrapping
analysis (See the comments at the beginning of ShrinkWrap.cpp for more details).
It then stores the safe save and restore point into the MachineFrameInfo
attached to the MachineFunction.
This information is then used by the PrologEpilogInserter (PEI) to place the
related code at the right place. This pass runs right before the PEI.
Unlike the original paper of Chow from PLDI’88, this implementation of
shrink-wrapping does not use expensive data-flow analysis and does not need hack
to properly avoid frequently executed point. Instead, it relies on dominance and
loop properties.
The pass is off by default and each target can opt-in by setting the
EnableShrinkWrap boolean to true in their derived class of TargetPassConfig.
This setting can also be overwritten on the command line by using
-enable-shrink-wrap.
Before you try out the pass for your target, make sure you properly fix your
emitProlog/emitEpilog/adjustForXXX method to cope with basic blocks that are not
necessarily the entry block.
** Design Decisions **
1. ShrinkWrap is its own pass right now. It could frankly be merged into PEI but
for debugging and clarity I thought it was best to have its own file.
2. Right now, we only support one save point and one restore point. At some
point we can expand this to several save point and restore point, the impacted
component would then be:
- The pass itself: New algorithm needed.
- MachineFrameInfo: Hold a list or set of Save/Restore point instead of one
pointer.
- PEI: Should loop over the save point and restore point.
Anyhow, at least for this first iteration, I do not believe this is interesting
to support the complex cases. We should revisit that when we motivating
examples.
Differential Revision: http://reviews.llvm.org/D9210
<rdar://problem/3201744>
llvm-svn: 236507
2015-05-05 19:38:16 +02:00
|
|
|
initializeShrinkWrapPass(Registry);
|
2010-10-07 20:41:20 +02:00
|
|
|
initializeSlotIndexesPass(Registry);
|
2015-02-20 03:15:36 +01:00
|
|
|
initializeStackColoringPass(Registry);
|
2015-03-09 23:45:16 +01:00
|
|
|
initializeStackMapLivenessPass(Registry);
|
2015-12-16 12:09:48 +01:00
|
|
|
initializeLiveDebugValuesPass(Registry);
|
2016-01-27 17:53:42 +01:00
|
|
|
initializeSafeStackPass(Registry);
|
2015-03-09 23:45:16 +01:00
|
|
|
initializeStackProtectorPass(Registry);
|
2010-10-07 20:41:20 +02:00
|
|
|
initializeStackSlotColoringPass(Registry);
|
2012-02-08 22:23:13 +01:00
|
|
|
initializeTailDuplicatePassPass(Registry);
|
2012-02-04 03:56:45 +01:00
|
|
|
initializeTargetPassConfigPass(Registry);
|
2010-10-07 20:41:20 +02:00
|
|
|
initializeTwoAddressInstructionPassPass(Registry);
|
2012-02-08 22:23:13 +01:00
|
|
|
initializeUnpackMachineBundlesPass(Registry);
|
2010-10-07 20:41:20 +02:00
|
|
|
initializeUnreachableBlockElimPass(Registry);
|
|
|
|
initializeUnreachableMachineBlockElimPass(Registry);
|
|
|
|
initializeVirtRegMapPass(Registry);
|
2012-06-09 01:44:45 +02:00
|
|
|
initializeVirtRegRewriterPass(Registry);
|
2015-03-09 23:45:16 +01:00
|
|
|
initializeWinEHPreparePass(Registry);
|
2010-10-07 20:41:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMInitializeCodeGen(LLVMPassRegistryRef R) {
|
|
|
|
initializeCodeGen(*unwrap(R));
|
|
|
|
}
|