Skip to content

Commit d2cf0bd

Browse files
committed
[RISCV] Add callback plumbing for getArithmeticInstrCost [nfc]
Most of the code for this was taken from https://reviews.llvm.org/D133552, with one bug fix by me. I'm landing the plumbing so that we can focus on the cost model pieces in the review.
1 parent 652713e commit d2cf0bd

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,40 @@ InstructionCost RISCVTTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val,
993993
return BaseCost + SlideCost;
994994
}
995995

996+
InstructionCost RISCVTTIImpl::getArithmeticInstrCost(
997+
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
998+
TTI::OperandValueInfo Op1Info, TTI::OperandValueInfo Op2Info,
999+
ArrayRef<const Value *> Args, const Instruction *CxtI) {
1000+
1001+
// TODO: Handle more cost kinds.
1002+
if (CostKind != TTI::TCK_RecipThroughput)
1003+
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info, Op2Info,
1004+
Args, CxtI);
1005+
1006+
if (isa<FixedVectorType>(Ty) && !ST->useRVVForFixedLengthVectors())
1007+
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info, Op2Info,
1008+
Args, CxtI);
1009+
1010+
// Skip if scalar size of Ty is bigger than ELEN.
1011+
if (isa<VectorType>(Ty) && Ty->getScalarSizeInBits() > ST->getELEN())
1012+
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info, Op2Info,
1013+
Args, CxtI);
1014+
1015+
// Legalize the type.
1016+
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Ty);
1017+
1018+
// TODO: Handle scalar type.
1019+
if (!LT.second.isVector())
1020+
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info, Op2Info,
1021+
Args, CxtI);
1022+
1023+
// TODO: Put a real cost model here, the plumbing change was landed without
1024+
// one to simplify review and fault isolation.
1025+
1026+
return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info, Op2Info,
1027+
Args, CxtI);
1028+
}
1029+
9961030
void RISCVTTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
9971031
TTI::UnrollingPreferences &UP,
9981032
OptimizationRemarkEmitter *ORE) {

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ class RISCVTTIImpl : public BasicTTIImplBase<RISCVTTIImpl> {
155155
InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val,
156156
unsigned Index);
157157

158+
InstructionCost getArithmeticInstrCost(
159+
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
160+
TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},
161+
TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},
162+
ArrayRef<const Value *> Args = ArrayRef<const Value *>(),
163+
const Instruction *CxtI = nullptr);
164+
158165
bool isElementTypeLegalForScalableVector(Type *Ty) const {
159166
return TLI->isLegalElementTypeForRVV(Ty);
160167
}

0 commit comments

Comments
 (0)