LLVM API Documentation

Local.h

Go to the documentation of this file.
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 /// ConstantFoldInstOperands - Attempt to constant fold an instruction with the
00052 /// specified opcode and operands.  If successful, the constant result is
00053 /// returned, if not, null is returned.  Note that this function can fail when
00054 /// attempting to fold instructions like loads and stores, which have no
00055 /// constant expression form.
00056 ///
00057 Constant *ConstantFoldInstOperands(unsigned Opc, const Type *DestTy,
00058                                    const std::vector<Constant*> &Ops);
00059 
00060 
00061 /// ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a
00062 /// getelementptr constantexpr, return the constant value being addressed by the
00063 /// constant expression, or null if something is funny and we can't decide.
00064 Constant *ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE);
00065 
00066 //===----------------------------------------------------------------------===//
00067 //  Local dead code elimination...
00068 //
00069 
00070 /// isInstructionTriviallyDead - Return true if the result produced by the
00071 /// instruction is not used, and the instruction has no side effects.
00072 ///
00073 bool isInstructionTriviallyDead(Instruction *I);
00074 
00075 
00076 /// dceInstruction - Inspect the instruction at *BBI and figure out if it
00077 /// isTriviallyDead.  If so, remove the instruction and update the iterator to
00078 /// point to the instruction that immediately succeeded the original
00079 /// instruction.
00080 ///
00081 bool dceInstruction(BasicBlock::iterator &BBI);
00082 
00083 //===----------------------------------------------------------------------===//
00084 //  Control Flow Graph Restructuring...
00085 //
00086 
00087 /// SimplifyCFG - This function is used to do simplification of a CFG.  For
00088 /// example, it adjusts branches to branches to eliminate the extra hop, it
00089 /// eliminates unreachable basic blocks, and does other "peephole" optimization
00090 /// of the CFG.  It returns true if a modification was made, possibly deleting
00091 /// the basic block that was pointed to.
00092 ///
00093 /// WARNING:  The entry node of a method may not be simplified.
00094 ///
00095 bool SimplifyCFG(BasicBlock *BB);
00096 
00097 /// DemoteRegToStack - This function takes a virtual register computed by an
00098 /// Instruction and replaces it with a slot in the stack frame, allocated via
00099 /// alloca.  This allows the CFG to be changed around without fear of
00100 /// invalidating the SSA information for the value.  It returns the pointer to
00101 /// the alloca inserted to create a stack slot for X.
00102 ///
00103 AllocaInst *DemoteRegToStack(Instruction &X, bool VolatileLoads = false);
00104 
00105 } // End llvm namespace
00106 
00107 #endif