[llvm] [BOLT][BTI] Add MCPlusBuilder::addBTItoBBStart (PR #167329)
Gergely Bálint via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 5 04:27:03 PST 2025
================
@@ -2808,6 +2808,81 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
Inst.addOperand(MCOperand::createImm(HintNum));
}
+ bool isBTIVariantCoveringCall(MCInst &Call, MCInst &Pad) const override {
+ assert((isIndirectCall(Call) || isIndirectBranch(Call)) &&
+ "Not an indirect call or branch.");
+
+ // A BLR can be accepted by a BTI c.
+ if (isIndirectCall(Call))
+ return isBTILandingPad(Pad, true, false) ||
+ isBTILandingPad(Pad, true, true);
+
+ // A BR can be accepted by a BTI j or BTI c (and BTI jc) IF the operand is
+ // x16 or x17. If the operand is not x16 or x17, it can be accepted by a BTI
+ // j or BTI jc (and not BTI c).
+ if (isIndirectBranch(Call)) {
+ assert(Call.getNumOperands() == 1 &&
+ "Indirect branch needs to have 1 operand.");
+ assert(Call.getOperand(0).isReg() &&
+ "Indirect branch does not have a register operand.");
+ MCPhysReg Reg = Call.getOperand(0).getReg();
+ if (Reg == AArch64::X16 || Reg == AArch64::X17)
+ return isBTILandingPad(Pad, true, false) ||
----------------
bgergely0 wrote:
It can be changed to an enum yeah. `createBTI` and `isBTILandingpad` would have to do the translation from enum values to the <bool, bool> pair. It would not require changes on LLVM's side.
However, I'm not sure if it should be changed in this PR, as it changes the interface of already merged code. And the functions I add here are _not_ taking two bools as arguments, but the indirect call variant.
DYT it's ok to change this as a follow-up?
https://github.com/llvm/llvm-project/pull/167329
More information about the llvm-commits
mailing list