Skip to content

Commit a127c4a

Browse files
committed
[TargetLowering] Change getOptimalMemOpType and findOptimalMemOpLowering to take LLVM Context
1 parent 4aa23cc commit a127c4a

23 files changed

+56
-42
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
}
@@ -4118,8 +4118,9 @@ class LLVM_ABI TargetLowering : public TargetLoweringBase {
41184118
/// It returns the types of the sequence of memory ops to perform
41194119
/// memset / memcpy by reference.
41204120
virtual bool
4121-
findOptimalMemOpLowering(std::vector<EVT> &MemOps, unsigned Limit,
4122-
const MemOp &Op, unsigned DstAS, unsigned SrcAS,
4121+
findOptimalMemOpLowering(LLVMContext &Context, std::vector<EVT> &MemOps,
4122+
unsigned Limit, const MemOp &Op, unsigned DstAS,
4123+
unsigned SrcAS,
41234124
const AttributeList &FuncAttributes) const;
41244125

41254126
/// 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
@@ -17593,7 +17593,8 @@ bool AArch64TargetLowering::lowerInterleaveIntrinsicToStore(
1759317593
}
1759417594

1759517595
EVT AArch64TargetLowering::getOptimalMemOpType(
17596-
const MemOp &Op, const AttributeList &FuncAttributes) const {
17596+
LLVMContext &Context, const MemOp &Op,
17597+
const AttributeList &FuncAttributes) const {
1759717598
bool CanImplicitFloat = !FuncAttributes.hasFnAttr(Attribute::NoImplicitFloat);
1759817599
bool CanUseNEON = Subtarget->hasNEON() && CanImplicitFloat;
1759917600
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
@@ -19242,9 +19242,9 @@ bool ARMTargetLowering::allowsMisalignedMemoryAccesses(EVT VT, unsigned,
1924219242
return false;
1924319243
}
1924419244

19245-
1924619245
EVT ARMTargetLowering::getOptimalMemOpType(
19247-
const MemOp &Op, const AttributeList &FuncAttributes) const {
19246+
LLVMContext &Context, const MemOp &Op,
19247+
const AttributeList &FuncAttributes) const {
1924819248
// See if we can use NEON instructions for this...
1924919249
if ((Op.isMemcpy() || Op.isZeroMemset()) && Subtarget->hasNEON() &&
1925019250
!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)