llvm.org GIT mirror llvm / 3845c07
Revert "Reapply "LTO: add API to set strategy for -internalize"" This reverts commit r199244. Conflicts: include/llvm-c/lto.h include/llvm/LTO/LTOCodeGenerator.h lib/LTO/LTOCodeGenerator.cpp git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205471 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 5 years ago
6 changed file(s) with 19 addition(s) and 88 deletion(s). Raw diff Collapse all Expand all
7070 void setTargetOptions(llvm::TargetOptions options);
7171 void setDebugInfo(lto_debug_model);
7272 void setCodePICModel(lto_codegen_model);
73 void setInternalizeStrategy(lto_internalize_strategy);
7473
7574 void setCpu(const char *mCpu) { MCpu = mCpu; }
7675
117116
118117 void setDiagnosticHandler(lto_diagnostic_handler_t, void *);
119118
120 bool shouldInternalize() const {
121 return InternalizeStrategy != LTO_INTERNALIZE_NONE;
122 }
123
124 bool shouldOnlyInternalizeHidden() const {
125 return InternalizeStrategy == LTO_INTERNALIZE_HIDDEN;
126 }
127
128119 private:
129120 void initializeLTOPasses();
130121
153144 bool EmitDwarfDebugInfo;
154145 bool ScopeRestrictionsDone;
155146 lto_codegen_model CodeModel;
156 lto_internalize_strategy InternalizeStrategy;
157147 StringSet MustPreserveSymbols;
158148 StringSet AsmUndefinedRefs;
159149 llvm::MemoryBuffer *NativeObjectFile;
111111 ////
112112 /// The symbols in \p ExportList are never internalized.
113113 ///
114 /// When OnlyHidden=true, only symbols with hidden visibility are internalized.
115 ///
116114 /// The symbol in DSOList are internalized if it is safe to drop them from
117115 /// the symbol table.
118116 ///
119117 /// Note that commandline options that are used with the above function are not
120118 /// used now!
121 ModulePass *createInternalizePass(ArrayRef ExportList,
122 bool OnlyHidden = false);
119 ModulePass *createInternalizePass(ArrayRef ExportList);
123120 /// createInternalizePass - Same as above, but with an empty exportList.
124 ModulePass *createInternalizePass(bool OnlyHidden = false);
125 /// createInternalizePass - Resolve ambiguity when passed a const char *.
126 ModulePass *createInternalizePass(const char *SingleExport);
121 ModulePass *createInternalizePass();
127122
128123 //===----------------------------------------------------------------------===//
129124 /// createDeadArgEliminationPass - This pass removes arguments from functions
8181 LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC = 2
8282 } lto_codegen_model;
8383
84 /**
85 * \since LTO_API_VERSION=6
86 */
87 typedef enum {
88 LTO_INTERNALIZE_FULL = 0,
89 LTO_INTERNALIZE_NONE = 1,
90 LTO_INTERNALIZE_HIDDEN = 2
91 } lto_internalize_strategy;
92
9384 /** opaque reference to a loaded object module */
9485 typedef struct LTOModule* lto_module_t;
9586
402393 int nargs);
403394
404395 /**
405 * Sets the strategy to use during internalize. Default strategy is
406 * LTO_INTERNALIZE_FULL.
407 *
408 * \since LTO_API_VERSION=6
409 */
410 extern void
411 lto_codegen_set_internalize_strategy(lto_code_gen_t cg,
412 lto_internalize_strategy);
413
414 /**
415396 * Tells LTO optimization passes that this symbol must be preserved
416397 * because it is referenced by native code or a command line option.
417398 *
6464 LTOCodeGenerator::LTOCodeGenerator()
6565 : Context(getGlobalContext()), Linker(new Module("ld-temp.o", Context)),
6666 TargetMach(NULL), EmitDwarfDebugInfo(false), ScopeRestrictionsDone(false),
67 CodeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC),
68 InternalizeStrategy(LTO_INTERNALIZE_FULL), NativeObjectFile(NULL),
67 CodeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC), NativeObjectFile(NULL),
6968 DiagHandler(NULL), DiagContext(NULL) {
7069 initializeLTOPasses();
7170 }
168167 llvm_unreachable("Unknown PIC model!");
169168 }
170169
171 void
172 LTOCodeGenerator::setInternalizeStrategy(lto_internalize_strategy Strategy) {
173 switch (Strategy) {
174 case LTO_INTERNALIZE_FULL:
175 case LTO_INTERNALIZE_NONE:
176 case LTO_INTERNALIZE_HIDDEN:
177 InternalizeStrategy = Strategy;
178 return;
179 }
180 llvm_unreachable("Unknown internalize strategy!");
181 }
182
183170 bool LTOCodeGenerator::writeMergedModules(const char *path,
184171 std::string &errMsg) {
185172 if (!determineTarget(errMsg))
401388 }
402389
403390 void LTOCodeGenerator::applyScopeRestrictions() {
404 if (ScopeRestrictionsDone || !shouldInternalize())
391 if (ScopeRestrictionsDone)
405392 return;
406393 Module *mergedModule = Linker.getModule();
407394
453440 LLVMCompilerUsed->setSection("llvm.metadata");
454441 }
455442
456 passes.add(
457 createInternalizePass(MustPreserveList, shouldOnlyInternalizeHidden()));
443 passes.add(createInternalizePass(MustPreserveList));
458444
459445 // apply scope restrictions
460446 passes.run(*mergedModule);
5353 namespace {
5454 class InternalizePass : public ModulePass {
5555 std::set ExternalNames;
56 bool OnlyHidden;
5756 public:
5857 static char ID; // Pass identification, replacement for typeid
59 explicit InternalizePass(bool OnlyHidden = false);
60 explicit InternalizePass(ArrayRef ExportList, bool OnlyHidden);
58 explicit InternalizePass();
59 explicit InternalizePass(ArrayRef ExportList);
6160 void LoadFile(const char *Filename);
6261 bool runOnModule(Module &M) override;
6362
7271 INITIALIZE_PASS(InternalizePass, "internalize",
7372 "Internalize Global Symbols", false, false)
7473
75 InternalizePass::InternalizePass(bool OnlyHidden)
76 : ModulePass(ID), OnlyHidden(OnlyHidden) {
74 InternalizePass::InternalizePass() : ModulePass(ID) {
7775 initializeInternalizePassPass(*PassRegistry::getPassRegistry());
7876 if (!APIFile.empty()) // If a filename is specified, use it.
7977 LoadFile(APIFile.c_str());
8078 ExternalNames.insert(APIList.begin(), APIList.end());
8179 }
8280
83 InternalizePass::InternalizePass(ArrayRef ExportList,
84 bool OnlyHidden)
85 : ModulePass(ID), OnlyHidden(OnlyHidden) {
81 InternalizePass::InternalizePass(ArrayRef ExportList)
82 : ModulePass(ID) {
8683 initializeInternalizePassPass(*PassRegistry::getPassRegistry());
8784 for(ArrayRef::const_iterator itr = ExportList.begin();
8885 itr != ExportList.end(); itr++) {
107104 }
108105
109106 static bool shouldInternalize(const GlobalValue &GV,
110 const std::set &ExternalNames,
111 bool OnlyHidden) {
112 if (OnlyHidden && !GV.hasHiddenVisibility())
113 return false;
114
107 const std::set &ExternalNames) {
115108 // Function must be defined here
116109 if (GV.isDeclaration())
117110 return false;
161154
162155 // Mark all functions not in the api as internal.
163156 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
164 if (!shouldInternalize(*I, ExternalNames, OnlyHidden))
157 if (!shouldInternalize(*I, ExternalNames))
165158 continue;
166159
167160 I->setLinkage(GlobalValue::InternalLinkage);
197190 // internal as well.
198191 for (Module::global_iterator I = M.global_begin(), E = M.global_end();
199192 I != E; ++I) {
200 if (!shouldInternalize(*I, ExternalNames, OnlyHidden))
193 if (!shouldInternalize(*I, ExternalNames))
201194 continue;
202195
203196 I->setLinkage(GlobalValue::InternalLinkage);
209202 // Mark all aliases that are not in the api as internal as well.
210203 for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end();
211204 I != E; ++I) {
212 if (!shouldInternalize(*I, ExternalNames, OnlyHidden))
205 if (!shouldInternalize(*I, ExternalNames))
213206 continue;
214207
215208 I->setLinkage(GlobalValue::InternalLinkage);
221214 return Changed;
222215 }
223216
224 ModulePass *llvm::createInternalizePass(bool OnlyHidden) {
225 return new InternalizePass(OnlyHidden);
226 }
227
228 ModulePass *llvm::createInternalizePass(ArrayRef ExportList,
229 bool OnlyHidden) {
230 return new InternalizePass(ExportList, OnlyHidden);
231 }
232
233 ModulePass *llvm::createInternalizePass(const char *SingleExport) {
234 return createInternalizePass(ArrayRef(SingleExport));
235 }
217 ModulePass *llvm::createInternalizePass() { return new InternalizePass(); }
218
219 ModulePass *llvm::createInternalizePass(ArrayRef ExportList) {
220 return new InternalizePass(ExportList);
221 }
261261 void lto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args,
262262 int nargs) {
263263 // In here only for backwards compatibility. We use MC now.
264 }
265
266 /// lto_codegen_set_internalize_strategy - Sets the strategy to use during
267 /// internalize.
268 void lto_codegen_set_internalize_strategy(lto_code_gen_t cg,
269 lto_internalize_strategy strategy) {
270 cg->setInternalizeStrategy(strategy);
271264 }
272265
273266 /// lto_codegen_add_must_preserve_symbol - Adds to a list of all global symbols