summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2015-08-21 22:57:17 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2015-08-21 22:57:17 +0000
commit44ee84eec5ffc9bed4daee3de971689ae2e31501 (patch)
treebf37b95c9290478ee05e715822de8f6144fe5b85
parentbd8a0856e2f959d313f8a8888ca468f02e6e4173 (diff)
downloadbcm5719-llvm-44ee84eec5ffc9bed4daee3de971689ae2e31501.tar.gz
bcm5719-llvm-44ee84eec5ffc9bed4daee3de971689ae2e31501.zip
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. llvm-svn: 245756
-rw-r--r--llvm/include/llvm/LTO/LTOCodeGenerator.h4
-rw-r--r--llvm/lib/LTO/LTOCodeGenerator.cpp30
-rw-r--r--llvm/tools/llvm-lto/llvm-lto.cpp14
-rw-r--r--llvm/tools/lto/lto.cpp18
4 files changed, 19 insertions, 47 deletions
diff --git a/llvm/include/llvm/LTO/LTOCodeGenerator.h b/llvm/include/llvm/LTO/LTOCodeGenerator.h
index a7ccbceda41..1676530a972 100644
--- a/llvm/include/llvm/LTO/LTOCodeGenerator.h
+++ b/llvm/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<TargetMachine> 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<std::string> CodegenOptions;
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp
index 6203000c2ec..efeac033850 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/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/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp
index 7f87859f3b2..b17f1ea307b 100644
--- a/llvm/tools/llvm-lto/llvm-lto.cpp
+++ b/llvm/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/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp
index 5c712f18c9e..aebb1c64a31 100644
--- a/llvm/tools/lto/lto.cpp
+++ b/llvm/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) {
OpenPOWER on IntegriCloud