Skip to content

Commit

Permalink
[BOLT] Fix branch data for __builtin_unreachable().
Browse files Browse the repository at this point in the history
Summary:
When we have a conditional branch past the end of function (a result
of a call to__builtin_unreachable()), we replace the branch with nop,
but keep branch information for validation purposes. If that branch
has a recorded profile we mistakenly create an additional successor
to a containing basic block (a 3rd successor).

Instead of adding the branch to FTBranches list we should be adding
to IgnoredBranches.

(cherry picked from FBD4912840)
  • Loading branch information
maksfb committed Apr 19, 2017
1 parent 075f076 commit 13c89e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions bolt/BinaryFunction.cpp
Expand Up @@ -1134,8 +1134,8 @@ void BinaryFunction::disassemble(ArrayRef<uint8_t> FunctionData) {
<< " : replacing with nop.\n");
BC.MIA->createNoop(Instruction);
if (IsCondBranch) {
// Register FT branch for passing function profile validation.
FTBranches.emplace_back(Offset, Offset + Size);
// Register branch function profile validation.
IgnoredBranches.emplace_back(Offset, Offset + Size);
}
goto add_instruction;
}
Expand Down Expand Up @@ -1888,6 +1888,7 @@ bool BinaryFunction::buildCFG() {
clearList(OffsetToCFI);
clearList(TakenBranches);
clearList(FTBranches);
clearList(IgnoredBranches);
clearList(LPToBBIndex);
clearList(EntryOffsets);

Expand Down Expand Up @@ -1986,6 +1987,9 @@ void BinaryFunction::evaluateProfileData(const FuncBranchData &BranchData) {
FunctionBranches.insert(FunctionBranches.end(),
FTBranches.begin(),
FTBranches.end());
FunctionBranches.insert(FunctionBranches.end(),
IgnoredBranches.begin(),
IgnoredBranches.end());
std::sort(FunctionBranches.begin(), FunctionBranches.end());

BranchListType DiffBranches; // Branches in profile without a match.
Expand Down
5 changes: 3 additions & 2 deletions bolt/BinaryFunction.h
Expand Up @@ -439,8 +439,9 @@ class BinaryFunction : public AddressRangesOwner {
std::unordered_map<const MCSymbol *, BinaryBasicBlock *> LabelToBB;

using BranchListType = std::vector<std::pair<uint32_t, uint32_t>>;
BranchListType TakenBranches; /// All local taken branches.
BranchListType FTBranches; /// All fall-through branches.
BranchListType TakenBranches; /// All local taken branches.
BranchListType FTBranches; /// All fall-through branches.
BranchListType IgnoredBranches; /// Branches ignored by CFG purposes.

/// Storage for all landing pads and their corresponding invokes.
using LandingPadsMapType = std::map<const MCSymbol *, std::vector<unsigned> >;
Expand Down

0 comments on commit 13c89e6

Please sign in to comment.