[llvm] [BOLT][BTI] Add MCPlusBuilder::insertBTI (PR #167329)
Gergely Bálint via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 5 04:48:32 PST 2025
================
@@ -2781,6 +2781,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) ||
+ isBTILandingPad(Pad, false, true) ||
+ isBTILandingPad(Pad, true, true);
+ return isBTILandingPad(Pad, false, true) ||
+ isBTILandingPad(Pad, true, true);
+ }
+ return false;
+ }
+
+ void addBTItoBBStart(BinaryBasicBlock &BB, MCInst &Call) const override {
+ auto II = BB.getFirstNonPseudo();
+ if (II != BB.end()) {
----------------
bgergely0 wrote:
added the assertion, plus an MCPlusBuilder unittest for it.
https://github.com/llvm/llvm-project/pull/167329
More information about the llvm-commits
mailing list