Skip to content

Commit 7e44c55

Browse files
committed
Use instructions() and avoid goto.
1 parent be26bc9 commit 7e44c55

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
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

Comments
 (0)