Revert r70645 for now; it's causing a variety of regressions.
[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 constant propagation.
35 //
36
37 /// ConstantFoldTerminator - If a terminator instruction is predicated on a
38 /// constant value, convert it into an unconditional branch to the constant
39 /// destination.  This is a nontrivial operation because the successors of this
40 /// basic block must have their PHI nodes updated.
41 ///
42 bool ConstantFoldTerminator(BasicBlock *BB);
43
44 //===----------------------------------------------------------------------===//
45 //  Local dead code elimination.
46 //
47
48 /// isInstructionTriviallyDead - Return true if the result produced by the
49 /// instruction is not used, and the instruction has no side effects.
50 ///
51 bool isInstructionTriviallyDead(Instruction *I);
52
53 /// ValueDeletionListener - A simple abstract interface for delivering
54 /// notifications when Values are deleted.
55 ///
56 /// @todo Consider whether ValueDeletionListener can be made obsolete by
57 ///       requiring clients to use CallbackVH instead.
58 class ValueDeletionListener {
59 public:
60   /// ValueWillBeDeleted - This method is called shortly before the specified
61   /// value will be deleted.
62   virtual void ValueWillBeDeleted(Value *V) = 0;
63
64 protected:
65   virtual ~ValueDeletionListener();
66 };
67
68 /// RecursivelyDeleteTriviallyDeadInstructions - If the specified value is a
69 /// trivially dead instruction, delete it.  If that makes any of its operands
70 /// trivially dead, delete them too, recursively.
71 ///
72 /// If a ValueDeletionListener is specified, it is notified of instructions that
73 /// are actually deleted (before they are actually deleted).
74 void RecursivelyDeleteTriviallyDeadInstructions(Value *V,
75                                                 ValueDeletionListener *VDL = 0);
76
77 /// RecursivelyDeleteDeadPHINode - If the specified value is an effectively
78 /// dead PHI node, due to being a def-use chain of single-use nodes that
79 /// either forms a cycle or is terminated by a trivially dead instruction,
80 /// delete it.  If that makes any of its operands trivially dead, delete them
81 /// too, recursively.
82 ///
83 /// If a ValueDeletionListener is specified, it is notified of instructions that
84 /// are actually deleted (before they are actually deleted).
85 void RecursivelyDeleteDeadPHINode(PHINode *PN,
86                                   ValueDeletionListener *VDL = 0);
87
88 //===----------------------------------------------------------------------===//
89 //  Control Flow Graph Restructuring.
90 //
91
92 /// MergeBasicBlockIntoOnlyPred - BB is a block with one predecessor and its
93 /// predecessor is known to have one successor (BB!).  Eliminate the edge
94 /// between them, moving the instructions in the predecessor into BB.  This
95 /// deletes the predecessor block.
96 ///
97 void MergeBasicBlockIntoOnlyPred(BasicBlock *BB);
98     
99   
100 /// SimplifyCFG - This function is used to do simplification of a CFG.  For
101 /// example, it adjusts branches to branches to eliminate the extra hop, it
102 /// eliminates unreachable basic blocks, and does other "peephole" optimization
103 /// of the CFG.  It returns true if a modification was made, possibly deleting
104 /// the basic block that was pointed to.
105 ///
106 /// WARNING:  The entry node of a method may not be simplified.
107 ///
108 bool SimplifyCFG(BasicBlock *BB);
109
110 /// DemoteRegToStack - This function takes a virtual register computed by an
111 /// Instruction and replaces it with a slot in the stack frame, allocated via
112 /// alloca.  This allows the CFG to be changed around without fear of
113 /// invalidating the SSA information for the value.  It returns the pointer to
114 /// the alloca inserted to create a stack slot for X.
115 ///
116 AllocaInst *DemoteRegToStack(Instruction &X, bool VolatileLoads = false,
117                              Instruction *AllocaPoint = 0);
118
119 /// DemotePHIToStack - This function takes a virtual register computed by a phi
120 /// node and replaces it with a slot in the stack frame, allocated via alloca.
121 /// The phi node is deleted and it returns the pointer to the alloca inserted. 
122 AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = 0);
123
124 /// OnlyUsedByDbgIntrinsics - Return true if the instruction I is only used
125 /// by DbgIntrinsics. If DbgInUses is specified then the vector is filled 
126 /// with DbgInfoIntrinsic that use the instruction I.
127 bool OnlyUsedByDbgInfoIntrinsics(Instruction *I, 
128                            SmallVectorImpl<DbgInfoIntrinsic *> *DbgInUses = 0);
129
130 /// UserIsDebugInfo - Return true if U is a constant expr used by 
131 /// llvm.dbg.variable or llvm.dbg.global_variable
132 bool UserIsDebugInfo(User *U);
133
134 /// RemoveDbgInfoUser - Remove an User which is representing debug info.
135 void RemoveDbgInfoUser(User *U);
136
137 } // End llvm namespace
138
139 #endif