@@ -29,7 +29,9 @@ IN THE SOFTWARE.
29
29
#include < map>
30
30
#include < memory>
31
31
#include < mutex>
32
+ #include < regex>
32
33
#include < utility>
34
+ #include < cstdlib>
33
35
34
36
#include " cif/builtins/memory/buffer/impl/buffer_impl.h"
35
37
#include " cif/export/pimpl_base.h"
@@ -49,6 +51,8 @@ namespace TC{
49
51
50
52
namespace IGC {
51
53
54
+ static constexpr const char * UseLegacyCMCPrefixEnv = " IGC_USE_LEGACY_CMC_PREFIX" ;
55
+
52
56
CIF_DECLARE_INTERFACE_PIMPL (FclOclTranslationCtx) : CIF::PimplBase
53
57
{
54
58
CIF_PIMPL_DECLARE_CONSTRUCTOR (CIF::Version_t version, CIF_PIMPL (FclOclDeviceCtx) *globalState,
@@ -109,7 +113,19 @@ CIF_DECLARE_INTERFACE_PIMPL(FclOclTranslationCtx) : CIF::PimplBase
109
113
CIF::Builtins::BufferSimple *tracingOptions,
110
114
uint32_t tracingOptionsCount
111
115
) {
112
- if ((options != nullptr ) && (options->GetSizeRaw () > 0 ) && (strstr (options->GetMemory <char >(), " -cmc" ))) {
116
+ auto needsCMFE = [](const char *optStart, size_t size) {
117
+ if (!optStart)
118
+ return false ;
119
+
120
+ // TODO: remove this once all clients fixed their tests
121
+ if (std::getenv (UseLegacyCMCPrefixEnv)) {
122
+ return strstr (optStart, " -cmc" ) != nullptr ;
123
+ }
124
+ // "-cmc" should be present as the first argument to invoke CM frontend
125
+ return std::regex_match (optStart, optStart + size,
126
+ std::regex (" ^\\ s*-cmc(($)|(\\ s+.*))" ));
127
+ };
128
+ if (options != nullptr && needsCMFE (options->GetMemory <char >(), options->GetSizeRaw ())) {
113
129
assert (this ->outType == CodeType::spirV);
114
130
return TranslateCM (outVersion, src, options, internalOptions, tracingOptions, tracingOptionsCount);
115
131
}
0 commit comments