LLVM API Documentation
00001 //===-- Local.h - Functions to perform local transformations ----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This family of functions perform various local transformations to the 00011 // program. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_TRANSFORMS_UTILS_LOCAL_H 00016 #define LLVM_TRANSFORMS_UTILS_LOCAL_H 00017 00018 namespace llvm { 00019 00020 class User; 00021 class BasicBlock; 00022 class BranchInst; 00023 class Instruction; 00024 class Value; 00025 class Pass; 00026 class PHINode; 00027 class AllocaInst; 00028 class ConstantExpr; 00029 class TargetData; 00030 class LLVMContext; 00031 struct DbgInfoIntrinsic; 00032 00033 template<typename T> class SmallVectorImpl; 00034 00035 //===----------------------------------------------------------------------===// 00036 // Local analysis. 00037 // 00038 00039 /// isSafeToLoadUnconditionally - Return true if we know that executing a load 00040 /// from this value cannot trap. If it is not obviously safe to load from the 00041 /// specified pointer, we do a quick local scan of the basic block containing 00042 /// ScanFrom, to determine if the address is already accessed. 00043 bool isSafeToLoadUnconditionally(Value *V, Instruction *ScanFrom); 00044 00045 //===----------------------------------------------------------------------===// 00046 // Local constant propagation. 00047 // 00048 00049 /// ConstantFoldTerminator - If a terminator instruction is predicated on a 00050 /// constant value, convert it into an unconditional branch to the constant 00051 /// destination. This is a nontrivial operation because the successors of this 00052 /// basic block must have their PHI nodes updated. 00053 /// 00054 bool ConstantFoldTerminator(BasicBlock *BB); 00055 00056 //===----------------------------------------------------------------------===// 00057 // Local dead code elimination. 00058 // 00059 00060 /// isInstructionTriviallyDead - Return true if the result produced by the 00061 /// instruction is not used, and the instruction has no side effects. 00062 /// 00063 bool isInstructionTriviallyDead(Instruction *I); 00064 00065 /// RecursivelyDeleteTriviallyDeadInstructions - If the specified value is a 00066 /// trivially dead instruction, delete it. If that makes any of its operands 00067 /// trivially dead, delete them too, recursively. 00068 void RecursivelyDeleteTriviallyDeadInstructions(Value *V); 00069 00070 /// RecursivelyDeleteDeadPHINode - If the specified value is an effectively 00071 /// dead PHI node, due to being a def-use chain of single-use nodes that 00072 /// either forms a cycle or is terminated by a trivially dead instruction, 00073 /// delete it. If that makes any of its operands trivially dead, delete them 00074 /// too, recursively. 00075 void RecursivelyDeleteDeadPHINode(PHINode *PN); 00076 00077 //===----------------------------------------------------------------------===// 00078 // Control Flow Graph Restructuring. 00079 // 00080 00081 /// MergeBasicBlockIntoOnlyPred - BB is a block with one predecessor and its 00082 /// predecessor is known to have one successor (BB!). Eliminate the edge 00083 /// between them, moving the instructions in the predecessor into BB. This 00084 /// deletes the predecessor block. 00085 /// 00086 void MergeBasicBlockIntoOnlyPred(BasicBlock *BB); 00087 00088 00089 /// SimplifyCFG - This function is used to do simplification of a CFG. For 00090 /// example, it adjusts branches to branches to eliminate the extra hop, it 00091 /// eliminates unreachable basic blocks, and does other "peephole" optimization 00092 /// of the CFG. It returns true if a modification was made, possibly deleting 00093 /// the basic block that was pointed to. 00094 /// 00095 /// WARNING: The entry node of a method may not be simplified. 00096 /// 00097 bool SimplifyCFG(BasicBlock *BB); 00098 00099 /// FoldBranchToCommonDest - If this basic block is ONLY a setcc and a branch, 00100 /// and if a predecessor branches to us and one of our successors, fold the 00101 /// setcc into the predecessor and use logical operations to pick the right 00102 /// destination. 00103 bool FoldBranchToCommonDest(BranchInst *BI); 00104 00105 /// DemoteRegToStack - This function takes a virtual register computed by an 00106 /// Instruction and replaces it with a slot in the stack frame, allocated via 00107 /// alloca. This allows the CFG to be changed around without fear of 00108 /// invalidating the SSA information for the value. It returns the pointer to 00109 /// the alloca inserted to create a stack slot for X. 00110 /// 00111 AllocaInst *DemoteRegToStack(Instruction &X, 00112 bool VolatileLoads = false, 00113 Instruction *AllocaPoint = 0); 00114 00115 /// DemotePHIToStack - This function takes a virtual register computed by a phi 00116 /// node and replaces it with a slot in the stack frame, allocated via alloca. 00117 /// The phi node is deleted and it returns the pointer to the alloca inserted. 00118 AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = 0); 00119 00120 /// OnlyUsedByDbgIntrinsics - Return true if the instruction I is only used 00121 /// by DbgIntrinsics. If DbgInUses is specified then the vector is filled 00122 /// with DbgInfoIntrinsic that use the instruction I. 00123 bool OnlyUsedByDbgInfoIntrinsics(Instruction *I, 00124 SmallVectorImpl<DbgInfoIntrinsic *> *DbgInUses = 0); 00125 00126 } // End llvm namespace 00127 00128 #endif