blob: d0b2667369b934f998d85209157a1844d78df619 [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
Mehdi Amini01e32132016-03-26 05:40:34 +000016#include "llvm/ADT/SmallVector.h"
Teresa Johnsond29478f2016-03-27 15:27:30 +000017#include "llvm/ADT/Statistic.h"
Mehdi Amini42418ab2015-11-24 06:07:49 +000018#include "llvm/ADT/StringSet.h"
Teresa Johnson04c9a2d2016-05-25 14:03:11 +000019#include "llvm/ADT/Triple.h"
Mehdi Amini42418ab2015-11-24 06:07:49 +000020#include "llvm/IR/AutoUpgrade.h"
21#include "llvm/IR/DiagnosticPrinter.h"
22#include "llvm/IR/IntrinsicInst.h"
23#include "llvm/IR/Module.h"
24#include "llvm/IRReader/IRReader.h"
25#include "llvm/Linker/Linker.h"
Teresa Johnson04c9a2d2016-05-25 14:03:11 +000026#include "llvm/Object/IRObjectFile.h"
Teresa Johnson26ab5772016-03-15 00:04:37 +000027#include "llvm/Object/ModuleSummaryIndexObjectFile.h"
Mehdi Amini42418ab2015-11-24 06:07:49 +000028#include "llvm/Support/CommandLine.h"
29#include "llvm/Support/Debug.h"
30#include "llvm/Support/SourceMgr.h"
Teresa Johnson04c9a2d2016-05-25 14:03:11 +000031#include "llvm/Transforms/IPO/Internalize.h"
Teresa Johnson488a8002016-02-10 18:11:31 +000032#include "llvm/Transforms/Utils/FunctionImportUtils.h"
Mehdi Amini7e88d0d2015-12-09 08:17:35 +000033
Mehdi Amini01e32132016-03-26 05:40:34 +000034#define DEBUG_TYPE "function-import"
Mehdi Amini7e88d0d2015-12-09 08:17:35 +000035
Mehdi Amini42418ab2015-11-24 06:07:49 +000036using namespace llvm;
37
Teresa Johnsond29478f2016-03-27 15:27:30 +000038STATISTIC(NumImported, "Number of functions imported");
39
Teresa Johnson39303612015-11-24 22:55:46 +000040/// Limit on instruction count of imported functions.
41static cl::opt<unsigned> ImportInstrLimit(
42 "import-instr-limit", cl::init(100), cl::Hidden, cl::value_desc("N"),
43 cl::desc("Only import functions with less than N instructions"));
44
Mehdi Amini40641742016-02-10 23:31:45 +000045static cl::opt<float>
46 ImportInstrFactor("import-instr-evolution-factor", cl::init(0.7),
47 cl::Hidden, cl::value_desc("x"),
48 cl::desc("As we import functions, multiply the "
49 "`import-instr-limit` threshold by this factor "
50 "before processing newly imported functions"));
51
Teresa Johnsond29478f2016-03-27 15:27:30 +000052static cl::opt<bool> PrintImports("print-imports", cl::init(false), cl::Hidden,
53 cl::desc("Print imported functions"));
54
Mehdi Aminibda3c972016-04-21 01:59:39 +000055// Temporary allows the function import pass to disable always linking
56// referenced discardable symbols.
57static cl::opt<bool>
58 DontForceImportReferencedDiscardableSymbols("disable-force-link-odr",
59 cl::init(false), cl::Hidden);
60
Mehdi Amini42418ab2015-11-24 06:07:49 +000061// Load lazily a module from \p FileName in \p Context.
62static std::unique_ptr<Module> loadFile(const std::string &FileName,
63 LLVMContext &Context) {
64 SMDiagnostic Err;
65 DEBUG(dbgs() << "Loading '" << FileName << "'\n");
Teresa Johnson6cba37c2016-01-22 00:15:53 +000066 // Metadata isn't loaded until functions are imported, to minimize
67 // the memory overhead.
Teresa Johnsona1080ee2016-01-08 14:17:41 +000068 std::unique_ptr<Module> Result =
69 getLazyIRFileModule(FileName, Err, Context,
70 /* ShouldLazyLoadMetadata = */ true);
Mehdi Amini42418ab2015-11-24 06:07:49 +000071 if (!Result) {
72 Err.print("function-import", errs());
Mehdi Aminid7ad2212016-04-01 05:33:11 +000073 report_fatal_error("Abort");
Mehdi Amini42418ab2015-11-24 06:07:49 +000074 }
75
Mehdi Amini42418ab2015-11-24 06:07:49 +000076 return Result;
77}
78
Mehdi Amini7e88d0d2015-12-09 08:17:35 +000079namespace {
Mehdi Amini40641742016-02-10 23:31:45 +000080
Mehdi Aminib4e1e822016-04-27 00:32:13 +000081// Return true if the Summary describes a GlobalValue that can be externally
82// referenced, i.e. it does not need renaming (linkage is not local) or renaming
83// is possible (does not have a section for instance).
84static bool canBeExternallyReferenced(const GlobalValueSummary &Summary) {
85 if (!Summary.needsRenaming())
86 return true;
87
88 if (Summary.hasSection())
89 // Can't rename a global that needs renaming if has a section.
90 return false;
91
92 return true;
93}
94
95// Return true if \p GUID describes a GlobalValue that can be externally
96// referenced, i.e. it does not need renaming (linkage is not local) or
97// renaming is possible (does not have a section for instance).
98static bool canBeExternallyReferenced(const ModuleSummaryIndex &Index,
99 GlobalValue::GUID GUID) {
100 auto Summaries = Index.findGlobalValueSummaryList(GUID);
101 if (Summaries == Index.end())
102 return true;
103 if (Summaries->second.size() != 1)
104 // If there are multiple globals with this GUID, then we know it is
105 // not a local symbol, and it is necessarily externally referenced.
106 return true;
107
108 // We don't need to check for the module path, because if it can't be
109 // externally referenced and we call it, it is necessarilly in the same
110 // module
111 return canBeExternallyReferenced(**Summaries->second.begin());
112}
113
114// Return true if the global described by \p Summary can be imported in another
115// module.
116static bool eligibleForImport(const ModuleSummaryIndex &Index,
117 const GlobalValueSummary &Summary) {
118 if (!canBeExternallyReferenced(Summary))
119 // Can't import a global that needs renaming if has a section for instance.
120 // FIXME: we may be able to import it by copying it without promotion.
121 return false;
122
123 // Check references (and potential calls) in the same module. If the current
124 // value references a global that can't be externally referenced it is not
125 // eligible for import.
126 bool AllRefsCanBeExternallyReferenced =
127 llvm::all_of(Summary.refs(), [&](const ValueInfo &VI) {
128 return canBeExternallyReferenced(Index, VI.getGUID());
129 });
130 if (!AllRefsCanBeExternallyReferenced)
131 return false;
132
133 if (auto *FuncSummary = dyn_cast<FunctionSummary>(&Summary)) {
134 bool AllCallsCanBeExternallyReferenced = llvm::all_of(
135 FuncSummary->calls(), [&](const FunctionSummary::EdgeTy &Edge) {
136 return canBeExternallyReferenced(Index, Edge.first.getGUID());
137 });
138 if (!AllCallsCanBeExternallyReferenced)
139 return false;
140 }
141 return true;
142}
143
Mehdi Amini01e32132016-03-26 05:40:34 +0000144/// Given a list of possible callee implementation for a call site, select one
145/// that fits the \p Threshold.
146///
147/// FIXME: select "best" instead of first that fits. But what is "best"?
148/// - The smallest: more likely to be inlined.
149/// - The one with the least outgoing edges (already well optimized).
150/// - One from a module already being imported from in order to reduce the
151/// number of source modules parsed/linked.
152/// - One that has PGO data attached.
153/// - [insert you fancy metric here]
Mehdi Amini2d28f7a2016-04-16 06:56:44 +0000154static const GlobalValueSummary *
Mehdi Aminib4e1e822016-04-27 00:32:13 +0000155selectCallee(const ModuleSummaryIndex &Index,
156 const GlobalValueSummaryList &CalleeSummaryList,
Teresa Johnson28e457b2016-04-24 14:57:11 +0000157 unsigned Threshold) {
Mehdi Amini01e32132016-03-26 05:40:34 +0000158 auto It = llvm::find_if(
Teresa Johnson28e457b2016-04-24 14:57:11 +0000159 CalleeSummaryList,
160 [&](const std::unique_ptr<GlobalValueSummary> &SummaryPtr) {
161 auto *GVSummary = SummaryPtr.get();
Rafael Espindolaf329be82016-05-11 01:26:06 +0000162 if (GlobalValue::isInterposableLinkage(GVSummary->linkage()))
Mehdi Amini5b85d8d2016-05-03 00:27:28 +0000163 // There is no point in importing these, we can't inline them
Mehdi Amini01e32132016-03-26 05:40:34 +0000164 return false;
Mehdi Amini2c719cc2016-04-20 04:17:36 +0000165 if (auto *AS = dyn_cast<AliasSummary>(GVSummary)) {
166 GVSummary = &AS->getAliasee();
167 // Alias can't point to "available_externally". However when we import
168 // linkOnceODR the linkage does not change. So we import the alias
169 // and aliasee only in this case.
170 // FIXME: we should import alias as available_externally *function*,
171 // the destination module does need to know it is an alias.
172 if (!GlobalValue::isLinkOnceODRLinkage(GVSummary->linkage()))
173 return false;
174 }
175
176 auto *Summary = cast<FunctionSummary>(GVSummary);
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000177
Mehdi Amini01e32132016-03-26 05:40:34 +0000178 if (Summary->instCount() > Threshold)
179 return false;
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000180
Mehdi Aminib4e1e822016-04-27 00:32:13 +0000181 if (!eligibleForImport(Index, *Summary))
182 return false;
183
Mehdi Amini01e32132016-03-26 05:40:34 +0000184 return true;
185 });
Teresa Johnson28e457b2016-04-24 14:57:11 +0000186 if (It == CalleeSummaryList.end())
Mehdi Amini01e32132016-03-26 05:40:34 +0000187 return nullptr;
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000188
Teresa Johnson28e457b2016-04-24 14:57:11 +0000189 return cast<GlobalValueSummary>(It->get());
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000190}
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000191
Mehdi Amini01e32132016-03-26 05:40:34 +0000192/// Return the summary for the function \p GUID that fits the \p Threshold, or
193/// null if there's no match.
Mehdi Amini2d28f7a2016-04-16 06:56:44 +0000194static const GlobalValueSummary *selectCallee(GlobalValue::GUID GUID,
195 unsigned Threshold,
196 const ModuleSummaryIndex &Index) {
Teresa Johnson28e457b2016-04-24 14:57:11 +0000197 auto CalleeSummaryList = Index.findGlobalValueSummaryList(GUID);
Mehdi Aminib4e1e822016-04-27 00:32:13 +0000198 if (CalleeSummaryList == Index.end())
Mehdi Amini01e32132016-03-26 05:40:34 +0000199 return nullptr; // This function does not have a summary
Mehdi Aminib4e1e822016-04-27 00:32:13 +0000200 return selectCallee(Index, CalleeSummaryList->second, Threshold);
Mehdi Amini01e32132016-03-26 05:40:34 +0000201}
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000202
Mehdi Aminicb874942016-04-23 23:29:24 +0000203/// Mark the global \p GUID as export by module \p ExportModulePath if found in
204/// this module. If it is a GlobalVariable, we also mark any referenced global
205/// in the current module as exported.
206static void exportGlobalInModule(const ModuleSummaryIndex &Index,
207 StringRef ExportModulePath,
208 GlobalValue::GUID GUID,
209 FunctionImporter::ExportSetTy &ExportList) {
Teresa Johnson28e457b2016-04-24 14:57:11 +0000210 auto FindGlobalSummaryInModule =
211 [&](GlobalValue::GUID GUID) -> GlobalValueSummary *{
212 auto SummaryList = Index.findGlobalValueSummaryList(GUID);
213 if (SummaryList == Index.end())
Mehdi Aminicb874942016-04-23 23:29:24 +0000214 // This global does not have a summary, it is not part of the ThinLTO
215 // process
216 return nullptr;
Teresa Johnson28e457b2016-04-24 14:57:11 +0000217 auto SummaryIter = llvm::find_if(
218 SummaryList->second,
219 [&](const std::unique_ptr<GlobalValueSummary> &Summary) {
Mehdi Aminicb874942016-04-23 23:29:24 +0000220 return Summary->modulePath() == ExportModulePath;
221 });
Teresa Johnson28e457b2016-04-24 14:57:11 +0000222 if (SummaryIter == SummaryList->second.end())
Mehdi Aminicb874942016-04-23 23:29:24 +0000223 return nullptr;
Teresa Johnson28e457b2016-04-24 14:57:11 +0000224 return SummaryIter->get();
Mehdi Aminicb874942016-04-23 23:29:24 +0000225 };
226
Teresa Johnson28e457b2016-04-24 14:57:11 +0000227 auto *Summary = FindGlobalSummaryInModule(GUID);
228 if (!Summary)
Mehdi Aminicb874942016-04-23 23:29:24 +0000229 return;
230 // We found it in the current module, mark as exported
231 ExportList.insert(GUID);
232
Mehdi Aminicb874942016-04-23 23:29:24 +0000233 auto GVS = dyn_cast<GlobalVarSummary>(Summary);
234 if (!GVS)
235 return;
236 // FunctionImportGlobalProcessing::doPromoteLocalToGlobal() will always
237 // trigger importing the initializer for `constant unnamed addr` globals that
238 // are referenced. We conservatively export all the referenced symbols for
239 // every global to workaround this, so that the ExportList is accurate.
240 // FIXME: with a "isConstant" flag in the summary we could be more targetted.
241 for (auto &Ref : GVS->refs()) {
242 auto GUID = Ref.getGUID();
Teresa Johnson28e457b2016-04-24 14:57:11 +0000243 auto *RefSummary = FindGlobalSummaryInModule(GUID);
244 if (RefSummary)
Mehdi Aminicb874942016-04-23 23:29:24 +0000245 // Found a ref in the current module, mark it as exported
246 ExportList.insert(GUID);
247 }
Mehdi Amini01e32132016-03-26 05:40:34 +0000248}
Mehdi Amini40641742016-02-10 23:31:45 +0000249
Mehdi Amini01e32132016-03-26 05:40:34 +0000250using EdgeInfo = std::pair<const FunctionSummary *, unsigned /* Threshold */>;
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000251
Mehdi Amini01e32132016-03-26 05:40:34 +0000252/// Compute the list of functions to import for a given caller. Mark these
253/// imported functions and the symbols they reference in their source module as
254/// exported from their source module.
255static void computeImportForFunction(
Teresa Johnson3255eec2016-04-10 15:17:26 +0000256 const FunctionSummary &Summary, const ModuleSummaryIndex &Index,
Teresa Johnsonc851d212016-04-25 21:09:51 +0000257 unsigned Threshold, const GVSummaryMapTy &DefinedGVSummaries,
Mehdi Amini01e32132016-03-26 05:40:34 +0000258 SmallVectorImpl<EdgeInfo> &Worklist,
259 FunctionImporter::ImportMapTy &ImportsForModule,
Teresa Johnsonc86af332016-04-12 21:13:11 +0000260 StringMap<FunctionImporter::ExportSetTy> *ExportLists = nullptr) {
Mehdi Amini01e32132016-03-26 05:40:34 +0000261 for (auto &Edge : Summary.calls()) {
Teresa Johnson2d5487c2016-04-11 13:58:45 +0000262 auto GUID = Edge.first.getGUID();
Mehdi Amini01e32132016-03-26 05:40:34 +0000263 DEBUG(dbgs() << " edge -> " << GUID << " Threshold:" << Threshold << "\n");
264
Mehdi Amini1aafabf2016-04-16 07:02:16 +0000265 if (DefinedGVSummaries.count(GUID)) {
Mehdi Amini01e32132016-03-26 05:40:34 +0000266 DEBUG(dbgs() << "ignored! Target already in destination module.\n");
267 continue;
Teresa Johnsond450da32015-11-24 21:15:19 +0000268 }
Mehdi Amini01e32132016-03-26 05:40:34 +0000269
270 auto *CalleeSummary = selectCallee(GUID, Threshold, Index);
271 if (!CalleeSummary) {
272 DEBUG(dbgs() << "ignored! No qualifying callee with summary found.\n");
273 continue;
274 }
Mehdi Amini2d28f7a2016-04-16 06:56:44 +0000275 // "Resolve" the summary, traversing alias,
276 const FunctionSummary *ResolvedCalleeSummary;
Mehdi Amini6968ef72016-04-20 01:04:20 +0000277 if (isa<AliasSummary>(CalleeSummary)) {
Mehdi Amini2d28f7a2016-04-16 06:56:44 +0000278 ResolvedCalleeSummary = cast<FunctionSummary>(
279 &cast<AliasSummary>(CalleeSummary)->getAliasee());
Mehdi Amini2c719cc2016-04-20 04:17:36 +0000280 assert(
281 GlobalValue::isLinkOnceODRLinkage(ResolvedCalleeSummary->linkage()) &&
282 "Unexpected alias to a non-linkonceODR in import list");
Mehdi Amini6968ef72016-04-20 01:04:20 +0000283 } else
Mehdi Amini2d28f7a2016-04-16 06:56:44 +0000284 ResolvedCalleeSummary = cast<FunctionSummary>(CalleeSummary);
285
286 assert(ResolvedCalleeSummary->instCount() <= Threshold &&
Mehdi Amini01e32132016-03-26 05:40:34 +0000287 "selectCallee() didn't honor the threshold");
288
Mehdi Amini2d28f7a2016-04-16 06:56:44 +0000289 auto ExportModulePath = ResolvedCalleeSummary->modulePath();
290 auto &ProcessedThreshold = ImportsForModule[ExportModulePath][GUID];
Mehdi Amini01e32132016-03-26 05:40:34 +0000291 /// Since the traversal of the call graph is DFS, we can revisit a function
292 /// a second time with a higher threshold. In this case, it is added back to
293 /// the worklist with the new threshold.
Teresa Johnson2e030942016-05-11 22:56:19 +0000294 if (ProcessedThreshold && ProcessedThreshold >= Threshold) {
Mehdi Amini01e32132016-03-26 05:40:34 +0000295 DEBUG(dbgs() << "ignored! Target was already seen with Threshold "
296 << ProcessedThreshold << "\n");
297 continue;
298 }
299 // Mark this function as imported in this module, with the current Threshold
300 ProcessedThreshold = Threshold;
301
302 // Make exports in the source module.
Teresa Johnsonc86af332016-04-12 21:13:11 +0000303 if (ExportLists) {
Mehdi Aminief7555f2016-04-13 01:52:32 +0000304 auto &ExportList = (*ExportLists)[ExportModulePath];
Teresa Johnsonc86af332016-04-12 21:13:11 +0000305 ExportList.insert(GUID);
306 // Mark all functions and globals referenced by this function as exported
307 // to the outside if they are defined in the same source module.
Mehdi Amini2d28f7a2016-04-16 06:56:44 +0000308 for (auto &Edge : ResolvedCalleeSummary->calls()) {
Teresa Johnsonc86af332016-04-12 21:13:11 +0000309 auto CalleeGUID = Edge.first.getGUID();
Mehdi Aminicb874942016-04-23 23:29:24 +0000310 exportGlobalInModule(Index, ExportModulePath, CalleeGUID, ExportList);
Teresa Johnsonc86af332016-04-12 21:13:11 +0000311 }
Mehdi Amini2d28f7a2016-04-16 06:56:44 +0000312 for (auto &Ref : ResolvedCalleeSummary->refs()) {
Teresa Johnsonc86af332016-04-12 21:13:11 +0000313 auto GUID = Ref.getGUID();
Mehdi Aminicb874942016-04-23 23:29:24 +0000314 exportGlobalInModule(Index, ExportModulePath, GUID, ExportList);
Teresa Johnsonc86af332016-04-12 21:13:11 +0000315 }
Mehdi Amini01e32132016-03-26 05:40:34 +0000316 }
317
318 // Insert the newly imported function to the worklist.
Mehdi Amini2d28f7a2016-04-16 06:56:44 +0000319 Worklist.push_back(std::make_pair(ResolvedCalleeSummary, Threshold));
Teresa Johnsond450da32015-11-24 21:15:19 +0000320 }
321}
322
Mehdi Amini01e32132016-03-26 05:40:34 +0000323/// Given the list of globals defined in a module, compute the list of imports
324/// as well as the list of "exports", i.e. the list of symbols referenced from
325/// another module (that may require promotion).
326static void ComputeImportForModule(
Teresa Johnsonc851d212016-04-25 21:09:51 +0000327 const GVSummaryMapTy &DefinedGVSummaries, const ModuleSummaryIndex &Index,
Mehdi Amini01e32132016-03-26 05:40:34 +0000328 FunctionImporter::ImportMapTy &ImportsForModule,
Teresa Johnsonc86af332016-04-12 21:13:11 +0000329 StringMap<FunctionImporter::ExportSetTy> *ExportLists = nullptr) {
Mehdi Amini01e32132016-03-26 05:40:34 +0000330 // Worklist contains the list of function imported in this module, for which
331 // we will analyse the callees and may import further down the callgraph.
332 SmallVector<EdgeInfo, 128> Worklist;
333
334 // Populate the worklist with the import for the functions in the current
335 // module
Teresa Johnson28e457b2016-04-24 14:57:11 +0000336 for (auto &GVSummary : DefinedGVSummaries) {
337 auto *Summary = GVSummary.second;
Mehdi Amini2d28f7a2016-04-16 06:56:44 +0000338 if (auto *AS = dyn_cast<AliasSummary>(Summary))
339 Summary = &AS->getAliasee();
Mehdi Amini1aafabf2016-04-16 07:02:16 +0000340 auto *FuncSummary = dyn_cast<FunctionSummary>(Summary);
341 if (!FuncSummary)
342 // Skip import for global variables
343 continue;
Teresa Johnson28e457b2016-04-24 14:57:11 +0000344 DEBUG(dbgs() << "Initalize import for " << GVSummary.first << "\n");
Mehdi Amini2d28f7a2016-04-16 06:56:44 +0000345 computeImportForFunction(*FuncSummary, Index, ImportInstrLimit,
Mehdi Amini1aafabf2016-04-16 07:02:16 +0000346 DefinedGVSummaries, Worklist, ImportsForModule,
Mehdi Amini01e32132016-03-26 05:40:34 +0000347 ExportLists);
348 }
349
Mehdi Amini42418ab2015-11-24 06:07:49 +0000350 while (!Worklist.empty()) {
Mehdi Amini01e32132016-03-26 05:40:34 +0000351 auto FuncInfo = Worklist.pop_back_val();
352 auto *Summary = FuncInfo.first;
353 auto Threshold = FuncInfo.second;
Mehdi Amini42418ab2015-11-24 06:07:49 +0000354
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000355 // Process the newly imported functions and add callees to the worklist.
Mehdi Amini40641742016-02-10 23:31:45 +0000356 // Adjust the threshold
357 Threshold = Threshold * ImportInstrFactor;
Mehdi Amini01e32132016-03-26 05:40:34 +0000358
Mehdi Amini1aafabf2016-04-16 07:02:16 +0000359 computeImportForFunction(*Summary, Index, Threshold, DefinedGVSummaries,
Teresa Johnson3255eec2016-04-10 15:17:26 +0000360 Worklist, ImportsForModule, ExportLists);
Mehdi Amini42418ab2015-11-24 06:07:49 +0000361 }
Mehdi Aminic8c55172015-12-03 02:37:33 +0000362}
Mehdi Aminiffe2e4a2015-12-02 04:34:28 +0000363
Mehdi Amini01e32132016-03-26 05:40:34 +0000364} // anonymous namespace
365
Teresa Johnsonc86af332016-04-12 21:13:11 +0000366/// Compute all the import and export for every module using the Index.
Mehdi Amini01e32132016-03-26 05:40:34 +0000367void llvm::ComputeCrossModuleImport(
368 const ModuleSummaryIndex &Index,
Teresa Johnsonc851d212016-04-25 21:09:51 +0000369 const StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries,
Mehdi Amini01e32132016-03-26 05:40:34 +0000370 StringMap<FunctionImporter::ImportMapTy> &ImportLists,
371 StringMap<FunctionImporter::ExportSetTy> &ExportLists) {
Mehdi Amini01e32132016-03-26 05:40:34 +0000372 // For each module that has function defined, compute the import/export lists.
Mehdi Amini1aafabf2016-04-16 07:02:16 +0000373 for (auto &DefinedGVSummaries : ModuleToDefinedGVSummaries) {
374 auto &ImportsForModule = ImportLists[DefinedGVSummaries.first()];
375 DEBUG(dbgs() << "Computing import for Module '"
376 << DefinedGVSummaries.first() << "'\n");
377 ComputeImportForModule(DefinedGVSummaries.second, Index, ImportsForModule,
Teresa Johnsonc86af332016-04-12 21:13:11 +0000378 &ExportLists);
Mehdi Amini01e32132016-03-26 05:40:34 +0000379 }
380
381#ifndef NDEBUG
382 DEBUG(dbgs() << "Import/Export lists for " << ImportLists.size()
383 << " modules:\n");
384 for (auto &ModuleImports : ImportLists) {
385 auto ModName = ModuleImports.first();
386 auto &Exports = ExportLists[ModName];
387 DEBUG(dbgs() << "* Module " << ModName << " exports " << Exports.size()
388 << " functions. Imports from " << ModuleImports.second.size()
389 << " modules.\n");
390 for (auto &Src : ModuleImports.second) {
391 auto SrcModName = Src.first();
392 DEBUG(dbgs() << " - " << Src.second.size() << " functions imported from "
393 << SrcModName << "\n");
394 }
395 }
396#endif
397}
398
Teresa Johnsonc86af332016-04-12 21:13:11 +0000399/// Compute all the imports for the given module in the Index.
400void llvm::ComputeCrossModuleImportForModule(
401 StringRef ModulePath, const ModuleSummaryIndex &Index,
402 FunctionImporter::ImportMapTy &ImportList) {
403
404 // Collect the list of functions this module defines.
405 // GUID -> Summary
Teresa Johnsonc851d212016-04-25 21:09:51 +0000406 GVSummaryMapTy FunctionSummaryMap;
Teresa Johnson28e457b2016-04-24 14:57:11 +0000407 Index.collectDefinedFunctionsForModule(ModulePath, FunctionSummaryMap);
Teresa Johnsonc86af332016-04-12 21:13:11 +0000408
409 // Compute the import list for this module.
410 DEBUG(dbgs() << "Computing import for Module '" << ModulePath << "'\n");
Teresa Johnson28e457b2016-04-24 14:57:11 +0000411 ComputeImportForModule(FunctionSummaryMap, Index, ImportList);
Teresa Johnsonc86af332016-04-12 21:13:11 +0000412
413#ifndef NDEBUG
414 DEBUG(dbgs() << "* Module " << ModulePath << " imports from "
415 << ImportList.size() << " modules.\n");
416 for (auto &Src : ImportList) {
417 auto SrcModName = Src.first();
418 DEBUG(dbgs() << " - " << Src.second.size() << " functions imported from "
419 << SrcModName << "\n");
420 }
421#endif
422}
423
Teresa Johnson84174c32016-05-10 13:48:23 +0000424/// Compute the set of summaries needed for a ThinLTO backend compilation of
425/// \p ModulePath.
426void llvm::gatherImportedSummariesForModule(
427 StringRef ModulePath,
428 const StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries,
429 const StringMap<FunctionImporter::ImportMapTy> &ImportLists,
430 std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex) {
431 // Include all summaries from the importing module.
432 ModuleToSummariesForIndex[ModulePath] =
433 ModuleToDefinedGVSummaries.lookup(ModulePath);
434 auto ModuleImports = ImportLists.find(ModulePath);
435 if (ModuleImports != ImportLists.end()) {
436 // Include summaries for imports.
437 for (auto &ILI : ModuleImports->second) {
438 auto &SummariesForIndex = ModuleToSummariesForIndex[ILI.first()];
439 const auto &DefinedGVSummaries =
440 ModuleToDefinedGVSummaries.lookup(ILI.first());
441 for (auto &GI : ILI.second) {
442 const auto &DS = DefinedGVSummaries.find(GI.first);
443 assert(DS != DefinedGVSummaries.end() &&
444 "Expected a defined summary for imported global value");
445 SummariesForIndex[GI.first] = DS->second;
446 }
447 }
448 }
449}
450
Teresa Johnson8570fe42016-05-10 15:54:09 +0000451/// Emit the files \p ModulePath will import from into \p OutputFilename.
452std::error_code llvm::EmitImportsFiles(
453 StringRef ModulePath, StringRef OutputFilename,
454 const StringMap<FunctionImporter::ImportMapTy> &ImportLists) {
455 auto ModuleImports = ImportLists.find(ModulePath);
456 std::error_code EC;
457 raw_fd_ostream ImportsOS(OutputFilename, EC, sys::fs::OpenFlags::F_None);
458 if (EC)
459 return EC;
460 if (ModuleImports != ImportLists.end())
461 for (auto &ILI : ModuleImports->second)
462 ImportsOS << ILI.first() << "\n";
463 return std::error_code();
464}
465
Teresa Johnson04c9a2d2016-05-25 14:03:11 +0000466/// Fixup WeakForLinker linkages in \p TheModule based on summary analysis.
467void llvm::thinLTOResolveWeakForLinkerModule(
468 Module &TheModule, const GVSummaryMapTy &DefinedGlobals) {
469 auto updateLinkage = [&](GlobalValue &GV) {
470 if (!GlobalValue::isWeakForLinker(GV.getLinkage()))
471 return;
472 // See if the global summary analysis computed a new resolved linkage.
473 const auto &GS = DefinedGlobals.find(GV.getGUID());
474 if (GS == DefinedGlobals.end())
475 return;
476 auto NewLinkage = GS->second->linkage();
477 if (NewLinkage == GV.getLinkage())
478 return;
479 DEBUG(dbgs() << "ODR fixing up linkage for `" << GV.getName() << "` from "
480 << GV.getLinkage() << " to " << NewLinkage << "\n");
481 GV.setLinkage(NewLinkage);
482 };
483
484 // Process functions and global now
485 for (auto &GV : TheModule)
486 updateLinkage(GV);
487 for (auto &GV : TheModule.globals())
488 updateLinkage(GV);
489 for (auto &GV : TheModule.aliases())
490 updateLinkage(GV);
491}
492
493/// Run internalization on \p TheModule based on symmary analysis.
494void llvm::thinLTOInternalizeModule(Module &TheModule,
495 const GVSummaryMapTy &DefinedGlobals) {
496 // Parse inline ASM and collect the list of symbols that are not defined in
497 // the current module.
498 StringSet<> AsmUndefinedRefs;
499 object::IRObjectFile::CollectAsmUndefinedRefs(
500 Triple(TheModule.getTargetTriple()), TheModule.getModuleInlineAsm(),
501 [&AsmUndefinedRefs](StringRef Name, object::BasicSymbolRef::Flags Flags) {
502 if (Flags & object::BasicSymbolRef::SF_Undefined)
503 AsmUndefinedRefs.insert(Name);
504 });
505
506 // Declare a callback for the internalize pass that will ask for every
507 // candidate GlobalValue if it can be internalized or not.
508 auto MustPreserveGV = [&](const GlobalValue &GV) -> bool {
509 // Can't be internalized if referenced in inline asm.
510 if (AsmUndefinedRefs.count(GV.getName()))
511 return true;
512
513 // Lookup the linkage recorded in the summaries during global analysis.
514 const auto &GS = DefinedGlobals.find(GV.getGUID());
515 GlobalValue::LinkageTypes Linkage;
516 if (GS == DefinedGlobals.end()) {
517 // Must have been promoted (possibly conservatively). Find original
518 // name so that we can access the correct summary and see if it can
519 // be internalized again.
520 // FIXME: Eventually we should control promotion instead of promoting
521 // and internalizing again.
522 StringRef OrigName =
523 ModuleSummaryIndex::getOriginalNameBeforePromote(GV.getName());
524 std::string OrigId = GlobalValue::getGlobalIdentifier(
525 OrigName, GlobalValue::InternalLinkage,
526 TheModule.getSourceFileName());
527 const auto &GS = DefinedGlobals.find(GlobalValue::getGUID(OrigId));
Teresa Johnson7ab1f692016-06-09 01:14:13 +0000528 if (GS == DefinedGlobals.end()) {
529 // Also check the original non-promoted non-globalized name. In some
530 // cases a preempted weak value is linked in as a local copy because
531 // it is referenced by an alias (IRLinker::linkGlobalValueProto).
532 // In that case, since it was originally not a local value, it was
533 // recorded in the index using the original name.
534 // FIXME: This may not be needed once PR27866 is fixed.
535 const auto &GS = DefinedGlobals.find(GlobalValue::getGUID(OrigName));
536 assert(GS != DefinedGlobals.end());
537 Linkage = GS->second->linkage();
538 } else {
539 Linkage = GS->second->linkage();
540 }
Teresa Johnson04c9a2d2016-05-25 14:03:11 +0000541 } else
542 Linkage = GS->second->linkage();
543 return !GlobalValue::isLocalLinkage(Linkage);
544 };
545
546 // FIXME: See if we can just internalize directly here via linkage changes
547 // based on the index, rather than invoking internalizeModule.
548 llvm::internalizeModule(TheModule, MustPreserveGV);
549}
550
Mehdi Aminic8c55172015-12-03 02:37:33 +0000551// Automatically import functions in Module \p DestModule based on the summaries
552// index.
553//
Mehdi Amini01e32132016-03-26 05:40:34 +0000554bool FunctionImporter::importFunctions(
Mehdi Aminibda3c972016-04-21 01:59:39 +0000555 Module &DestModule, const FunctionImporter::ImportMapTy &ImportList,
556 bool ForceImportReferencedDiscardableSymbols) {
Mehdi Amini5411d052015-12-08 23:04:19 +0000557 DEBUG(dbgs() << "Starting import for Module "
Mehdi Amini311fef62015-12-03 02:58:14 +0000558 << DestModule.getModuleIdentifier() << "\n");
Mehdi Aminic8c55172015-12-03 02:37:33 +0000559 unsigned ImportedCount = 0;
560
Mehdi Aminic8c55172015-12-03 02:37:33 +0000561 // Linker that will be used for importing function
Rafael Espindola9d2bfc42015-12-14 23:17:03 +0000562 Linker TheLinker(DestModule);
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000563 // Do the actual import of functions now, one Module at a time
Mehdi Amini01e32132016-03-26 05:40:34 +0000564 std::set<StringRef> ModuleNameOrderedList;
565 for (auto &FunctionsToImportPerModule : ImportList) {
566 ModuleNameOrderedList.insert(FunctionsToImportPerModule.first());
567 }
568 for (auto &Name : ModuleNameOrderedList) {
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000569 // Get the module for the import
Mehdi Amini01e32132016-03-26 05:40:34 +0000570 const auto &FunctionsToImportPerModule = ImportList.find(Name);
571 assert(FunctionsToImportPerModule != ImportList.end());
572 std::unique_ptr<Module> SrcModule = ModuleLoader(Name);
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000573 assert(&DestModule.getContext() == &SrcModule->getContext() &&
574 "Context mismatch");
575
Teresa Johnson6cba37c2016-01-22 00:15:53 +0000576 // If modules were created with lazy metadata loading, materialize it
577 // now, before linking it (otherwise this will be a noop).
578 SrcModule->materializeMetadata();
579 UpgradeDebugInfo(*SrcModule);
Teresa Johnsone5a61912015-12-17 17:14:09 +0000580
Mehdi Amini01e32132016-03-26 05:40:34 +0000581 auto &ImportGUIDs = FunctionsToImportPerModule->second;
582 // Find the globals to import
583 DenseSet<const GlobalValue *> GlobalsToImport;
584 for (auto &GV : *SrcModule) {
Teresa Johnson0beb8582016-04-04 18:52:23 +0000585 if (!GV.hasName())
586 continue;
587 auto GUID = GV.getGUID();
588 auto Import = ImportGUIDs.count(GUID);
Mehdi Aminiaeb1e592016-04-19 09:21:30 +0000589 DEBUG(dbgs() << (Import ? "Is" : "Not") << " importing function " << GUID
590 << " " << GV.getName() << " from "
591 << SrcModule->getSourceFileName() << "\n");
Teresa Johnson0beb8582016-04-04 18:52:23 +0000592 if (Import) {
Mehdi Amini01e32132016-03-26 05:40:34 +0000593 GV.materialize();
594 GlobalsToImport.insert(&GV);
595 }
596 }
Mehdi Amini2d28f7a2016-04-16 06:56:44 +0000597 for (auto &GV : SrcModule->globals()) {
598 if (!GV.hasName())
599 continue;
600 auto GUID = GV.getGUID();
601 auto Import = ImportGUIDs.count(GUID);
Mehdi Aminiaeb1e592016-04-19 09:21:30 +0000602 DEBUG(dbgs() << (Import ? "Is" : "Not") << " importing global " << GUID
603 << " " << GV.getName() << " from "
604 << SrcModule->getSourceFileName() << "\n");
Mehdi Amini2d28f7a2016-04-16 06:56:44 +0000605 if (Import) {
606 GV.materialize();
607 GlobalsToImport.insert(&GV);
608 }
609 }
Mehdi Amini01e32132016-03-26 05:40:34 +0000610 for (auto &GV : SrcModule->aliases()) {
611 if (!GV.hasName())
612 continue;
613 auto GUID = GV.getGUID();
Teresa Johnson0beb8582016-04-04 18:52:23 +0000614 auto Import = ImportGUIDs.count(GUID);
Mehdi Aminiaeb1e592016-04-19 09:21:30 +0000615 DEBUG(dbgs() << (Import ? "Is" : "Not") << " importing alias " << GUID
616 << " " << GV.getName() << " from "
617 << SrcModule->getSourceFileName() << "\n");
Teresa Johnson0beb8582016-04-04 18:52:23 +0000618 if (Import) {
Mehdi Amini01e32132016-03-26 05:40:34 +0000619 // Alias can't point to "available_externally". However when we import
Teresa Johnson9aae3952016-03-27 15:01:11 +0000620 // linkOnceODR the linkage does not change. So we import the alias
Mehdi Amini6968ef72016-04-20 01:04:20 +0000621 // and aliasee only in this case. This has been handled by
622 // computeImportForFunction()
Mehdi Amini2d28f7a2016-04-16 06:56:44 +0000623 GlobalObject *GO = GV.getBaseObject();
Mehdi Amini6968ef72016-04-20 01:04:20 +0000624 assert(GO->hasLinkOnceODRLinkage() &&
625 "Unexpected alias to a non-linkonceODR in import list");
Mehdi Amini2d28f7a2016-04-16 06:56:44 +0000626#ifndef NDEBUG
627 if (!GlobalsToImport.count(GO))
628 DEBUG(dbgs() << " alias triggers importing aliasee " << GO->getGUID()
629 << " " << GO->getName() << " from "
630 << SrcModule->getSourceFileName() << "\n");
631#endif
632 GO->materialize();
Mehdi Amini01e32132016-03-26 05:40:34 +0000633 GlobalsToImport.insert(GO);
Mehdi Amini01e32132016-03-26 05:40:34 +0000634 GV.materialize();
635 GlobalsToImport.insert(&GV);
636 }
637 }
638
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000639 // Link in the specified functions.
Mehdi Amini01e32132016-03-26 05:40:34 +0000640 if (renameModuleForThinLTO(*SrcModule, Index, &GlobalsToImport))
Mehdi Amini8d051852016-03-19 00:40:31 +0000641 return true;
642
Teresa Johnsond29478f2016-03-27 15:27:30 +0000643 if (PrintImports) {
644 for (const auto *GV : GlobalsToImport)
645 dbgs() << DestModule.getSourceFileName() << ": Import " << GV->getName()
646 << " from " << SrcModule->getSourceFileName() << "\n";
647 }
648
Mehdi Aminibda3c972016-04-21 01:59:39 +0000649 // Instruct the linker that the client will take care of linkonce resolution
650 unsigned Flags = Linker::Flags::None;
651 if (!ForceImportReferencedDiscardableSymbols)
652 Flags |= Linker::Flags::DontForceLinkLinkonceODR;
653
654 if (TheLinker.linkInModule(std::move(SrcModule), Flags, &GlobalsToImport))
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000655 report_fatal_error("Function Import: link error");
656
Mehdi Amini01e32132016-03-26 05:40:34 +0000657 ImportedCount += GlobalsToImport.size();
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000658 }
Teresa Johnsone5a61912015-12-17 17:14:09 +0000659
Teresa Johnsond29478f2016-03-27 15:27:30 +0000660 NumImported += ImportedCount;
661
Mehdi Amini7e88d0d2015-12-09 08:17:35 +0000662 DEBUG(dbgs() << "Imported " << ImportedCount << " functions for Module "
Mehdi Aminic8c55172015-12-03 02:37:33 +0000663 << DestModule.getModuleIdentifier() << "\n");
664 return ImportedCount;
Mehdi Amini42418ab2015-11-24 06:07:49 +0000665}
666
667/// Summary file to use for function importing when using -function-import from
668/// the command line.
669static cl::opt<std::string>
670 SummaryFile("summary-file",
671 cl::desc("The summary file to use for function importing."));
672
673static void diagnosticHandler(const DiagnosticInfo &DI) {
674 raw_ostream &OS = errs();
675 DiagnosticPrinterRawOStream DP(OS);
676 DI.print(DP);
677 OS << '\n';
678}
679
Teresa Johnson26ab5772016-03-15 00:04:37 +0000680/// Parse the summary index out of an IR file and return the summary
Mehdi Amini42418ab2015-11-24 06:07:49 +0000681/// index object if found, or nullptr if not.
Teresa Johnson26ab5772016-03-15 00:04:37 +0000682static std::unique_ptr<ModuleSummaryIndex>
683getModuleSummaryIndexForFile(StringRef Path, std::string &Error,
684 DiagnosticHandlerFunction DiagnosticHandler) {
Mehdi Amini42418ab2015-11-24 06:07:49 +0000685 std::unique_ptr<MemoryBuffer> Buffer;
686 ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
687 MemoryBuffer::getFile(Path);
688 if (std::error_code EC = BufferOrErr.getError()) {
689 Error = EC.message();
690 return nullptr;
691 }
692 Buffer = std::move(BufferOrErr.get());
Teresa Johnson26ab5772016-03-15 00:04:37 +0000693 ErrorOr<std::unique_ptr<object::ModuleSummaryIndexObjectFile>> ObjOrErr =
694 object::ModuleSummaryIndexObjectFile::create(Buffer->getMemBufferRef(),
695 DiagnosticHandler);
Mehdi Amini42418ab2015-11-24 06:07:49 +0000696 if (std::error_code EC = ObjOrErr.getError()) {
697 Error = EC.message();
698 return nullptr;
699 }
700 return (*ObjOrErr)->takeIndex();
701}
702
Benjamin Kramerfe2b5412015-12-24 10:03:35 +0000703namespace {
Mehdi Amini42418ab2015-11-24 06:07:49 +0000704/// Pass that performs cross-module function import provided a summary file.
705class FunctionImportPass : public ModulePass {
Teresa Johnson26ab5772016-03-15 00:04:37 +0000706 /// Optional module summary index to use for importing, otherwise
Teresa Johnson5fcbdb72015-12-07 19:21:11 +0000707 /// the summary-file option must be specified.
Teresa Johnson26ab5772016-03-15 00:04:37 +0000708 const ModuleSummaryIndex *Index;
Mehdi Amini42418ab2015-11-24 06:07:49 +0000709
710public:
711 /// Pass identification, replacement for typeid
712 static char ID;
713
Teresa Johnson5fcbdb72015-12-07 19:21:11 +0000714 /// Specify pass name for debug output
Mehdi Amini2d28f7a2016-04-16 06:56:44 +0000715 const char *getPassName() const override { return "Function Importing"; }
Teresa Johnson5fcbdb72015-12-07 19:21:11 +0000716
Teresa Johnson26ab5772016-03-15 00:04:37 +0000717 explicit FunctionImportPass(const ModuleSummaryIndex *Index = nullptr)
Teresa Johnson5fcbdb72015-12-07 19:21:11 +0000718 : ModulePass(ID), Index(Index) {}
Mehdi Amini42418ab2015-11-24 06:07:49 +0000719
720 bool runOnModule(Module &M) override {
Andrew Kayloraa641a52016-04-22 22:06:11 +0000721 if (skipModule(M))
722 return false;
723
Teresa Johnson5fcbdb72015-12-07 19:21:11 +0000724 if (SummaryFile.empty() && !Index)
725 report_fatal_error("error: -function-import requires -summary-file or "
726 "file from frontend\n");
Teresa Johnson26ab5772016-03-15 00:04:37 +0000727 std::unique_ptr<ModuleSummaryIndex> IndexPtr;
Teresa Johnson5fcbdb72015-12-07 19:21:11 +0000728 if (!SummaryFile.empty()) {
729 if (Index)
730 report_fatal_error("error: -summary-file and index from frontend\n");
731 std::string Error;
Teresa Johnson26ab5772016-03-15 00:04:37 +0000732 IndexPtr =
733 getModuleSummaryIndexForFile(SummaryFile, Error, diagnosticHandler);
Teresa Johnson5fcbdb72015-12-07 19:21:11 +0000734 if (!IndexPtr) {
735 errs() << "Error loading file '" << SummaryFile << "': " << Error
736 << "\n";
737 return false;
738 }
739 Index = IndexPtr.get();
Mehdi Amini42418ab2015-11-24 06:07:49 +0000740 }
741
Teresa Johnsonc86af332016-04-12 21:13:11 +0000742 // First step is collecting the import list.
743 FunctionImporter::ImportMapTy ImportList;
744 ComputeCrossModuleImportForModule(M.getModuleIdentifier(), *Index,
745 ImportList);
Mehdi Amini01e32132016-03-26 05:40:34 +0000746
747 // Next we need to promote to global scope and rename any local values that
Teresa Johnson1b00f2d2016-01-08 17:06:29 +0000748 // are potentially exported to other modules.
Mehdi Amini01e32132016-03-26 05:40:34 +0000749 if (renameModuleForThinLTO(M, *Index, nullptr)) {
Teresa Johnson1b00f2d2016-01-08 17:06:29 +0000750 errs() << "Error renaming module\n";
751 return false;
752 }
753
Mehdi Amini42418ab2015-11-24 06:07:49 +0000754 // Perform the import now.
Mehdi Aminid16c8062015-12-08 22:39:40 +0000755 auto ModuleLoader = [&M](StringRef Identifier) {
756 return loadFile(Identifier, M.getContext());
757 };
Rafael Espindola9d2bfc42015-12-14 23:17:03 +0000758 FunctionImporter Importer(*Index, ModuleLoader);
Mehdi Aminibda3c972016-04-21 01:59:39 +0000759 return Importer.importFunctions(
760 M, ImportList, !DontForceImportReferencedDiscardableSymbols);
Mehdi Amini42418ab2015-11-24 06:07:49 +0000761 }
762};
Benjamin Kramerfe2b5412015-12-24 10:03:35 +0000763} // anonymous namespace
Mehdi Amini42418ab2015-11-24 06:07:49 +0000764
765char FunctionImportPass::ID = 0;
766INITIALIZE_PASS_BEGIN(FunctionImportPass, "function-import",
767 "Summary Based Function Import", false, false)
768INITIALIZE_PASS_END(FunctionImportPass, "function-import",
769 "Summary Based Function Import", false, false)
770
771namespace llvm {
Teresa Johnson26ab5772016-03-15 00:04:37 +0000772Pass *createFunctionImportPass(const ModuleSummaryIndex *Index = nullptr) {
Teresa Johnson5fcbdb72015-12-07 19:21:11 +0000773 return new FunctionImportPass(Index);
774}
Mehdi Amini42418ab2015-11-24 06:07:49 +0000775}