forked from OSchip/llvm-project
[PM] Port FunctionImport Pass to new PM
Summary: Port FunctionImport Pass to new PM. Reviewers: mehdi_amini, davide Subscribers: davidxl, llvm-commits Differential Revision: https://reviews.llvm.org/D22475 llvm-svn: 275916
This commit is contained in:
parent
f9afff71a2
commit
2124157102
|
@ -130,7 +130,7 @@ void initializeFloat2IntLegacyPassPass(PassRegistry&);
|
|||
void initializeForceFunctionAttrsLegacyPassPass(PassRegistry&);
|
||||
void initializeForwardControlFlowIntegrityPass(PassRegistry&);
|
||||
void initializeFuncletLayoutPass(PassRegistry &);
|
||||
void initializeFunctionImportPassPass(PassRegistry &);
|
||||
void initializeFunctionImportLegacyPassPass(PassRegistry &);
|
||||
void initializeGCMachineCodeAnalysisPass(PassRegistry&);
|
||||
void initializeGCModuleInfoPass(PassRegistry&);
|
||||
void initializeGCOVProfilerLegacyPassPass(PassRegistry&);
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/IR/GlobalValue.h"
|
||||
#include "llvm/IR/ModuleSummaryIndex.h"
|
||||
#include "llvm/IR/PassManager.h"
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
|
@ -63,6 +64,17 @@ private:
|
|||
std::function<std::unique_ptr<Module>(StringRef Identifier)> ModuleLoader;
|
||||
};
|
||||
|
||||
/// The function importing pass
|
||||
class FunctionImportPass : public PassInfoMixin<FunctionImportPass> {
|
||||
public:
|
||||
FunctionImportPass(const ModuleSummaryIndex *Index = nullptr)
|
||||
: Index(Index) {}
|
||||
PreservedAnalyses run(Module &M, AnalysisManager<Module> &AM);
|
||||
|
||||
private:
|
||||
const ModuleSummaryIndex *Index;
|
||||
};
|
||||
|
||||
/// Compute all the imports and exports for every module in the Index.
|
||||
///
|
||||
/// \p ModuleToDefinedGVSummaries contains for each Module a map
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
#include "llvm/Transforms/IPO/ElimAvailExtern.h"
|
||||
#include "llvm/Transforms/IPO/ForceFunctionAttrs.h"
|
||||
#include "llvm/Transforms/IPO/FunctionAttrs.h"
|
||||
#include "llvm/Transforms/IPO/FunctionImport.h"
|
||||
#include "llvm/Transforms/IPO/GlobalDCE.h"
|
||||
#include "llvm/Transforms/IPO/GlobalOpt.h"
|
||||
#include "llvm/Transforms/IPO/InferFunctionAttrs.h"
|
||||
|
|
|
@ -42,6 +42,7 @@ MODULE_PASS("cross-dso-cfi", CrossDSOCFIPass())
|
|||
MODULE_PASS("deadargelim", DeadArgumentEliminationPass())
|
||||
MODULE_PASS("elim-avail-extern", EliminateAvailableExternallyPass())
|
||||
MODULE_PASS("forceattrs", ForceFunctionAttrsPass())
|
||||
MODULE_PASS("function-import", FunctionImportPass())
|
||||
MODULE_PASS("globaldce", GlobalDCEPass())
|
||||
MODULE_PASS("globalopt", GlobalOptPass())
|
||||
MODULE_PASS("inferattrs", InferFunctionAttrsPass())
|
||||
|
|
|
@ -719,9 +719,48 @@ static std::unique_ptr<ModuleSummaryIndex> getModuleSummaryIndexForFile(
|
|||
return (*ObjOrErr)->takeIndex();
|
||||
}
|
||||
|
||||
static bool doImportingForModule(Module &M, const ModuleSummaryIndex *Index) {
|
||||
if (SummaryFile.empty() && !Index)
|
||||
report_fatal_error("error: -function-import requires -summary-file or "
|
||||
"file from frontend\n");
|
||||
std::unique_ptr<ModuleSummaryIndex> IndexPtr;
|
||||
if (!SummaryFile.empty()) {
|
||||
if (Index)
|
||||
report_fatal_error("error: -summary-file and index from frontend\n");
|
||||
std::string Error;
|
||||
IndexPtr =
|
||||
getModuleSummaryIndexForFile(SummaryFile, Error, diagnosticHandler);
|
||||
if (!IndexPtr) {
|
||||
errs() << "Error loading file '" << SummaryFile << "': " << Error << "\n";
|
||||
return false;
|
||||
}
|
||||
Index = IndexPtr.get();
|
||||
}
|
||||
|
||||
// First step is collecting the import list.
|
||||
FunctionImporter::ImportMapTy ImportList;
|
||||
ComputeCrossModuleImportForModule(M.getModuleIdentifier(), *Index,
|
||||
ImportList);
|
||||
|
||||
// Next we need to promote to global scope and rename any local values that
|
||||
// are potentially exported to other modules.
|
||||
if (renameModuleForThinLTO(M, *Index, nullptr)) {
|
||||
errs() << "Error renaming module\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Perform the import now.
|
||||
auto ModuleLoader = [&M](StringRef Identifier) {
|
||||
return loadFile(Identifier, M.getContext());
|
||||
};
|
||||
FunctionImporter Importer(*Index, ModuleLoader);
|
||||
return Importer.importFunctions(M, ImportList,
|
||||
!DontForceImportReferencedDiscardableSymbols);
|
||||
}
|
||||
|
||||
namespace {
|
||||
/// Pass that performs cross-module function import provided a summary file.
|
||||
class FunctionImportPass : public ModulePass {
|
||||
class FunctionImportLegacyPass : public ModulePass {
|
||||
/// Optional module summary index to use for importing, otherwise
|
||||
/// the summary-file option must be specified.
|
||||
const ModuleSummaryIndex *Index;
|
||||
|
@ -733,62 +772,32 @@ public:
|
|||
/// Specify pass name for debug output
|
||||
const char *getPassName() const override { return "Function Importing"; }
|
||||
|
||||
explicit FunctionImportPass(const ModuleSummaryIndex *Index = nullptr)
|
||||
explicit FunctionImportLegacyPass(const ModuleSummaryIndex *Index = nullptr)
|
||||
: ModulePass(ID), Index(Index) {}
|
||||
|
||||
bool runOnModule(Module &M) override {
|
||||
if (skipModule(M))
|
||||
return false;
|
||||
|
||||
if (SummaryFile.empty() && !Index)
|
||||
report_fatal_error("error: -function-import requires -summary-file or "
|
||||
"file from frontend\n");
|
||||
std::unique_ptr<ModuleSummaryIndex> IndexPtr;
|
||||
if (!SummaryFile.empty()) {
|
||||
if (Index)
|
||||
report_fatal_error("error: -summary-file and index from frontend\n");
|
||||
std::string Error;
|
||||
IndexPtr =
|
||||
getModuleSummaryIndexForFile(SummaryFile, Error, diagnosticHandler);
|
||||
if (!IndexPtr) {
|
||||
errs() << "Error loading file '" << SummaryFile << "': " << Error
|
||||
<< "\n";
|
||||
return false;
|
||||
}
|
||||
Index = IndexPtr.get();
|
||||
}
|
||||
|
||||
// First step is collecting the import list.
|
||||
FunctionImporter::ImportMapTy ImportList;
|
||||
ComputeCrossModuleImportForModule(M.getModuleIdentifier(), *Index,
|
||||
ImportList);
|
||||
|
||||
// Next we need to promote to global scope and rename any local values that
|
||||
// are potentially exported to other modules.
|
||||
if (renameModuleForThinLTO(M, *Index, nullptr)) {
|
||||
errs() << "Error renaming module\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Perform the import now.
|
||||
auto ModuleLoader = [&M](StringRef Identifier) {
|
||||
return loadFile(Identifier, M.getContext());
|
||||
};
|
||||
FunctionImporter Importer(*Index, ModuleLoader);
|
||||
return Importer.importFunctions(
|
||||
M, ImportList, !DontForceImportReferencedDiscardableSymbols);
|
||||
return doImportingForModule(M, Index);
|
||||
}
|
||||
};
|
||||
} // anonymous namespace
|
||||
|
||||
char FunctionImportPass::ID = 0;
|
||||
INITIALIZE_PASS_BEGIN(FunctionImportPass, "function-import",
|
||||
"Summary Based Function Import", false, false)
|
||||
INITIALIZE_PASS_END(FunctionImportPass, "function-import",
|
||||
"Summary Based Function Import", false, false)
|
||||
PreservedAnalyses FunctionImportPass::run(Module &M,
|
||||
AnalysisManager<Module> &AM) {
|
||||
if (!doImportingForModule(M, Index))
|
||||
return PreservedAnalyses::all();
|
||||
|
||||
return PreservedAnalyses::none();
|
||||
}
|
||||
|
||||
char FunctionImportLegacyPass::ID = 0;
|
||||
INITIALIZE_PASS(FunctionImportLegacyPass, "function-import",
|
||||
"Summary Based Function Import", false, false)
|
||||
|
||||
namespace llvm {
|
||||
Pass *createFunctionImportPass(const ModuleSummaryIndex *Index = nullptr) {
|
||||
return new FunctionImportPass(Index);
|
||||
return new FunctionImportLegacyPass(Index);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ void llvm::initializeIPO(PassRegistry &Registry) {
|
|||
initializeBarrierNoopPass(Registry);
|
||||
initializeEliminateAvailableExternallyLegacyPassPass(Registry);
|
||||
initializeSampleProfileLoaderLegacyPassPass(Registry);
|
||||
initializeFunctionImportPassPass(Registry);
|
||||
initializeFunctionImportLegacyPassPass(Registry);
|
||||
initializeWholeProgramDevirtPass(Registry);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
; Do the import now
|
||||
; RUN: opt -disable-force-link-odr -function-import -stats -print-imports -enable-import-metadata -summary-file %t3.thinlto.bc %t.bc -S 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=INSTLIMDEF
|
||||
; Try again with new pass manager
|
||||
; RUN: opt -disable-force-link-odr -passes='function-import' -stats -print-imports -enable-import-metadata -summary-file %t3.thinlto.bc %t.bc -S 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=INSTLIMDEF
|
||||
; "-stats" requires +Asserts.
|
||||
; REQUIRES: asserts
|
||||
|
||||
|
|
Loading…
Reference in New Issue