Skip to content

Commit f359347

Browse files
committed
[PPC][BOLT] Implement convertJmpToTailCall for PowerPC.
BOLT relies on treating tail calls as calls to build correct CFGs and preserve interprocedural analysis. On PowerPC, the compiler often emits plain branches (b, ba, bctr) instead of explicit calls when lowering tail calls. (TCO Tail Call Optimisation). This patch overrides convertJmpToTailCall in PPCMCPlusBuilder so that uncoditional branches are converted into their link-bit variants (BL, BLA, BCTRL). This way, BOLT can consistently recognise them as calls/tail calls during dissasembly and optimisation, including when skipping PLT (Procedure Linkage Table) stubs.
1 parent 3b1e7d2 commit f359347

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

bolt/lib/Target/PowerPC/PPCMCPlusBuilder.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,23 @@ const MCSymbol *PPCMCPlusBuilder::getTargetSymbol(const MCInst &Inst,
9898
}
9999

100100
bool PPCMCPlusBuilder::convertJmpToTailCall(MCInst &Inst) {
101-
(void)Inst;
102-
return false;
101+
switch (Inst.getOpcode()) {
102+
// Uncoditional direct branch -> add link bit
103+
case PPC::B: // relative
104+
Inst.setOpcode(PPC::BL);
105+
return true;
106+
case PPC::BA: // absolute
107+
Inst.setOpcode(PPC::BLA);
108+
return true;
109+
110+
// Indirect branch via CTR -> add link bit
111+
case PPC::BCTR:
112+
Inst.setOpcode(PPC::BCTRL);
113+
return true;
114+
// Contitional branches
115+
default:
116+
return false;
117+
}
103118
}
104119

105120
bool PPCMCPlusBuilder::isTailCall(const MCInst &I) const {

0 commit comments

Comments
 (0)