Remove trailing whitespace
[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 class AllocaInst;
25
26 //===----------------------------------------------------------------------===//
27 //  Local constant propagation...
28 //
29
30 /// doConstantPropagation - Constant prop a specific instruction.  Returns true
31 /// and potentially moves the iterator if constant propagation was performed.
32 ///
33 bool doConstantPropagation(BasicBlock::iterator &I);
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 /// ConstantFoldInstruction - Attempt to constant fold the specified
43 /// instruction.  If successful, the constant result is returned, if not, null
44 /// is returned.  Note that this function can only fail when attempting to fold
45 /// instructions like loads and stores, which have no constant expression form.
46 ///
47 Constant *ConstantFoldInstruction(Instruction *I);
48
49
50 /// canConstantFoldCallTo - Return true if its even possible to fold a call to
51 /// the specified function.
52 bool canConstantFoldCallTo(Function *F);
53
54 /// ConstantFoldCall - Attempt to constant fold a call to the specified function
55 /// with the specified arguments, returning null if unsuccessful.
56 Constant *ConstantFoldCall(Function *F, const std::vector<Constant*> &Operands);
57
58
59 //===----------------------------------------------------------------------===//
60 //  Local dead code elimination...
61 //
62
63 /// isInstructionTriviallyDead - Return true if the result produced by the
64 /// instruction is not used, and the instruction has no side effects.
65 ///
66 bool isInstructionTriviallyDead(Instruction *I);
67
68
69 /// dceInstruction - Inspect the instruction at *BBI and figure out if it
70 /// isTriviallyDead.  If so, remove the instruction and update the iterator to
71 /// point to the instruction that immediately succeeded the original
72 /// instruction.
73 ///
74 bool dceInstruction(BasicBlock::iterator &BBI);
75
76 //===----------------------------------------------------------------------===//
77 //  PHI Instruction Simplification
78 //
79
80 /// hasConstantValue - If the specified PHI node always merges together the same
81 /// value, return the value, otherwise return null.
82 ///
83 Value *hasConstantValue(PHINode *PN);
84
85
86 //===----------------------------------------------------------------------===//
87 //  Control Flow Graph Restructuring...
88 //
89
90 /// SimplifyCFG - This function is used to do simplification of a CFG.  For
91 /// example, it adjusts branches to branches to eliminate the extra hop, it
92 /// eliminates unreachable basic blocks, and does other "peephole" optimization
93 /// of the CFG.  It returns true if a modification was made, possibly deleting
94 /// the basic block that was pointed to.
95 ///
96 /// WARNING:  The entry node of a method may not be simplified.
97 ///
98 bool SimplifyCFG(BasicBlock *BB);
99
100 /// DemoteRegToStack - This function takes a virtual register computed by an
101 /// Instruction and replaces it with a slot in the stack frame, allocated via
102 /// alloca.  This allows the CFG to be changed around without fear of
103 /// invalidating the SSA information for the value.  It returns the pointer to
104 /// the alloca inserted to create a stack slot for X.
105 ///
106 AllocaInst *DemoteRegToStack(Instruction &X);
107
108 } // End llvm namespace
109
110 #endif