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
29 struct DbgInfoIntrinsic;
31 template<typename T> class SmallVectorImpl;
33 //===----------------------------------------------------------------------===//
34 // Local constant propagation.
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);
53 /// RecursivelyDeleteTriviallyDeadInstructions - If the specified value is a
54 /// trivially dead instruction, delete it. If that makes any of its operands
55 /// trivially dead, delete them too, recursively.
56 void RecursivelyDeleteTriviallyDeadInstructions(Value *V);
58 /// RecursivelyDeleteDeadPHINode - If the specified value is an effectively
59 /// dead PHI node, due to being a def-use chain of single-use nodes that
60 /// either forms a cycle or is terminated by a trivially dead instruction,
61 /// delete it. If that makes any of its operands trivially dead, delete them
63 void RecursivelyDeleteDeadPHINode(PHINode *PN);
65 //===----------------------------------------------------------------------===//
66 // Control Flow Graph Restructuring.
69 /// MergeBasicBlockIntoOnlyPred - BB is a block with one predecessor and its
70 /// predecessor is known to have one successor (BB!). Eliminate the edge
71 /// between them, moving the instructions in the predecessor into BB. This
72 /// deletes the predecessor block.
74 void MergeBasicBlockIntoOnlyPred(BasicBlock *BB);
77 /// SimplifyCFG - This function is used to do simplification of a CFG. For
78 /// example, it adjusts branches to branches to eliminate the extra hop, it
79 /// eliminates unreachable basic blocks, and does other "peephole" optimization
80 /// of the CFG. It returns true if a modification was made, possibly deleting
81 /// the basic block that was pointed to.
83 /// WARNING: The entry node of a method may not be simplified.
85 bool SimplifyCFG(BasicBlock *BB);
87 /// DemoteRegToStack - This function takes a virtual register computed by an
88 /// Instruction and replaces it with a slot in the stack frame, allocated via
89 /// alloca. This allows the CFG to be changed around without fear of
90 /// invalidating the SSA information for the value. It returns the pointer to
91 /// the alloca inserted to create a stack slot for X.
93 AllocaInst *DemoteRegToStack(Instruction &X, bool VolatileLoads = false,
94 Instruction *AllocaPoint = 0);
96 /// DemotePHIToStack - This function takes a virtual register computed by a phi
97 /// node and replaces it with a slot in the stack frame, allocated via alloca.
98 /// The phi node is deleted and it returns the pointer to the alloca inserted.
99 AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = 0);
101 /// OnlyUsedByDbgIntrinsics - Return true if the instruction I is only used
102 /// by DbgIntrinsics. If DbgInUses is specified then the vector is filled
103 /// with DbgInfoIntrinsic that use the instruction I.
104 bool OnlyUsedByDbgInfoIntrinsics(Instruction *I,
105 SmallVectorImpl<DbgInfoIntrinsic *> *DbgInUses = 0);
107 /// UserIsDebugInfo - Return true if U is a constant expr used by
108 /// llvm.dbg.variable or llvm.dbg.global_variable
109 bool UserIsDebugInfo(User *U);
111 /// RemoveDbgInfoUser - Remove an User which is representing debug info.
112 void RemoveDbgInfoUser(User *U);
114 } // End llvm namespace