LLVM API Documentation
00001 //===-- Local.h - Functions to perform local transformations ----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source 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 #include "llvm/Function.h" 00019 00020 namespace llvm { 00021 00022 class Pass; 00023 class PHINode; 00024 class AllocaInst; 00025 00026 //===----------------------------------------------------------------------===// 00027 // Local constant propagation... 00028 // 00029 00030 /// doConstantPropagation - Constant prop a specific instruction. Returns true 00031 /// and potentially moves the iterator if constant propagation was performed. 00032 /// 00033 bool doConstantPropagation(BasicBlock::iterator &I); 00034 00035 /// ConstantFoldTerminator - If a terminator instruction is predicated on a 00036 /// constant value, convert it into an unconditional branch to the constant 00037 /// destination. This is a nontrivial operation because the successors of this 00038 /// basic block must have their PHI nodes updated. 00039 /// 00040 bool ConstantFoldTerminator(BasicBlock *BB); 00041 00042 /// ConstantFoldInstruction - Attempt to constant fold the specified 00043 /// instruction. If successful, the constant result is returned, if not, null 00044 /// is returned. Note that this function can only fail when attempting to fold 00045 /// instructions like loads and stores, which have no constant expression form. 00046 /// 00047 Constant *ConstantFoldInstruction(Instruction *I); 00048 00049 00050 /// canConstantFoldCallTo - Return true if its even possible to fold a call to 00051 /// the specified function. 00052 bool canConstantFoldCallTo(Function *F); 00053 00054 /// ConstantFoldCall - Attempt to constant fold a call to the specified function 00055 /// with the specified arguments, returning null if unsuccessful. 00056 Constant *ConstantFoldCall(Function *F, const std::vector<Constant*> &Operands); 00057 00058 00059 //===----------------------------------------------------------------------===// 00060 // Local dead code elimination... 00061 // 00062 00063 /// isInstructionTriviallyDead - Return true if the result produced by the 00064 /// instruction is not used, and the instruction has no side effects. 00065 /// 00066 bool isInstructionTriviallyDead(Instruction *I); 00067 00068 00069 /// dceInstruction - Inspect the instruction at *BBI and figure out if it 00070 /// isTriviallyDead. If so, remove the instruction and update the iterator to 00071 /// point to the instruction that immediately succeeded the original 00072 /// instruction. 00073 /// 00074 bool dceInstruction(BasicBlock::iterator &BBI); 00075 00076 //===----------------------------------------------------------------------===// 00077 // PHI Instruction Simplification 00078 // 00079 00080 /// hasConstantValue - If the specified PHI node always merges together the same 00081 /// value, return the value, otherwise return null. 00082 /// 00083 Value *hasConstantValue(PHINode *PN); 00084 00085 00086 //===----------------------------------------------------------------------===// 00087 // Control Flow Graph Restructuring... 00088 // 00089 00090 /// SimplifyCFG - This function is used to do simplification of a CFG. For 00091 /// example, it adjusts branches to branches to eliminate the extra hop, it 00092 /// eliminates unreachable basic blocks, and does other "peephole" optimization 00093 /// of the CFG. It returns true if a modification was made, possibly deleting 00094 /// the basic block that was pointed to. 00095 /// 00096 /// WARNING: The entry node of a method may not be simplified. 00097 /// 00098 bool SimplifyCFG(BasicBlock *BB); 00099 00100 /// DemoteRegToStack - This function takes a virtual register computed by an 00101 /// Instruction and replaces it with a slot in the stack frame, allocated via 00102 /// alloca. This allows the CFG to be changed around without fear of 00103 /// invalidating the SSA information for the value. It returns the pointer to 00104 /// the alloca inserted to create a stack slot for X. 00105 /// 00106 AllocaInst *DemoteRegToStack(Instruction &X); 00107 00108 } // End llvm namespace 00109 00110 #endif