From 0edf1ffbdff92371320f39f3132a6ba5d640d1dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20MARTINEZ=20CAAMA=C3=91O?= Date: Fri, 28 Oct 2022 08:44:53 +0000 Subject: [PATCH] SWDEV-286150 - [NFC] Refactor repeated option parsing code into function Change-Id: I606dc1cd48d880974142e523d16f5d9ac6f3aff1 [ROCm/clr commit: 40f75306d5b426a3fd3bcfc9ae4562d6dd100919] --- projects/clr/rocclr/platform/program.cpp | 52 +++++++++--------------- 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/projects/clr/rocclr/platform/program.cpp b/projects/clr/rocclr/platform/program.cpp index 3e57c99bc5..4d9649c4a7 100644 --- a/projects/clr/rocclr/platform/program.cpp +++ b/projects/clr/rocclr/platform/program.cpp @@ -229,6 +229,22 @@ device::Program* Program::getDeviceProgram(const Device& device) const { Monitor Program::buildLock_("OCL build program", true); +static bool adjustOptionsOnIgnoreEnv(std::string &cppstr) { + // if there is a -ignore-env, adjust options. + bool optionChangable = true; + if (cppstr.size() > 0) { + // Set the options to be the string after -ignore-env + const char ignore_env[] = "-ignore-env"; + size_t pos = cppstr.find(ignore_env); + if (pos != std::string::npos) { + cppstr = cppstr.substr(pos + sizeof(ignore_env)); + optionChangable = false; + } + remove_g_option(cppstr); + } + return optionChangable; +} + int32_t Program::compile(const std::vector& devices, size_t numHeaders, const std::vector& headerPrograms, const char** headerIncludeNames, const char* options, @@ -243,17 +259,7 @@ int32_t Program::compile(const std::vector& devices, size_t numHeaders, // Process build options. std::string cppstr(options ? options : ""); - - // if there is a -ignore-env, adjust options. - if (cppstr.size() > 0) { - // Set the options to be the string after -ignore-env - size_t pos = cppstr.find("-ignore-env"); - if (pos != std::string::npos) { - cppstr = cppstr.substr(pos + sizeof("-ignore-env")); - optionChangable = false; - } - remove_g_option(cppstr); - } + optionChangable &= adjustOptionsOnIgnoreEnv(cppstr); std::vector headers(numHeaders); for (size_t i = 0; i < numHeaders; ++i) { @@ -330,17 +336,7 @@ int32_t Program::link(const std::vector& devices, size_t numInputs, // Process build options. std::string cppstr(options ? options : ""); - - // if there is a -ignore-env, adjust options. - if (cppstr.size() > 0) { - // Set the options to be the string after -ignore-env - size_t pos = cppstr.find("-ignore-env"); - if (pos != std::string::npos) { - cppstr = cppstr.substr(pos + sizeof("-ignore-env")); - optionChangable = false; - } - remove_g_option(cppstr); - } + optionChangable &= adjustOptionsOnIgnoreEnv(cppstr); // Link the program programs associated with the given devices. for (const auto& it : devices) { @@ -515,17 +511,7 @@ int32_t Program::build(const std::vector& devices, const char* options, // Process build options. std::string cppstr(options ? options : ""); - - // if there is a -ignore-env, adjust options. - if (cppstr.size() > 0) { - // Set the options to be the string after -ignore-env - size_t pos = cppstr.find("-ignore-env"); - if (pos != std::string::npos) { - cppstr = cppstr.substr(pos + sizeof("-ignore-env")); - optionChangable = false; - } - remove_g_option(cppstr); - } + optionChangable &= adjustOptionsOnIgnoreEnv(cppstr); // Build the program programs associated with the given devices. for (const auto& it : devices) {