LLVM 20.0.0git
Classes | Macros | Functions | Variables
FunctionSpecialization.cpp File Reference
#include "llvm/Transforms/IPO/FunctionSpecialization.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/CodeMetrics.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/InlineCost.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Analysis/ValueLattice.h"
#include "llvm/Analysis/ValueLatticeUtils.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/Transforms/Scalar/SCCP.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/SCCPSolver.h"
#include "llvm/Transforms/Utils/SizeOpts.h"
#include <cmath>

Go to the source code of this file.

Classes

struct  llvm::DenseMapInfo< SpecSig >
 

Macros

#define DEBUG_TYPE   "function-specialization"
 

Functions

 STATISTIC (NumSpecsCreated, "Number of specializations created")
 
static void removeSSACopy (Function &F)
 
static unsigned getCostValue (const Cost &C)
 Get the unsigned Value of given Cost object.
 
static FunctioncloneCandidateFunction (Function *F, unsigned NSpecs)
 Clone the function F and remove the ssa_copy intrinsics added by the SCCPSolver in the cloned version.
 

Variables

static cl::opt< boolForceSpecialization ("force-specialization", cl::init(false), cl::Hidden, cl::desc("Force function specialization for every call site with a constant " "argument"))
 
static cl::opt< unsignedMaxClones ("funcspec-max-clones", cl::init(3), cl::Hidden, cl::desc("The maximum number of clones allowed for a single function " "specialization"))
 
static cl::opt< unsignedMaxDiscoveryIterations ("funcspec-max-discovery-iterations", cl::init(100), cl::Hidden, cl::desc("The maximum number of iterations allowed " "when searching for transitive " "phis"))
 
static cl::opt< unsignedMaxIncomingPhiValues ("funcspec-max-incoming-phi-values", cl::init(8), cl::Hidden, cl::desc("The maximum number of incoming values a PHI node can have to be " "considered during the specialization bonus estimation"))
 
static cl::opt< unsignedMaxBlockPredecessors ("funcspec-max-block-predecessors", cl::init(2), cl::Hidden, cl::desc("The maximum number of predecessors a basic block can have to be " "considered during the estimation of dead code"))
 
static cl::opt< unsignedMinFunctionSize ("funcspec-min-function-size", cl::init(500), cl::Hidden, cl::desc("Don't specialize functions that have less than this number of " "instructions"))
 
static cl::opt< unsignedMaxCodeSizeGrowth ("funcspec-max-codesize-growth", cl::init(3), cl::Hidden, cl::desc("Maximum codesize growth allowed per function"))
 
static cl::opt< unsignedMinCodeSizeSavings ("funcspec-min-codesize-savings", cl::init(20), cl::Hidden, cl::desc("Reject specializations whose codesize savings are less than this" "much percent of the original function size"))
 
static cl::opt< unsignedMinLatencySavings ("funcspec-min-latency-savings", cl::init(40), cl::Hidden, cl::desc("Reject specializations whose latency savings are less than this" "much percent of the original function size"))
 
static cl::opt< unsignedMinInliningBonus ("funcspec-min-inlining-bonus", cl::init(300), cl::Hidden, cl::desc("Reject specializations whose inlining bonus is less than this" "much percent of the original function size"))
 
static cl::opt< boolSpecializeOnAddress ("funcspec-on-address", cl::init(false), cl::Hidden, cl::desc("Enable function specialization on the address of global values"))
 
static cl::opt< boolSpecializeLiteralConstant ("funcspec-for-literal-constant", cl::init(true), cl::Hidden, cl::desc("Enable specialization of functions that take a literal constant as an " "argument"))
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "function-specialization"

Definition at line 28 of file FunctionSpecialization.cpp.

Function Documentation

◆ cloneCandidateFunction()

static Function * cloneCandidateFunction ( Function F,
unsigned  NSpecs 
)
static

Clone the function F and remove the ssa_copy intrinsics added by the SCCPSolver in the cloned version.

Definition at line 860 of file FunctionSpecialization.cpp.

References llvm::CloneFunction(), F, removeSSACopy(), and llvm::Value::setName().

◆ getCostValue()

static unsigned getCostValue ( const Cost &  C)
static

Get the unsigned Value of given Cost object.

Assumes the Cost is always non-negative, which is true for both TCK_CodeSize and TCK_Latency, and always Valid.

Definition at line 662 of file FunctionSpecialization.cpp.

References assert(), and llvm::CallingConv::C.

◆ removeSSACopy()

static void removeSSACopy ( Function F)
static

Definition at line 614 of file FunctionSpecialization.cpp.

References F, II, and llvm::make_early_inc_range().

Referenced by cloneCandidateFunction().

◆ STATISTIC()

STATISTIC ( NumSpecsCreated  ,
"Number of specializations created"   
)

Variable Documentation

◆ ForceSpecialization

cl::opt< bool > ForceSpecialization("force-specialization", cl::init(false), cl::Hidden, cl::desc( "Force function specialization for every call site with a constant " "argument")) ( "force-specialization"  ,
cl::init(false)  ,
cl::Hidden  ,
cl::desc( "Force function specialization for every call site with a constant " "argument")   
)
static

◆ MaxBlockPredecessors

cl::opt< unsigned > MaxBlockPredecessors("funcspec-max-block-predecessors", cl::init(2), cl::Hidden, cl::desc( "The maximum number of predecessors a basic block can have to be " "considered during the estimation of dead code")) ( "funcspec-max-block-predecessors"  ,
cl::init(2)  ,
cl::Hidden  ,
cl::desc( "The maximum number of predecessors a basic block can have to be " "considered during the estimation of dead code")   
)
static

◆ MaxClones

cl::opt< unsigned > MaxClones("funcspec-max-clones", cl::init(3), cl::Hidden, cl::desc( "The maximum number of clones allowed for a single function " "specialization")) ( "funcspec-max-clones"  ,
cl::init(3)  ,
cl::Hidden  ,
cl::desc( "The maximum number of clones allowed for a single function " "specialization")   
)
static

◆ MaxCodeSizeGrowth

cl::opt< unsigned > MaxCodeSizeGrowth("funcspec-max-codesize-growth", cl::init(3), cl::Hidden, cl::desc( "Maximum codesize growth allowed per function")) ( "funcspec-max-codesize-growth"  ,
cl::init(3)  ,
cl::Hidden  ,
cl::desc( "Maximum codesize growth allowed per function")   
)
static

◆ MaxDiscoveryIterations

cl::opt< unsigned > MaxDiscoveryIterations("funcspec-max-discovery-iterations", cl::init(100), cl::Hidden, cl::desc("The maximum number of iterations allowed " "when searching for transitive " "phis")) ( "funcspec-max-discovery-iterations"  ,
cl::init(100)  ,
cl::Hidden  ,
cl::desc("The maximum number of iterations allowed " "when searching for transitive " "phis")   
)
static

◆ MaxIncomingPhiValues

cl::opt< unsigned > MaxIncomingPhiValues("funcspec-max-incoming-phi-values", cl::init(8), cl::Hidden, cl::desc("The maximum number of incoming values a PHI node can have to be " "considered during the specialization bonus estimation")) ( "funcspec-max-incoming-phi-values"  ,
cl::init(8)  ,
cl::Hidden  ,
cl::desc("The maximum number of incoming values a PHI node can have to be " "considered during the specialization bonus estimation")   
)
static

◆ MinCodeSizeSavings

cl::opt< unsigned > MinCodeSizeSavings("funcspec-min-codesize-savings", cl::init(20), cl::Hidden, cl::desc( "Reject specializations whose codesize savings are less than this" "much percent of the original function size")) ( "funcspec-min-codesize-savings"  ,
cl::init(20)  ,
cl::Hidden  ,
cl::desc( "Reject specializations whose codesize savings are less than this" "much percent of the original function size")   
)
static

◆ MinFunctionSize

cl::opt< unsigned > MinFunctionSize("funcspec-min-function-size", cl::init(500), cl::Hidden, cl::desc("Don't specialize functions that have less than this number of " "instructions")) ( "funcspec-min-function-size"  ,
cl::init(500)  ,
cl::Hidden  ,
cl::desc("Don't specialize functions that have less than this number of " "instructions")   
)
static

◆ MinInliningBonus

cl::opt< unsigned > MinInliningBonus("funcspec-min-inlining-bonus", cl::init(300), cl::Hidden, cl::desc( "Reject specializations whose inlining bonus is less than this" "much percent of the original function size")) ( "funcspec-min-inlining-bonus"  ,
cl::init(300)  ,
cl::Hidden  ,
cl::desc( "Reject specializations whose inlining bonus is less than this" "much percent of the original function size")   
)
static

◆ MinLatencySavings

cl::opt< unsigned > MinLatencySavings("funcspec-min-latency-savings", cl::init(40), cl::Hidden, cl::desc("Reject specializations whose latency savings are less than this" "much percent of the original function size")) ( "funcspec-min-latency-savings"  ,
cl::init(40)  ,
cl::Hidden  ,
cl::desc("Reject specializations whose latency savings are less than this" "much percent of the original function size")   
)
static

◆ SpecializeLiteralConstant

cl::opt< bool > SpecializeLiteralConstant("funcspec-for-literal-constant", cl::init(true), cl::Hidden, cl::desc( "Enable specialization of functions that take a literal constant as an " "argument")) ( "funcspec-for-literal-constant"  ,
cl::init(true ,
cl::Hidden  ,
cl::desc( "Enable specialization of functions that take a literal constant as an " "argument")   
)
static

◆ SpecializeOnAddress

cl::opt< bool > SpecializeOnAddress("funcspec-on-address", cl::init(false), cl::Hidden, cl::desc( "Enable function specialization on the address of global values")) ( "funcspec-on-address"  ,
cl::init(false)  ,
cl::Hidden  ,
cl::desc( "Enable function specialization on the address of global values")   
)
static