[llvm] 5cd4271 - [TTI] Start process of merging OperandValueKind and OperandValueProperties [nfc]
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 22 09:49:11 PDT 2022
Author: Philip Reames
Date: 2022-08-22T09:48:15-07:00
New Revision: 5cd427106dd25949b716639c9c1e6559f77fb697
URL: https://github.com/llvm/llvm-project/commit/5cd427106dd25949b716639c9c1e6559f77fb697
DIFF: https://github.com/llvm/llvm-project/commit/5cd427106dd25949b716639c9c1e6559f77fb697.diff
LOG: [TTI] Start process of merging OperandValueKind and OperandValueProperties [nfc]
OperandValueKind and OperandValueProperties both provide facts about the operands of an instruction for purposes of cost modeling. We've discussed merging them several times; before I plumb through more flags, let's go ahead and do so.
This change only adds the client side interface for getArithmeticInstrCost and makes a couple of minor changes in client code to prove that it works. Target TTI implementations still use the split flags. I'm deliberately splitting what could be one big change into a series of smaller ones so that I can lean on the compiler to catch errors along the way.
Added:
Modified:
llvm/include/llvm/Analysis/TargetTransformInfo.h
llvm/lib/Analysis/TargetTransformInfo.cpp
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/TargetTransformInfo.h b/llvm/include/llvm/Analysis/TargetTransformInfo.h
index 4dffc3a36a578..1c61677dba0ef 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfo.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfo.h
@@ -900,6 +900,14 @@ class TargetTransformInfo {
/// Additional properties of an operand's values.
enum OperandValueProperties { OP_None = 0, OP_PowerOf2 = 1 };
+ // Describe the values an operand can take. We're in the process
+ // of migrating uses of OperandValueKind and OperandValueProperties
+ // to use this class, and then will change the internal representation.
+ struct OperandValueInfo {
+ OperandValueKind Kind;
+ OperandValueProperties Properties;
+ };
+
/// \return the number of registers in the target-provided register class.
unsigned getNumberOfRegisters(unsigned ClassID) const;
@@ -1056,14 +1064,22 @@ class TargetTransformInfo {
/// provide even more information.
InstructionCost getArithmeticInstrCost(
unsigned Opcode, Type *Ty,
- TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
- OperandValueKind Opd1Info = OK_AnyValue,
+ TTI::TargetCostKind CostKind,
+ OperandValueKind Opd1Info,
OperandValueKind Opd2Info = OK_AnyValue,
OperandValueProperties Opd1PropInfo = OP_None,
OperandValueProperties Opd2PropInfo = OP_None,
ArrayRef<const Value *> Args = ArrayRef<const Value *>(),
const Instruction *CxtI = nullptr) const;
+ InstructionCost getArithmeticInstrCost(
+ unsigned Opcode, Type *Ty,
+ TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
+ TTI::OperandValueInfo Opd1Info = {TTI::OK_AnyValue, TTI::OP_None},
+ TTI::OperandValueInfo Opd2Info = {TTI::OK_AnyValue, TTI::OP_None},
+ ArrayRef<const Value *> Args = ArrayRef<const Value *>(),
+ const Instruction *CxtI = nullptr) const;
+
/// \return The cost of a shuffle instruction of kind Kind and of type Tp.
/// The exact mask may be passed as Mask, or else the array will be empty.
/// The index and subtype parameters are used by the subvector insertion and
@@ -1719,6 +1735,11 @@ class TargetTransformInfo::Concept {
OperandValueKind Opd1Info, OperandValueKind Opd2Info,
OperandValueProperties Opd1PropInfo, OperandValueProperties Opd2PropInfo,
ArrayRef<const Value *> Args, const Instruction *CxtI = nullptr) = 0;
+ virtual InstructionCost getArithmeticInstrCost(
+ unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
+ OperandValueInfo Op1Info, OperandValueInfo Op2Info,
+ ArrayRef<const Value *> Args, const Instruction *CxtI = nullptr) = 0;
+
virtual InstructionCost getShuffleCost(ShuffleKind Kind, VectorType *Tp,
ArrayRef<int> Mask,
TTI::TargetCostKind CostKind,
@@ -2273,6 +2294,18 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
return Impl.getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info, Opd2Info,
Opd1PropInfo, Opd2PropInfo, Args, CxtI);
}
+
+ InstructionCost getArithmeticInstrCost(
+ unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
+ OperandValueInfo Opd1Info, OperandValueInfo Opd2Info,
+ ArrayRef<const Value *> Args,
+ const Instruction *CxtI = nullptr) override {
+ return Impl.getArithmeticInstrCost(Opcode, Ty, CostKind,
+ Opd1Info.Kind, Opd2Info.Kind,
+ Opd1Info.Properties, Opd2Info.Properties,
+ Args, CxtI);
+ }
+
InstructionCost getShuffleCost(ShuffleKind Kind, VectorType *Tp,
ArrayRef<int> Mask,
TTI::TargetCostKind CostKind, int Index,
diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp
index c81b8ba6e7857..057562e613c7a 100644
--- a/llvm/lib/Analysis/TargetTransformInfo.cpp
+++ b/llvm/lib/Analysis/TargetTransformInfo.cpp
@@ -784,6 +784,19 @@ InstructionCost TargetTransformInfo::getArithmeticInstrCost(
return Cost;
}
+InstructionCost TargetTransformInfo::getArithmeticInstrCost(
+ unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
+ OperandValueInfo Op1Info, OperandValueInfo Op2Info,
+ ArrayRef<const Value *> Args, const Instruction *CxtI) const {
+ InstructionCost Cost =
+ TTIImpl->getArithmeticInstrCost(Opcode, Ty, CostKind,
+ Op1Info.Kind, Op2Info.Kind,
+ Op1Info.Properties, Op2Info.Properties,
+ Args, CxtI);
+ assert(Cost >= 0 && "TTI should not produce negative costs!");
+ return Cost;
+}
+
InstructionCost TargetTransformInfo::getShuffleCost(
ShuffleKind Kind, VectorType *Ty, ArrayRef<int> Mask,
TTI::TargetCostKind CostKind, int Index, VectorType *SubTp,
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 84ea2b14a3d62..23f63f36646cf 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -7119,14 +7119,16 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, ElementCount VF,
SmallVector<const Value *, 4> Operands(I->operand_values());
return TTI.getArithmeticInstrCost(
- I->getOpcode(), VectorTy, CostKind, TargetTransformInfo::OK_AnyValue,
- Op2VK, TargetTransformInfo::OP_None, Op2VP, Operands, I);
+ I->getOpcode(), VectorTy, CostKind,
+ {TargetTransformInfo::OK_AnyValue, TargetTransformInfo::OP_None},
+ {Op2VK, Op2VP}, Operands, I);
}
case Instruction::FNeg: {
return TTI.getArithmeticInstrCost(
- I->getOpcode(), VectorTy, CostKind, TargetTransformInfo::OK_AnyValue,
- TargetTransformInfo::OK_AnyValue, TargetTransformInfo::OP_None,
- TargetTransformInfo::OP_None, I->getOperand(0), I);
+ I->getOpcode(), VectorTy, CostKind,
+ {TargetTransformInfo::OK_AnyValue, TargetTransformInfo::OP_None},
+ {TargetTransformInfo::OK_AnyValue, TargetTransformInfo::OP_None},
+ I->getOperand(0), I);
}
case Instruction::Select: {
SelectInst *SI = cast<SelectInst>(I);
@@ -7149,7 +7151,7 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, ElementCount VF,
SmallVector<const Value *, 2> Operands{Op0, Op1};
return TTI.getArithmeticInstrCost(
match(I, m_LogicalOr()) ? Instruction::Or : Instruction::And, VectorTy,
- CostKind, Op1VK, Op2VK, Op1VP, Op2VP, Operands, I);
+ CostKind, {Op1VK, Op1VP}, {Op2VK, Op2VP}, Operands, I);
}
Type *CondTy = SI->getCondition()->getType();
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 0a235c8720fce..7d623b0297b9c 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -6409,8 +6409,9 @@ InstructionCost BoUpSLP::getEntryCost(const TreeEntry *E,
SmallVector<const Value *, 4> Operands(VL0->operand_values());
InstructionCost ScalarEltCost =
- TTI->getArithmeticInstrCost(E->getOpcode(), ScalarTy, CostKind, Op1VK,
- Op2VK, Op1VP, Op2VP, Operands, VL0);
+ TTI->getArithmeticInstrCost(E->getOpcode(), ScalarTy, CostKind,
+ {Op1VK, Op1VP}, {Op2VK, Op2VP},
+ Operands, VL0);
if (NeedToShuffleReuses) {
CommonCost -= (EntryVF - VL.size()) * ScalarEltCost;
}
@@ -6422,8 +6423,9 @@ InstructionCost BoUpSLP::getEntryCost(const TreeEntry *E,
Operands[I] = ConstantVector::getNullValue(VecTy);
}
InstructionCost VecCost =
- TTI->getArithmeticInstrCost(E->getOpcode(), VecTy, CostKind, Op1VK,
- Op2VK, Op1VP, Op2VP, Operands, VL0);
+ TTI->getArithmeticInstrCost(E->getOpcode(), VecTy, CostKind,
+ {Op1VK, Op1VP}, {Op2VK, Op2VP},
+ Operands, VL0);
LLVM_DEBUG(dumpTreeCosts(E, CommonCost, VecCost, ScalarCost));
return CommonCost + VecCost - ScalarCost;
}
More information about the llvm-commits
mailing list