Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ unsigned SystemZTTIImpl::adjustInliningThreshold(const CallBase *CB) const {
const Function *Callee = CB->getCalledFunction();
if (!Callee)
return 0;
const Module *M = Caller->getParent();

// Increase the threshold if an incoming argument is used only as a memcpy
// source.
Expand All @@ -92,29 +91,41 @@ unsigned SystemZTTIImpl::adjustInliningThreshold(const CallBase *CB) const {
}
}

// Give bonus for globals used much in both caller and callee.
std::set<const GlobalVariable *> CalleeGlobals;
std::set<const GlobalVariable *> CallerGlobals;
for (const GlobalVariable &Global : M->globals())
for (const User *U : Global.users())
if (const Instruction *User = dyn_cast<Instruction>(U)) {
if (User->getParent()->getParent() == Callee)
CalleeGlobals.insert(&Global);
if (User->getParent()->getParent() == Caller)
CallerGlobals.insert(&Global);
// Give bonus for globals used much in both caller and a relatively small
// callee.
unsigned InstrCount = 0;
SmallDenseMap<const Value *, unsigned> Ptr2NumUses;
for (auto &BB : *Callee)
for (auto &I : BB.instructionsWithoutDebug()) {
if (++InstrCount == 200)
goto GlobalsDone;
if (const auto *SI = dyn_cast<StoreInst>(&I)) {
if (!SI->isVolatile())
if (auto GV = dyn_cast<GlobalVariable>(SI->getPointerOperand()))
Ptr2NumUses[GV]++;
} else if (const auto *LI = dyn_cast<LoadInst>(&I)) {
if (!LI->isVolatile())
if (auto GV = dyn_cast<GlobalVariable>(LI->getPointerOperand()))
Ptr2NumUses[GV]++;
} else if (const auto *GEP = dyn_cast<GetElementPtrInst>(&I)) {
if (auto GV = dyn_cast<GlobalVariable>(GEP->getPointerOperand())) {
unsigned NumStores = 0, NumLoads = 0;
countNumMemAccesses(GEP, NumStores, NumLoads, Callee);
Ptr2NumUses[GV] += NumLoads + NumStores;
}
}
for (auto *GV : CalleeGlobals)
if (CallerGlobals.count(GV)) {
unsigned CalleeStores = 0, CalleeLoads = 0;
}

for (auto [Ptr, NumCalleeUses] : Ptr2NumUses)
if (NumCalleeUses > 10) {
unsigned CallerStores = 0, CallerLoads = 0;
countNumMemAccesses(GV, CalleeStores, CalleeLoads, Callee);
countNumMemAccesses(GV, CallerStores, CallerLoads, Caller);
if ((CalleeStores + CalleeLoads) > 10 &&
(CallerStores + CallerLoads) > 10) {
countNumMemAccesses(Ptr, CallerStores, CallerLoads, Caller);
if (CallerStores + CallerLoads > 10) {
Bonus = 1000;
break;
}
}
GlobalsDone:

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