diff options
author | Nadav Rotem <nrotem@apple.com> | 2012-10-24 17:22:41 +0000 |
---|---|---|
committer | Nadav Rotem <nrotem@apple.com> | 2012-10-24 17:22:41 +0000 |
commit | 270483466124fe1e19d5439e958fef63cebd43cd (patch) | |
tree | 8aa10bb526f940d3553d573ab23532e1554a9b3d /include | |
parent | c0a14b86f7ad334c2a557c1ee4fff12e8d396fd0 (diff) | |
download | external_llvm-270483466124fe1e19d5439e958fef63cebd43cd.zip external_llvm-270483466124fe1e19d5439e958fef63cebd43cd.tar.gz external_llvm-270483466124fe1e19d5439e958fef63cebd43cd.tar.bz2 |
Implement a basic VectorTargetTransformInfo interface to be used by the loop and bb vectorizers for modeling the cost of instructions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166593 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Target/TargetTransformImpl.h | 18 | ||||
-rw-r--r-- | include/llvm/TargetTransformInfo.h | 41 |
2 files changed, 55 insertions, 4 deletions
diff --git a/include/llvm/Target/TargetTransformImpl.h b/include/llvm/Target/TargetTransformImpl.h index 7648f4f..ec39f99 100644 --- a/include/llvm/Target/TargetTransformImpl.h +++ b/include/llvm/Target/TargetTransformImpl.h @@ -47,7 +47,23 @@ public: virtual unsigned getJumpBufSize() const; }; -class VectorTargetTransformImpl : public VectorTargetTransformInfo { }; +class VectorTargetTransformImpl : public VectorTargetTransformInfo { +private: + const TargetLowering *TLI; + +public: + explicit VectorTargetTransformImpl(const TargetLowering *TL) : TLI(TL) {} + + virtual ~VectorTargetTransformImpl() {} + + virtual unsigned getInstrCost(unsigned Opcode, Type *Ty1, Type *Ty2) const; + + virtual unsigned getBroadcastCost(Type *Tp) const; + + virtual unsigned getMemoryOpCost(unsigned Opcode, Type *Src, + unsigned Alignment, + unsigned AddressSpace) const; +}; } // end llvm namespace diff --git a/include/llvm/TargetTransformInfo.h b/include/llvm/TargetTransformInfo.h index 82fc14d..96470c3 100644 --- a/include/llvm/TargetTransformInfo.h +++ b/include/llvm/TargetTransformInfo.h @@ -54,10 +54,10 @@ public: TargetTransformInfo(const TargetTransformInfo &T) : ImmutablePass(ID), STTI(T.STTI), VTTI(T.VTTI) { } - const ScalarTargetTransformInfo* getScalarTargetTransformInfo() { + const ScalarTargetTransformInfo* getScalarTargetTransformInfo() const { return STTI; } - const VectorTargetTransformInfo* getVectorTargetTransformInfo() { + const VectorTargetTransformInfo* getVectorTargetTransformInfo() const { return VTTI; } @@ -119,8 +119,43 @@ public: } }; +/// VectorTargetTransformInfo - This interface is used by the vectorizers +/// to estimate the profitability of vectorization for different instructions. class VectorTargetTransformInfo { - // TODO: define an interface for VectorTargetTransformInfo. +public: + virtual ~VectorTargetTransformInfo() {} + + /// Returns the expected cost of the instruction opcode. The opcode is one of + /// the enums like Instruction::Add. The type arguments are the type of the + /// operation. + /// Most instructions only use the first type and in that case the second + /// operand is ignored. + /// + /// Exceptions: + /// * Br instructions do not use any of the types. + /// * Select instructions pass the return type as Ty1 and the selector as Ty2. + /// * Cast instructions pass the destination as Ty1 and the source as Ty2. + /// * Insert/Extract element pass only the vector type as Ty1. + /// * ShuffleVector, Load, Store do not use this call. + virtual unsigned getInstrCost(unsigned Opcode, + Type *Ty1 = 0, + Type *Ty2 = 0) const { + return 1; + } + + /// Returns the cost of a vector broadcast of a scalar at place zero to a + /// vector of type 'Tp'. + virtual unsigned getBroadcastCost(Type *Tp) const { + return 1; + } + + /// Returns the cost of Load and Store instructions. + virtual unsigned getMemoryOpCost(unsigned Opcode, Type *Src, + unsigned Alignment, + unsigned AddressSpace) const { + return 1; + } + }; } // End llvm namespace |