Skip to content

Commit

Permalink
[BOLT] Fix SCTC again.
Browse files Browse the repository at this point in the history
Summary: Respect hot/cold boundaries when using BinaryFunction::getBasicBlockAfter().

(cherry picked from FBD5153379)
  • Loading branch information
Bill Nell authored and maksfb committed May 31, 2017
1 parent 2e744e6 commit 35d2530
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions bolt/BinaryFunction.h
Expand Up @@ -965,20 +965,22 @@ class BinaryFunction {

/// Returns the basic block after the given basic block in the layout or
/// nullptr the last basic block is given.
const BinaryBasicBlock *getBasicBlockAfter(const BinaryBasicBlock *BB) const {
const BinaryBasicBlock *getBasicBlockAfter(const BinaryBasicBlock *BB,
bool IgnoreSplits = true) const {
for (auto I = layout_begin(), E = layout_end(); I != E; ++I) {
if (*I == BB && std::next(I) != E)
return *std::next(I);
auto Next = std::next(I);
if (*I == BB && Next != E) {
return (IgnoreSplits || (*I)->isCold() == (*Next)->isCold())
? *Next : nullptr;
}
}
return nullptr;
}

BinaryBasicBlock *getBasicBlockAfter(const BinaryBasicBlock *BB) {
for (auto I = layout_begin(), E = layout_end(); I != E; ++I) {
if (*I == BB && std::next(I) != E)
return *std::next(I);
}
return nullptr;
BinaryBasicBlock *getBasicBlockAfter(const BinaryBasicBlock *BB,
bool IgnoreSplits = true) {
return
const_cast<BinaryFunction *>(this)->getBasicBlockAfter(BB, IgnoreSplits);
}

/// Retrieve the landing pad BB associated with invoke instruction \p Invoke
Expand Down
2 changes: 1 addition & 1 deletion bolt/Passes/BinaryPasses.cpp
Expand Up @@ -672,7 +672,7 @@ uint64_t SimplifyConditionalTailCalls::fixTailCalls(BinaryContext &BC,
PredBB->analyzeBranch(TBB, FBB, CondBranch, UncondBranch);

// Only add a new branch if the target is not the fall-through.
if (BF.getBasicBlockAfter(BB) != CondSucc || isValid(BB)) {
if (BF.getBasicBlockAfter(BB, false) != CondSucc || isValid(BB)) {
if (UncondBranch) {
MIA->replaceBranchTarget(*UncondBranch,
CondSucc->getLabel(),
Expand Down

0 comments on commit 35d2530

Please sign in to comment.