1818#include " llvm/CodeGen/BasicTTIImpl.h"
1919#include " llvm/CodeGen/TargetLowering.h"
2020#include " llvm/IR/DerivedTypes.h"
21+ #include " llvm/IR/InstIterator.h"
2122#include " llvm/IR/IntrinsicInst.h"
2223#include " llvm/IR/Intrinsics.h"
2324#include " llvm/Support/Debug.h"
@@ -95,26 +96,27 @@ unsigned SystemZTTIImpl::adjustInliningThreshold(const CallBase *CB) const {
9596 // callee.
9697 unsigned InstrCount = 0 ;
9798 SmallDenseMap<const Value *, unsigned > Ptr2NumUses;
98- for (auto &BB : * Callee)
99- for ( auto &I : BB. instructionsWithoutDebug () ) {
100- if (++InstrCount == 200 )
101- goto GlobalsDone ;
102- if ( const auto *SI = dyn_cast<StoreInst>(&I)) {
103- if (!SI-> isVolatile ())
104- if (auto GV = dyn_cast<GlobalVariable>( SI->getPointerOperand () ))
105- Ptr2NumUses[GV]++;
106- } else if ( const auto *LI = dyn_cast<LoadInst>(&I)) {
107- if (!LI-> isVolatile ())
108- if (auto GV = dyn_cast<GlobalVariable>( LI->getPointerOperand () ))
109- Ptr2NumUses[GV]++;
110- } else if ( const auto *GEP = dyn_cast<GetElementPtrInst>(&I)) {
111- if (auto GV = dyn_cast<GlobalVariable>(GEP-> getPointerOperand () )) {
112- unsigned NumStores = 0 , NumLoads = 0 ;
113- countNumMemAccesses (GEP, NumStores , NumLoads, Callee) ;
114- Ptr2NumUses[GV] += NumLoads + NumStores ;
115- }
99+ for (auto &I : instructions ( Callee)) {
100+ if (++InstrCount == 200 ) {
101+ Ptr2NumUses. clear ();
102+ break ;
103+ }
104+ if ( const auto *SI = dyn_cast<StoreInst>(&I)) {
105+ if (! SI->isVolatile ( ))
106+ if ( auto GV = dyn_cast<GlobalVariable>(SI-> getPointerOperand ()))
107+ Ptr2NumUses[GV]++;
108+ } else if (const auto *LI = dyn_cast<LoadInst>(&I)) {
109+ if (! LI->isVolatile ( ))
110+ if ( auto GV = dyn_cast<GlobalVariable>(LI-> getPointerOperand ()))
111+ Ptr2NumUses[GV]++;
112+ } else if (const auto *GEP = dyn_cast<GetElementPtrInst>(&I )) {
113+ if ( auto GV = dyn_cast<GlobalVariable>(GEP-> getPointerOperand ())) {
114+ unsigned NumStores = 0 , NumLoads = 0 ;
115+ countNumMemAccesses (GEP, NumStores, NumLoads, Callee) ;
116+ Ptr2NumUses[GV] += NumLoads + NumStores;
116117 }
117118 }
119+ }
118120
119121 for (auto [Ptr, NumCalleeUses] : Ptr2NumUses)
120122 if (NumCalleeUses > 10 ) {
@@ -125,7 +127,6 @@ unsigned SystemZTTIImpl::adjustInliningThreshold(const CallBase *CB) const {
125127 break ;
126128 }
127129 }
128- GlobalsDone:
129130
130131 // Give bonus when Callee accesses an Alloca of Caller heavily.
131132 unsigned NumStores = 0 ;
0 commit comments