llvm.org GIT mirror llvm / aa7ad07
LTO: Change signature of LTOCodeGenerator::setCodePICModel() to take a Reloc::Model. This allows us to remove a bunch of code in LTOCodeGenerator and llvm-lto and has the side effect of improving error handling in the libLTO C API. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245756 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 4 years ago
4 changed file(s) with 19 addition(s) and 47 deletion(s). Raw diff Collapse all Expand all
7272
7373 void setTargetOptions(TargetOptions options);
7474 void setDebugInfo(lto_debug_model);
75 void setCodePICModel(lto_codegen_model);
75 void setCodePICModel(Reloc::Model model) { RelocModel = model; }
7676
7777 void setCpu(const char *mCpu) { MCpu = mCpu; }
7878 void setAttr(const char *mAttr) { MAttr = mAttr; }
161161 std::unique_ptr TargetMach;
162162 bool EmitDwarfDebugInfo = false;
163163 bool ScopeRestrictionsDone = false;
164 lto_codegen_model CodeModel = LTO_CODEGEN_PIC_MODEL_DEFAULT;
164 Reloc::Model RelocModel = Reloc::Default;
165165 StringSet MustPreserveSymbols;
166166 StringSet AsmUndefinedRefs;
167167 std::vector CodegenOptions;
163163 llvm_unreachable("Unknown debug format!");
164164 }
165165
166 void LTOCodeGenerator::setCodePICModel(lto_codegen_model model) {
167 switch (model) {
168 case LTO_CODEGEN_PIC_MODEL_STATIC:
169 case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
170 case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
171 case LTO_CODEGEN_PIC_MODEL_DEFAULT:
172 CodeModel = model;
173 return;
174 }
175 llvm_unreachable("Unknown PIC model!");
176 }
177
178166 bool LTOCodeGenerator::writeMergedModules(const char *path,
179167 std::string &errMsg) {
180168 if (!determineTarget(errMsg))
298286 const Target *march = TargetRegistry::lookupTarget(TripleStr, errMsg);
299287 if (!march)
300288 return false;
301
302 // The relocation model is actually a static member of TargetMachine and
303 // needs to be set before the TargetMachine is instantiated.
304 Reloc::Model RelocModel = Reloc::Default;
305 switch (CodeModel) {
306 case LTO_CODEGEN_PIC_MODEL_STATIC:
307 RelocModel = Reloc::Static;
308 break;
309 case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
310 RelocModel = Reloc::PIC_;
311 break;
312 case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
313 RelocModel = Reloc::DynamicNoPIC;
314 break;
315 case LTO_CODEGEN_PIC_MODEL_DEFAULT:
316 // RelocModel is already the default, so leave it that way.
317 break;
318 }
319289
320290 // Construct LTOModule, hand over ownership of module and target. Use MAttr as
321291 // the default set of features.
173173 if (UseDiagnosticHandler)
174174 CodeGen.setDiagnosticHandler(handleDiagnostics, nullptr);
175175
176 switch (RelocModel) {
177 case Reloc::Static:
178 CodeGen.setCodePICModel(LTO_CODEGEN_PIC_MODEL_STATIC);
179 break;
180 case Reloc::PIC_:
181 CodeGen.setCodePICModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC);
182 break;
183 case Reloc::DynamicNoPIC:
184 CodeGen.setCodePICModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC);
185 break;
186 default:
187 CodeGen.setCodePICModel(LTO_CODEGEN_PIC_MODEL_DEFAULT);
188 }
176 CodeGen.setCodePICModel(RelocModel);
189177
190178 CodeGen.setDebugInfo(LTO_DEBUG_MODEL_DWARF);
191179 CodeGen.setTargetOptions(Options);
268268 }
269269
270270 bool lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model model) {
271 unwrap(cg)->setCodePICModel(model);
272 return false;
271 switch (model) {
272 case LTO_CODEGEN_PIC_MODEL_STATIC:
273 unwrap(cg)->setCodePICModel(Reloc::Static);
274 return false;
275 case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
276 unwrap(cg)->setCodePICModel(Reloc::PIC_);
277 return false;
278 case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
279 unwrap(cg)->setCodePICModel(Reloc::DynamicNoPIC);
280 return false;
281 case LTO_CODEGEN_PIC_MODEL_DEFAULT:
282 unwrap(cg)->setCodePICModel(Reloc::Default);
283 return false;
284 }
285 sLastErrorString = "Unknown PIC model";
286 return true;
273287 }
274288
275289 void lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu) {