Skip to content

Commit 7b75f40

Browse files
committed
[TTI] Use MemIntrinsicCostAttributes for getExpandCompressMemoryOpCost
- Following from llvm#168029. This is a step toward a unified interface for masked/gather-scatter/strided/expand-compress cost modeling. - Replace the ad-hoc parameter list with a single attributes object. API change: ``` - InstructionCost getExpandCompressMemoryOpCost(Opcode, DataTy, - VariableMask, Alignment, - CostKind, Inst); + InstructionCost getExpandCompressMemoryOpCost(MemIntrinsicCostAttributes, + CostKind); ``` Notes: - NFCI intended: callers populate MemIntrinsicCostAttributes with same information as before.
1 parent 961940e commit 7b75f40

File tree

6 files changed

+46
-33
lines changed

6 files changed

+46
-33
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,20 @@ struct HardwareLoopInfo {
125125

126126
/// Information for memory intrinsic cost model.
127127
class MemIntrinsicCostAttributes {
128+
/// Optional context instruction, if one exists, e.g. the
129+
/// load/store to transform to the intrinsic.
130+
const Instruction *I = nullptr;
131+
128132
/// Vector type of the data to be loaded or stored.
129133
Type *DataTy = nullptr;
130134

131135
/// ID of the memory intrinsic.
132136
Intrinsic::ID IID;
133137

138+
/// True when the memory access is predicated with a mask
139+
/// that is not a compile-time constant.
140+
bool VariableMask = true;
141+
134142
/// Address space of the pointer.
135143
unsigned AddressSpace = 0;
136144

@@ -143,8 +151,16 @@ class MemIntrinsicCostAttributes {
143151
: DataTy(DataTy), IID(Id), AddressSpace(AddressSpace),
144152
Alignment(Alignment) {}
145153

154+
LLVM_ABI MemIntrinsicCostAttributes(Intrinsic::ID Id, Type *DataTy,
155+
bool VariableMask, Align Alignment,
156+
const Instruction *I = nullptr)
157+
: I(I), DataTy(DataTy), IID(Id), VariableMask(VariableMask),
158+
Alignment(Alignment) {}
159+
146160
Intrinsic::ID getID() const { return IID; }
161+
const Instruction *getInst() const { return I; }
147162
Type *getDataType() const { return DataTy; }
163+
bool getVariableMask() const { return VariableMask; }
148164
unsigned getAddressSpace() const { return AddressSpace; }
149165
Align getAlignment() const { return Alignment; }
150166
};
@@ -1600,17 +1616,9 @@ class TargetTransformInfo {
16001616
const Instruction *I = nullptr) const;
16011617

16021618
/// \return The cost of Expand Load or Compress Store operation
1603-
/// \p Opcode - is a type of memory access Load or Store
1604-
/// \p Src - a vector type of the data to be loaded or stored
1605-
/// \p VariableMask - true when the memory access is predicated with a mask
1606-
/// that is not a compile-time constant
1607-
/// \p Alignment - alignment of single element
1608-
/// \p I - the optional original context instruction, if one exists, e.g. the
1609-
/// load/store to transform or the call to the gather/scatter intrinsic
16101619
LLVM_ABI InstructionCost getExpandCompressMemoryOpCost(
1611-
unsigned Opcode, Type *DataTy, bool VariableMask, Align Alignment,
1612-
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
1613-
const Instruction *I = nullptr) const;
1620+
const MemIntrinsicCostAttributes &MICA,
1621+
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput) const;
16141622

16151623
/// \return The cost of strided memory operations.
16161624
/// \p Opcode - is a type of memory access Load or Store

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -855,9 +855,9 @@ class TargetTransformInfoImplBase {
855855
return 1;
856856
}
857857

858-
virtual InstructionCost getExpandCompressMemoryOpCost(
859-
unsigned Opcode, Type *DataTy, bool VariableMask, Align Alignment,
860-
TTI::TargetCostKind CostKind, const Instruction *I = nullptr) const {
858+
virtual InstructionCost
859+
getExpandCompressMemoryOpCost(const MemIntrinsicCostAttributes &MICA,
860+
TTI::TargetCostKind CostKind) const {
861861
return 1;
862862
}
863863

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,10 +1580,14 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
15801580
}
15811581

15821582
InstructionCost
1583-
getExpandCompressMemoryOpCost(unsigned Opcode, Type *DataTy,
1584-
bool VariableMask, Align Alignment,
1585-
TTI::TargetCostKind CostKind,
1586-
const Instruction *I = nullptr) const override {
1583+
getExpandCompressMemoryOpCost(const MemIntrinsicCostAttributes &MICA,
1584+
TTI::TargetCostKind CostKind) const override {
1585+
unsigned Opcode = MICA.getID() == Intrinsic::masked_expandload
1586+
? Instruction::Load
1587+
: Instruction::Store;
1588+
Type *DataTy = MICA.getDataType();
1589+
bool VariableMask = MICA.getVariableMask();
1590+
Align Alignment = MICA.getAlignment();
15871591
// Treat expand load/compress store as gather/scatter operation.
15881592
// TODO: implement more precise cost estimation for these intrinsics.
15891593
return getCommonMaskedMemoryOpCost(Opcode, DataTy, Alignment, VariableMask,
@@ -1964,15 +1968,13 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
19641968
const Value *Mask = Args[2];
19651969
Align Alignment = I->getParamAlign(1).valueOrOne();
19661970
return thisT()->getExpandCompressMemoryOpCost(
1967-
Instruction::Store, Data->getType(), !isa<Constant>(Mask), Alignment,
1968-
CostKind, I);
1971+
{IID, Data->getType(), !isa<Constant>(Mask), Alignment, I}, CostKind);
19691972
}
19701973
case Intrinsic::masked_expandload: {
19711974
const Value *Mask = Args[1];
19721975
Align Alignment = I->getParamAlign(0).valueOrOne();
1973-
return thisT()->getExpandCompressMemoryOpCost(Instruction::Load, RetTy,
1974-
!isa<Constant>(Mask),
1975-
Alignment, CostKind, I);
1976+
return thisT()->getExpandCompressMemoryOpCost(
1977+
{IID, RetTy, !isa<Constant>(Mask), Alignment, I}, CostKind);
19761978
}
19771979
case Intrinsic::experimental_vp_strided_store: {
19781980
const Value *Data = Args[0];

llvm/lib/Analysis/TargetTransformInfo.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,10 +1201,9 @@ InstructionCost TargetTransformInfo::getGatherScatterOpCost(
12011201
}
12021202

12031203
InstructionCost TargetTransformInfo::getExpandCompressMemoryOpCost(
1204-
unsigned Opcode, Type *DataTy, bool VariableMask, Align Alignment,
1205-
TTI::TargetCostKind CostKind, const Instruction *I) const {
1206-
InstructionCost Cost = TTIImpl->getExpandCompressMemoryOpCost(
1207-
Opcode, DataTy, VariableMask, Alignment, CostKind, I);
1204+
const MemIntrinsicCostAttributes &MICA,
1205+
TTI::TargetCostKind CostKind) const {
1206+
InstructionCost Cost = TTIImpl->getExpandCompressMemoryOpCost(MICA, CostKind);
12081207
assert(Cost >= 0 && "TTI should not produce negative costs!");
12091208
return Cost;
12101209
}

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,15 +1146,20 @@ InstructionCost RISCVTTIImpl::getGatherScatterOpCost(
11461146
}
11471147

11481148
InstructionCost RISCVTTIImpl::getExpandCompressMemoryOpCost(
1149-
unsigned Opcode, Type *DataTy, bool VariableMask, Align Alignment,
1150-
TTI::TargetCostKind CostKind, const Instruction *I) const {
1149+
const MemIntrinsicCostAttributes &MICA,
1150+
TTI::TargetCostKind CostKind) const {
1151+
unsigned Opcode = MICA.getID() == Intrinsic::masked_expandload
1152+
? Instruction::Load
1153+
: Instruction::Store;
1154+
Type *DataTy = MICA.getDataType();
1155+
bool VariableMask = MICA.getVariableMask();
1156+
Align Alignment = MICA.getAlignment();
11511157
bool IsLegal = (Opcode == Instruction::Store &&
11521158
isLegalMaskedCompressStore(DataTy, Alignment)) ||
11531159
(Opcode == Instruction::Load &&
11541160
isLegalMaskedExpandLoad(DataTy, Alignment));
11551161
if (!IsLegal || CostKind != TTI::TCK_RecipThroughput)
1156-
return BaseT::getExpandCompressMemoryOpCost(Opcode, DataTy, VariableMask,
1157-
Alignment, CostKind, I);
1162+
return BaseT::getExpandCompressMemoryOpCost(MICA, CostKind);
11581163
// Example compressstore sequence:
11591164
// vsetivli zero, 8, e32, m2, ta, ma (ignored)
11601165
// vcompress.vm v10, v8, v0

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,8 @@ class RISCVTTIImpl final : public BasicTTIImplBase<RISCVTTIImpl> {
197197
const Instruction *I) const override;
198198

199199
InstructionCost
200-
getExpandCompressMemoryOpCost(unsigned Opcode, Type *Src, bool VariableMask,
201-
Align Alignment, TTI::TargetCostKind CostKind,
202-
const Instruction *I = nullptr) const override;
200+
getExpandCompressMemoryOpCost(const MemIntrinsicCostAttributes &MICA,
201+
TTI::TargetCostKind CostKind) const override;
203202

204203
InstructionCost getStridedMemoryOpCost(unsigned Opcode, Type *DataTy,
205204
const Value *Ptr, bool VariableMask,

0 commit comments

Comments
 (0)