[llvm] [BOLT][BTI] Add MCPlusBuilder::addBTItoBBStart (PR #167329)

Paschalis Mpeis via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 5 03:39:16 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) ||
----------------
paschalis-mpeis wrote:

We might want to consider whether those bool arguments could be improved in a few places, e.g.:
```
isBTILandingPad(Pad, true, false)
```

Inline comments could help, but an enum might make code easier to parse. Not sure if that would trigger a change on the llvm side as well. What to you think?

https://github.com/llvm/llvm-project/pull/167329


More information about the llvm-commits mailing list