@@ -66,7 +66,8 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
66
66
ArgsVector &effectiveArgs) {
67
67
// Reset args
68
68
int iCLStdSet = 0 ;
69
- int fp64Enable = 0 ;
69
+ bool fp64Enabled = false ;
70
+ bool useFdeclareOpenCLBuiltins = false ;
70
71
std::string szTriple;
71
72
std::string sourceName (llvm::Twine (s_progID++).str ());
72
73
@@ -163,6 +164,10 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
163
164
effectiveArgs.push_back (" -debug-info-kind=line-tables-only" );
164
165
effectiveArgs.push_back (" -dwarf-version=4" );
165
166
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 ;
166
171
}
167
172
}
168
173
@@ -198,8 +203,10 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
198
203
}
199
204
200
205
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
+ }
203
210
204
211
// Don't optimize in the frontend
205
212
// 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,
230
237
end = effectiveArgs.end ();
231
238
it != end; ++it) {
232
239
if (it->compare (" -Dcl_khr_fp64" ) == 0 ) {
233
- fp64Enable = true ;
240
+ fp64Enabled = true ;
234
241
}
235
242
}
236
243
@@ -287,9 +294,9 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
287
294
bool useModules = !std::any_of (extMap.begin (), extMap.end (),
288
295
[](const auto & p) {return p.second == false ;});
289
296
290
- if (useModules && (iCLStdSet < 300 )) {
297
+ if (!useFdeclareOpenCLBuiltins && useModules && (iCLStdSet < 300 )) {
291
298
effectiveArgs.push_back (" -fmodules" );
292
- if (fp64Enable == 0 ) {
299
+ if (!fp64Enabled ) {
293
300
if (szTriple.find (" spir64" ) != szTriple.npos ) {
294
301
if (iCLStdSet <= 120 ) {
295
302
effectiveArgs.push_back (" -fmodule-file=opencl-c-12-spir64.pcm" );
@@ -303,7 +310,7 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
303
310
effectiveArgs.push_back (" -fmodule-file=opencl-c-20-spir.pcm" );
304
311
}
305
312
}
306
- } else if (fp64Enable == 1 ) {
313
+ } else {
307
314
if (szTriple.find (" spir64" ) != szTriple.npos ) {
308
315
if (iCLStdSet <= 120 ) {
309
316
effectiveArgs.push_back (" -fmodule-file=opencl-c-12-spir64-fp64.pcm" );
0 commit comments