class IROutliner

Declaration

class IROutliner { /* full declaration omitted */ };

Description

This class is a pass that identifies similarity in a Module, extracts instances of the similarity, and then consolidating the similar regions in an effort to reduce code size. It uses the IRSimilarityIdentifier pass to identify the similar regions of code, and then extracts the similar sections into a single function. See the above for an example as to how code is extracted and consolidated into a single function.

Declared at: llvm/include/llvm/Transforms/IPO/IROutliner.h:199

Member Variables

private bool OutlineFromLinkODRs = false
If true, enables us to outline from functions that have LinkOnceFromODR linkages.
private bool CostModel = true
If false, we do not worry if the cost is greater than the benefit. This is for debugging and testing, so that we can test small cases to ensure that the outlining is being done correctly.
private DenseSet<unsigned int> Outlined
The set of outlined Instructions, identified by their location in the sequential ordering of instructions in a Module.
private function_ref<llvm::TargetTransformInfo&( llvm::Function&)> getTTI
TargetTransformInfo lambda for target specific information.
private DenseMap<llvm::Value*, llvm::Value*> OutputMappings
A mapping from newly created reloaded output values to the original value. If an value is replace by an output from an outlined region, this maps that Value, back to its original Value.
private function_ref< llvm::IRSimilarity::IRSimilarityIdentifier&( llvm::Module&)> getIRSI
IRSimilarityIdentifier lambda to retrieve IRSimilarityIdentifier.
private function_ref<llvm::OptimizationRemarkEmitter&( llvm::Function&)> getORE
The optimization remark emitter for the pass.
private SpecificBumpPtrAllocator<llvm::CodeExtractor> ExtractorAllocator
The memory allocator used to allocate the CodeExtractors.
private SpecificBumpPtrAllocator<llvm::OutlinableRegion> RegionAllocator
The memory allocator used to allocate the OutlinableRegions.
private SpecificBumpPtrAllocator< llvm::IRSimilarity::IRInstructionData> InstDataAllocator
The memory allocator used to allocate new IRInstructionData.
private llvm::IROutliner::InstructionAllowed InstructionClassifier
A InstVisitor used to exclude certain instructions from being outlined.

Method Overview

  • public IROutliner(function_ref<llvm::TargetTransformInfo &(llvm::Function &)> GTTI, function_ref<llvm::IRSimilarity::IRSimilarityIdentifier &(llvm::Module &)> GIRSI, function_ref<llvm::OptimizationRemarkEmitter &(llvm::Function &)> GORE)
  • private llvm::Function * createFunction(llvm::Module & M, OutlinableGroup & CG, unsigned int FunctionNameSuffix)
  • private void deduplicateExtractedSections(llvm::Module & M, OutlinableGroup & CurrentGroup, std::vector<Function *> & FuncsToRemove, unsigned int & OutlinedFunctionNum)
  • private unsigned int doOutline(llvm::Module & M)
  • private bool extractSection(llvm::OutlinableRegion & Region)
  • private void findAddInputsOutputs(llvm::Module & M, llvm::OutlinableRegion & Region, DenseSet<unsigned int> & NotSame)
  • private llvm::InstructionCost findBenefitFromAllRegions(OutlinableGroup & CurrentGroup)
  • private void findCostBenefit(llvm::Module & M, OutlinableGroup & CurrentGroup)
  • private llvm::InstructionCost findCostOutputReloads(OutlinableGroup & CurrentGroup)
  • private bool isCompatibleWithAlreadyOutlinedCode(const llvm::OutlinableRegion & Region)
  • private void pruneIncompatibleRegions(std::vector<IRSimilarityCandidate> & CandidateVec, OutlinableGroup & CurrentGroup)
  • public bool run(llvm::Module & M)
  • private void updateOutputMapping(llvm::OutlinableRegion & Region, ArrayRef<llvm::Value *> Outputs, llvm::LoadInst * LI)

Methods

IROutliner(
    function_ref<llvm::TargetTransformInfo&(
        llvm::Function&)> GTTI,
    function_ref<llvm::IRSimilarity::
                     IRSimilarityIdentifier&(
                         llvm::Module&)> GIRSI,
    function_ref<llvm::OptimizationRemarkEmitter&(
        llvm::Function&)> GORE)

Declared at: llvm/include/llvm/Transforms/IPO/IROutliner.h:201

Parameters

function_ref<llvm::TargetTransformInfo&( llvm::Function&)> GTTI
function_ref< llvm::IRSimilarity::IRSimilarityIdentifier&( llvm::Module&)> GIRSI
function_ref<llvm::OptimizationRemarkEmitter&( llvm::Function&)> GORE

llvm::Function* createFunction(
    llvm::Module& M,
    OutlinableGroup& CG,
    unsigned int FunctionNameSuffix)

Description

Create the function based on the overall types found in the current regions being outlined.

Declared at: llvm/include/llvm/Transforms/IPO/IROutliner.h:252

Parameters

llvm::Module& M
- The module to outline from.
OutlinableGroup& CG
- The OutlinableGroup for the regions to be outlined.
unsigned int FunctionNameSuffix
- How many functions have we previously created.

Returns

the newly created function.

void deduplicateExtractedSections(
    llvm::Module& M,
    OutlinableGroup& CurrentGroup,
    std::vector<Function*>& FuncsToRemove,
    unsigned int& OutlinedFunctionNum)

Description

For the similarities found, and the extracted sections, create a single outlined function with appropriate output blocks as necessary.

Declared at: llvm/include/llvm/Transforms/IPO/IROutliner.h:311

Parameters

llvm::Module& M
- The module to outline from
OutlinableGroup& CurrentGroup
- The set of extracted sections to consolidate.
std::vector<Function*>& FuncsToRemove
- List of functions to remove from the module after outlining is completed.
unsigned int& OutlinedFunctionNum
- the number of new outlined functions.

unsigned int doOutline(llvm::Module& M)

Description

Find repeated similar code sequences in \p M and outline them into new Functions.

Declared at: llvm/include/llvm/Transforms/IPO/IROutliner.h:220

Parameters

llvm::Module& M
- The module to outline from.

Returns

The number of Functions created.

bool extractSection(
    llvm::OutlinableRegion& Region)

Description

Extract \p Region into its own function.

Declared at: llvm/include/llvm/Transforms/IPO/IROutliner.h:300

Parameters

llvm::OutlinableRegion& Region
- The region to be extracted into its own function.

Returns

True if it was successfully outlined.

void findAddInputsOutputs(
    llvm::Module& M,
    llvm::OutlinableRegion& Region,
    DenseSet<unsigned int>& NotSame)

Description

Identify the needed extracted inputs in a section, and add to the overall function if needed.

Declared at: llvm/include/llvm/Transforms/IPO/IROutliner.h:262

Parameters

llvm::Module& M
- The module to outline from.
llvm::OutlinableRegion& Region
- The region to be extracted.
DenseSet<unsigned int>& NotSame
- The global value numbers of the Values in the region that do not have the same Constant in each strucutrally similar region.

llvm::InstructionCost findBenefitFromAllRegions(
    OutlinableGroup& CurrentGroup)

Description

Find the number of instructions that will be removed by extracting the OutlinableRegions in \p CurrentGroup.

Declared at: llvm/include/llvm/Transforms/IPO/IROutliner.h:271

Parameters

OutlinableGroup& CurrentGroup
- The collection of OutlinableRegions to be analyzed.

Returns

the number of outlined instructions across all regions.

void findCostBenefit(
    llvm::Module& M,
    OutlinableGroup& CurrentGroup)

Description

Find the cost and the benefit of \p CurrentGroup and save it back to\p CurrentGroup.

Declared at: llvm/include/llvm/Transforms/IPO/IROutliner.h:285

Parameters

llvm::Module& M
- The module being analyzed
OutlinableGroup& CurrentGroup
- The overall outlined section

llvm::InstructionCost findCostOutputReloads(
    OutlinableGroup& CurrentGroup)

Description

Find the number of instructions that will be added by reloading arguments.

Declared at: llvm/include/llvm/Transforms/IPO/IROutliner.h:278

Parameters

OutlinableGroup& CurrentGroup
- The collection of OutlinableRegions to be analyzed.

Returns

the number of added reload instructions across all regions.

bool isCompatibleWithAlreadyOutlinedCode(
    const llvm::OutlinableRegion& Region)

Description

Check whether an OutlinableRegion is incompatible with code already outlined. OutlinableRegions are incomptaible when there are overlapping instructions, or code that has not been recorded has been added to the instructions.

Declared at: llvm/include/llvm/Transforms/IPO/IROutliner.h:230

Parameters

const llvm::OutlinableRegion& Region
- The OutlinableRegion to check for conflicts with already outlined code.

Returns

whether the region can safely be outlined.

void pruneIncompatibleRegions(
    std::vector<IRSimilarityCandidate>&
        CandidateVec,
    OutlinableGroup& CurrentGroup)

Description

Remove all the IRSimilarityCandidates from \p CandidateVec that have instructions contained in a previously outlined region and put the remaining regions in \p CurrentGroup.

Declared at: llvm/include/llvm/Transforms/IPO/IROutliner.h:241

Parameters

std::vector<IRSimilarityCandidate>& CandidateVec
- List of similarity candidates for regions with the same similarity structure.
OutlinableGroup& CurrentGroup
- Contains the potential sections to be outlined.

bool run(llvm::Module& M)

Declared at: llvm/include/llvm/Transforms/IPO/IROutliner.h:212

Parameters

llvm::Module& M

void updateOutputMapping(
    llvm::OutlinableRegion& Region,
    ArrayRef<llvm::Value*> Outputs,
    llvm::LoadInst* LI)

Description

Update the output mapping based on the load instruction, and the outputs of the extracted function.

Declared at: llvm/include/llvm/Transforms/IPO/IROutliner.h:293

Parameters

llvm::OutlinableRegion& Region
- The region extracted
ArrayRef<llvm::Value*> Outputs
- The outputs from the extracted function.
llvm::LoadInst* LI
- The load instruction used to update the mapping.