From: Peter Collingbourne Date: Fri, 21 Aug 2015 22:57:17 +0000 (+0000) Subject: LTO: Change signature of LTOCodeGenerator::setCodePICModel() to take a Reloc::Model. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=aa7ad072c97a20161a4d75a054f75535998558f9;p=oota-llvm.git 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 --- diff --git a/include/llvm/LTO/LTOCodeGenerator.h b/include/llvm/LTO/LTOCodeGenerator.h index a7ccbceda41..1676530a972 100644 --- a/include/llvm/LTO/LTOCodeGenerator.h +++ b/include/llvm/LTO/LTOCodeGenerator.h @@ -73,7 +73,7 @@ struct LTOCodeGenerator { void setTargetOptions(TargetOptions options); void setDebugInfo(lto_debug_model); - void setCodePICModel(lto_codegen_model); + void setCodePICModel(Reloc::Model model) { RelocModel = model; } void setCpu(const char *mCpu) { MCpu = mCpu; } void setAttr(const char *mAttr) { MAttr = mAttr; } @@ -162,7 +162,7 @@ private: std::unique_ptr TargetMach; bool EmitDwarfDebugInfo = false; bool ScopeRestrictionsDone = false; - lto_codegen_model CodeModel = LTO_CODEGEN_PIC_MODEL_DEFAULT; + Reloc::Model RelocModel = Reloc::Default; StringSet MustPreserveSymbols; StringSet AsmUndefinedRefs; std::vector CodegenOptions; diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp index 6203000c2ec..efeac033850 100644 --- a/lib/LTO/LTOCodeGenerator.cpp +++ b/lib/LTO/LTOCodeGenerator.cpp @@ -164,18 +164,6 @@ void LTOCodeGenerator::setDebugInfo(lto_debug_model debug) { llvm_unreachable("Unknown debug format!"); } -void LTOCodeGenerator::setCodePICModel(lto_codegen_model model) { - switch (model) { - case LTO_CODEGEN_PIC_MODEL_STATIC: - case LTO_CODEGEN_PIC_MODEL_DYNAMIC: - case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC: - case LTO_CODEGEN_PIC_MODEL_DEFAULT: - CodeModel = model; - return; - } - llvm_unreachable("Unknown PIC model!"); -} - bool LTOCodeGenerator::writeMergedModules(const char *path, std::string &errMsg) { if (!determineTarget(errMsg)) @@ -300,24 +288,6 @@ bool LTOCodeGenerator::determineTarget(std::string &errMsg) { if (!march) return false; - // The relocation model is actually a static member of TargetMachine and - // needs to be set before the TargetMachine is instantiated. - Reloc::Model RelocModel = Reloc::Default; - switch (CodeModel) { - case LTO_CODEGEN_PIC_MODEL_STATIC: - RelocModel = Reloc::Static; - break; - case LTO_CODEGEN_PIC_MODEL_DYNAMIC: - RelocModel = Reloc::PIC_; - break; - case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC: - RelocModel = Reloc::DynamicNoPIC; - break; - case LTO_CODEGEN_PIC_MODEL_DEFAULT: - // RelocModel is already the default, so leave it that way. - break; - } - // Construct LTOModule, hand over ownership of module and target. Use MAttr as // the default set of features. SubtargetFeatures Features(MAttr); diff --git a/tools/llvm-lto/llvm-lto.cpp b/tools/llvm-lto/llvm-lto.cpp index 7f87859f3b2..b17f1ea307b 100644 --- a/tools/llvm-lto/llvm-lto.cpp +++ b/tools/llvm-lto/llvm-lto.cpp @@ -174,19 +174,7 @@ int main(int argc, char **argv) { if (UseDiagnosticHandler) CodeGen.setDiagnosticHandler(handleDiagnostics, nullptr); - switch (RelocModel) { - case Reloc::Static: - CodeGen.setCodePICModel(LTO_CODEGEN_PIC_MODEL_STATIC); - break; - case Reloc::PIC_: - CodeGen.setCodePICModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC); - break; - case Reloc::DynamicNoPIC: - CodeGen.setCodePICModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC); - break; - default: - CodeGen.setCodePICModel(LTO_CODEGEN_PIC_MODEL_DEFAULT); - } + CodeGen.setCodePICModel(RelocModel); CodeGen.setDebugInfo(LTO_DEBUG_MODEL_DWARF); CodeGen.setTargetOptions(Options); diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp index 5c712f18c9e..aebb1c64a31 100644 --- a/tools/lto/lto.cpp +++ b/tools/lto/lto.cpp @@ -269,8 +269,22 @@ bool lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model debug) { } bool lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model model) { - unwrap(cg)->setCodePICModel(model); - return false; + switch (model) { + case LTO_CODEGEN_PIC_MODEL_STATIC: + unwrap(cg)->setCodePICModel(Reloc::Static); + return false; + case LTO_CODEGEN_PIC_MODEL_DYNAMIC: + unwrap(cg)->setCodePICModel(Reloc::PIC_); + return false; + case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC: + unwrap(cg)->setCodePICModel(Reloc::DynamicNoPIC); + return false; + case LTO_CODEGEN_PIC_MODEL_DEFAULT: + unwrap(cg)->setCodePICModel(Reloc::Default); + return false; + } + sLastErrorString = "Unknown PIC model"; + return true; } void lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu) {