@@ -153,7 +153,7 @@ namespace llvm {
153153
154154    void  GenIntrinsicsTTIImpl::getUnrollingPreferences (Loop* L,
155155        ScalarEvolution& SE,
156-         TTI::UnrollingPreferences& UP,  
156+         TTI::UnrollingPreferences& UP,
157157        OptimizationRemarkEmitter* ORE
158158        )
159159    {
@@ -608,90 +608,56 @@ namespace llvm {
608608        return  BaseT::isProfitableToHoist (I);
609609    }
610610
611- #if  LLVM_VERSION_MAJOR <= 10
612-     unsigned  GenIntrinsicsTTIImpl::getCallCost (const  Function* F,
613-         ArrayRef<const  Value*> Arguments, const  User* U)
611+     //  TODO: Upon the complete removal of pre-LLVM 14 conditions, move to 'getInstructionCost' per LLVM 16 API
612+     llvm::InstructionCost GenIntrinsicsTTIImpl::getUserCost (const  User* U, ArrayRef<const  Value*> Operands, TTI::TargetCostKind CostKind)
614613    {
615-         //  The extra cost of speculative execution for math intrinsics
616-         if  (auto  *II = dyn_cast_or_null<IntrinsicInst>(U)) {
617-             if  (Intrinsic::ID IID = II->getIntrinsicID ()) {
618-                 switch  (IID) {
619-                     case  Intrinsic::cos:
620-                     case  Intrinsic::sin:
621-                     case  Intrinsic::sqrt:
622-                         return  TTI::TCC_Expensive;
623-                     default :
624-                         break ;
625-                 }
626-             }
627-         }
628- 
629-         IGC::CodeGenContext* CGC = this ->ctx ;
630-         if  (!CGC->enableFunctionCall () && !GenISAIntrinsic::isIntrinsic (F) &&
631-             !F->isIntrinsic ()) {
632-             //  If subroutine call is not enabled but we have function call. They
633-             //  are not inlined. e.g. due to two-phase inlining. Return function
634-             //  size instead of to avoid under-estimating the cost of function call.
635-             // 
636-             //  FIXME: We need to collect the cost following calling graph. However,
637-             //  as LLVM's ininer only support bottom-up inlining currently. That's
638-             //  not a big issue so far.
639-             // 
640-             //  FIXME: We also need to consider the case where sub-routine call is
641-             //  enabled.
642-             unsigned  FuncSize = countTotalInstructions (F, false );
643-             return  TargetTransformInfo::TCC_Basic * FuncSize;
644-         }
645-         return  BaseT::getCallCost (F, Arguments, U);
614+       return  GenIntrinsicsTTIImpl::internalCalculateCost (U, Operands, CostKind);
646615    }
647- #else 
648-     //  [LLVM-UPGRADE] moved from getCallCost to getUserCost
649-     //  https://github.com/llvm/llvm-project/commit/2641a19981e71c887bece92074e00d1af3e716c9#diff-dd4bd65dc55d754674d9a945a0d22911
650616
651- #if  LLVM_VERSION_MAJOR <= 12 
652-     int  GenIntrinsicsTTIImpl::getUserCost  (const  User* U, ArrayRef<const  Value*> Operands, TTI::TargetCostKind CostKind)
653- # else 
654-     //  TODO: Upon the complete removal of pre-LLVM 14 conditions, move to 'getInstructionCost' per LLVM 16 API 
655-     llvm::InstructionCost  GenIntrinsicsTTIImpl::getUserCost ( const  User* U, ArrayRef< const  Value*> Operands, TTI::TargetCostKind CostKind) 
617+ #if  LLVM_VERSION_MAJOR >= 16 
618+     llvm::InstructionCost  GenIntrinsicsTTIImpl::getInstructionCost  (const  User* U, ArrayRef<const  Value*> Operands, TTI::TargetCostKind CostKind)
619+     { 
620+        return   GenIntrinsicsTTIImpl::internalCalculateCost (U, Operands, CostKind); 
621+     } 
656622#endif 
623+ 
624+     llvm::InstructionCost GenIntrinsicsTTIImpl::internalCalculateCost (const  User* U, ArrayRef<const  Value*> Operands, TTI::TargetCostKind CostKind)
657625    {
658-         //  The extra cost of speculative execution for math intrinsics
659-         if  (auto  *II = dyn_cast_or_null<IntrinsicInst>(U)) {
660-             if  (Intrinsic::ID IID = II->getIntrinsicID ()) {
661-                 switch  (IID) {
662-                     case  Intrinsic::cos:
663-                     case  Intrinsic::sin:
664-                     case  Intrinsic::sqrt:
665-                         return  TTI::TCC_Expensive;
666-                     default :
667-                         break ;
668-                 }
669-             }
626+       //  The extra cost of speculative execution for math intrinsics
627+       if  (auto * II = dyn_cast_or_null<IntrinsicInst>(U)) {
628+         if  (Intrinsic::ID IID = II->getIntrinsicID ()) {
629+           switch  (IID) {
630+           case  Intrinsic::cos:
631+           case  Intrinsic::sin:
632+           case  Intrinsic::sqrt:
633+             return  TTI::TCC_Expensive;
634+           default :
635+             break ;
636+           }
670637        }
638+       }
671639
672-         const  Function* F = dyn_cast<Function>(U);
673-         if  (F != nullptr )
674-         {
675-             IGC::CodeGenContext* CGC = this ->ctx ;
676-             if  (!CGC->enableFunctionCall () && !GenISAIntrinsic::isIntrinsic (F) &&
677-                 !F->isIntrinsic ()) {
678-                 //  If subroutine call is not enabled but we have function call. They
679-                 //  are not inlined. e.g. due to two-phase inlining. Return function
680-                 //  size instead of to avoid under-estimating the cost of function call.
681-                 // 
682-                 //  FIXME: We need to collect the cost following calling graph. However,
683-                 //  as LLVM's ininer only support bottom-up inlining currently. That's
684-                 //  not a big issue so far.
685-                 // 
686-                 //  FIXME: We also need to consider the case where sub-routine call is
687-                 //  enabled.
688-                 unsigned  FuncSize = countTotalInstructions (F, false );
689-                 return  TargetTransformInfo::TCC_Basic * FuncSize;
690-             }
640+       const  Function* F = dyn_cast<Function>(U);
641+       if  (F != nullptr )
642+       {
643+         IGC::CodeGenContext* CGC = this ->ctx ;
644+         if  (!CGC->enableFunctionCall () && !GenISAIntrinsic::isIntrinsic (F) &&
645+           !F->isIntrinsic ()) {
646+           //  If subroutine call is not enabled but we have function call. They
647+           //  are not inlined. e.g. due to two-phase inlining. Return function
648+           //  size instead of to avoid under-estimating the cost of function call.
649+           // 
650+           //  FIXME: We need to collect the cost following calling graph. However,
651+           //  as LLVM's ininer only support bottom-up inlining currently. That's
652+           //  not a big issue so far.
653+           // 
654+           //  FIXME: We also need to consider the case where sub-routine call is
655+           //  enabled.
656+           unsigned  FuncSize = countTotalInstructions (F, false );
657+           return  TargetTransformInfo::TCC_Basic * FuncSize;
691658        }
659+       }
692660
693-          return  BaseT::getInstructionCost (U, Operands, CostKind);
661+       return  BaseT::getInstructionCost (U, Operands, CostKind);
694662    }
695- #endif 
696- 
697663} //  namespace llvm
0 commit comments