LLVM 17.0.0git
IROutliner.cpp File Reference
#include "llvm/Transforms/IPO/IROutliner.h"
#include "llvm/Analysis/IRSimilarityIdentifier.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Mangler.h"
#include "llvm/IR/PassManager.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Transforms/IPO.h"
#include <optional>
#include <vector>
Include dependency graph for IROutliner.cpp:

Go to the source code of this file.

## Classes

struct  OutlinableGroup
The OutlinableGroup holds all the overarching information for outlining a set of regions that are structurally similar to one another, such as the types of the overall function, the output blocks, the sets of stores needed and a list of the different regions. More...

## Namespaces

namespace  llvm
This is an optimization pass for GlobalISel generic memory operations.

## Macros

#define DEBUG_TYPE   "iroutliner"

## Typedefs

using ArgLocWithBBCanon = std::pair< unsigned, unsigned >

using CanonList = SmallVector< unsigned, 2 >

using PHINodeData = std::pair< ArgLocWithBBCanon, CanonList >

## Functions

static void moveBBContents (BasicBlock &SourceBB, BasicBlock &TargetBB)
Move the contents of SourceBB to before the last instruction of TargetBB.

static void getSortedConstantKeys (std::vector< Value * > &SortedKeys, DenseMap< Value *, BasicBlock * > &Map)
A function to sort the keys of Map, which must be a mapping of constant values to basic blocks and return it in SortedKeys.

static void replaceTargetsFromPHINode (BasicBlock *PHIBlock, BasicBlock *Find, BasicBlock *Replace, DenseSet< BasicBlock * > &Included)
Rewrite the BranchInsts in the incoming blocks to PHIBlock that are found in Included to branch to BasicBlock Replace if they currently branch to the BasicBlock Find.

static std::optional< boolconstantMatches (Value *V, unsigned GVN, DenseMap< unsigned, Constant * > &GVNToConstant)
Find whether V matches the Constants previously found for the GVN.

static ValuefindOutputMapping (const DenseMap< Value *, Value * > OutputMappings, Value *Input)
Check the OutputMappings structure for value Input, if it exists it has been used as an output for outlining, and has been renamed, and we return the new value, otherwise, we return the same value.

static bool collectRegionsConstants (OutlinableRegion &Region, DenseMap< unsigned, Constant * > &GVNToConstant, DenseSet< unsigned > &NotSame)
Find whether Region matches the global value numbering to Constant mapping found so far.

static DISubprogramgetSubprogramOrNull (OutlinableGroup &Group)
Get the subprogram if it exists for one of the outlined regions.

static void moveFunctionData (Function &Old, Function &New, DenseMap< Value *, BasicBlock * > &NewEnds)
Move each BasicBlock in Old to New.

static void findConstants (IRSimilarityCandidate &C, DenseSet< unsigned > &NotSame, std::vector< unsigned > &Inputs)
Find the the constants that will need to be lifted into arguments as they are not the same in each instance of the region.

static void mapInputsToGVNs (IRSimilarityCandidate &C, SetVector< Value * > &CurrentInputs, const DenseMap< Value *, Value * > &OutputMappings, std::vector< unsigned > &EndInputNumbers)
Find the GVN for the inputs that have been found by the CodeExtractor.

static void remapExtractedInputs (const ArrayRef< Value * > ArgInputs, const DenseMap< Value *, Value * > &OutputMappings, SetVector< Value * > &RemappedArgInputs)
Find the original value for the ArgInput values if any one of them was replaced during a previous extraction.

static void getCodeExtractorArguments (OutlinableRegion &Region, std::vector< unsigned > &InputGVNs, DenseSet< unsigned > &NotSame, DenseMap< Value *, Value * > &OutputMappings, SetVector< Value * > &ArgInputs, SetVector< Value * > &Outputs)
Find the input GVNs and the output values for a region of Instructions.

static void findExtractedInputToOverallInputMapping (OutlinableRegion &Region, std::vector< unsigned > &InputGVNs, SetVector< Value * > &ArgInputs)
Look over the inputs and map each input argument to an argument in the overall function for the OutlinableRegions.

static bool outputHasNonPHI (Value *V, unsigned PHILoc, PHINode &PN, SmallPtrSet< BasicBlock *, 1 > &Exits, DenseSet< BasicBlock * > &BlocksInRegion)
Check if the V has any uses outside of the region other than PN.

static void analyzeExitPHIsForOutputUses (BasicBlock *CurrentExitFromRegion, SmallPtrSet< BasicBlock *, 1 > &PotentialExitsFromRegion, DenseSet< BasicBlock * > &RegionBlocks, SetVector< Value * > &Outputs, DenseSet< Value * > &OutputsReplacedByPHINode, DenseSet< Value * > &OutputsWithNonPhiUses)
Test whether CurrentExitFromRegion contains any PhiNodes that should be considered outputs.

static hash_code encodePHINodeData (PHINodeData &PND)
Encode PND as an integer for easy lookup based on the argument location, the parent BasicBlock canonical numbering, and the canonical numbering of the values stored in the PHINode.

static std::optional< unsignedgetGVNForPHINode (OutlinableRegion &Region, PHINode *PN, DenseSet< BasicBlock * > &Blocks, unsigned AggArgIdx)
Create a special GVN for PHINodes that will be used outside of the region.

static void findExtractedOutputToOverallOutputMapping (Module &M, OutlinableRegion &Region, SetVector< Value * > &Outputs)
Create a mapping of the output arguments for the Region to the output arguments of the overall outlined function.

CallInstreplaceCalledFunction (Module &M, OutlinableRegion &Region)
Replace the extracted function in the Region with a call to the overall function constructed from the deduplicated similar regions, replacing and remapping the values passed to the extracted function as arguments to the new arguments of the overall function.

static BasicBlockfindOrCreatePHIBlock (OutlinableGroup &Group, Value *RetVal)
Find or create a BasicBlock in the outlined function containing PhiBlocks for RetVal.

static ValuegetPassedArgumentInAlreadyOutlinedFunction (const Argument *A, const OutlinableRegion &Region)
For the function call now representing the Region, find the passed value to that call that represents Argument A at the call location if the call has already been replaced with a call to the overall, aggregate function.

static ValuegetPassedArgumentAndAdjustArgumentLocation (const Argument *A, const OutlinableRegion &Region)
For the function call now representing the Region, find the passed value to that call that represents Argument A at the call location if the call has only been replaced by the call to the aggregate function.

static void findCanonNumsForPHI (PHINode *PN, OutlinableRegion &Region, const DenseMap< Value *, Value * > &OutputMappings, SmallVector< std::pair< unsigned, BasicBlock * > > &CanonNums, bool ReplacedWithOutlinedCall=true)
Find the canonical numbering for the incoming Values into the PHINode PN.

static PHINodefindOrCreatePHIInBlock (PHINode &PN, OutlinableRegion &Region, BasicBlock *OverallPhiBlock, const DenseMap< Value *, Value * > &OutputMappings, DenseSet< PHINode * > &UsedPHIs)
Find, or add PHINode PN to the combined PHINode Block OverallPHIBlock in order to condense the number of instructions added to the outlined function.

static void replaceArgumentUses (OutlinableRegion &Region, DenseMap< Value *, BasicBlock * > &OutputBBs, const DenseMap< Value *, Value * > &OutputMappings, bool FirstFunction=false)

void replaceConstants (OutlinableRegion &Region)
Within an extracted function, replace the constants that need to be lifted into arguments with the actual argument.

std::optional< unsignedfindDuplicateOutputBlock (DenseMap< Value *, BasicBlock * > &OutputBBs, std::vector< DenseMap< Value *, BasicBlock * > > &OutputStoreBBs)
It is possible that there is a basic block that already performs the same stores.

static bool analyzeAndPruneOutputBlocks (DenseMap< Value *, BasicBlock * > &BlocksToPrune, OutlinableRegion &Region)
Remove empty output blocks from the outlined region.

static void alignOutputBlockWithAggFunc (OutlinableGroup &OG, OutlinableRegion &Region, DenseMap< Value *, BasicBlock * > &OutputBBs, DenseMap< Value *, BasicBlock * > &EndBBs, const DenseMap< Value *, Value * > &OutputMappings, std::vector< DenseMap< Value *, BasicBlock * > > &OutputStoreBBs)
For the outlined section, move needed the StoreInsts for the output registers into their own block.

static void createAndInsertBasicBlocks (DenseMap< Value *, BasicBlock * > &OldMap, DenseMap< Value *, BasicBlock * > &NewMap, Function *ParentFunc, Twine BaseName)
Takes in a mapping, OldMap of ConstantValues to BasicBlocks, sorts keys, before creating a basic block for each NewMap, and inserting into the new block.

void createSwitchStatement (Module &M, OutlinableGroup &OG, DenseMap< Value *, BasicBlock * > &EndBBs, std::vector< DenseMap< Value *, BasicBlock * > > &OutputStoreBBs)
Create the switch statement for outlined function to differentiate between all the output blocks.

static void fillOverallFunction (Module &M, OutlinableGroup &CurrentGroup, std::vector< DenseMap< Value *, BasicBlock * > > &OutputStoreBBs, std::vector< Function * > &FuncsToRemove, const DenseMap< Value *, Value * > &OutputMappings)
Fill the new function that will serve as the replacement function for all of the extracted regions of a certain structure from the first region in the list of regions.

static bool nextIRInstructionDataMatchesNextInst (IRInstructionData &ID)
Checks that the next instruction in the InstructionDataList matches the next instruction in the module.

static ValuefindOutputValueInRegion (OutlinableRegion &Region, unsigned OutputCanon)
For the OutputCanon number passed in find the value represented by this canonical number.

static InstructionCost findCostForOutputBlocks (Module &M, OutlinableGroup &CurrentGroup, TargetTransformInfo &TTI)
Find the extra instructions needed to handle any output values for the region.

## Variables

static cl::opt< boolNoCostModel ("ir-outlining-no-cost", cl::init(false), cl::ReallyHidden, cl::desc("Debug option to outline greedily, without restriction that " "calculated benefit outweighs cost"))

## ◆ DEBUG_TYPE

 #define DEBUG_TYPE   "iroutliner"

Definition at line 32 of file IROutliner.cpp.

## ◆ ArgLocWithBBCanon

 using ArgLocWithBBCanon = std::pair

Definition at line 1143 of file IROutliner.cpp.

## ◆ CanonList

 using CanonList = SmallVector

Definition at line 1145 of file IROutliner.cpp.

## ◆ PHINodeData

 using PHINodeData = std::pair

Definition at line 1148 of file IROutliner.cpp.

## ◆ alignOutputBlockWithAggFunc()

 static void alignOutputBlockWithAggFunc ( OutlinableGroup & OG, OutlinableRegion & Region, DenseMap< Value *, BasicBlock * > & OutputBBs, DenseMap< Value *, BasicBlock * > & EndBBs, const DenseMap< Value *, Value * > & OutputMappings, std::vector< DenseMap< Value *, BasicBlock * > > & OutputStoreBBs )
static

For the outlined section, move needed the StoreInsts for the output registers into their own block.

Then, determine if there is a duplicate output block already created.

Parameters
 [in] OG - The OutlinableGroup of regions to be outlined. [in] Region - The OutlinableRegion that is being analyzed. [in,out] OutputBBs - the blocks that stores for this region will be placed in. [in] EndBBs - the final blocks of the extracted function. [in] OutputMappings - OutputMappings the mapping of values that have been replaced by a new output value. [in,out] OutputStoreBBs - The existing output blocks.

Definition at line 2072 of file IROutliner.cpp.

## ◆ analyzeAndPruneOutputBlocks()

 static bool analyzeAndPruneOutputBlocks ( DenseMap< Value *, BasicBlock * > & BlocksToPrune, OutlinableRegion & Region )
static

Remove empty output blocks from the outlined region.

Parameters
 BlocksToPrune - Mapping of return values output blocks for the Region. Region - The OutlinableRegion we are analyzing.

Definition at line 2025 of file IROutliner.cpp.

Referenced by alignOutputBlockWithAggFunc(), and fillOverallFunction().

## ◆ analyzeExitPHIsForOutputUses()

 static void analyzeExitPHIsForOutputUses ( BasicBlock * CurrentExitFromRegion, SmallPtrSet< BasicBlock *, 1 > & PotentialExitsFromRegion, DenseSet< BasicBlock * > & RegionBlocks, SetVector< Value * > & Outputs, DenseSet< Value * > & OutputsReplacedByPHINode, DenseSet< Value * > & OutputsWithNonPhiUses )
static

Test whether CurrentExitFromRegion contains any PhiNodes that should be considered outputs.

A PHINodes is an output when more than one incoming value has been marked by the CodeExtractor as an output.

Parameters
 CurrentExitFromRegion [in] - The block to analyze. PotentialExitsFromRegion [in] - The potential exit blocks from the region. RegionBlocks [in] - The basic blocks in the region. Outputs [in, out] - The existing outputs for the region, we may add PHINodes to this as we find that they replace output values. OutputsReplacedByPHINode [out] - A set containing outputs that are totally replaced by a PHINode. OutputsWithNonPhiUses [out] - A set containing outputs that are used in PHINodes, but have other uses, and should still be considered outputs.

Definition at line 1095 of file IROutliner.cpp.

Referenced by findExtractedOutputToOverallOutputMapping().

## ◆ collectRegionsConstants()

 static bool collectRegionsConstants ( OutlinableRegion & Region, DenseMap< unsigned, Constant * > & GVNToConstant, DenseSet< unsigned > & NotSame )
static

Find whether Region matches the global value numbering to Constant mapping found so far.

Parameters
 Region - The OutlinableRegion we are checking for constants GVNToConstant - The mapping of global value number to Constants. NotSame - The set of global value numbers that do not have the same constant in each region.
Returns
true if all Constants are the same in every use of a Constant in Region and false if not

Definition at line 552 of file IROutliner.cpp.

Referenced by OutlinableGroup::findSameConstants().

## ◆ constantMatches()

 static std::optional< bool > constantMatches ( Value * V, unsigned GVN, DenseMap< unsigned, Constant * > & GVNToConstant )
static

Find whether V matches the Constants previously found for the GVN.

Parameters
 V - The value to check for consistency. GVN - The global value number assigned to V. GVNToConstant - The mapping of global value number to Constants.
Returns
true if the Value matches the Constant mapped to by V and false if it V is a Constant but does not match.
std::nullopt if V is not a Constant.

Definition at line 466 of file IROutliner.cpp.

Referenced by collectRegionsConstants().

## ◆ createAndInsertBasicBlocks()

 static void createAndInsertBasicBlocks ( DenseMap< Value *, BasicBlock * > & OldMap, DenseMap< Value *, BasicBlock * > & NewMap, Function * ParentFunc, Twine BaseName )
static

Takes in a mapping, OldMap of ConstantValues to BasicBlocks, sorts keys, before creating a basic block for each NewMap, and inserting into the new block.

Each BasicBlock is named with the scheme "<basename>_<key_idx>".

Parameters
 OldMap [in] - The mapping to base the new mapping off of. NewMap [out] - The output mapping using the keys of OldMap. ParentFunc [in] - The function to put the new basic block in. BaseName [in] - The start of the BasicBlock names to be appended to by an index value.

Definition at line 2127 of file IROutliner.cpp.

Referenced by createSwitchStatement(), and fillOverallFunction().

## ◆ createSwitchStatement()

 void createSwitchStatement ( Module & M, OutlinableGroup & OG, DenseMap< Value *, BasicBlock * > & EndBBs, std::vector< DenseMap< Value *, BasicBlock * > > & OutputStoreBBs )

Create the switch statement for outlined function to differentiate between all the output blocks.

For the outlined section, determine if an outlined block already exists that matches the needed stores for the extracted section.

Parameters
 [in] M - The module we are outlining from. [in] OG - The group of regions to be outlined. [in] EndBBs - The final blocks of the extracted function. [in,out] OutputStoreBBs - The existing output blocks.

Definition at line 2153 of file IROutliner.cpp.

## ◆ encodePHINodeData()

 static hash_code encodePHINodeData ( PHINodeData & PND )
static

Encode PND as an integer for easy lookup based on the argument location, the parent BasicBlock canonical numbering, and the canonical numbering of the values stored in the PHINode.

Parameters
 PND - The data to hash.
Returns
The hash code of PND.

Definition at line 1156 of file IROutliner.cpp.

References llvm::hash_combine(), llvm::hash_combine_range(), and llvm::hash_value().

Referenced by getGVNForPHINode().

## ◆ fillOverallFunction()

 static void fillOverallFunction ( Module & M, OutlinableGroup & CurrentGroup, std::vector< DenseMap< Value *, BasicBlock * > > & OutputStoreBBs, std::vector< Function * > & FuncsToRemove, const DenseMap< Value *, Value * > & OutputMappings )
static

Fill the new function that will serve as the replacement function for all of the extracted regions of a certain structure from the first region in the list of regions.

Replace this first region's extracted function with the new overall function.

Parameters
 [in] M - The module we are outlining from. [in] CurrentGroup - The group of regions to be outlined. [in,out] OutputStoreBBs - The output blocks for each different set of stores needed for the different functions. [in,out] FuncsToRemove - Extracted functions to erase from module once outlining is complete. [in] OutputMappings - Extracted functions to erase from module once outlining is complete.

Definition at line 2246 of file IROutliner.cpp.

## ◆ findCanonNumsForPHI()

 static void findCanonNumsForPHI ( PHINode * PN, OutlinableRegion & Region, const DenseMap< Value *, Value * > & OutputMappings, SmallVector< std::pair< unsigned, BasicBlock * > > & CanonNums, bool ReplacedWithOutlinedCall = true )
static

Find the canonical numbering for the incoming Values into the PHINode PN.

Parameters
 PN [in] - The PHINode that we are finding the canonical numbers for. Region [in] - The OutlinableRegion containing PN. OutputMappings [in] - The mapping of output values from outlined region to their original values. CanonNums [out] - The canonical numbering for the incoming values to PN paired with their incoming block. ReplacedWithOutlinedCall - A flag to use the extracted function call of Region rather than the overall function's call.

Definition at line 1637 of file IROutliner.cpp.

Referenced by findOrCreatePHIInBlock().

## ◆ findConstants()

 static void findConstants ( IRSimilarityCandidate & C, DenseSet< unsigned > & NotSame, std::vector< unsigned > & Inputs )
static

Find the the constants that will need to be lifted into arguments as they are not the same in each instance of the region.

Parameters
 [in] C - The IRSimilarityCandidate containing the region we are analyzing. [in] NotSame - The set of global value numbers that do not have a single Constant across all OutlinableRegions similar to C. [out] Inputs - The list containing the global value numbers of the arguments needed for the region of code.

Definition at line 780 of file IROutliner.cpp.

Referenced by getCodeExtractorArguments().

## ◆ findCostForOutputBlocks()

 static InstructionCost findCostForOutputBlocks ( Module & M, OutlinableGroup & CurrentGroup, TargetTransformInfo & TTI )
static

Find the extra instructions needed to handle any output values for the region.

Parameters
 [in] M - The Module to outline from. [in] CurrentGroup - The collection of OutlinableRegions to analyze. [in] TTI - The TargetTransformInfo used to collect information for new instruction costs.
Returns
the additional cost to handle the outputs.

Definition at line 2559 of file IROutliner.cpp.

## ◆ findDuplicateOutputBlock()

 std::optional< unsigned > findDuplicateOutputBlock ( DenseMap< Value *, BasicBlock * > & OutputBBs, std::vector< DenseMap< Value *, BasicBlock * > > & OutputStoreBBs )

It is possible that there is a basic block that already performs the same stores.

This returns a duplicate block, if it exists

Parameters
 OutputBBs [in] the blocks we are looking for a duplicate of. OutputStoreBBs [in] The existing output blocks.
Returns
an optional value with the number output block if there is a match.

Definition at line 1970 of file IROutliner.cpp.

Referenced by alignOutputBlockWithAggFunc().

## ◆ findExtractedInputToOverallInputMapping()

 static void findExtractedInputToOverallInputMapping ( OutlinableRegion & Region, std::vector< unsigned > & InputGVNs, SetVector< Value * > & ArgInputs )
static

Look over the inputs and map each input argument to an argument in the overall function for the OutlinableRegions.

This creates a way to replace the arguments of the extracted function with the arguments of the new overall function.

Parameters
 [in,out] Region - The region of code to be analyzed. [in] InputGVNs - The global value numbering of the input values collected. [in] ArgInputs - The values of the arguments to the extracted function.

Definition at line 936 of file IROutliner.cpp.

## ◆ findExtractedOutputToOverallOutputMapping()

 static void findExtractedOutputToOverallOutputMapping ( Module & M, OutlinableRegion & Region, SetVector< Value * > & Outputs )
static

Create a mapping of the output arguments for the Region to the output arguments of the overall outlined function.

Parameters
 [in,out] Region - The region of code to be analyzed. [in] Outputs - The values found by the code extractor.

Definition at line 1278 of file IROutliner.cpp.

## ◆ findOrCreatePHIBlock()

 static BasicBlock * findOrCreatePHIBlock ( OutlinableGroup & Group, Value * RetVal )
static

Find or create a BasicBlock in the outlined function containing PhiBlocks for RetVal.

Parameters
 Group - The OutlinableGroup containing the information about the overall outlined function. RetVal - The return value or exit option that we are currently evaluating.
Returns
The found or newly created BasicBlock to contain the needed PHINodes to be used as outputs.

Definition at line 1543 of file IROutliner.cpp.

Referenced by replaceArgumentUses().

## ◆ findOrCreatePHIInBlock()

 static PHINode * findOrCreatePHIInBlock ( PHINode & PN, OutlinableRegion & Region, BasicBlock * OverallPhiBlock, const DenseMap< Value *, Value * > & OutputMappings, DenseSet< PHINode * > & UsedPHIs )
static

Find, or add PHINode PN to the combined PHINode Block OverallPHIBlock in order to condense the number of instructions added to the outlined function.

Parameters
 PN [in] - The PHINode that we are finding the canonical numbers for. Region [in] - The OutlinableRegion containing PN. OverallPhiBlock [in] - The overall PHIBlock we are trying to find PN in. OutputMappings [in] - The mapping of output values from outlined region to their original values. UsedPHIs [in, out] - The PHINodes in the block that have already been matched.
Returns
the newly found or created PHINode in OverallPhiBlock.

Definition at line 1681 of file IROutliner.cpp.

Referenced by replaceArgumentUses().

## ◆ findOutputMapping()

 static Value * findOutputMapping ( const DenseMap< Value *, Value * > OutputMappings, Value * Input )
static

Check the OutputMappings structure for value Input, if it exists it has been used as an output for outlining, and has been renamed, and we return the new value, otherwise, we return the same value.

Parameters
 OutputMappings [in] - The mapping of values to their renamed value after being used as an output for an outlined region. Input [in] - The value to find the remapped value of, if it exists.
Returns
The remapped value if it has been renamed, and the same value if has not.

Definition at line 533 of file IROutliner.cpp.

Referenced by findCanonNumsForPHI(), and findOrCreatePHIInBlock().

## ◆ findOutputValueInRegion()

 static Value * findOutputValueInRegion ( OutlinableRegion & Region, unsigned OutputCanon )
static

For the OutputCanon number passed in find the value represented by this canonical number.

If it is from a PHINode, we pick the first incoming value and return that Value instead.

Parameters
 Region - The OutlinableRegion to get the Value from. OutputCanon - The canonical number to find the Value from.
Returns
The Value represented by a canonical number OutputCanon in Region.

Definition at line 2507 of file IROutliner.cpp.

Referenced by findCostForOutputBlocks().

## ◆ getCodeExtractorArguments()

 static void getCodeExtractorArguments ( OutlinableRegion & Region, std::vector< unsigned > & InputGVNs, DenseSet< unsigned > & NotSame, DenseMap< Value *, Value * > & OutputMappings, SetVector< Value * > & ArgInputs, SetVector< Value * > & Outputs )
static

Find the input GVNs and the output values for a region of Instructions.

Using the code extractor, we collect the inputs to the extracted function.

The Region can be identified as needing to be ignored in this function. It should be checked whether it should be ignored after a call to this function.

Parameters
 [in,out] Region - The region of code to be analyzed. [out] InputGVNs - The global value numbers for the extracted arguments. [in] NotSame - The global value numbers in the region that do not have the same constant value in the regions structurally similar to Region. [in] OutputMappings - The mapping of values that have been replaced by a new output value after extraction. [out] ArgInputs - The values of the inputs to the extracted function. [out] Outputs - The set of values extracted by the CodeExtractor as outputs.

Definition at line 865 of file IROutliner.cpp.

## ◆ getGVNForPHINode()

 static std::optional< unsigned > getGVNForPHINode ( OutlinableRegion & Region, PHINode * PN, DenseSet< BasicBlock * > & Blocks, unsigned AggArgIdx )
static

Create a special GVN for PHINodes that will be used outside of the region.

We create a hash code based on the Canonical number of the parent BasicBlock, the canonical numbering of the values stored in the PHINode and the aggregate argument location. This is used to find whether this PHINode type has been given a canonical numbering already. If not, we assign it a value and store it for later use. The value is returned to identify different output schemes for the set of regions.

Parameters
 Region - The region that PN is an output for. PN - The PHINode we are analyzing. Blocks - The blocks for the region we are analyzing. AggArgIdx - The argument PN will be stored into.
Returns
An optional holding the assigned canonical number, or std::nullopt if there is some attribute of the PHINode blocking it from being used.

Definition at line 1176 of file IROutliner.cpp.

Referenced by findExtractedOutputToOverallOutputMapping().

 static Value * getPassedArgumentAndAdjustArgumentLocation ( const Argument * A, const OutlinableRegion & Region )
static

For the function call now representing the Region, find the passed value to that call that represents Argument A at the call location if the call has only been replaced by the call to the aggregate function.

Parameters
 A - The Argument to get the passed value for. Region - The extracted Region corresponding to the outlined function.
Returns
The Value representing A at the call site.

Definition at line 1612 of file IROutliner.cpp.

References A.

Referenced by findCanonNumsForPHI().

 static Value * getPassedArgumentInAlreadyOutlinedFunction ( const Argument * A, const OutlinableRegion & Region )
static

For the function call now representing the Region, find the passed value to that call that represents Argument A at the call location if the call has already been replaced with a call to the overall, aggregate function.

Parameters
 A - The Argument to get the passed value for. Region - The extracted Region corresponding to the outlined function.
Returns
The Value representing A at the call site.

Definition at line 1596 of file IROutliner.cpp.

References A.

Referenced by findCanonNumsForPHI().

## ◆ getSortedConstantKeys()

 static void getSortedConstantKeys ( std::vector< Value * > & SortedKeys, DenseMap< Value *, BasicBlock * > & Map )
static

A function to sort the keys of Map, which must be a mapping of constant values to basic blocks and return it in SortedKeys.

Parameters
 SortedKeys - The vector the keys will be return in and sorted. Map - The DenseMap containing keys to sort.

Definition at line 168 of file IROutliner.cpp.

References assert(), llvm::ConstantInt::getLimitedValue(), LHS, RHS, and llvm::stable_sort().

Referenced by createAndInsertBasicBlocks().

## ◆ getSubprogramOrNull()

 static DISubprogram * getSubprogramOrNull ( OutlinableGroup & Group )
static

Get the subprogram if it exists for one of the outlined regions.

Parameters
 [in] Group - The set of regions to find a subprogram for.
Returns
the subprogram if it exists, or nullptr.

Definition at line 623 of file IROutliner.cpp.

References F, OS, and OutlinableGroup::Regions.

## ◆ mapInputsToGVNs()

 static void mapInputsToGVNs ( IRSimilarityCandidate & C, SetVector< Value * > & CurrentInputs, const DenseMap< Value *, Value * > & OutputMappings, std::vector< unsigned > & EndInputNumbers )
static

Find the GVN for the inputs that have been found by the CodeExtractor.

Parameters
 [in] C - The IRSimilarityCandidate containing the region we are analyzing. [in] CurrentInputs - The set of inputs found by the CodeExtractor. [in] OutputMappings - The mapping of values that have been replaced by a new output value. [out] EndInputNumbers - The global value numbers for the extracted arguments.

Definition at line 810 of file IROutliner.cpp.

Referenced by getCodeExtractorArguments().

## ◆ moveBBContents()

 static void moveBBContents ( BasicBlock & SourceBB, BasicBlock & TargetBB )
static

Move the contents of SourceBB to before the last instruction of TargetBB.

Parameters
 SourceBB - the BasicBlock to pull Instructions from. TargetBB - the BasicBlock to put Instruction into.

Definition at line 158 of file IROutliner.cpp.

References llvm::BasicBlock::end(), I, and llvm::make_early_inc_range().

Referenced by createSwitchStatement(), and llvm::OutlinableRegion::reattachCandidate().

## ◆ moveFunctionData()

 static void moveFunctionData ( Function & Old, Function & New, DenseMap< Value *, BasicBlock * > & NewEnds )
static

Move each BasicBlock in Old to New.

Parameters
 [in] Old - The function to move the basic blocks from. [in] New - The function to move the basic blocks to. [out] NewEnds - The return blocks of the new overall function.

Definition at line 711 of file IROutliner.cpp.

Referenced by fillOverallFunction().

## ◆ nextIRInstructionDataMatchesNextInst()

 static bool nextIRInstructionDataMatchesNextInst ( IRInstructionData & ID )
static

Checks that the next instruction in the InstructionDataList matches the next instruction in the module.

If they do not, there could be the possibility that extra code has been inserted, and we must ignore it.

Parameters
 ID - The IRInstructionData to check the next instruction of.
Returns
true if the InstructionDataList and actual instruction match.

Definition at line 2340 of file IROutliner.cpp.

## ◆ outputHasNonPHI()

 static bool outputHasNonPHI ( Value * V, unsigned PHILoc, PHINode & PN, SmallPtrSet< BasicBlock *, 1 > & Exits, DenseSet< BasicBlock * > & BlocksInRegion )
static

Check if the V has any uses outside of the region other than PN.

Parameters
 V [in] - The value to check. PHILoc [in] - The location in the PHINode of V. PN [in] - The PHINode using V. Exits [in] - The potential blocks we exit to from the outlined region. BlocksInRegion [in] - The basic blocks contained in the region.
Returns
true if V has any use soutside its region other than PN.

Definition at line 1038 of file IROutliner.cpp.

References llvm::any_of(), llvm::PHINode::getNumIncomingValues(), and Idx.

Referenced by analyzeExitPHIsForOutputUses().

## ◆ remapExtractedInputs()

 static void remapExtractedInputs ( const ArrayRef< Value * > ArgInputs, const DenseMap< Value *, Value * > & OutputMappings, SetVector< Value * > & RemappedArgInputs )
static

Find the original value for the ArgInput values if any one of them was replaced during a previous extraction.

Parameters
 [in] ArgInputs - The inputs to be extracted by the code extractor. [in] OutputMappings - The mapping of values that have been replaced by a new output value. [out] RemappedArgInputs - The remapped values according to OutputMappings that will be extracted.

Definition at line 835 of file IROutliner.cpp.

Referenced by getCodeExtractorArguments().

## ◆ replaceArgumentUses()

 static void replaceArgumentUses ( OutlinableRegion & Region, DenseMap< Value *, BasicBlock * > & OutputBBs, const DenseMap< Value *, Value * > & OutputMappings, bool FirstFunction = false )
static
Parameters
 [in] Region - The region of extracted code to be changed. [in,out] OutputBBs - The BasicBlock for the output stores for this region. [in] FirstFunction - A flag to indicate whether we are using this function to define the overall outlined function for all the regions, or if we are operating on one of the following regions.

Definition at line 1803 of file IROutliner.cpp.

Referenced by fillOverallFunction().

## ◆ replaceCalledFunction()

 CallInst * replaceCalledFunction ( Module & M, OutlinableRegion & Region )

Replace the extracted function in the Region with a call to the overall function constructed from the deduplicated similar regions, replacing and remapping the values passed to the extracted function as arguments to the new arguments of the overall function.

Parameters
 [in] M - The module to outline from. [in] Region - The regions of extracted code to be replaced with a new function.
Returns
a call instruction with the replaced function.

Definition at line 1432 of file IROutliner.cpp.

Referenced by fillOverallFunction().

## ◆ replaceConstants()

 void replaceConstants ( OutlinableRegion & Region )

Within an extracted function, replace the constants that need to be lifted into arguments with the actual argument.

Parameters
 Region [in] - The region of extracted code to be changed.

Definition at line 1937 of file IROutliner.cpp.

Referenced by fillOverallFunction().

## ◆ replaceTargetsFromPHINode()

 static void replaceTargetsFromPHINode ( BasicBlock * PHIBlock, BasicBlock * Find, BasicBlock * Replace, DenseSet< BasicBlock * > & Included )
static

Rewrite the BranchInsts in the incoming blocks to PHIBlock that are found in Included to branch to BasicBlock Replace if they currently branch to the BasicBlock Find.

This is used to fix up the incoming basic blocks when PHINodes are included in outlined regions.

Parameters
 PHIBlock - The BasicBlock containing the PHINodes that need to be checked. Find - The successor block to be replaced. Replace - The new succesor block to branch to. Included - The set of blocks about to be outlined.

Definition at line 223 of file IROutliner.cpp.