Skip to content

Commit 8e53cc4

Browse files
Formatting changes
1 parent f1e3f28 commit 8e53cc4

File tree

4 files changed

+72
-61
lines changed

4 files changed

+72
-61
lines changed

llvm/lib/Target/SystemZ/SystemZISelLowering.cpp

Lines changed: 62 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
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

1114411153
namespace {
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.
1120811218
MachineBasicBlock *
1120911219
SystemZTargetLowering::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);

llvm/lib/Target/SystemZ/SystemZISelLowering.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,10 @@ class SystemZTargetLowering : public TargetLowering {
852852
unsigned Opcode) const;
853853
MachineBasicBlock *emitProbedAlloca(MachineInstr &MI,
854854
MachineBasicBlock *MBB) const;
855-
MachineBasicBlock *emitMoveStackGuard(MachineInstr &MI, MachineBasicBlock *MBB) const;
856-
MachineBasicBlock *emitCompareStackGuard(MachineInstr &MI, MachineBasicBlock *MBB) const;
855+
MachineBasicBlock *emitMoveStackGuard(MachineInstr &MI,
856+
MachineBasicBlock *MBB) const;
857+
MachineBasicBlock *emitCompareStackGuard(MachineInstr &MI,
858+
MachineBasicBlock *MBB) const;
857859

858860
SDValue getBackchainAddress(SDValue SP, SelectionDAG &DAG) const;
859861

llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,8 @@ void SystemZInstrInfo::expandLoadStackGuard(MachineInstr *MI) const {
18181818
MachineInstrBuilder(MF, MI).addReg(Reg64).addImm(40).addReg(0);
18191819
} else if (GuardType == "global") {
18201820
// Expanding the load of a global stack guard post-RA is an error.
1821-
llvm_unreachable("global stack guard expansion should have happened during isel.");
1821+
llvm_unreachable(
1822+
"global stack guard expansion should have happened during isel.");
18221823
} else {
18231824
llvm_unreachable(
18241825
(Twine("Unknown stack protector type \"") + GuardType + "\"")
@@ -1827,7 +1828,6 @@ void SystemZInstrInfo::expandLoadStackGuard(MachineInstr *MI) const {
18271828
}
18281829
}
18291830

1830-
18311831
unsigned SystemZInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
18321832
if (MI.isInlineAsm()) {
18331833
const MachineFunction *MF = MI.getParent()->getParent();

llvm/lib/Target/SystemZ/SystemZInstrInfo.td

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,13 +523,12 @@ let SimpleBDXStore = 1, mayStore = 1 in {
523523
}
524524

525525
let hasNoSchedulingInfo = 1, usesCustomInserter = 1, mayLoad = 1 in {
526-
let mayStore = 1 in
527-
def MOVE_STACK_GUARD : Pseudo<(outs), (ins bdaddr12only:$grdloc), []>;
528-
let Defs = [CC] in
529-
def COMPARE_STACK_GUARD : Pseudo<(outs), (ins bdaddr12only:$grdloc), []>;
526+
let mayStore = 1 in def MOVE_STACK_GUARD
527+
: Pseudo<(outs), (ins bdaddr12only:$grdloc), []>;
528+
let Defs = [CC] in def COMPARE_STACK_GUARD
529+
: Pseudo<(outs), (ins bdaddr12only:$grdloc), []>;
530530
}
531531

532-
533532
def STRL : StoreRILPC<"strl", 0xC4F, aligned_store, GR32>;
534533
def STGRL : StoreRILPC<"stgrl", 0xC4B, aligned_store, GR64>;
535534

0 commit comments

Comments
 (0)