LLVM API Documentation

BasicBlockUtils.h

Go to the documentation of this file.
00001 //===-- Transform/Utils/BasicBlockUtils.h - BasicBlock Utils ----*- 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 manipulations on basic blocks, and
00011 // instructions contained within basic blocks.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_TRANSFORMS_UTILS_BASICBLOCK_H
00016 #define LLVM_TRANSFORMS_UTILS_BASICBLOCK_H
00017 
00018 // FIXME: Move to this file: BasicBlock::removePredecessor, BB::splitBasicBlock
00019 
00020 #include "llvm/BasicBlock.h"
00021 #include "llvm/Support/CFG.h"
00022 
00023 namespace llvm {
00024 
00025 class Instruction;
00026 class Pass;
00027 
00028 // ReplaceInstWithValue - Replace all uses of an instruction (specified by BI)
00029 // with a value, then remove and delete the original instruction.
00030 //
00031 void ReplaceInstWithValue(BasicBlock::InstListType &BIL,
00032                           BasicBlock::iterator &BI, Value *V);
00033 
00034 // ReplaceInstWithInst - Replace the instruction specified by BI with the
00035 // instruction specified by I.  The original instruction is deleted and BI is
00036 // updated to point to the new instruction.
00037 //
00038 void ReplaceInstWithInst(BasicBlock::InstListType &BIL,
00039                          BasicBlock::iterator &BI, Instruction *I);
00040 
00041 // ReplaceInstWithInst - Replace the instruction specified by From with the
00042 // instruction specified by To.
00043 //
00044 void ReplaceInstWithInst(Instruction *From, Instruction *To);
00045 
00046 
00047 // RemoveSuccessor - Change the specified terminator instruction such that its
00048 // successor #SuccNum no longer exists.  Because this reduces the outgoing
00049 // degree of the current basic block, the actual terminator instruction itself
00050 // may have to be changed.  In the case where the last successor of the block is
00051 // deleted, a return instruction is inserted in its place which can cause a
00052 // suprising change in program behavior if it is not expected.
00053 //
00054 void RemoveSuccessor(TerminatorInst *TI, unsigned SuccNum);
00055 
00056 /// isCriticalEdge - Return true if the specified edge is a critical edge.
00057 /// Critical edges are edges from a block with multiple successors to a block
00058 /// with multiple predecessors.
00059 ///
00060 bool isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum);
00061 
00062 /// SplitCriticalEdge - If this edge is a critical edge, insert a new node to
00063 /// split the critical edge.  This will update DominatorSet, ImmediateDominator,
00064 /// DominatorTree, and DominatorFrontier information if it is available, thus
00065 /// calling this pass will not invalidate either of them.  This returns true if
00066 /// the edge was split, false otherwise.
00067 ///
00068 bool SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P = 0);
00069 
00070 inline bool SplitCriticalEdge(BasicBlock *BB, succ_iterator SI, Pass *P = 0) {
00071   return SplitCriticalEdge(BB->getTerminator(), SI.getSuccessorIndex(), P);
00072 }
00073 
00074 /// SplitCriticalEdge - If the edge from *PI to BB is not critical, return
00075 /// false.  Otherwise, split all edges between the two blocks and return true.
00076 /// This updates all of the same analyses as the other SplitCriticalEdge
00077 /// function.  If P is specified, it updates the analyses
00078 /// described above.
00079 inline bool SplitCriticalEdge(BasicBlock *Succ, pred_iterator PI, Pass *P = 0) {
00080   bool MadeChange = false;
00081   TerminatorInst *TI = (*PI)->getTerminator();
00082   for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
00083     if (TI->getSuccessor(i) == Succ)
00084       MadeChange |= SplitCriticalEdge(TI, i, P);
00085   return MadeChange;
00086 }
00087 
00088 /// SplitCriticalEdge - If an edge from Src to Dst is critical, split the edge
00089 /// and return true, otherwise return false.  This method requires that there be
00090 /// an edge between the two blocks.  If P is specified, it updates the analyses
00091 /// described above.
00092 inline bool SplitCriticalEdge(BasicBlock *Src, BasicBlock *Dst, Pass *P = 0) {
00093   TerminatorInst *TI = Src->getTerminator();
00094   unsigned i = 0;
00095   while (1) {
00096     assert(i != TI->getNumSuccessors() && "Edge doesn't exist!");
00097     if (TI->getSuccessor(i) == Dst)
00098       return SplitCriticalEdge(TI, i, P);
00099     ++i;
00100   }
00101 }
00102 } // End llvm namespace
00103 
00104 #endif