blob: e402f93ec1721bc638d6b46181f9587e10f7b165 [file] [log] [blame]
Mehdi Amini42418ab2015-11-24 06:07:49 +00001//===- FunctionImport.cpp - ThinLTO Summary-based Function Import ---------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements Function import based on summaries.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Transforms/IPO/FunctionImport.h"
15
16#include "llvm/ADT/StringSet.h"
17#include "llvm/IR/AutoUpgrade.h"
18#include "llvm/IR/DiagnosticPrinter.h"
19#include "llvm/IR/IntrinsicInst.h"
20#include "llvm/IR/Module.h"
21#include "llvm/IRReader/IRReader.h"
22#include "llvm/Linker/Linker.h"
23#include "llvm/Object/FunctionIndexObjectFile.h"
24#include "llvm/Support/CommandLine.h"
25#include "llvm/Support/Debug.h"
26#include "llvm/Support/SourceMgr.h"
Teresa Johnson488a8002016-02-10 18:11:31 +000027#include "llvm/Transforms/Utils/FunctionImportUtils.h"
Mehdi Amini7e88d0d2015-12-09 08:17:35 +000028
29#include <map>
30
Mehdi Amini42418ab2015-11-24 06:07:49 +000031using namespace llvm;
32
33#define DEBUG_TYPE "function-import"
34
Teresa Johnson39303612015-11-24 22:55:46 +000035/// Limit on instruction count of imported functions.
36static cl::opt<unsigned> ImportInstrLimit(
37 "import-instr-limit", cl::init(100), cl::Hidden, cl::value_desc("N"),
38 cl::desc("Only import functions with less than N instructions"));
39
Mehdi Amini42418ab2015-11-24 06:07:49 +000040// Load lazily a module from \p FileName in \p Context.
41static std::unique_ptr<Module> loadFile(const std::string &FileName,
42 LLVMContext &Context) {
43 SMDiagnostic Err;
44 DEBUG(dbgs() << "Loading '" << FileName << "'\n");
Teresa Johnson6cba37c2016-01-22 00:15:53 +000045 // Metadata isn't loaded until functions are imported, to minimize
46 // the memory overhead.
Teresa Johnsona1080ee2016-01-08 14:17:41 +000047 std::unique_ptr<Module> Result =
48 getLazyIRFileModule(FileName, Err, Context,
49 /* ShouldLazyLoadMetadata = */ true);
Mehdi Amini42418ab2015-11-24 06:07:49 +000050 if (!Result) {
51 Err.print("function-import", errs());
52 return nullptr;
53 }
54
Mehdi Amini42418ab2015-11-24 06:07:49 +000055 return Result;
56}
57
Mehdi Amini7e88d0d2015-12-09 08:17:35 +000058namespace {
59/// Helper to load on demand a Module from file and cache it for subsequent
60/// queries. It can be used with the FunctionImporter.
61class ModuleLazyLoaderCache {
62 /// Cache of lazily loaded module for import.
63 StringMap<std::unique_ptr<Module>> ModuleMap;
64
65 /// Retrieve a Module from the cache or lazily load it on demand.
66 std::function<std::unique_ptr<Module>(StringRef FileName)> createLazyModule;
67
68public:
69 /// Create the loader, Module will be initialized in \p Context.
70 ModuleLazyLoaderCache(std::function<
71 std::unique_ptr<Module>(StringRef FileName)> createLazyModule)
72 : createLazyModule(createLazyModule) {}
73
74 /// Retrieve a Module from the cache or lazily load it on demand.
75 Module &operator()(StringRef FileName);
Rafael Espindola434e9562015-12-16 23:16:33 +000076
77 std::unique_ptr<Module> takeModule(StringRef FileName) {
78 auto I = ModuleMap.find(FileName);
79 assert(I != ModuleMap.end());
80 std::unique_ptr<Module> Ret = std::move(I->second);
81 ModuleMap.erase(I);
82 return Ret;
83 }
Mehdi Amini7e88d0d2015-12-09 08:17:35 +000084};
85
86// Get a Module for \p FileName from the cache, or load it lazily.
87Module &ModuleLazyLoaderCache::operator()(StringRef Identifier) {
88 auto &Module = ModuleMap[Identifier];
89 if (!Module)
90 Module = createLazyModule(Identifier);
91 return *Module;
92}
93} // anonymous namespace
94
Teresa Johnsond450da32015-11-24 21:15:19 +000095/// Walk through the instructions in \p F looking for external
96/// calls not already in the \p CalledFunctions set. If any are
97/// found they are added to the \p Worklist for importing.
Mehdi Amini7e88d0d2015-12-09 08:17:35 +000098static void findExternalCalls(const Module &DestModule, Function &F,
99 const FunctionInfoIndex &Index,
100 StringSet<> &CalledFunctions,
Teresa Johnsond450da32015-11-24 21:15:19 +0000101 SmallVector<StringRef, 64> &Worklist) {
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000102 // We need to suffix internal function calls imported from other modules,
103 // prepare the suffix ahead of time.
Rafael Espindola9edc3b82015-12-09 20:41:10 +0000104 std::string Suffix;
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000105 if (F.getParent() != &DestModule)
106 Suffix =
107 (Twine(".llvm.") +
108 Twine(Index.getModuleId(F.getParent()->getModuleIdentifier()))).str();
109
Teresa Johnsond450da32015-11-24 21:15:19 +0000110 for (auto &BB : F) {
111 for (auto &I : BB) {
112 if (isa<CallInst>(I)) {
Teresa Johnsond450da32015-11-24 21:15:19 +0000113 auto CalledFunction = cast<CallInst>(I).getCalledFunction();
114 // Insert any new external calls that have not already been
115 // added to set/worklist.
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000116 if (!CalledFunction || !CalledFunction->hasName())
117 continue;
118 // Ignore intrinsics early
119 if (CalledFunction->isIntrinsic()) {
120 assert(CalledFunction->getIntrinsicID() != 0);
121 continue;
Teresa Johnsond450da32015-11-24 21:15:19 +0000122 }
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000123 auto ImportedName = CalledFunction->getName();
124 auto Renamed = (ImportedName + Suffix).str();
125 // Rename internal functions
126 if (CalledFunction->hasInternalLinkage()) {
127 ImportedName = Renamed;
128 }
129 auto It = CalledFunctions.insert(ImportedName);
130 if (!It.second) {
131 // This is a call to a function we already considered, skip.
132 continue;
133 }
134 // Ignore functions already present in the destination module
135 auto *SrcGV = DestModule.getNamedValue(ImportedName);
136 if (SrcGV) {
Teresa Johnson388497e2016-01-12 17:48:44 +0000137 if (GlobalAlias *SGA = dyn_cast<GlobalAlias>(SrcGV))
138 SrcGV = SGA->getBaseObject();
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000139 assert(isa<Function>(SrcGV) && "Name collision during import");
140 if (!cast<Function>(SrcGV)->isDeclaration()) {
Teresa Johnson9f2ff9c2015-12-10 16:39:07 +0000141 DEBUG(dbgs() << DestModule.getModuleIdentifier() << ": Ignoring "
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000142 << ImportedName << " already in DestinationModule\n");
143 continue;
144 }
145 }
146
147 Worklist.push_back(It.first->getKey());
148 DEBUG(dbgs() << DestModule.getModuleIdentifier()
Teresa Johnson9f2ff9c2015-12-10 16:39:07 +0000149 << ": Adding callee for : " << ImportedName << " : "
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000150 << F.getName() << "\n");
Teresa Johnsond450da32015-11-24 21:15:19 +0000151 }
152 }
153 }
154}
155
Mehdi Aminic8c55172015-12-03 02:37:33 +0000156// Helper function: given a worklist and an index, will process all the worklist
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000157// and decide what to import based on the summary information.
158//
159// Nothing is actually imported, functions are materialized in their source
160// module and analyzed there.
161//
162// \p ModuleToFunctionsToImportMap is filled with the set of Function to import
163// per Module.
Rafael Espindola434e9562015-12-16 23:16:33 +0000164static void GetImportList(Module &DestModule,
165 SmallVector<StringRef, 64> &Worklist,
166 StringSet<> &CalledFunctions,
167 std::map<StringRef, DenseSet<const GlobalValue *>>
168 &ModuleToFunctionsToImportMap,
169 const FunctionInfoIndex &Index,
170 ModuleLazyLoaderCache &ModuleLoaderCache) {
Mehdi Amini42418ab2015-11-24 06:07:49 +0000171 while (!Worklist.empty()) {
172 auto CalledFunctionName = Worklist.pop_back_val();
Teresa Johnson9f2ff9c2015-12-10 16:39:07 +0000173 DEBUG(dbgs() << DestModule.getModuleIdentifier() << ": Process import for "
Mehdi Amini5411d052015-12-08 23:04:19 +0000174 << CalledFunctionName << "\n");
Mehdi Amini42418ab2015-11-24 06:07:49 +0000175
176 // Try to get a summary for this function call.
177 auto InfoList = Index.findFunctionInfoList(CalledFunctionName);
178 if (InfoList == Index.end()) {
Teresa Johnson9f2ff9c2015-12-10 16:39:07 +0000179 DEBUG(dbgs() << DestModule.getModuleIdentifier() << ": No summary for "
Mehdi Amini5411d052015-12-08 23:04:19 +0000180 << CalledFunctionName << " Ignoring.\n");
Mehdi Amini42418ab2015-11-24 06:07:49 +0000181 continue;
182 }
183 assert(!InfoList->second.empty() && "No summary, error at import?");
184
185 // Comdat can have multiple entries, FIXME: what do we do with them?
186 auto &Info = InfoList->second[0];
187 assert(Info && "Nullptr in list, error importing summaries?\n");
188
189 auto *Summary = Info->functionSummary();
190 if (!Summary) {
191 // FIXME: in case we are lazyloading summaries, we can do it now.
Mehdi Amini5411d052015-12-08 23:04:19 +0000192 DEBUG(dbgs() << DestModule.getModuleIdentifier()
Teresa Johnson9f2ff9c2015-12-10 16:39:07 +0000193 << ": Missing summary for " << CalledFunctionName
Teresa Johnson430110c2015-12-01 17:12:10 +0000194 << ", error at import?\n");
Mehdi Amini42418ab2015-11-24 06:07:49 +0000195 llvm_unreachable("Missing summary");
196 }
197
Teresa Johnson39303612015-11-24 22:55:46 +0000198 if (Summary->instCount() > ImportInstrLimit) {
Teresa Johnson9f2ff9c2015-12-10 16:39:07 +0000199 DEBUG(dbgs() << DestModule.getModuleIdentifier() << ": Skip import of "
Mehdi Amini5411d052015-12-08 23:04:19 +0000200 << CalledFunctionName << " with " << Summary->instCount()
201 << " instructions (limit " << ImportInstrLimit << ")\n");
Teresa Johnson39303612015-11-24 22:55:46 +0000202 continue;
203 }
204
Mehdi Amini42418ab2015-11-24 06:07:49 +0000205 // Get the module path from the summary.
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000206 auto ModuleIdentifier = Summary->modulePath();
Teresa Johnson9f2ff9c2015-12-10 16:39:07 +0000207 DEBUG(dbgs() << DestModule.getModuleIdentifier() << ": Importing "
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000208 << CalledFunctionName << " from " << ModuleIdentifier << "\n");
Mehdi Amini42418ab2015-11-24 06:07:49 +0000209
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000210 auto &SrcModule = ModuleLoaderCache(ModuleIdentifier);
Mehdi Amini42418ab2015-11-24 06:07:49 +0000211
212 // The function that we will import!
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000213 GlobalValue *SGV = SrcModule.getNamedValue(CalledFunctionName);
214
Teresa Johnson130de7a2015-11-24 19:55:04 +0000215 if (!SGV) {
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000216 // The destination module is referencing function using their renamed name
217 // when importing a function that was originally local in the source
218 // module. The source module we have might not have been renamed so we try
219 // to remove the suffix added during the renaming to recover the original
220 // name in the source module.
Teresa Johnson130de7a2015-11-24 19:55:04 +0000221 std::pair<StringRef, StringRef> Split =
222 CalledFunctionName.split(".llvm.");
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000223 SGV = SrcModule.getNamedValue(Split.first);
224 assert(SGV && "Can't find function to import in source module");
Teresa Johnson130de7a2015-11-24 19:55:04 +0000225 }
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000226 if (!SGV) {
227 report_fatal_error(Twine("Can't load function '") + CalledFunctionName +
228 "' in Module '" + SrcModule.getModuleIdentifier() +
229 "', error in the summary?\n");
230 }
231
Mehdi Amini42418ab2015-11-24 06:07:49 +0000232 Function *F = dyn_cast<Function>(SGV);
233 if (!F && isa<GlobalAlias>(SGV)) {
234 auto *SGA = dyn_cast<GlobalAlias>(SGV);
235 F = dyn_cast<Function>(SGA->getBaseObject());
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000236 CalledFunctionName = F->getName();
Mehdi Amini42418ab2015-11-24 06:07:49 +0000237 }
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000238 assert(F && "Imported Function is ... not a Function");
Mehdi Amini42418ab2015-11-24 06:07:49 +0000239
Teresa Johnson17626652015-11-24 16:10:43 +0000240 // We cannot import weak_any functions/aliases without possibly affecting
241 // the order they are seen and selected by the linker, changing program
Mehdi Amini42418ab2015-11-24 06:07:49 +0000242 // semantics.
Teresa Johnson17626652015-11-24 16:10:43 +0000243 if (SGV->hasWeakAnyLinkage()) {
Mehdi Amini5411d052015-12-08 23:04:19 +0000244 DEBUG(dbgs() << DestModule.getModuleIdentifier()
Teresa Johnson9f2ff9c2015-12-10 16:39:07 +0000245 << ": Ignoring import request for weak-any "
Teresa Johnson17626652015-11-24 16:10:43 +0000246 << (isa<Function>(SGV) ? "function " : "alias ")
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000247 << CalledFunctionName << " from "
248 << SrcModule.getModuleIdentifier() << "\n");
Mehdi Amini42418ab2015-11-24 06:07:49 +0000249 continue;
250 }
251
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000252 // Add the function to the import list
253 auto &Entry = ModuleToFunctionsToImportMap[SrcModule.getModuleIdentifier()];
Rafael Espindola434e9562015-12-16 23:16:33 +0000254 Entry.insert(F);
Mehdi Amini42418ab2015-11-24 06:07:49 +0000255
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000256 // Process the newly imported functions and add callees to the worklist.
257 F->materialize();
258 findExternalCalls(DestModule, *F, Index, CalledFunctions, Worklist);
Mehdi Amini42418ab2015-11-24 06:07:49 +0000259 }
Mehdi Aminic8c55172015-12-03 02:37:33 +0000260}
Mehdi Aminiffe2e4a2015-12-02 04:34:28 +0000261
Mehdi Aminic8c55172015-12-03 02:37:33 +0000262// Automatically import functions in Module \p DestModule based on the summaries
263// index.
264//
265// The current implementation imports every called functions that exists in the
266// summaries index.
267bool FunctionImporter::importFunctions(Module &DestModule) {
Mehdi Amini5411d052015-12-08 23:04:19 +0000268 DEBUG(dbgs() << "Starting import for Module "
Mehdi Amini311fef62015-12-03 02:58:14 +0000269 << DestModule.getModuleIdentifier() << "\n");
Mehdi Aminic8c55172015-12-03 02:37:33 +0000270 unsigned ImportedCount = 0;
271
272 /// First step is collecting the called external functions.
273 StringSet<> CalledFunctions;
274 SmallVector<StringRef, 64> Worklist;
275 for (auto &F : DestModule) {
276 if (F.isDeclaration() || F.hasFnAttribute(Attribute::OptimizeNone))
277 continue;
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000278 findExternalCalls(DestModule, F, Index, CalledFunctions, Worklist);
Mehdi Aminic8c55172015-12-03 02:37:33 +0000279 }
280 if (Worklist.empty())
281 return false;
282
283 /// Second step: for every call to an external function, try to import it.
284
285 // Linker that will be used for importing function
Rafael Espindola9d2bfc42015-12-14 23:17:03 +0000286 Linker TheLinker(DestModule);
Mehdi Aminic8c55172015-12-03 02:37:33 +0000287
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000288 // Map of Module -> List of Function to import from the Module
Rafael Espindola434e9562015-12-16 23:16:33 +0000289 std::map<StringRef, DenseSet<const GlobalValue *>>
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000290 ModuleToFunctionsToImportMap;
Mehdi Aminic8c55172015-12-03 02:37:33 +0000291
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000292 // Analyze the summaries and get the list of functions to import by
293 // populating ModuleToFunctionsToImportMap
294 ModuleLazyLoaderCache ModuleLoaderCache(ModuleLoader);
295 GetImportList(DestModule, Worklist, CalledFunctions,
296 ModuleToFunctionsToImportMap, Index, ModuleLoaderCache);
297 assert(Worklist.empty() && "Worklist hasn't been flushed in GetImportList");
298
299 // Do the actual import of functions now, one Module at a time
300 for (auto &FunctionsToImportPerModule : ModuleToFunctionsToImportMap) {
301 // Get the module for the import
Rafael Espindola434e9562015-12-16 23:16:33 +0000302 auto &FunctionsToImport = FunctionsToImportPerModule.second;
303 std::unique_ptr<Module> SrcModule =
304 ModuleLoaderCache.takeModule(FunctionsToImportPerModule.first);
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000305 assert(&DestModule.getContext() == &SrcModule->getContext() &&
306 "Context mismatch");
307
Teresa Johnson6cba37c2016-01-22 00:15:53 +0000308 // If modules were created with lazy metadata loading, materialize it
309 // now, before linking it (otherwise this will be a noop).
310 SrcModule->materializeMetadata();
311 UpgradeDebugInfo(*SrcModule);
Teresa Johnsone5a61912015-12-17 17:14:09 +0000312
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000313 // Link in the specified functions.
Rafael Espindola434e9562015-12-16 23:16:33 +0000314 if (TheLinker.linkInModule(std::move(SrcModule), Linker::Flags::None,
Teresa Johnson6cba37c2016-01-22 00:15:53 +0000315 &Index, &FunctionsToImport))
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000316 report_fatal_error("Function Import: link error");
317
318 ImportedCount += FunctionsToImport.size();
319 }
Teresa Johnsone5a61912015-12-17 17:14:09 +0000320
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000321 DEBUG(dbgs() << "Imported " << ImportedCount << " functions for Module "
Mehdi Aminic8c55172015-12-03 02:37:33 +0000322 << DestModule.getModuleIdentifier() << "\n");
323 return ImportedCount;
Mehdi Amini42418ab2015-11-24 06:07:49 +0000324}
325
326/// Summary file to use for function importing when using -function-import from
327/// the command line.
328static cl::opt<std::string>
329 SummaryFile("summary-file",
330 cl::desc("The summary file to use for function importing."));
331
332static void diagnosticHandler(const DiagnosticInfo &DI) {
333 raw_ostream &OS = errs();
334 DiagnosticPrinterRawOStream DP(OS);
335 DI.print(DP);
336 OS << '\n';
337}
338
339/// Parse the function index out of an IR file and return the function
340/// index object if found, or nullptr if not.
341static std::unique_ptr<FunctionInfoIndex>
342getFunctionIndexForFile(StringRef Path, std::string &Error,
343 DiagnosticHandlerFunction DiagnosticHandler) {
344 std::unique_ptr<MemoryBuffer> Buffer;
345 ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
346 MemoryBuffer::getFile(Path);
347 if (std::error_code EC = BufferOrErr.getError()) {
348 Error = EC.message();
349 return nullptr;
350 }
351 Buffer = std::move(BufferOrErr.get());
352 ErrorOr<std::unique_ptr<object::FunctionIndexObjectFile>> ObjOrErr =
353 object::FunctionIndexObjectFile::create(Buffer->getMemBufferRef(),
354 DiagnosticHandler);
355 if (std::error_code EC = ObjOrErr.getError()) {
356 Error = EC.message();
357 return nullptr;
358 }
359 return (*ObjOrErr)->takeIndex();
360}
361
Benjamin Kramerfe2b5412015-12-24 10:03:35 +0000362namespace {
Mehdi Amini42418ab2015-11-24 06:07:49 +0000363/// Pass that performs cross-module function import provided a summary file.
364class FunctionImportPass : public ModulePass {
Teresa Johnson5fcbdb72015-12-07 19:21:11 +0000365 /// Optional function summary index to use for importing, otherwise
366 /// the summary-file option must be specified.
Teresa Johnson7f961e12015-12-09 19:39:47 +0000367 const FunctionInfoIndex *Index;
Mehdi Amini42418ab2015-11-24 06:07:49 +0000368
369public:
370 /// Pass identification, replacement for typeid
371 static char ID;
372
Teresa Johnson5fcbdb72015-12-07 19:21:11 +0000373 /// Specify pass name for debug output
374 const char *getPassName() const override {
375 return "Function Importing";
376 }
377
Teresa Johnson7f961e12015-12-09 19:39:47 +0000378 explicit FunctionImportPass(const FunctionInfoIndex *Index = nullptr)
Teresa Johnson5fcbdb72015-12-07 19:21:11 +0000379 : ModulePass(ID), Index(Index) {}
Mehdi Amini42418ab2015-11-24 06:07:49 +0000380
381 bool runOnModule(Module &M) override {
Teresa Johnson5fcbdb72015-12-07 19:21:11 +0000382 if (SummaryFile.empty() && !Index)
383 report_fatal_error("error: -function-import requires -summary-file or "
384 "file from frontend\n");
385 std::unique_ptr<FunctionInfoIndex> IndexPtr;
386 if (!SummaryFile.empty()) {
387 if (Index)
388 report_fatal_error("error: -summary-file and index from frontend\n");
389 std::string Error;
390 IndexPtr = getFunctionIndexForFile(SummaryFile, Error, diagnosticHandler);
391 if (!IndexPtr) {
392 errs() << "Error loading file '" << SummaryFile << "': " << Error
393 << "\n";
394 return false;
395 }
396 Index = IndexPtr.get();
Mehdi Amini42418ab2015-11-24 06:07:49 +0000397 }
398
Teresa Johnson1b00f2d2016-01-08 17:06:29 +0000399 // First we need to promote to global scope and rename any local values that
400 // are potentially exported to other modules.
401 if (renameModuleForThinLTO(M, Index)) {
402 errs() << "Error renaming module\n";
403 return false;
404 }
405
Mehdi Amini42418ab2015-11-24 06:07:49 +0000406 // Perform the import now.
Mehdi Aminid16c8062015-12-08 22:39:40 +0000407 auto ModuleLoader = [&M](StringRef Identifier) {
408 return loadFile(Identifier, M.getContext());
409 };
Rafael Espindola9d2bfc42015-12-14 23:17:03 +0000410 FunctionImporter Importer(*Index, ModuleLoader);
Mehdi Amini42418ab2015-11-24 06:07:49 +0000411 return Importer.importFunctions(M);
Mehdi Amini42418ab2015-11-24 06:07:49 +0000412 }
413};
Benjamin Kramerfe2b5412015-12-24 10:03:35 +0000414} // anonymous namespace
Mehdi Amini42418ab2015-11-24 06:07:49 +0000415
416char FunctionImportPass::ID = 0;
417INITIALIZE_PASS_BEGIN(FunctionImportPass, "function-import",
418 "Summary Based Function Import", false, false)
419INITIALIZE_PASS_END(FunctionImportPass, "function-import",
420 "Summary Based Function Import", false, false)
421
422namespace llvm {
Teresa Johnson7f961e12015-12-09 19:39:47 +0000423Pass *createFunctionImportPass(const FunctionInfoIndex *Index = nullptr) {
Teresa Johnson5fcbdb72015-12-07 19:21:11 +0000424 return new FunctionImportPass(Index);
425}
Mehdi Amini42418ab2015-11-24 06:07:49 +0000426}