diff --git a/llvm/include/llvm-c/lto.h b/llvm/include/llvm-c/lto.h --- a/llvm/include/llvm-c/lto.h +++ b/llvm/include/llvm-c/lto.h @@ -46,7 +46,7 @@ * @{ */ -#define LTO_API_VERSION 25 +#define LTO_API_VERSION 26 /** * \since prior to LTO_API_VERSION=3 @@ -514,12 +514,25 @@ /** * Sets options to help debug codegen bugs. * + * This function takes one or more options separated by spaces. + * Warning: passing file paths through this function may confuse the argument + * parser if the paths contain spaces. + * * \since prior to LTO_API_VERSION=3 */ extern void lto_codegen_debug_options(lto_code_gen_t cg, const char *); /** + * Same as the previous function, but takes every option separately through an + * array. + * + * \since prior to LTO_API_VERSION=26 + */ +extern void lto_codegen_debug_options_array(lto_code_gen_t cg, + const char *const *, int number); + +/** * Initializes LLVM disassemblers. * FIXME: This doesn't really belong here. * diff --git a/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h b/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h --- a/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h +++ b/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h @@ -35,6 +35,7 @@ #define LLVM_LTO_LTOCODEGENERATOR_H #include "llvm-c/lto.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringSet.h" @@ -122,7 +123,7 @@ /// name is misleading). This function should be called before /// LTOCodeGenerator::compilexxx(), and /// LTOCodeGenerator::writeMergedModules(). - void setCodeGenDebugOptions(StringRef Opts); + void setCodeGenDebugOptions(ArrayRef Opts); /// Parse the options set in setCodeGenDebugOptions. /// diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp --- a/llvm/lib/LTO/LTOCodeGenerator.cpp +++ b/llvm/lib/LTO/LTOCodeGenerator.cpp @@ -622,12 +622,9 @@ return true; } -/// setCodeGenDebugOptions - Set codegen debugging options to aid in debugging -/// LTO problems. -void LTOCodeGenerator::setCodeGenDebugOptions(StringRef Options) { - for (std::pair o = getToken(Options); !o.first.empty(); - o = getToken(o.second)) - CodegenOptions.push_back(o.first); +void LTOCodeGenerator::setCodeGenDebugOptions(ArrayRef Options) { + for (StringRef Option : Options) + CodegenOptions.push_back(Option); } void LTOCodeGenerator::parseCodeGenDebugOptions() { diff --git a/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp --- a/llvm/tools/lto/lto.cpp +++ b/llvm/tools/lto/lto.cpp @@ -13,6 +13,7 @@ #include "llvm-c/lto.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Bitcode/BitcodeReader.h" #include "llvm/CodeGen/CommandFlags.inc" #include "llvm/IR/DiagnosticInfo.h" @@ -453,7 +454,17 @@ } void lto_codegen_debug_options(lto_code_gen_t cg, const char *opt) { - unwrap(cg)->setCodeGenDebugOptions(opt); + std::vector Options; + for (std::pair o = getToken(opt); !o.first.empty(); + o = getToken(o.second)) + Options.push_back(o.first.data()); + + unwrap(cg)->setCodeGenDebugOptions(Options); +} + +void lto_codegen_debug_options_array(lto_code_gen_t cg, + const char *const *options, int number) { + unwrap(cg)->setCodeGenDebugOptions(makeArrayRef(options, number)); } unsigned int lto_api_version() { return LTO_API_VERSION; } diff --git a/llvm/tools/lto/lto.exports b/llvm/tools/lto/lto.exports --- a/llvm/tools/lto/lto.exports +++ b/llvm/tools/lto/lto.exports @@ -33,6 +33,7 @@ lto_codegen_set_pic_model lto_codegen_write_merged_modules lto_codegen_debug_options +lto_codegen_debug_options_array lto_codegen_set_assembler_args lto_codegen_set_assembler_path lto_codegen_set_cpu