@@ -67,10 +67,14 @@ static const std::pair<MCPhysReg, int8_t> FixedCSRFIMap[] = {
6767static void emitSCSPrologue (MachineFunction &MF, MachineBasicBlock &MBB,
6868 MachineBasicBlock::iterator MI,
6969 const DebugLoc &DL) {
70- if (!MF.getFunction ().hasFnAttribute (Attribute::ShadowCallStack))
70+ const auto &STI = MF.getSubtarget <RISCVSubtarget>();
71+ bool HasHWShadowStack = MF.getFunction ().hasFnAttribute (" hw-shadow-stack" ) &&
72+ STI.hasStdExtZimop ();
73+ bool HasSWShadowStack =
74+ MF.getFunction ().hasFnAttribute (Attribute::ShadowCallStack);
75+ if (!HasHWShadowStack && !HasSWShadowStack)
7176 return ;
7277
73- const auto &STI = MF.getSubtarget <RISCVSubtarget>();
7478 const llvm::RISCVRegisterInfo *TRI = STI.getRegisterInfo ();
7579 Register RAReg = TRI->getRARegister ();
7680
@@ -82,7 +86,7 @@ static void emitSCSPrologue(MachineFunction &MF, MachineBasicBlock &MBB,
8286 return ;
8387
8488 const RISCVInstrInfo *TII = STI.getInstrInfo ();
85- if (!STI. hasForcedSWShadowStack () && STI. hasStdExtZicfiss () ) {
89+ if (HasHWShadowStack ) {
8690 BuildMI (MBB, MI, DL, TII->get (RISCV::SSPUSH)).addReg (RAReg);
8791 return ;
8892 }
@@ -129,10 +133,14 @@ static void emitSCSPrologue(MachineFunction &MF, MachineBasicBlock &MBB,
129133static void emitSCSEpilogue (MachineFunction &MF, MachineBasicBlock &MBB,
130134 MachineBasicBlock::iterator MI,
131135 const DebugLoc &DL) {
132- if (!MF.getFunction ().hasFnAttribute (Attribute::ShadowCallStack))
136+ const auto &STI = MF.getSubtarget <RISCVSubtarget>();
137+ bool HasHWShadowStack = MF.getFunction ().hasFnAttribute (" hw-shadow-stack" ) &&
138+ STI.hasStdExtZimop ();
139+ bool HasSWShadowStack =
140+ MF.getFunction ().hasFnAttribute (Attribute::ShadowCallStack);
141+ if (!HasHWShadowStack && !HasSWShadowStack)
133142 return ;
134143
135- const auto &STI = MF.getSubtarget <RISCVSubtarget>();
136144 Register RAReg = STI.getRegisterInfo ()->getRARegister ();
137145
138146 // See emitSCSPrologue() above.
@@ -142,7 +150,7 @@ static void emitSCSEpilogue(MachineFunction &MF, MachineBasicBlock &MBB,
142150 return ;
143151
144152 const RISCVInstrInfo *TII = STI.getInstrInfo ();
145- if (!STI. hasForcedSWShadowStack () && STI. hasStdExtZicfiss () ) {
153+ if (HasHWShadowStack ) {
146154 BuildMI (MBB, MI, DL, TII->get (RISCV::SSPOPCHK)).addReg (RAReg);
147155 return ;
148156 }
0 commit comments