@@ -15,7 +15,6 @@ SPDX-License-Identifier: MIT
1515#include " Compiler/CISACodeGen/OpenCLKernelCodeGen.hpp"
1616#include " Compiler/CodeGenContextWrapper.hpp"
1717#include " Compiler/Optimizer/OpenCLPasses/StackOverflowDetection/StackOverflowDetection.hpp"
18- #include " SPIRV/SPIRVInternal.h"
1918
2019#include " common/LLVMWarningsPush.hpp"
2120
@@ -48,6 +47,40 @@ using namespace IGC::IGCMD;
4847
4948namespace {
5049
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+
5184class ProcessFuncAttributes : public ModulePass
5285{
5386public:
@@ -355,14 +388,8 @@ bool ProcessFuncAttributes::runOnModule(Module& M)
355388 return false ;
356389 };
357390
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-
364391 // 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) {
366393 if (F->getName ().startswith (Prefix))
367394 {
368395 if (F->getReturnType ()->isDoubleTy () ||
@@ -372,7 +399,7 @@ bool ProcessFuncAttributes::runOnModule(Module& M)
372399 functionName = functionName.drop_front (Prefix.size ());
373400 functionName = functionName.take_front (functionName.find (' _' ));
374401
375- if (mathFunctionNames .find (functionName) != mathFunctionNames .end ()) {
402+ if (OCLExtOpBuiltinNames .find (functionName. str ()) != OCLExtOpBuiltinNames .end ()) {
376403 return true ;
377404 }
378405 }
@@ -385,8 +412,7 @@ bool ProcessFuncAttributes::runOnModule(Module& M)
385412 // if we don't make any fast relaxed math optimizations.
386413 auto IsBuiltinFP64 = [&IsBuiltinFP64WithPrefix](Function* F)
387414 {
388- StringRef buildinPrefixOpenCL = igc_spv::kLLVMName ::builtinExtInstPrefixOpenCL;
389- return IsBuiltinFP64WithPrefix (F, buildinPrefixOpenCL);
415+ return IsBuiltinFP64WithPrefix (F, " __spirv_ocl_" );
390416 };
391417
392418 // Process through all functions and add the appropriate function attributes
@@ -565,8 +591,7 @@ bool ProcessFuncAttributes::runOnModule(Module& M)
565591 bool defaultStackCall = IGC_IS_FLAG_ENABLED (EnableStackCallFuncCall);
566592
567593 // 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_" ))
570595 {
571596 // OptNone builtins are special versions of builtins assuring that all
572597 // theirs parameters are constant values.
@@ -579,7 +604,7 @@ bool ProcessFuncAttributes::runOnModule(Module& M)
579604 F->removeFnAttr (llvm::Attribute::NoInline);
580605 }
581606 else if (pCtx->m_hasDPEmu &&
582- IsBuiltinFP64WithPrefix (F, igc_spv:: kLLVMName ::builtinIMFPrefixSVML ))
607+ IsBuiltinFP64WithPrefix (F, " __ocl_svml_ " ))
583608 {
584609 defaultStackCall = true ;
585610 mustAlwaysInline = false ;
0 commit comments