Skip to content

Commit dfdbfa7

Browse files
committed
Add an option to enable fdeclare-opencl-builtins
Signed-off-by: haonanya <[email protected]>
1 parent 4e83bbf commit dfdbfa7

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

opencl_clang_options.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ def target_triple : Separate<["-"], "target-triple">, HelpText<"Specify target
4040
def spir_std_1_0: Flag<["-"], "spir-std=1.0">;
4141
def spir_std_1_2: Flag<["-"], "spir-std=1.2">;
4242
def x : Separate<["-"], "x">;
43+
def fdeclare_opencl_builtins : Flag<["-"], "fdeclare-opencl-builtins">;

options_compile.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
6666
ArgsVector &effectiveArgs) {
6767
// Reset args
6868
int iCLStdSet = 0;
69-
int fp64Enable = 0;
69+
bool fp64Enabled = false;
70+
bool useFdeclareOpenCLBuiltins = false;
7071
std::string szTriple;
7172
std::string sourceName(llvm::Twine(s_progID++).str());
7273

@@ -163,6 +164,10 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
163164
effectiveArgs.push_back("-debug-info-kind=line-tables-only");
164165
effectiveArgs.push_back("-dwarf-version=4");
165166
break;
167+
case OPT_COMPILE_fdeclare_opencl_builtins:
168+
effectiveArgs.push_back("-fdeclare-opencl-builtins");
169+
effectiveArgs.push_back("-finclude-default-header");
170+
useFdeclareOpenCLBuiltins = true;
166171
}
167172
}
168173

@@ -198,8 +203,10 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
198203
}
199204

200205
effectiveArgs.push_back(szTriple);
201-
effectiveArgs.push_back("-include");
202-
effectiveArgs.push_back("opencl-c.h");
206+
if (!useFdeclareOpenCLBuiltins) {
207+
effectiveArgs.push_back("-include");
208+
effectiveArgs.push_back("opencl-c.h");
209+
}
203210

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

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

290-
if (useModules && (iCLStdSet < 300)) {
297+
if (!useFdeclareOpenCLBuiltins && useModules && (iCLStdSet < 300)) {
291298
effectiveArgs.push_back("-fmodules");
292-
if (fp64Enable == 0) {
299+
if (!fp64Enabled) {
293300
if (szTriple.find("spir64") != szTriple.npos) {
294301
if (iCLStdSet <= 120) {
295302
effectiveArgs.push_back("-fmodule-file=opencl-c-12-spir64.pcm");
@@ -303,7 +310,7 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
303310
effectiveArgs.push_back("-fmodule-file=opencl-c-20-spir.pcm");
304311
}
305312
}
306-
} else if (fp64Enable == 1) {
313+
} else {
307314
if (szTriple.find("spir64") != szTriple.npos) {
308315
if (iCLStdSet <= 120) {
309316
effectiveArgs.push_back("-fmodule-file=opencl-c-12-spir64-fp64.pcm");

0 commit comments

Comments
 (0)