1 //===-- Local.h - Functions to perform local transformations ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This family of functions perform various local transformations to the
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TRANSFORMS_UTILS_LOCAL_H
16 #define LLVM_TRANSFORMS_UTILS_LOCAL_H
30 struct DbgInfoIntrinsic;
32 template<typename T> class SmallVectorImpl;
34 //===----------------------------------------------------------------------===//
38 /// isSafeToLoadUnconditionally - Return true if we know that executing a load
39 /// from this value cannot trap. If it is not obviously safe to load from the
40 /// specified pointer, we do a quick local scan of the basic block containing
41 /// ScanFrom, to determine if the address is already accessed.
42 bool isSafeToLoadUnconditionally(Value *V, Instruction *ScanFrom);
44 //===----------------------------------------------------------------------===//
45 // Local constant propagation.
48 /// ConstantFoldTerminator - If a terminator instruction is predicated on a
49 /// constant value, convert it into an unconditional branch to the constant
50 /// destination. This is a nontrivial operation because the successors of this
51 /// basic block must have their PHI nodes updated.
53 bool ConstantFoldTerminator(BasicBlock *BB);
55 //===----------------------------------------------------------------------===//
56 // Local dead code elimination.
59 /// isInstructionTriviallyDead - Return true if the result produced by the
60 /// instruction is not used, and the instruction has no side effects.
62 bool isInstructionTriviallyDead(Instruction *I);
64 /// RecursivelyDeleteTriviallyDeadInstructions - If the specified value is a
65 /// trivially dead instruction, delete it. If that makes any of its operands
66 /// trivially dead, delete them too, recursively.
67 void RecursivelyDeleteTriviallyDeadInstructions(Value *V);
69 /// RecursivelyDeleteDeadPHINode - If the specified value is an effectively
70 /// dead PHI node, due to being a def-use chain of single-use nodes that
71 /// either forms a cycle or is terminated by a trivially dead instruction,
72 /// delete it. If that makes any of its operands trivially dead, delete them
74 void RecursivelyDeleteDeadPHINode(PHINode *PN);
76 //===----------------------------------------------------------------------===//
77 // Control Flow Graph Restructuring.
80 /// MergeBasicBlockIntoOnlyPred - BB is a block with one predecessor and its
81 /// predecessor is known to have one successor (BB!). Eliminate the edge
82 /// between them, moving the instructions in the predecessor into BB. This
83 /// deletes the predecessor block.
85 void MergeBasicBlockIntoOnlyPred(BasicBlock *BB);
88 /// SimplifyCFG - This function is used to do simplification of a CFG. For
89 /// example, it adjusts branches to branches to eliminate the extra hop, it
90 /// eliminates unreachable basic blocks, and does other "peephole" optimization
91 /// of the CFG. It returns true if a modification was made, possibly deleting
92 /// the basic block that was pointed to.
94 /// WARNING: The entry node of a method may not be simplified.
96 bool SimplifyCFG(BasicBlock *BB);
98 /// FoldBranchToCommonDest - If this basic block is ONLY a setcc and a branch,
99 /// and if a predecessor branches to us and one of our successors, fold the
100 /// setcc into the predecessor and use logical operations to pick the right
102 bool FoldBranchToCommonDest(BranchInst *BI);
104 /// DemoteRegToStack - This function takes a virtual register computed by an
105 /// Instruction and replaces it with a slot in the stack frame, allocated via
106 /// alloca. This allows the CFG to be changed around without fear of
107 /// invalidating the SSA information for the value. It returns the pointer to
108 /// the alloca inserted to create a stack slot for X.
110 AllocaInst *DemoteRegToStack(Instruction &X, bool VolatileLoads = false,
111 Instruction *AllocaPoint = 0);
113 /// DemotePHIToStack - This function takes a virtual register computed by a phi
114 /// node and replaces it with a slot in the stack frame, allocated via alloca.
115 /// The phi node is deleted and it returns the pointer to the alloca inserted.
116 AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = 0);
118 /// OnlyUsedByDbgIntrinsics - Return true if the instruction I is only used
119 /// by DbgIntrinsics. If DbgInUses is specified then the vector is filled
120 /// with DbgInfoIntrinsic that use the instruction I.
121 bool OnlyUsedByDbgInfoIntrinsics(Instruction *I,
122 SmallVectorImpl<DbgInfoIntrinsic *> *DbgInUses = 0);
124 } // End llvm namespace