2003-08-21 22:14:26 +00:00
|
|
|
//===-- Passes.h - Target independent code generation passes ----*- C++ -*-===//
|
2005-04-21 20:39:54 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:39:54 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-01-13 01:01:31 +00:00
|
|
|
//
|
2003-08-21 22:14:26 +00:00
|
|
|
// This file defines interfaces to access the target independent code generation
|
2003-01-13 01:01:31 +00:00
|
|
|
// passes provided by the LLVM backend.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_PASSES_H
|
|
|
|
#define LLVM_CODEGEN_PASSES_H
|
|
|
|
|
2009-10-16 21:06:15 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2004-02-04 21:41:10 +00:00
|
|
|
#include <string>
|
2004-01-30 21:53:46 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2003-12-20 10:18:58 +00:00
|
|
|
class FunctionPass;
|
2010-04-02 23:17:14 +00:00
|
|
|
class MachineFunctionPass;
|
2003-12-20 10:18:58 +00:00
|
|
|
class PassInfo;
|
2008-11-04 21:53:09 +00:00
|
|
|
class TargetLowering;
|
2011-09-27 23:50:46 +00:00
|
|
|
class TargetRegisterClass;
|
2009-08-23 03:13:20 +00:00
|
|
|
class raw_ostream;
|
2004-07-02 05:44:13 +00:00
|
|
|
|
|
|
|
/// createUnreachableBlockEliminationPass - The LLVM code generator does not
|
|
|
|
/// work well with unreachable basic blocks (what live ranges make sense for a
|
|
|
|
/// block that cannot be reached?). As such, a code generator should either
|
2010-08-06 21:31:35 +00:00
|
|
|
/// not instruction select unreachable blocks, or run this pass as its
|
2004-07-02 05:44:13 +00:00
|
|
|
/// last LLVM modifying pass to clean up blocks that are not reachable from
|
|
|
|
/// the entry block.
|
|
|
|
FunctionPass *createUnreachableBlockEliminationPass();
|
2005-04-21 20:39:54 +00:00
|
|
|
|
2003-12-20 10:18:58 +00:00
|
|
|
/// MachineFunctionPrinter pass - This pass prints out the machine function to
|
2010-08-06 21:31:35 +00:00
|
|
|
/// the given stream as a debugging tool.
|
2010-04-02 23:17:14 +00:00
|
|
|
MachineFunctionPass *
|
|
|
|
createMachineFunctionPrinterPass(raw_ostream &OS,
|
|
|
|
const std::string &Banner ="");
|
2004-01-30 21:53:46 +00:00
|
|
|
|
2008-01-04 20:54:55 +00:00
|
|
|
/// MachineLoopInfo pass - This pass is a loop analysis pass.
|
2010-08-06 21:31:35 +00:00
|
|
|
///
|
2010-08-06 18:33:48 +00:00
|
|
|
extern char &MachineLoopInfoID;
|
2008-01-04 20:54:55 +00:00
|
|
|
|
2010-12-15 23:41:23 +00:00
|
|
|
/// MachineLoopRanges pass - This pass is an on-demand loop coverage
|
|
|
|
/// analysis pass.
|
|
|
|
///
|
|
|
|
extern char &MachineLoopRangesID;
|
|
|
|
|
2008-01-04 20:54:55 +00:00
|
|
|
/// MachineDominators pass - This pass is a machine dominators analysis pass.
|
2010-08-06 21:31:35 +00:00
|
|
|
///
|
2010-08-06 18:33:48 +00:00
|
|
|
extern char &MachineDominatorsID;
|
2008-01-04 20:54:55 +00:00
|
|
|
|
2011-01-04 21:10:05 +00:00
|
|
|
/// EdgeBundles analysis - Bundle machine CFG edges.
|
|
|
|
///
|
|
|
|
extern char &EdgeBundlesID;
|
|
|
|
|
2003-12-20 10:18:58 +00:00
|
|
|
/// PHIElimination pass - This pass eliminates machine instruction PHI nodes
|
|
|
|
/// by inserting copy instructions. This destroys SSA information, but is the
|
|
|
|
/// desired input for some register allocators. This pass is "required" by
|
|
|
|
/// these register allocator like this: AU.addRequiredID(PHIEliminationID);
|
|
|
|
///
|
2010-08-06 18:33:48 +00:00
|
|
|
extern char &PHIEliminationID;
|
2010-08-06 21:31:35 +00:00
|
|
|
|
2007-10-31 03:37:57 +00:00
|
|
|
/// StrongPHIElimination pass - This pass eliminates machine instruction PHI
|
|
|
|
/// nodes by inserting copy instructions. This destroys SSA information, but
|
|
|
|
/// is the desired input for some register allocators. This pass is
|
|
|
|
/// "required" by these register allocator like this:
|
|
|
|
/// AU.addRequiredID(PHIEliminationID);
|
|
|
|
/// This pass is still in development
|
2010-08-06 18:33:48 +00:00
|
|
|
extern char &StrongPHIEliminationID;
|
2003-01-13 01:01:31 +00:00
|
|
|
|
2010-10-26 00:11:33 +00:00
|
|
|
/// LiveStacks pass. An analysis keeping track of the liveness of stack slots.
|
|
|
|
extern char &LiveStacksID;
|
|
|
|
|
2003-12-20 10:18:58 +00:00
|
|
|
/// TwoAddressInstruction pass - This pass reduces two-address instructions to
|
|
|
|
/// use two operands. This destroys SSA information but it is desired by
|
|
|
|
/// register allocators.
|
2010-08-06 18:33:48 +00:00
|
|
|
extern char &TwoAddressInstructionPassID;
|
2003-01-13 01:01:31 +00:00
|
|
|
|
2011-08-09 00:29:53 +00:00
|
|
|
/// RegisteCoalescer pass - This pass merges live ranges to eliminate copies.
|
|
|
|
extern char &RegisterCoalescerPassID;
|
|
|
|
|
2012-01-13 06:30:30 +00:00
|
|
|
/// MachineScheduler pass - This pass schedules machine instructions.
|
2012-01-17 06:55:03 +00:00
|
|
|
extern char &MachineSchedulerID;
|
2012-01-13 06:30:30 +00:00
|
|
|
|
2011-01-06 01:21:53 +00:00
|
|
|
/// SpillPlacement analysis. Suggest optimal placement of spill code between
|
|
|
|
/// basic blocks.
|
|
|
|
///
|
|
|
|
extern char &SpillPlacementID;
|
|
|
|
|
2008-08-04 23:54:43 +00:00
|
|
|
/// UnreachableMachineBlockElimination pass - This pass removes unreachable
|
|
|
|
/// machine basic blocks.
|
2010-08-06 18:33:48 +00:00
|
|
|
extern char &UnreachableMachineBlockElimID;
|
2008-08-04 23:54:43 +00:00
|
|
|
|
2008-09-17 00:43:24 +00:00
|
|
|
/// DeadMachineInstructionElim pass - This pass removes dead machine
|
|
|
|
/// instructions.
|
|
|
|
///
|
|
|
|
FunctionPass *createDeadMachineInstructionElimPass();
|
|
|
|
|
2010-05-27 23:57:25 +00:00
|
|
|
/// Creates a register allocator as the user specified on the command line, or
|
|
|
|
/// picks one that matches OptLevel.
|
2003-12-20 10:18:58 +00:00
|
|
|
///
|
2010-05-27 23:57:25 +00:00
|
|
|
FunctionPass *createRegisterAllocator(CodeGenOpt::Level OptLevel);
|
2003-01-13 01:01:31 +00:00
|
|
|
|
2010-04-21 18:02:42 +00:00
|
|
|
/// FastRegisterAllocation Pass - This pass register allocates as fast as
|
|
|
|
/// possible. It is best suited for debug code where live ranges are short.
|
|
|
|
///
|
|
|
|
FunctionPass *createFastRegisterAllocator();
|
|
|
|
|
2010-10-22 23:09:15 +00:00
|
|
|
/// BasicRegisterAllocation Pass - This pass implements a degenerate global
|
|
|
|
/// register allocator using the basic regalloc framework.
|
|
|
|
///
|
|
|
|
FunctionPass *createBasicRegisterAllocator();
|
|
|
|
|
2010-12-08 03:26:16 +00:00
|
|
|
/// Greedy register allocation pass - This pass implements a global register
|
|
|
|
/// allocator for optimized builds.
|
|
|
|
///
|
|
|
|
FunctionPass *createGreedyRegisterAllocator();
|
|
|
|
|
2008-10-02 18:29:27 +00:00
|
|
|
/// PBQPRegisterAllocation Pass - This pass implements the Partitioned Boolean
|
|
|
|
/// Quadratic Prograaming (PBQP) based register allocator.
|
|
|
|
///
|
2010-09-23 04:28:54 +00:00
|
|
|
FunctionPass *createDefaultPBQPRegisterAllocator();
|
2003-01-13 01:01:31 +00:00
|
|
|
|
2003-12-20 10:18:58 +00:00
|
|
|
/// PrologEpilogCodeInserter Pass - This pass inserts prolog and epilog code,
|
|
|
|
/// and eliminates abstract frame references.
|
|
|
|
///
|
|
|
|
FunctionPass *createPrologEpilogCodeInserter();
|
2010-08-06 21:31:35 +00:00
|
|
|
|
2011-09-25 16:46:08 +00:00
|
|
|
/// ExpandPostRAPseudos Pass - This pass expands pseudo instructions after
|
|
|
|
/// register allocation.
|
2007-07-26 08:18:32 +00:00
|
|
|
///
|
2011-09-25 16:46:08 +00:00
|
|
|
FunctionPass *createExpandPostRAPseudosPass();
|
2003-09-30 20:14:43 +00:00
|
|
|
|
2009-10-16 21:06:15 +00:00
|
|
|
/// createPostRAScheduler - This pass performs post register allocation
|
|
|
|
/// scheduling.
|
|
|
|
FunctionPass *createPostRAScheduler(CodeGenOpt::Level OptLevel);
|
2007-07-13 17:13:54 +00:00
|
|
|
|
2004-07-31 09:59:14 +00:00
|
|
|
/// BranchFolding Pass - This pass performs machine code CFG based
|
|
|
|
/// optimizations to delete branches to branches, eliminate branches to
|
|
|
|
/// successor blocks (creating fall throughs), and eliminating branches over
|
|
|
|
/// branches.
|
2009-10-28 20:46:46 +00:00
|
|
|
FunctionPass *createBranchFoldingPass(bool DefaultEnableTailMerge);
|
2004-07-31 09:59:14 +00:00
|
|
|
|
2009-11-26 21:38:41 +00:00
|
|
|
/// TailDuplicate Pass - Duplicate blocks with unconditional branches
|
2009-11-26 00:32:21 +00:00
|
|
|
/// into tails of their predecessors.
|
2009-12-04 09:42:45 +00:00
|
|
|
FunctionPass *createTailDuplicatePass(bool PreRegAlloc = false);
|
2009-11-26 00:32:21 +00:00
|
|
|
|
2009-10-28 20:46:46 +00:00
|
|
|
/// IfConverter Pass - This pass performs machine code if conversion.
|
|
|
|
FunctionPass *createIfConverterPass();
|
2007-05-16 02:00:57 +00:00
|
|
|
|
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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142641 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-21 06:46:38 +00:00
|
|
|
/// MachineBlockPlacement Pass - This pass places basic blocks based on branch
|
|
|
|
/// probabilities.
|
|
|
|
FunctionPass *createMachineBlockPlacementPass();
|
|
|
|
|
2011-11-02 07:17:12 +00:00
|
|
|
/// MachineBlockPlacementStats Pass - This pass collects statistics about the
|
|
|
|
/// basic block placement using branch probabilities and block frequency
|
|
|
|
/// information.
|
|
|
|
FunctionPass *createMachineBlockPlacementStatsPass();
|
|
|
|
|
2009-05-07 05:42:24 +00:00
|
|
|
/// Code Placement Pass - This pass optimize code placement and aligns loop
|
|
|
|
/// headers to target specific alignment boundary.
|
|
|
|
FunctionPass *createCodePlacementOptPass();
|
2008-02-28 00:43:03 +00:00
|
|
|
|
2007-12-11 00:30:17 +00:00
|
|
|
/// IntrinsicLowering Pass - Performs target-independent LLVM IR
|
2008-08-17 18:44:35 +00:00
|
|
|
/// transformations for highly portable strategies.
|
2007-12-11 00:30:17 +00:00
|
|
|
FunctionPass *createGCLoweringPass();
|
2010-08-06 21:31:35 +00:00
|
|
|
|
2007-12-11 00:30:17 +00:00
|
|
|
/// MachineCodeAnalysis Pass - Target-independent pass to mark safe points in
|
|
|
|
/// machine code. Must be added very late during code generation, just prior
|
|
|
|
/// to output, and importantly after all CFG transformations (such as branch
|
|
|
|
/// folding).
|
|
|
|
FunctionPass *createGCMachineCodeAnalysisPass();
|
2010-08-06 21:31:35 +00:00
|
|
|
|
2008-08-17 18:44:35 +00:00
|
|
|
/// Deleter Pass - Releases GC metadata.
|
2010-08-06 21:31:35 +00:00
|
|
|
///
|
2008-08-17 18:44:35 +00:00
|
|
|
FunctionPass *createGCInfoDeleter();
|
2010-08-06 21:31:35 +00:00
|
|
|
|
2008-08-17 18:44:35 +00:00
|
|
|
/// Creates a pass to print GC metadata.
|
2010-08-06 21:31:35 +00:00
|
|
|
///
|
2009-08-23 03:13:20 +00:00
|
|
|
FunctionPass *createGCInfoPrinter(raw_ostream &OS);
|
2010-08-06 21:31:35 +00:00
|
|
|
|
2010-03-02 02:38:24 +00:00
|
|
|
/// createMachineCSEPass - This pass performs global CSE on machine
|
|
|
|
/// instructions.
|
|
|
|
FunctionPass *createMachineCSEPass();
|
|
|
|
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
/// createMachineLICMPass - This pass performs LICM on machine instructions.
|
2010-08-06 21:31:35 +00:00
|
|
|
///
|
2010-04-07 00:41:17 +00:00
|
|
|
FunctionPass *createMachineLICMPass(bool PreRegAlloc = true);
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
|
Add a really quick hack at a machine code sinking pass, enabled with --enable-sinking.
It is missing validity checks, so it is known broken. However, it is powerful enough
to compile this contrived code:
void test1(int C, double A, double B, double *P) {
double Tmp = A*A+B*B;
*P = C ? Tmp : A;
}
into:
_test1:
movsd 8(%esp), %xmm0
cmpl $0, 4(%esp)
je LBB1_2 # entry
LBB1_1: # entry
movsd 16(%esp), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
LBB1_2: # entry
movl 24(%esp), %eax
movsd %xmm0, (%eax)
ret
instead of:
_test1:
movsd 16(%esp), %xmm0
mulsd %xmm0, %xmm0
movsd 8(%esp), %xmm1
movapd %xmm1, %xmm2
mulsd %xmm2, %xmm2
addsd %xmm0, %xmm2
cmpl $0, 4(%esp)
je LBB1_2 # entry
LBB1_1: # entry
movapd %xmm2, %xmm1
LBB1_2: # entry
movl 24(%esp), %eax
movsd %xmm1, (%eax)
ret
woo.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45570 91177308-0d34-0410-b5e6-96231b3b80d8
2008-01-04 07:36:53 +00:00
|
|
|
/// createMachineSinkingPass - This pass performs sinking on machine
|
|
|
|
/// instructions.
|
|
|
|
FunctionPass *createMachineSinkingPass();
|
2008-06-04 09:18:41 +00:00
|
|
|
|
2012-01-07 03:02:36 +00:00
|
|
|
/// createMachineCopyPropagationPass - This pass performs copy propagation on
|
|
|
|
/// machine instructions.
|
|
|
|
FunctionPass *createMachineCopyPropagationPass();
|
|
|
|
|
2010-08-09 23:59:04 +00:00
|
|
|
/// createPeepholeOptimizerPass - This pass performs peephole optimizations -
|
|
|
|
/// like extension and comparison eliminations.
|
|
|
|
FunctionPass *createPeepholeOptimizerPass();
|
2010-01-13 00:30:23 +00:00
|
|
|
|
2010-02-12 01:30:21 +00:00
|
|
|
/// createOptimizePHIsPass - This pass optimizes machine instruction PHIs
|
|
|
|
/// to take advantage of opportunities created during DAG legalization.
|
|
|
|
FunctionPass *createOptimizePHIsPass();
|
|
|
|
|
2008-06-04 09:18:41 +00:00
|
|
|
/// createStackSlotColoringPass - This pass performs stack slot coloring.
|
2009-05-07 01:33:38 +00:00
|
|
|
FunctionPass *createStackSlotColoringPass(bool);
|
2008-11-04 02:10:20 +00:00
|
|
|
|
|
|
|
/// createStackProtectorPass - This pass adds stack protectors to functions.
|
2008-11-13 01:02:14 +00:00
|
|
|
FunctionPass *createStackProtectorPass(const TargetLowering *tli);
|
2008-11-04 02:10:20 +00:00
|
|
|
|
2009-05-16 00:33:53 +00:00
|
|
|
/// createMachineVerifierPass - This pass verifies cenerated machine code
|
|
|
|
/// instructions for correctness.
|
2010-12-18 00:06:56 +00:00
|
|
|
FunctionPass *createMachineVerifierPass(const char *Banner = 0);
|
2009-05-16 00:33:53 +00:00
|
|
|
|
2009-05-22 20:36:31 +00:00
|
|
|
/// createDwarfEHPass - This pass mulches exception handling code into a form
|
|
|
|
/// adapted to code generation. Required if using dwarf exception handling.
|
2010-08-31 09:05:06 +00:00
|
|
|
FunctionPass *createDwarfEHPass(const TargetMachine *tm);
|
2009-05-22 20:36:31 +00:00
|
|
|
|
2009-08-17 16:41:22 +00:00
|
|
|
/// createSjLjEHPass - This pass adapts exception handling code to use
|
|
|
|
/// the GCC-style builtin setjmp/longjmp (sjlj) to handling EH control flow.
|
|
|
|
FunctionPass *createSjLjEHPass(const TargetLowering *tli);
|
|
|
|
|
2010-08-14 00:15:52 +00:00
|
|
|
/// createLocalStackSlotAllocationPass - This pass assigns local frame
|
|
|
|
/// indices to stack slots relative to one another and allocates
|
|
|
|
/// base registers to access them when it is estimated by the target to
|
|
|
|
/// be out of range of normal frame pointer or stack pointer index
|
|
|
|
/// addressing.
|
|
|
|
FunctionPass *createLocalStackSlotAllocationPass();
|
|
|
|
|
2010-11-18 18:45:06 +00:00
|
|
|
/// createExpandISelPseudosPass - This pass expands pseudo-instructions.
|
2010-11-16 21:02:37 +00:00
|
|
|
///
|
2010-11-18 18:45:06 +00:00
|
|
|
FunctionPass *createExpandISelPseudosPass();
|
2010-11-16 21:02:37 +00:00
|
|
|
|
2011-09-27 23:50:46 +00:00
|
|
|
/// createExecutionDependencyFixPass - This pass fixes execution time
|
|
|
|
/// problems with dependent instructions, such as switching execution
|
|
|
|
/// domains to match.
|
|
|
|
///
|
|
|
|
/// The pass will examine instructions using and defining registers in RC.
|
|
|
|
///
|
|
|
|
FunctionPass *createExecutionDependencyFixPass(const TargetRegisterClass *RC);
|
|
|
|
|
2011-12-14 02:11:42 +00:00
|
|
|
/// createUnpackMachineBundles - This pass unpack machine instruction bundles.
|
|
|
|
///
|
|
|
|
FunctionPass *createUnpackMachineBundlesPass();
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2003-01-13 01:01:31 +00:00
|
|
|
#endif
|