@@ -200,7 +200,7 @@ struct MachineSMEABI : public MachineFunctionPass {
200200
201201 // / Inserts code to handle changes between ZA states within the function.
202202 // / E.g., ACTIVE -> LOCAL_SAVED will insert code required to save ZA.
203- void insertStateChanges (bool IsAgnosticZA );
203+ void insertStateChanges ();
204204
205205 // Emission routines for private and shared ZA functions (using lazy saves).
206206 void emitNewZAPrologue (MachineBasicBlock &MBB,
@@ -227,26 +227,25 @@ struct MachineSMEABI : public MachineFunctionPass {
227227 LiveRegs PhysLiveRegs);
228228
229229 void emitStateChange (MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
230- ZAState From, ZAState To, LiveRegs PhysLiveRegs,
231- bool IsAgnosticZA);
230+ ZAState From, ZAState To, LiveRegs PhysLiveRegs);
232231
233232 // Helpers for switching between lazy/full ZA save/restore routines.
234233 void emitZASave (MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
235- LiveRegs PhysLiveRegs, bool IsAgnosticZA ) {
236- if (IsAgnosticZA )
234+ LiveRegs PhysLiveRegs) {
235+ if (AFI-> getSMEFnAttrs (). hasAgnosticZAInterface () )
237236 return emitFullZASaveRestore (MBB, MBBI, PhysLiveRegs, /* IsSave=*/ true );
238237 return emitSetupLazySave (MBB, MBBI);
239238 }
240239 void emitZARestore (MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
241- LiveRegs PhysLiveRegs, bool IsAgnosticZA ) {
242- if (IsAgnosticZA )
240+ LiveRegs PhysLiveRegs) {
241+ if (AFI-> getSMEFnAttrs (). hasAgnosticZAInterface () )
243242 return emitFullZASaveRestore (MBB, MBBI, PhysLiveRegs, /* IsSave=*/ false );
244243 return emitRestoreLazySave (MBB, MBBI, PhysLiveRegs);
245244 }
246245 void emitAllocateZASaveBuffer (MachineBasicBlock &MBB,
247246 MachineBasicBlock::iterator MBBI,
248- LiveRegs PhysLiveRegs, bool IsAgnosticZA ) {
249- if (IsAgnosticZA )
247+ LiveRegs PhysLiveRegs) {
248+ if (AFI-> getSMEFnAttrs (). hasAgnosticZAInterface () )
250249 return emitAllocateFullZASaveBuffer (MBB, MBBI, PhysLiveRegs);
251250 return emitAllocateLazySaveBuffer (MBB, MBBI);
252251 }
@@ -288,13 +287,13 @@ struct MachineSMEABI : public MachineFunctionPass {
288287 std::optional<MachineBasicBlock::iterator> AfterSMEProloguePt;
289288 Register AgnosticZABufferPtr = AArch64::NoRegister;
290289 LiveRegs PhysLiveRegsAfterSMEPrologue = LiveRegs::None;
291- bool HasFullZASaveRestore = false ;
292290 } State;
293291
294292 MachineFunction *MF = nullptr ;
295293 EdgeBundles *Bundles = nullptr ;
296294 const AArch64Subtarget *Subtarget = nullptr ;
297295 const AArch64RegisterInfo *TRI = nullptr ;
296+ const AArch64FunctionInfo *AFI = nullptr ;
298297 const TargetInstrInfo *TII = nullptr ;
299298 MachineRegisterInfo *MRI = nullptr ;
300299};
@@ -425,7 +424,7 @@ void MachineSMEABI::assignBundleZAStates() {
425424 }
426425}
427426
428- void MachineSMEABI::insertStateChanges (bool IsAgnosticZA ) {
427+ void MachineSMEABI::insertStateChanges () {
429428 for (MachineBasicBlock &MBB : *MF) {
430429 const BlockInfo &Block = State.Blocks [MBB.getNumber ()];
431430 ZAState InState = State.BundleStates [Bundles->getBundle (MBB.getNumber (),
@@ -438,7 +437,7 @@ void MachineSMEABI::insertStateChanges(bool IsAgnosticZA) {
438437 for (auto &Inst : Block.Insts ) {
439438 if (CurrentState != Inst.NeededState )
440439 emitStateChange (MBB, Inst.InsertPt , CurrentState, Inst.NeededState ,
441- Inst.PhysLiveRegs , IsAgnosticZA );
440+ Inst.PhysLiveRegs );
442441 CurrentState = Inst.NeededState ;
443442 }
444443
@@ -449,7 +448,7 @@ void MachineSMEABI::insertStateChanges(bool IsAgnosticZA) {
449448 State.BundleStates [Bundles->getBundle (MBB.getNumber (), /* Out=*/ true )];
450449 if (CurrentState != OutState)
451450 emitStateChange (MBB, MBB.getFirstTerminator (), CurrentState, OutState,
452- Block.PhysLiveRegsAtExit , IsAgnosticZA );
451+ Block.PhysLiveRegsAtExit );
453452 }
454453}
455454
@@ -582,8 +581,6 @@ void MachineSMEABI::emitZAOff(MachineBasicBlock &MBB,
582581void MachineSMEABI::emitAllocateLazySaveBuffer (
583582 MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI) {
584583 MachineFrameInfo &MFI = MF->getFrameInfo ();
585- auto *AFI = MF->getInfo <AArch64FunctionInfo>();
586-
587584 DebugLoc DL = getDebugLoc (MBB, MBBI);
588585 Register SP = MRI->createVirtualRegister (&AArch64::GPR64RegClass);
589586 Register SVL = MRI->createVirtualRegister (&AArch64::GPR64RegClass);
@@ -680,7 +677,6 @@ void MachineSMEABI::emitFullZASaveRestore(MachineBasicBlock &MBB,
680677 MachineBasicBlock::iterator MBBI,
681678 LiveRegs PhysLiveRegs, bool IsSave) {
682679 auto *TLI = Subtarget->getTargetLowering ();
683- State.HasFullZASaveRestore = true ;
684680 DebugLoc DL = getDebugLoc (MBB, MBBI);
685681 Register BufferPtr = AArch64::X0;
686682
@@ -705,8 +701,6 @@ void MachineSMEABI::emitFullZASaveRestore(MachineBasicBlock &MBB,
705701void MachineSMEABI::emitAllocateFullZASaveBuffer (
706702 MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
707703 LiveRegs PhysLiveRegs) {
708- auto *AFI = MF->getInfo <AArch64FunctionInfo>();
709-
710704 // Buffer already allocated in SelectionDAG.
711705 if (AFI->getEarlyAllocSMESaveBuffer ())
712706 return ;
@@ -751,7 +745,7 @@ void MachineSMEABI::emitAllocateFullZASaveBuffer(
751745void MachineSMEABI::emitStateChange (MachineBasicBlock &MBB,
752746 MachineBasicBlock::iterator InsertPt,
753747 ZAState From, ZAState To,
754- LiveRegs PhysLiveRegs, bool IsAgnosticZA ) {
748+ LiveRegs PhysLiveRegs) {
755749
756750 // ZA not used.
757751 if (From == ZAState::ANY || To == ZAState::ANY)
@@ -783,13 +777,14 @@ void MachineSMEABI::emitStateChange(MachineBasicBlock &MBB,
783777 }
784778
785779 if (From == ZAState::ACTIVE && To == ZAState::LOCAL_SAVED)
786- emitZASave (MBB, InsertPt, PhysLiveRegs, IsAgnosticZA );
780+ emitZASave (MBB, InsertPt, PhysLiveRegs);
787781 else if (From == ZAState::LOCAL_SAVED && To == ZAState::ACTIVE)
788- emitZARestore (MBB, InsertPt, PhysLiveRegs, IsAgnosticZA );
782+ emitZARestore (MBB, InsertPt, PhysLiveRegs);
789783 else if (To == ZAState::OFF) {
790784 assert (From != ZAState::CALLER_DORMANT &&
791785 " CALLER_DORMANT to OFF should have already been handled" );
792- assert (!IsAgnosticZA && " Should not turn ZA off in agnostic ZA function" );
786+ assert (!AFI->getSMEFnAttrs ().hasAgnosticZAInterface () &&
787+ " Should not turn ZA off in agnostic ZA function" );
793788 emitZAOff (MBB, InsertPt, /* ClearTPIDR2=*/ From == ZAState::LOCAL_SAVED);
794789 } else {
795790 dbgs () << " Error: Transition from " << getZAStateString (From) << " to "
@@ -807,7 +802,7 @@ bool MachineSMEABI::runOnMachineFunction(MachineFunction &MF) {
807802 if (!MF.getSubtarget <AArch64Subtarget>().hasSME ())
808803 return false ;
809804
810- auto * AFI = MF.getInfo <AArch64FunctionInfo>();
805+ AFI = MF.getInfo <AArch64FunctionInfo>();
811806 SMEAttrs SMEFnAttrs = AFI->getSMEFnAttrs ();
812807 if (!SMEFnAttrs.hasZAState () && !SMEFnAttrs.hasZT0State () &&
813808 !SMEFnAttrs.hasAgnosticZAInterface ())
@@ -824,27 +819,23 @@ bool MachineSMEABI::runOnMachineFunction(MachineFunction &MF) {
824819 TRI = Subtarget->getRegisterInfo ();
825820 MRI = &MF.getRegInfo ();
826821
827- bool IsAgnosticZA = SMEFnAttrs.hasAgnosticZAInterface ();
828-
829822 collectNeededZAStates (SMEFnAttrs);
830823 assignBundleZAStates ();
831- insertStateChanges (/* IsAgnosticZA= */ IsAgnosticZA );
824+ insertStateChanges ();
832825
833826 // Allocate save buffer (if needed).
834- if (State.HasFullZASaveRestore || State.TPIDR2Block ) {
827+ if (State.AgnosticZABufferPtr != AArch64::NoRegister || State.TPIDR2Block ) {
835828 if (State.AfterSMEProloguePt ) {
836829 // Note: With inline stack probes the AfterSMEProloguePt may not be in the
837830 // entry block (due to the probing loop).
838831 emitAllocateZASaveBuffer (*(*State.AfterSMEProloguePt )->getParent (),
839832 *State.AfterSMEProloguePt ,
840- State.PhysLiveRegsAfterSMEPrologue ,
841- /* IsAgnosticZA=*/ IsAgnosticZA);
833+ State.PhysLiveRegsAfterSMEPrologue );
842834 } else {
843835 MachineBasicBlock &EntryBlock = MF.front ();
844836 emitAllocateZASaveBuffer (
845837 EntryBlock, EntryBlock.getFirstNonPHI (),
846- State.Blocks [EntryBlock.getNumber ()].PhysLiveRegsAtEntry ,
847- /* IsAgnosticZA=*/ IsAgnosticZA);
838+ State.Blocks [EntryBlock.getNumber ()].PhysLiveRegsAtEntry );
848839 }
849840 }
850841
0 commit comments