Change constant folding APIs to take an optional TargetData, and change
[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 #include "llvm/Analysis/ConstantFolding.h"
20
21 namespace llvm {
22
23 class Pass;
24 class PHINode;
25 class AllocaInst;
26 class ConstantExpr;
27 class TargetData;
28
29 //===----------------------------------------------------------------------===//
30 //  Local constant propagation...
31 //
32
33 /// doConstantPropagation - Constant prop a specific instruction.  Returns true
34 /// and potentially moves the iterator if constant propagation was performed.
35 ///
36 bool doConstantPropagation(BasicBlock::iterator &I, const TargetData *TD = 0);
37
38 /// ConstantFoldTerminator - If a terminator instruction is predicated on a
39 /// constant value, convert it into an unconditional branch to the constant
40 /// destination.  This is a nontrivial operation because the successors of this
41 /// basic block must have their PHI nodes updated.
42 ///
43 bool ConstantFoldTerminator(BasicBlock *BB);
44
45 /// ConstantFoldInstruction - Attempt to constant fold the specified
46 /// instruction.  If successful, the constant result is returned, if not, null
47 /// is returned.  Note that this function can only fail when attempting to fold
48 /// instructions like loads and stores, which have no constant expression form.
49 ///
50 Constant *ConstantFoldInstruction(Instruction *I, const TargetData *TD = 0);
51
52 /// ConstantFoldInstOperands - Attempt to constant fold an instruction with the
53 /// specified operands.  If successful, the constant result is returned, if not,
54 /// null is returned.  Note that this function can fail when attempting to 
55 /// fold instructions like loads and stores, which have no constant expression 
56 /// form.
57 ///
58 Constant *ConstantFoldInstOperands(
59   const Instruction *I, ///< The model instruction
60   Constant** Ops,       ///< The array of constant operands to use.
61   unsigned NumOps,      ///< The number of operands provided.
62   const TargetData *TD = 0 ///< Optional target information.
63 );
64
65
66 /// ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a
67 /// getelementptr constantexpr, return the constant value being addressed by the
68 /// constant expression, or null if something is funny and we can't decide.
69 Constant *ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE);
70
71 //===----------------------------------------------------------------------===//
72 //  Local dead code elimination...
73 //
74
75 /// isInstructionTriviallyDead - Return true if the result produced by the
76 /// instruction is not used, and the instruction has no side effects.
77 ///
78 bool isInstructionTriviallyDead(Instruction *I);
79
80
81 /// dceInstruction - Inspect the instruction at *BBI and figure out if it
82 /// isTriviallyDead.  If so, remove the instruction and update the iterator to
83 /// point to the instruction that immediately succeeded the original
84 /// instruction.
85 ///
86 bool dceInstruction(BasicBlock::iterator &BBI);
87
88 //===----------------------------------------------------------------------===//
89 //  Control Flow Graph Restructuring...
90 //
91
92 /// SimplifyCFG - This function is used to do simplification of a CFG.  For
93 /// example, it adjusts branches to branches to eliminate the extra hop, it
94 /// eliminates unreachable basic blocks, and does other "peephole" optimization
95 /// of the CFG.  It returns true if a modification was made, possibly deleting
96 /// the basic block that was pointed to.
97 ///
98 /// WARNING:  The entry node of a method may not be simplified.
99 ///
100 bool SimplifyCFG(BasicBlock *BB);
101
102 /// DemoteRegToStack - This function takes a virtual register computed by an
103 /// Instruction and replaces it with a slot in the stack frame, allocated via
104 /// alloca.  This allows the CFG to be changed around without fear of
105 /// invalidating the SSA information for the value.  It returns the pointer to
106 /// the alloca inserted to create a stack slot for X.
107 ///
108 AllocaInst *DemoteRegToStack(Instruction &X, bool VolatileLoads = false);
109
110 } // End llvm namespace
111
112 #endif