[clang] [llvm] [AArch64][SME] Save VG for unwind info when changing streaming-mode (PR #83301)

Kerry McLaughlin via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 3 09:50:48 PDT 2024


================
@@ -1552,6 +1553,57 @@ bool AArch64ExpandPseudo::expandMI(MachineBasicBlock &MBB,
    case AArch64::COALESCER_BARRIER_FPR128:
      MI.eraseFromParent();
      return true;
+   case AArch64::VGSavePseudo:
+   case AArch64::VGRestorePseudo: {
+     MachineFunction &MF = *MBB.getParent();
+     SMEAttrs FuncAttrs(MF.getFunction());
+     bool LocallyStreaming =
+         FuncAttrs.hasStreamingBody() && !FuncAttrs.hasStreamingInterface();
+     const AArch64FunctionInfo *AFI = MF.getInfo<AArch64FunctionInfo>();
+
+     if (!AFI->requiresVGSpill(MF))
+       return false;
+
+     int64_t VGFrameIdx =
+         LocallyStreaming ? AFI->getStreamingVGIdx() : AFI->getVGIdx();
+     assert(VGFrameIdx != std::numeric_limits<int>::max() &&
+            "Expected FrameIdx for VG");
+
+     const TargetSubtargetInfo &STI = MF.getSubtarget();
+     const TargetInstrInfo &TII = *STI.getInstrInfo();
+     const TargetRegisterInfo &TRI = *STI.getRegisterInfo();
+
+     if (Opcode == AArch64::VGSavePseudo) {
+       // This pseudo has been inserted after a streaming-mode change
+       // to save the streaming value of VG before a call.
+       // Calculate and emit the CFI offset using VGFrameIdx.
+       MachineFrameInfo &MFI = MF.getFrameInfo();
+       const AArch64FrameLowering *TFI =
+           MF.getSubtarget<AArch64Subtarget>().getFrameLowering();
+
+       int64_t Offset =
+           MFI.getObjectOffset(VGFrameIdx) - TFI->getOffsetOfLocalArea();
+       unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createOffset(
+           nullptr, TRI.getDwarfRegNum(AArch64::VG, true), Offset));
+       BuildMI(MBB, MBBI, MBBI->getDebugLoc(),
+               TII.get(TargetOpcode::CFI_INSTRUCTION))
+           .addCFIIndex(CFIIndex)
+           .setMIFlags(MachineInstr::FrameSetup);
+     } else {
----------------
kmclaughlin-arm wrote:

Expanding the pseudos has moved to AArch64FrameLowering.cpp. There is more common code here, so I have only added one function to expand both (`emitVGSaveRestore`). I can split this into an `emitVGSave`/`emitVGRestore` if you'd still prefer they be kept separate.

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


More information about the llvm-commits mailing list