Scalar.h revision 239462
159412Smsmith//===-- Scalar.h - Scalar Transformations -----------------------*- C++ -*-===// 265577Sdes// 365577Sdes// The LLVM Compiler Infrastructure 459412Smsmith// 559412Smsmith// This file is distributed under the University of Illinois Open Source 659412Smsmith// License. See LICENSE.TXT for details. 759412Smsmith// 859412Smsmith//===----------------------------------------------------------------------===// 959412Smsmith// 1059412Smsmith// This header file defines prototypes for accessor functions that expose passes 1159412Smsmith// in the Scalar transformations library. 1259412Smsmith// 1359412Smsmith//===----------------------------------------------------------------------===// 1459412Smsmith 1559412Smsmith#ifndef LLVM_TRANSFORMS_SCALAR_H 1659412Smsmith#define LLVM_TRANSFORMS_SCALAR_H 1759412Smsmith 1859412Smsmithnamespace llvm { 1959412Smsmith 2059412Smsmithclass FunctionPass; 2159412Smsmithclass Pass; 2259412Smsmithclass GetElementPtrInst; 2359412Smsmithclass PassInfo; 2459412Smsmithclass TerminatorInst; 2559412Smsmithclass TargetLowering; 2659412Smsmith 2759412Smsmith//===----------------------------------------------------------------------===// 2859412Smsmith// 2959412Smsmith// ConstantPropagation - A worklist driven constant propagation pass 3059412Smsmith// 3159412SmsmithFunctionPass *createConstantPropagationPass(); 3259412Smsmith 3359412Smsmith//===----------------------------------------------------------------------===// 3459412Smsmith// 3559412Smsmith// SCCP - Sparse conditional constant propagation. 3659412Smsmith// 3759412SmsmithFunctionPass *createSCCPPass(); 3859412Smsmith 3959412Smsmith//===----------------------------------------------------------------------===// 4059412Smsmith// 4159412Smsmith// DeadInstElimination - This pass quickly removes trivially dead instructions 4259412Smsmith// without modifying the CFG of the function. It is a BasicBlockPass, so it 4359412Smsmith// runs efficiently when queued next to other BasicBlockPass's. 4459412Smsmith// 4583926SdesPass *createDeadInstEliminationPass(); 4676166Smarkm 4774135Sjlemon//===----------------------------------------------------------------------===// 4865633Sdes// 4983926Sdes// DeadCodeElimination - This pass is more powerful than DeadInstElimination, 5076166Smarkm// because it is worklist driven that can potentially revisit instructions when 5165633Sdes// their other instructions become dead, to eliminate chains of dead 5283926Sdes// computations. 5376166Smarkm// 5474135SjlemonFunctionPass *createDeadCodeEliminationPass(); 5578025Sdes 5676827Salfred//===----------------------------------------------------------------------===// 5785289Sdes// 5865633Sdes// DeadStoreElimination - This pass deletes stores that are post-dominated by 5965633Sdes// must-aliased stores and are not loaded used between the stores. 6069995Sdes// 6183926SdesFunctionPass *createDeadStoreEliminationPass(); 6276839Sjlemon 6383926Sdes//===----------------------------------------------------------------------===// 6465633Sdes// 6583926Sdes// AggressiveDCE - This pass uses the SSA based Aggressive DCE algorithm. This 6683926Sdes// algorithm assumes instructions are dead until proven otherwise, which makes 6759412Smsmith// it more successful are removing non-obviously dead instructions. 6859412Smsmith// 6983926SdesFunctionPass *createAggressiveDCEPass(); 7083926Sdes 7159412Smsmith//===----------------------------------------------------------------------===// 7259412Smsmith// 7367588Sdes// ScalarReplAggregates - Break up alloca's of aggregates into multiple allocas 7459412Smsmith// if possible. 7560860Sdes// 7669995SdesFunctionPass *createScalarReplAggregatesPass(signed Threshold = -1, 7759412Smsmith bool UseDomTree = true, 7869799Sdes signed StructMemberThreshold = -1, 7967589Sdes signed ArrayElementThreshold = -1, 8078113Sdes signed ScalarLoadThreshold = -1); 8178113Sdes 8278113Sdes//===----------------------------------------------------------------------===// 8378113Sdes// 8478113Sdes// InductionVariableSimplify - Transform induction variables in a program to all 8578113Sdes// use a single canonical induction variable per loop. 8678113Sdes// 8778113SdesPass *createIndVarSimplifyPass(); 8878113Sdes 8967589Sdes//===----------------------------------------------------------------------===// 9059412Smsmith// 9178113Sdes// InstructionCombining - Combine instructions to form fewer, simple 9259412Smsmith// instructions. This pass does not modify the CFG, and has a tendency to make 9387275Srwatson// instructions dead, so a subsequent DCE pass is useful. 9485129Sdes// 9569995Sdes// This pass combines things like: 9685289Sdes// %Y = add int 1, %X 9778025Sdes// %Z = add int 1, %Y 9884248Sdes// into: 9959412Smsmith// %Z = add int 2, %X 10067588Sdes// 10167588SdesFunctionPass *createInstructionCombiningPass(); 10267588Sdes 10376405Sdes//===----------------------------------------------------------------------===// 10467588Sdes// 10567588Sdes// LICM - This pass is a loop invariant code motion and memory promotion pass. 10669799Sdes// 10767588SdesPass *createLICMPass(); 10867588Sdes 10974135Sjlemon//===----------------------------------------------------------------------===// 11078113Sdes// 11178113Sdes// LoopStrengthReduce - This pass is strength reduces GEP instructions that use 11278113Sdes// a loop's canonical induction variable as one of their indices. It takes an 11378025Sdes// optional parameter used to consult the target machine whether certain 11478025Sdes// transformations are profitable. 11559412Smsmith// 11659412SmsmithPass *createLoopStrengthReducePass(const TargetLowering *TLI = 0); 11759412Smsmith 11859412SmsmithPass *createGlobalMergePass(const TargetLowering *TLI = 0); 11959412Smsmith 12059412Smsmith//===----------------------------------------------------------------------===// 12176839Sjlemon// 12276839Sjlemon// LoopUnswitch - This pass is a simple loop unswitching pass. 12376839Sjlemon// 12460860SdesPass *createLoopUnswitchPass(bool OptimizeForSize = false); 12559412Smsmith 12659412Smsmith//===----------------------------------------------------------------------===// 12759412Smsmith// 12859412Smsmith// LoopInstSimplify - This pass simplifies instructions in a loop's body. 12959412Smsmith// 13059412SmsmithPass *createLoopInstSimplifyPass(); 13159412Smsmith 13259412Smsmith//===----------------------------------------------------------------------===// 13359412Smsmith// 13459412Smsmith// LoopUnroll - This pass is a simple loop unrolling pass. 13559412Smsmith// 13659412SmsmithPass *createLoopUnrollPass(int Threshold = -1, int Count = -1, int AllowPartial = -1); 13759412Smsmith 13859412Smsmith//===----------------------------------------------------------------------===// 13964560Sbde// 14064560Sbde// LoopRotate - This pass is a simple loop rotating pass. 14164560Sbde// 14264560SbdePass *createLoopRotatePass(); 14376839Sjlemon 14476839Sjlemon//===----------------------------------------------------------------------===// 14564560Sbde// 14659412Smsmith// LoopIdiom - This pass recognizes and replaces idioms in loops. 14760860Sdes// 14871471SjhbPass *createLoopIdiomPass(); 14960860Sdes 15060860Sdes//===----------------------------------------------------------------------===// 15160860Sdes// 15259412Smsmith// PromoteMemoryToRegister - This pass is used to promote memory references to 15359412Smsmith// be register references. A simple example of the transformation performed by 15459412Smsmith// this pass is: 15559412Smsmith// 15659412Smsmith// FROM CODE TO CODE 15759412Smsmith// %X = alloca i32, i32 1 ret i32 42 15859412Smsmith// store i32 42, i32 *%X 15959412Smsmith// %Y = load i32* %X 16059412Smsmith// ret i32 %Y 16159412Smsmith// 16259412SmsmithFunctionPass *createPromoteMemoryToRegisterPass(); 16378025Sdes 16478031Sdes//===----------------------------------------------------------------------===// 16569799Sdes// 16676839Sjlemon// DemoteRegisterToMemoryPass - This pass is used to demote registers to memory 16769799Sdes// references. In basically undoes the PromoteMemoryToRegister pass to make cfg 16869799Sdes// hacking easier. 16969799Sdes// 17069799SdesFunctionPass *createDemoteRegisterToMemoryPass(); 17169799Sdesextern char &DemoteRegisterToMemoryID; 17276839Sjlemon 17376839Sjlemon//===----------------------------------------------------------------------===// 17469799Sdes// 17569799Sdes// Reassociate - This pass reassociates commutative expressions in an order that 17669799Sdes// is designed to promote better constant propagation, GCSE, LICM, PRE... 17769799Sdes// 17869799Sdes// For example: 4 + (x + 5) -> x + (4 + 5) 17959412Smsmith// 18078025SdesFunctionPass *createReassociatePass(); 18159412Smsmith 18259412Smsmith//===----------------------------------------------------------------------===// 18378113Sdes// 18478113Sdes// JumpThreading - Thread control through mult-pred/multi-succ blocks where some 18578113Sdes// preds always go to some succ. 18678113Sdes// 18778025SdesFunctionPass *createJumpThreadingPass(); 18878025Sdes 18959412Smsmith//===----------------------------------------------------------------------===// 19078113Sdes// 19178113Sdes// CFGSimplification - Merge basic blocks, eliminate unreachable blocks, 19278113Sdes// simplify terminator instructions, etc... 19378113Sdes// 19478113SdesFunctionPass *createCFGSimplificationPass(); 19578113Sdes 19678113Sdes//===----------------------------------------------------------------------===// 19778113Sdes// 19878113Sdes// BreakCriticalEdges - Break all of the critical edges in the CFG by inserting 19978113Sdes// a dummy basic block. This pass may be "required" by passes that cannot deal 20078113Sdes// with critical edges. For this usage, a pass must call: 20178113Sdes// 20278113Sdes// AU.addRequiredID(BreakCriticalEdgesID); 20378113Sdes// 20478113Sdes// This pass obviously invalidates the CFG, but can update forward dominator 20578113Sdes// (set, immediate dominators, tree, and frontier) information. 20678113Sdes// 20778113SdesFunctionPass *createBreakCriticalEdgesPass(); 20878113Sdesextern char &BreakCriticalEdgesID; 20978113Sdes 21078113Sdes//===----------------------------------------------------------------------===// 21178113Sdes// 21278113Sdes// LoopSimplify - Insert Pre-header blocks into the CFG for every function in 21378113Sdes// the module. This pass updates dominator information, loop information, and 21478113Sdes// does not add critical edges to the CFG. 21578113Sdes// 21678113Sdes// AU.addRequiredID(LoopSimplifyID); 21778113Sdes// 21878113SdesPass *createLoopSimplifyPass(); 21978113Sdesextern char &LoopSimplifyID; 22078113Sdes 22178113Sdes//===----------------------------------------------------------------------===// 22278113Sdes// 22378113Sdes// TailCallElimination - This pass eliminates call instructions to the current 22478113Sdes// function which occur immediately before return instructions. 22578113Sdes// 22678113SdesFunctionPass *createTailCallEliminationPass(); 22778113Sdes 22878113Sdes//===----------------------------------------------------------------------===// 22978113Sdes// 23078113Sdes// LowerSwitch - This pass converts SwitchInst instructions into a sequence of 23178113Sdes// chained binary branch instructions. 23278113Sdes// 23378113SdesFunctionPass *createLowerSwitchPass(); 23478113Sdesextern char &LowerSwitchID; 23578113Sdes 23678113Sdes//===----------------------------------------------------------------------===// 23778113Sdes// 23878113Sdes// LowerInvoke - This pass converts invoke and unwind instructions to use sjlj 23978113Sdes// exception handling mechanisms. Note that after this pass runs the CFG is not 24078113Sdes// entirely accurate (exceptional control flow edges are not correct anymore) so 24178113Sdes// only very simple things should be done after the lowerinvoke pass has run 24278113Sdes// (like generation of native code). This should *NOT* be used as a general 24378113Sdes// purpose "my LLVM-to-LLVM pass doesn't support the invoke instruction yet" 24478113Sdes// lowering pass. 24578113Sdes// 24678113SdesFunctionPass *createLowerInvokePass(const TargetLowering *TLI = 0); 24778113SdesFunctionPass *createLowerInvokePass(const TargetLowering *TLI, 24878113Sdes bool useExpensiveEHSupport); 24978113Sdesextern char &LowerInvokePassID; 25078113Sdes 25178113Sdes//===----------------------------------------------------------------------===// 25278113Sdes// 25378113Sdes// BlockPlacement - This pass reorders basic blocks in order to increase the 25478113Sdes// number of fall-through conditional branches. 25578113Sdes// 25678113SdesFunctionPass *createBlockPlacementPass(); 25778113Sdes 25878113Sdes//===----------------------------------------------------------------------===// 25978113Sdes// 26069799Sdes// LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop 26159412Smsmith// optimizations. 26269799Sdes// 26378031SdesPass *createLCSSAPass(); 26478031Sdesextern char &LCSSAID; 26569799Sdes 26678031Sdes//===----------------------------------------------------------------------===// 26778031Sdes// 26878031Sdes// EarlyCSE - This pass performs a simple and fast CSE pass over the dominator 26978031Sdes// tree. 27078031Sdes// 27178031SdesFunctionPass *createEarlyCSEPass(); 27278031Sdes 27367589Sdes//===----------------------------------------------------------------------===// 27467589Sdes// 27567589Sdes// GVN - This pass performs global value numbering and redundant load 27659412Smsmith// elimination cotemporaneously. 27759412Smsmith// 27867589SdesFunctionPass *createGVNPass(bool NoLoads = false); 27959412Smsmith 28059412Smsmith//===----------------------------------------------------------------------===// 28167589Sdes// 28259412Smsmith// MemCpyOpt - This pass performs optimizations related to eliminating memcpy 28359412Smsmith// calls and/or combining multiple stores into memset's. 28467589Sdes// 28559412SmsmithFunctionPass *createMemCpyOptPass(); 28659412Smsmith 28767589Sdes//===----------------------------------------------------------------------===// 28859412Smsmith// 28959412Smsmith// LoopDeletion - This pass performs DCE of non-infinite loops that it 29067589Sdes// can prove are dead. 29159412Smsmith// 29259412SmsmithPass *createLoopDeletionPass(); 29378031Sdes 29459412Smsmith//===----------------------------------------------------------------------===// 29559412Smsmith// 29659412Smsmith/// createSimplifyLibCallsPass - This pass optimizes specific calls to 29778025Sdes/// specific well-known (library) functions. 29878031SdesFunctionPass *createSimplifyLibCallsPass(); 29969799Sdes 30069799Sdes//===----------------------------------------------------------------------===// 30169799Sdes// 30269799Sdes// CodeGenPrepare - This pass prepares a function for instruction selection. 30369799Sdes// 30459412SmsmithFunctionPass *createCodeGenPreparePass(const TargetLowering *TLI = 0); 30578031Sdes 30678031Sdes//===----------------------------------------------------------------------===// 30767589Sdes// 30878031Sdes// InstructionNamer - Give any unnamed non-void instructions "tmp" names. 30967589Sdes// 31078031SdesFunctionPass *createInstructionNamerPass(); 31167589Sdesextern char &InstructionNamerID; 31278031Sdes 31378031Sdes//===----------------------------------------------------------------------===// 31478031Sdes// 31567589Sdes// Sink - Code Sinking 31678025Sdes// 31778025SdesFunctionPass *createSinkingPass(); 31878031Sdes 31969799Sdes//===----------------------------------------------------------------------===// 32069799Sdes// 32178025Sdes// LowerAtomic - Lower atomic intrinsics to non-atomic form 32269799Sdes// 32369799SdesPass *createLowerAtomicPass(); 32469799Sdes 32578031Sdes//===----------------------------------------------------------------------===// 32669995Sdes// 32778025Sdes// ValuePropagation - Propagate CFG-derived value information 32859412Smsmith// 32978113SdesPass *createCorrelatedValuePropagationPass(); 33065633Sdes 33178113Sdes//===----------------------------------------------------------------------===// 33285289Sdes// 33385289Sdes// ObjCARCAPElim - ObjC ARC autorelease pool elimination. 33485289Sdes// 33585289SdesPass *createObjCARCAPElimPass(); 33685289Sdes 33785289Sdes//===----------------------------------------------------------------------===// 33885289Sdes// 33985289Sdes// ObjCARCExpand - ObjC ARC preliminary simplifications. 34085289Sdes// 34185289SdesPass *createObjCARCExpandPass(); 34285289Sdes 34385289Sdes//===----------------------------------------------------------------------===// 34485289Sdes// 34585289Sdes// ObjCARCContract - Late ObjC ARC cleanups. 34685289Sdes// 34785289SdesPass *createObjCARCContractPass(); 34885289Sdes 34985289Sdes//===----------------------------------------------------------------------===// 35085289Sdes// 35185289Sdes// ObjCARCOpt - ObjC ARC optimization. 35285289Sdes// 35385289SdesPass *createObjCARCOptPass(); 35485289Sdes 35585289Sdes//===----------------------------------------------------------------------===// 35685289Sdes// 35785289Sdes// InstructionSimplifier - Remove redundant instructions. 35885289Sdes// 35985289SdesFunctionPass *createInstructionSimplifierPass(); 36085289Sdesextern char &InstructionSimplifierID; 36185289Sdes 36285289Sdes 36385289Sdes//===----------------------------------------------------------------------===// 36485289Sdes// 36585289Sdes// LowerExpectIntriniscs - Removes llvm.expect intrinsics and creates 36685289Sdes// "block_weights" metadata. 36785289SdesFunctionPass *createLowerExpectIntrinsicPass(); 36885289Sdes 36985289Sdes 37085289Sdes} // End llvm namespace 37185289Sdes 37285289Sdes#endif 37385289Sdes