[PATCH] D59252: [TTI] getMemcpyCost
Sjoerd Meijer via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 12 06:59:34 PDT 2019
SjoerdMeijer created this revision.
SjoerdMeijer added reviewers: RKSimon, efriedma, samparker, dmgreen.
Non-functional change that adds getMemcpyCost to TTI, so that the
cost of a memcpy instruction can be modeled and queried.
https://reviews.llvm.org/D59252
Files:
include/llvm/Analysis/TargetTransformInfo.h
include/llvm/Analysis/TargetTransformInfoImpl.h
Index: include/llvm/Analysis/TargetTransformInfoImpl.h
===================================================================
--- include/llvm/Analysis/TargetTransformInfoImpl.h
+++ include/llvm/Analysis/TargetTransformInfoImpl.h
@@ -140,15 +140,22 @@
unsigned getInliningThresholdMultiplier() { return 1; }
+ unsigned getMemcpyCost(const Instruction *I) {
+ return TTI::TCC_Basic;
+ }
+
unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,
ArrayRef<Type *> ParamTys, const User *U) {
switch (IID) {
default:
// Intrinsics rarely (if ever) have normal argument setup constraints.
// Model them as having a basic instruction cost.
- // FIXME: This is wrong for libc intrinsics.
return TTI::TCC_Basic;
+ // TODO: other libc intrinsics.
+ case Intrinsic::memcpy:
+ return getMemcpyCost(dyn_cast<Instruction>(U));
+
case Intrinsic::annotation:
case Intrinsic::assume:
case Intrinsic::sideeffect:
Index: include/llvm/Analysis/TargetTransformInfo.h
===================================================================
--- include/llvm/Analysis/TargetTransformInfo.h
+++ include/llvm/Analysis/TargetTransformInfo.h
@@ -246,6 +246,10 @@
ArrayRef<const Value *> Arguments,
const User *U = nullptr) const;
+ /// \Return the expected cost of a memcpy, which could e.g. depend on the
+ /// source/destination type and alignment and the number of bytes copied.
+ int getMemcpyCost(const Instruction *I) const;
+
/// \return The estimated number of case clusters when lowering \p 'SI'.
/// \p JTSize Set a jump table size only when \p SI is suitable for a jump
/// table.
@@ -1053,6 +1057,7 @@
virtual int getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,
ArrayRef<const Value *> Arguments,
const User *U) = 0;
+ virtual int getMemcpyCost(const Instruction *I) = 0;
virtual unsigned getEstimatedNumberOfCaseClusters(const SwitchInst &SI,
unsigned &JTSize) = 0;
virtual int
@@ -1267,6 +1272,9 @@
const User *U = nullptr) override {
return Impl.getIntrinsicCost(IID, RetTy, Arguments, U);
}
+ int getMemcpyCost(const Instruction *I) {
+ return Impl.getMemcpyCost(I);
+ }
int getUserCost(const User *U, ArrayRef<const Value *> Operands) override {
return Impl.getUserCost(U, Operands);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59252.190249.patch
Type: text/x-patch
Size: 2516 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190312/de33f6a0/attachment.bin>
More information about the llvm-commits
mailing list