[LLVMdev] Using CostModel to estimate machine cycles of each instruction

Jonas Wagner jonas.wagner at epfl.ch
Fri Jul 18 01:13:07 PDT 2014


Hi Don,

In it's current version, tha pass can only be used via "opt -cost-model
-analyze". It will then print out the estimated cost for every instruction.

In order to be able to use it from a different pass, I split it into a
source and header file (attached).

You can then add it to your pass dependencies, and use it as follows:
custom::CostModelAnalysis &CM = getAnalysis<custom::CostModelAnalysis>();
Instruction *Inst = ...
unsigned Cost = CM.getInstructionCost(CI);
if (Cost != (unsigned)(-1)) {
  // do something
}

Hope this helps!
Jonas


On Thu, Jul 17, 2014 at 4:10 AM, <donney.blue at gmail.com> wrote:

> There is CostModel.cpp since LLVM3, I am wondering if anyone can give me
> an concrete example on how to use this pass to estimate cycles used in a
> given IR file.
>
> Thank you very much.
>
>
> Don
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140718/0a8b2f10/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CostModel.cpp
Type: text/x-c++src
Size: 15842 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140718/0a8b2f10/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CostModel.h
Type: text/x-chdr
Size: 916 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140718/0a8b2f10/attachment.h>


More information about the llvm-dev mailing list