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.