From 842667e62b3a27f43d07074ddd26235d4cce5ebb Mon Sep 17 00:00:00 2001 From: Wenju He Date: Fri, 17 May 2024 14:10:52 +0800 Subject: [PATCH] Add parsing of OpenCL C++ -cl-std flags (#510) (#513) Hello! Support for OpenCL C++ was added into LLVM 14, but IGC doesn't support parsing of those flags just yet. I've opened PRs which adds support for parsing these flags to the following repositories: [intel-graphics-compiler](https://github.com/intel/intel-graphics-compiler/pull/328), [compute-runtime](https://github.com/intel/compute-runtime/pull/731) and [opencl-clang](https://github.com/intel/opencl-clang/pull/510). The options are passed down into LLVM which then happily compiles my C++ kernel. PRs should be merged in the following order: opencl-clang, intel-graphics-compiler, then finally compute-runtime. Kind regards, -Lucas Co-authored-by: Lucas Zadrozny (cherry picked from commit 545a14577cbeb3cee371afed22fea71c2025e724) Co-authored-by: lucasz93 --- opencl_clang_options.td | 3 +++ options_compile.cpp | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/opencl_clang_options.td b/opencl_clang_options.td index feadb6e6..1404acc5 100644 --- a/opencl_clang_options.td +++ b/opencl_clang_options.td @@ -33,6 +33,9 @@ def cl_std_CL1_1: Flag<["-"], "cl-std=CL1.1">; def cl_std_CL1_2: Flag<["-"], "cl-std=CL1.2">; def cl_std_CL2_0: Flag<["-"], "cl-std=CL2.0">; def cl_std_CL3_0: Flag<["-"], "cl-std=CL3.0">; +def cl_std_CLCxx: Flag<["-"], "cl-std=CLC++">; +def cl_std_CLCxx1_0: Flag<["-"], "cl-std=CLC++1.0">; +def cl_std_CLCxx2021: Flag<["-"], "cl-std=CLC++2021">; def cl_uniform_work_group_size: Flag<["-"], "cl-uniform-work-group-size">; def cl_no_subgroup_ifp: Flag<["-"], "cl-no-subgroup-ifp">; def triple : Separate<["-"], "triple">, HelpText<"Specify target triple (e.g. i686-apple-darwin9)">; diff --git a/options_compile.cpp b/options_compile.cpp index 85ebde1b..fa9ecfcb 100644 --- a/options_compile.cpp +++ b/options_compile.cpp @@ -71,6 +71,7 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args, ArgsVector &effectiveArgs) { // Reset args int iCLStdSet = 0; + bool isCpp = false; bool fp64Enabled = false; std::string szTriple; std::string sourceName(llvm::Twine(s_progID++).str()); @@ -139,6 +140,17 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args, iCLStdSet = 300; effectiveArgs.push_back((*it)->getAsString(args)); break; + case OPT_COMPILE_cl_std_CLCxx: + case OPT_COMPILE_cl_std_CLCxx1_0: + iCLStdSet = 200; + isCpp = true; + effectiveArgs.push_back((*it)->getAsString(args)); + break; + case OPT_COMPILE_cl_std_CLCxx2021: + iCLStdSet = 300; + isCpp = true; + effectiveArgs.push_back((*it)->getAsString(args)); + break; case OPT_COMPILE_triple: szTriple = (*it)->getValue(); break; @@ -220,7 +232,9 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args, // Specifying the option makes clang emit function body for functions // marked with inline keyword. - effectiveArgs.push_back("-fgnu89-inline"); + if (!isCpp) { + effectiveArgs.push_back("-fgnu89-inline"); + } // Do not support all extensions by default. Support for a particular // extension should be enabled by passing a '-cl-ext' option in pszOptionsEx.