1 //===-- Local.h - Functions to perform local transformations ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // 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"
28 //===----------------------------------------------------------------------===//
29 // Local constant propagation...
32 /// doConstantPropagation - Constant prop a specific instruction. Returns true
33 /// and potentially moves the iterator if constant propagation was performed.
35 bool doConstantPropagation(BasicBlock::iterator &I, const TargetData *TD = 0);
37 /// ConstantFoldTerminator - If a terminator instruction is predicated on a
38 /// constant value, convert it into an unconditional branch to the constant
39 /// destination. This is a nontrivial operation because the successors of this
40 /// basic block must have their PHI nodes updated.
42 bool ConstantFoldTerminator(BasicBlock *BB);
44 //===----------------------------------------------------------------------===//
45 // Local dead code elimination...
48 /// isInstructionTriviallyDead - Return true if the result produced by the
49 /// instruction is not used, and the instruction has no side effects.
51 bool isInstructionTriviallyDead(Instruction *I);
54 /// dceInstruction - Inspect the instruction at *BBI and figure out if it
55 /// isTriviallyDead. If so, remove the instruction and update the iterator to
56 /// point to the instruction that immediately succeeded the original
59 bool dceInstruction(BasicBlock::iterator &BBI);
61 //===----------------------------------------------------------------------===//
62 // Control Flow Graph Restructuring...
65 /// SimplifyCFG - This function is used to do simplification of a CFG. For
66 /// example, it adjusts branches to branches to eliminate the extra hop, it
67 /// eliminates unreachable basic blocks, and does other "peephole" optimization
68 /// of the CFG. It returns true if a modification was made, possibly deleting
69 /// the basic block that was pointed to.
71 /// WARNING: The entry node of a method may not be simplified.
73 bool SimplifyCFG(BasicBlock *BB);
75 /// DemoteRegToStack - This function takes a virtual register computed by an
76 /// Instruction and replaces it with a slot in the stack frame, allocated via
77 /// alloca. This allows the CFG to be changed around without fear of
78 /// invalidating the SSA information for the value. It returns the pointer to
79 /// the alloca inserted to create a stack slot for X.
81 AllocaInst *DemoteRegToStack(Instruction &X, bool VolatileLoads = false,
82 Instruction *AllocaPoint = NULL);
84 /// DemotePHIToStack - This function takes a virtual register computed by a phi
85 /// node and replaces it with a slot in the stack frame, allocated via alloca.
86 /// The phi node is deleted and it returns the pointer to the alloca inserted.
87 AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = NULL);
89 } // End llvm namespace