[llvm] [LFI][AArch64] Add rewrites for memory accesses (PR #195167)
Peter Smith via llvm-commits
llvm-commits at lists.llvm.org
Tue May 5 10:11:36 PDT 2026
================
@@ -64,6 +66,97 @@ static bool isPrivilegedTPAccess(const MCInst &Inst) {
return false;
}
+// Instructions that have mayLoad/mayStore set in TableGen but don't actually
+// perform memory accesses.
+static bool isNotMemAccess(const MCInst &Inst) {
+ switch (Inst.getOpcode()) {
+ case AArch64::DMB:
+ case AArch64::DSB:
+ case AArch64::ISB:
+ case AArch64::HINT:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static bool mayPrefetch(const MCInst &Inst) {
+ switch (Inst.getOpcode()) {
+ case AArch64::PRFMl:
+ case AArch64::PRFMroW:
+ case AArch64::PRFMroX:
+ case AArch64::PRFMui:
+ case AArch64::PRFUMi:
+ return true;
+ default:
+ return false;
+ }
+}
+
+// User-mode DC/IC instructions that take a virtual address operand. Encoded as
+// SYSxt with op1=3, Cn=7, op2=1 where the Cm field selects the operation.
+static bool isVASysOp(const MCInst &Inst) {
+ if (Inst.getOpcode() != AArch64::SYSxt)
+ return false;
+ if (Inst.getOperand(0).getImm() != 3 || Inst.getOperand(1).getImm() != 7 ||
+ Inst.getOperand(3).getImm() != 1)
+ return false;
+ switch (Inst.getOperand(2).getImm()) {
+ case 4: // DC ZVA
+ case 5: // IC IVAU
+ case 10: // DC CVAC
+ case 11: // DC CVAU
+ case 12: // DC CVAP
+ case 13: // DC CVADP
+ case 14: // DC CIVAC
+ return true;
+ default:
+ return false;
+ }
+}
+
+static MCInst replaceRegAt(const MCInst &Inst, unsigned Idx,
+ MCRegister NewReg) {
+ MCInst New;
+ New.setOpcode(Inst.getOpcode());
+ New.setLoc(Inst.getLoc());
+ for (unsigned I = 0, E = Inst.getNumOperands(); I != E; ++I) {
+ if (I == Idx)
+ New.addOperand(MCOperand::createReg(NewReg));
+ else
+ New.addOperand(Inst.getOperand(I));
+ }
+ return New;
+}
+
+// Memory instruction information for the basic load/store rewriting path.
+// Provides operand indices for the base register and offset, and whether
+// the instruction uses pre/post-indexed addressing.
+struct MemInstInfo {
+ int BaseRegIdx;
+ int OffsetIdx; // -1 if no offset operand.
+ bool IsPrePost;
+ bool IsLiteral;
+};
+
+// Returns memory instruction info for a given opcode, or std::nullopt if
+// the opcode is not a recognized memory instruction.
+static std::optional<MemInstInfo> getMemInstInfo(unsigned Op);
+
----------------
smithp35 wrote:
There's a comment further down explaining what RoW means, could be worth a quick acronym definition here. In particular:
Ui, RoW and RoX
https://github.com/llvm/llvm-project/pull/195167
More information about the llvm-commits
mailing list