Skip to content

Commit 6fc2953

Browse files
committed
[CodeGen] Provide Module to useLoadStackGuardNode
Use of LOAD_STACK_GUARD may depend upon compilation parameters; the Module has access to all of the stack guard parameter methods. Allow targets to only implement the old interface by providing a wrapper. Mark the old interface protected to catch callers who fail to pass the Module. Signed-off-by: Keith Packard <[email protected]>
1 parent 144dc4c commit 6fc2953

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5586,8 +5586,8 @@ class TargetLowering : public TargetLoweringBase {
55865586

55875587
/// If this function returns true, SelectionDAGBuilder emits a
55885588
/// LOAD_STACK_GUARD node when it is lowering Intrinsic::stackprotector.
5589-
virtual bool useLoadStackGuardNode() const {
5590-
return false;
5589+
virtual bool useLoadStackGuardNode(const Module &M) const {
5590+
return useLoadStackGuardNode();
55915591
}
55925592

55935593
virtual SDValue emitStackGuardXorFP(SelectionDAG &DAG, SDValue Val,
@@ -5616,6 +5616,10 @@ class TargetLowering : public TargetLoweringBase {
56165616
return true;
56175617
}
56185618

5619+
protected:
5620+
// Simple interface for targets without a Module dependency
5621+
virtual bool useLoadStackGuardNode() const { return false; }
5622+
56195623
private:
56205624
SDValue foldSetCCWithAnd(EVT VT, SDValue N0, SDValue N1, ISD::CondCode Cond,
56215625
const SDLoc &DL, DAGCombinerInfo &DCI) const;

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,7 +2377,7 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID,
23772377
case Intrinsic::stackprotector: {
23782378
LLT PtrTy = getLLTForType(*CI.getArgOperand(0)->getType(), *DL);
23792379
Register GuardVal;
2380-
if (TLI->useLoadStackGuardNode()) {
2380+
if (TLI->useLoadStackGuardNode(*CI.getModule())) {
23812381
GuardVal = MRI->createGenericVirtualRegister(PtrTy);
23822382
getStackGuard(GuardVal, MIRBuilder);
23832383
} else
@@ -3868,7 +3868,7 @@ bool IRTranslator::emitSPDescriptorParent(StackProtectorDescriptor &SPD,
38683868

38693869
// If useLoadStackGuardNode returns true, generate LOAD_STACK_GUARD.
38703870
// Otherwise, emit a volatile load to retrieve the stack guard value.
3871-
if (TLI->useLoadStackGuardNode()) {
3871+
if (TLI->useLoadStackGuardNode(*ParentBB->getBasicBlock()->getModule())) {
38723872
Guard =
38733873
MRI->createGenericVirtualRegister(LLT::scalar(PtrTy.getSizeInBits()));
38743874
getStackGuard(Guard, *CurBuilder);

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3138,7 +3138,7 @@ void SelectionDAGBuilder::visitSPDescriptorParent(StackProtectorDescriptor &SPD,
31383138
// If useLoadStackGuardNode returns true, generate LOAD_STACK_GUARD.
31393139
// Otherwise, emit a volatile load to retrieve the stack guard value.
31403140
SDValue Chain = DAG.getEntryNode();
3141-
if (TLI.useLoadStackGuardNode()) {
3141+
if (TLI.useLoadStackGuardNode(M)) {
31423142
Guard = getLoadStackGuard(DAG, dl, Chain);
31433143
} else {
31443144
const Value *IRGuard = TLI.getSDagStackGuard(M);
@@ -7331,7 +7331,7 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
73317331
const Module &M = *MF.getFunction().getParent();
73327332
EVT PtrTy = TLI.getValueType(DAG.getDataLayout(), I.getType());
73337333
SDValue Chain = getRoot();
7334-
if (TLI.useLoadStackGuardNode()) {
7334+
if (TLI.useLoadStackGuardNode(M)) {
73357335
Res = getLoadStackGuard(DAG, sdl, Chain);
73367336
Res = DAG.getPtrExtOrTrunc(Res, sdl, PtrTy);
73377337
} else {
@@ -7351,9 +7351,10 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
73517351
// Emit code into the DAG to store the stack guard onto the stack.
73527352
MachineFunction &MF = DAG.getMachineFunction();
73537353
MachineFrameInfo &MFI = MF.getFrameInfo();
7354+
const Module &M = *MF.getFunction().getParent();
73547355
SDValue Src, Chain = getRoot();
73557356

7356-
if (TLI.useLoadStackGuardNode())
7357+
if (TLI.useLoadStackGuardNode(M))
73577358
Src = getLoadStackGuard(DAG, sdl, Chain);
73587359
else
73597360
Src = getValue(I.getArgOperand(0)); // The guard's value.

0 commit comments

Comments
 (0)