LLVM 20.0.0git
Namespaces | Macros | Functions | Variables
ModuleSummaryAnalysis.cpp File Reference
#include "llvm/Analysis/ModuleSummaryAnalysis.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/BranchProbabilityInfo.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/IndirectCallPromotionAnalysis.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/MemoryProfileInfo.h"
#include "llvm/Analysis/ProfileSummaryInfo.h"
#include "llvm/Analysis/StackSafetyAnalysis.h"
#include "llvm/Analysis/TypeMetadataUtils.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ModuleSummaryIndex.h"
#include "llvm/IR/Use.h"
#include "llvm/IR/User.h"
#include "llvm/InitializePasses.h"
#include "llvm/Object/ModuleSymbolTable.h"
#include "llvm/Object/SymbolicFile.h"
#include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <vector>

Go to the source code of this file.

Namespaces

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

Macros

#define DEBUG_TYPE   "module-summary-analysis"
 

Functions

static bool findRefEdges (ModuleSummaryIndex &Index, const User *CurUser, SetVector< ValueInfo, std::vector< ValueInfo > > &RefEdges, SmallPtrSet< const User *, 8 > &Visited, bool &RefLocalLinkageIFunc)
 
static CalleeInfo::HotnessType getHotness (uint64_t ProfileCount, ProfileSummaryInfo *PSI)
 
static bool isNonRenamableLocal (const GlobalValue &GV)
 
static void addVCallToSet (DevirtCallSite Call, GlobalValue::GUID Guid, SetVector< FunctionSummary::VFuncId, std::vector< FunctionSummary::VFuncId > > &VCalls, SetVector< FunctionSummary::ConstVCall, std::vector< FunctionSummary::ConstVCall > > &ConstVCalls)
 Determine whether this call has all constant integer arguments (excluding "this") and summarize it to VCalls or ConstVCalls as appropriate.
 
static void addIntrinsicToSummary (const CallInst *CI, SetVector< GlobalValue::GUID, std::vector< GlobalValue::GUID > > &TypeTests, SetVector< FunctionSummary::VFuncId, std::vector< FunctionSummary::VFuncId > > &TypeTestAssumeVCalls, SetVector< FunctionSummary::VFuncId, std::vector< FunctionSummary::VFuncId > > &TypeCheckedLoadVCalls, SetVector< FunctionSummary::ConstVCall, std::vector< FunctionSummary::ConstVCall > > &TypeTestAssumeConstVCalls, SetVector< FunctionSummary::ConstVCall, std::vector< FunctionSummary::ConstVCall > > &TypeCheckedLoadConstVCalls, DominatorTree &DT)
 If this intrinsic call requires that we add information to the function summary, do so via the non-constant reference arguments.
 
static bool isNonVolatileLoad (const Instruction *I)
 
static bool isNonVolatileStore (const Instruction *I)
 
static bool mustBeUnreachableFunction (const Function &F)
 
static void computeFunctionSummary (ModuleSummaryIndex &Index, const Module &M, const Function &F, BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI, DominatorTree &DT, bool HasLocalsInUsedOrAsm, DenseSet< GlobalValue::GUID > &CantBePromoted, bool IsThinLTO, std::function< const StackSafetyInfo *(const Function &F)> GetSSICallback)
 
static void findFuncPointers (const Constant *I, uint64_t StartingOffset, const Module &M, ModuleSummaryIndex &Index, VTableFuncList &VTableFuncs, const GlobalVariable &OrigGV)
 Find function pointers referenced within the given vtable initializer (or subset of an initializer) I.
 
static void computeVTableFuncs (ModuleSummaryIndex &Index, const GlobalVariable &V, const Module &M, VTableFuncList &VTableFuncs)
 
static void recordTypeIdCompatibleVtableReferences (ModuleSummaryIndex &Index, const GlobalVariable &V, SmallVectorImpl< MDNode * > &Types)
 Record vtable definition V for each type metadata it references.
 
static void computeVariableSummary (ModuleSummaryIndex &Index, const GlobalVariable &V, DenseSet< GlobalValue::GUID > &CantBePromoted, const Module &M, SmallVectorImpl< MDNode * > &Types)
 
static void computeAliasSummary (ModuleSummaryIndex &Index, const GlobalAlias &A, DenseSet< GlobalValue::GUID > &CantBePromoted)
 
static void setLiveRoot (ModuleSummaryIndex &Index, StringRef Name)
 
 INITIALIZE_PASS_BEGIN (ModuleSummaryIndexWrapperPass, "module-summary-analysis", "Module Summary Analysis", false, true) INITIALIZE_PASS_END(ModuleSummaryIndexWrapperPass
 
 INITIALIZE_PASS (ImmutableModuleSummaryIndexWrapperPass, "module-summary-info", "Module summary info", false, true) bool llvm
 

Variables

FunctionSummary::ForceSummaryHotnessType llvm::ForceSummaryEdgesCold
 
static cl::opt< FunctionSummary::ForceSummaryHotnessType, trueFSEC ("force-summary-edges-cold", cl::Hidden, cl::location(ForceSummaryEdgesCold), cl::desc("Force all edges in the function summary to cold"), cl::values(clEnumValN(FunctionSummary::FSHT_None, "none", "None."), clEnumValN(FunctionSummary::FSHT_AllNonCritical, "all-non-critical", "All non-critical edges."), clEnumValN(FunctionSummary::FSHT_All, "all", "All edges.")))
 
static cl::opt< std::string > ModuleSummaryDotFile ("module-summary-dot-file", cl::Hidden, cl::value_desc("filename"), cl::desc("File to emit dot graph of new summary into"))
 
cl::opt< boolScalePartialSampleProfileWorkingSetSize
 
cl::opt< unsignedMaxNumVTableAnnotations
 
cl::opt< boolMemProfReportHintedSizes
 
module summary analysis
 
module summary Module Summary Analysis
 
module summary Module Summary false
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "module-summary-analysis"

Definition at line 63 of file ModuleSummaryAnalysis.cpp.

Function Documentation

◆ addIntrinsicToSummary()

static void addIntrinsicToSummary ( const CallInst CI,
SetVector< GlobalValue::GUID, std::vector< GlobalValue::GUID > > &  TypeTests,
SetVector< FunctionSummary::VFuncId, std::vector< FunctionSummary::VFuncId > > &  TypeTestAssumeVCalls,
SetVector< FunctionSummary::VFuncId, std::vector< FunctionSummary::VFuncId > > &  TypeCheckedLoadVCalls,
SetVector< FunctionSummary::ConstVCall, std::vector< FunctionSummary::ConstVCall > > &  TypeTestAssumeConstVCalls,
SetVector< FunctionSummary::ConstVCall, std::vector< FunctionSummary::ConstVCall > > &  TypeCheckedLoadConstVCalls,
DominatorTree DT 
)
static

◆ addVCallToSet()

static void addVCallToSet ( DevirtCallSite  Call,
GlobalValue::GUID  Guid,
SetVector< FunctionSummary::VFuncId, std::vector< FunctionSummary::VFuncId > > &  VCalls,
SetVector< FunctionSummary::ConstVCall, std::vector< FunctionSummary::ConstVCall > > &  ConstVCalls 
)
static

Determine whether this call has all constant integer arguments (excluding "this") and summarize it to VCalls or ConstVCalls as appropriate.

Definition at line 178 of file ModuleSummaryAnalysis.cpp.

References llvm::drop_begin(), and llvm::Guid.

Referenced by addIntrinsicToSummary().

◆ computeAliasSummary()

static void computeAliasSummary ( ModuleSummaryIndex Index,
const GlobalAlias A,
DenseSet< GlobalValue::GUID > &  CantBePromoted 
)
static

◆ computeFunctionSummary()

static void computeFunctionSummary ( ModuleSummaryIndex Index,
const Module M,
const Function F,
BlockFrequencyInfo BFI,
ProfileSummaryInfo PSI,
DominatorTree DT,
bool  HasLocalsInUsedOrAsm,
DenseSet< GlobalValue::GUID > &  CantBePromoted,
bool  IsThinLTO,
std::function< const StackSafetyInfo *(const Function &F)>  GetSSICallback 
)
static

Definition at line 297 of file ModuleSummaryAnalysis.cpp.

References addIntrinsicToSummary(), assert(), llvm::SmallVectorTemplateCommon< T, typename >::back(), BBFreq, llvm::memprof::CallStack< NodeT, IteratorT >::beginAfterSharedPrefix(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::count(), llvm::SmallVectorBase< Size_T >::empty(), llvm::memprof::CallStack< NodeT, IteratorT >::empty(), llvm::memprof::CallStack< NodeT, IteratorT >::end(), F, findRefEdges(), llvm::ForceSummaryEdgesCold, llvm::FunctionSummary::FSHT_All, llvm::FunctionSummary::FSHT_None, llvm::BlockAddress::get(), getHotness(), llvm::memprof::getMIBAllocType(), llvm::memprof::getMIBStackNode(), llvm::memprof::getMIBTotalSize(), llvm::ProfileSummaryInfo::getProfileCount(), llvm::ICallPromotionAnalysis::getPromotionCandidatesForInstruction(), llvm::ProfileSummaryInfo::hasPartialSampleProfile(), I, llvm::SetVector< T, Vector, Set, N >::insert(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::insert(), llvm::SmallPtrSetImpl< PtrType >::insert(), isNonRenamableLocal(), isNonVolatileLoad(), isNonVolatileStore(), llvm::mayHaveMemprofSummary(), MemProfReportHintedSizes, mustBeUnreachableFunction(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SetVector< T, Vector, Set, N >::remove(), ScalePartialSampleProfileWorkingSetSize, llvm::SetVector< T, Vector, Set, N >::size(), llvm::MapVector< KeyT, ValueT, MapType, VectorType >::takeVector(), llvm::SetVector< T, Vector, Set, N >::takeVector(), and users.

Referenced by llvm::buildModuleSummaryIndex().

◆ computeVariableSummary()

static void computeVariableSummary ( ModuleSummaryIndex Index,
const GlobalVariable V,
DenseSet< GlobalValue::GUID > &  CantBePromoted,
const Module M,
SmallVectorImpl< MDNode * > &  Types 
)
static

◆ computeVTableFuncs()

static void computeVTableFuncs ( ModuleSummaryIndex Index,
const GlobalVariable V,
const Module M,
VTableFuncList VTableFuncs 
)
static

Definition at line 762 of file ModuleSummaryAnalysis.cpp.

References assert(), findFuncPointers(), and P.

Referenced by computeVariableSummary().

◆ findFuncPointers()

static void findFuncPointers ( const Constant I,
uint64_t  StartingOffset,
const Module M,
ModuleSummaryIndex Index,
VTableFuncList VTableFuncs,
const GlobalVariable OrigGV 
)
static

Find function pointers referenced within the given vtable initializer (or subset of an initializer) I.

The starting offset of I within the vtable initializer is StartingOffset. Any discovered function pointers are added to VTableFuncs along with their cumulative offset within the initializer.

Definition at line 690 of file ModuleSummaryAnalysis.cpp.

References A, assert(), llvm::CallingConv::C, DL, llvm::StructType::elements(), llvm::enumerate(), findFuncPointers(), llvm::StructLayout::getElementContainingOffset(), llvm::StructLayout::getElementOffset(), llvm::GlobalVariable::getInitializer(), llvm::Value::getType(), I, llvm::IsConstantOffsetFromGlobal(), LHS, llvm::Offset, and RHS.

Referenced by computeVTableFuncs(), and findFuncPointers().

◆ findRefEdges()

static bool findRefEdges ( ModuleSummaryIndex Index,
const User CurUser,
SetVector< ValueInfo, std::vector< ValueInfo > > &  RefEdges,
SmallPtrSet< const User *, 8 > &  Visited,
bool RefLocalLinkageIFunc 
)
static

◆ getHotness()

static CalleeInfo::HotnessType getHotness ( uint64_t  ProfileCount,
ProfileSummaryInfo PSI 
)
static

◆ INITIALIZE_PASS()

INITIALIZE_PASS ( ImmutableModuleSummaryIndexWrapperPass  ,
"module-summary-info"  ,
"Module summary info"  ,
false  ,
true   
)

Definition at line 1186 of file ModuleSummaryAnalysis.cpp.

References assert().

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( ModuleSummaryIndexWrapperPass  ,
"module-summary-analysis"  ,
"Module Summary Analysis"  ,
false  ,
true   
)

◆ isNonRenamableLocal()

static bool isNonRenamableLocal ( const GlobalValue GV)
static

◆ isNonVolatileLoad()

static bool isNonVolatileLoad ( const Instruction I)
static

Definition at line 271 of file ModuleSummaryAnalysis.cpp.

References I.

Referenced by computeFunctionSummary().

◆ isNonVolatileStore()

static bool isNonVolatileStore ( const Instruction I)
static

Definition at line 278 of file ModuleSummaryAnalysis.cpp.

References I.

Referenced by computeFunctionSummary().

◆ mustBeUnreachableFunction()

static bool mustBeUnreachableFunction ( const Function F)
static

Definition at line 290 of file ModuleSummaryAnalysis.cpp.

References assert(), and F.

Referenced by computeFunctionSummary().

◆ recordTypeIdCompatibleVtableReferences()

static void recordTypeIdCompatibleVtableReferences ( ModuleSummaryIndex Index,
const GlobalVariable V,
SmallVectorImpl< MDNode * > &  Types 
)
static

Record vtable definition V for each type metadata it references.

Definition at line 786 of file ModuleSummaryAnalysis.cpp.

References llvm::Offset.

Referenced by computeVariableSummary().

◆ setLiveRoot()

static void setLiveRoot ( ModuleSummaryIndex Index,
StringRef  Name 
)
static

Definition at line 878 of file ModuleSummaryAnalysis.cpp.

References llvm::GlobalValue::getGUID(), and Name.

Referenced by llvm::buildModuleSummaryIndex().

Variable Documentation

◆ analysis

module summary analysis

Definition at line 1123 of file ModuleSummaryAnalysis.cpp.

◆ Analysis

module summary Module Summary Analysis

Definition at line 1124 of file ModuleSummaryAnalysis.cpp.

◆ false

module summary Module Summary false

Definition at line 1124 of file ModuleSummaryAnalysis.cpp.

◆ FSEC

cl::opt< FunctionSummary::ForceSummaryHotnessType, true > FSEC("force-summary-edges-cold", cl::Hidden, cl::location(ForceSummaryEdgesCold), cl::desc("Force all edges in the function summary to cold"), cl::values(clEnumValN(FunctionSummary::FSHT_None, "none", "None."), clEnumValN(FunctionSummary::FSHT_AllNonCritical, "all-non-critical", "All non-critical edges."), clEnumValN(FunctionSummary::FSHT_All, "all", "All edges."))) ( "force-summary-edges-cold"  ,
cl::Hidden  ,
cl::location(ForceSummaryEdgesCold)  ,
cl::desc("Force all edges in the function summary to cold")  ,
cl::values(clEnumValN(FunctionSummary::FSHT_None, "none", "None."), clEnumValN(FunctionSummary::FSHT_AllNonCritical, "all-non-critical", "All non-critical edges."), clEnumValN(FunctionSummary::FSHT_All, "all", "All edges."))   
)
static

◆ MaxNumVTableAnnotations

cl::opt<unsigned> MaxNumVTableAnnotations
extern

Referenced by findRefEdges().

◆ MemProfReportHintedSizes

cl::opt<bool> MemProfReportHintedSizes
extern

Referenced by computeFunctionSummary().

◆ ModuleSummaryDotFile

cl::opt< std::string > ModuleSummaryDotFile("module-summary-dot-file", cl::Hidden, cl::value_desc("filename"), cl::desc("File to emit dot graph of new summary into")) ( "module-summary-dot-file"  ,
cl::Hidden  ,
cl::value_desc("filename")  ,
cl::desc("File to emit dot graph of new summary into")   
)
static

◆ ScalePartialSampleProfileWorkingSetSize

cl::opt<bool> ScalePartialSampleProfileWorkingSetSize
extern

Referenced by computeFunctionSummary().