@@ -15,7 +15,6 @@ SPDX-License-Identifier: MIT
15
15
#include " Compiler/CISACodeGen/OpenCLKernelCodeGen.hpp"
16
16
#include " Compiler/CodeGenContextWrapper.hpp"
17
17
#include " Compiler/Optimizer/OpenCLPasses/StackOverflowDetection/StackOverflowDetection.hpp"
18
- #include " SPIRV/SPIRVInternal.h"
19
18
20
19
#include " common/LLVMWarningsPush.hpp"
21
20
@@ -48,6 +47,40 @@ using namespace IGC::IGCMD;
48
47
49
48
namespace {
50
49
50
+ static const std::unordered_set<std::string> OCLExtOpBuiltinNames = {
51
+ " acos" , " acosh" , " acospi" , " asin" , " asinh" , " asinpi" ,
52
+ " atan" , " atan2" , " atanh" , " atanpi" , " atan2pi" , " cbrt" ,
53
+ " ceil" , " copysign" , " cos" , " cosh" , " cospi" , " erfc" ,
54
+ " erf" , " exp" , " exp2" , " exp10" , " expm1" , " fabs" ,
55
+ " fdim" , " floor" , " fma" , " fmax" , " fmin" , " fmod" ,
56
+ " fract" , " frexp" , " hypot" , " ilogb" , " ldexp" , " lgamma" ,
57
+ " lgamma_r" , " log" , " log2" , " log10" , " log1p" , " logb" ,
58
+ " mad" , " maxmag" , " minmag" , " modf" , " nan" , " nextafter" ,
59
+ " pow" , " pown" , " powr" , " remainder" , " remquo" , " rint" ,
60
+ " rootn" , " round" , " rsqrt" , " sin" , " sincos" , " sinh" ,
61
+ " sinpi" , " sqrt" , " tan" , " tanh" , " tanpi" , " tgamma" ,
62
+ " trunc" , " half_cos" , " half_divide" , " half_exp" , " half_exp2" ,
63
+ " half_exp10" , " half_log" , " half_log2" , " half_log10" ,
64
+ " half_powr" , " half_recip" , " half_rsqrt" , " half_sin" ,
65
+ " half_sqrt" , " half_tan" , " native_cos" , " native_divide" ,
66
+ " native_exp" , " native_exp2" , " native_exp10" , " native_log" ,
67
+ " native_log2" , " native_log10" , " native_powr" , " native_recip" ,
68
+ " native_rsqrt" , " native_sin" , " native_sqrt" , " native_tan" ,
69
+ " fclamp" , " degrees" , " mix" , " fmax_common" , " fmin_common" ,
70
+ " radians" , " step" , " smoothstep" , " sign" , " cross" , " distance" ,
71
+ " length" , " normalize" , " fast_distance" , " fast_length" , " fast_normalize" ,
72
+ " s_abs" , " s_abs_diff" , " s_add_sat" , " u_add_sat" , " s_hadd" , " u_hadd" ,
73
+ " s_rhadd" , " u_rhadd" , " s_clamp" , " u_clamp" , " clz" , " ctz" ,
74
+ " s_mad_hi" , " s_mad_sat" , " u_mad_sat" , " s_max" , " s_min" , " u_max" ,
75
+ " u_min" , " s_mul_hi" , " rotate" , " s_sub_sat" , " u_sub_sat" , " u_upsample" ,
76
+ " s_upsample" , " popcount" , " s_mad24" , " u_mad24" , " s_mul24" , " u_mul24" ,
77
+ " vloadn" , " vstoren" , " vload_half" , " vload_halfn" , " vstore_half" ,
78
+ " vstore_half_r" , " vstore_halfn" , " vstore_halfn_r" , " vloada_halfn" ,
79
+ " vstorea_halfn" , " vstorea_halfn_r" , " shuffle" , " shuffle2" , " printf" ,
80
+ " prefetch" , " bitselect" , " select" , " u_abs" , " u_abs_diff" ,
81
+ " u_mul_hi" , " u_mad_hi"
82
+ };
83
+
51
84
class ProcessFuncAttributes : public ModulePass
52
85
{
53
86
public:
@@ -355,14 +388,8 @@ bool ProcessFuncAttributes::runOnModule(Module& M)
355
388
return false ;
356
389
};
357
390
358
- static std::set<StringRef> mathFunctionNames = {
359
- #define _OCL_EXT_OP (name, num ) #name,
360
- #include " SPIRV/libSPIRV/OpenCL.stdfuncs.h"
361
- #undef _OCL_EXT_OP
362
- };
363
-
364
391
// If a builtin func is a FP64 one with the given prefix, return true.
365
- auto IsBuiltinFP64WithPrefix = [](Function* F, StringRef Prefix) {
392
+ auto IsBuiltinFP64WithPrefix = [](Function* F, const std::string& Prefix) {
366
393
if (F->getName ().startswith (Prefix))
367
394
{
368
395
if (F->getReturnType ()->isDoubleTy () ||
@@ -372,7 +399,7 @@ bool ProcessFuncAttributes::runOnModule(Module& M)
372
399
functionName = functionName.drop_front (Prefix.size ());
373
400
functionName = functionName.take_front (functionName.find (' _' ));
374
401
375
- if (mathFunctionNames .find (functionName) != mathFunctionNames .end ()) {
402
+ if (OCLExtOpBuiltinNames .find (functionName. str ()) != OCLExtOpBuiltinNames .end ()) {
376
403
return true ;
377
404
}
378
405
}
@@ -385,8 +412,7 @@ bool ProcessFuncAttributes::runOnModule(Module& M)
385
412
// if we don't make any fast relaxed math optimizations.
386
413
auto IsBuiltinFP64 = [&IsBuiltinFP64WithPrefix](Function* F)
387
414
{
388
- StringRef buildinPrefixOpenCL = igc_spv::kLLVMName ::builtinExtInstPrefixOpenCL;
389
- return IsBuiltinFP64WithPrefix (F, buildinPrefixOpenCL);
415
+ return IsBuiltinFP64WithPrefix (F, " __spirv_ocl_" );
390
416
};
391
417
392
418
// Process through all functions and add the appropriate function attributes
@@ -565,8 +591,7 @@ bool ProcessFuncAttributes::runOnModule(Module& M)
565
591
bool defaultStackCall = IGC_IS_FLAG_ENABLED (EnableStackCallFuncCall);
566
592
567
593
// Add always attribute if function is a builtin
568
- if (F->hasFnAttribute (" OclBuiltin" ) ||
569
- F->getName ().startswith (igc_spv::kLLVMName ::builtinPrefix))
594
+ if (F->hasFnAttribute (" OclBuiltin" ) || F->getName ().startswith (" __builtin_spirv_" ))
570
595
{
571
596
// OptNone builtins are special versions of builtins assuring that all
572
597
// theirs parameters are constant values.
@@ -579,7 +604,7 @@ bool ProcessFuncAttributes::runOnModule(Module& M)
579
604
F->removeFnAttr (llvm::Attribute::NoInline);
580
605
}
581
606
else if (pCtx->m_hasDPEmu &&
582
- IsBuiltinFP64WithPrefix (F, igc_spv:: kLLVMName ::builtinIMFPrefixSVML ))
607
+ IsBuiltinFP64WithPrefix (F, " __ocl_svml_ " ))
583
608
{
584
609
defaultStackCall = true ;
585
610
mustAlwaysInline = false ;
0 commit comments