[PATCH] D37170: [TargetTransformInfo] Add a new public interface getInstructionCost

Guozhi Wei via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 25 16:34:53 PDT 2017


Carrot created this revision.

Current TargetTransformInfo can support throughput cost model, but sometimes we also need instruction latency and code size cost model in different optimizations. Hal suggested we need a single public interface to query the different cost of an instruction. So I proposed following interface:

  enum TargetCostKind {
    TCK_Throughput, ///< The traditional cost model, it actually
                    ///< means reciprocal throughputs.
    TCK_Latency,    ///< The latency of instruction.
    TCK_CodeSize    ///< Instruction code size.
  };
  
  int getInstructionCost(const Instruction *I, enum TargetCostKind kind) const;

All clients should mainly use this function to query the cost of an instruction, parameter <kind> specifies the desired cost model.

This patch also provides a simple default implementation of getInstructionSize and getInstructionLatency.

The default implementation of getInstructionSize returns 4 directly, it is enough for many RISC processors. But variable encoding targets should provide their own implementations.

The default getInstructionLatency provides latency numbers for only small number of instruction classes, those latency numbers are only reasonable for modern OOO processors. It can be extended in following ways:

- Add more detail into this function.
- Add getXXXLatency function and call it from here.
- Implement target specific getInstructionLatency function.


https://reviews.llvm.org/D37170

Files:
  include/llvm/Analysis/TargetTransformInfo.h
  include/llvm/Analysis/TargetTransformInfoImpl.h
  lib/Analysis/TargetTransformInfo.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37170.112755.patch
Type: text/x-patch
Size: 4411 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170825/1b0393a0/attachment.bin>


More information about the llvm-commits mailing list