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