llvm.org GIT mirror llvm / d13b9da
Revert r199191, "LTO: add API to set strategy for -internalize" Please update also Other/link-opts.ll, in next time. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199197 91177308-0d34-0410-b5e6-96231b3b80d8 NAKAMURA Takumi 6 years ago
6 changed file(s) with 25 addition(s) and 77 deletion(s). Raw diff Collapse all Expand all
6969 void setTargetOptions(llvm::TargetOptions options);
7070 void setDebugInfo(lto_debug_model);
7171 void setCodePICModel(lto_codegen_model);
72 void setInternalizeStrategy(lto_internalize_strategy);
7372
7473 void setCpu(const char *mCpu) { MCpu = mCpu; }
7574
114113 bool disableGVNLoadPRE,
115114 std::string &errMsg);
116115
117 bool shouldInternalize() const {
118 return InternalizeStrategy != LTO_INTERNALIZE_NONE;
119 }
120
121 bool shouldOnlyInternalizeHidden() const {
122 return InternalizeStrategy == LTO_INTERNALIZE_HIDDEN;
123 }
124
125116 private:
126117 void initializeLTOPasses();
127118
146137 bool EmitDwarfDebugInfo;
147138 bool ScopeRestrictionsDone;
148139 lto_codegen_model CodeModel;
149 lto_internalize_strategy InternalizeStrategy;
150140 StringSet MustPreserveSymbols;
151141 StringSet AsmUndefinedRefs;
152142 llvm::MemoryBuffer *NativeObjectFile;
107107 ////
108108 /// The symbols in \p ExportList are never internalized.
109109 ///
110 /// When OnlyHidden=true, only symbols with hidden visibility are internalized.
111 ///
112110 /// The symbol in DSOList are internalized if it is safe to drop them from
113111 /// the symbol table.
114112 ///
115113 /// Note that commandline options that are used with the above function are not
116114 /// used now!
117 ModulePass *createInternalizePass(ArrayRef ExportList,
118 bool OnlyHidden = false);
115 ModulePass *createInternalizePass(ArrayRef ExportList);
119116 /// createInternalizePass - Same as above, but with an empty exportList.
120 ModulePass *createInternalizePass(bool OnlyHidden = false);
117 ModulePass *createInternalizePass();
121118
122119 //===----------------------------------------------------------------------===//
123120 /// createDeadArgEliminationPass - This pass removes arguments from functions
3939 * @{
4040 */
4141
42 #define LTO_API_VERSION 6
42 #define LTO_API_VERSION 5
4343
4444 typedef enum {
4545 LTO_SYMBOL_ALIGNMENT_MASK = 0x0000001F, /* log2 of alignment */
7272 LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC = 2
7373 } lto_codegen_model;
7474
75 typedef enum {
76 LTO_INTERNALIZE_FULL = 0,
77 LTO_INTERNALIZE_NONE = 1,
78 LTO_INTERNALIZE_HIDDEN = 2
79 } lto_internalize_strategy;
8075
8176 /** opaque reference to a loaded object module */
8277 typedef struct LTOModule* lto_module_t;
266261 extern void
267262 lto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args,
268263 int nargs);
269
270 /**
271 * Sets the strategy to use during internalize. Default strategy is
272 * LTO_INTERNALIZE_FULL.
273 */
274 extern void
275 lto_codegen_set_internalize_strategy(lto_code_gen_t cg,
276 lto_internalize_strategy);
277264
278265 /**
279266 * Tells LTO optimization passes that this symbol must be preserved
6161 LTOCodeGenerator::LTOCodeGenerator()
6262 : Context(getGlobalContext()), Linker(new Module("ld-temp.o", Context)),
6363 TargetMach(NULL), EmitDwarfDebugInfo(false), ScopeRestrictionsDone(false),
64 CodeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC),
65 InternalizeStrategy(LTO_INTERNALIZE_FULL), NativeObjectFile(NULL) {
64 CodeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC), NativeObjectFile(NULL) {
6665 initializeLTOPasses();
6766 }
6867
164163 llvm_unreachable("Unknown PIC model!");
165164 }
166165
167 void
168 LTOCodeGenerator::setInternalizeStrategy(lto_internalize_strategy Strategy) {
169 switch (Strategy) {
170 case LTO_INTERNALIZE_FULL:
171 case LTO_INTERNALIZE_NONE:
172 case LTO_INTERNALIZE_HIDDEN:
173 InternalizeStrategy = Strategy;
174 return;
175 }
176 llvm_unreachable("Unknown internalize strategy!");
177 }
178
179166 bool LTOCodeGenerator::writeMergedModules(const char *path,
180167 std::string &errMsg) {
181168 if (!determineTarget(errMsg))
389376 }
390377
391378 void LTOCodeGenerator::applyScopeRestrictions() {
392 if (ScopeRestrictionsDone || !shouldInternalize())
379 if (ScopeRestrictionsDone)
393380 return;
394381 Module *mergedModule = Linker.getModule();
395382
441428 LLVMCompilerUsed->setSection("llvm.metadata");
442429 }
443430
444 passes.add(
445 createInternalizePass(MustPreserveList, shouldOnlyInternalizeHidden()));
431 passes.add(createInternalizePass(MustPreserveList));
446432
447433 // apply scope restrictions
448434 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 virtual bool runOnModule(Module &M);
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()
75 : ModulePass(ID) {
7776 initializeInternalizePassPass(*PassRegistry::getPassRegistry());
7877 if (!APIFile.empty()) // If a filename is specified, use it.
7978 LoadFile(APIFile.c_str());
8079 ExternalNames.insert(APIList.begin(), APIList.end());
8180 }
8281
83 InternalizePass::InternalizePass(ArrayRef ExportList,
84 bool OnlyHidden)
85 : ModulePass(ID), OnlyHidden(OnlyHidden) {
82 InternalizePass::InternalizePass(ArrayRef ExportList)
83 : ModulePass(ID){
8684 initializeInternalizePassPass(*PassRegistry::getPassRegistry());
8785 for(ArrayRef::const_iterator itr = ExportList.begin();
8886 itr != ExportList.end(); itr++) {
107105 }
108106
109107 static bool shouldInternalize(const GlobalValue &GV,
110 const std::set &ExternalNames,
111 bool OnlyHidden) {
112 if (OnlyHidden && !GV.hasHiddenVisibility())
113 return false;
114
108 const std::set &ExternalNames) {
115109 // Function must be defined here
116110 if (GV.isDeclaration())
117111 return false;
160154 }
161155
162156 // Mark all functions not in the api as internal.
157 // FIXME: maybe use private linkage?
163158 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
164 if (!shouldInternalize(*I, ExternalNames, OnlyHidden))
159 if (!shouldInternalize(*I, ExternalNames))
165160 continue;
166161
167162 I->setLinkage(GlobalValue::InternalLinkage);
195190
196191 // Mark all global variables with initializers that are not in the api as
197192 // internal as well.
193 // FIXME: maybe use private linkage?
198194 for (Module::global_iterator I = M.global_begin(), E = M.global_end();
199195 I != E; ++I) {
200 if (!shouldInternalize(*I, ExternalNames, OnlyHidden))
196 if (!shouldInternalize(*I, ExternalNames))
201197 continue;
202198
203199 I->setLinkage(GlobalValue::InternalLinkage);
209205 // Mark all aliases that are not in the api as internal as well.
210206 for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end();
211207 I != E; ++I) {
212 if (!shouldInternalize(*I, ExternalNames, OnlyHidden))
208 if (!shouldInternalize(*I, ExternalNames))
213209 continue;
214210
215211 I->setLinkage(GlobalValue::InternalLinkage);
221217 return Changed;
222218 }
223219
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 }
220 ModulePass *llvm::createInternalizePass() {
221 return new InternalizePass();
222 }
223
224 ModulePass *llvm::createInternalizePass(ArrayRef ExportList) {
225 return new InternalizePass(ExportList);
226 }
251251 // In here only for backwards compatibility. We use MC now.
252252 }
253253
254 /// lto_codegen_set_internalize_strategy - Sets the strategy to use during
255 /// internalize.
256 void lto_codegen_set_internalize_strategy(lto_code_gen_t cg,
257 lto_internalize_strategy strategy) {
258 cg->setInternalizeStrategy(strategy);
259 }
260
261254 /// lto_codegen_add_must_preserve_symbol - Adds to a list of all global symbols
262255 /// that must exist in the final generated code. If a function is not listed
263256 /// there, it might be inlined into every usage and optimized away.