LLVM  4.0.0
Public Member Functions | Static Public Member Functions | List of all members
llvm::CodeExtractor Class Reference

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...
 
FunctionextractCodeRegion ()
 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...
 

Detailed Description

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.

Constructor & Destructor Documentation

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.

Member Function Documentation

Function * CodeExtractor::extractCodeRegion ( )
void CodeExtractor::findInputsOutputs ( ValueSet Inputs,
ValueSet Outputs 
) 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 172 of file CodeExtractor.cpp.

References definedInCaller(), definedInRegion(), llvm::SetVector< T, Vector, Set >::insert(), and llvm::Value::users().

Referenced by extractCodeRegion().

bool CodeExtractor::isBlockValidForExtraction ( const BasicBlock BB)
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().

bool llvm::CodeExtractor::isEligible ( ) const
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().


The documentation for this class was generated from the following files: