llvm.org GIT mirror llvm / 5d0d98f
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254926 91177308-0d34-0410-b5e6-96231b3b80d8 Teresa Johnson 3 years ago
5 changed file(s) with 45 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
8585 (void) llvm::createDomViewerPass();
8686 (void) llvm::createGCOVProfilerPass();
8787 (void) llvm::createInstrProfilingPass();
88 (void) llvm::createFunctionImportPass();
8889 (void) llvm::createFunctionInliningPass();
8990 (void) llvm::createAlwaysInlinerPass();
9091 (void) llvm::createGlobalDCEPass();
1414 #ifndef LLVM_TRANSFORMS_IPO_PASSMANAGERBUILDER_H
1515 #define LLVM_TRANSFORMS_IPO_PASSMANAGERBUILDER_H
1616
17 #include
1718 #include
1819
1920 namespace llvm {
21 class FunctionInfoIndex;
2022 class Pass;
2123 class TargetLibraryInfoImpl;
2224 class TargetMachine;
113115 /// added to the per-module passes.
114116 Pass *Inliner;
115117
118 /// The function summary index to use for function importing.
119 FunctionInfoIndex *FunctionIndex;
120
116121 bool DisableTailCalls;
117122 bool DisableUnitAtATime;
118123 bool DisableUnrollLoops;
1919
2020 namespace llvm {
2121
22 class FunctionInfoIndex;
2223 class ModulePass;
2324 class Pass;
2425 class Function;
8586 deleteFn = false);
8687
8788 //===----------------------------------------------------------------------===//
89 /// This pass performs iterative function importing from other modules.
90 ModulePass *createFunctionImportPass(FunctionInfoIndex *Index = nullptr);
91
92 //===----------------------------------------------------------------------===//
8893 /// createFunctionInliningPass - Return a new pass object that uses a heuristic
8994 /// to inline direct function calls to small functions.
9095 ///
255255
256256 /// Pass that performs cross-module function import provided a summary file.
257257 class FunctionImportPass : public ModulePass {
258 /// Optional function summary index to use for importing, otherwise
259 /// the summary-file option must be specified.
260 FunctionInfoIndex *Index;
258261
259262 public:
260263 /// Pass identification, replacement for typeid
261264 static char ID;
262265
263 explicit FunctionImportPass() : ModulePass(ID) {}
266 /// Specify pass name for debug output
267 const char *getPassName() const override {
268 return "Function Importing";
269 }
270
271 explicit FunctionImportPass(FunctionInfoIndex *Index = nullptr)
272 : ModulePass(ID), Index(Index) {}
264273
265274 bool runOnModule(Module &M) override {
266 if (SummaryFile.empty()) {
267 report_fatal_error("error: -function-import requires -summary-file\n");
268 }
269 std::string Error;
270 std::unique_ptr Index =
271 getFunctionIndexForFile(SummaryFile, Error, diagnosticHandler);
272 if (!Index) {
273 errs() << "Error loading file '" << SummaryFile << "': " << Error << "\n";
274 return false;
275 if (SummaryFile.empty() && !Index)
276 report_fatal_error("error: -function-import requires -summary-file or "
277 "file from frontend\n");
278 std::unique_ptr IndexPtr;
279 if (!SummaryFile.empty()) {
280 if (Index)
281 report_fatal_error("error: -summary-file and index from frontend\n");
282 std::string Error;
283 IndexPtr = getFunctionIndexForFile(SummaryFile, Error, diagnosticHandler);
284 if (!IndexPtr) {
285 errs() << "Error loading file '" << SummaryFile << "': " << Error
286 << "\n";
287 return false;
288 }
289 Index = IndexPtr.get();
275290 }
276291
277292 // Perform the import now.
292307 "Summary Based Function Import", false, false)
293308
294309 namespace llvm {
295 Pass *createFunctionImportPass() { return new FunctionImportPass(); }
296 }
310 Pass *createFunctionImportPass(FunctionInfoIndex *Index = nullptr) {
311 return new FunctionImportPass(Index);
312 }
313 }
1717 #include "llvm/ADT/SmallVector.h"
1818 #include "llvm/Analysis/Passes.h"
1919 #include "llvm/IR/DataLayout.h"
20 #include "llvm/IR/FunctionInfo.h"
2021 #include "llvm/IR/Verifier.h"
2122 #include "llvm/IR/LegacyPassManager.h"
2223 #include "llvm/Support/CommandLine.h"
107108 SizeLevel = 0;
108109 LibraryInfo = nullptr;
109110 Inliner = nullptr;
111 FunctionIndex = nullptr;
110112 DisableUnitAtATime = false;
111113 DisableUnrollLoops = false;
112114 BBVectorize = RunBBVectorization;
475477 // Provide AliasAnalysis services for optimizations.
476478 addInitialAliasAnalysisPasses(PM);
477479
480 if (FunctionIndex)
481 PM.add(createFunctionImportPass(FunctionIndex));
482
478483 // Propagate constants at call sites into the functions they call. This
479484 // opens opportunities for globalopt (and inlining) by substituting function
480485 // pointers passed as arguments to direct uses of functions.