[llvm-dev] Fwd: How to use CostModel?

Stephen Thomas stephen.warner.thomas at gmail.com
Wed Aug 5 07:54:21 PDT 2015


Sorry if double posted... might have sent this to old mailing list
address...

---------- Forwarded message ----------
From: Stephen Thomas <stephen.warner.thomas at gmail.com>
Date: Wed, Aug 5, 2015 at 10:39 AM
Subject: How to use CostModel?
To: LLVM Dev <llvmdev at cs.uiuc.edu>


Hi,

I'm trying to use the built-in CostModel class to estimate the number of
machine instructions for each IR Instruction. To get a feel for what kind
of output the CostModel pass gives, I ran it on the command line like so:

$ cat test.c
int main(){
    int r = rand();
    if (r > 1){
        return ++r;
    }
    return r*86;
}

$ clang-3.6 -S -emit-llvm test.c -o test.bc

$ opt-3.6  -analyze -targetlibinfo -cost-model ./test.bc
Printing analysis 'Target Library Information':
Pass::print not implemented for pass: 'Target Library Information'!
Printing analysis 'Cost Model Analysis' for function 'main':
Cost Model: Unknown cost for instruction:   %1 = alloca i32, align 4
Cost Model: Unknown cost for instruction:   %r = alloca i32, align 4
Cost Model: Found an estimated cost of 1 for instruction:   store i32 0,
i32* %1
Cost Model: Unknown cost for instruction:   %2 = call i32 (...)* @rand()
Cost Model: Found an estimated cost of 1 for instruction:   store i32 %2,
i32* %r, align 4
Cost Model: Found an estimated cost of 1 for instruction:   %3 = load i32*
%r, align 4
Cost Model: Found an estimated cost of 1 for instruction:   %4 = icmp sgt
i32 %3, 1
Cost Model: Found an estimated cost of 0 for instruction:   br i1 %4, label
%5, label %8
Cost Model: Found an estimated cost of 1 for instruction:   %6 = load i32*
%r, align 4
Cost Model: Found an estimated cost of 1 for instruction:   %7 = add nsw
i32 %6, 1
Cost Model: Found an estimated cost of 1 for instruction:   store i32 %7,
i32* %r, align 4
Cost Model: Found an estimated cost of 1 for instruction:   store i32 %7,
i32* %1
Cost Model: Found an estimated cost of 0 for instruction:   br label %11
Cost Model: Found an estimated cost of 1 for instruction:   %9 = load i32*
%r, align 4
Cost Model: Found an estimated cost of 1 for instruction:   %10 = mul nsw
i32 %9, 86
Cost Model: Found an estimated cost of 1 for instruction:   store i32 %10,
i32* %1
Cost Model: Found an estimated cost of 0 for instruction:   br label %11
Cost Model: Found an estimated cost of 1 for instruction:   %12 = load i32*
%1
Cost Model: Found an estimated cost of 0 for instruction:   ret i32 %12


Is it expected to only have 1s and 0s output? Also, what target
architecture is being used for the estimations? (Is it auto detecting the
architecture I'm on?)


Thanks,
Steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150805/ebffcedc/attachment-0001.html>


More information about the llvm-dev mailing list