Skip to content

Commit f58bc50

Browse files
BoyaoWang430github-actions[bot]
authored andcommitted
Automerge: [TargetLowering] Change getOptimalMemOpType and findOptimalMemOpLowering to take LLVM Context (#147664)
Add LLVM Context to getOptimalMemOpType and findOptimalMemOpLowering. So that we can use EVT::getVectorVT to generate EVT type in getOptimalMemOpType. Related to [#146673](llvm/llvm-project#146673).
2 parents 88de769 + 697beb3 commit f58bc50

23 files changed

+53
-41
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2017,7 +2017,7 @@ class LLVM_ABI TargetLoweringBase {
20172017
/// It returns EVT::Other if the type should be determined using generic
20182018
/// target-independent logic.
20192019
virtual EVT
2020-
getOptimalMemOpType(const MemOp &Op,
2020+
getOptimalMemOpType(LLVMContext &Context, const MemOp &Op,
20212021
const AttributeList & /*FuncAttributes*/) const {
20222022
return MVT::Other;
20232023
}
@@ -4109,8 +4109,9 @@ class LLVM_ABI TargetLowering : public TargetLoweringBase {
41094109
/// It returns the types of the sequence of memory ops to perform
41104110
/// memset / memcpy by reference.
41114111
virtual bool
4112-
findOptimalMemOpLowering(std::vector<EVT> &MemOps, unsigned Limit,
4113-
const MemOp &Op, unsigned DstAS, unsigned SrcAS,
4112+
findOptimalMemOpLowering(LLVMContext &Context, std::vector<EVT> &MemOps,
4113+
unsigned Limit, const MemOp &Op, unsigned DstAS,
4114+
unsigned SrcAS,
41144115
const AttributeList &FuncAttributes) const;
41154116

41164117
/// Check to see if the specified operand of the specified instruction is a

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8410,7 +8410,7 @@ static SDValue getMemcpyLoadsAndStores(
84108410
: MemOp::Copy(Size, DstAlignCanChange, Alignment,
84118411
*SrcAlign, isVol, CopyFromConstant);
84128412
if (!TLI.findOptimalMemOpLowering(
8413-
MemOps, Limit, Op, DstPtrInfo.getAddrSpace(),
8413+
C, MemOps, Limit, Op, DstPtrInfo.getAddrSpace(),
84148414
SrcPtrInfo.getAddrSpace(), MF.getFunction().getAttributes()))
84158415
return SDValue();
84168416

@@ -8602,7 +8602,7 @@ static SDValue getMemmoveLoadsAndStores(SelectionDAG &DAG, const SDLoc &dl,
86028602
assert(SrcAlign && "SrcAlign must be set");
86038603
unsigned Limit = AlwaysInline ? ~0U : TLI.getMaxStoresPerMemmove(OptSize);
86048604
if (!TLI.findOptimalMemOpLowering(
8605-
MemOps, Limit,
8605+
C, MemOps, Limit,
86068606
MemOp::Copy(Size, DstAlignCanChange, Alignment, *SrcAlign,
86078607
/*IsVolatile*/ true),
86088608
DstPtrInfo.getAddrSpace(), SrcPtrInfo.getAddrSpace(),
@@ -8711,6 +8711,7 @@ static SDValue getMemsetStores(SelectionDAG &DAG, const SDLoc &dl,
87118711
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
87128712
std::vector<EVT> MemOps;
87138713
bool DstAlignCanChange = false;
8714+
LLVMContext &C = *DAG.getContext();
87148715
MachineFunction &MF = DAG.getMachineFunction();
87158716
MachineFrameInfo &MFI = MF.getFrameInfo();
87168717
bool OptSize = shouldLowerMemFuncForSize(MF, DAG);
@@ -8721,7 +8722,7 @@ static SDValue getMemsetStores(SelectionDAG &DAG, const SDLoc &dl,
87218722
unsigned Limit = AlwaysInline ? ~0 : TLI.getMaxStoresPerMemset(OptSize);
87228723

87238724
if (!TLI.findOptimalMemOpLowering(
8724-
MemOps, Limit,
8725+
C, MemOps, Limit,
87258726
MemOp::Set(Size, DstAlignCanChange, Alignment, IsZeroVal, isVol),
87268727
DstPtrInfo.getAddrSpace(), ~0u, MF.getFunction().getAttributes()))
87278728
return SDValue();

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,14 @@ TargetLowering::makeLibCall(SelectionDAG &DAG, RTLIB::Libcall LC, EVT RetVT,
210210
}
211211

212212
bool TargetLowering::findOptimalMemOpLowering(
213-
std::vector<EVT> &MemOps, unsigned Limit, const MemOp &Op, unsigned DstAS,
214-
unsigned SrcAS, const AttributeList &FuncAttributes) const {
213+
LLVMContext &Context, std::vector<EVT> &MemOps, unsigned Limit,
214+
const MemOp &Op, unsigned DstAS, unsigned SrcAS,
215+
const AttributeList &FuncAttributes) const {
215216
if (Limit != ~unsigned(0) && Op.isMemcpyWithFixedDstAlign() &&
216217
Op.getSrcAlign() < Op.getDstAlign())
217218
return false;
218219

219-
EVT VT = getOptimalMemOpType(Op, FuncAttributes);
220+
EVT VT = getOptimalMemOpType(Context, Op, FuncAttributes);
220221

221222
if (VT == MVT::Other) {
222223
// Use the largest integer type whose alignment constraints are satisfied.

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17599,7 +17599,8 @@ bool AArch64TargetLowering::lowerInterleaveIntrinsicToStore(
1759917599
}
1760017600

1760117601
EVT AArch64TargetLowering::getOptimalMemOpType(
17602-
const MemOp &Op, const AttributeList &FuncAttributes) const {
17602+
LLVMContext &Context, const MemOp &Op,
17603+
const AttributeList &FuncAttributes) const {
1760317604
bool CanImplicitFloat = !FuncAttributes.hasFnAttr(Attribute::NoImplicitFloat);
1760417605
bool CanUseNEON = Subtarget->hasNEON() && CanImplicitFloat;
1760517606
bool CanUseFP = Subtarget->hasFPARMv8() && CanImplicitFloat;

llvm/lib/Target/AArch64/AArch64ISelLowering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ class AArch64TargetLowering : public TargetLowering {
233233

234234
bool shouldConsiderGEPOffsetSplit() const override;
235235

236-
EVT getOptimalMemOpType(const MemOp &Op,
236+
EVT getOptimalMemOpType(LLVMContext &Context, const MemOp &Op,
237237
const AttributeList &FuncAttributes) const override;
238238

239239
LLT getOptimalMemOpLLT(const MemOp &Op,

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1983,7 +1983,8 @@ bool SITargetLowering::allowsMisalignedMemoryAccesses(
19831983
}
19841984

19851985
EVT SITargetLowering::getOptimalMemOpType(
1986-
const MemOp &Op, const AttributeList &FuncAttributes) const {
1986+
LLVMContext &Context, const MemOp &Op,
1987+
const AttributeList &FuncAttributes) const {
19871988
// FIXME: Should account for address space here.
19881989

19891990
// The default fallback uses the private pointer size as a guess for a type to

llvm/lib/Target/AMDGPU/SIISelLowering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ class SITargetLowering final : public AMDGPUTargetLowering {
357357
MachineMemOperand::Flags Flags = MachineMemOperand::MONone,
358358
unsigned *IsFast = nullptr) const override;
359359

360-
EVT getOptimalMemOpType(const MemOp &Op,
360+
EVT getOptimalMemOpType(LLVMContext &Context, const MemOp &Op,
361361
const AttributeList &FuncAttributes) const override;
362362

363363
bool isMemOpHasNoClobberedMemOperand(const SDNode *N) const;

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19219,9 +19219,9 @@ bool ARMTargetLowering::allowsMisalignedMemoryAccesses(EVT VT, unsigned,
1921919219
return false;
1922019220
}
1922119221

19222-
1922319222
EVT ARMTargetLowering::getOptimalMemOpType(
19224-
const MemOp &Op, const AttributeList &FuncAttributes) const {
19223+
LLVMContext &Context, const MemOp &Op,
19224+
const AttributeList &FuncAttributes) const {
1922519225
// See if we can use NEON instructions for this...
1922619226
if ((Op.isMemcpy() || Op.isZeroMemset()) && Subtarget->hasNEON() &&
1922719227
!FuncAttributes.hasFnAttr(Attribute::NoImplicitFloat)) {

llvm/lib/Target/ARM/ARMISelLowering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ class VectorType;
472472
MachineMemOperand::Flags Flags,
473473
unsigned *Fast) const override;
474474

475-
EVT getOptimalMemOpType(const MemOp &Op,
475+
EVT getOptimalMemOpType(LLVMContext &Context, const MemOp &Op,
476476
const AttributeList &FuncAttributes) const override;
477477

478478
bool isTruncateFree(Type *SrcTy, Type *DstTy) const override;

llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,9 +1213,9 @@ int ARMTTIImpl::getNumMemOps(const IntrinsicInst *I) const {
12131213
// loaded and stored. That's why we multiply the number of elements by 2 to
12141214
// get the cost for this memcpy.
12151215
std::vector<EVT> MemOps;
1216-
if (getTLI()->findOptimalMemOpLowering(
1217-
MemOps, Limit, MOp, DstAddrSpace,
1218-
SrcAddrSpace, F->getAttributes()))
1216+
LLVMContext &C = F->getContext();
1217+
if (getTLI()->findOptimalMemOpLowering(C, MemOps, Limit, MOp, DstAddrSpace,
1218+
SrcAddrSpace, F->getAttributes()))
12191219
return MemOps.size() * Factor;
12201220

12211221
// If we can't find an optimal memop lowering, return the default cost

0 commit comments

Comments
 (0)