llvm::ConstantFoldInstruction
[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 was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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
25 //===----------------------------------------------------------------------===//
26 //  Local constant propagation...
27 //
28
29 /// doConstantPropagation - Constant prop a specific instruction.  Returns true
30 /// and potentially moves the iterator if constant propagation was performed.
31 ///
32 bool doConstantPropagation(BasicBlock::iterator &I);
33
34 /// ConstantFoldTerminator - If a terminator instruction is predicated on a
35 /// constant value, convert it into an unconditional branch to the constant
36 /// destination.  This is a nontrivial operation because the successors of this
37 /// basic block must have their PHI nodes updated.
38 ///
39 bool ConstantFoldTerminator(BasicBlock *BB);
40
41 /// ConstantFoldInstruction - Attempt to constant fold the specified
42 /// instruction.  If successful, the constant result is returned, if not, null
43 /// is returned.  Note that this function can only fail when attempting to fold
44 /// instructions like loads and stores, which have no constant expression form.
45 ///
46 Constant *ConstantFoldInstruction(Instruction *I);
47
48
49 //===----------------------------------------------------------------------===//
50 //  Local dead code elimination...
51 //
52
53 /// isInstructionTriviallyDead - Return true if the result produced by the
54 /// instruction is not used, and the instruction has no side effects.
55 ///
56 bool isInstructionTriviallyDead(Instruction *I);
57
58
59 /// dceInstruction - Inspect the instruction at *BBI and figure out if it
60 /// isTriviallyDead.  If so, remove the instruction and update the iterator to
61 /// point to the instruction that immediately succeeded the original
62 /// instruction.
63 ///
64 bool dceInstruction(BasicBlock::iterator &BBI);
65
66 //===----------------------------------------------------------------------===//
67 //  PHI Instruction Simplification
68 //
69
70 /// hasConstantValue - If the specified PHI node always merges together the same
71 /// value, return the value, otherwise return null.
72 ///
73 Value *hasConstantValue(PHINode *PN);
74
75
76 //===----------------------------------------------------------------------===//
77 //  Control Flow Graph Restructuring...
78 //
79
80 /// SimplifyCFG - This function is used to do simplification of a CFG.  For
81 /// example, it adjusts branches to branches to eliminate the extra hop, it
82 /// eliminates unreachable basic blocks, and does other "peephole" optimization
83 /// of the CFG.  It returns true if a modification was made, possibly deleting
84 /// the basic block that was pointed to.
85 ///
86 /// WARNING:  The entry node of a method may not be simplified.
87 ///
88 bool SimplifyCFG(BasicBlock *BB);
89
90 } // End llvm namespace
91
92 #endif