Skip to content

Commit 76fdc2e

Browse files
authored
[BOLT][NFC] Rename isUnsupportedBranch to isReversibleBranch (#92447)
`isUnsupportedBranch` is not a very informative name, and doesn't match its corresponding `reverseBranchCondition`, as I noted in PR #92018. Here's a renaming to a more mnemonic name.
1 parent 1b58940 commit 76fdc2e

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,8 @@ class MCPlusBuilder {
438438
return false;
439439
}
440440

441-
/// Check whether we support inverting this branch
442-
virtual bool isUnsupportedBranch(const MCInst &Inst) const { return false; }
441+
/// Check whether this conditional branch can be reversed
442+
virtual bool isReversibleBranch(const MCInst &Inst) const { return true; }
443443

444444
/// Return true of the instruction is of pseudo kind.
445445
virtual bool isPseudo(const MCInst &Inst) const {

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ Error BinaryFunction::disassemble() {
12841284
const bool IsCondBranch = MIB->isConditionalBranch(Instruction);
12851285
MCSymbol *TargetSymbol = nullptr;
12861286

1287-
if (BC.MIB->isUnsupportedBranch(Instruction)) {
1287+
if (!BC.MIB->isReversibleBranch(Instruction)) {
12881288
setIgnored();
12891289
if (BinaryFunction *TargetFunc =
12901290
BC.getBinaryFunctionContainingAddress(TargetAddress))
@@ -3381,7 +3381,7 @@ void BinaryFunction::fixBranches() {
33813381

33823382
// Reverse branch condition and swap successors.
33833383
auto swapSuccessors = [&]() {
3384-
if (MIB->isUnsupportedBranch(*CondBranch)) {
3384+
if (!MIB->isReversibleBranch(*CondBranch)) {
33853385
if (opts::Verbosity) {
33863386
BC.outs() << "BOLT-INFO: unable to swap successors in " << *this
33873387
<< '\n';

bolt/lib/Passes/Instrumentation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ void Instrumentation::instrumentFunction(BinaryFunction &Function,
480480
else if (BC.MIB->isUnconditionalBranch(Inst))
481481
HasUnconditionalBranch = true;
482482
else if ((!BC.MIB->isCall(Inst) && !BC.MIB->isConditionalBranch(Inst)) ||
483-
BC.MIB->isUnsupportedBranch(Inst))
483+
!BC.MIB->isReversibleBranch(Inst))
484484
continue;
485485

486486
const uint32_t FromOffset = *BC.MIB->getOffset(Inst);

bolt/lib/Target/X86/X86MCPlusBuilder.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,19 +328,19 @@ class X86MCPlusBuilder : public MCPlusBuilder {
328328
return false;
329329
}
330330

331-
bool isUnsupportedBranch(const MCInst &Inst) const override {
331+
bool isReversibleBranch(const MCInst &Inst) const override {
332332
if (isDynamicBranch(Inst))
333-
return true;
333+
return false;
334334

335335
switch (Inst.getOpcode()) {
336336
default:
337-
return false;
337+
return true;
338338
case X86::LOOP:
339339
case X86::LOOPE:
340340
case X86::LOOPNE:
341341
case X86::JECXZ:
342342
case X86::JRCXZ:
343-
return true;
343+
return false;
344344
}
345345
}
346346

@@ -1874,7 +1874,7 @@ class X86MCPlusBuilder : public MCPlusBuilder {
18741874
}
18751875

18761876
// Handle conditional branches and ignore indirect branches
1877-
if (!isUnsupportedBranch(*I) && getCondCode(*I) == X86::COND_INVALID) {
1877+
if (isReversibleBranch(*I) && getCondCode(*I) == X86::COND_INVALID) {
18781878
// Indirect branch
18791879
return false;
18801880
}

0 commit comments

Comments
 (0)