diff options
author | Teresa Johnson <tejohnson@google.com> | 2016-07-18 21:22:24 +0000 |
---|---|---|
committer | Teresa Johnson <tejohnson@google.com> | 2016-07-18 21:22:24 +0000 |
commit | 2124157102577f323b7d3cec949bc9a854faab1f (patch) | |
tree | 889e69d0a900b72265bfe365d8630ea0f68d0e73 /llvm/lib/Transforms/IPO/FunctionImport.cpp | |
parent | f9afff71a2c79f4f6fd9f05871dc9ca5be5a70c3 (diff) | |
download | bcm5719-llvm-2124157102577f323b7d3cec949bc9a854faab1f.tar.gz bcm5719-llvm-2124157102577f323b7d3cec949bc9a854faab1f.zip |
[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
Diffstat (limited to 'llvm/lib/Transforms/IPO/FunctionImport.cpp')
-rw-r--r-- | llvm/lib/Transforms/IPO/FunctionImport.cpp | 99 |
1 files changed, 54 insertions, 45 deletions
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp index c9d075e7632..25ef17cefb8 100644 --- a/llvm/lib/Transforms/IPO/FunctionImport.cpp +++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -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); } } |