1 //===-- Local.h - Functions to perform local transformations ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This family of functions perform various local transformations to the
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TRANSFORMS_UTILS_LOCAL_H
16 #define LLVM_TRANSFORMS_UTILS_LOCAL_H
18 #include "llvm/Function.h"
27 //===----------------------------------------------------------------------===//
28 // Local constant propagation...
31 /// doConstantPropagation - Constant prop a specific instruction. Returns true
32 /// and potentially moves the iterator if constant propagation was performed.
34 bool doConstantPropagation(BasicBlock::iterator &I);
36 /// ConstantFoldTerminator - If a terminator instruction is predicated on a
37 /// constant value, convert it into an unconditional branch to the constant
38 /// destination. This is a nontrivial operation because the successors of this
39 /// basic block must have their PHI nodes updated.
41 bool ConstantFoldTerminator(BasicBlock *BB);
43 /// ConstantFoldInstruction - Attempt to constant fold the specified
44 /// instruction. If successful, the constant result is returned, if not, null
45 /// is returned. Note that this function can only fail when attempting to fold
46 /// instructions like loads and stores, which have no constant expression form.
48 Constant *ConstantFoldInstruction(Instruction *I);
51 /// canConstantFoldCallTo - Return true if its even possible to fold a call to
52 /// the specified function.
53 bool canConstantFoldCallTo(Function *F);
55 /// ConstantFoldCall - Attempt to constant fold a call to the specified function
56 /// with the specified arguments, returning null if unsuccessful.
57 Constant *ConstantFoldCall(Function *F, const std::vector<Constant*> &Operands);
59 /// ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a
60 /// getelementptr constantexpr, return the constant value being addressed by the
61 /// constant expression, or null if something is funny and we can't decide.
62 Constant *ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE);
64 //===----------------------------------------------------------------------===//
65 // Local dead code elimination...
68 /// isInstructionTriviallyDead - Return true if the result produced by the
69 /// instruction is not used, and the instruction has no side effects.
71 bool isInstructionTriviallyDead(Instruction *I);
74 /// dceInstruction - Inspect the instruction at *BBI and figure out if it
75 /// isTriviallyDead. If so, remove the instruction and update the iterator to
76 /// point to the instruction that immediately succeeded the original
79 bool dceInstruction(BasicBlock::iterator &BBI);
81 //===----------------------------------------------------------------------===//
82 // Control Flow Graph Restructuring...
85 /// SimplifyCFG - This function is used to do simplification of a CFG. For
86 /// example, it adjusts branches to branches to eliminate the extra hop, it
87 /// eliminates unreachable basic blocks, and does other "peephole" optimization
88 /// of the CFG. It returns true if a modification was made, possibly deleting
89 /// the basic block that was pointed to.
91 /// WARNING: The entry node of a method may not be simplified.
93 bool SimplifyCFG(BasicBlock *BB);
95 /// DemoteRegToStack - This function takes a virtual register computed by an
96 /// Instruction and replaces it with a slot in the stack frame, allocated via
97 /// alloca. This allows the CFG to be changed around without fear of
98 /// invalidating the SSA information for the value. It returns the pointer to
99 /// the alloca inserted to create a stack slot for X.
101 AllocaInst *DemoteRegToStack(Instruction &X, bool VolatileLoads = false);
103 } // End llvm namespace