Skip to content

Add an option to enable fdeclare-opencl-builtins #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions opencl_clang_options.td
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ def target_triple : Separate<["-"], "target-triple">, HelpText<"Specify target
def spir_std_1_0: Flag<["-"], "spir-std=1.0">;
def spir_std_1_2: Flag<["-"], "spir-std=1.2">;
def x : Separate<["-"], "x">;
def fdeclare_opencl_builtins : Flag<["-"], "fdeclare-opencl-builtins">;
21 changes: 14 additions & 7 deletions options_compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
ArgsVector &effectiveArgs) {
// Reset args
int iCLStdSet = 0;
int fp64Enable = 0;
bool fp64Enabled = false;
bool useFdeclareOpenCLBuiltins = false;
std::string szTriple;
std::string sourceName(llvm::Twine(s_progID++).str());

Expand Down Expand Up @@ -163,6 +164,10 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
effectiveArgs.push_back("-debug-info-kind=line-tables-only");
effectiveArgs.push_back("-dwarf-version=4");
break;
case OPT_COMPILE_fdeclare_opencl_builtins:
effectiveArgs.push_back("-fdeclare-opencl-builtins");
effectiveArgs.push_back("-finclude-default-header");
useFdeclareOpenCLBuiltins = true;
}
}

Expand Down Expand Up @@ -198,8 +203,10 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
}

effectiveArgs.push_back(szTriple);
effectiveArgs.push_back("-include");
effectiveArgs.push_back("opencl-c.h");
if (!useFdeclareOpenCLBuiltins) {
effectiveArgs.push_back("-include");
effectiveArgs.push_back("opencl-c.h");
}

// Don't optimize in the frontend
// clang defaults to -O0, and in that mode, does not produce IR that is
Expand Down Expand Up @@ -230,7 +237,7 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
end = effectiveArgs.end();
it != end; ++it) {
if (it->compare("-Dcl_khr_fp64") == 0) {
fp64Enable = true;
fp64Enabled = true;
}
}

Expand Down Expand Up @@ -287,9 +294,9 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
bool useModules = !std::any_of(extMap.begin(), extMap.end(),
[](const auto& p) {return p.second == false;});

if (useModules && (iCLStdSet < 300)) {
if (!useFdeclareOpenCLBuiltins && useModules && (iCLStdSet < 300)) {
effectiveArgs.push_back("-fmodules");
if (fp64Enable == 0) {
if (!fp64Enabled) {
if (szTriple.find("spir64") != szTriple.npos) {
if (iCLStdSet <= 120) {
effectiveArgs.push_back("-fmodule-file=opencl-c-12-spir64.pcm");
Expand All @@ -303,7 +310,7 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
effectiveArgs.push_back("-fmodule-file=opencl-c-20-spir.pcm");
}
}
} else if (fp64Enable == 1) {
} else {
if (szTriple.find("spir64") != szTriple.npos) {
if (iCLStdSet <= 120) {
effectiveArgs.push_back("-fmodule-file=opencl-c-12-spir64-fp64.pcm");
Expand Down