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 #include "llvm/Analysis/ConstantFolding.h" 00020 00021 namespace llvm { 00022 00023 class Pass; 00024 class PHINode; 00025 class AllocaInst; 00026 class ConstantExpr; 00027 00028 //===----------------------------------------------------------------------===// 00029 // Local constant propagation... 00030 // 00031 00032 /// doConstantPropagation - Constant prop a specific instruction. Returns true 00033 /// and potentially moves the iterator if constant propagation was performed. 00034 /// 00035 bool doConstantPropagation(BasicBlock::iterator &I); 00036 00037 /// ConstantFoldTerminator - If a terminator instruction is predicated on a 00038 /// constant value, convert it into an unconditional branch to the constant 00039 /// destination. This is a nontrivial operation because the successors of this 00040 /// basic block must have their PHI nodes updated. 00041 /// 00042 bool ConstantFoldTerminator(BasicBlock *BB); 00043 00044 /// ConstantFoldInstruction - Attempt to constant fold the specified 00045 /// instruction. If successful, the constant result is returned, if not, null 00046 /// is returned. Note that this function can only fail when attempting to fold 00047 /// instructions like loads and stores, which have no constant expression form. 00048 /// 00049 Constant *ConstantFoldInstruction(Instruction *I); 00050 00051 00052 /// ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a 00053 /// getelementptr constantexpr, return the constant value being addressed by the 00054 /// constant expression, or null if something is funny and we can't decide. 00055 Constant *ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE); 00056 00057 //===----------------------------------------------------------------------===// 00058 // Local dead code elimination... 00059 // 00060 00061 /// isInstructionTriviallyDead - Return true if the result produced by the 00062 /// instruction is not used, and the instruction has no side effects. 00063 /// 00064 bool isInstructionTriviallyDead(Instruction *I); 00065 00066 00067 /// dceInstruction - Inspect the instruction at *BBI and figure out if it 00068 /// isTriviallyDead. If so, remove the instruction and update the iterator to 00069 /// point to the instruction that immediately succeeded the original 00070 /// instruction. 00071 /// 00072 bool dceInstruction(BasicBlock::iterator &BBI); 00073 00074 //===----------------------------------------------------------------------===// 00075 // Control Flow Graph Restructuring... 00076 // 00077 00078 /// SimplifyCFG - This function is used to do simplification of a CFG. For 00079 /// example, it adjusts branches to branches to eliminate the extra hop, it 00080 /// eliminates unreachable basic blocks, and does other "peephole" optimization 00081 /// of the CFG. It returns true if a modification was made, possibly deleting 00082 /// the basic block that was pointed to. 00083 /// 00084 /// WARNING: The entry node of a method may not be simplified. 00085 /// 00086 bool SimplifyCFG(BasicBlock *BB); 00087 00088 /// DemoteRegToStack - This function takes a virtual register computed by an 00089 /// Instruction and replaces it with a slot in the stack frame, allocated via 00090 /// alloca. This allows the CFG to be changed around without fear of 00091 /// invalidating the SSA information for the value. It returns the pointer to 00092 /// the alloca inserted to create a stack slot for X. 00093 /// 00094 AllocaInst *DemoteRegToStack(Instruction &X, bool VolatileLoads = false); 00095 00096 } // End llvm namespace 00097 00098 #endif