Skip to content

Commit 0408a96

Browse files
committed
Add new isUnsupportedInst & adjust isReversibleBranch
1 parent 17f179d commit 0408a96

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,20 @@ class MCPlusBuilder {
439439
}
440440

441441
/// Check whether this conditional branch can be reversed
442-
virtual bool isReversibleBranch(const MCInst &Inst) const { return true; }
442+
virtual bool isReversibleBranch(const MCInst &Inst) const {
443+
assert(!isUnsupportedInstruction(Inst) && isConditionalBranch(Inst) &&
444+
"Instruction is not known conditional branch");
445+
446+
if (isDynamicBranch(Inst))
447+
return false;
448+
return true;
449+
}
450+
451+
/// Return true if this instruction inhibits analysis of the containing
452+
/// function.
453+
virtual bool isUnsupportedInstruction(const MCInst &Inst) const {
454+
return false;
455+
}
443456

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

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,10 @@ Error BinaryFunction::disassemble() {
12751275
}
12761276
}
12771277

1278+
bool IsUnsupported = BC.MIB->isUnsupportedInstruction(Instruction);
1279+
if (IsUnsupported)
1280+
setIgnored();
1281+
12781282
if (MIB->isBranch(Instruction) || MIB->isCall(Instruction)) {
12791283
uint64_t TargetAddress = 0;
12801284
if (MIB->evaluateBranch(Instruction, AbsoluteInstrAddr, Size,
@@ -1288,6 +1292,11 @@ Error BinaryFunction::disassemble() {
12881292
const bool IsCondBranch = MIB->isConditionalBranch(Instruction);
12891293
MCSymbol *TargetSymbol = nullptr;
12901294

1295+
if (IsUnsupported)
1296+
if (auto *TargetFunc =
1297+
BC.getBinaryFunctionContainingAddress(TargetAddress))
1298+
TargetFunc->setIgnored();
1299+
12911300
if (IsCall && containsAddress(TargetAddress)) {
12921301
if (TargetAddress == getAddress()) {
12931302
// Recursive call.

bolt/lib/Passes/Instrumentation.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,7 @@ void Instrumentation::instrumentFunction(BinaryFunction &Function,
479479
HasJumpTable = true;
480480
else if (BC.MIB->isUnconditionalBranch(Inst))
481481
HasUnconditionalBranch = true;
482-
else if ((!BC.MIB->isCall(Inst) && !BC.MIB->isConditionalBranch(Inst)) ||
483-
!BC.MIB->isReversibleBranch(Inst))
482+
else if (!(BC.MIB->isCall(Inst) || BC.MIB->isConditionalBranch(Inst)))
484483
continue;
485484

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

bolt/lib/Target/X86/X86MCPlusBuilder.cpp

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

331-
bool isReversibleBranch(const MCInst &Inst) const override {
332-
if (isDynamicBranch(Inst))
333-
return false;
334-
331+
bool isUnsupportedInstruction(const MCInst &Inst) const override {
335332
switch (Inst.getOpcode()) {
336333
default:
337-
return true;
334+
return false;
335+
338336
case X86::LOOP:
339337
case X86::LOOPE:
340338
case X86::LOOPNE:
341339
case X86::JECXZ:
342340
case X86::JRCXZ:
343-
return false;
341+
// These have a short displacement, and therefore (often) break after
342+
// basic block relayout.
343+
return true;
344344
}
345345
}
346346

@@ -1879,11 +1879,9 @@ class X86MCPlusBuilder : public MCPlusBuilder {
18791879
continue;
18801880
}
18811881

1882-
// Handle conditional branches and ignore indirect branches
1883-
if (isReversibleBranch(*I) && getCondCode(*I) == X86::COND_INVALID) {
1884-
// Indirect branch
1882+
// Ignore indirect branches
1883+
if (getCondCode(*I) == X86::COND_INVALID)
18851884
return false;
1886-
}
18871885

18881886
if (CondBranch == nullptr) {
18891887
const MCSymbol *TargetBB = getTargetSymbol(*I);

0 commit comments

Comments
 (0)