-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[SystemZ] Fix compile time regression in adjustInliningThreshold(). #137527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -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) { | ||
std::map<const Value *, unsigned> Ptr2NumUses; | ||
JonPsson1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (auto &BB : *Callee) | ||
for (auto &I : BB) { | ||
if (const auto *SI = dyn_cast<StoreInst>(&I)) { | ||
if (!SI->isVolatile()) | ||
Ptr2NumUses[SI->getPointerOperand()]++; | ||
JonPsson1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
JonPsson1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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; | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.