diff options
Diffstat (limited to 'llvm/tools/llvm-lto')
-rw-r--r-- | llvm/tools/llvm-lto/llvm-lto.cpp | 65 |
1 files changed, 48 insertions, 17 deletions
diff --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp index b47e68e82850c..0bd9078f2d8ca 100644 --- a/llvm/tools/llvm-lto/llvm-lto.cpp +++ b/llvm/tools/llvm-lto/llvm-lto.cpp @@ -21,7 +21,7 @@ #include "llvm/ADT/Twine.h" #include "llvm/Bitcode/BitcodeReader.h" #include "llvm/Bitcode/BitcodeWriter.h" -#include "llvm/CodeGen/CommandFlags.inc" +#include "llvm/CodeGen/CommandFlags.h" #include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/LLVMContext.h" @@ -62,6 +62,8 @@ using namespace llvm; +static codegen::RegisterCodeGenFlags CGF; + static cl::opt<char> OptLevel("O", cl::desc("Optimization level. [-O0, -O1, -O2, or -O3] " "(default = '-O2')"), @@ -223,6 +225,10 @@ static cl::opt<bool> CheckHasObjC( "check-for-objc", cl::init(false), cl::desc("Only check if the module has objective-C defined in it")); +static cl::opt<bool> PrintMachOCPUOnly( + "print-macho-cpu-only", cl::init(false), + cl::desc("Instead of running LTO, print the mach-o cpu in each IR file")); + namespace { struct ModuleInfo { @@ -404,6 +410,30 @@ static void listDependentLibraries() { } } +static void printMachOCPUOnly() { + LLVMContext Context; + Context.setDiagnosticHandler(std::make_unique<LLVMLTODiagnosticHandler>(), + true); + TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags(); + for (auto &Filename : InputFilenames) { + ErrorOr<std::unique_ptr<LTOModule>> ModuleOrErr = + LTOModule::createFromFile(Context, Filename, Options); + if (!ModuleOrErr) + error(ModuleOrErr, "llvm-lto: "); + + Expected<uint32_t> CPUType = (*ModuleOrErr)->getMachOCPUType(); + Expected<uint32_t> CPUSubType = (*ModuleOrErr)->getMachOCPUSubType(); + if (!CPUType) + error("Error while printing mach-o cputype: " + + toString(CPUType.takeError())); + if (!CPUSubType) + error("Error while printing mach-o cpusubtype: " + + toString(CPUSubType.takeError())); + outs() << llvm::format("%s:\ncputype: %u\ncpusubtype: %u\n", + Filename.c_str(), *CPUType, *CPUSubType); + } +} + /// Create a combined index file from the input IR files and write it. /// /// This is meant to enable testing of ThinLTO combined index generation, @@ -454,7 +484,7 @@ static std::string getThinLTOOutputFile(const std::string &Path, if (std::error_code EC = llvm::sys::fs::create_directories(ParentPath)) error(EC, "error creating the directory '" + ParentPath + "'"); } - return NewPath.str(); + return std::string(NewPath.str()); } namespace thinlto { @@ -521,7 +551,7 @@ public: ThinLTOCodeGenerator ThinGenerator; ThinLTOProcessing(const TargetOptions &Options) { - ThinGenerator.setCodePICModel(getRelocModel()); + ThinGenerator.setCodePICModel(codegen::getExplicitRelocModel()); ThinGenerator.setTargetOptions(Options); ThinGenerator.setCacheDir(ThinLTOCacheDir); ThinGenerator.setCachePruningInterval(ThinLTOCachePruningInterval); @@ -873,7 +903,7 @@ int main(int argc, char **argv) { InitializeAllAsmParsers(); // set up the TargetOptions for the machine - TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); + TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags(); if (ListSymbolsOnly) { listSymbols(Options); @@ -905,6 +935,11 @@ int main(int argc, char **argv) { return 0; } + if (PrintMachOCPUOnly) { + printMachOCPUOnly(); + return 0; + } + if (ThinLTOMode.getNumOccurrences()) { if (ThinLTOMode.getNumOccurrences() > 1) report_fatal_error("You can't specify more than one -thinlto-action"); @@ -929,7 +964,7 @@ int main(int argc, char **argv) { if (UseDiagnosticHandler) CodeGen.setDiagnosticHandler(handleDiagnostics, nullptr); - CodeGen.setCodePICModel(getRelocModel()); + CodeGen.setCodePICModel(codegen::getExplicitRelocModel()); CodeGen.setFreestanding(EnableFreestanding); CodeGen.setDebugInfo(LTO_DEBUG_MODEL_DWARF); @@ -957,7 +992,7 @@ int main(int argc, char **argv) { lto_symbol_attributes Attrs = Module->getSymbolAttributes(I); unsigned Scope = Attrs & LTO_SYMBOL_SCOPE_MASK; if (Scope != LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN) - KeptDSOSyms.push_back(Name); + KeptDSOSyms.push_back(std::string(Name)); } // We use the first input module as the destination module when @@ -980,22 +1015,18 @@ int main(int argc, char **argv) { CodeGen.addMustPreserveSymbol(KeptDSOSyms[i]); // Set cpu and attrs strings for the default target/subtarget. - CodeGen.setCpu(MCPU.c_str()); + CodeGen.setCpu(codegen::getMCPU().c_str()); CodeGen.setOptLevel(OptLevel - '0'); - std::string attrs; - for (unsigned i = 0; i < MAttrs.size(); ++i) { - if (i > 0) - attrs.append(","); - attrs.append(MAttrs[i]); - } - - if (!attrs.empty()) + auto MAttrs = codegen::getMAttrs(); + if (!MAttrs.empty()) { + std::string attrs = join(MAttrs, ","); CodeGen.setAttr(attrs); + } - if (FileType.getNumOccurrences()) - CodeGen.setFileType(FileType); + if (auto FT = codegen::getExplicitFileType()) + CodeGen.setFileType(FT.getValue()); if (!OutputFilename.empty()) { if (!CodeGen.optimize(DisableVerify, DisableInline, DisableGVNLoadPRE, |