Inspired by https://www.agner.org/optimize/instruction_tables.pdf, which gives us the latency and reciprocal throughput of each instruction in the different architecture of X86, Is there anybody taking the effort to do a similar job for LLVM IR?
There is no fixed latency/throughput to LLVM IR instructions. Instructions are lowered to target instructions based on the target and the subtarget, and these lowerings can have multiple IR instructions coalesced into a single target instruction or one IR instruction split into several instructions. Latency/throughput is provided for target instructions based on the *Schedule.td files, but there is no easy mapping between these instructions and LLVM IR. Some ad-hoc estimation for the IR level is provided by TargetLowering and especially TargetTransformInfo, but these do not provide complete coverage and only provide coarse estimates.
It sounds like you might be interested in llvm’s Machine Code Analyzer. It’s an llvm tool that can calculate reciprocal throughput by simulating an out-of-order instruction pipeline. It also provides other useful cycle information:
Your question asks about IR. llvm-mca currently only works on assembly. However, you can easily generate assembly from IR or make use of MCA as a library. I suggest just converting your IR to assembly and running that through llvm-mca.
MCA is built on LLVM instruction scheduling information which contains cycle latency information. If you’re curious of what that data looks like, outside of MCA, take a peek at the X86 instruction scheduling information located around: ‘llvm/lib/Target/X86/X86Schedule.td’
We have an interface for estimating this, although it depends on the targets providing appropriate information through the TargetTransformInfo interface.
Call TTI->getInstructionCost with the kind parameter set to TCK_Latency.
Am i correct in assuming that the cost returned from this function is for the current compiled hardware? Also is there any way for me to get the same information for other targets?
I am just a beginner at LLVM so any help will be appreciated!