Index: llvm/include/llvm-c/lto.h =================================================================== --- llvm/include/llvm-c/lto.h +++ llvm/include/llvm-c/lto.h @@ -44,7 +44,7 @@ * @{ */ -#define LTO_API_VERSION 25 +#define LTO_API_VERSION 26 /** * \since prior to LTO_API_VERSION=3 @@ -514,11 +514,24 @@ /** * 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. Index: llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h =================================================================== --- llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h +++ 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" @@ -124,6 +125,13 @@ /// LTOCodeGenerator::writeMergedModules(). void setCodeGenDebugOptions(StringRef Opts); + /// Pass options to the driver and optimization passes. + /// + /// See the function above for more information. + /// + /// This version takes an array of already separated strings. + void setCodeGenDebugOptions(ArrayRef Opts); + /// Parse the options set in setCodeGenDebugOptions. /// /// Like \a setCodeGenDebugOptions(), this must be called before Index: llvm/lib/LTO/LTOCodeGenerator.cpp =================================================================== --- llvm/lib/LTO/LTOCodeGenerator.cpp +++ llvm/lib/LTO/LTOCodeGenerator.cpp @@ -630,6 +630,11 @@ CodegenOptions.push_back(o.first); } +void LTOCodeGenerator::setCodeGenDebugOptions(ArrayRef Options) { + for (StringRef Option : Options) + CodegenOptions.push_back(Option); +} + void LTOCodeGenerator::parseCodeGenDebugOptions() { // if options were requested, set them if (!CodegenOptions.empty()) { Index: llvm/tools/lto/lto.cpp =================================================================== --- llvm/tools/lto/lto.cpp +++ llvm/tools/lto/lto.cpp @@ -453,7 +453,15 @@ } void lto_codegen_debug_options(lto_code_gen_t cg, const char *opt) { - unwrap(cg)->setCodeGenDebugOptions(opt); + unwrap(cg)->setCodeGenDebugOptions(StringRef(opt)); +} + +void lto_codegen_debug_options_array(lto_code_gen_t cg, + const char *const *options, int number) { + if (!number || !options) + return; + + unwrap(cg)->setCodeGenDebugOptions(makeArrayRef(options, number)); } unsigned int lto_api_version() { return LTO_API_VERSION; } Index: llvm/tools/lto/lto.exports =================================================================== --- llvm/tools/lto/lto.exports +++ 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