Skip to content

Commit e0fae9f

Browse files
fda0igcbot
authored andcommitted
Refactor LoadRegistryKeys error reporting and igc_opts handling
- Fold ExtractIGCOptsFromOptions into LoadRegistryKeys so callers pass raw options instead of pre-extracted igc_opts. - Replace bool* error output with std::string* to propagate descriptive parse error messages to callers. - Guard PrintIGCFlags with !defined(IGC_FCL_BUILD).
1 parent 0f383cf commit e0fae9f

6 files changed

Lines changed: 59 additions & 62 deletions

File tree

IGC/AdaptorOCL/ocl_igc_interface/impl/igc_ocl_translation_ctx_impl.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,11 @@ CIF_DECLARE_INTERFACE_PIMPL(IgcOclTranslationCtx) : CIF::PimplBase {
237237
USC::SShaderStageBTLayout zeroLayout = USC::g_cZeroShaderStageBTLayout;
238238
IGC::COCLBTILayout oclLayout(&zeroLayout);
239239

240-
std::string igcOptsError;
241-
std::string RegKeysFlagsFromOptions = ExtractIGCOptsFromOptions(inputArgs.pOptions, igcOptsError);
242-
if (!igcOptsError.empty()) {
243-
outputInterface->GetImpl()->SetError(TranslationErrorType::Unused, igcOptsError.c_str());
244-
return outputInterface.release();
240+
std::string igcFlagsError;
241+
LoadRegistryKeys(inputArgs.pOptions ? inputArgs.pOptions : "", &igcFlagsError);
242+
if (!igcFlagsError.empty()) {
243+
outputInterface->GetImpl()->SetError(TranslationErrorType::Unused, igcFlagsError.c_str());
245244
}
246-
bool RegFlagNameError = 0;
247-
LoadRegistryKeys(RegKeysFlagsFromOptions, &RegFlagNameError);
248-
if (RegFlagNameError)
249-
outputInterface->GetImpl()->SetError(
250-
TranslationErrorType::Unused, "Invalid registry flag name in -igc_opts, at least one flag has been ignored");
251245

252246
IGC::CPlatform igcPlatform = this->globalState.GetIgcCPlatform();
253247

IGC/OCLFE/igd_fcl_mcl/source/clang_tb.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,10 +1136,9 @@ bool CClangTranslationBlock::Translate(const STB_TranslateInputArgs *pInputArgs,
11361136

11371137
// Initialize IGC flags from env vars, registry, and -igc_opts on first call.
11381138
std::string igcOptsError;
1139-
std::string igcOpts = ExtractIGCOptsFromOptions(pInputArgs->pOptions, igcOptsError);
1140-
LoadRegistryKeys(igcOpts);
1139+
LoadRegistryKeys(pInputArgs->pOptions ? pInputArgs->pOptions : "", &igcOptsError);
11411140
if (!igcOptsError.empty()) {
1142-
pOutputArgs->ErrorString.append("warning: " + igcOptsError + "\n");
1141+
pOutputArgs->ErrorString.append(igcOptsError);
11431142
}
11441143

11451144
std::string exceptString;

IGC/common/igc_regkeys.cpp

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ static void LoadIGCFlagsFromRegistry(const std::string &options = "", bool *RegF
960960
}
961961
}
962962

963-
static void LoadIGCFlagsFromOptionsString(const std::string_view &options, bool *parseError) {
963+
static void LoadIGCFlagsFromOptionsString(const std::string_view &options, std::string *parseError) {
964964
std::string_view allSeparators = ", \v\f\t\r\n";
965965

966966
for (IGCFlag &igcFlag : g_IGCFlagsArray) {
@@ -993,19 +993,28 @@ static void LoadIGCFlagsFromOptionsString(const std::string_view &options, bool
993993
igcFlag.m_Value = parsedInt;
994994
igcFlag.isSet = true;
995995
} else {
996-
std::cerr << "Failed to parse flag '" << igcFlag.name << "' as an unsigned integer. Token: '" << token << "\n";
996+
std::string msg = "Failed to parse flag '" + std::string(igcFlag.name) + "' as an unsigned integer. Token: '" +
997+
std::string(token) + "'\n";
998+
if (parseError)
999+
*parseError += msg;
9971000
setError = true;
9981001
}
9991002
} else { // IsString
10001003
size_t foundEqual = token.find('=');
10011004
if (foundEqual != std::string::npos) {
1002-
std::cerr << "Failed to parse flag '" << igcFlag.name << "', found an unexpected '=' character in token: '"
1003-
<< token << "'. Make sure to use comma , separator in igc_opts.\n";
1005+
std::string msg = "Failed to parse flag '" + std::string(igcFlag.name) +
1006+
"', found an unexpected '=' character in token: '" + std::string(token) +
1007+
"'. Make sure to use comma , separator in igc_opts.\n";
1008+
if (parseError)
1009+
*parseError += msg;
10041010
setError = true;
10051011
}
10061012

10071013
if (!setError && sizeof(igcFlag.m_string) <= token.size()) {
1008-
std::cerr << "Failed to parse flag '" << igcFlag.name << "' due to max length limit overflow.\n";
1014+
std::string msg =
1015+
"Failed to parse flag '" + std::string(igcFlag.name) + "' due to max length limit overflow.\n";
1016+
if (parseError)
1017+
*parseError += msg;
10091018
setError = true;
10101019
}
10111020

@@ -1014,13 +1023,10 @@ static void LoadIGCFlagsFromOptionsString(const std::string_view &options, bool
10141023
igcFlag.isSet = true;
10151024
}
10161025
}
1017-
1018-
if (setError && parseError != nullptr)
1019-
*parseError = true;
10201026
}
10211027
}
10221028

1023-
static void PrintIGCFlags() {
1029+
[[maybe_unused]] static void PrintIGCFlags() {
10241030
if (IGC_IS_FLAG_ENABLED(PrintDebugSettings)) {
10251031
for (IGCFlag &igcFlag : g_IGCFlagsArray) {
10261032
if (igcFlag.IsSetToNonDefaultValue()) {
@@ -1072,7 +1078,30 @@ void InitializeRegKeys() {
10721078
}
10731079
}
10741080

1075-
void LoadRegistryKeys(const std::string &options, bool *optionsParseError) {
1081+
static std::string ExtractIGCOptsFromOptions(const std::string &options, std::string *errorString) {
1082+
std::string result;
1083+
std::string_view remaining = options;
1084+
while (!remaining.empty()) {
1085+
std::size_t found = remaining.find("-igc_opts");
1086+
if (found == std::string_view::npos)
1087+
break;
1088+
1089+
std::size_t firstQuote = remaining.find('\'', found);
1090+
std::size_t secondQuote =
1091+
(firstQuote != std::string_view::npos) ? remaining.find('\'', firstQuote + 1) : std::string_view::npos;
1092+
if (firstQuote == std::string_view::npos || secondQuote == std::string_view::npos) {
1093+
if (errorString)
1094+
*errorString += "Missing single quotes for -igc_opts\n";
1095+
break;
1096+
}
1097+
result += remaining.substr(firstQuote + 1, secondQuote - firstQuote - 1);
1098+
result += ',';
1099+
remaining = remaining.substr(secondQuote + 1);
1100+
}
1101+
return result;
1102+
}
1103+
1104+
void LoadRegistryKeys(const std::string &options, std::string *optionsParseError) {
10761105
// only load the debug flags once before compiling to avoid any multi-threading issue
10771106
static std::mutex loadFlags;
10781107
static volatile bool flagsSet = false;
@@ -1081,8 +1110,15 @@ void LoadRegistryKeys(const std::string &options, bool *optionsParseError) {
10811110
if (!flagsSet) {
10821111
flagsSet = true;
10831112
LoadIGCFlagsFromRegistry();
1084-
LoadIGCFlagsFromOptionsString(options, optionsParseError);
1113+
1114+
std::string igcOpts = ExtractIGCOptsFromOptions(options, optionsParseError);
1115+
if (!igcOpts.empty()) {
1116+
LoadIGCFlagsFromOptionsString(igcOpts, optionsParseError);
1117+
}
1118+
1119+
#if !defined(IGC_FCL_BUILD)
10851120
PrintIGCFlags();
1121+
#endif
10861122
InitializeRegKeys();
10871123
}
10881124
}
@@ -1149,28 +1185,3 @@ void GetKeysSetExplicitly(std::string *KeyValuePairs, std::string *OptionKeys) {
11491185
}
11501186
}
11511187
#endif
1152-
1153-
std::string ExtractIGCOptsFromOptions(const char *pOptions, std::string &errorString) {
1154-
std::string result;
1155-
if (pOptions == nullptr)
1156-
return result;
1157-
1158-
std::string_view remaining = pOptions;
1159-
while (!remaining.empty()) {
1160-
std::size_t found = remaining.find("-igc_opts");
1161-
if (found == std::string_view::npos)
1162-
break;
1163-
1164-
std::size_t firstQuote = remaining.find('\'', found);
1165-
std::size_t secondQuote =
1166-
(firstQuote != std::string_view::npos) ? remaining.find('\'', firstQuote + 1) : std::string_view::npos;
1167-
if (firstQuote == std::string_view::npos || secondQuote == std::string_view::npos) {
1168-
errorString = "Missing single quotes for -igc_opts";
1169-
break;
1170-
}
1171-
result += remaining.substr(firstQuote + 1, secondQuote - firstQuote - 1);
1172-
result += ',';
1173-
remaining = remaining.substr(secondQuote + 1);
1174-
}
1175-
return result;
1176-
}

IGC/common/igc_regkeys.hpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void DumpIGCRegistryKeyDefinitions();
176176
void DumpIGCRegistryKeyDefinitions3(std::string driverRegistryPath, unsigned long pciBus, unsigned long pciDevice,
177177
unsigned long pciFunction);
178178
void InitializeRegKeys();
179-
void LoadRegistryKeys(const std::string &options = "", bool *RegFlagNameError = nullptr);
179+
void LoadRegistryKeys(const std::string &options = "", std::string *optionsParseError = nullptr);
180180
extern "C" bool ReadIGCRegistry(const char *pName, void *pValue, unsigned int size, IGCFlagType type);
181181
void SetCurrentDebugHash(const ShaderHash &hash);
182182
void SetCurrentEntryPoints(const std::vector<std::string> &entry_points);
@@ -191,9 +191,9 @@ static inline void GetKeysSetExplicitly(std::string *KeyValuePairs, std::string
191191
static inline void SetCurrentDebugHash(const ShaderHash &hash) { IGC_UNUSED(hash); }
192192
static inline void SetCurrentEntryPoints(const std::vector<std::string> &entry_points) { IGC_UNUSED(entry_points); }
193193
static inline void InitializeRegKeys() {};
194-
static inline void LoadRegistryKeys(const std::string &options = "", bool *RegFlagNameError = nullptr) {
194+
static inline void LoadRegistryKeys(const std::string &options = "", std::string *optionsParseError = nullptr) {
195195
IGC_UNUSED(options);
196-
IGC_UNUSED(RegFlagNameError);
196+
IGC_UNUSED(optionsParseError);
197197
}
198198
#define IGC_SET_FLAG_VALUE(name, regkeyValue) true
199199
#define DECLARE_IGC_REGKEY(dataType, regkeyName, defaultValue, description, releaseMode) \
@@ -225,12 +225,6 @@ template <typename T> bool IsEnabled(const T &value) { return value != 0; }
225225
inline bool doesRegexMatch(const std::string &src, const char *regex) { return false; }
226226
#endif
227227

228-
// Extracts the content of -igc_opts '...' sections from an options string.
229-
// Supports multiple -igc_opts instances; their contents are concatenated with commas.
230-
// Returns the extracted comma-separated key=value pairs suitable for LoadRegistryKeys.
231-
// On malformed input (missing quotes), sets errorString and returns what was extracted so far.
232-
std::string ExtractIGCOptsFromOptions(const char *pOptions, std::string &errorString);
233-
234228
// unset: Unlimited/Enable - return true
235229
// 0: Disabled - return false
236230
// >=1: Enable - key_value -= 1; return true

IGC/ocloc_tests/Options/igc_opts_parsing_edge_cases.cl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ SPDX-License-Identifier: MIT
5959
// RUN: env IGC_PrintDebugSettings=1 ocloc compile -file %s \
6060
// RUN: -options "-igc_opts 'PrintAfter=SomePass ForceOCLSIMDWidth=8'" \
6161
// RUN: -device dg2 2>&1 | FileCheck %s --check-prefix=STR-NOT-LAST
62-
// STR-NOT-LAST: Failed to parse flag 'PrintAfter'
63-
// STR-NOT-LAST: ForceOCLSIMDWidth 8
62+
// STR-NOT-LAST-DAG: Failed to parse flag 'PrintAfter'
63+
// STR-NOT-LAST-DAG: ForceOCLSIMDWidth 8
6464

6565
// String between two numbers, space-separated.
6666
// RUN: env IGC_PrintDebugSettings=1 ocloc compile -file %s \
6767
// RUN: -options "-igc_opts 'ForceOCLSIMDWidth=8 PrintAfter=SomePass SetLoopUnrollThreshold=100'" \
6868
// RUN: -device dg2 2>&1 | FileCheck %s --check-prefix=STR-MIDDLE
69-
// STR-MIDDLE: Failed to parse flag 'PrintAfter'
69+
// STR-MIDDLE-DAG: Failed to parse flag 'PrintAfter'
7070
// STR-MIDDLE-DAG: ForceOCLSIMDWidth 8
7171
// STR-MIDDLE-DAG: SetLoopUnrollThreshold 100
7272

IGC/ocloc_tests/Options/igc_opts_single_quotes.cl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22

33
// RUN: ocloc compile -file %s -options " -igc_opts 'DumpVISAASMToConsole=1" -device dg2 | FileCheck %s
44

5-
// XFAIL: *
65
// CHECK: Missing single quotes for -igc_opts
76
__kernel void foo(int a, int b, __global int *res) { *res = a + b; }

0 commit comments

Comments
 (0)