Index: llvm/lib/Target/SystemZ/SystemZISelLowering.cpp =================================================================== --- llvm/lib/Target/SystemZ/SystemZISelLowering.cpp +++ llvm/lib/Target/SystemZ/SystemZISelLowering.cpp @@ -82,6 +82,8 @@ : TargetLowering(TM), Subtarget(STI) { MVT PtrVT = MVT::getIntegerVT(8 * TM.getPointerSize(0)); + auto *Regs = STI.getSpecialRegisters(); + // Set up the register classes. if (Subtarget.hasHighWord()) addRegisterClass(MVT::i32, &SystemZ::GRX32BitRegClass); @@ -115,7 +117,7 @@ computeRegisterProperties(Subtarget.getRegisterInfo()); // Set up special registers. - setStackPointerRegisterToSaveRestore(SystemZ::R15D); + setStackPointerRegisterToSaveRestore(Regs->getStackPointerRegister()); // TODO: It may be better to default to latency-oriented scheduling, however // LLVM's current latency-oriented scheduler can't handle physreg definitions @@ -4139,17 +4141,21 @@ SDValue SystemZTargetLowering::lowerSTACKSAVE(SDValue Op, SelectionDAG &DAG) const { MachineFunction &MF = DAG.getMachineFunction(); + const SystemZSubtarget *Subtarget = &MF.getSubtarget(); + auto *Regs = Subtarget->getSpecialRegisters(); MF.getInfo()->setManipulatesSP(true); if (MF.getFunction().getCallingConv() == CallingConv::GHC) report_fatal_error("Variable-sized stack allocations are not supported " "in GHC calling convention"); return DAG.getCopyFromReg(Op.getOperand(0), SDLoc(Op), - SystemZ::R15D, Op.getValueType()); + Regs->getStackPointerRegister(), Op.getValueType()); } SDValue SystemZTargetLowering::lowerSTACKRESTORE(SDValue Op, SelectionDAG &DAG) const { MachineFunction &MF = DAG.getMachineFunction(); + const SystemZSubtarget *Subtarget = &MF.getSubtarget(); + auto *Regs = Subtarget->getSpecialRegisters(); MF.getInfo()->setManipulatesSP(true); bool StoreBackchain = MF.getFunction().hasFnAttribute("backchain"); @@ -4163,12 +4169,13 @@ SDLoc DL(Op); if (StoreBackchain) { - SDValue OldSP = DAG.getCopyFromReg(Chain, DL, SystemZ::R15D, MVT::i64); + SDValue OldSP = DAG.getCopyFromReg( + Chain, DL, Regs->getStackPointerRegister(), MVT::i64); Backchain = DAG.getLoad(MVT::i64, DL, Chain, getBackchainAddress(OldSP, DAG), MachinePointerInfo()); } - Chain = DAG.getCopyToReg(Chain, DL, SystemZ::R15D, NewSP); + Chain = DAG.getCopyToReg(Chain, DL, Regs->getStackPointerRegister(), NewSP); if (StoreBackchain) Chain = DAG.getStore(Chain, DL, Backchain, getBackchainAddress(NewSP, DAG),