Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bolt/include/bolt/Core/MCPlusBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,10 @@ class MCPlusBuilder {
return false;
}

/// Return true if the hlt instruction under the x86, otherwise, default to
/// false.
virtual bool isX86HLT(const MCInst &Inst) const { return false; }

/// Return the width, in bytes, of the memory access performed by \p Inst, if
/// this is a pop instruction. Return zero otherwise.
virtual int getPopSize(const MCInst &Inst) const {
Expand Down
6 changes: 4 additions & 2 deletions bolt/lib/Core/MCPlusBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ bool MCPlusBuilder::equals(const MCSpecifierExpr &A, const MCSpecifierExpr &B,
}

bool MCPlusBuilder::isTerminator(const MCInst &Inst) const {
return Analysis->isTerminator(Inst) ||
(opts::TerminalTrap && Info->get(Inst.getOpcode()).isTrap());
return (opts::TerminalTrap && Info->get(Inst.getOpcode()).isTrap()) ||
Analysis->isTerminator(Inst)
? !isX86HLT(Inst)
: false;
}

void MCPlusBuilder::setTailCall(MCInst &Inst) const {
Expand Down
4 changes: 4 additions & 0 deletions bolt/lib/Target/X86/X86MCPlusBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ class X86MCPlusBuilder : public MCPlusBuilder {
return Inst.getOpcode() == X86::ENDBR32 || Inst.getOpcode() == X86::ENDBR64;
}

bool isX86HLT(const MCInst &Inst) const override {
return Inst.getOpcode() == X86::HLT;
}

int getPopSize(const MCInst &Inst) const override {
switch (Inst.getOpcode()) {
case X86::POP16r:
Expand Down
17 changes: 17 additions & 0 deletions bolt/test/X86/cfg_build_hlt.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Check CFG for halt instruction

# RUN: %clang %cflags %s -static -o %t.exe -nostdlib
# RUN: llvm-bolt %t.exe --print-cfg --print-only=main -o %t 2>&1 | FileCheck %s --check-prefix=CHECK-CFG
# RUN: llvm-objdump -d %t --print-imm-hex | FileCheck %s --check-prefix=CHECK-BIN

# CHECK-CFG: BB Count : 1
# CHECK-BIN: <main>:
# CHECK-BIN-NEXT: f4 hlt
# CHECK-BIN-NEXT: c3 retq

.global main
.type main, %function
main:
hlt
retq
.size main, .-main
Loading