3232#include " llvm/IR/Intrinsics.h"
3333#include " llvm/IR/IntrinsicsS390.h"
3434#include " llvm/IR/Module.h"
35- #include " llvm/Support/Casting.h"
3635#include " llvm/IR/PatternMatch.h"
36+ #include " llvm/Support/Casting.h"
3737#include " llvm/Support/CommandLine.h"
3838#include " llvm/Support/ErrorHandling.h"
3939#include " llvm/Support/KnownBits.h"
@@ -8187,12 +8187,17 @@ SDValue SystemZTargetLowering::combineSTORE(
81878187 }
81888188
81898189 // combine STORE (LOAD_STACK_GUARD) into MOVE_STACK_GUARD
8190- if (Op1->isMachineOpcode () && (Op1->getMachineOpcode () == SystemZ::LOAD_STACK_GUARD)) {
8191- // If so, create a MOVE_STACK_GUARD node to subsume the LOAD_STACK_GUARD, Store sequence.
8190+ if (Op1->isMachineOpcode () &&
8191+ (Op1->getMachineOpcode () == SystemZ::LOAD_STACK_GUARD)) {
8192+ // If so, create a MOVE_STACK_GUARD node to subsume the LOAD_STACK_GUARD,
8193+ // Store sequence.
81928194 int FI = cast<FrameIndexSDNode>(SN->getOperand (2 ))->getIndex ();
81938195 // Dummy Register, FrameIndex, Dummy Displacement
8194- SDValue Ops[] = {DAG.getTargetFrameIndex (FI, MVT::i64 ), DAG.getTargetConstant (0 , SDLoc (SN), MVT::i64 ), SN->getChain ()};
8195- MachineSDNode* Move = DAG.getMachineNode (SystemZ::MOVE_STACK_GUARD, SDLoc (SN), MVT::Other, Ops);
8196+ SDValue Ops[] = {DAG.getTargetFrameIndex (FI, MVT::i64 ),
8197+ DAG.getTargetConstant (0 , SDLoc (SN), MVT::i64 ),
8198+ SN->getChain ()};
8199+ MachineSDNode *Move = DAG.getMachineNode (SystemZ::MOVE_STACK_GUARD,
8200+ SDLoc (SN), MVT::Other, Ops);
81968201
81978202 return SDValue (Move, 0 );
81988203 }
@@ -9133,27 +9138,30 @@ SDValue SystemZTargetLowering::combineICMP(SDNode *N,
91339138
91349139 // Combine icmp (load fi, LOAD_STACK_GUARD) into COMPARE_STACK_GUARD.
91359140
9136- const SDValue & LHS = N->getOperand (0 );
9137- const SDValue & RHS = N->getOperand (1 );
9141+ const SDValue &LHS = N->getOperand (0 );
9142+ const SDValue &RHS = N->getOperand (1 );
91389143
9139- if (!ISD::isNormalLoad (RHS.getNode ()) || !(LHS.isMachineOpcode () && (LHS->getMachineOpcode () == SystemZ::LOAD_STACK_GUARD)))
9144+ if (!ISD::isNormalLoad (RHS.getNode ()) ||
9145+ !(LHS.isMachineOpcode () &&
9146+ (LHS->getMachineOpcode () == SystemZ::LOAD_STACK_GUARD)))
91409147 return SDValue ();
91419148
9142- auto const * StackLoad = cast<LoadSDNode>(RHS.getNode ());
9149+ auto const *StackLoad = cast<LoadSDNode>(RHS.getNode ());
91439150
91449151 // The StackLoad will have an outgoing chain that needs to be redirected.
91459152 SDValue InChain = StackLoad->getChain ();
9146- SDValue OutChain = SDValue (const_cast <LoadSDNode*>(StackLoad), 1 );
9153+ SDValue OutChain = SDValue (const_cast <LoadSDNode *>(StackLoad), 1 );
91479154 DAG.ReplaceAllUsesOfValueWith (OutChain, InChain);
91489155
91499156 int FI = cast<FrameIndexSDNode>(StackLoad->getOperand (1 ))->getIndex ();
91509157
91519158 // Now, create a COMPARE_STACK_GUARD node to subsume the
91529159 // LoadFI, LOAD_STACK_GUARD, Compare sequence.
9153- // Operands are the FrameIndex where the stackguard is stored, and the input chain.
9154- SDValue Ops[] = {DAG.getTargetFrameIndex (FI, MVT::i64 ), InChain };
9155- MachineSDNode *Move = DAG.getMachineNode (SystemZ::COMPARE_STACK_GUARD,
9156- DL, MVT::i32 , Ops);
9160+ // Operands are the FrameIndex where the stackguard is stored, and the input
9161+ // chain.
9162+ SDValue Ops[] = {DAG.getTargetFrameIndex (FI, MVT::i64 ), InChain};
9163+ MachineSDNode *Move =
9164+ DAG.getMachineNode (SystemZ::COMPARE_STACK_GUARD, DL, MVT::i32 , Ops);
91579165
91589166 return SDValue (Move, 0 );
91599167}
@@ -9472,7 +9480,8 @@ SDValue SystemZTargetLowering::PerformDAGCombine(SDNode *N,
94729480 case SystemZISD::BR_CCMASK: return combineBR_CCMASK (N, DCI);
94739481 case SystemZISD::SELECT_CCMASK: return combineSELECT_CCMASK (N, DCI);
94749482 case SystemZISD::GET_CCMASK: return combineGET_CCMASK (N, DCI);
9475- case SystemZISD::ICMP: return combineICMP (N, DCI);
9483+ case SystemZISD::ICMP:
9484+ return combineICMP (N, DCI);
94769485 case ISD::SRL:
94779486 case ISD::SRA: return combineShiftToMulAddHigh (N, DCI);
94789487 case ISD::MUL: return combineMUL (N, DCI);
@@ -11142,43 +11151,44 @@ getBackchainAddress(SDValue SP, SelectionDAG &DAG) const {
1114211151}
1114311152
1114411153namespace {
11145- // The custom inserters for MOVE_STACK_GUARD and COMPARE_STACK_GUARD both
11146- // need to load the address of the stack guard. This function enables that.
11147- Register emitLoadStackGuard (MachineInstr& MI, MachineBasicBlock* MBB) {
11148- MachineFunction &MF = *MBB->getParent ();
11149- auto *II = MF.getTarget ().getMCInstrInfo ();
11150- const Register AddrReg =
11151- MF.getRegInfo ().createVirtualRegister (&SystemZ::ADDR64BitRegClass);
11152-
11153-
11154- Module *M = MF.getFunction ().getParent ();
11155- StringRef GuardType = M->getStackProtectorGuard ();
11156-
11157- if (GuardType.empty () || (GuardType == " tls" )) {
11158- // TLS-based stack guard loading will be emitted post RA.
11159- // This is so we can more easily guarantee the ear, sllg, ear, load sequence.
11160- BuildMI (*MBB, MI, MI.getDebugLoc (), II->get (TargetOpcode::LOAD_STACK_GUARD), AddrReg);
11161-
11162- } else if (GuardType == " global" ) {
11163- // Obtain the global value.
11164- const GlobalValue *GV = M->getOrInsertGlobal (
11165- " __stack_chk_guard" , PointerType::getUnqual (M->getContext ()));
11166- // Emit the move.
11167- if (M->getPICLevel () == PICLevel::NotPIC) {
11168- BuildMI (*MBB, MI, MI.getDebugLoc (), II->get (SystemZ::LARL), AddrReg)
11169- .addGlobalAddress (GV);
11170- } else {
11171- BuildMI (*MBB, MI, MI.getDebugLoc (), II->get (SystemZ::LGRL), AddrReg)
11172- .addGlobalAddress (GV);
11173- }
11154+ // The custom inserters for MOVE_STACK_GUARD and COMPARE_STACK_GUARD both
11155+ // need to load the address of the stack guard. This function enables that.
11156+ Register emitLoadStackGuard (MachineInstr &MI, MachineBasicBlock *MBB) {
11157+ MachineFunction &MF = *MBB->getParent ();
11158+ auto *II = MF.getTarget ().getMCInstrInfo ();
11159+ const Register AddrReg =
11160+ MF.getRegInfo ().createVirtualRegister (&SystemZ::ADDR64BitRegClass);
11161+
11162+ Module *M = MF.getFunction ().getParent ();
11163+ StringRef GuardType = M->getStackProtectorGuard ();
11164+
11165+ if (GuardType.empty () || (GuardType == " tls" )) {
11166+ // TLS-based stack guard loading will be emitted post RA.
11167+ // This is so we can more easily guarantee the ear, sllg, ear, load
11168+ // sequence.
11169+ BuildMI (*MBB, MI, MI.getDebugLoc (), II->get (TargetOpcode::LOAD_STACK_GUARD),
11170+ AddrReg);
11171+
11172+ } else if (GuardType == " global" ) {
11173+ // Obtain the global value.
11174+ const GlobalValue *GV = M->getOrInsertGlobal (
11175+ " __stack_chk_guard" , PointerType::getUnqual (M->getContext ()));
11176+ // Emit the move.
11177+ if (M->getPICLevel () == PICLevel::NotPIC) {
11178+ BuildMI (*MBB, MI, MI.getDebugLoc (), II->get (SystemZ::LARL), AddrReg)
11179+ .addGlobalAddress (GV);
1117411180 } else {
11175- llvm_unreachable (
11176- (Twine (" Unknown stack protector type \" " ) + GuardType + " \" " )
11177- .str ()
11178- .c_str ());
11181+ BuildMI (*MBB, MI, MI.getDebugLoc (), II->get (SystemZ::LGRL), AddrReg)
11182+ .addGlobalAddress (GV);
1117911183 }
11180- return AddrReg;
11184+ } else {
11185+ llvm_unreachable (
11186+ (Twine (" Unknown stack protector type \" " ) + GuardType + " \" " )
11187+ .str ()
11188+ .c_str ());
1118111189 }
11190+ return AddrReg;
11191+ }
1118211192} // namespace
1118311193
1118411194// Custom Inserter for MOVE_STACK_GUARD. Loads the address of the stack guard,
@@ -11203,11 +11213,11 @@ SystemZTargetLowering::emitMoveStackGuard(MachineInstr &MI,
1120311213 return MBB;
1120411214}
1120511215
11206- // Custom Inserter for COMPARE_STACK_GUARD. Loads the address of the stack guard,
11207- // then inserts a CLC.
11216+ // Custom Inserter for COMPARE_STACK_GUARD. Loads the address of the stack
11217+ // guard, then inserts a CLC.
1120811218MachineBasicBlock *
1120911219SystemZTargetLowering::emitCompareStackGuard (MachineInstr &MI,
11210- MachineBasicBlock *MBB) const {
11220+ MachineBasicBlock *MBB) const {
1121111221 MachineOperand &FI = MI.getOperand (0 );
1121211222 auto *II = MBB->getParent ()->getTarget ().getMCInstrInfo ();
1121311223 Register AddrReg = emitLoadStackGuard (MI, MBB);
0 commit comments