xref: /aosp_15_r20/external/llvm/lib/Transforms/IPO/Internalize.cpp (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===-- Internalize.cpp - Mark functions internal -------------------------===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This pass loops over all of the functions and variables in the input module.
11*9880d681SAndroid Build Coastguard Worker // If the function or variable does not need to be preserved according to the
12*9880d681SAndroid Build Coastguard Worker // client supplied callback, it is marked as internal.
13*9880d681SAndroid Build Coastguard Worker //
14*9880d681SAndroid Build Coastguard Worker // This transformation would not be legal in a regular compilation, but it gets
15*9880d681SAndroid Build Coastguard Worker // extra information from the linker about what is safe.
16*9880d681SAndroid Build Coastguard Worker //
17*9880d681SAndroid Build Coastguard Worker // For example: Internalizing a function with external linkage. Only if we are
18*9880d681SAndroid Build Coastguard Worker // told it is only used from within this module, it is safe to do it.
19*9880d681SAndroid Build Coastguard Worker //
20*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
21*9880d681SAndroid Build Coastguard Worker 
22*9880d681SAndroid Build Coastguard Worker #include "llvm/Transforms/IPO/Internalize.h"
23*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/SmallPtrSet.h"
24*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/Statistic.h"
25*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/StringSet.h"
26*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/CallGraph.h"
27*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/Module.h"
28*9880d681SAndroid Build Coastguard Worker #include "llvm/Pass.h"
29*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/CommandLine.h"
30*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Debug.h"
31*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/raw_ostream.h"
32*9880d681SAndroid Build Coastguard Worker #include "llvm/Transforms/IPO.h"
33*9880d681SAndroid Build Coastguard Worker #include "llvm/Transforms/Utils/GlobalStatus.h"
34*9880d681SAndroid Build Coastguard Worker #include <fstream>
35*9880d681SAndroid Build Coastguard Worker #include <set>
36*9880d681SAndroid Build Coastguard Worker using namespace llvm;
37*9880d681SAndroid Build Coastguard Worker 
38*9880d681SAndroid Build Coastguard Worker #define DEBUG_TYPE "internalize"
39*9880d681SAndroid Build Coastguard Worker 
40*9880d681SAndroid Build Coastguard Worker STATISTIC(NumAliases, "Number of aliases internalized");
41*9880d681SAndroid Build Coastguard Worker STATISTIC(NumFunctions, "Number of functions internalized");
42*9880d681SAndroid Build Coastguard Worker STATISTIC(NumGlobals, "Number of global vars internalized");
43*9880d681SAndroid Build Coastguard Worker 
44*9880d681SAndroid Build Coastguard Worker // APIFile - A file which contains a list of symbols that should not be marked
45*9880d681SAndroid Build Coastguard Worker // external.
46*9880d681SAndroid Build Coastguard Worker static cl::opt<std::string>
47*9880d681SAndroid Build Coastguard Worker     APIFile("internalize-public-api-file", cl::value_desc("filename"),
48*9880d681SAndroid Build Coastguard Worker             cl::desc("A file containing list of symbol names to preserve"));
49*9880d681SAndroid Build Coastguard Worker 
50*9880d681SAndroid Build Coastguard Worker // APIList - A list of symbols that should not be marked internal.
51*9880d681SAndroid Build Coastguard Worker static cl::list<std::string>
52*9880d681SAndroid Build Coastguard Worker     APIList("internalize-public-api-list", cl::value_desc("list"),
53*9880d681SAndroid Build Coastguard Worker             cl::desc("A list of symbol names to preserve"), cl::CommaSeparated);
54*9880d681SAndroid Build Coastguard Worker 
55*9880d681SAndroid Build Coastguard Worker namespace {
56*9880d681SAndroid Build Coastguard Worker // Helper to load an API list to preserve from file and expose it as a functor
57*9880d681SAndroid Build Coastguard Worker // for internalization.
58*9880d681SAndroid Build Coastguard Worker class PreserveAPIList {
59*9880d681SAndroid Build Coastguard Worker public:
PreserveAPIList()60*9880d681SAndroid Build Coastguard Worker   PreserveAPIList() {
61*9880d681SAndroid Build Coastguard Worker     if (!APIFile.empty())
62*9880d681SAndroid Build Coastguard Worker       LoadFile(APIFile);
63*9880d681SAndroid Build Coastguard Worker     ExternalNames.insert(APIList.begin(), APIList.end());
64*9880d681SAndroid Build Coastguard Worker   }
65*9880d681SAndroid Build Coastguard Worker 
operator ()(const GlobalValue & GV)66*9880d681SAndroid Build Coastguard Worker   bool operator()(const GlobalValue &GV) {
67*9880d681SAndroid Build Coastguard Worker     return ExternalNames.count(GV.getName());
68*9880d681SAndroid Build Coastguard Worker   }
69*9880d681SAndroid Build Coastguard Worker 
70*9880d681SAndroid Build Coastguard Worker private:
71*9880d681SAndroid Build Coastguard Worker   // Contains the set of symbols loaded from file
72*9880d681SAndroid Build Coastguard Worker   StringSet<> ExternalNames;
73*9880d681SAndroid Build Coastguard Worker 
LoadFile(StringRef Filename)74*9880d681SAndroid Build Coastguard Worker   void LoadFile(StringRef Filename) {
75*9880d681SAndroid Build Coastguard Worker     // Load the APIFile...
76*9880d681SAndroid Build Coastguard Worker     std::ifstream In(Filename.data());
77*9880d681SAndroid Build Coastguard Worker     if (!In.good()) {
78*9880d681SAndroid Build Coastguard Worker       errs() << "WARNING: Internalize couldn't load file '" << Filename
79*9880d681SAndroid Build Coastguard Worker              << "'! Continuing as if it's empty.\n";
80*9880d681SAndroid Build Coastguard Worker       return; // Just continue as if the file were empty
81*9880d681SAndroid Build Coastguard Worker     }
82*9880d681SAndroid Build Coastguard Worker     while (In) {
83*9880d681SAndroid Build Coastguard Worker       std::string Symbol;
84*9880d681SAndroid Build Coastguard Worker       In >> Symbol;
85*9880d681SAndroid Build Coastguard Worker       if (!Symbol.empty())
86*9880d681SAndroid Build Coastguard Worker         ExternalNames.insert(Symbol);
87*9880d681SAndroid Build Coastguard Worker     }
88*9880d681SAndroid Build Coastguard Worker   }
89*9880d681SAndroid Build Coastguard Worker };
90*9880d681SAndroid Build Coastguard Worker } // end anonymous namespace
91*9880d681SAndroid Build Coastguard Worker 
shouldPreserveGV(const GlobalValue & GV)92*9880d681SAndroid Build Coastguard Worker bool InternalizePass::shouldPreserveGV(const GlobalValue &GV) {
93*9880d681SAndroid Build Coastguard Worker   // Function must be defined here
94*9880d681SAndroid Build Coastguard Worker   if (GV.isDeclaration())
95*9880d681SAndroid Build Coastguard Worker     return true;
96*9880d681SAndroid Build Coastguard Worker 
97*9880d681SAndroid Build Coastguard Worker   // Available externally is really just a "declaration with a body".
98*9880d681SAndroid Build Coastguard Worker   if (GV.hasAvailableExternallyLinkage())
99*9880d681SAndroid Build Coastguard Worker     return true;
100*9880d681SAndroid Build Coastguard Worker 
101*9880d681SAndroid Build Coastguard Worker   // Assume that dllexported symbols are referenced elsewhere
102*9880d681SAndroid Build Coastguard Worker   if (GV.hasDLLExportStorageClass())
103*9880d681SAndroid Build Coastguard Worker     return true;
104*9880d681SAndroid Build Coastguard Worker 
105*9880d681SAndroid Build Coastguard Worker   // Already local, has nothing to do.
106*9880d681SAndroid Build Coastguard Worker   if (GV.hasLocalLinkage())
107*9880d681SAndroid Build Coastguard Worker     return false;
108*9880d681SAndroid Build Coastguard Worker 
109*9880d681SAndroid Build Coastguard Worker   // Check some special cases
110*9880d681SAndroid Build Coastguard Worker   if (AlwaysPreserved.count(GV.getName()))
111*9880d681SAndroid Build Coastguard Worker     return true;
112*9880d681SAndroid Build Coastguard Worker 
113*9880d681SAndroid Build Coastguard Worker   return MustPreserveGV(GV);
114*9880d681SAndroid Build Coastguard Worker }
115*9880d681SAndroid Build Coastguard Worker 
maybeInternalize(GlobalValue & GV,const std::set<const Comdat * > & ExternalComdats)116*9880d681SAndroid Build Coastguard Worker bool InternalizePass::maybeInternalize(
117*9880d681SAndroid Build Coastguard Worker     GlobalValue &GV, const std::set<const Comdat *> &ExternalComdats) {
118*9880d681SAndroid Build Coastguard Worker   if (Comdat *C = GV.getComdat()) {
119*9880d681SAndroid Build Coastguard Worker     if (ExternalComdats.count(C))
120*9880d681SAndroid Build Coastguard Worker       return false;
121*9880d681SAndroid Build Coastguard Worker 
122*9880d681SAndroid Build Coastguard Worker     // If a comdat is not externally visible we can drop it.
123*9880d681SAndroid Build Coastguard Worker     if (auto GO = dyn_cast<GlobalObject>(&GV))
124*9880d681SAndroid Build Coastguard Worker       GO->setComdat(nullptr);
125*9880d681SAndroid Build Coastguard Worker 
126*9880d681SAndroid Build Coastguard Worker     if (GV.hasLocalLinkage())
127*9880d681SAndroid Build Coastguard Worker       return false;
128*9880d681SAndroid Build Coastguard Worker   } else {
129*9880d681SAndroid Build Coastguard Worker     if (GV.hasLocalLinkage())
130*9880d681SAndroid Build Coastguard Worker       return false;
131*9880d681SAndroid Build Coastguard Worker 
132*9880d681SAndroid Build Coastguard Worker     if (shouldPreserveGV(GV))
133*9880d681SAndroid Build Coastguard Worker       return false;
134*9880d681SAndroid Build Coastguard Worker   }
135*9880d681SAndroid Build Coastguard Worker 
136*9880d681SAndroid Build Coastguard Worker   GV.setVisibility(GlobalValue::DefaultVisibility);
137*9880d681SAndroid Build Coastguard Worker   GV.setLinkage(GlobalValue::InternalLinkage);
138*9880d681SAndroid Build Coastguard Worker   return true;
139*9880d681SAndroid Build Coastguard Worker }
140*9880d681SAndroid Build Coastguard Worker 
141*9880d681SAndroid Build Coastguard Worker // If GV is part of a comdat and is externally visible, keep track of its
142*9880d681SAndroid Build Coastguard Worker // comdat so that we don't internalize any of its members.
checkComdatVisibility(GlobalValue & GV,std::set<const Comdat * > & ExternalComdats)143*9880d681SAndroid Build Coastguard Worker void InternalizePass::checkComdatVisibility(
144*9880d681SAndroid Build Coastguard Worker     GlobalValue &GV, std::set<const Comdat *> &ExternalComdats) {
145*9880d681SAndroid Build Coastguard Worker   Comdat *C = GV.getComdat();
146*9880d681SAndroid Build Coastguard Worker   if (!C)
147*9880d681SAndroid Build Coastguard Worker     return;
148*9880d681SAndroid Build Coastguard Worker 
149*9880d681SAndroid Build Coastguard Worker   if (shouldPreserveGV(GV))
150*9880d681SAndroid Build Coastguard Worker     ExternalComdats.insert(C);
151*9880d681SAndroid Build Coastguard Worker }
152*9880d681SAndroid Build Coastguard Worker 
internalizeModule(Module & M,CallGraph * CG)153*9880d681SAndroid Build Coastguard Worker bool InternalizePass::internalizeModule(Module &M, CallGraph *CG) {
154*9880d681SAndroid Build Coastguard Worker   bool Changed = false;
155*9880d681SAndroid Build Coastguard Worker   CallGraphNode *ExternalNode = CG ? CG->getExternalCallingNode() : nullptr;
156*9880d681SAndroid Build Coastguard Worker 
157*9880d681SAndroid Build Coastguard Worker   SmallPtrSet<GlobalValue *, 8> Used;
158*9880d681SAndroid Build Coastguard Worker   collectUsedGlobalVariables(M, Used, false);
159*9880d681SAndroid Build Coastguard Worker 
160*9880d681SAndroid Build Coastguard Worker   // Collect comdat visiblity information for the module.
161*9880d681SAndroid Build Coastguard Worker   std::set<const Comdat *> ExternalComdats;
162*9880d681SAndroid Build Coastguard Worker   if (!M.getComdatSymbolTable().empty()) {
163*9880d681SAndroid Build Coastguard Worker     for (Function &F : M)
164*9880d681SAndroid Build Coastguard Worker       checkComdatVisibility(F, ExternalComdats);
165*9880d681SAndroid Build Coastguard Worker     for (GlobalVariable &GV : M.globals())
166*9880d681SAndroid Build Coastguard Worker       checkComdatVisibility(GV, ExternalComdats);
167*9880d681SAndroid Build Coastguard Worker     for (GlobalAlias &GA : M.aliases())
168*9880d681SAndroid Build Coastguard Worker       checkComdatVisibility(GA, ExternalComdats);
169*9880d681SAndroid Build Coastguard Worker   }
170*9880d681SAndroid Build Coastguard Worker 
171*9880d681SAndroid Build Coastguard Worker   // We must assume that globals in llvm.used have a reference that not even
172*9880d681SAndroid Build Coastguard Worker   // the linker can see, so we don't internalize them.
173*9880d681SAndroid Build Coastguard Worker   // For llvm.compiler.used the situation is a bit fuzzy. The assembler and
174*9880d681SAndroid Build Coastguard Worker   // linker can drop those symbols. If this pass is running as part of LTO,
175*9880d681SAndroid Build Coastguard Worker   // one might think that it could just drop llvm.compiler.used. The problem
176*9880d681SAndroid Build Coastguard Worker   // is that even in LTO llvm doesn't see every reference. For example,
177*9880d681SAndroid Build Coastguard Worker   // we don't see references from function local inline assembly. To be
178*9880d681SAndroid Build Coastguard Worker   // conservative, we internalize symbols in llvm.compiler.used, but we
179*9880d681SAndroid Build Coastguard Worker   // keep llvm.compiler.used so that the symbol is not deleted by llvm.
180*9880d681SAndroid Build Coastguard Worker   for (GlobalValue *V : Used) {
181*9880d681SAndroid Build Coastguard Worker     AlwaysPreserved.insert(V->getName());
182*9880d681SAndroid Build Coastguard Worker   }
183*9880d681SAndroid Build Coastguard Worker 
184*9880d681SAndroid Build Coastguard Worker   // Mark all functions not in the api as internal.
185*9880d681SAndroid Build Coastguard Worker   for (Function &I : M) {
186*9880d681SAndroid Build Coastguard Worker     if (!maybeInternalize(I, ExternalComdats))
187*9880d681SAndroid Build Coastguard Worker       continue;
188*9880d681SAndroid Build Coastguard Worker     Changed = true;
189*9880d681SAndroid Build Coastguard Worker 
190*9880d681SAndroid Build Coastguard Worker     if (ExternalNode)
191*9880d681SAndroid Build Coastguard Worker       // Remove a callgraph edge from the external node to this function.
192*9880d681SAndroid Build Coastguard Worker       ExternalNode->removeOneAbstractEdgeTo((*CG)[&I]);
193*9880d681SAndroid Build Coastguard Worker 
194*9880d681SAndroid Build Coastguard Worker     ++NumFunctions;
195*9880d681SAndroid Build Coastguard Worker     DEBUG(dbgs() << "Internalizing func " << I.getName() << "\n");
196*9880d681SAndroid Build Coastguard Worker   }
197*9880d681SAndroid Build Coastguard Worker 
198*9880d681SAndroid Build Coastguard Worker   // Never internalize the llvm.used symbol.  It is used to implement
199*9880d681SAndroid Build Coastguard Worker   // attribute((used)).
200*9880d681SAndroid Build Coastguard Worker   // FIXME: Shouldn't this just filter on llvm.metadata section??
201*9880d681SAndroid Build Coastguard Worker   AlwaysPreserved.insert("llvm.used");
202*9880d681SAndroid Build Coastguard Worker   AlwaysPreserved.insert("llvm.compiler.used");
203*9880d681SAndroid Build Coastguard Worker 
204*9880d681SAndroid Build Coastguard Worker   // Never internalize anchors used by the machine module info, else the info
205*9880d681SAndroid Build Coastguard Worker   // won't find them.  (see MachineModuleInfo.)
206*9880d681SAndroid Build Coastguard Worker   AlwaysPreserved.insert("llvm.global_ctors");
207*9880d681SAndroid Build Coastguard Worker   AlwaysPreserved.insert("llvm.global_dtors");
208*9880d681SAndroid Build Coastguard Worker   AlwaysPreserved.insert("llvm.global.annotations");
209*9880d681SAndroid Build Coastguard Worker 
210*9880d681SAndroid Build Coastguard Worker   // Never internalize symbols code-gen inserts.
211*9880d681SAndroid Build Coastguard Worker   // FIXME: We should probably add this (and the __stack_chk_guard) via some
212*9880d681SAndroid Build Coastguard Worker   // type of call-back in CodeGen.
213*9880d681SAndroid Build Coastguard Worker   AlwaysPreserved.insert("__stack_chk_fail");
214*9880d681SAndroid Build Coastguard Worker   AlwaysPreserved.insert("__stack_chk_guard");
215*9880d681SAndroid Build Coastguard Worker 
216*9880d681SAndroid Build Coastguard Worker   // Mark all global variables with initializers that are not in the api as
217*9880d681SAndroid Build Coastguard Worker   // internal as well.
218*9880d681SAndroid Build Coastguard Worker   for (auto &GV : M.globals()) {
219*9880d681SAndroid Build Coastguard Worker     if (!maybeInternalize(GV, ExternalComdats))
220*9880d681SAndroid Build Coastguard Worker       continue;
221*9880d681SAndroid Build Coastguard Worker     Changed = true;
222*9880d681SAndroid Build Coastguard Worker 
223*9880d681SAndroid Build Coastguard Worker     ++NumGlobals;
224*9880d681SAndroid Build Coastguard Worker     DEBUG(dbgs() << "Internalized gvar " << GV.getName() << "\n");
225*9880d681SAndroid Build Coastguard Worker   }
226*9880d681SAndroid Build Coastguard Worker 
227*9880d681SAndroid Build Coastguard Worker   // Mark all aliases that are not in the api as internal as well.
228*9880d681SAndroid Build Coastguard Worker   for (auto &GA : M.aliases()) {
229*9880d681SAndroid Build Coastguard Worker     if (!maybeInternalize(GA, ExternalComdats))
230*9880d681SAndroid Build Coastguard Worker       continue;
231*9880d681SAndroid Build Coastguard Worker     Changed = true;
232*9880d681SAndroid Build Coastguard Worker 
233*9880d681SAndroid Build Coastguard Worker     ++NumAliases;
234*9880d681SAndroid Build Coastguard Worker     DEBUG(dbgs() << "Internalized alias " << GA.getName() << "\n");
235*9880d681SAndroid Build Coastguard Worker   }
236*9880d681SAndroid Build Coastguard Worker 
237*9880d681SAndroid Build Coastguard Worker   return Changed;
238*9880d681SAndroid Build Coastguard Worker }
239*9880d681SAndroid Build Coastguard Worker 
InternalizePass()240*9880d681SAndroid Build Coastguard Worker InternalizePass::InternalizePass() : MustPreserveGV(PreserveAPIList()) {}
241*9880d681SAndroid Build Coastguard Worker 
run(Module & M,AnalysisManager<Module> & AM)242*9880d681SAndroid Build Coastguard Worker PreservedAnalyses InternalizePass::run(Module &M, AnalysisManager<Module> &AM) {
243*9880d681SAndroid Build Coastguard Worker   if (!internalizeModule(M, AM.getCachedResult<CallGraphAnalysis>(M)))
244*9880d681SAndroid Build Coastguard Worker     return PreservedAnalyses::all();
245*9880d681SAndroid Build Coastguard Worker 
246*9880d681SAndroid Build Coastguard Worker   PreservedAnalyses PA;
247*9880d681SAndroid Build Coastguard Worker   PA.preserve<CallGraphAnalysis>();
248*9880d681SAndroid Build Coastguard Worker   return PA;
249*9880d681SAndroid Build Coastguard Worker }
250*9880d681SAndroid Build Coastguard Worker 
251*9880d681SAndroid Build Coastguard Worker namespace {
252*9880d681SAndroid Build Coastguard Worker class InternalizeLegacyPass : public ModulePass {
253*9880d681SAndroid Build Coastguard Worker   // Client supplied callback to control wheter a symbol must be preserved.
254*9880d681SAndroid Build Coastguard Worker   std::function<bool(const GlobalValue &)> MustPreserveGV;
255*9880d681SAndroid Build Coastguard Worker 
256*9880d681SAndroid Build Coastguard Worker public:
257*9880d681SAndroid Build Coastguard Worker   static char ID; // Pass identification, replacement for typeid
258*9880d681SAndroid Build Coastguard Worker 
InternalizeLegacyPass()259*9880d681SAndroid Build Coastguard Worker   InternalizeLegacyPass() : ModulePass(ID), MustPreserveGV(PreserveAPIList()) {}
260*9880d681SAndroid Build Coastguard Worker 
InternalizeLegacyPass(std::function<bool (const GlobalValue &)> MustPreserveGV)261*9880d681SAndroid Build Coastguard Worker   InternalizeLegacyPass(std::function<bool(const GlobalValue &)> MustPreserveGV)
262*9880d681SAndroid Build Coastguard Worker       : ModulePass(ID), MustPreserveGV(std::move(MustPreserveGV)) {
263*9880d681SAndroid Build Coastguard Worker     initializeInternalizeLegacyPassPass(*PassRegistry::getPassRegistry());
264*9880d681SAndroid Build Coastguard Worker   }
265*9880d681SAndroid Build Coastguard Worker 
runOnModule(Module & M)266*9880d681SAndroid Build Coastguard Worker   bool runOnModule(Module &M) override {
267*9880d681SAndroid Build Coastguard Worker     if (skipModule(M))
268*9880d681SAndroid Build Coastguard Worker       return false;
269*9880d681SAndroid Build Coastguard Worker 
270*9880d681SAndroid Build Coastguard Worker     CallGraphWrapperPass *CGPass =
271*9880d681SAndroid Build Coastguard Worker         getAnalysisIfAvailable<CallGraphWrapperPass>();
272*9880d681SAndroid Build Coastguard Worker     CallGraph *CG = CGPass ? &CGPass->getCallGraph() : nullptr;
273*9880d681SAndroid Build Coastguard Worker     return internalizeModule(M, MustPreserveGV, CG);
274*9880d681SAndroid Build Coastguard Worker   }
275*9880d681SAndroid Build Coastguard Worker 
getAnalysisUsage(AnalysisUsage & AU) const276*9880d681SAndroid Build Coastguard Worker   void getAnalysisUsage(AnalysisUsage &AU) const override {
277*9880d681SAndroid Build Coastguard Worker     AU.setPreservesCFG();
278*9880d681SAndroid Build Coastguard Worker     AU.addPreserved<CallGraphWrapperPass>();
279*9880d681SAndroid Build Coastguard Worker   }
280*9880d681SAndroid Build Coastguard Worker };
281*9880d681SAndroid Build Coastguard Worker }
282*9880d681SAndroid Build Coastguard Worker 
283*9880d681SAndroid Build Coastguard Worker char InternalizeLegacyPass::ID = 0;
284*9880d681SAndroid Build Coastguard Worker INITIALIZE_PASS(InternalizeLegacyPass, "internalize",
285*9880d681SAndroid Build Coastguard Worker                 "Internalize Global Symbols", false, false)
286*9880d681SAndroid Build Coastguard Worker 
createInternalizePass()287*9880d681SAndroid Build Coastguard Worker ModulePass *llvm::createInternalizePass() {
288*9880d681SAndroid Build Coastguard Worker   return new InternalizeLegacyPass();
289*9880d681SAndroid Build Coastguard Worker }
290*9880d681SAndroid Build Coastguard Worker 
createInternalizePass(std::function<bool (const GlobalValue &)> MustPreserveGV)291*9880d681SAndroid Build Coastguard Worker ModulePass *llvm::createInternalizePass(
292*9880d681SAndroid Build Coastguard Worker     std::function<bool(const GlobalValue &)> MustPreserveGV) {
293*9880d681SAndroid Build Coastguard Worker   return new InternalizeLegacyPass(std::move(MustPreserveGV));
294*9880d681SAndroid Build Coastguard Worker }
295