Skip to content
Open
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
21 changes: 21 additions & 0 deletions bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,27 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
return isLoadFromStack(Inst);
};

bool isReturn(const MCInst &Inst) const override {
// BR X30 is equivalent to RET
if (Inst.getOpcode() == AArch64::BR &&
Inst.getOperand(0).getReg() == AArch64::LR)
return true;

return Analysis->isReturn(Inst);
}

bool isBranch(const MCInst &Inst) const override {
if (isReturn(Inst))
return false;
return Analysis->isBranch(Inst);
}

bool isIndirectBranch(const MCInst &Inst) const override {
if (isReturn(Inst))
return false;
return Analysis->isIndirectBranch(Inst);
}

void createCall(MCInst &Inst, const MCSymbol *Target,
MCContext *Ctx) override {
createDirectCall(Inst, Target, Ctx, false);
Expand Down
16 changes: 16 additions & 0 deletions bolt/test/AArch64/br-x30.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Test that "br x30" is treated as a return instruction and not as an indirect
## branch.

# RUN: %clang %cflags %s -o %t.exe -Wl,-q -Wl,--entry=foo
# RUN: llvm-bolt %t.exe -o %t.bolt --print-cfg 2>&1 | FileCheck %s

# CHECK: BB Count : 2
# CHECK-NOT: UNKNOWN CONTROL FLOW

.text
.global foo
.type foo, %function
foo:
br x30
nop
.size foo, .-foo
Loading