|
LLVM
5.0.0
|
Utility class for extracting code into a new function. More...
#include "llvm/Transforms/Utils/CodeExtractor.h"
Public Member Functions | |
| CodeExtractor (ArrayRef< BasicBlock * > BBs, DominatorTree *DT=nullptr, bool AggregateArgs=false, BlockFrequencyInfo *BFI=nullptr, BranchProbabilityInfo *BPI=nullptr) | |
| Create a code extractor for a sequence of blocks. More... | |
| CodeExtractor (DominatorTree &DT, Loop &L, bool AggregateArgs=false, BlockFrequencyInfo *BFI=nullptr, BranchProbabilityInfo *BPI=nullptr) | |
| Create a code extractor for a loop body. More... | |
| Function * | extractCodeRegion () |
| Perform the extraction, returning the new function. More... | |
| bool | isEligible () const |
| Test whether this code extractor is eligible. More... | |
| void | findInputsOutputs (ValueSet &Inputs, ValueSet &Outputs, const ValueSet &Allocas) const |
| Compute the set of input values and output values for the code. More... | |
| bool | isLegalToShrinkwrapLifetimeMarkers (Instruction *AllocaAddr) const |
| Check if life time marker nodes can be hoisted/sunk into the outline region. More... | |
| void | findAllocas (ValueSet &SinkCands, ValueSet &HoistCands, BasicBlock *&ExitBlock) const |
| Find the set of allocas whose life ranges are contained within the outlined region. More... | |
| BasicBlock * | findOrCreateBlockForHoisting (BasicBlock *CommonExitBlock) |
| Find or create a block within the outline region for placing hoisted code. More... | |
Static Public Member Functions | |
| static bool | isBlockValidForExtraction (const BasicBlock &BB) |
| Check to see if a block is valid for extraction. More... | |
Utility class for extracting code into a new function.
This utility provides a simple interface for extracting some sequence of code into its own function, replacing it with a call to that function. It also provides various methods to query about the nature and result of such a transformation.
The rough algorithm used is: 1) Find both the inputs and outputs for the extracted region. 2) Pass the inputs as arguments, remapping them within the extracted function to arguments. 3) Add allocas for any scalar outputs, adding all of the outputs' allocas as arguments, and inserting stores to the arguments for any scalars.
Definition at line 48 of file CodeExtractor.h.
| CodeExtractor::CodeExtractor | ( | ArrayRef< BasicBlock * > | BBs, |
| DominatorTree * | DT = nullptr, |
||
| bool | AggregateArgs = false, |
||
| BlockFrequencyInfo * | BFI = nullptr, |
||
| BranchProbabilityInfo * | BPI = nullptr |
||
| ) |
Create a code extractor for a sequence of blocks.
Given a sequence of basic blocks where the first block in the sequence dominates the rest, prepare a code extractor object for pulling this sequence out into its new function. When a DominatorTree is also given, extra checking and transformations are enabled.
Definition at line 139 of file CodeExtractor.cpp.
| CodeExtractor::CodeExtractor | ( | DominatorTree & | DT, |
| Loop & | L, | ||
| bool | AggregateArgs = false, |
||
| BlockFrequencyInfo * | BFI = nullptr, |
||
| BranchProbabilityInfo * | BPI = nullptr |
||
| ) |
Create a code extractor for a loop body.
Behaves just like the generic code sequence constructor, but uses the block sequence of the loop.
Definition at line 145 of file CodeExtractor.cpp.
| Function * CodeExtractor::extractCodeRegion | ( | ) |
Perform the extraction, returning the new function.
Returns zero when called on a CodeExtractor instance where isEligible returns false.
Definition at line 984 of file CodeExtractor.cpp.
References assert(), llvm::sys::path::begin(), llvm::BasicBlock::begin(), llvm::BasicBlock::Create(), llvm::BranchInst::Create(), DEBUG, llvm::SetVector< T, Vector, Set >::empty(), findAllocas(), findInputsOutputs(), findOrCreateBlockForHoisting(), llvm::BlockFrequencyInfo::getBlockFreq(), llvm::BasicBlock::getContext(), llvm::BranchProbabilityInfo::getEdgeProbability(), llvm::BlockFrequency::getFrequency(), llvm::PHINode::getIncomingBlock(), llvm::BasicBlock::getInstList(), llvm::PHINode::getNumIncomingValues(), llvm::BasicBlock::getParent(), llvm::GlobalValue::getParent(), llvm::BlockFrequencyInfo::getProfileCountFromFreq(), llvm::Optional< T >::getValue(), llvm::Optional< T >::hasValue(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), isEligible(), llvm::predecessors(), llvm::iplist_impl< IntrusiveListT, TraitsT >::push_back(), llvm::PHINode::removeIncomingValue(), llvm::report_fatal_error(), second, llvm::BlockFrequencyInfo::setBlockFreq(), llvm::Function::setEntryCount(), llvm::PHINode::setIncomingBlock(), llvm::SmallPtrSetImplBase::size(), llvm::succ_begin(), llvm::succ_end(), and llvm::verifyFunction().
| void CodeExtractor::findAllocas | ( | ValueSet & | SinkCands, |
| ValueSet & | HoistCands, | ||
| BasicBlock *& | ExitBlock | ||
| ) | const |
Find the set of allocas whose life ranges are contained within the outlined region.
Allocas which have life_time markers contained in the outlined region should be pushed to the outlined function. The address bitcasts that are used by the lifetime markers are also candidates for shrink- wrapping. The instructions that need to be sunk are collected in 'Allocas'.
Definition at line 300 of file CodeExtractor.cpp.
References llvm::MCID::Bitcast, definedInRegion(), llvm::dyn_cast(), getCommonExitBlock(), llvm::IntrinsicInst::getIntrinsicID(), getParent(), llvm::SetVector< T, Vector, Set >::insert(), isLegalToShrinkwrapLifetimeMarkers(), and llvm::Value::users().
Referenced by extractCodeRegion().
| void CodeExtractor::findInputsOutputs | ( | ValueSet & | Inputs, |
| ValueSet & | Outputs, | ||
| const ValueSet & | Allocas | ||
| ) | const |
Compute the set of input values and output values for the code.
These can be used either when performing the extraction or to evaluate the expected size of a call to the extracted function. Note that this work cannot be cached between the two as once we decide to extract a code sequence, that sequence is modified, including changing these sets, before extraction occurs. These modifications won't have any significant impact on the cost however.
Definition at line 408 of file CodeExtractor.cpp.
References llvm::SetVector< T, Vector, Set >::count(), definedInCaller(), definedInRegion(), llvm::SetVector< T, Vector, Set >::insert(), and llvm::Value::users().
Referenced by extractCodeRegion().
| BasicBlock * CodeExtractor::findOrCreateBlockForHoisting | ( | BasicBlock * | CommonExitBlock | ) |
Find or create a block within the outline region for placing hoisted code.
CommonExitBlock is block outside the outline region. It is the common successor of blocks inside the region. If there exists a single block inside the region that is the predecessor of CommonExitBlock, that block will be returned. Otherwise CommonExitBlock will be split and the original block will be added to the outline region.
Definition at line 249 of file CodeExtractor.cpp.
References assert(), llvm::dyn_cast(), llvm::BasicBlock::getFirstNonPHI(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::BasicBlock::getTerminator(), I, llvm::predecessors(), llvm::User::replaceUsesOfWith(), and llvm::BasicBlock::splitBasicBlock().
Referenced by extractCodeRegion().
|
static |
Check to see if a block is valid for extraction.
Test whether a block is valid for extraction.
Blocks containing EHPads, allocas, invokes, or vastarts are not valid.
Definition at line 58 of file CodeExtractor.cpp.
References E, llvm::SmallVectorBase::empty(), F, getParent(), llvm::BasicBlock::hasAddressTaken(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::BasicBlock::isEHPad(), llvm::User::operands(), llvm::SmallVectorImpl< T >::pop_back_val(), and llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back().
Referenced by buildExtractionBlockSet().
|
inline |
Test whether this code extractor is eligible.
Based on the blocks used when constructing the code extractor, determine whether it is eligible for extraction.
Definition at line 97 of file CodeExtractor.h.
Referenced by extractCodeRegion().
| bool CodeExtractor::isLegalToShrinkwrapLifetimeMarkers | ( | Instruction * | AllocaAddr | ) | const |
Check if life time marker nodes can be hoisted/sunk into the outline region.
Returns true if it is safe to do the code motion.
Definition at line 197 of file CodeExtractor.cpp.
References llvm::dyn_cast(), llvm::IntrinsicInst::getIntrinsicID(), getParent(), llvm::LoadInst::getPointerOperand(), llvm::StoreInst::getPointerOperand(), llvm::SPII::Load, SI, llvm::SPII::Store, and llvm::Value::stripInBoundsConstantOffsets().
Referenced by findAllocas().
1.8.6