Index: llvm/include/llvm-c/lto.h =================================================================== --- llvm/include/llvm-c/lto.h +++ llvm/include/llvm-c/lto.h @@ -46,7 +46,7 @@ * @{ */ -#define LTO_API_VERSION 27 +#define LTO_API_VERSION 28 /** * \since prior to LTO_API_VERSION=3 @@ -536,7 +536,7 @@ * \since prior to LTO_API_VERSION=3 */ extern void -lto_codegen_debug_options(lto_code_gen_t cg, const char *); +lto_codegen_debug_options(const char *); /** * Same as the previous function, but takes every option separately through an @@ -544,8 +544,7 @@ * * \since prior to LTO_API_VERSION=26 */ -extern void lto_codegen_debug_options_array(lto_code_gen_t cg, - const char *const *, int number); +extern void lto_codegen_debug_options_array(const char *const *, int number); /** * Initializes LLVM disassemblers. Index: llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h =================================================================== --- llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h +++ llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h @@ -117,21 +117,6 @@ void addMustPreserveSymbol(StringRef Sym) { MustPreserveSymbols.insert(Sym); } - /// Pass options to the driver and optimization passes. - /// - /// These options are not necessarily for debugging purpose (the function - /// name is misleading). This function should be called before - /// LTOCodeGenerator::compilexxx(), and - /// LTOCodeGenerator::writeMergedModules(). - void setCodeGenDebugOptions(ArrayRef Opts); - - /// Parse the options set in setCodeGenDebugOptions. - /// - /// Like \a setCodeGenDebugOptions(), this must be called before - /// LTOCodeGenerator::compilexxx() and - /// LTOCodeGenerator::writeMergedModules(). - void parseCodeGenDebugOptions(); - /// Write the merged module to the file specified by the given path. Return /// true on success. /// Index: llvm/lib/LTO/LTOCodeGenerator.cpp =================================================================== --- llvm/lib/LTO/LTOCodeGenerator.cpp +++ llvm/lib/LTO/LTOCodeGenerator.cpp @@ -647,23 +647,6 @@ return true; } -void LTOCodeGenerator::setCodeGenDebugOptions(ArrayRef Options) { - for (StringRef Option : Options) - CodegenOptions.push_back(Option.str()); -} - -void LTOCodeGenerator::parseCodeGenDebugOptions() { - // if options were requested, set them - if (!CodegenOptions.empty()) { - // ParseCommandLineOptions() expects argv[0] to be program name. - std::vector CodegenArgv(1, "libLLVMLTO"); - for (std::string &Arg : CodegenOptions) - CodegenArgv.push_back(Arg.c_str()); - cl::ParseCommandLineOptions(CodegenArgv.size(), CodegenArgv.data()); - } -} - - void LTOCodeGenerator::DiagnosticHandler(const DiagnosticInfo &DI) { // Map the LLVM internal diagnostic severity to the LTO diagnostic severity. lto_codegen_diagnostic_severity_t Severity; Index: llvm/tools/lto/lto.cpp =================================================================== --- llvm/tools/lto/lto.cpp +++ llvm/tools/lto/lto.cpp @@ -80,6 +80,8 @@ static LLVMContext *LTOContext = nullptr; +static std::vector CGOptions; + struct LTOToolDiagnosticHandler : public DiagnosticHandler { bool handleDiagnostics(const DiagnosticInfo &DI) override { if (DI.getSeverity() != DS_Error) { @@ -98,6 +100,16 @@ } }; +void parseCodeGenDebugOptions(ArrayRef Options) { + if (!Options.empty()) { + // ParseCommandLineOptions() expects argv[0] to be program name. + std::vector CodegenArgv(1, "libLLVMLTO"); + for (const std::string &Arg : Options) + CodegenArgv.push_back(Arg.c_str()); + cl::ParseCommandLineOptions(CodegenArgv.size(), CodegenArgv.data()); + } +} + // Initialize the configured targets if they have not been initialized. static void lto_initialize() { if (!initialized) { @@ -118,6 +130,8 @@ LTOContext = &Context; LTOContext->setDiagnosticHandler( std::make_unique(), true); + + parseCodeGenDebugOptions(CGOptions); initialized = true; } } @@ -434,7 +448,6 @@ static void maybeParseOptions(lto_code_gen_t cg) { if (!parsedOptions) { - unwrap(cg)->parseCodeGenDebugOptions(); lto_add_attrs(cg); parsedOptions = true; } @@ -480,21 +493,15 @@ DisableLTOVectorization); } -void lto_codegen_debug_options(lto_code_gen_t cg, const char *opt) { - SmallVector Options; +void lto_codegen_debug_options(const char *opt) { for (std::pair o = getToken(opt); !o.first.empty(); o = getToken(o.second)) - Options.push_back(o.first); - - unwrap(cg)->setCodeGenDebugOptions(Options); + CGOptions.push_back(o.first.str()); } -void lto_codegen_debug_options_array(lto_code_gen_t cg, - const char *const *options, int number) { - SmallVector Options; +void lto_codegen_debug_options_array(const char *const *options, int number) { for (int i = 0; i < number; ++i) - Options.push_back(options[i]); - unwrap(cg)->setCodeGenDebugOptions(makeArrayRef(Options)); + CGOptions.push_back(options[i]); } unsigned int lto_api_version() { return LTO_API_VERSION; }