Generalize instcombine's isSafeToLoadUnconditionally() function
[oota-llvm.git] / include / llvm / Transforms / Utils / Local.h
1 //===-- Local.h - Functions to perform local transformations ----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This family of functions perform various local transformations to the
11 // program.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_TRANSFORMS_UTILS_LOCAL_H
16 #define LLVM_TRANSFORMS_UTILS_LOCAL_H
17
18 namespace llvm {
19
20 class User;
21 class BasicBlock;
22 class Instruction;
23 class Value;
24 class Pass;
25 class PHINode;
26 class AllocaInst;
27 class ConstantExpr;
28 class TargetData;
29 struct DbgInfoIntrinsic;
30
31 template<typename T> class SmallVectorImpl;
32   
33 //===----------------------------------------------------------------------===//
34 //  Local analysis.
35 //
36
37 /// isSafeToLoadUnconditionally - Return true if we know that executing a load
38 /// from this value cannot trap.  If it is not obviously safe to load from the
39 /// specified pointer, we do a quick local scan of the basic block containing
40 /// ScanFrom, to determine if the address is already accessed.
41 bool isSafeToLoadUnconditionally(Value *V, Instruction *ScanFrom);
42
43 //===----------------------------------------------------------------------===//
44 //  Local constant propagation.
45 //
46
47 /// ConstantFoldTerminator - If a terminator instruction is predicated on a
48 /// constant value, convert it into an unconditional branch to the constant
49 /// destination.  This is a nontrivial operation because the successors of this
50 /// basic block must have their PHI nodes updated.
51 ///
52 bool ConstantFoldTerminator(BasicBlock *BB);
53
54 //===----------------------------------------------------------------------===//
55 //  Local dead code elimination.
56 //
57
58 /// isInstructionTriviallyDead - Return true if the result produced by the
59 /// instruction is not used, and the instruction has no side effects.
60 ///
61 bool isInstructionTriviallyDead(Instruction *I);
62
63 /// RecursivelyDeleteTriviallyDeadInstructions - If the specified value is a
64 /// trivially dead instruction, delete it.  If that makes any of its operands
65 /// trivially dead, delete them too, recursively.
66 void RecursivelyDeleteTriviallyDeadInstructions(Value *V);
67
68 /// RecursivelyDeleteDeadPHINode - If the specified value is an effectively
69 /// dead PHI node, due to being a def-use chain of single-use nodes that
70 /// either forms a cycle or is terminated by a trivially dead instruction,
71 /// delete it.  If that makes any of its operands trivially dead, delete them
72 /// too, recursively.
73 void RecursivelyDeleteDeadPHINode(PHINode *PN);
74
75 //===----------------------------------------------------------------------===//
76 //  Control Flow Graph Restructuring.
77 //
78
79 /// MergeBasicBlockIntoOnlyPred - BB is a block with one predecessor and its
80 /// predecessor is known to have one successor (BB!).  Eliminate the edge
81 /// between them, moving the instructions in the predecessor into BB.  This
82 /// deletes the predecessor block.
83 ///
84 void MergeBasicBlockIntoOnlyPred(BasicBlock *BB);
85     
86   
87 /// SimplifyCFG - This function is used to do simplification of a CFG.  For
88 /// example, it adjusts branches to branches to eliminate the extra hop, it
89 /// eliminates unreachable basic blocks, and does other "peephole" optimization
90 /// of the CFG.  It returns true if a modification was made, possibly deleting
91 /// the basic block that was pointed to.
92 ///
93 /// WARNING:  The entry node of a method may not be simplified.
94 ///
95 bool SimplifyCFG(BasicBlock *BB);
96
97 /// DemoteRegToStack - This function takes a virtual register computed by an
98 /// Instruction and replaces it with a slot in the stack frame, allocated via
99 /// alloca.  This allows the CFG to be changed around without fear of
100 /// invalidating the SSA information for the value.  It returns the pointer to
101 /// the alloca inserted to create a stack slot for X.
102 ///
103 AllocaInst *DemoteRegToStack(Instruction &X, bool VolatileLoads = false,
104                              Instruction *AllocaPoint = 0);
105
106 /// DemotePHIToStack - This function takes a virtual register computed by a phi
107 /// node and replaces it with a slot in the stack frame, allocated via alloca.
108 /// The phi node is deleted and it returns the pointer to the alloca inserted. 
109 AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = 0);
110
111 /// OnlyUsedByDbgIntrinsics - Return true if the instruction I is only used
112 /// by DbgIntrinsics. If DbgInUses is specified then the vector is filled 
113 /// with DbgInfoIntrinsic that use the instruction I.
114 bool OnlyUsedByDbgInfoIntrinsics(Instruction *I, 
115                            SmallVectorImpl<DbgInfoIntrinsic *> *DbgInUses = 0);
116
117 /// UserIsDebugInfo - Return true if U is a constant expr used by 
118 /// llvm.dbg.variable or llvm.dbg.global_variable
119 bool UserIsDebugInfo(User *U);
120
121 /// RemoveDbgInfoUser - Remove an User which is representing debug info.
122 void RemoveDbgInfoUser(User *U);
123
124 } // End llvm namespace
125
126 #endif