LLVM  8.0.1
Macros | Functions | Variables
FunctionImport.cpp File Reference
#include "llvm/Transforms/IPO/FunctionImport.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/IR/AutoUpgrade.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/GlobalObject.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ModuleSummaryIndex.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/Linker/IRMover.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/Debug.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/IPO/Internalize.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
#include "llvm/Transforms/Utils/ValueMapper.h"
#include <cassert>
#include <memory>
#include <set>
#include <string>
#include <system_error>
#include <tuple>
#include <utility>
Include dependency graph for FunctionImport.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "function-import"
 

Functions

 STATISTIC (NumImportedFunctionsThinLink, "Number of functions thin link decided to import")
 
 STATISTIC (NumImportedHotFunctionsThinLink, "Number of hot functions thin link decided to import")
 
 STATISTIC (NumImportedCriticalFunctionsThinLink, "Number of critical functions thin link decided to import")
 
 STATISTIC (NumImportedGlobalVarsThinLink, "Number of global variables thin link decided to import")
 
 STATISTIC (NumImportedFunctions, "Number of functions imported in backend")
 
 STATISTIC (NumImportedGlobalVars, "Number of global variables imported in backend")
 
 STATISTIC (NumImportedModules, "Number of modules imported from")
 
 STATISTIC (NumDeadSymbols, "Number of dead stripped symbols in index")
 
 STATISTIC (NumLiveSymbols, "Number of live symbols in index")
 
static std::unique_ptr< ModuleloadFile (const std::string &FileName, LLVMContext &Context)
 
static const GlobalValueSummaryselectCallee (const ModuleSummaryIndex &Index, ArrayRef< std::unique_ptr< GlobalValueSummary >> CalleeSummaryList, unsigned Threshold, StringRef CallerModulePath, FunctionImporter::ImportFailureReason &Reason, GlobalValue::GUID GUID)
 Given a list of possible callee implementation for a call site, select one that fits the Threshold. More...
 
static ValueInfo updateValueInfoForIndirectCalls (const ModuleSummaryIndex &Index, ValueInfo VI)
 
static void computeImportForReferencedGlobals (const FunctionSummary &Summary, const GVSummaryMapTy &DefinedGVSummaries, FunctionImporter::ImportMapTy &ImportList, StringMap< FunctionImporter::ExportSetTy > *ExportLists)
 
static const chargetFailureName (FunctionImporter::ImportFailureReason Reason)
 
static void computeImportForFunction (const FunctionSummary &Summary, const ModuleSummaryIndex &Index, const unsigned Threshold, const GVSummaryMapTy &DefinedGVSummaries, SmallVectorImpl< EdgeInfo > &Worklist, FunctionImporter::ImportMapTy &ImportList, StringMap< FunctionImporter::ExportSetTy > *ExportLists, FunctionImporter::ImportThresholdsTy &ImportThresholds)
 Compute the list of functions to import for a given caller. More...
 
static void ComputeImportForModule (const GVSummaryMapTy &DefinedGVSummaries, const ModuleSummaryIndex &Index, StringRef ModName, FunctionImporter::ImportMapTy &ImportList, StringMap< FunctionImporter::ExportSetTy > *ExportLists=nullptr)
 Given the list of globals defined in a module, compute the list of imports as well as the list of "exports", i.e. More...
 
static bool isGlobalVarSummary (const ModuleSummaryIndex &Index, GlobalValue::GUID G)
 
static GlobalValue::GUID getGUID (GlobalValue::GUID G)
 
template<class T >
static unsigned numGlobalVarSummaries (const ModuleSummaryIndex &Index, T &Cont)
 
static void dumpImportListForModule (const ModuleSummaryIndex &Index, StringRef ModulePath, FunctionImporter::ImportMapTy &ImportList)
 
static FunctionreplaceAliasWithAliasee (Module *SrcModule, GlobalAlias *GA)
 Make alias a clone of its aliasee. More...
 
static void internalizeImmutableGVs (Module &M)
 
static bool doImportingForModule (Module &M)
 
 INITIALIZE_PASS (FunctionImportLegacyPass, "function-import", "Summary Based Function Import", false, false) namespace llvm
 

Variables

static cl::opt< unsignedImportInstrLimit ("import-instr-limit", cl::init(100), cl::Hidden, cl::value_desc("N"), cl::desc("Only import functions with less than N instructions"))
 Limit on instruction count of imported functions. More...
 
static cl::opt< int > ImportCutoff ("import-cutoff", cl::init(-1), cl::Hidden, cl::value_desc("N"), cl::desc("Only import first N functions if N>=0 (default -1)"))
 
static cl::opt< float > ImportInstrFactor ("import-instr-evolution-factor", cl::init(0.7), cl::Hidden, cl::value_desc("x"), cl::desc("As we import functions, multiply the " "`import-instr-limit` threshold by this factor " "before processing newly imported functions"))
 
static cl::opt< float > ImportHotInstrFactor ("import-hot-evolution-factor", cl::init(1.0), cl::Hidden, cl::value_desc("x"), cl::desc("As we import functions called from hot callsite, multiply the " "`import-instr-limit` threshold by this factor " "before processing newly imported functions"))
 
static cl::opt< float > ImportHotMultiplier ("import-hot-multiplier", cl::init(10.0), cl::Hidden, cl::value_desc("x"), cl::desc("Multiply the `import-instr-limit` threshold for hot callsites"))
 
static cl::opt< float > ImportCriticalMultiplier ("import-critical-multiplier", cl::init(100.0), cl::Hidden, cl::value_desc("x"), cl::desc("Multiply the `import-instr-limit` threshold for critical callsites"))
 
static cl::opt< float > ImportColdMultiplier ("import-cold-multiplier", cl::init(0), cl::Hidden, cl::value_desc("N"), cl::desc("Multiply the `import-instr-limit` threshold for cold callsites"))
 
static cl::opt< boolPrintImports ("print-imports", cl::init(false), cl::Hidden, cl::desc("Print imported functions"))
 
static cl::opt< boolPrintImportFailures ("print-import-failures", cl::init(false), cl::Hidden, cl::desc("Print information for functions rejected for importing"))
 
static cl::opt< boolComputeDead ("compute-dead", cl::init(true), cl::Hidden, cl::desc("Compute dead symbols"))
 
static cl::opt< boolEnableImportMetadata ("enable-import-metadata", cl::init(true), cl::Hidden, cl::desc("Enable import metadata like 'thinlto_src_module'"))
 
static cl::opt< std::string > SummaryFile ("summary-file", cl::desc("The summary file to use for function importing."))
 Summary file to use for function importing when using -function-import from the command line. More...
 
static cl::opt< boolImportAllIndex ("import-all-index", cl::desc("Import all external functions in index."))
 Used when testing importing from distributed indexes via opt. More...
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "function-import"

Definition at line 61 of file FunctionImport.cpp.

Function Documentation

◆ computeImportForFunction()

static void computeImportForFunction ( const FunctionSummary Summary,
const ModuleSummaryIndex Index,
const unsigned  Threshold,
const GVSummaryMapTy DefinedGVSummaries,
SmallVectorImpl< EdgeInfo > &  Worklist,
FunctionImporter::ImportMapTy ImportList,
StringMap< FunctionImporter::ExportSetTy > *  ExportLists,
FunctionImporter::ImportThresholdsTy ImportThresholds 
)
static

◆ ComputeImportForModule()

static void ComputeImportForModule ( const GVSummaryMapTy DefinedGVSummaries,
const ModuleSummaryIndex Index,
StringRef  ModName,
FunctionImporter::ImportMapTy ImportList,
StringMap< FunctionImporter::ExportSetTy > *  ExportLists = nullptr 
)
static

Given the list of globals defined in a module, compute the list of imports as well as the list of "exports", i.e.

the list of symbols referenced from another module (that may require promotion).

Definition at line 526 of file FunctionImport.cpp.

References assert(), computeImportForFunction(), llvm::dbgs(), llvm::dyn_cast(), llvm::SmallVectorBase::empty(), getFailureName(), llvm::getHotnessName(), llvm::ModuleSummaryIndex::getValueInfo(), I, ImportInstrLimit, llvm::FunctionSummary::instCount(), llvm::ModuleSummaryIndex::isGlobalValueLive(), LLVM_DEBUG, llvm::SmallVectorImpl< T >::pop_back_val(), PrintImportFailures, Threshold, and VI.

Referenced by llvm::ComputeCrossModuleImport(), and llvm::ComputeCrossModuleImportForModule().

◆ computeImportForReferencedGlobals()

static void computeImportForReferencedGlobals ( const FunctionSummary Summary,
const GVSummaryMapTy DefinedGVSummaries,
FunctionImporter::ImportMapTy ImportList,
StringMap< FunctionImporter::ExportSetTy > *  ExportLists 
)
static

◆ doImportingForModule()

static bool doImportingForModule ( Module M)
static

◆ dumpImportListForModule()

static void dumpImportListForModule ( const ModuleSummaryIndex Index,
StringRef  ModulePath,
FunctionImporter::ImportMapTy ImportList 
)
static

◆ getFailureName()

static const char* getFailureName ( FunctionImporter::ImportFailureReason  Reason)
static

Definition at line 323 of file FunctionImport.cpp.

References llvm::lltok::GlobalVar, llvm_unreachable, and llvm::None.

Referenced by ComputeImportForModule().

◆ getGUID()

static GlobalValue::GUID getGUID ( GlobalValue::GUID  G)
static

◆ INITIALIZE_PASS()

INITIALIZE_PASS ( FunctionImportLegacyPass  ,
"function-import"  ,
"Summary Based Function Import"  ,
false  ,
false   
)

Definition at line 1298 of file FunctionImport.cpp.

References llvm::createFunctionImportPass().

◆ internalizeImmutableGVs()

static void internalizeImmutableGVs ( Module M)
static

◆ isGlobalVarSummary()

static bool isGlobalVarSummary ( const ModuleSummaryIndex Index,
GlobalValue::GUID  G 
)
static

◆ loadFile()

static std::unique_ptr<Module> loadFile ( const std::string &  FileName,
LLVMContext Context 
)
static

Definition at line 149 of file FunctionImport.cpp.

Referenced by llvm::createBlockExtractorPass(), and doImportingForModule().

◆ numGlobalVarSummaries()

template<class T >
static unsigned numGlobalVarSummaries ( const ModuleSummaryIndex Index,
T Cont 
)
static

Definition at line 608 of file FunctionImport.cpp.

References getGUID(), and isGlobalVarSummary().

Referenced by llvm::ComputeCrossModuleImport(), and dumpImportListForModule().

◆ replaceAliasWithAliasee()

static Function* replaceAliasWithAliasee ( Module SrcModule,
GlobalAlias GA 
)
static

◆ selectCallee()

static const GlobalValueSummary* selectCallee ( const ModuleSummaryIndex Index,
ArrayRef< std::unique_ptr< GlobalValueSummary >>  CalleeSummaryList,
unsigned  Threshold,
StringRef  CallerModulePath,
FunctionImporter::ImportFailureReason Reason,
GlobalValue::GUID  GUID 
)
static

Given a list of possible callee implementation for a call site, select one that fits the Threshold.

FIXME: select "best" instead of first that fits. But what is "best"?

  • The smallest: more likely to be inlined.
  • The one with the least outgoing edges (already well optimized).
  • One from a module already being imported from in order to reduce the number of source modules parsed/linked.
  • One that has PGO data attached.
  • [insert you fancy metric here]

Definition at line 177 of file FunctionImport.cpp.

References llvm::find_if(), llvm::lltok::GlobalVar, llvm::GlobalValueSummary::GlobalVarKind, llvm::ModuleSummaryIndex::isGlobalValueLive(), llvm::GlobalValue::isInterposableLinkage(), llvm::GlobalValue::isLocalLinkage(), llvm::None, and Threshold.

Referenced by computeImportForFunction().

◆ STATISTIC() [1/9]

STATISTIC ( NumImportedFunctionsThinLink  ,
"Number of functions thin link decided to import"   
)

◆ STATISTIC() [2/9]

STATISTIC ( NumImportedHotFunctionsThinLink  ,
"Number of hot functions thin link decided to import"   
)

◆ STATISTIC() [3/9]

STATISTIC ( NumImportedCriticalFunctionsThinLink  ,
"Number of critical functions thin link decided to import"   
)

◆ STATISTIC() [4/9]

STATISTIC ( NumImportedGlobalVarsThinLink  ,
"Number of global variables thin link decided to import"   
)

◆ STATISTIC() [5/9]

STATISTIC ( NumImportedFunctions  ,
"Number of functions imported in backend"   
)

◆ STATISTIC() [6/9]

STATISTIC ( NumImportedGlobalVars  ,
"Number of global variables imported in backend"   
)

◆ STATISTIC() [7/9]

STATISTIC ( NumImportedModules  ,
"Number of modules imported from"   
)

◆ STATISTIC() [8/9]

STATISTIC ( NumDeadSymbols  ,
"Number of dead stripped symbols in index"   
)

◆ STATISTIC() [9/9]

STATISTIC ( NumLiveSymbols  ,
"Number of live symbols in index"   
)

◆ updateValueInfoForIndirectCalls()

static ValueInfo updateValueInfoForIndirectCalls ( const ModuleSummaryIndex Index,
ValueInfo  VI 
)
static

Variable Documentation

◆ ComputeDead

cl::opt<bool> ComputeDead("compute-dead", cl::init(true), cl::Hidden, cl::desc("Compute dead symbols"))
static

◆ EnableImportMetadata

cl::opt<bool> EnableImportMetadata("enable-import-metadata", cl::init( true), cl::Hidden, cl::desc("Enable import metadata like 'thinlto_src_module'"))
static

◆ ImportAllIndex

cl::opt<bool> ImportAllIndex("import-all-index", cl::desc("Import all external functions in index."))
static

Used when testing importing from distributed indexes via opt.

Referenced by doImportingForModule().

◆ ImportColdMultiplier

cl::opt<float> ImportColdMultiplier("import-cold-multiplier", cl::init(0), cl::Hidden, cl::value_desc("N"), cl::desc("Multiply the `import-instr-limit` threshold for cold callsites"))
static

◆ ImportCriticalMultiplier

cl::opt<float> ImportCriticalMultiplier("import-critical-multiplier", cl::init(100.0), cl::Hidden, cl::value_desc("x"), cl::desc( "Multiply the `import-instr-limit` threshold for critical callsites"))
static

◆ ImportCutoff

cl::opt<int> ImportCutoff("import-cutoff", cl::init(-1), cl::Hidden, cl::value_desc("N"), cl::desc("Only import first N functions if N>=0 (default -1)"))
static

◆ ImportHotInstrFactor

cl::opt<float> ImportHotInstrFactor("import-hot-evolution-factor", cl::init(1.0), cl::Hidden, cl::value_desc("x"), cl::desc("As we import functions called from hot callsite, multiply the " "`import-instr-limit` threshold by this factor " "before processing newly imported functions"))
static

◆ ImportHotMultiplier

cl::opt<float> ImportHotMultiplier("import-hot-multiplier", cl::init(10.0), cl::Hidden, cl::value_desc("x"), cl::desc("Multiply the `import-instr-limit` threshold for hot callsites"))
static

◆ ImportInstrFactor

cl::opt<float> ImportInstrFactor("import-instr-evolution-factor", cl::init(0.7), cl::Hidden, cl::value_desc("x"), cl::desc("As we import functions, multiply the " "`import-instr-limit` threshold by this factor " "before processing newly imported functions"))
static

◆ ImportInstrLimit

cl::opt<unsigned> ImportInstrLimit("import-instr-limit", cl::init(100), cl::Hidden, cl::value_desc("N"), cl::desc("Only import functions with less than N instructions"))
static

Limit on instruction count of imported functions.

Referenced by ComputeImportForModule().

◆ PrintImportFailures

cl::opt<bool> PrintImportFailures("print-import-failures", cl::init(false), cl::Hidden, cl::desc("Print information for functions rejected for importing"))
static

◆ PrintImports

cl::opt<bool> PrintImports("print-imports", cl::init(false), cl::Hidden, cl::desc("Print imported functions"))
static

◆ SummaryFile

cl::opt<std::string> SummaryFile("summary-file", cl::desc("The summary file to use for function importing."))
static

Summary file to use for function importing when using -function-import from the command line.

Referenced by doImportingForModule().