Frage

Suppose that I have a function represented in LLVM IR and I want to estimate the number of cpu cycles that this function would take on my machine.

I know this is an information which is specific to the architecture, but I want to get a rough estimate of that for some planning purposes.

Is that possible to write a pass which iterates over the instructions in a function and returns the total number of cycles that these instructions would take ?

Would appreciate any ideas.

Thank you,

Kayhan

War es hilfreich?

Lösung

You might be interested in the CostModel analysis pass. It's a pass which uses the codegen to estimate the cost associated with each instruction - you can run it on each instruction in your function and sum up the values for a rough estimate of the entire function.

From the inline documentation:

This file defines the cost model analysis. It provides a very basic cost estimation for LLVM-IR. This analysis uses the services of the codegen to approximate the cost of any IR instruction when lowered to machine instructions. The cost results are unit-less and the cost number represents the throughput of the machine assuming that all loads hit the cache, all branches are predicted, etc. The cost numbers can be added in order to compare two or more transformation alternatives.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top