<div dir="ltr"><span style="font-size:12.8000001907349px">Sorry if double posted... might have sent this to old mailing list address...<br></span><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Stephen Thomas</b> <span dir="ltr"><<a href="mailto:stephen.warner.thomas@gmail.com">stephen.warner.thomas@gmail.com</a>></span><br>Date: Wed, Aug 5, 2015 at 10:39 AM<br>Subject: How to use CostModel?<br>To: LLVM Dev <<a href="mailto:llvmdev@cs.uiuc.edu">llvmdev@cs.uiuc.edu</a>><br><br><br><div dir="ltr">Hi,<div><br></div><div>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><br></div><div><div>$ cat test.c </div><div>int main(){</div><div> int r = rand();</div><div> if (r > 1){</div><div> return ++r;</div><div> }</div><div> return r*86;</div><div>}</div><div><br></div><div>$ clang-3.6 -S -emit-llvm test.c -o test.bc</div><div><br></div><div>$ opt-3.6 -analyze -targetlibinfo -cost-model ./test.bc</div><div>Printing analysis 'Target Library Information':</div><div>Pass::print not implemented for pass: 'Target Library Information'!</div><div>Printing analysis 'Cost Model Analysis' for function 'main':</div><div>Cost Model: Unknown cost for instruction: %1 = alloca i32, align 4</div><div>Cost Model: Unknown cost for instruction: %r = alloca i32, align 4</div><div>Cost Model: Found an estimated cost of 1 for instruction: store i32 0, i32* %1</div><div>Cost Model: Unknown cost for instruction: %2 = call i32 (...)* @rand()</div><div>Cost Model: Found an estimated cost of 1 for instruction: store i32 %2, i32* %r, align 4</div><div>Cost Model: Found an estimated cost of 1 for instruction: %3 = load i32* %r, align 4</div><div>Cost Model: Found an estimated cost of 1 for instruction: %4 = icmp sgt i32 %3, 1</div><div>Cost Model: Found an estimated cost of 0 for instruction: br i1 %4, label %5, label %8</div><div>Cost Model: Found an estimated cost of 1 for instruction: %6 = load i32* %r, align 4</div><div>Cost Model: Found an estimated cost of 1 for instruction: %7 = add nsw i32 %6, 1</div><div>Cost Model: Found an estimated cost of 1 for instruction: store i32 %7, i32* %r, align 4</div><div>Cost Model: Found an estimated cost of 1 for instruction: store i32 %7, i32* %1</div><div>Cost Model: Found an estimated cost of 0 for instruction: br label %11</div><div>Cost Model: Found an estimated cost of 1 for instruction: %9 = load i32* %r, align 4</div><div>Cost Model: Found an estimated cost of 1 for instruction: %10 = mul nsw i32 %9, 86</div><div>Cost Model: Found an estimated cost of 1 for instruction: store i32 %10, i32* %1</div><div>Cost Model: Found an estimated cost of 0 for instruction: br label %11</div><div>Cost Model: Found an estimated cost of 1 for instruction: %12 = load i32* %1</div><div>Cost Model: Found an estimated cost of 0 for instruction: ret i32 %12</div></div><div><br></div><div><br></div><div>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?)<br></div><div><br></div><div><br></div><div>Thanks,</div><div>Steve</div></div>
</div><br></div>