Skip to content

Commit b15d6eb

Browse files
PawelJureksys_zuul
authored andcommitted
Create extenstion -D options for clang based on active extension string.
Change-Id: Iee5aa0d0259abc3ab821396b4c8e7b0366161d78
1 parent 7fe6b82 commit b15d6eb

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

IGC/OCLFE/igd_fcl_mcl/source/clang_tb.cpp

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,43 @@ namespace TC
10371037
return internalDefines;
10381038
}
10391039

1040+
// The expected extensions input string is in a form:
1041+
// -cl-ext=-all,+supported_ext_name,+second_supported_ext_name
1042+
std::string GetCDefinesForExtensions(llvm::StringRef extensions, unsigned int oclStd) {
1043+
1044+
std::string extDefines;
1045+
1046+
// check for the last occurence of -all, as it invalidates previous occurances.
1047+
const StringRef clExtPrefix = "-cl-ext=-all,";
1048+
size_t pos = extensions.rfind(clExtPrefix);
1049+
if (pos == llvm::StringRef::npos) {
1050+
// If this string does not exist the input string does not contain valid extension list
1051+
// or it has all extensions disabled (-all without colon afterwards).
1052+
return extDefines;
1053+
}
1054+
1055+
extensions = extensions.substr(pos+clExtPrefix.size());
1056+
1057+
// string with defines should be similar in size, ",+" will change to "-D".
1058+
extDefines.reserve(extensions.size());
1059+
1060+
llvm::SmallVector<StringRef, 0> v;
1061+
extensions.split(v, ',');
1062+
1063+
for (auto ext : v) {
1064+
if (ext.consume_front("+")) {
1065+
if (ext.equals("cl_intel_device_side_avc_motion_estimation")) {
1066+
// If the user provided -cl-std option we need to add the define only if it's 1.2 and above.
1067+
// This is because clang will not allow declarations of extension's functions which use avc types otherwise.
1068+
if (!(oclStd >= 120 || oclStd == 0)) continue;
1069+
}
1070+
extDefines.append(" -D").append(ext);
1071+
}
1072+
}
1073+
1074+
return extDefines;
1075+
}
1076+
10401077
/*****************************************************************************\
10411078
10421079
Function:
@@ -1407,47 +1444,10 @@ namespace TC
14071444

14081445
optionsEx += " " + extensions;
14091446

1447+
unsigned int oclStd = GetOclCVersionFromOptions(pInputArgs->options.data(), nullptr, pInputArgs->oclVersion, exceptString);
14101448
// get additional -D flags from internal options
14111449
optionsEx += " " + GetCDefinesFromInternalOptions(pInternalOptions);
1412-
1413-
if (extensions.find("cl_intel_subgroups_short") != std::string::npos)
1414-
{
1415-
optionsEx += " -Dcl_intel_subgroups_short";
1416-
}
1417-
if (extensions.find("cl_intel_subgroups_char") != std::string::npos)
1418-
{
1419-
optionsEx += " -Dcl_intel_subgroups_char";
1420-
}
1421-
if (extensions.find("cl_intel_subgroups_long") != std::string::npos)
1422-
{
1423-
optionsEx += " -Dcl_intel_subgroups_long";
1424-
}
1425-
if (extensions.find("cl_intel_media_block_io") != std::string::npos)
1426-
{
1427-
optionsEx += " -Dcl_intel_media_block_io";
1428-
}
1429-
if (extensions.find("cl_intel_device_side_avc_motion_estimation") != std::string::npos)
1430-
{
1431-
// If the user provided -cl-std option we need to add the define only if it's 1.2 and above.
1432-
// This is because clang will not allow declarations of extension's functions which use avc types otherwise.
1433-
unsigned int oclStd = GetOclCVersionFromOptions(pInputArgs->options.data(), nullptr, pInputArgs->oclVersion, exceptString);
1434-
if (oclStd >= 120 || oclStd == 0) {
1435-
optionsEx += " -Dcl_intel_device_side_avc_motion_estimation";
1436-
}
1437-
}
1438-
if (extensions.find("cl_intel_64bit_global_atomics_placeholder") != std::string::npos)
1439-
{
1440-
optionsEx += " -Dcl_intel_64bit_global_atomics_placeholder";
1441-
}
1442-
if (extensions.find("cl_khr_int64_base_atomics") != std::string::npos)
1443-
{
1444-
optionsEx += " -Dcl_khr_int64_base_atomics";
1445-
}
1446-
if (extensions.find("cl_khr_int64_extended_atomics") != std::string::npos)
1447-
{
1448-
optionsEx += " -Dcl_khr_int64_extended_atomics";
1449-
}
1450-
1450+
optionsEx += " " + GetCDefinesForExtensions(extensions, oclStd);
14511451
optionsEx += " -D__IMAGE_SUPPORT__ -D__ENDIAN_LITTLE__";
14521452

14531453
IOCLFEBinaryResult *pResultPtr = NULL;

0 commit comments

Comments
 (0)