2003-09-30 18:37:50 +00:00
|
|
|
//===-- Local.h - Functions to perform local transformations ----*- C++ -*-===//
|
2005-04-21 20:59:05 +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:59:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-05-07 18:52:48 +00:00
|
|
|
//
|
|
|
|
// This family of functions perform various local transformations to the
|
|
|
|
// program.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_TRANSFORMS_UTILS_LOCAL_H
|
|
|
|
#define LLVM_TRANSFORMS_UTILS_LOCAL_H
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2009-03-06 00:19:37 +00:00
|
|
|
class User;
|
2009-01-05 17:59:02 +00:00
|
|
|
class BasicBlock;
|
2009-06-27 21:30:38 +00:00
|
|
|
class BranchInst;
|
2009-01-05 17:59:02 +00:00
|
|
|
class Instruction;
|
|
|
|
class Value;
|
2002-09-06 02:19:25 +00:00
|
|
|
class Pass;
|
2003-12-19 05:56:28 +00:00
|
|
|
class PHINode;
|
2004-03-14 02:13:07 +00:00
|
|
|
class AllocaInst;
|
2005-09-26 05:26:32 +00:00
|
|
|
class ConstantExpr;
|
2007-01-30 23:12:47 +00:00
|
|
|
class TargetData;
|
2009-08-11 17:45:13 +00:00
|
|
|
class LLVMContext;
|
2009-02-14 16:06:42 +00:00
|
|
|
struct DbgInfoIntrinsic;
|
2009-01-05 17:59:02 +00:00
|
|
|
|
|
|
|
template<typename T> class SmallVectorImpl;
|
2008-11-27 23:14:34 +00:00
|
|
|
|
2009-06-16 17:23:12 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Local analysis.
|
|
|
|
//
|
|
|
|
|
|
|
|
/// isSafeToLoadUnconditionally - Return true if we know that executing a load
|
|
|
|
/// from this value cannot trap. If it is not obviously safe to load from the
|
|
|
|
/// specified pointer, we do a quick local scan of the basic block containing
|
|
|
|
/// ScanFrom, to determine if the address is already accessed.
|
|
|
|
bool isSafeToLoadUnconditionally(Value *V, Instruction *ScanFrom);
|
|
|
|
|
2002-05-07 18:52:48 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-11-27 22:57:53 +00:00
|
|
|
// Local constant propagation.
|
2002-05-07 18:52:48 +00:00
|
|
|
//
|
|
|
|
|
2002-09-06 02:19:25 +00:00
|
|
|
/// ConstantFoldTerminator - If a terminator instruction is predicated on a
|
|
|
|
/// constant value, convert it into an unconditional branch to the constant
|
|
|
|
/// destination. This is a nontrivial operation because the successors of this
|
|
|
|
/// basic block must have their PHI nodes updated.
|
|
|
|
///
|
2002-05-21 20:04:50 +00:00
|
|
|
bool ConstantFoldTerminator(BasicBlock *BB);
|
2002-05-07 18:52:48 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2008-11-27 22:57:53 +00:00
|
|
|
// Local dead code elimination.
|
2002-05-07 18:52:48 +00:00
|
|
|
//
|
|
|
|
|
2002-09-06 02:19:25 +00:00
|
|
|
/// isInstructionTriviallyDead - Return true if the result produced by the
|
|
|
|
/// instruction is not used, and the instruction has no side effects.
|
|
|
|
///
|
2002-05-07 18:52:48 +00:00
|
|
|
bool isInstructionTriviallyDead(Instruction *I);
|
|
|
|
|
2008-11-27 22:57:53 +00:00
|
|
|
/// RecursivelyDeleteTriviallyDeadInstructions - If the specified value is a
|
|
|
|
/// trivially dead instruction, delete it. If that makes any of its operands
|
|
|
|
/// trivially dead, delete them too, recursively.
|
2009-05-04 22:30:44 +00:00
|
|
|
void RecursivelyDeleteTriviallyDeadInstructions(Value *V);
|
2009-05-02 18:29:22 +00:00
|
|
|
|
|
|
|
/// RecursivelyDeleteDeadPHINode - If the specified value is an effectively
|
|
|
|
/// dead PHI node, due to being a def-use chain of single-use nodes that
|
|
|
|
/// either forms a cycle or is terminated by a trivially dead instruction,
|
|
|
|
/// delete it. If that makes any of its operands trivially dead, delete them
|
|
|
|
/// too, recursively.
|
2009-05-04 22:30:44 +00:00
|
|
|
void RecursivelyDeleteDeadPHINode(PHINode *PN);
|
2009-05-02 18:29:22 +00:00
|
|
|
|
2002-05-07 18:52:48 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-12-03 19:44:02 +00:00
|
|
|
// Control Flow Graph Restructuring.
|
2002-05-07 18:52:48 +00:00
|
|
|
//
|
|
|
|
|
2008-11-27 07:43:12 +00:00
|
|
|
/// MergeBasicBlockIntoOnlyPred - BB is a block with one predecessor and its
|
|
|
|
/// predecessor is known to have one successor (BB!). Eliminate the edge
|
|
|
|
/// between them, moving the instructions in the predecessor into BB. This
|
|
|
|
/// deletes the predecessor block.
|
|
|
|
///
|
|
|
|
void MergeBasicBlockIntoOnlyPred(BasicBlock *BB);
|
|
|
|
|
|
|
|
|
2002-09-06 02:19:25 +00:00
|
|
|
/// SimplifyCFG - This function is used to do simplification of a CFG. For
|
|
|
|
/// example, it adjusts branches to branches to eliminate the extra hop, it
|
|
|
|
/// eliminates unreachable basic blocks, and does other "peephole" optimization
|
|
|
|
/// of the CFG. It returns true if a modification was made, possibly deleting
|
|
|
|
/// the basic block that was pointed to.
|
|
|
|
///
|
|
|
|
/// WARNING: The entry node of a method may not be simplified.
|
|
|
|
///
|
2002-06-25 16:12:52 +00:00
|
|
|
bool SimplifyCFG(BasicBlock *BB);
|
2002-05-07 18:52:48 +00:00
|
|
|
|
2009-06-27 21:30:38 +00:00
|
|
|
/// FoldBranchToCommonDest - If this basic block is ONLY a setcc and a branch,
|
|
|
|
/// and if a predecessor branches to us and one of our successors, fold the
|
|
|
|
/// setcc into the predecessor and use logical operations to pick the right
|
|
|
|
/// destination.
|
|
|
|
bool FoldBranchToCommonDest(BranchInst *BI);
|
|
|
|
|
2004-03-14 02:13:07 +00:00
|
|
|
/// DemoteRegToStack - This function takes a virtual register computed by an
|
2004-03-17 01:29:36 +00:00
|
|
|
/// Instruction and replaces it with a slot in the stack frame, allocated via
|
2004-03-14 02:13:07 +00:00
|
|
|
/// alloca. This allows the CFG to be changed around without fear of
|
|
|
|
/// invalidating the SSA information for the value. It returns the pointer to
|
|
|
|
/// the alloca inserted to create a stack slot for X.
|
|
|
|
///
|
2009-07-15 23:53:25 +00:00
|
|
|
AllocaInst *DemoteRegToStack(Instruction &X,
|
2009-07-14 23:09:55 +00:00
|
|
|
bool VolatileLoads = false,
|
2009-01-05 17:59:02 +00:00
|
|
|
Instruction *AllocaPoint = 0);
|
2004-03-14 02:13:07 +00:00
|
|
|
|
2007-07-11 18:41:34 +00:00
|
|
|
/// DemotePHIToStack - This function takes a virtual register computed by a phi
|
|
|
|
/// node and replaces it with a slot in the stack frame, allocated via alloca.
|
|
|
|
/// The phi node is deleted and it returns the pointer to the alloca inserted.
|
2009-07-15 23:53:25 +00:00
|
|
|
AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = 0);
|
2007-07-11 18:41:34 +00:00
|
|
|
|
2009-02-10 07:00:59 +00:00
|
|
|
/// OnlyUsedByDbgIntrinsics - Return true if the instruction I is only used
|
|
|
|
/// by DbgIntrinsics. If DbgInUses is specified then the vector is filled
|
|
|
|
/// with DbgInfoIntrinsic that use the instruction I.
|
|
|
|
bool OnlyUsedByDbgInfoIntrinsics(Instruction *I,
|
|
|
|
SmallVectorImpl<DbgInfoIntrinsic *> *DbgInUses = 0);
|
2009-03-06 00:19:37 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2002-05-07 18:52:48 +00:00
|
|
|
#endif
|