forked from OSchip/llvm-project
[ThinLTO] Support for specifying function index from pass manager
Summary: Add a field on the PassManagerBuilder that clang or gold can use to pass down a pointer to the function index in memory to use for importing when the ThinLTO backend is triggered. Add support to supply this to the function import pass. Reviewers: joker.eph, dexonsmith Subscribers: davidxl, llvm-commits, joker.eph Differential Revision: http://reviews.llvm.org/D15024 llvm-svn: 254926
This commit is contained in:
parent
f9bdb872bd
commit
5fcbdb717c
|
@ -86,6 +86,7 @@ namespace {
|
||||||
(void) llvm::createDomViewerPass();
|
(void) llvm::createDomViewerPass();
|
||||||
(void) llvm::createGCOVProfilerPass();
|
(void) llvm::createGCOVProfilerPass();
|
||||||
(void) llvm::createInstrProfilingPass();
|
(void) llvm::createInstrProfilingPass();
|
||||||
|
(void) llvm::createFunctionImportPass();
|
||||||
(void) llvm::createFunctionInliningPass();
|
(void) llvm::createFunctionInliningPass();
|
||||||
(void) llvm::createAlwaysInlinerPass();
|
(void) llvm::createAlwaysInlinerPass();
|
||||||
(void) llvm::createGlobalDCEPass();
|
(void) llvm::createGlobalDCEPass();
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
|
class FunctionInfoIndex;
|
||||||
class ModulePass;
|
class ModulePass;
|
||||||
class Pass;
|
class Pass;
|
||||||
class Function;
|
class Function;
|
||||||
|
@ -85,6 +86,10 @@ ModulePass *createEliminateAvailableExternallyPass();
|
||||||
ModulePass *createGVExtractionPass(std::vector<GlobalValue*>& GVs, bool
|
ModulePass *createGVExtractionPass(std::vector<GlobalValue*>& GVs, bool
|
||||||
deleteFn = false);
|
deleteFn = false);
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
/// This pass performs iterative function importing from other modules.
|
||||||
|
ModulePass *createFunctionImportPass(FunctionInfoIndex *Index = nullptr);
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
/// createFunctionInliningPass - Return a new pass object that uses a heuristic
|
/// createFunctionInliningPass - Return a new pass object that uses a heuristic
|
||||||
/// to inline direct function calls to small functions.
|
/// to inline direct function calls to small functions.
|
||||||
|
|
|
@ -15,9 +15,11 @@
|
||||||
#ifndef LLVM_TRANSFORMS_IPO_PASSMANAGERBUILDER_H
|
#ifndef LLVM_TRANSFORMS_IPO_PASSMANAGERBUILDER_H
|
||||||
#define LLVM_TRANSFORMS_IPO_PASSMANAGERBUILDER_H
|
#define LLVM_TRANSFORMS_IPO_PASSMANAGERBUILDER_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
class FunctionInfoIndex;
|
||||||
class Pass;
|
class Pass;
|
||||||
class TargetLibraryInfoImpl;
|
class TargetLibraryInfoImpl;
|
||||||
class TargetMachine;
|
class TargetMachine;
|
||||||
|
@ -114,6 +116,9 @@ public:
|
||||||
/// added to the per-module passes.
|
/// added to the per-module passes.
|
||||||
Pass *Inliner;
|
Pass *Inliner;
|
||||||
|
|
||||||
|
/// The function summary index to use for function importing.
|
||||||
|
FunctionInfoIndex *FunctionIndex;
|
||||||
|
|
||||||
bool DisableTailCalls;
|
bool DisableTailCalls;
|
||||||
bool DisableUnitAtATime;
|
bool DisableUnitAtATime;
|
||||||
bool DisableUnrollLoops;
|
bool DisableUnrollLoops;
|
||||||
|
|
|
@ -256,23 +256,38 @@ getFunctionIndexForFile(StringRef Path, std::string &Error,
|
||||||
|
|
||||||
/// Pass that performs cross-module function import provided a summary file.
|
/// Pass that performs cross-module function import provided a summary file.
|
||||||
class FunctionImportPass : public ModulePass {
|
class FunctionImportPass : public ModulePass {
|
||||||
|
/// Optional function summary index to use for importing, otherwise
|
||||||
|
/// the summary-file option must be specified.
|
||||||
|
FunctionInfoIndex *Index;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Pass identification, replacement for typeid
|
/// Pass identification, replacement for typeid
|
||||||
static char ID;
|
static char ID;
|
||||||
|
|
||||||
explicit FunctionImportPass() : ModulePass(ID) {}
|
/// Specify pass name for debug output
|
||||||
|
const char *getPassName() const override {
|
||||||
|
return "Function Importing";
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit FunctionImportPass(FunctionInfoIndex *Index = nullptr)
|
||||||
|
: ModulePass(ID), Index(Index) {}
|
||||||
|
|
||||||
bool runOnModule(Module &M) override {
|
bool runOnModule(Module &M) override {
|
||||||
if (SummaryFile.empty()) {
|
if (SummaryFile.empty() && !Index)
|
||||||
report_fatal_error("error: -function-import requires -summary-file\n");
|
report_fatal_error("error: -function-import requires -summary-file or "
|
||||||
}
|
"file from frontend\n");
|
||||||
std::string Error;
|
std::unique_ptr<FunctionInfoIndex> IndexPtr;
|
||||||
std::unique_ptr<FunctionInfoIndex> Index =
|
if (!SummaryFile.empty()) {
|
||||||
getFunctionIndexForFile(SummaryFile, Error, diagnosticHandler);
|
if (Index)
|
||||||
if (!Index) {
|
report_fatal_error("error: -summary-file and index from frontend\n");
|
||||||
errs() << "Error loading file '" << SummaryFile << "': " << Error << "\n";
|
std::string Error;
|
||||||
return false;
|
IndexPtr = getFunctionIndexForFile(SummaryFile, Error, diagnosticHandler);
|
||||||
|
if (!IndexPtr) {
|
||||||
|
errs() << "Error loading file '" << SummaryFile << "': " << Error
|
||||||
|
<< "\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Index = IndexPtr.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform the import now.
|
// Perform the import now.
|
||||||
|
@ -293,5 +308,7 @@ INITIALIZE_PASS_END(FunctionImportPass, "function-import",
|
||||||
"Summary Based Function Import", false, false)
|
"Summary Based Function Import", false, false)
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
Pass *createFunctionImportPass() { return new FunctionImportPass(); }
|
Pass *createFunctionImportPass(FunctionInfoIndex *Index = nullptr) {
|
||||||
|
return new FunctionImportPass(Index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include "llvm/Analysis/Passes.h"
|
#include "llvm/Analysis/Passes.h"
|
||||||
#include "llvm/IR/DataLayout.h"
|
#include "llvm/IR/DataLayout.h"
|
||||||
|
#include "llvm/IR/FunctionInfo.h"
|
||||||
#include "llvm/IR/Verifier.h"
|
#include "llvm/IR/Verifier.h"
|
||||||
#include "llvm/IR/LegacyPassManager.h"
|
#include "llvm/IR/LegacyPassManager.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
|
@ -108,6 +109,7 @@ PassManagerBuilder::PassManagerBuilder() {
|
||||||
SizeLevel = 0;
|
SizeLevel = 0;
|
||||||
LibraryInfo = nullptr;
|
LibraryInfo = nullptr;
|
||||||
Inliner = nullptr;
|
Inliner = nullptr;
|
||||||
|
FunctionIndex = nullptr;
|
||||||
DisableUnitAtATime = false;
|
DisableUnitAtATime = false;
|
||||||
DisableUnrollLoops = false;
|
DisableUnrollLoops = false;
|
||||||
BBVectorize = RunBBVectorization;
|
BBVectorize = RunBBVectorization;
|
||||||
|
@ -476,6 +478,9 @@ void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
|
||||||
// Provide AliasAnalysis services for optimizations.
|
// Provide AliasAnalysis services for optimizations.
|
||||||
addInitialAliasAnalysisPasses(PM);
|
addInitialAliasAnalysisPasses(PM);
|
||||||
|
|
||||||
|
if (FunctionIndex)
|
||||||
|
PM.add(createFunctionImportPass(FunctionIndex));
|
||||||
|
|
||||||
// Propagate constants at call sites into the functions they call. This
|
// Propagate constants at call sites into the functions they call. This
|
||||||
// opens opportunities for globalopt (and inlining) by substituting function
|
// opens opportunities for globalopt (and inlining) by substituting function
|
||||||
// pointers passed as arguments to direct uses of functions.
|
// pointers passed as arguments to direct uses of functions.
|
||||||
|
|
Loading…
Reference in New Issue