@@ -58,10 +58,14 @@ static const std::pair<MCPhysReg, int8_t> FixedCSRFIMap[] = {
5858static void emitSCSPrologue (MachineFunction &MF, MachineBasicBlock &MBB,
5959 MachineBasicBlock::iterator MI,
6060 const DebugLoc &DL) {
61- if (!MF.getFunction ().hasFnAttribute (Attribute::ShadowCallStack))
61+ const auto &STI = MF.getSubtarget <RISCVSubtarget>();
62+ bool HasHWShadowStack =
63+ MF.getFunction ().hasFnAttribute (" hw-shadow-stack" ) && STI.hasStdExtZimop ();
64+ bool HasSWShadowStack =
65+ MF.getFunction ().hasFnAttribute (Attribute::ShadowCallStack);
66+ if (!HasHWShadowStack && !HasSWShadowStack)
6267 return ;
6368
64- const auto &STI = MF.getSubtarget <RISCVSubtarget>();
6569 const llvm::RISCVRegisterInfo *TRI = STI.getRegisterInfo ();
6670 Register RAReg = TRI->getRARegister ();
6771
@@ -73,7 +77,7 @@ static void emitSCSPrologue(MachineFunction &MF, MachineBasicBlock &MBB,
7377 return ;
7478
7579 const RISCVInstrInfo *TII = STI.getInstrInfo ();
76- if (!STI. hasForcedSWShadowStack () && STI. hasStdExtZicfiss () ) {
80+ if (HasHWShadowStack ) {
7781 BuildMI (MBB, MI, DL, TII->get (RISCV::SSPUSH)).addReg (RAReg);
7882 return ;
7983 }
@@ -120,10 +124,14 @@ static void emitSCSPrologue(MachineFunction &MF, MachineBasicBlock &MBB,
120124static void emitSCSEpilogue (MachineFunction &MF, MachineBasicBlock &MBB,
121125 MachineBasicBlock::iterator MI,
122126 const DebugLoc &DL) {
123- if (!MF.getFunction ().hasFnAttribute (Attribute::ShadowCallStack))
127+ const auto &STI = MF.getSubtarget <RISCVSubtarget>();
128+ bool HasHWShadowStack =
129+ MF.getFunction ().hasFnAttribute (" hw-shadow-stack" ) && STI.hasStdExtZimop ();
130+ bool HasSWShadowStack =
131+ MF.getFunction ().hasFnAttribute (Attribute::ShadowCallStack);
132+ if (!HasHWShadowStack && !HasSWShadowStack)
124133 return ;
125134
126- const auto &STI = MF.getSubtarget <RISCVSubtarget>();
127135 Register RAReg = STI.getRegisterInfo ()->getRARegister ();
128136
129137 // See emitSCSPrologue() above.
@@ -133,7 +141,7 @@ static void emitSCSEpilogue(MachineFunction &MF, MachineBasicBlock &MBB,
133141 return ;
134142
135143 const RISCVInstrInfo *TII = STI.getInstrInfo ();
136- if (!STI. hasForcedSWShadowStack () && STI. hasStdExtZicfiss () ) {
144+ if (HasHWShadowStack ) {
137145 BuildMI (MBB, MI, DL, TII->get (RISCV::SSPOPCHK)).addReg (RAReg);
138146 return ;
139147 }
0 commit comments