<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=""><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Feb 8, 2016, at 9:17 AM, Mohammad Norouzi <<a href="mailto:mnmomn@gmail.com" class="">mnmomn@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I'm writing a pass that eliminates some variables. </div></div></blockquote><div><br class=""></div><div>Why?</div><div><br class=""></div><div>The notion of a "variable from the user code" is meaningless after the minimal amount of optimizations. </div><div><div class=""><br class=""></div><div class="">For example:</div><div class=""><br class=""></div><div class=""><div class="">int foo(int a, int b) {</div><div class=""> int c = a + 1;</div><div class=""> int d = b + 2;</div><div class=""> return c + d;</div><div class="">}</div></div><div class=""><br class=""></div><div class="">Just running mem2reg and reassociate leads to:</div><div class=""><br class=""></div><div class="">; Function Attrs: nounwind ssp uwtable<br class="">define i32 @_Z3fooii(i32 %a, i32 %b) #0 !dbg !4 {<br class="">entry:<br class=""> call void @llvm.dbg.value(metadata i32 %a, i64 0, metadata !12, metadata !13), !dbg !14<br class=""> call void @llvm.dbg.value(metadata i32 %b, i64 0, metadata !15, metadata !13), !dbg !16<br class=""> call void @llvm.dbg.value(metadata i32 %add, i64 0, metadata !17, metadata !13), !dbg !18<br class=""> call void @llvm.dbg.value(metadata !2, i64 0, metadata !19, metadata !13), !dbg !20<br class=""> %add = add i32 %a, 3, !dbg !21<br class=""> %add2 = add i32 %add, %b, !dbg !22<br class=""> ret i32 %add2, !dbg !23<br class="">}<br class=""><br class=""></div><div class=""><br class=""></div><div class="">You still have two values (%add and %add2) but they don't really match any source variable.</div><div class="">The first %add is still attached to a llvm.dbg.value, but not %add2.</div><div class=""><br class=""></div><div class="">And this is just a very simple example, with only one transformation (beside mem2reg).</div><div class=""><br class=""></div><div class="">-- </div><div class="">Mehdi</div><div class=""><br class=""></div><div class=""><br class=""></div></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class="">To show the effect of the pass i need to show that I deleted the variables that originally appear in the user code, not temporary variables added by llvm.<br class=""></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Feb 8, 2016 at 5:59 PM, Mehdi Amini <span dir="ltr" class=""><<a href="mailto:mehdi.amini@apple.com" target="_blank" class="">mehdi.amini@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br class="">
> On Feb 8, 2016, at 6:39 AM, Mohammad Norouzi via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:<br class="">
><br class="">
> Hi,<br class="">
><br class="">
> I need to check if a variable belongs to the program originally. Consider the following code line:<br class="">
><br class="">
> y = x + 4<br class="">
><br class="">
> and its corresponding llvm ir (roughly):<br class="">
><br class="">
> %16 = load i32 %x<br class="">
> %add = add i32 %16, i32 4<br class="">
> store i32 %add, %y<br class="">
><br class="">
> I need to distinguish between %16, %add and %x, %y.<br class="">
<br class="">
<br class="">
</span>This look like it will quickly degrades with optimization to a point where it won't be meaningful.<br class="">
Why are you needing this? What are you trying to accomplish?<br class="">
<span class="HOEnZb"><font color="#888888" class=""><br class="">
--<br class="">
Mehdi<br class="">
<br class="">
</font></span></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>