LLVM API Documentation
#include <BasicBlock.h>
This represents a single basic block in LLVM. A basic block is simply a container of instructions that execute sequentially. Basic blocks are Values because they are referenced by instructions such as branches and switch tables. The type of a BasicBlock is "Type::LabelTy" because the basic block represents a label to which a branch can jump.
A well formed basic block is formed of a list of non-terminating instructions followed by a single TerminatorInst instruction. TerminatorInst's may not occur in the middle of basic blocks, and must terminate the blocks. The BasicBlock class allows malformed basic blocks to occur because it may be useful in the intermediate stage of constructing or modifying a program. However, the verifier will ensure that basic blocks are "well formed".
Definition at line 67 of file BasicBlock.h.
Definition at line 71 of file BasicBlock.h.
| typedef InstListType::iterator llvm::BasicBlock::iterator |
| typedef InstListType::const_iterator llvm::BasicBlock::const_iterator |
Definition at line 94 of file BasicBlock.h.
| BasicBlock::~BasicBlock | ( | ) |
| LLVMContext & BasicBlock::getContext | ( | ) | const |
getContext - Get the context in which this basic block lives.
Reimplemented from llvm::Value.
Definition at line 32 of file BasicBlock.cpp.
References llvm::Type::getContext(), and llvm::Value::getType().
Referenced by AddReachableCodeToWorklist(), llvm::CloneBasicBlock(), EvaluateExpression(), FoldCondBranchOnPHI(), FoldValueComparisonIntoPredecessors(), HoistThenElseCodeToIf(), llvm::RSProfilers_std::IncrementCounterInBlock(), llvm::IncrementCounterInBlock(), OptimizeCmpExpression(), llvm::MSILWriter::printBasicBlock(), llvm::RemapInstruction(), llvm::SimplifyCFG(), splitBasicBlock(), and llvm::SplitBlockPredecessors().
| static BasicBlock* llvm::BasicBlock::Create | ( | LLVMContext & | Context, | |
| const Twine & | Name = "", |
|||
| Function * | Parent = 0, |
|||
| BasicBlock * | InsertBefore = 0 | |||
| ) | [inline, static] |
Create - Creates a new BasicBlock. If the Parent parameter is specified, the basic block is automatically inserted at either the end of the function (if InsertBefore is 0), or before the specified basic block.
Definition at line 99 of file BasicBlock.h.
References llvm::ISD::BasicBlock, and Name.
Referenced by llvm::CloneBasicBlock(), PerformHeapAllocSRoA(), llvm::JIT::runFunction(), llvm::UnifyFunctionExitNodes::runOnFunction(), SimplifyCondBranchToCondBranch(), splitBasicBlock(), llvm::SplitBlockPredecessors(), llvm::SplitCriticalEdge(), and ThunkGToF().
| const Function* llvm::BasicBlock::getParent | ( | ) | const [inline] |
getParent - Return the enclosing method, or null if none
Definition at line 107 of file BasicBlock.h.
Referenced by CheckForEscapingAllocas(), llvm::CloneBasicBlock(), llvm::CloneLoop(), llvm::ConstantFoldTerminator(), llvm::IRBuilder< true, llvm::TargetFolder >::CreateAggregateRet(), llvm::IRBuilder< true, llvm::TargetFolder >::CreateGlobalString(), llvm::DemotePHIToStack(), llvm::DemoteRegToStack(), eraseFromParent(), FoldCondBranchOnPHI(), FoldValueComparisonIntoPredecessors(), llvm::CallSite::getCaller(), getCommonReturnValue(), llvm::MemoryDependenceAnalysis::getDependency(), llvm::ProfileInfo::getExecutionCount(), llvm::Trace::getFunction(), llvm::InlineCostAnalyzer::getInlineCost(), llvm::MemoryDependenceAnalysis::getNonLocalCallDependency(), getValueSymbolTable(), HandleInlinedInvoke(), llvm::InlineFunction(), llvm::BasicInlinerImpl::inlineFunctions(), isDynamicConstant(), llvm::SelectionDAGLowering::isExportableFromCurrentBlock(), isInTailCallPosition(), llvm::AllocaInst::isStaticAlloca(), LLVMGetNextBasicBlock(), LLVMGetPreviousBasicBlock(), LLVMInsertBasicBlockInContext(), LowerToBSwap(), moveAfter(), moveBefore(), PerformHeapAllocSRoA(), llvm::Value::print(), removeFromParent(), llvm::RemoveSuccessor(), ReplaceCallWith(), llvm::SimplifyCFG(), SimplifyCondBranchToCondBranch(), splitBasicBlock(), llvm::DominanceFrontier::splitBlock(), llvm::SplitBlockPredecessors(), llvm::SplitCriticalEdge(), SplitEdgeNicely(), TryToSinkInstruction(), UpdateCallGraphAfterInlining(), and ~BasicBlock().
| Function* llvm::BasicBlock::getParent | ( | ) | [inline] |
Definition at line 108 of file BasicBlock.h.
| Instruction* llvm::BasicBlock::use_back | ( | ) | [inline] |
use_back - Specialize the methods defined in Value, as we know that an BasicBlock can only be used by Instructions (specifically PHI nodes and terminators).
Reimplemented from llvm::Value.
Definition at line 113 of file BasicBlock.h.
References llvm::Value::use_begin().
| const Instruction* llvm::BasicBlock::use_back | ( | ) | const [inline] |
Reimplemented from llvm::Value.
Definition at line 114 of file BasicBlock.h.
References llvm::Value::use_begin().
| TerminatorInst * BasicBlock::getTerminator | ( | ) |
getTerminator() - If this is a well formed basic block, then this returns a pointer to the terminator instruction. If it is not, then you get a null pointer back.
Definition at line 101 of file BasicBlock.cpp.
References llvm::dyn_cast().
Referenced by AddReachableCodeToWorklist(), ApproximateLoopSize(), BlockIsSimpleEnoughToThreadThrough(), llvm::CloneBasicBlock(), llvm::CloneFunctionInto(), llvm::ConstantFoldTerminator(), llvm::DeleteDeadBlock(), llvm::DemotePHIToStack(), DominatesMergePoint(), llvm::findBBStopPoint(), llvm::findStopPoint(), FoldBlockIntoPredecessor(), llvm::FoldBranchToCommonDest(), FoldCondBranchOnPHI(), FoldTwoEntryPHINode(), FoldValueComparisonIntoPredecessors(), llvm::DOTGraphTraits< const Function * >::getEdgeSourceLabel(), GetIfCondition(), llvm::InlineFunction(), InsertAffinePhi(), llvm::SparseSolver::isEdgeFeasible(), isInTailCallPosition(), llvm::ScalarEvolution::isLoopBackedgeGuardedByCond(), llvm::Loop::makeLoopInvariant(), MarkAliveBlocks(), llvm::MergeBasicBlockIntoOnlyPred(), llvm::MergeBlockIntoPredecessor(), PerformHeapAllocSRoA(), recBackEdge(), llvm::UnifyFunctionExitNodes::runOnFunction(), llvm::SimplifyCFG(), SimplifyCondBranchToTwoReturns(), SimplifyEqualityComparisonWithOnlyPredecessor(), SpeculativelyExecuteBB(), splitBasicBlock(), llvm::DominanceFrontier::splitBlock(), llvm::SplitCriticalEdge(), llvm::SplitEdge(), SplitEdgeNicely(), llvm::succ_begin(), llvm::succ_end(), and llvm::UnrollLoop().
| const TerminatorInst * BasicBlock::getTerminator | ( | ) | const |
| Instruction * BasicBlock::getFirstNonPHI | ( | ) |
Returns a pointer to the first instructon in this block that is not a PHINode instruction. When adding instruction to the beginning of the basic block, they should be added before the returned value, not before the first instruction, which might be PHI. Returns 0 is there's no non-PHI instruction.
Definition at line 111 of file BasicBlock.cpp.
References begin().
Referenced by getFirstNonPHI(), getJumpThreadDuplicationCost(), llvm::RSProfilers_std::IncrementCounterInBlock(), llvm::IncrementCounterInBlock(), OptimizeCmpExpression(), OptimizeNoopCopyExpression(), llvm::SimplifyCFG(), and TryToSinkInstruction().
| const Instruction* llvm::BasicBlock::getFirstNonPHI | ( | ) | const [inline] |
| void BasicBlock::removeFromParent | ( | ) |
removeFromParent - This method unlinks 'this' from the containing function, but does not delete it.
Definition at line 77 of file BasicBlock.cpp.
References llvm::Function::getBasicBlockList(), and getParent().
| void BasicBlock::eraseFromParent | ( | ) |
eraseFromParent - This method unlinks 'this' from the containing function and deletes it.
Definition at line 81 of file BasicBlock.cpp.
References llvm::Function::getBasicBlockList(), and getParent().
Referenced by llvm::CloneAndPruneFunctionInto(), llvm::DeleteDeadBlock(), FoldBlockIntoPredecessor(), llvm::InlineFunction(), llvm::MergeBasicBlockIntoOnlyPred(), and llvm::MergeBlockIntoPredecessor().
| void BasicBlock::moveBefore | ( | BasicBlock * | MovePos | ) |
moveBefore - Unlink this basic block from its current function and insert it into the function that MovePos lives in, right before MovePos.
moveBefore - Unlink this basic block from its current function and insert it into the function that MovePos lives in, right before MovePos.
Definition at line 87 of file BasicBlock.cpp.
References llvm::Function::getBasicBlockList(), and getParent().
| void BasicBlock::moveAfter | ( | BasicBlock * | MovePos | ) |
moveAfter - Unlink this basic block from its current function and insert it into the function that MovePos lives in, right after MovePos.
moveAfter - Unlink this basic block from its current function and insert it into the function that MovePos lives in, right after MovePos.
Definition at line 94 of file BasicBlock.cpp.
References llvm::Function::getBasicBlockList(), and getParent().
| BasicBlock * BasicBlock::getSinglePredecessor | ( | ) |
getSinglePredecessor - If this basic block has a single predecessor block, return the block, otherwise return a null pointer.
getSinglePredecessor - If this basic block has a single predecessor block, return the block, otherwise return a null pointer.
Definition at line 128 of file BasicBlock.cpp.
References E, PI, llvm::pred_begin(), and llvm::pred_end().
Referenced by CanPropagatePredecessorsForPHIs(), llvm::CloneAndPruneFunctionInto(), llvm::DeleteDeadBlock(), llvm::DemoteRegToStack(), FoldBlockIntoPredecessor(), getSinglePredecessor(), llvm::MergeBasicBlockIntoOnlyPred(), llvm::SimplifyCFG(), llvm::SplitEdge(), and TryToSimplifyUncondBranchFromEmptyBlock().
| const BasicBlock* llvm::BasicBlock::getSinglePredecessor | ( | ) | const [inline] |
| BasicBlock * BasicBlock::getUniquePredecessor | ( | ) |
getUniquePredecessor - If this basic block has a unique predecessor block, return the block, otherwise return a null pointer. Note that unique predecessor doesn't mean single edge, there can be multiple edges from the unique predecessor to this block (for example a switch statement with multiple cases having the same destination).
getUniquePredecessor - If this basic block has a unique predecessor block, return the block, otherwise return a null pointer. Note that unique predecessor doesn't mean single edge, there can be multiple edges from the unique predecessor to this block (for example a switch statement with multiple cases having the same destination).
Definition at line 141 of file BasicBlock.cpp.
References E, PI, llvm::pred_begin(), and llvm::pred_end().
Referenced by llvm::findBBStopPoint(), and getUniquePredecessor().
| const BasicBlock* llvm::BasicBlock::getUniquePredecessor | ( | ) | const [inline] |
| iterator llvm::BasicBlock::begin | ( | ) | [inline] |
Instruction iterator methods
Definition at line 172 of file BasicBlock.h.
Referenced by llvm::AliasSetTracker::add(), AddPredecessorToBlock(), AddReachableCodeToWorklist(), ApproximateLoopSize(), BlockIsSimpleEnoughToThreadThrough(), llvm::Interpreter::callFunction(), CanPropagatePredecessorsForPHIs(), CheckForEscapingAllocas(), llvm::CloneAndPruneFunctionInto(), llvm::CloneBasicBlock(), llvm::CloneLoop(), llvm::CloneTrace(), CollapsePhi(), copyCatchInfo(), llvm::CopyPrecedingStopPoint(), llvm::DeleteDeadPHIs(), llvm::DemotePHIToStack(), llvm::DemoteRegToStack(), llvm::DominatorTree::dominates(), DominatesMergePoint(), dropAllReferences(), equals(), EvaluateFunction(), llvm::FindAvailableLoadedValue(), llvm::findBBStopPoint(), llvm::findStopPoint(), FoldCondBranchOnPHI(), llvm::FoldSingleEntryPHINodes(), FoldTwoEntryPHINode(), llvm::Loop::getCanonicalInductionVariable(), llvm::MemoryDependenceAnalysis::getDependency(), getFirstNonPHI(), llvm::MemoryDependenceAnalysis::getNonLocalCallDependency(), llvm::MemoryDependenceAnalysis::getNonLocalPointerDependency(), HandleInlinedInvoke(), HoistThenElseCodeToIf(), llvm::InlineFunction(), llvm::InsertProfilingInitCall(), llvm::Loop::isLCSSAForm(), llvm::isSafeToLoadUnconditionally(), isTerminatorFirstRelevantInsn(), isTrivialLoopExitBlockHelper(), LLVMGetFirstInstruction(), LLVMGetLastInstruction(), LLVMGetPreviousInstruction(), MarkAliveBlocks(), llvm::MergeBasicBlockIntoOnlyPred(), llvm::MergeBlockIntoPredecessor(), llvm::SparseSolver::Print(), llvm::MSILWriter::printBasicBlock(), llvm::MSILWriter::printBranchToBlock(), llvm::MSILWriter::printPHICopy(), PushLoopPHIs(), removePredecessor(), ReplacePhiPred(), llvm::SimplifyCFG(), SimplifyCondBranchToCondBranch(), llvm::SparseSolver::Solve(), SpeculativelyExecuteBB(), splitBasicBlock(), llvm::SplitBlockPredecessors(), llvm::SplitCriticalEdge(), llvm::SplitEdge(), SplitEdgeNicely(), and TryToSimplifyUncondBranchFromEmptyBlock().
| const_iterator llvm::BasicBlock::begin | ( | ) | const [inline] |
Definition at line 173 of file BasicBlock.h.
| iterator llvm::BasicBlock::end | ( | ) | [inline] |
Definition at line 174 of file BasicBlock.h.
Referenced by llvm::AliasSetTracker::add(), AddReachableCodeToWorklist(), ApproximateLoopSize(), ChangeToUnreachable(), CheckForEscapingAllocas(), llvm::CloneAndPruneFunctionInto(), llvm::CloneBasicBlock(), llvm::CloneLoop(), CollapsePhi(), copyCatchInfo(), dropAllReferences(), equals(), llvm::findBBStopPoint(), llvm::MemoryDependenceAnalysis::getNonLocalCallDependency(), llvm::InlineFunction(), isInTailCallPosition(), llvm::Loop::isLCSSAForm(), isSafeAndProfitableToSinkLoad(), isTrivialLoopExitBlockHelper(), LLVMGetFirstInstruction(), LLVMGetLastInstruction(), LLVMGetNextInstruction(), LLVMPositionBuilder(), MarkAliveBlocks(), llvm::MergeBlockIntoPredecessor(), llvm::SparseSolver::Print(), llvm::MSILWriter::printBasicBlock(), llvm::MSILWriter::printPHICopy(), ReplacePhiPred(), llvm::IRBuilder< true, llvm::TargetFolder >::SetInsertPoint(), llvm::SparseSolver::Solve(), SpeculativelyExecuteBB(), splitBasicBlock(), and TryToSinkInstruction().
| const_iterator llvm::BasicBlock::end | ( | ) | const [inline] |
Definition at line 175 of file BasicBlock.h.
| size_t llvm::BasicBlock::size | ( | ) | const [inline] |
Definition at line 177 of file BasicBlock.h.
Referenced by FoldValueComparisonIntoPredecessors(), and llvm::SimplifyCFG().
| bool llvm::BasicBlock::empty | ( | ) | const [inline] |
| const Instruction& llvm::BasicBlock::front | ( | ) | const [inline] |
Definition at line 179 of file BasicBlock.h.
Referenced by llvm::AliasAnalysis::canBasicBlockModify(), llvm::FoldBranchToCommonDest(), llvm::MergeBlockIntoPredecessor(), removePredecessor(), llvm::UnifyFunctionExitNodes::runOnFunction(), and llvm::SimplifyCFG().
| Instruction& llvm::BasicBlock::front | ( | ) | [inline] |
Definition at line 180 of file BasicBlock.h.
| const Instruction& llvm::BasicBlock::back | ( | ) | const [inline] |
Definition at line 181 of file BasicBlock.h.
Referenced by llvm::AliasAnalysis::canBasicBlockModify(), llvm::CloneAndPruneFunctionInto(), llvm::DeleteDeadBlock(), and llvm::LiveVariables::MarkVirtRegAliveInBlock().
| Instruction& llvm::BasicBlock::back | ( | ) | [inline] |
Definition at line 182 of file BasicBlock.h.
| const InstListType& llvm::BasicBlock::getInstList | ( | ) | const [inline] |
getInstList() - Return the underlying instruction list container. You need to access it directly if you want to modify it currently.
Definition at line 187 of file BasicBlock.h.
Referenced by ChangeToCall(), ChangeToUnreachable(), llvm::CloneAndPruneFunctionInto(), llvm::CloneBasicBlock(), llvm::CloneTrace(), llvm::ConstantFoldTerminator(), llvm::BinaryOperator::Create(), llvm::DeleteDeadBlock(), llvm::Instruction::eraseFromParent(), FoldBlockIntoPredecessor(), llvm::FoldBranchToCommonDest(), FoldCondBranchOnPHI(), FoldTwoEntryPHINode(), HandleInlinedInvoke(), HoistThenElseCodeToIf(), llvm::InlineFunction(), llvm::Instruction::insertAfter(), llvm::Instruction::insertBefore(), llvm::IRBuilder< true, llvm::TargetFolder >::InsertHelper(), llvm::Instruction::Instruction(), llvm::MergeBasicBlockIntoOnlyPred(), llvm::MergeBlockIntoPredecessor(), llvm::Instruction::moveBefore(), llvm::Instruction::removeFromParent(), removePredecessor(), llvm::ReplaceInstWithInst(), llvm::UnifyFunctionExitNodes::runOnFunction(), llvm::SimplifyCFG(), SpeculativelyExecuteBB(), splitBasicBlock(), TryToSimplifyUncondBranchFromEmptyBlock(), and llvm::UnrollLoop().
| InstListType& llvm::BasicBlock::getInstList | ( | ) | [inline] |
Definition at line 188 of file BasicBlock.h.
| static iplist<Instruction> BasicBlock::* llvm::BasicBlock::getSublistAccess | ( | Instruction * | ) | [inline, static] |
getSublistAccess() - returns pointer to member of instruction list
Definition at line 191 of file BasicBlock.h.
| ValueSymbolTable * BasicBlock::getValueSymbolTable | ( | ) |
getValueSymbolTable() - returns pointer to symbol table (if any)
Definition at line 26 of file BasicBlock.cpp.
References F, and getParent().
| static bool llvm::BasicBlock::classof | ( | const BasicBlock * | ) | [inline, static] |
Methods for support type inquiry through isa, cast, and dyn_cast:.
Definition at line 199 of file BasicBlock.h.
Reimplemented from llvm::Value.
Definition at line 200 of file BasicBlock.h.
References llvm::Value::BasicBlockVal, and llvm::Value::getValueID().
| void BasicBlock::dropAllReferences | ( | ) |
dropAllReferences() - This function causes all the subinstructions to "let go" of all references that they are maintaining. This allows one to 'delete' a whole class at a time, even though there may be circular references... first all references are dropped, and all use counts go to zero. Then everything is delete'd for real. Note that no operations are valid on an object that has "dropped all references", except operator delete.
Definition at line 121 of file BasicBlock.cpp.
References begin(), E, and end().
Referenced by ~BasicBlock().
| void BasicBlock::removePredecessor | ( | BasicBlock * | Pred, | |
| bool | DontDeleteUselessPHIs = false | |||
| ) |
removePredecessor - This method is used to notify a BasicBlock that the specified Predecessor of the block is no longer able to reach it. This is actually not used to update the Predecessor list, but is actually used to update the PHI nodes that reside in the block. Note that this should be called while the predecessor still refers to this block.
removePredecessor - This method is used to notify a BasicBlock that the specified Predecessor of the block is no longer able to reach it. This is actually not used to update the Predecessor list, but is actually used to update the PHI nodes that reside in the block. Note that this should be called while the predecessor still refers to this block.
Definition at line 161 of file BasicBlock.cpp.
References begin(), llvm::dyn_cast(), llvm::Instruction::eraseFromParent(), front(), llvm::UndefValue::get(), llvm::PHINode::getIncomingBlock(), getInstList(), llvm::PHINode::getNumIncomingValues(), llvm::PHINode::hasConstantValue(), llvm::Value::hasNUsesOrMore(), II, llvm::pred_begin(), llvm::pred_end(), llvm::PHINode::removeIncomingValue(), and llvm::Value::replaceAllUsesWith().
Referenced by ChangeToCall(), ChangeToUnreachable(), llvm::ConstantFoldTerminator(), llvm::DeleteDeadBlock(), FoldCondBranchOnPHI(), FoldValueComparisonIntoPredecessors(), HandleInlinedInvoke(), llvm::RemoveSuccessor(), llvm::SimplifyCFG(), SimplifyCondBranchToTwoReturns(), SimplifyEqualityComparisonWithOnlyPredecessor(), llvm::SplitCriticalEdge(), and SplitEdgeNicely().
| BasicBlock * BasicBlock::splitBasicBlock | ( | iterator | I, | |
| const Twine & | BBName = "" | |||
| ) |
splitBasicBlock - This splits a basic block into two at the specified instruction. Note that all instructions BEFORE the specified iterator stay as part of the original basic block, an unconditional branch is added to the original BB, and the rest of the instructions in the BB are moved to the new BB, including the old terminator. The newly formed BasicBlock is returned. This function invalidates the specified iterator.
Note that this only works on well formed basic blocks (must have a terminator), and 'I' must not be the end of instruction list (which would cause a degenerate basic block to be formed, having a terminator inside of the basic block).
splitBasicBlock - This splits a basic block into two at the specified instruction. Note that all instructions BEFORE the specified iterator stay as part of the original basic block, an unconditional branch is added to the new BB, and the rest of the instructions in the BB are moved to the new BB, including the old terminator. This invalidates the iterator.
Note that this only works on well formed basic blocks (must have a terminator), and 'I' must not be the end of instruction list (which would cause a degenerate basic block to be formed, having a terminator inside of the basic block).
Definition at line 242 of file BasicBlock.cpp.
References begin(), Create(), llvm::BranchInst::Create(), llvm::dyn_cast(), E, end(), llvm::PHINode::getBasicBlockIndex(), getContext(), getInstList(), getParent(), getTerminator(), II, llvm::next(), llvm::PHINode::setIncomingBlock(), llvm::succ_begin(), and llvm::succ_end().
Referenced by llvm::InlineFunction(), PerformHeapAllocSRoA(), and llvm::SplitBlock().
friend class SymbolTableListTraits< BasicBlock, Function > [friend] |
Definition at line 77 of file BasicBlock.h.