Skip to content
Merged
Changes from 1 commit
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
50 changes: 29 additions & 21 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,38 @@ 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.
if (Callee->getInstructionCount() < 200) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getInstructionCount() is going to iterate over the whole function to determine the instruction count. It's usually better to always do the analysis and just bail out if it inspects too many instructions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, using a counter instead.

std::map<const Value *, unsigned> Ptr2NumUses;
for (auto &BB : *Callee)
for (auto &I : BB) {
if (const auto *SI = dyn_cast<StoreInst>(&I)) {
if (!SI->isVolatile())
Ptr2NumUses[SI->getPointerOperand()]++;
} else if (const auto *LI = dyn_cast<LoadInst>(&I)) {
if (!LI->isVolatile())
Ptr2NumUses[LI->getPointerOperand()]++;
} else if (const auto *GEP = dyn_cast<GetElementPtrInst>(&I)) {
unsigned NumStores = 0, NumLoads = 0;
countNumMemAccesses(GEP, NumStores, NumLoads, Callee);
Ptr2NumUses[GEP->getPointerOperand()] += NumLoads + NumStores;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like nothing actually cares about loads and stores separately? Make things simpler by having countNumMemAccesses return the total count?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There actually is a bit further down - separate checks for number of loads and stores. It may be that these could be combined there as well, but that should probably wait and be benchmarked after this.

}
}
for (auto *GV : CalleeGlobals)
if (CallerGlobals.count(GV)) {
unsigned CalleeStores = 0, CalleeLoads = 0;
unsigned CallerStores = 0, CallerLoads = 0;
countNumMemAccesses(GV, CalleeStores, CalleeLoads, Callee);
countNumMemAccesses(GV, CallerStores, CallerLoads, Caller);
if ((CalleeStores + CalleeLoads) > 10 &&
(CallerStores + CallerLoads) > 10) {
Bonus = 1000;
break;

for (auto I : Ptr2NumUses) {
const Value *Ptr = I.first;
unsigned NumCalleeUses = I.second;
if (NumCalleeUses > 10 && isa<GlobalVariable>(Ptr)) {
unsigned CallerStores = 0, CallerLoads = 0;
countNumMemAccesses(Ptr, CallerStores, CallerLoads, Caller);
if (CallerStores + CallerLoads > 10) {
Bonus = 1000;
break;
}
}
}
}

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