<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 5, 2015, at 7:54 AM, Stephen Thomas <<a href="mailto:stephen.warner.thomas@gmail.com" class="">stephen.warner.thomas@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><span style="font-size:12.8000001907349px" class="">Sorry if double posted... might have sent this to old mailing list address...<br class=""></span><br class=""><div class="gmail_quote">---------- Forwarded message ----------<br class="">From: <b class="gmail_sendername">Stephen Thomas</b> <span dir="ltr" class=""><<a href="mailto:stephen.warner.thomas@gmail.com" class="">stephen.warner.thomas@gmail.com</a>></span><br class="">Date: Wed, Aug 5, 2015 at 10:39 AM<br class="">Subject: How to use CostModel?<br class="">To: LLVM Dev <<a href="mailto:llvmdev@cs.uiuc.edu" class="">llvmdev@cs.uiuc.edu</a>><br class=""><br class=""><br class=""><div dir="ltr" class="">Hi,<div class=""><br class=""></div><div class="">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:</div><div class=""><br class=""></div><div class=""><div class="">$ cat test.c </div><div class="">int main(){</div><div class=""> int r = rand();</div><div class=""> if (r > 1){</div><div class=""> return ++r;</div><div class=""> }</div><div class=""> return r*86;</div><div class="">}</div><div class=""><br class=""></div><div class="">$ clang-3.6 -S -emit-llvm test.c -o test.bc</div><div class=""><br class=""></div><div class="">$ opt-3.6 -analyze -targetlibinfo -cost-model ./test.bc</div><div class="">Printing analysis 'Target Library Information':</div><div class="">Pass::print not implemented for pass: 'Target Library Information'!</div><div class="">Printing analysis 'Cost Model Analysis' for function 'main':</div><div class="">Cost Model: Unknown cost for instruction: %1 = alloca i32, align 4</div><div class="">Cost Model: Unknown cost for instruction: %r = alloca i32, align 4</div><div class="">Cost Model: Found an estimated cost of 1 for instruction: store i32 0, i32* %1</div><div class="">Cost Model: Unknown cost for instruction: %2 = call i32 (...)* @rand()</div><div class="">Cost Model: Found an estimated cost of 1 for instruction: store i32 %2, i32* %r, align 4</div><div class="">Cost Model: Found an estimated cost of 1 for instruction: %3 = load i32* %r, align 4</div><div class="">Cost Model: Found an estimated cost of 1 for instruction: %4 = icmp sgt i32 %3, 1</div><div class="">Cost Model: Found an estimated cost of 0 for instruction: br i1 %4, label %5, label %8</div><div class="">Cost Model: Found an estimated cost of 1 for instruction: %6 = load i32* %r, align 4</div><div class="">Cost Model: Found an estimated cost of 1 for instruction: %7 = add nsw i32 %6, 1</div><div class="">Cost Model: Found an estimated cost of 1 for instruction: store i32 %7, i32* %r, align 4</div><div class="">Cost Model: Found an estimated cost of 1 for instruction: store i32 %7, i32* %1</div><div class="">Cost Model: Found an estimated cost of 0 for instruction: br label %11</div><div class="">Cost Model: Found an estimated cost of 1 for instruction: %9 = load i32* %r, align 4</div><div class="">Cost Model: Found an estimated cost of 1 for instruction: %10 = mul nsw i32 %9, 86</div><div class="">Cost Model: Found an estimated cost of 1 for instruction: store i32 %10, i32* %1</div><div class="">Cost Model: Found an estimated cost of 0 for instruction: br label %11</div><div class="">Cost Model: Found an estimated cost of 1 for instruction: %12 = load i32* %1</div><div class="">Cost Model: Found an estimated cost of 0 for instruction: ret i32 %12</div></div><div class=""><br class=""></div></div></div></div></div></blockquote><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_quote"><div dir="ltr" class=""><div class=""><br class=""></div><div class="">Is it expected to only have 1s and 0s output?</div></div></div></div></div></blockquote><div><br class=""></div><div>The output looks correct. Try adding multiplication and division and you'll see higher costs. </div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_quote"><div dir="ltr" class=""><div class=""> Also, what target architecture is being used for the estimations? (Is it auto detecting the architecture I'm on?)<br class=""></div></div></div></div></div></blockquote><div><br class=""></div><div>When the cost model analysis uses it uses the target that the compiler driver sets. In your experiments with OPT you can request a specific target using the -mcpu and -mtriple flags. Like this:</div><div><br class=""></div><div>-mcpu=core-avx2 -mtriple=x86_64-apple-darwin </div><div><br class=""></div><div>You can find more examples under llvm/test/Analysis/CostModel.</div><div><br class=""></div><div>-Nadav</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_quote"><div dir="ltr" class=""><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Steve</div></div>
</div><br class=""></div>
_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a> <a href="http://llvm.cs.uiuc.edu" class="">http://llvm.cs.uiuc.edu</a><br class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class=""></div></blockquote></div><br class=""></body></html>