1488a800aSTeresa Johnson //===- lib/Transforms/Utils/FunctionImportUtils.cpp - Importing utilities -===//
2488a800aSTeresa Johnson //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6488a800aSTeresa Johnson //
7488a800aSTeresa Johnson //===----------------------------------------------------------------------===//
8488a800aSTeresa Johnson //
9488a800aSTeresa Johnson // This file implements the FunctionImportGlobalProcessing class, used
10488a800aSTeresa Johnson // to perform the necessary global value handling for function importing.
11488a800aSTeresa Johnson //
12488a800aSTeresa Johnson //===----------------------------------------------------------------------===//
13488a800aSTeresa Johnson 
14488a800aSTeresa Johnson #include "llvm/Transforms/Utils/FunctionImportUtils.h"
15488a800aSTeresa Johnson using namespace llvm;
16488a800aSTeresa Johnson 
17488a800aSTeresa Johnson /// Checks if we should import SGV as a definition, otherwise import as a
18488a800aSTeresa Johnson /// declaration.
doImportAsDefinition(const GlobalValue * SGV)19488a800aSTeresa Johnson bool FunctionImportGlobalProcessing::doImportAsDefinition(
20cc1b0bc2STeresa Johnson     const GlobalValue *SGV) {
21cc1b0bc2STeresa Johnson   if (!isPerformingImport())
22cc1b0bc2STeresa Johnson     return false;
238d05185aSMehdi Amini 
248d05185aSMehdi Amini   // Only import the globals requested for importing.
2572c0b1ccSDavid Blaikie   if (!GlobalsToImport->count(const_cast<GlobalValue *>(SGV)))
2672c0b1ccSDavid Blaikie     return false;
272f0cc477SDavid Blaikie 
282f0cc477SDavid Blaikie   assert(!isa<GlobalAlias>(SGV) &&
292f0cc477SDavid Blaikie          "Unexpected global alias in the import list.");
302f0cc477SDavid Blaikie 
3172c0b1ccSDavid Blaikie   // Otherwise yes.
3272c0b1ccSDavid Blaikie   return true;
33488a800aSTeresa Johnson }
34488a800aSTeresa Johnson 
shouldPromoteLocalToGlobal(const GlobalValue * SGV,ValueInfo VI)3538d4df71STeresa Johnson bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal(
36cc1b0bc2STeresa Johnson     const GlobalValue *SGV, ValueInfo VI) {
37488a800aSTeresa Johnson   assert(SGV->hasLocalLinkage());
38*30402720SSchrodinger ZHU Yifan 
39*30402720SSchrodinger ZHU Yifan   // Ifuncs and ifunc alias does not have summary.
40*30402720SSchrodinger ZHU Yifan   if (isa<GlobalIFunc>(SGV) ||
41*30402720SSchrodinger ZHU Yifan       (isa<GlobalAlias>(SGV) &&
42*30402720SSchrodinger ZHU Yifan        isa<GlobalIFunc>(cast<GlobalAlias>(SGV)->getAliaseeObject())))
43*30402720SSchrodinger ZHU Yifan     return false;
44*30402720SSchrodinger ZHU Yifan 
45488a800aSTeresa Johnson   // Both the imported references and the original local variable must
46488a800aSTeresa Johnson   // be promoted.
47488a800aSTeresa Johnson   if (!isPerformingImport() && !isModuleExporting())
48488a800aSTeresa Johnson     return false;
49488a800aSTeresa Johnson 
504fef68cbSTeresa Johnson   if (isPerformingImport()) {
516d8f817fSPeter Collingbourne     assert((!GlobalsToImport->count(const_cast<GlobalValue *>(SGV)) ||
526d8f817fSPeter Collingbourne             !isNonRenamableLocal(*SGV)) &&
53519465b9STeresa Johnson            "Attempting to promote non-renamable local");
544fef68cbSTeresa Johnson     // We don't know for sure yet if we are importing this value (as either
554fef68cbSTeresa Johnson     // a reference or a def), since we are simply walking all values in the
564fef68cbSTeresa Johnson     // module. But by necessity if we end up importing it and it is local,
574fef68cbSTeresa Johnson     // it must be promoted, so unconditionally promote all values in the
584fef68cbSTeresa Johnson     // importing module.
594fef68cbSTeresa Johnson     return true;
600515fb8dSTeresa Johnson   }
61b4e1e829SMehdi Amini 
629006d526STeresa Johnson   // When exporting, consult the index. We can have more than one local
639006d526STeresa Johnson   // with the same GUID, in the case of same-named locals in different but
649006d526STeresa Johnson   // same-named source files that were compiled in their respective directories
659006d526STeresa Johnson   // (so the source file name and resulting GUID is the same). Find the one
669006d526STeresa Johnson   // in this module.
679006d526STeresa Johnson   auto Summary = ImportIndex.findSummaryInModule(
68cc1b0bc2STeresa Johnson       VI, SGV->getParent()->getModuleIdentifier());
699006d526STeresa Johnson   assert(Summary && "Missing summary for global value when exporting");
709006d526STeresa Johnson   auto Linkage = Summary->linkage();
714fef68cbSTeresa Johnson   if (!GlobalValue::isLocalLinkage(Linkage)) {
72519465b9STeresa Johnson     assert(!isNonRenamableLocal(*SGV) &&
73519465b9STeresa Johnson            "Attempting to promote non-renamable local");
74488a800aSTeresa Johnson     return true;
75488a800aSTeresa Johnson   }
76488a800aSTeresa Johnson 
774fef68cbSTeresa Johnson   return false;
784fef68cbSTeresa Johnson }
794fef68cbSTeresa Johnson 
80519465b9STeresa Johnson #ifndef NDEBUG
isNonRenamableLocal(const GlobalValue & GV) const81519465b9STeresa Johnson bool FunctionImportGlobalProcessing::isNonRenamableLocal(
82519465b9STeresa Johnson     const GlobalValue &GV) const {
83519465b9STeresa Johnson   if (!GV.hasLocalLinkage())
84519465b9STeresa Johnson     return false;
85519465b9STeresa Johnson   // This needs to stay in sync with the logic in buildModuleSummaryIndex.
86519465b9STeresa Johnson   if (GV.hasSection())
87519465b9STeresa Johnson     return true;
88519465b9STeresa Johnson   if (Used.count(const_cast<GlobalValue *>(&GV)))
89519465b9STeresa Johnson     return true;
90519465b9STeresa Johnson   return false;
91519465b9STeresa Johnson }
92519465b9STeresa Johnson #endif
93519465b9STeresa Johnson 
943be6dbcaSTeresa Johnson std::string
getPromotedName(const GlobalValue * SGV)953be6dbcaSTeresa Johnson FunctionImportGlobalProcessing::getPromotedName(const GlobalValue *SGV) {
963be6dbcaSTeresa Johnson   assert(SGV->hasLocalLinkage());
97488a800aSTeresa Johnson   // For locals that must be promoted to global scope, ensure that
98488a800aSTeresa Johnson   // the promoted name uniquely identifies the copy in the original module,
993be6dbcaSTeresa Johnson   // using the ID assigned during combined index creation.
10026ab5772STeresa Johnson   return ModuleSummaryIndex::getGlobalNameForLocal(
101488a800aSTeresa Johnson       SGV->getName(),
102ae280e54SMehdi Amini       ImportIndex.getModuleHash(SGV->getParent()->getModuleIdentifier()));
103488a800aSTeresa Johnson }
104488a800aSTeresa Johnson 
105488a800aSTeresa Johnson GlobalValue::LinkageTypes
getLinkage(const GlobalValue * SGV,bool DoPromote)1061b9c2be8STeresa Johnson FunctionImportGlobalProcessing::getLinkage(const GlobalValue *SGV,
1071b9c2be8STeresa Johnson                                            bool DoPromote) {
108488a800aSTeresa Johnson   // Any local variable that is referenced by an exported function needs
109488a800aSTeresa Johnson   // to be promoted to global scope. Since we don't currently know which
110488a800aSTeresa Johnson   // functions reference which local variables/functions, we must treat
111488a800aSTeresa Johnson   // all as potentially exported if this module is exporting anything.
112488a800aSTeresa Johnson   if (isModuleExporting()) {
1131b9c2be8STeresa Johnson     if (SGV->hasLocalLinkage() && DoPromote)
114488a800aSTeresa Johnson       return GlobalValue::ExternalLinkage;
115488a800aSTeresa Johnson     return SGV->getLinkage();
116488a800aSTeresa Johnson   }
117488a800aSTeresa Johnson 
118488a800aSTeresa Johnson   // Otherwise, if we aren't importing, no linkage change is needed.
119488a800aSTeresa Johnson   if (!isPerformingImport())
120488a800aSTeresa Johnson     return SGV->getLinkage();
121488a800aSTeresa Johnson 
122488a800aSTeresa Johnson   switch (SGV->getLinkage()) {
1232f0cc477SDavid Blaikie   case GlobalValue::LinkOnceODRLinkage:
124488a800aSTeresa Johnson   case GlobalValue::ExternalLinkage:
1252f0cc477SDavid Blaikie     // External and linkonce definitions are converted to available_externally
126488a800aSTeresa Johnson     // definitions upon import, so that they are available for inlining
127488a800aSTeresa Johnson     // and/or optimization, but are turned into declarations later
128488a800aSTeresa Johnson     // during the EliminateAvailableExternally pass.
1292c5c12c0SFangrui Song     if (doImportAsDefinition(SGV) && !isa<GlobalAlias>(SGV))
130488a800aSTeresa Johnson       return GlobalValue::AvailableExternallyLinkage;
131488a800aSTeresa Johnson     // An imported external declaration stays external.
132488a800aSTeresa Johnson     return SGV->getLinkage();
133488a800aSTeresa Johnson 
134488a800aSTeresa Johnson   case GlobalValue::AvailableExternallyLinkage:
135488a800aSTeresa Johnson     // An imported available_externally definition converts
136488a800aSTeresa Johnson     // to external if imported as a declaration.
137488a800aSTeresa Johnson     if (!doImportAsDefinition(SGV))
138488a800aSTeresa Johnson       return GlobalValue::ExternalLinkage;
139488a800aSTeresa Johnson     // An imported available_externally declaration stays that way.
140488a800aSTeresa Johnson     return SGV->getLinkage();
141488a800aSTeresa Johnson 
14253e52e47SXin Tong   case GlobalValue::LinkOnceAnyLinkage:
143488a800aSTeresa Johnson   case GlobalValue::WeakAnyLinkage:
14453e52e47SXin Tong     // Can't import linkonce_any/weak_any definitions correctly, or we might
14553e52e47SXin Tong     // change the program semantics, since the linker will pick the first
14653e52e47SXin Tong     // linkonce_any/weak_any definition and importing would change the order
14753e52e47SXin Tong     // they are seen by the linker. The module linking caller needs to enforce
14853e52e47SXin Tong     // this.
149488a800aSTeresa Johnson     assert(!doImportAsDefinition(SGV));
150488a800aSTeresa Johnson     // If imported as a declaration, it becomes external_weak.
151bb3a1d92SMehdi Amini     return SGV->getLinkage();
152488a800aSTeresa Johnson 
153488a800aSTeresa Johnson   case GlobalValue::WeakODRLinkage:
154488a800aSTeresa Johnson     // For weak_odr linkage, there is a guarantee that all copies will be
155488a800aSTeresa Johnson     // equivalent, so the issue described above for weak_any does not exist,
156488a800aSTeresa Johnson     // and the definition can be imported. It can be treated similarly
157488a800aSTeresa Johnson     // to an imported externally visible global value.
1582c5c12c0SFangrui Song     if (doImportAsDefinition(SGV) && !isa<GlobalAlias>(SGV))
159488a800aSTeresa Johnson       return GlobalValue::AvailableExternallyLinkage;
160488a800aSTeresa Johnson     else
161488a800aSTeresa Johnson       return GlobalValue::ExternalLinkage;
162488a800aSTeresa Johnson 
163488a800aSTeresa Johnson   case GlobalValue::AppendingLinkage:
164488a800aSTeresa Johnson     // It would be incorrect to import an appending linkage variable,
165488a800aSTeresa Johnson     // since it would cause global constructors/destructors to be
166488a800aSTeresa Johnson     // executed multiple times. This should have already been handled
167488a800aSTeresa Johnson     // by linkIfNeeded, and we will assert in shouldLinkFromSource
168488a800aSTeresa Johnson     // if we try to import, so we simply return AppendingLinkage.
169488a800aSTeresa Johnson     return GlobalValue::AppendingLinkage;
170488a800aSTeresa Johnson 
171488a800aSTeresa Johnson   case GlobalValue::InternalLinkage:
172488a800aSTeresa Johnson   case GlobalValue::PrivateLinkage:
173488a800aSTeresa Johnson     // If we are promoting the local to global scope, it is handled
174488a800aSTeresa Johnson     // similarly to a normal externally visible global.
1751b9c2be8STeresa Johnson     if (DoPromote) {
1762c5c12c0SFangrui Song       if (doImportAsDefinition(SGV) && !isa<GlobalAlias>(SGV))
177488a800aSTeresa Johnson         return GlobalValue::AvailableExternallyLinkage;
178488a800aSTeresa Johnson       else
179488a800aSTeresa Johnson         return GlobalValue::ExternalLinkage;
180488a800aSTeresa Johnson     }
181488a800aSTeresa Johnson     // A non-promoted imported local definition stays local.
182488a800aSTeresa Johnson     // The ThinLTO pass will eventually force-import their definitions.
183488a800aSTeresa Johnson     return SGV->getLinkage();
184488a800aSTeresa Johnson 
185488a800aSTeresa Johnson   case GlobalValue::ExternalWeakLinkage:
186488a800aSTeresa Johnson     // External weak doesn't apply to definitions, must be a declaration.
187488a800aSTeresa Johnson     assert(!doImportAsDefinition(SGV));
188488a800aSTeresa Johnson     // Linkage stays external_weak.
189488a800aSTeresa Johnson     return SGV->getLinkage();
190488a800aSTeresa Johnson 
191488a800aSTeresa Johnson   case GlobalValue::CommonLinkage:
192488a800aSTeresa Johnson     // Linkage stays common on definitions.
193488a800aSTeresa Johnson     // The ThinLTO pass will eventually force-import their definitions.
194488a800aSTeresa Johnson     return SGV->getLinkage();
195488a800aSTeresa Johnson   }
196488a800aSTeresa Johnson 
197488a800aSTeresa Johnson   llvm_unreachable("unknown linkage type");
198488a800aSTeresa Johnson }
199488a800aSTeresa Johnson 
processGlobalForThinLTO(GlobalValue & GV)200488a800aSTeresa Johnson void FunctionImportGlobalProcessing::processGlobalForThinLTO(GlobalValue &GV) {
2014595a915SSean Fertile 
202bf46e741SEugene Leviant   ValueInfo VI;
2034595a915SSean Fertile   if (GV.hasName()) {
204bf46e741SEugene Leviant     VI = ImportIndex.getValueInfo(GV.getGUID());
2055a7056faSEaswaran Raman     // Set synthetic function entry counts.
2065a7056faSEaswaran Raman     if (VI && ImportIndex.hasSyntheticEntryCounts()) {
2075a7056faSEaswaran Raman       if (Function *F = dyn_cast<Function>(&GV)) {
2085a7056faSEaswaran Raman         if (!F->isDeclaration()) {
2095a7056faSEaswaran Raman           for (auto &S : VI.getSummaryList()) {
210f71f23d1SSimon Pilgrim             auto *FS = cast<FunctionSummary>(S->getBaseObject());
2115a7056faSEaswaran Raman             if (FS->modulePath() == M.getModuleIdentifier()) {
2125a7056faSEaswaran Raman               F->setEntryCount(Function::ProfileCount(FS->entryCount(),
2135a7056faSEaswaran Raman                                                       Function::PCT_Synthetic));
2145a7056faSEaswaran Raman               break;
2155a7056faSEaswaran Raman             }
2165a7056faSEaswaran Raman           }
2175a7056faSEaswaran Raman         }
2185a7056faSEaswaran Raman       }
2195a7056faSEaswaran Raman     }
2204595a915SSean Fertile   }
2214595a915SSean Fertile 
222cc1b0bc2STeresa Johnson   // We should always have a ValueInfo (i.e. GV in index) for definitions when
223cc1b0bc2STeresa Johnson   // we are exporting, and also when importing that value.
224cc1b0bc2STeresa Johnson   assert(VI || GV.isDeclaration() ||
225cc1b0bc2STeresa Johnson          (isPerformingImport() && !doImportAsDefinition(&GV)));
226cc1b0bc2STeresa Johnson 
2273aef3528SEugene Leviant   // Mark read/write-only variables which can be imported with specific
2283aef3528SEugene Leviant   // attribute. We can't internalize them now because IRMover will fail
2293aef3528SEugene Leviant   // to link variable definitions to their external declarations during
2303aef3528SEugene Leviant   // ThinLTO import. We'll internalize read-only variables later, after
2313aef3528SEugene Leviant   // import is finished. See internalizeGVsAfterImport.
232bf46e741SEugene Leviant   //
233bf46e741SEugene Leviant   // If global value dead stripping is not enabled in summary then
234bf46e741SEugene Leviant   // propagateConstants hasn't been run. We can't internalize GV
235bf46e741SEugene Leviant   // in such case.
236dde58938Sevgeny   if (!GV.isDeclaration() && VI && ImportIndex.withAttributePropagation()) {
23716ec00eeSTeresa Johnson     if (GlobalVariable *V = dyn_cast<GlobalVariable>(&GV)) {
23816ec00eeSTeresa Johnson       // We can have more than one local with the same GUID, in the case of
23916ec00eeSTeresa Johnson       // same-named locals in different but same-named source files that were
24016ec00eeSTeresa Johnson       // compiled in their respective directories (so the source file name
24116ec00eeSTeresa Johnson       // and resulting GUID is the same). Find the one in this module.
24216ec00eeSTeresa Johnson       // Handle the case where there is no summary found in this module. That
24316ec00eeSTeresa Johnson       // can happen in the distributed ThinLTO backend, because the index only
24416ec00eeSTeresa Johnson       // contains summaries from the source modules if they are being imported.
24516ec00eeSTeresa Johnson       // We might have a non-null VI and get here even in that case if the name
24616ec00eeSTeresa Johnson       // matches one in this module (e.g. weak or appending linkage).
24716ec00eeSTeresa Johnson       auto *GVS = dyn_cast_or_null<GlobalVarSummary>(
24816ec00eeSTeresa Johnson           ImportIndex.findSummaryInModule(VI, M.getModuleIdentifier()));
2497f92d66fSevgeny       if (GVS &&
2507f92d66fSevgeny           (ImportIndex.isReadOnly(GVS) || ImportIndex.isWriteOnly(GVS))) {
25116ec00eeSTeresa Johnson         V->addAttribute("thinlto-internalize");
2527f92d66fSevgeny         // Objects referenced by writeonly GV initializer should not be
2537f92d66fSevgeny         // promoted, because there is no any kind of read access to them
2547f92d66fSevgeny         // on behalf of this writeonly GV. To avoid promotion we convert
2557f92d66fSevgeny         // GV initializer to 'zeroinitializer'. This effectively drops
2567f92d66fSevgeny         // references in IR module (not in combined index), so we can
2577f92d66fSevgeny         // ignore them when computing import. We do not export references
2587f92d66fSevgeny         // of writeonly object. See computeImportForReferencedGlobals
259e420c0c7STeresa Johnson         if (ImportIndex.isWriteOnly(GVS))
2607f92d66fSevgeny           V->setInitializer(Constant::getNullValue(V->getValueType()));
2617f92d66fSevgeny       }
26216ec00eeSTeresa Johnson     }
263bf46e741SEugene Leviant   }
264bf46e741SEugene Leviant 
265cc1b0bc2STeresa Johnson   if (GV.hasLocalLinkage() && shouldPromoteLocalToGlobal(&GV, VI)) {
266f59242e5STeresa Johnson     // Save the original name string before we rename GV below.
267f59242e5STeresa Johnson     auto Name = GV.getName().str();
2683be6dbcaSTeresa Johnson     GV.setName(getPromotedName(&GV));
2693be6dbcaSTeresa Johnson     GV.setLinkage(getLinkage(&GV, /* DoPromote */ true));
2703be6dbcaSTeresa Johnson     assert(!GV.hasLocalLinkage());
271488a800aSTeresa Johnson     GV.setVisibility(GlobalValue::HiddenVisibility);
272f59242e5STeresa Johnson 
273f59242e5STeresa Johnson     // If we are renaming a COMDAT leader, ensure that we record the COMDAT
274f59242e5STeresa Johnson     // for later renaming as well. This is required for COFF.
275f59242e5STeresa Johnson     if (const auto *C = GV.getComdat())
276f59242e5STeresa Johnson       if (C->getName() == Name)
277f59242e5STeresa Johnson         RenamedComdats.try_emplace(C, M.getOrInsertComdat(GV.getName()));
278488a800aSTeresa Johnson   } else
2791b9c2be8STeresa Johnson     GV.setLinkage(getLinkage(&GV, /* DoPromote */ false));
280488a800aSTeresa Johnson 
281d2ef8c1fSFangrui Song   // When ClearDSOLocalOnDeclarations is true, clear dso_local if GV is
282d2ef8c1fSFangrui Song   // converted to a declaration, to disable direct access. Don't do this if GV
283d2ef8c1fSFangrui Song   // is implicitly dso_local due to a non-default visibility.
284252a1eecSFangrui Song   if (ClearDSOLocalOnDeclarations &&
285252a1eecSFangrui Song       (GV.isDeclarationForLinker() ||
286252a1eecSFangrui Song        (isPerformingImport() && !doImportAsDefinition(&GV))) &&
287d2ef8c1fSFangrui Song       !GV.isImplicitDSOLocal()) {
288d2ef8c1fSFangrui Song     GV.setDSOLocal(false);
28980dc0661SWei Wang   } else if (VI && VI.isDSOLocal(ImportIndex.withDSOLocalPropagation())) {
290d2ef8c1fSFangrui Song     // If all summaries are dso_local, symbol gets resolved to a known local
291d2ef8c1fSFangrui Song     // definition.
292d2ef8c1fSFangrui Song     GV.setDSOLocal(true);
293d2ef8c1fSFangrui Song     if (GV.hasDLLImportStorageClass())
294d2ef8c1fSFangrui Song       GV.setDLLStorageClass(GlobalValue::DefaultStorageClass);
295d2ef8c1fSFangrui Song   }
296d2ef8c1fSFangrui Song 
297488a800aSTeresa Johnson   // Remove functions imported as available externally defs from comdats,
298488a800aSTeresa Johnson   // as this is a declaration for the linker, and will be dropped eventually.
299488a800aSTeresa Johnson   // It is illegal for comdats to contain declarations.
300bf46e741SEugene Leviant   auto *GO = dyn_cast<GlobalObject>(&GV);
301488a800aSTeresa Johnson   if (GO && GO->isDeclarationForLinker() && GO->hasComdat()) {
302488a800aSTeresa Johnson     // The IRMover should not have placed any imported declarations in
303488a800aSTeresa Johnson     // a comdat, so the only declaration that should be in a comdat
304488a800aSTeresa Johnson     // at this point would be a definition imported as available_externally.
305488a800aSTeresa Johnson     assert(GO->hasAvailableExternallyLinkage() &&
306488a800aSTeresa Johnson            "Expected comdat on definition (possibly available external)");
307488a800aSTeresa Johnson     GO->setComdat(nullptr);
308488a800aSTeresa Johnson   }
309488a800aSTeresa Johnson }
310488a800aSTeresa Johnson 
processGlobalsForThinLTO()311488a800aSTeresa Johnson void FunctionImportGlobalProcessing::processGlobalsForThinLTO() {
312488a800aSTeresa Johnson   for (GlobalVariable &GV : M.globals())
313488a800aSTeresa Johnson     processGlobalForThinLTO(GV);
314488a800aSTeresa Johnson   for (Function &SF : M)
315488a800aSTeresa Johnson     processGlobalForThinLTO(SF);
316488a800aSTeresa Johnson   for (GlobalAlias &GA : M.aliases())
317488a800aSTeresa Johnson     processGlobalForThinLTO(GA);
318f59242e5STeresa Johnson 
319f59242e5STeresa Johnson   // Replace any COMDATS that required renaming (because the COMDAT leader was
320f59242e5STeresa Johnson   // promoted and renamed).
321f59242e5STeresa Johnson   if (!RenamedComdats.empty())
322f59242e5STeresa Johnson     for (auto &GO : M.global_objects())
323f59242e5STeresa Johnson       if (auto *C = GO.getComdat()) {
324f59242e5STeresa Johnson         auto Replacement = RenamedComdats.find(C);
325f59242e5STeresa Johnson         if (Replacement != RenamedComdats.end())
326f59242e5STeresa Johnson           GO.setComdat(Replacement->second);
327f59242e5STeresa Johnson       }
328488a800aSTeresa Johnson }
329488a800aSTeresa Johnson 
run()330488a800aSTeresa Johnson bool FunctionImportGlobalProcessing::run() {
331488a800aSTeresa Johnson   processGlobalsForThinLTO();
332488a800aSTeresa Johnson   return false;
333488a800aSTeresa Johnson }
334488a800aSTeresa Johnson 
renameModuleForThinLTO(Module & M,const ModuleSummaryIndex & Index,bool ClearDSOLocalOnDeclarations,SetVector<GlobalValue * > * GlobalsToImport)3356d8f817fSPeter Collingbourne bool llvm::renameModuleForThinLTO(Module &M, const ModuleSummaryIndex &Index,
336d2ef8c1fSFangrui Song                                   bool ClearDSOLocalOnDeclarations,
3376d8f817fSPeter Collingbourne                                   SetVector<GlobalValue *> *GlobalsToImport) {
338d2ef8c1fSFangrui Song   FunctionImportGlobalProcessing ThinLTOProcessing(M, Index, GlobalsToImport,
339d2ef8c1fSFangrui Song                                                    ClearDSOLocalOnDeclarations);
340488a800aSTeresa Johnson   return ThinLTOProcessing.run();
341488a800aSTeresa Johnson }
342