Ignore dbg intrinsics while propagating conditional expression info.
[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 BasicBlock;
21 class Instruction;
22 class Value;
23 class Pass;
24 class PHINode;
25 class AllocaInst;
26 class ConstantExpr;
27 class TargetData;
28
29 template<typename T> class SmallVectorImpl;
30   
31 //===----------------------------------------------------------------------===//
32 //  Local constant propagation.
33 //
34
35 /// ConstantFoldTerminator - If a terminator instruction is predicated on a
36 /// constant value, convert it into an unconditional branch to the constant
37 /// destination.  This is a nontrivial operation because the successors of this
38 /// basic block must have their PHI nodes updated.
39 ///
40 bool ConstantFoldTerminator(BasicBlock *BB);
41
42 //===----------------------------------------------------------------------===//
43 //  CFG Simplification
44 //
45
46 /// isTerminatorFirstRelevantInsn - Return true if Term is very first 
47 /// instruction ignoring Phi nodes and dbg intrinsics.
48 bool isTerminatorFirstRelevantInsn(BasicBlock *BB, Instruction *Term);
49
50 //===----------------------------------------------------------------------===//
51 //  Local dead code elimination.
52 //
53
54 /// isInstructionTriviallyDead - Return true if the result produced by the
55 /// instruction is not used, and the instruction has no side effects.
56 ///
57 bool isInstructionTriviallyDead(Instruction *I);
58
59   
60 /// RecursivelyDeleteTriviallyDeadInstructions - If the specified value is a
61 /// trivially dead instruction, delete it.  If that makes any of its operands
62 /// trivially dead, delete them too, recursively.
63 ///
64 /// If DeadInst is specified, the vector is filled with the instructions that
65 /// are actually deleted.
66 void RecursivelyDeleteTriviallyDeadInstructions(Value *V,
67                                   SmallVectorImpl<Instruction*> *DeadInst = 0);
68     
69 //===----------------------------------------------------------------------===//
70 //  Control Flow Graph Restructuring.
71 //
72
73 /// MergeBasicBlockIntoOnlyPred - BB is a block with one predecessor and its
74 /// predecessor is known to have one successor (BB!).  Eliminate the edge
75 /// between them, moving the instructions in the predecessor into BB.  This
76 /// deletes the predecessor block.
77 ///
78 void MergeBasicBlockIntoOnlyPred(BasicBlock *BB);
79     
80   
81 /// SimplifyCFG - This function is used to do simplification of a CFG.  For
82 /// example, it adjusts branches to branches to eliminate the extra hop, it
83 /// eliminates unreachable basic blocks, and does other "peephole" optimization
84 /// of the CFG.  It returns true if a modification was made, possibly deleting
85 /// the basic block that was pointed to.
86 ///
87 /// WARNING:  The entry node of a method may not be simplified.
88 ///
89 bool SimplifyCFG(BasicBlock *BB);
90
91 /// DemoteRegToStack - This function takes a virtual register computed by an
92 /// Instruction and replaces it with a slot in the stack frame, allocated via
93 /// alloca.  This allows the CFG to be changed around without fear of
94 /// invalidating the SSA information for the value.  It returns the pointer to
95 /// the alloca inserted to create a stack slot for X.
96 ///
97 AllocaInst *DemoteRegToStack(Instruction &X, bool VolatileLoads = false,
98                              Instruction *AllocaPoint = 0);
99
100 /// DemotePHIToStack - This function takes a virtual register computed by a phi
101 /// node and replaces it with a slot in the stack frame, allocated via alloca.
102 /// The phi node is deleted and it returns the pointer to the alloca inserted. 
103 AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = 0);
104
105 } // End llvm namespace
106
107 #endif