|
LLVM
4.0.0
|
Utility class for extracting code into a new function. More...
#include <CodeExtractor.h>
Public Member Functions | |
| CodeExtractor (BasicBlock *BB, bool AggregateArgs=false, BlockFrequencyInfo *BFI=nullptr, BranchProbabilityInfo *BPI=nullptr) | |
| Create a code extractor for a single basic block. More... | |
| 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... | |
| CodeExtractor (DominatorTree &DT, const RegionNode &RN, bool AggregateArgs=false, BlockFrequencyInfo *BFI=nullptr, BranchProbabilityInfo *BPI=nullptr) | |
| Create a code extractor for a region node. 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 |
| Compute the set of input values and output values for the 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 47 of file CodeExtractor.h.
| CodeExtractor::CodeExtractor | ( | BasicBlock * | BB, |
| bool | AggregateArgs = false, |
||
| BlockFrequencyInfo * | BFI = nullptr, |
||
| BranchProbabilityInfo * | BPI = nullptr |
||
| ) |
Create a code extractor for a single basic block.
In this formation, we don't require a dominator tree. The given basic block is set up for extraction.
Definition at line 127 of file CodeExtractor.cpp.
| 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 133 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 139 of file CodeExtractor.cpp.
| CodeExtractor::CodeExtractor | ( | DominatorTree & | DT, |
| const RegionNode & | RN, | ||
| bool | AggregateArgs = false, |
||
| BlockFrequencyInfo * | BFI = nullptr, |
||
| BranchProbabilityInfo * | BPI = nullptr |
||
| ) |
Create a code extractor for a region node.
Behaves just like the generic code sequence constructor, but uses the block sequence of the region node passed in.
Definition at line 146 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 747 of file CodeExtractor.cpp.
References assert(), llvm::sys::path::begin(), llvm::BasicBlock::begin(), llvm::AMDGPUISD::BFI, llvm::BasicBlock::Create(), llvm::BranchInst::Create(), DEBUG, findInputsOutputs(), 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::Optional< T >::getValue(), llvm::Optional< T >::hasValue(), I, i, llvm::SmallPtrSetImpl< PtrType >::insert(), isEligible(), llvm::predecessors(), llvm::iplist_impl< IntrusiveListT, TraitsT >::push_back(), llvm::PHINode::removeIncomingValue(), llvm::report_fatal_error(), llvm::Function::setEntryCount(), llvm::PHINode::setIncomingBlock(), SI, llvm::SmallPtrSetImplBase::size(), llvm::succ_begin(), llvm::succ_end(), and llvm::verifyFunction().
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 172 of file CodeExtractor.cpp.
References definedInCaller(), definedInRegion(), llvm::SetVector< T, Vector, Set >::insert(), and llvm::Value::users().
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 57 of file CodeExtractor.cpp.
References llvm::BasicBlock::begin(), E, llvm::BasicBlock::end(), F, I, and llvm::BasicBlock::isEHPad().
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 112 of file CodeExtractor.h.
Referenced by extractCodeRegion().
1.8.6