diff options
Diffstat (limited to 'tools/llvm-lto/llvm-lto.cpp')
-rw-r--r-- | tools/llvm-lto/llvm-lto.cpp | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/tools/llvm-lto/llvm-lto.cpp b/tools/llvm-lto/llvm-lto.cpp index 0fc68ae3ad9d..8b39f1285f5f 100644 --- a/tools/llvm-lto/llvm-lto.cpp +++ b/tools/llvm-lto/llvm-lto.cpp @@ -17,11 +17,12 @@ #include "llvm/LTO/LTOCodeGenerator.h" #include "llvm/LTO/LTOModule.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/Signals.h" -#include "llvm/Support/raw_ostream.h" #include "llvm/Support/TargetSelect.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; @@ -77,32 +78,26 @@ int main(int argc, char **argv) { InitializeAllAsmParsers(); // set up the TargetOptions for the machine - TargetOptions Options; - Options.LessPreciseFPMADOption = EnableFPMAD; - Options.NoFramePointerElim = DisableFPElim; - Options.AllowFPOpFusion = FuseFPOps; - Options.UnsafeFPMath = EnableUnsafeFPMath; - Options.NoInfsFPMath = EnableNoInfsFPMath; - Options.NoNaNsFPMath = EnableNoNaNsFPMath; - Options.HonorSignDependentRoundingFPMathOption = - EnableHonorSignDependentRoundingFPMath; - Options.UseSoftFloat = GenerateSoftFloatCalls; - if (FloatABIForCalls != FloatABI::Default) - Options.FloatABIType = FloatABIForCalls; - Options.NoZerosInBSS = DontPlaceZerosInBSS; - Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt; - Options.DisableTailCalls = DisableTailCalls; - Options.StackAlignmentOverride = OverrideStackAlignment; - Options.TrapFuncName = TrapFuncName; - Options.PositionIndependentExecutable = EnablePIE; - Options.EnableSegmentedStacks = SegmentedStacks; - Options.UseInitArray = UseInitArray; + TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); unsigned BaseArg = 0; LTOCodeGenerator CodeGen; - CodeGen.setCodePICModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC); + 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.setDebugInfo(LTO_DEBUG_MODEL_DWARF); CodeGen.setTargetOptions(Options); @@ -114,8 +109,8 @@ int main(int argc, char **argv) { for (unsigned i = BaseArg; i < InputFilenames.size(); ++i) { std::string error; - OwningPtr<LTOModule> Module(LTOModule::makeLTOModule(InputFilenames[i].c_str(), - Options, error)); + std::unique_ptr<LTOModule> Module( + LTOModule::createFromFile(InputFilenames[i].c_str(), Options, error)); if (!error.empty()) { errs() << argv[0] << ": error loading file '" << InputFilenames[i] << "': " << error << "\n"; @@ -149,19 +144,29 @@ int main(int argc, char **argv) { for (unsigned i = 0; i < KeptDSOSyms.size(); ++i) CodeGen.addMustPreserveSymbol(KeptDSOSyms[i].c_str()); + std::string attrs; + for (unsigned i = 0; i < MAttrs.size(); ++i) { + if (i > 0) + attrs.append(","); + attrs.append(MAttrs[i]); + } + + if (!attrs.empty()) + CodeGen.setAttr(attrs.c_str()); + if (!OutputFilename.empty()) { size_t len = 0; std::string ErrorInfo; const void *Code = CodeGen.compile(&len, DisableOpt, DisableInline, DisableGVNLoadPRE, ErrorInfo); - if (Code == NULL) { + if (!Code) { errs() << argv[0] << ": error compiling the code: " << ErrorInfo << "\n"; return 1; } raw_fd_ostream FileStream(OutputFilename.c_str(), ErrorInfo, - sys::fs::F_Binary); + sys::fs::F_None); if (!ErrorInfo.empty()) { errs() << argv[0] << ": error opening the file '" << OutputFilename << "': " << ErrorInfo << "\n"; @@ -171,7 +176,7 @@ int main(int argc, char **argv) { FileStream.write(reinterpret_cast<const char *>(Code), len); } else { std::string ErrorInfo; - const char *OutputName = NULL; + const char *OutputName = nullptr; if (!CodeGen.compile_to_file(&OutputName, DisableOpt, DisableInline, DisableGVNLoadPRE, ErrorInfo)) { errs() << argv[0] |