Chris Lattner | 1b94c00 | 2002-04-28 05:43:27 +0000 | [diff] [blame] | 1 | //===-- Internalize.cpp - Mark functions internal -------------------------===// |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 1b94c00 | 2002-04-28 05:43:27 +0000 | [diff] [blame] | 9 | // |
Rafael Espindola | 4253bd8 | 2012-10-26 18:47:48 +0000 | [diff] [blame] | 10 | // This pass loops over all of the functions and variables in the input module. |
| 11 | // If the function or variable is not in the list of external names given to |
| 12 | // the pass it is marked as internal. |
Chris Lattner | 1b94c00 | 2002-04-28 05:43:27 +0000 | [diff] [blame] | 13 | // |
Rafael Espindola | 282a470 | 2013-10-31 20:51:58 +0000 | [diff] [blame] | 14 | // This transformation would not be legal in a regular compilation, but it gets |
| 15 | // extra information from the linker about what is safe. |
Rafael Espindola | 3d7fc25 | 2013-10-21 17:14:55 +0000 | [diff] [blame] | 16 | // |
Rafael Espindola | 282a470 | 2013-10-31 20:51:58 +0000 | [diff] [blame] | 17 | // For example: Internalizing a function with external linkage. Only if we are |
| 18 | // told it is only used from within this module, it is safe to do it. |
Rafael Espindola | 3d7fc25 | 2013-10-21 17:14:55 +0000 | [diff] [blame] | 19 | // |
Chris Lattner | 1b94c00 | 2002-04-28 05:43:27 +0000 | [diff] [blame] | 20 | //===----------------------------------------------------------------------===// |
| 21 | |
Chris Lattner | 99a53f6 | 2002-07-24 17:12:05 +0000 | [diff] [blame] | 22 | #include "llvm/Transforms/IPO.h" |
Rafael Espindola | 17600e2 | 2013-07-25 03:23:25 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/SmallPtrSet.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/Statistic.h" |
Mehdi Amini | c87d7d0 | 2016-02-10 23:24:31 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/StringSet.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 26 | #include "llvm/Analysis/CallGraph.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 27 | #include "llvm/IR/Module.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 28 | #include "llvm/Pass.h" |
Reid Spencer | 7c16caa | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 29 | #include "llvm/Support/CommandLine.h" |
| 30 | #include "llvm/Support/Debug.h" |
Daniel Dunbar | 0dd5e1e | 2009-07-25 00:23:56 +0000 | [diff] [blame] | 31 | #include "llvm/Support/raw_ostream.h" |
Rafael Espindola | 3d7fc25 | 2013-10-21 17:14:55 +0000 | [diff] [blame] | 32 | #include "llvm/Transforms/Utils/GlobalStatus.h" |
Rafael Espindola | 17600e2 | 2013-07-25 03:23:25 +0000 | [diff] [blame] | 33 | #include "llvm/Transforms/Utils/ModuleUtils.h" |
Chris Lattner | 44457bb | 2003-05-22 19:34:49 +0000 | [diff] [blame] | 34 | #include <fstream> |
| 35 | #include <set> |
Chris Lattner | f52e03c | 2003-11-21 21:54:22 +0000 | [diff] [blame] | 36 | using namespace llvm; |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 37 | |
Chandler Carruth | 964daaa | 2014-04-22 02:55:47 +0000 | [diff] [blame] | 38 | #define DEBUG_TYPE "internalize" |
| 39 | |
Duncan Sands | 582c53d | 2009-01-05 21:24:45 +0000 | [diff] [blame] | 40 | STATISTIC(NumAliases , "Number of aliases internalized"); |
Chris Lattner | 1631bcb | 2006-12-19 22:09:18 +0000 | [diff] [blame] | 41 | STATISTIC(NumFunctions, "Number of functions internalized"); |
| 42 | STATISTIC(NumGlobals , "Number of global vars internalized"); |
| 43 | |
Dan Gohman | d78c400 | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 44 | // APIFile - A file which contains a list of symbols that should not be marked |
| 45 | // external. |
| 46 | static cl::opt<std::string> |
| 47 | APIFile("internalize-public-api-file", cl::value_desc("filename"), |
| 48 | cl::desc("A file containing list of symbol names to preserve")); |
| 49 | |
| 50 | // APIList - A list of symbols that should not be marked internal. |
| 51 | static cl::list<std::string> |
| 52 | APIList("internalize-public-api-list", cl::value_desc("list"), |
| 53 | cl::desc("A list of symbol names to preserve"), |
| 54 | cl::CommaSeparated); |
| 55 | |
Chris Lattner | b28b680 | 2002-07-23 18:06:35 +0000 | [diff] [blame] | 56 | namespace { |
Mehdi Amini | 4078709 | 2016-04-13 04:20:32 +0000 | [diff] [blame^] | 57 | // Helper to load an API list to preserve from file and expose it as a functor |
| 58 | // to the Internalize Pass |
| 59 | class PreserveAPIList { |
| 60 | public: |
| 61 | PreserveAPIList() { |
| 62 | if (!APIFile.empty()) |
| 63 | LoadFile(APIFile); |
| 64 | ExternalNames.insert(APIList.begin(), APIList.end()); |
| 65 | } |
| 66 | |
| 67 | bool operator()(const GlobalValue &GV) { |
| 68 | return ExternalNames.count(GV.getName()); |
| 69 | } |
| 70 | |
| 71 | private: |
| 72 | // Contains the set of symbols loaded from file |
Mehdi Amini | c87d7d0 | 2016-02-10 23:24:31 +0000 | [diff] [blame] | 73 | StringSet<> ExternalNames; |
| 74 | |
Mehdi Amini | 4078709 | 2016-04-13 04:20:32 +0000 | [diff] [blame^] | 75 | void LoadFile(StringRef Filename) { |
| 76 | // Load the APIFile... |
| 77 | std::ifstream In(Filename.data()); |
| 78 | if (!In.good()) { |
| 79 | errs() << "WARNING: Internalize couldn't load file '" << Filename |
| 80 | << "'! Continuing as if it's empty.\n"; |
| 81 | return; // Just continue as if the file were empty |
| 82 | } |
| 83 | while (In) { |
| 84 | std::string Symbol; |
| 85 | In >> Symbol; |
| 86 | if (!Symbol.empty()) |
| 87 | ExternalNames.insert(Symbol); |
| 88 | } |
| 89 | } |
| 90 | }; |
| 91 | } |
| 92 | |
| 93 | namespace { |
| 94 | class InternalizePass : public ModulePass { |
| 95 | // Client supply callback to control wheter a symbol must be preserved. |
| 96 | std::function<bool(const GlobalValue &)> MustPreserveGV; |
| 97 | |
| 98 | // Set of symbols private to the compiler that this pass should not touch. |
| 99 | StringSet<> AlwaysPreserved; |
| 100 | |
| 101 | // Return false if we're allowed to internalize this GV. |
| 102 | bool ShouldPreserveGV(const GlobalValue &GV) { |
| 103 | // Function must be defined here |
| 104 | if (GV.isDeclaration()) |
| 105 | return true; |
| 106 | |
| 107 | // Available externally is really just a "declaration with a body". |
| 108 | if (GV.hasAvailableExternallyLinkage()) |
| 109 | return true; |
| 110 | |
| 111 | // Assume that dllexported symbols are referenced elsewhere |
| 112 | if (GV.hasDLLExportStorageClass()) |
| 113 | return true; |
| 114 | |
| 115 | // Already local, has nothing to do. |
| 116 | if (GV.hasLocalLinkage()) |
| 117 | return false; |
| 118 | |
| 119 | // Check some special cases |
| 120 | if (AlwaysPreserved.count(GV.getName())) |
| 121 | return true; |
| 122 | |
| 123 | return MustPreserveGV(GV); |
| 124 | } |
| 125 | |
Peter Collingbourne | 9b0fe61 | 2015-07-16 17:42:21 +0000 | [diff] [blame] | 126 | bool maybeInternalize(GlobalValue &GV, |
| 127 | const std::set<const Comdat *> &ExternalComdats); |
| 128 | void checkComdatVisibility(GlobalValue &GV, |
| 129 | std::set<const Comdat *> &ExternalComdats); |
Mehdi Amini | 4078709 | 2016-04-13 04:20:32 +0000 | [diff] [blame^] | 130 | |
| 131 | public: |
| 132 | static char ID; // Pass identification, replacement for typeid |
| 133 | explicit InternalizePass(); |
| 134 | InternalizePass(std::function<bool(const GlobalValue &)> MustPreserveGV); |
Craig Topper | 3e4c697 | 2014-03-05 09:10:37 +0000 | [diff] [blame] | 135 | bool runOnModule(Module &M) override; |
Nuno Lopes | 5093ab4 | 2008-09-30 22:04:30 +0000 | [diff] [blame] | 136 | |
Craig Topper | 3e4c697 | 2014-03-05 09:10:37 +0000 | [diff] [blame] | 137 | void getAnalysisUsage(AnalysisUsage &AU) const override { |
Nuno Lopes | 5093ab4 | 2008-09-30 22:04:30 +0000 | [diff] [blame] | 138 | AU.setPreservesCFG(); |
Chandler Carruth | 6378cf5 | 2013-11-26 04:19:30 +0000 | [diff] [blame] | 139 | AU.addPreserved<CallGraphWrapperPass>(); |
Nuno Lopes | 5093ab4 | 2008-09-30 22:04:30 +0000 | [diff] [blame] | 140 | } |
Chris Lattner | 47cc366 | 2002-07-30 19:48:44 +0000 | [diff] [blame] | 141 | }; |
Chris Lattner | b28b680 | 2002-07-23 18:06:35 +0000 | [diff] [blame] | 142 | } // end anonymous namespace |
| 143 | |
Dan Gohman | d78c400 | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 144 | char InternalizePass::ID = 0; |
Owen Anderson | a57b97e | 2010-07-21 22:09:45 +0000 | [diff] [blame] | 145 | INITIALIZE_PASS(InternalizePass, "internalize", |
Owen Anderson | df7a4f2 | 2010-10-07 22:25:06 +0000 | [diff] [blame] | 146 | "Internalize Global Symbols", false, false) |
Dan Gohman | d78c400 | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 147 | |
Mehdi Amini | 4078709 | 2016-04-13 04:20:32 +0000 | [diff] [blame^] | 148 | InternalizePass::InternalizePass() |
| 149 | : ModulePass(ID), MustPreserveGV(PreserveAPIList()) {} |
| 150 | |
| 151 | InternalizePass::InternalizePass( |
| 152 | std::function<bool(const GlobalValue &)> MustPreserveGV) |
| 153 | : ModulePass(ID), MustPreserveGV(std::move(MustPreserveGV)) { |
Owen Anderson | 6c18d1a | 2010-10-19 17:21:58 +0000 | [diff] [blame] | 154 | initializeInternalizePassPass(*PassRegistry::getPassRegistry()); |
Peter Collingbourne | 9b0fe61 | 2015-07-16 17:42:21 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | // Internalize GV if it is possible to do so, i.e. it is not externally visible |
| 158 | // and is not a member of an externally visible comdat. |
| 159 | bool InternalizePass::maybeInternalize( |
| 160 | GlobalValue &GV, const std::set<const Comdat *> &ExternalComdats) { |
| 161 | if (Comdat *C = GV.getComdat()) { |
| 162 | if (ExternalComdats.count(C)) |
| 163 | return false; |
| 164 | |
| 165 | // If a comdat is not externally visible we can drop it. |
| 166 | if (auto GO = dyn_cast<GlobalObject>(&GV)) |
| 167 | GO->setComdat(nullptr); |
| 168 | |
| 169 | if (GV.hasLocalLinkage()) |
| 170 | return false; |
| 171 | } else { |
| 172 | if (GV.hasLocalLinkage()) |
| 173 | return false; |
| 174 | |
Mehdi Amini | 4078709 | 2016-04-13 04:20:32 +0000 | [diff] [blame^] | 175 | if (ShouldPreserveGV(GV)) |
Peter Collingbourne | 9b0fe61 | 2015-07-16 17:42:21 +0000 | [diff] [blame] | 176 | return false; |
| 177 | } |
| 178 | |
| 179 | GV.setVisibility(GlobalValue::DefaultVisibility); |
| 180 | GV.setLinkage(GlobalValue::InternalLinkage); |
Rafael Espindola | 282a470 | 2013-10-31 20:51:58 +0000 | [diff] [blame] | 181 | return true; |
Rafael Espindola | 49a6c15 | 2013-09-04 18:37:36 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Peter Collingbourne | 9b0fe61 | 2015-07-16 17:42:21 +0000 | [diff] [blame] | 184 | // If GV is part of a comdat and is externally visible, keep track of its |
| 185 | // comdat so that we don't internalize any of its members. |
| 186 | void InternalizePass::checkComdatVisibility( |
| 187 | GlobalValue &GV, std::set<const Comdat *> &ExternalComdats) { |
| 188 | Comdat *C = GV.getComdat(); |
| 189 | if (!C) |
| 190 | return; |
| 191 | |
Mehdi Amini | 4078709 | 2016-04-13 04:20:32 +0000 | [diff] [blame^] | 192 | if (ShouldPreserveGV(GV)) |
Peter Collingbourne | 9b0fe61 | 2015-07-16 17:42:21 +0000 | [diff] [blame] | 193 | ExternalComdats.insert(C); |
| 194 | } |
| 195 | |
Chris Lattner | 8cdc773 | 2006-01-03 19:13:17 +0000 | [diff] [blame] | 196 | bool InternalizePass::runOnModule(Module &M) { |
Chandler Carruth | 6378cf5 | 2013-11-26 04:19:30 +0000 | [diff] [blame] | 197 | CallGraphWrapperPass *CGPass = getAnalysisIfAvailable<CallGraphWrapperPass>(); |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 198 | CallGraph *CG = CGPass ? &CGPass->getCallGraph() : nullptr; |
| 199 | CallGraphNode *ExternalNode = CG ? CG->getExternalCallingNode() : nullptr; |
Duncan Sands | d24b93f | 2009-01-05 20:38:27 +0000 | [diff] [blame] | 200 | |
Rafael Espindola | 17600e2 | 2013-07-25 03:23:25 +0000 | [diff] [blame] | 201 | SmallPtrSet<GlobalValue *, 8> Used; |
| 202 | collectUsedGlobalVariables(M, Used, false); |
| 203 | |
Peter Collingbourne | 9b0fe61 | 2015-07-16 17:42:21 +0000 | [diff] [blame] | 204 | // Collect comdat visiblity information for the module. |
| 205 | std::set<const Comdat *> ExternalComdats; |
| 206 | if (!M.getComdatSymbolTable().empty()) { |
| 207 | for (Function &F : M) |
| 208 | checkComdatVisibility(F, ExternalComdats); |
| 209 | for (GlobalVariable &GV : M.globals()) |
| 210 | checkComdatVisibility(GV, ExternalComdats); |
| 211 | for (GlobalAlias &GA : M.aliases()) |
| 212 | checkComdatVisibility(GA, ExternalComdats); |
| 213 | } |
| 214 | |
Rafael Espindola | 17600e2 | 2013-07-25 03:23:25 +0000 | [diff] [blame] | 215 | // We must assume that globals in llvm.used have a reference that not even |
| 216 | // the linker can see, so we don't internalize them. |
| 217 | // For llvm.compiler.used the situation is a bit fuzzy. The assembler and |
| 218 | // linker can drop those symbols. If this pass is running as part of LTO, |
| 219 | // one might think that it could just drop llvm.compiler.used. The problem |
| 220 | // is that even in LTO llvm doesn't see every reference. For example, |
| 221 | // we don't see references from function local inline assembly. To be |
| 222 | // conservative, we internalize symbols in llvm.compiler.used, but we |
| 223 | // keep llvm.compiler.used so that the symbol is not deleted by llvm. |
Craig Topper | 4627679 | 2014-08-24 23:23:06 +0000 | [diff] [blame] | 224 | for (GlobalValue *V : Used) { |
Mehdi Amini | 4078709 | 2016-04-13 04:20:32 +0000 | [diff] [blame^] | 225 | AlwaysPreserved.insert(V->getName()); |
Rafael Espindola | 17600e2 | 2013-07-25 03:23:25 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Devang Patel | f2763e2 | 2008-05-14 20:01:01 +0000 | [diff] [blame] | 228 | // Mark all functions not in the api as internal. |
Duncan P. N. Exon Smith | 1732340 | 2015-10-13 17:51:03 +0000 | [diff] [blame] | 229 | for (Function &I : M) { |
| 230 | if (!maybeInternalize(I, ExternalComdats)) |
Rafael Espindola | 49a6c15 | 2013-09-04 18:37:36 +0000 | [diff] [blame] | 231 | continue; |
Bill Wendling | 2865be7 | 2013-08-30 21:07:33 +0000 | [diff] [blame] | 232 | |
Rafael Espindola | 49a6c15 | 2013-09-04 18:37:36 +0000 | [diff] [blame] | 233 | if (ExternalNode) |
| 234 | // Remove a callgraph edge from the external node to this function. |
Duncan P. N. Exon Smith | 1732340 | 2015-10-13 17:51:03 +0000 | [diff] [blame] | 235 | ExternalNode->removeOneAbstractEdgeTo((*CG)[&I]); |
Rafael Espindola | 49a6c15 | 2013-09-04 18:37:36 +0000 | [diff] [blame] | 236 | |
Rafael Espindola | 49a6c15 | 2013-09-04 18:37:36 +0000 | [diff] [blame] | 237 | ++NumFunctions; |
Duncan P. N. Exon Smith | 1732340 | 2015-10-13 17:51:03 +0000 | [diff] [blame] | 238 | DEBUG(dbgs() << "Internalizing func " << I.getName() << "\n"); |
Rafael Espindola | 49a6c15 | 2013-09-04 18:37:36 +0000 | [diff] [blame] | 239 | } |
Duncan Sands | d24b93f | 2009-01-05 20:38:27 +0000 | [diff] [blame] | 240 | |
Chris Lattner | 8cdc773 | 2006-01-03 19:13:17 +0000 | [diff] [blame] | 241 | // Never internalize the llvm.used symbol. It is used to implement |
| 242 | // attribute((used)). |
Chris Lattner | 58f9bb2 | 2009-07-20 06:14:25 +0000 | [diff] [blame] | 243 | // FIXME: Shouldn't this just filter on llvm.metadata section?? |
Mehdi Amini | 4078709 | 2016-04-13 04:20:32 +0000 | [diff] [blame^] | 244 | AlwaysPreserved.insert("llvm.used"); |
| 245 | AlwaysPreserved.insert("llvm.compiler.used"); |
Duncan Sands | d24b93f | 2009-01-05 20:38:27 +0000 | [diff] [blame] | 246 | |
Jim Laskey | c56315c | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 247 | // Never internalize anchors used by the machine module info, else the info |
| 248 | // won't find them. (see MachineModuleInfo.) |
Mehdi Amini | 4078709 | 2016-04-13 04:20:32 +0000 | [diff] [blame^] | 249 | AlwaysPreserved.insert("llvm.global_ctors"); |
| 250 | AlwaysPreserved.insert("llvm.global_dtors"); |
| 251 | AlwaysPreserved.insert("llvm.global.annotations"); |
Duncan Sands | d24b93f | 2009-01-05 20:38:27 +0000 | [diff] [blame] | 252 | |
Bill Wendling | 585583c | 2012-04-13 01:06:27 +0000 | [diff] [blame] | 253 | // Never internalize symbols code-gen inserts. |
Bill Wendling | e1eaecd | 2013-08-12 20:09:37 +0000 | [diff] [blame] | 254 | // FIXME: We should probably add this (and the __stack_chk_guard) via some |
| 255 | // type of call-back in CodeGen. |
Mehdi Amini | 4078709 | 2016-04-13 04:20:32 +0000 | [diff] [blame^] | 256 | AlwaysPreserved.insert("__stack_chk_fail"); |
| 257 | AlwaysPreserved.insert("__stack_chk_guard"); |
Bill Wendling | 585583c | 2012-04-13 01:06:27 +0000 | [diff] [blame] | 258 | |
Devang Patel | f2763e2 | 2008-05-14 20:01:01 +0000 | [diff] [blame] | 259 | // Mark all global variables with initializers that are not in the api as |
| 260 | // internal as well. |
Chris Lattner | 8cdc773 | 2006-01-03 19:13:17 +0000 | [diff] [blame] | 261 | for (Module::global_iterator I = M.global_begin(), E = M.global_end(); |
Rafael Espindola | 49a6c15 | 2013-09-04 18:37:36 +0000 | [diff] [blame] | 262 | I != E; ++I) { |
Peter Collingbourne | 9b0fe61 | 2015-07-16 17:42:21 +0000 | [diff] [blame] | 263 | if (!maybeInternalize(*I, ExternalComdats)) |
Rafael Espindola | 49a6c15 | 2013-09-04 18:37:36 +0000 | [diff] [blame] | 264 | continue; |
| 265 | |
Rafael Espindola | 49a6c15 | 2013-09-04 18:37:36 +0000 | [diff] [blame] | 266 | ++NumGlobals; |
| 267 | DEBUG(dbgs() << "Internalized gvar " << I->getName() << "\n"); |
| 268 | } |
Duncan Sands | d24b93f | 2009-01-05 20:38:27 +0000 | [diff] [blame] | 269 | |
Duncan Sands | 582c53d | 2009-01-05 21:24:45 +0000 | [diff] [blame] | 270 | // Mark all aliases that are not in the api as internal as well. |
| 271 | for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end(); |
Rafael Espindola | 49a6c15 | 2013-09-04 18:37:36 +0000 | [diff] [blame] | 272 | I != E; ++I) { |
Peter Collingbourne | 9b0fe61 | 2015-07-16 17:42:21 +0000 | [diff] [blame] | 273 | if (!maybeInternalize(*I, ExternalComdats)) |
Rafael Espindola | 49a6c15 | 2013-09-04 18:37:36 +0000 | [diff] [blame] | 274 | continue; |
| 275 | |
Rafael Espindola | 49a6c15 | 2013-09-04 18:37:36 +0000 | [diff] [blame] | 276 | ++NumAliases; |
| 277 | DEBUG(dbgs() << "Internalized alias " << I->getName() << "\n"); |
| 278 | } |
Duncan Sands | 582c53d | 2009-01-05 21:24:45 +0000 | [diff] [blame] | 279 | |
Peter Collingbourne | 9b0fe61 | 2015-07-16 17:42:21 +0000 | [diff] [blame] | 280 | // We do not keep track of whether this pass changed the module because |
| 281 | // it adds unnecessary complexity: |
| 282 | // 1) This pass will generally be near the start of the pass pipeline, so |
| 283 | // there will be no analyses to invalidate. |
| 284 | // 2) This pass will most likely end up changing the module and it isn't worth |
| 285 | // worrying about optimizing the case where the module is unchanged. |
| 286 | return true; |
Chris Lattner | 8cdc773 | 2006-01-03 19:13:17 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Mehdi Amini | 4078709 | 2016-04-13 04:20:32 +0000 | [diff] [blame^] | 289 | ModulePass *llvm::createInternalizePass() { |
| 290 | return new InternalizePass(PreserveAPIList()); |
Devang Patel | 839d926 | 2006-07-20 17:48:05 +0000 | [diff] [blame] | 291 | } |
Mehdi Amini | c87d7d0 | 2016-02-10 23:24:31 +0000 | [diff] [blame] | 292 | |
Mehdi Amini | 4078709 | 2016-04-13 04:20:32 +0000 | [diff] [blame^] | 293 | ModulePass *llvm::createInternalizePass( |
| 294 | std::function<bool(const GlobalValue &)> MustPreserveGV) { |
| 295 | return new InternalizePass(std::move(MustPreserveGV)); |
Mehdi Amini | c87d7d0 | 2016-02-10 23:24:31 +0000 | [diff] [blame] | 296 | } |
Mehdi Amini | 4078709 | 2016-04-13 04:20:32 +0000 | [diff] [blame^] | 297 | |