Prepend -s option when -cmc is not used

Related-To: NEO-5582

- "-s filename" is added to build options
based on filename returned from debugger
- when "-cmc" is passed as first option, do not
modify user options.

Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2021-03-01 16:09:19 +01:00
committed by Compute-Runtime-Automation
parent 042e971a93
commit 4191dfdb43
5 changed files with 41 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2017-2020 Intel Corporation * Copyright (C) 2017-2021 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -99,10 +99,7 @@ cl_int Program::build(
} }
appendKernelDebugOptions(*clDevice, internalOptions); appendKernelDebugOptions(*clDevice, internalOptions);
notifyDebuggerWithSourceCode(*clDevice, filename); notifyDebuggerWithSourceCode(*clDevice, filename);
if (!filename.empty()) { prependFilePathToOptions(filename);
// Add "-s" flag first so it will be ignored by clang in case the options already have this flag set.
options = std::string("-s ") + filename + " " + options;
}
phaseReached[clDevice->getRootDeviceIndex()] = BuildPhase::SourceCodeNotification; phaseReached[clDevice->getRootDeviceIndex()] = BuildPhase::SourceCodeNotification;
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2017-2020 Intel Corporation * Copyright (C) 2017-2021 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -129,12 +129,10 @@ cl_int Program::compile(
if (sourceLevelDebuggerNotified[device->getRootDeviceIndex()]) { if (sourceLevelDebuggerNotified[device->getRootDeviceIndex()]) {
continue; continue;
} }
appendKernelDebugOptions(*device, internalOptions);
std::string filename; std::string filename;
appendKernelDebugOptions(*device, internalOptions);
notifyDebuggerWithSourceCode(*device, filename); notifyDebuggerWithSourceCode(*device, filename);
if (!filename.empty()) { prependFilePathToOptions(filename);
options = std::string("-s ") + filename + " " + options;
}
sourceLevelDebuggerNotified[device->getRootDeviceIndex()] = true; sourceLevelDebuggerNotified[device->getRootDeviceIndex()] = true;
} }

View File

@@ -546,4 +546,13 @@ cl_int Program::processInputDevices(ClDeviceVector *&deviceVectorPtr, cl_uint nu
} }
return CL_SUCCESS; return CL_SUCCESS;
} }
void Program::prependFilePathToOptions(const std::string &filename) {
ConstStringRef cmcOption = "-cmc";
if (!filename.empty() && options.compare(0, cmcOption.size(), cmcOption.data())) {
// Add "-s" flag first so it will be ignored by clang in case the options already have this flag set.
options = std::string("-s ") + filename + " " + options;
}
}
} // namespace NEO } // namespace NEO

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2017-2020 Intel Corporation * Copyright (C) 2017-2021 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -296,6 +296,7 @@ class Program : public BaseObject<_cl_program> {
MOCKABLE_VIRTUAL bool appendKernelDebugOptions(ClDevice &clDevice, std::string &internalOptions); MOCKABLE_VIRTUAL bool appendKernelDebugOptions(ClDevice &clDevice, std::string &internalOptions);
void notifyDebuggerWithSourceCode(ClDevice &clDevice, std::string &filename); void notifyDebuggerWithSourceCode(ClDevice &clDevice, std::string &filename);
void prependFilePathToOptions(const std::string &filename);
void setBuildStatus(cl_build_status status); void setBuildStatus(cl_build_status status);
void setBuildStatusSuccess(const ClDeviceVector &deviceVector, cl_program_binary_type binaryType); void setBuildStatusSuccess(const ClDeviceVector &deviceVector, cl_program_binary_type binaryType);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018-2020 Intel Corporation * Copyright (C) 2018-2021 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -129,6 +129,19 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsCompi
EXPECT_THAT(pProgram->getOptions(), ::testing::StartsWith("-s debugFileName")); EXPECT_THAT(pProgram->getOptions(), ::testing::StartsWith("-s debugFileName"));
} }
TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsCompiledWithCmCOptionThenDashSFilenameIsNotPrepended) {
MockActiveSourceLevelDebugger *sourceLevelDebugger = new MockActiveSourceLevelDebugger;
sourceLevelDebugger->sourceCodeFilename = "debugFileName";
pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->debugger.reset(sourceLevelDebugger);
char options[] = "-cmc -cl-opt-disable";
cl_int retVal = pProgram->compile(pProgram->getDevices(), options,
0, nullptr, nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_THAT(pProgram->getOptions(), ::testing::Not(::testing::StartsWith("-s debugFileName")));
EXPECT_THAT(pProgram->getOptions(), ::testing::HasSubstr(CompilerOptions::optDisable.data()));
}
TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsBuiltThenInternalOptionsIncludeDebugFlag) { TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsBuiltThenInternalOptionsIncludeDebugFlag) {
std::string receivedInternalOptions; std::string receivedInternalOptions;
@@ -169,6 +182,17 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsBuilt
EXPECT_THAT(pProgram->getOptions(), ::testing::StartsWith("-s debugFileName")); EXPECT_THAT(pProgram->getOptions(), ::testing::StartsWith("-s debugFileName"));
} }
TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsBuiltWithCmCOptionThenDashSFilenameIsNotPrepended) {
MockActiveSourceLevelDebugger *sourceLevelDebugger = new MockActiveSourceLevelDebugger;
sourceLevelDebugger->sourceCodeFilename = "debugFileName";
pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->debugger.reset(sourceLevelDebugger);
char options[] = "-cmc -cl-opt-disable";
cl_int retVal = pProgram->build(pProgram->getDevices(), options, false);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_THAT(pProgram->getOptions(), ::testing::Not(::testing::StartsWith("-s debugFileName")));
}
TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsLinkedThenKernelDebugOptionsAreAppended) { TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsLinkedThenKernelDebugOptionsAreAppended) {
MockActiveSourceLevelDebugger *sourceLevelDebugger = new MockActiveSourceLevelDebugger; MockActiveSourceLevelDebugger *sourceLevelDebugger = new MockActiveSourceLevelDebugger;
pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->debugger.reset(sourceLevelDebugger); pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->debugger.reset(sourceLevelDebugger);