Skip to content

Commit 65bc5bf

Browse files
committed
IP
1 parent 427b644 commit 65bc5bf

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ unsigned SystemZTTIImpl::adjustInliningThreshold(const CallBase *CB) const {
8080
const Function *Callee = CB->getCalledFunction();
8181
if (!Callee)
8282
return 0;
83-
const Module *M = Caller->getParent();
8483

8584
// Increase the threshold if an incoming argument is used only as a memcpy
8685
// source.
@@ -92,29 +91,38 @@ unsigned SystemZTTIImpl::adjustInliningThreshold(const CallBase *CB) const {
9291
}
9392
}
9493

95-
// Give bonus for globals used much in both caller and callee.
96-
std::set<const GlobalVariable *> CalleeGlobals;
97-
std::set<const GlobalVariable *> CallerGlobals;
98-
for (const GlobalVariable &Global : M->globals())
99-
for (const User *U : Global.users())
100-
if (const Instruction *User = dyn_cast<Instruction>(U)) {
101-
if (User->getParent()->getParent() == Callee)
102-
CalleeGlobals.insert(&Global);
103-
if (User->getParent()->getParent() == Caller)
104-
CallerGlobals.insert(&Global);
94+
// Give bonus for globals used much in both caller and a relatively small
95+
// callee.
96+
if (Callee->getInstructionCount() < 200) {
97+
std::map<const Value *, unsigned> Ptr2NumUses;
98+
for (auto &BB : *Callee)
99+
for (auto &I : BB) {
100+
if (const auto *SI = dyn_cast<StoreInst>(&I)) {
101+
if (!SI->isVolatile())
102+
Ptr2NumUses[SI->getPointerOperand()]++;
103+
} else if (const auto *LI = dyn_cast<LoadInst>(&I)) {
104+
if (!LI->isVolatile())
105+
Ptr2NumUses[LI->getPointerOperand()]++;
106+
} else if (const auto *GEP = dyn_cast<GetElementPtrInst>(&I)) {
107+
unsigned NumStores = 0, NumLoads = 0;
108+
countNumMemAccesses(GEP, NumStores, NumLoads, Callee);
109+
Ptr2NumUses[GEP->getPointerOperand()] += NumLoads + NumStores;
110+
}
105111
}
106-
for (auto *GV : CalleeGlobals)
107-
if (CallerGlobals.count(GV)) {
108-
unsigned CalleeStores = 0, CalleeLoads = 0;
109-
unsigned CallerStores = 0, CallerLoads = 0;
110-
countNumMemAccesses(GV, CalleeStores, CalleeLoads, Callee);
111-
countNumMemAccesses(GV, CallerStores, CallerLoads, Caller);
112-
if ((CalleeStores + CalleeLoads) > 10 &&
113-
(CallerStores + CallerLoads) > 10) {
114-
Bonus = 1000;
115-
break;
112+
113+
for (auto I : Ptr2NumUses) {
114+
const Value *Ptr = I.first;
115+
unsigned NumCalleeUses = I.second;
116+
if (NumCalleeUses > 10 && isa<GlobalVariable>(Ptr)) {
117+
unsigned CallerStores = 0, CallerLoads = 0;
118+
countNumMemAccesses(Ptr, CallerStores, CallerLoads, Caller);
119+
if (CallerStores + CallerLoads > 10) {
120+
Bonus = 1000;
121+
break;
122+
}
116123
}
117124
}
125+
}
118126

119127
// Give bonus when Callee accesses an Alloca of Caller heavily.
120128
unsigned NumStores = 0;

0 commit comments

Comments
 (0)