From 93c85b966d6151486987ae64cbdf6cc3f5caab83 Mon Sep 17 00:00:00 2001 From: foreman Date: Tue, 9 Jul 2019 16:10:34 -0400 Subject: [PATCH] P4 to Git Change 1961269 by slinder1@slinder1-fiji-ocllc on 2019/07/09 16:03:15 SWDEV-161424 - Fix broken option handling in Comgr path Introduces another potential bug if any options in Options::llvmOptions contain spaces, but this existed before the switch to Comgr. Affected files ... ... //depot/stg/opencl/drivers/opencl/runtime/device/devprogram.cpp#50 edit --- rocclr/runtime/device/devprogram.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/rocclr/runtime/device/devprogram.cpp b/rocclr/runtime/device/devprogram.cpp index bb91aa3892..60ce4282fc 100644 --- a/rocclr/runtime/device/devprogram.cpp +++ b/rocclr/runtime/device/devprogram.cpp @@ -51,6 +51,19 @@ typedef llvm::AMDGPU::HSAMD::Kernel::Arg::Metadata KernelArgMD; namespace device { +// TODO: Can this be unified with the copies in: +// runtime/device/pal/palprogram.cpp, runtime/device/gpu/gpuprogram.cpp, +// compiler/lib/utils/v0_8/libUtils.h, compiler/lib/backends/gpu/hsail_be.cpp, +// compiler/legacy-lib/utils/v0_8/libUtils.h, +// and compiler/legacy-lib/backends/gpu/hsail_be.cpp ? +inline static std::vector splitSpaceSeparatedString(const char *str) { + std::string s(str); + std::stringstream ss(s); + std::istream_iterator beg(ss), end; + std::vector vec(beg, end); + return vec; +} + // ================================================================================================ Program::Program(amd::Device& device) : device_(device), @@ -676,9 +689,10 @@ bool Program::compileImplLC(const std::string& sourceCode, optLevel << "-O" << options->oVariables->OptLevel; driverOptions.push_back(optLevel.str()); - for (int i = 0; i < options->getLLVMArgc(); ++i) { - driverOptions.push_back(options->getLLVMArgv()[i]); - } + // TODO: Can this be fixed at the source? options->llvmOptions is a flat + // string, but should really be a vector of strings. + std::vector splitLlvmOptions = splitSpaceSeparatedString(options->llvmOptions.c_str()); + driverOptions.insert(driverOptions.end(), splitLlvmOptions.begin(), splitLlvmOptions.end()); std::vector processedOptions = ProcessOptions(options); driverOptions.insert(driverOptions.end(), processedOptions.begin(), processedOptions.end()); @@ -1509,9 +1523,10 @@ bool Program::linkImplLC(amd::option::Options* options) { std::vector codegenOptions; - for (int i = 0; i < options->getLLVMArgc(); ++i) { - codegenOptions.push_back(options->getLLVMArgv()[i]); - } + // TODO: Can this be fixed at the source? options->llvmOptions is a flat + // string, but should really be a vector of strings. + std::vector splitLlvmOptions = splitSpaceSeparatedString(options->llvmOptions.c_str()); + codegenOptions.insert(codegenOptions.end(), splitLlvmOptions.begin(), splitLlvmOptions.end()); // Set the -O# std::ostringstream optLevel;