From 961f2ff21e02da0919deb74b4d022023cd123e8e Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 23 Mar 2016 21:19:27 +0000 Subject: [PATCH] ELF: Split BitcodeCompiler::compile. http://reviews.llvm.org/D18410 llvm-svn: 264193 --- lld/ELF/LTO.cpp | 29 ++++++++++++----------------- lld/ELF/LTO.h | 2 ++ 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp index 7197227..7b1c31a 100644 --- a/lld/ELF/LTO.cpp +++ b/lld/ELF/LTO.cpp @@ -111,23 +111,7 @@ std::unique_ptr> BitcodeCompiler::compile() { if (Config->SaveTemps) saveBCFile(Combined, ".lto.bc"); - StringRef TripleStr = Combined.getTargetTriple(); - Triple TheTriple(TripleStr); - - // FIXME: Should we have a default triple? The gold plugin uses - // sys::getDefaultTargetTriple(), but that is probably wrong given that this - // might be a cross linker. - - std::string ErrMsg; - const Target *TheTarget = TargetRegistry::lookupTarget(TripleStr, ErrMsg); - if (!TheTarget) - fatal("target not found: " + ErrMsg); - - TargetOptions Options; - Reloc::Model R = Config->Pic ? Reloc::PIC_ : Reloc::Static; - std::unique_ptr TM( - TheTarget->createTargetMachine(TripleStr, "", "", Options, R)); - + std::unique_ptr TM(getTargetMachine()); runLTOPasses(Combined, *TM); raw_svector_ostream OS(OwningData); @@ -146,6 +130,17 @@ std::unique_ptr> BitcodeCompiler::compile() { return std::unique_ptr>(OF); } +TargetMachine *BitcodeCompiler::getTargetMachine() { + StringRef TripleStr = Combined.getTargetTriple(); + std::string Msg; + const Target *T = TargetRegistry::lookupTarget(TripleStr, Msg); + if (!T) + fatal("target not found: " + Msg); + TargetOptions Options; + Reloc::Model R = Config->Pic ? Reloc::PIC_ : Reloc::Static; + return T->createTargetMachine(TripleStr, "", "", Options, R); +} + template std::unique_ptr> BitcodeCompiler::compile(); template std::unique_ptr> BitcodeCompiler::compile(); template std::unique_ptr> BitcodeCompiler::compile(); diff --git a/lld/ELF/LTO.h b/lld/ELF/LTO.h index 266c70c..bc4d5b0 100644 --- a/lld/ELF/LTO.h +++ b/lld/ELF/LTO.h @@ -39,6 +39,8 @@ public: template std::unique_ptr> compile(); private: + llvm::TargetMachine *getTargetMachine(); + llvm::LLVMContext Context; llvm::Module Combined{"ld-temp.o", Context}; llvm::IRMover Mover{Combined}; -- 2.7.4