Skip to content

Commit 2865ca1

Browse files
committed
deduplicate addTokenForArgument
1 parent 3a1079f commit 2865ca1

File tree

6 files changed

+36
-76
lines changed

6 files changed

+36
-76
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4999,6 +4999,12 @@ class LLVM_ABI TargetLowering : public TargetLoweringBase {
49994999
llvm_unreachable("Not Implemented");
50005000
}
50015001

5002+
/// Finds the incoming stack arguments which overlap the given fixed stack
5003+
/// object and incorporates their load into the current chain. This prevents
5004+
/// an upcoming store from clobbering the stack argument before it's used.
5005+
SDValue addTokenForArgument(SDValue Chain, SelectionDAG &DAG,
5006+
MachineFrameInfo &MFI, int ClobberedFI) const;
5007+
50025008
/// Target-specific cleanup for formal ByVal parameters.
50035009
virtual void HandleByVal(CCState *, unsigned &, Align) const {}
50045010

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,36 @@ bool TargetLowering::parametersInCSRMatch(const MachineRegisterInfo &MRI,
115115
return true;
116116
}
117117

118+
SDValue TargetLowering::addTokenForArgument(SDValue Chain, SelectionDAG &DAG,
119+
MachineFrameInfo &MFI,
120+
int ClobberedFI) const {
121+
SmallVector<SDValue, 8> ArgChains;
122+
int64_t FirstByte = MFI.getObjectOffset(ClobberedFI);
123+
int64_t LastByte = FirstByte + MFI.getObjectSize(ClobberedFI) - 1;
124+
125+
// Include the original chain at the beginning of the list. When this is
126+
// used by target LowerCall hooks, this helps legalize find the
127+
// CALLSEQ_BEGIN node.
128+
ArgChains.push_back(Chain);
129+
130+
// Add a chain value for each stack argument corresponding
131+
for (SDNode *U : DAG.getEntryNode().getNode()->users())
132+
if (LoadSDNode *L = dyn_cast<LoadSDNode>(U))
133+
if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(L->getBasePtr()))
134+
if (FI->getIndex() < 0) {
135+
int64_t InFirstByte = MFI.getObjectOffset(FI->getIndex());
136+
int64_t InLastByte = InFirstByte;
137+
InLastByte += MFI.getObjectSize(FI->getIndex()) - 1;
138+
139+
if ((InFirstByte <= FirstByte && FirstByte <= InLastByte) ||
140+
(FirstByte <= InFirstByte && InFirstByte <= LastByte))
141+
ArgChains.push_back(SDValue(L, 1));
142+
}
143+
144+
// Build a tokenfactor for all the chains.
145+
return DAG.getNode(ISD::TokenFactor, SDLoc(Chain), MVT::Other, ArgChains);
146+
}
147+
118148
/// Set CallLoweringInfo attribute flags based on a call instruction
119149
/// and called function attributes.
120150
void TargetLoweringBase::ArgListEntry::setAttributes(const CallBase *Call,

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9353,37 +9353,6 @@ bool AArch64TargetLowering::isEligibleForTailCallOptimization(
93539353
return true;
93549354
}
93559355

9356-
SDValue AArch64TargetLowering::addTokenForArgument(SDValue Chain,
9357-
SelectionDAG &DAG,
9358-
MachineFrameInfo &MFI,
9359-
int ClobberedFI) const {
9360-
SmallVector<SDValue, 8> ArgChains;
9361-
int64_t FirstByte = MFI.getObjectOffset(ClobberedFI);
9362-
int64_t LastByte = FirstByte + MFI.getObjectSize(ClobberedFI) - 1;
9363-
9364-
// Include the original chain at the beginning of the list. When this is
9365-
// used by target LowerCall hooks, this helps legalize find the
9366-
// CALLSEQ_BEGIN node.
9367-
ArgChains.push_back(Chain);
9368-
9369-
// Add a chain value for each stack argument corresponding
9370-
for (SDNode *U : DAG.getEntryNode().getNode()->users())
9371-
if (LoadSDNode *L = dyn_cast<LoadSDNode>(U))
9372-
if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(L->getBasePtr()))
9373-
if (FI->getIndex() < 0) {
9374-
int64_t InFirstByte = MFI.getObjectOffset(FI->getIndex());
9375-
int64_t InLastByte = InFirstByte;
9376-
InLastByte += MFI.getObjectSize(FI->getIndex()) - 1;
9377-
9378-
if ((InFirstByte <= FirstByte && FirstByte <= InLastByte) ||
9379-
(FirstByte <= InFirstByte && InFirstByte <= LastByte))
9380-
ArgChains.push_back(SDValue(L, 1));
9381-
}
9382-
9383-
// Build a tokenfactor for all the chains.
9384-
return DAG.getNode(ISD::TokenFactor, SDLoc(Chain), MVT::Other, ArgChains);
9385-
}
9386-
93879356
bool AArch64TargetLowering::DoesCalleeRestoreStack(CallingConv::ID CallCC,
93889357
bool TailCallOpt) const {
93899358
return (CallCC == CallingConv::Fast && TailCallOpt) ||

llvm/lib/Target/AArch64/AArch64ISelLowering.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -630,12 +630,6 @@ class AArch64TargetLowering : public TargetLowering {
630630
bool
631631
isEligibleForTailCallOptimization(const CallLoweringInfo &CLI) const;
632632

633-
/// Finds the incoming stack arguments which overlap the given fixed stack
634-
/// object and incorporates their load into the current chain. This prevents
635-
/// an upcoming store from clobbering the stack argument before it's used.
636-
SDValue addTokenForArgument(SDValue Chain, SelectionDAG &DAG,
637-
MachineFrameInfo &MFI, int ClobberedFI) const;
638-
639633
bool DoesCalleeRestoreStack(CallingConv::ID CallCC, bool TailCallOpt) const;
640634

641635
void saveVarArgRegisters(CCState &CCInfo, SelectionDAG &DAG, const SDLoc &DL,

llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,40 +1355,6 @@ CCAssignFn *AMDGPUTargetLowering::CCAssignFnForReturn(CallingConv::ID CC,
13551355
return AMDGPUCallLowering::CCAssignFnForReturn(CC, IsVarArg);
13561356
}
13571357

1358-
SDValue AMDGPUTargetLowering::addTokenForArgument(SDValue Chain,
1359-
SelectionDAG &DAG,
1360-
MachineFrameInfo &MFI,
1361-
int ClobberedFI) const {
1362-
SmallVector<SDValue, 8> ArgChains;
1363-
int64_t FirstByte = MFI.getObjectOffset(ClobberedFI);
1364-
int64_t LastByte = FirstByte + MFI.getObjectSize(ClobberedFI) - 1;
1365-
1366-
// Include the original chain at the beginning of the list. When this is
1367-
// used by target LowerCall hooks, this helps legalize find the
1368-
// CALLSEQ_BEGIN node.
1369-
ArgChains.push_back(Chain);
1370-
1371-
// Add a chain value for each stack argument corresponding
1372-
for (SDNode *U : DAG.getEntryNode().getNode()->users()) {
1373-
if (LoadSDNode *L = dyn_cast<LoadSDNode>(U)) {
1374-
if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(L->getBasePtr())) {
1375-
if (FI->getIndex() < 0) {
1376-
int64_t InFirstByte = MFI.getObjectOffset(FI->getIndex());
1377-
int64_t InLastByte = InFirstByte;
1378-
InLastByte += MFI.getObjectSize(FI->getIndex()) - 1;
1379-
1380-
if ((InFirstByte <= FirstByte && FirstByte <= InLastByte) ||
1381-
(FirstByte <= InFirstByte && InFirstByte <= LastByte))
1382-
ArgChains.push_back(SDValue(L, 1));
1383-
}
1384-
}
1385-
}
1386-
}
1387-
1388-
// Build a tokenfactor for all the chains.
1389-
return DAG.getNode(ISD::TokenFactor, SDLoc(Chain), MVT::Other, ArgChains);
1390-
}
1391-
13921358
SDValue AMDGPUTargetLowering::lowerUnhandledCall(CallLoweringInfo &CLI,
13931359
SmallVectorImpl<SDValue> &InVals,
13941360
StringRef Reason) const {

llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,6 @@ class AMDGPUTargetLowering : public TargetLowering {
255255
const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
256256
SelectionDAG &DAG) const override;
257257

258-
SDValue addTokenForArgument(SDValue Chain,
259-
SelectionDAG &DAG,
260-
MachineFrameInfo &MFI,
261-
int ClobberedFI) const;
262-
263258
SDValue lowerUnhandledCall(CallLoweringInfo &CLI,
264259
SmallVectorImpl<SDValue> &InVals,
265260
StringRef Reason) const;

0 commit comments

Comments
 (0)