Skip to content

Commit fa0b8b5

Browse files
authored
Merge pull request #161 from sx-aurora-dev/feature/merge-upstream-20220215
Feature/merge upstream 20220215
2 parents cf6016c + 8bca4ac commit fa0b8b5

File tree

735 files changed

+13701
-5942
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

735 files changed

+13701
-5942
lines changed

bolt/include/bolt/Core/BinaryBasicBlock.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class MCCodeEmitter;
3131
namespace bolt {
3232

3333
class BinaryFunction;
34+
class JumpTable;
3435

3536
class BinaryBasicBlock {
3637
public:
@@ -623,6 +624,10 @@ class BinaryBasicBlock {
623624
/// remove the conditional successor and branch instruction.
624625
void removeDuplicateConditionalSuccessor(MCInst *CondBranch);
625626

627+
/// Update successors of the basic block based on the jump table instruction.
628+
/// The block must end with a jump table instruction.
629+
void updateJumpTableSuccessors();
630+
626631
/// Test if BB is a predecessor of this block.
627632
bool isPredecessor(const BinaryBasicBlock *BB) const {
628633
auto Itr = std::find(Predecessors.begin(), Predecessors.end(), BB);
@@ -909,7 +914,12 @@ class BinaryBasicBlock {
909914
return Index;
910915
}
911916

912-
bool hasJumpTable() const;
917+
/// Return jump table if the block contains a jump table instruction or
918+
/// nullptr otherwise.
919+
const JumpTable *getJumpTable() const;
920+
921+
/// Check if the block has a jump table instruction.
922+
bool hasJumpTable() const { return getJumpTable() != nullptr; }
913923

914924
private:
915925
void adjustNumPseudos(const MCInst &Inst, int Sign);

bolt/lib/Core/BinaryBasicBlock.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ bool BinaryBasicBlock::hasInstructions() const {
3939
return getParent()->hasInstructions();
4040
}
4141

42-
bool BinaryBasicBlock::hasJumpTable() const {
42+
const JumpTable *BinaryBasicBlock::getJumpTable() const {
4343
const MCInst *Inst = getLastNonPseudoInstr();
4444
const JumpTable *JT = Inst ? Function->getJumpTable(*Inst) : nullptr;
45-
return (JT != nullptr);
45+
return JT;
4646
}
4747

4848
void BinaryBasicBlock::adjustNumPseudos(const MCInst &Inst, int Sign) {
@@ -351,6 +351,36 @@ void BinaryBasicBlock::removeDuplicateConditionalSuccessor(MCInst *CondBranch) {
351351
BranchInfo.push_back({Count, 0});
352352
}
353353

354+
void BinaryBasicBlock::updateJumpTableSuccessors() {
355+
const JumpTable *JT = getJumpTable();
356+
assert(JT && "Expected jump table instruction.");
357+
358+
// Clear existing successors.
359+
removeAllSuccessors();
360+
361+
// Generate the list of successors in deterministic order without duplicates.
362+
SmallVector<BinaryBasicBlock *, 16> SuccessorBBs;
363+
for (const MCSymbol *Label : JT->Entries) {
364+
BinaryBasicBlock *BB = getFunction()->getBasicBlockForLabel(Label);
365+
// Ignore __builtin_unreachable()
366+
if (!BB) {
367+
assert(Label == getFunction()->getFunctionEndLabel() &&
368+
"JT label should match a block or end of function.");
369+
continue;
370+
}
371+
SuccessorBBs.emplace_back(BB);
372+
}
373+
llvm::sort(SuccessorBBs,
374+
[](const BinaryBasicBlock *BB1, const BinaryBasicBlock *BB2) {
375+
return BB1->getInputOffset() < BB2->getInputOffset();
376+
});
377+
SuccessorBBs.erase(std::unique(SuccessorBBs.begin(), SuccessorBBs.end()),
378+
SuccessorBBs.end());
379+
380+
for (BinaryBasicBlock *BB : SuccessorBBs)
381+
addSuccessor(BB);
382+
}
383+
354384
void BinaryBasicBlock::adjustExecutionCount(double Ratio) {
355385
auto adjustedCount = [&](uint64_t Count) -> uint64_t {
356386
double NewCount = Count * Ratio;

bolt/lib/Core/BinaryContext.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "bolt/Utils/NameResolver.h"
1818
#include "bolt/Utils/Utils.h"
1919
#include "llvm/ADT/Twine.h"
20+
#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
2021
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
2122
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
2223
#include "llvm/MC/MCAsmLayout.h"
@@ -712,8 +713,10 @@ void BinaryContext::skipMarkedFragments() {
712713
std::for_each(BF->ParentFragments.begin(), BF->ParentFragments.end(),
713714
addToWorklist);
714715
}
715-
errs() << "BOLT-WARNING: Ignored " << FragmentsToSkip.size() << " functions "
716-
<< "due to cold fragments.\n";
716+
if (!FragmentsToSkip.empty())
717+
errs() << "BOLT-WARNING: ignored " << FragmentsToSkip.size() << " function"
718+
<< (FragmentsToSkip.size() == 1 ? "" : "s")
719+
<< " due to cold fragments\n";
717720
FragmentsToSkip.clear();
718721
}
719722

bolt/lib/Core/BinaryEmitter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "bolt/Core/DebugData.h"
1818
#include "bolt/Utils/CommandLineOpts.h"
1919
#include "bolt/Utils/Utils.h"
20+
#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
2021
#include "llvm/MC/MCSection.h"
2122
#include "llvm/MC/MCStreamer.h"
2223
#include "llvm/Support/CommandLine.h"

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,21 +1875,7 @@ bool BinaryFunction::postProcessIndirectBranches(
18751875
BC.MIB->setJumpTable(*LastIndirectJump, LastJT, LastJTIndexReg, AllocId);
18761876
HasUnknownControlFlow = false;
18771877

1878-
// re-populate successors based on the jump table.
1879-
std::set<const MCSymbol *> JTLabels;
1880-
LastIndirectJumpBB->removeAllSuccessors();
1881-
const JumpTable *JT = getJumpTableContainingAddress(LastJT);
1882-
for (const MCSymbol *Label : JT->Entries)
1883-
JTLabels.emplace(Label);
1884-
for (const MCSymbol *Label : JTLabels) {
1885-
BinaryBasicBlock *BB = getBasicBlockForLabel(Label);
1886-
// Ignore __builtin_unreachable()
1887-
if (!BB) {
1888-
assert(Label == getFunctionEndLabel() && "if no BB found, must be end");
1889-
continue;
1890-
}
1891-
LastIndirectJumpBB->addSuccessor(BB);
1892-
}
1878+
LastIndirectJumpBB->updateJumpTableSuccessors();
18931879
}
18941880

18951881
if (HasFixedIndirectBranch)

bolt/lib/Core/DebugData.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "bolt/Core/DebugData.h"
1414
#include "bolt/Core/BinaryContext.h"
1515
#include "bolt/Utils/Utils.h"
16+
#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
17+
#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
1618
#include "llvm/MC/MCAssembler.h"
1719
#include "llvm/MC/MCContext.h"
1820
#include "llvm/MC/MCObjectStreamer.h"

bolt/lib/Core/Exceptions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/Support/Casting.h"
2222
#include "llvm/Support/CommandLine.h"
2323
#include "llvm/Support/Debug.h"
24+
#include "llvm/Support/Errc.h"
2425
#include "llvm/Support/LEB128.h"
2526
#include "llvm/Support/MathExtras.h"
2627
#include "llvm/Support/raw_ostream.h"

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/ADT/ScopeExit.h"
2222
#include "llvm/Support/CommandLine.h"
2323
#include "llvm/Support/Debug.h"
24+
#include "llvm/Support/Errc.h"
2425
#include "llvm/Support/FileSystem.h"
2526
#include "llvm/Support/Process.h"
2627
#include "llvm/Support/Program.h"

bolt/lib/Profile/DataReader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "bolt/Utils/Utils.h"
1818
#include "llvm/Support/CommandLine.h"
1919
#include "llvm/Support/Debug.h"
20+
#include "llvm/Support/Errc.h"
2021
#include <map>
2122

2223
#undef DEBUG_TYPE

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include "llvm/BinaryFormat/Dwarf.h"
1818
#include "llvm/DWP/DWP.h"
1919
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
20+
#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
21+
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
2022
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
2123
#include "llvm/MC/MCAsmBackend.h"
2224
#include "llvm/MC/MCAsmLayout.h"

0 commit comments

Comments
 (0)