Oh, I appologize that I should not have asked about __main() ---- it appears in FAQ.<br>But the question remains that why call to __main() can alias stack location?<br>I think the memory location pointed by data_X pointers are not visible to __main().
<br>In comparison, calls to printf() do not have similar effect. <br><br><br><br><br><div><span class="gmail_quote">On 5/14/06, <b class="gmail_sendername">Nai Xia</b> <<a href="mailto:nelson.xia@gmail.com">nelson.xia@gmail.com
</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">In a code segment of my pass plugin, I try to gather AliasSets for all StoreInst, LoadInst and CallInst instructions in a function.
<br>Some behaviors of the pass puzzled me.<br>Below is the *.ll of the test program which I run the pass on,<br>it was get with "llvm-gcc -Wl,--disable-opt" from a rather simple *.c program.<br><br>----------------------------------
<br>; ModuleID = 'ptralias.bc'<br>target endian = little<br>target pointersize = 32<br>target triple = "i686-pc-linux-gnu"<br>deplibs = [ "c", "crtend" ]<br>%.str_1 = internal constant [25 x sbyte] c"ptra=0x ptrb=0x ptrc=0x\0A\00" ; <[25 x sbyte]*> [#uses=1]
<br>%ptr = weak global void ()* null ; <void ()**> [#uses=0]<br><br>implementation ; Functions:<br><br>declare int %printf(sbyte*, ...)<br><br>void %foo1() {<br> ret void<br>}<br><br>void %foo2() {
<br> ret void<br>}<br><br>int %main(int %argc, sbyte** %argv) {<br>entry:<br> %data_b = alloca int ; <int*> [#uses=2]<br> %data_c = alloca int ; <int*> [#uses=1]<br> %data_d = alloca int ; <int*> [#uses=3]
<br> %data_e = alloca int ; <int*> [#uses=2]<br> %data_f = alloca int ; <int*> [#uses=2]<br> call void %__main( )<br> store int 2, int* %data_b<br> store int 3, int* %data_c
<br> store int 4, int* %data_d<br> store int 5, int* %data_e<br> store int 6, int* %data_f<br> switch int %argc, label %switchexit [<br> int 3, label %label.3<br> int 2, label %then.2
<br> int 1, label %label.1<br> int 0, label %endif.2<br> ]<br><br>label.1: ; preds = %entry<br> br label %switchexit<br><br>label.3: ; preds = %entry<br>
br label %then.2<br><br>switchexit: ; preds = %label.1, %entry<br> %ptr_b.0 = phi int* [ %data_d, %label.1 ], [ null, %entry ] ; <int*> [#uses=1]<br> br label %endif.2<br><br>then.2
: ; preds = %label.3, %entry<br> %ptr_a.1.0 = phi int* [ %data_f, %label.3 ], [ %data_e, %entry ] ; <int*> [#uses=1]<br> store int 0, int* %ptr_a.1.0<br> br label %then.3<br>
<br>endif.2: ; preds = %switchexit, %entry<br> %ptr_b.0.1 = phi int* [ %ptr_b.0, %switchexit ], [ %data_b, %entry ] ; <int*> [#uses=2]<br> %tmp.12 = seteq int* %ptr_b.0.1, null ; <bool> [#uses=1]
<br> br bool %tmp.12, label %then.4, label %then.3<br><br>then.3: ; preds = %endif.2, %then.2<br> %ptr_b.0.2 = phi int* [ %data_d, %then.2 ], [ %ptr_b.0.1, %endif.2 ] ; <int*> [#uses=1]
<br> store int 0, int* %ptr_b.0.2<br> %tmp.1913 = call int (sbyte*, ...)* %printf( sbyte* getelementptr ([25 x sbyte]* %.str_1, int 0, int 0) ) ; <int> [#uses=0]<br> ret int 0<br><br>
then.4: ; preds = %endif.2<br> %tmp.19 = call int (sbyte*, ...)* %printf( sbyte* getelementptr ([25 x sbyte]* %.str_1, int 0, int 0) ) ; <int> [#uses=0]<br> ret int 0<br>}<br><br>void %__main() {
<br>entry:<br> ret void<br>}<br><br>----------------------------------<br>I think the right AliasSet information calculated for this program should be<br><br> Information for alias set0:<br> pointer0=data_b<br>
pointer1=data_d<br> pointer2=ptr_b.0.2<br> Information for alias set1:<br> pointer0=data_c<br> Information for alias set2:<br> Information for alias set3:<br> pointer0=data_e<br> pointer1=data_f
<br> pointer2=ptr_a.1.0<br> Information for alias set4:<br> Information for alias set5:<br><br>,where the empty AliasSets I think should be "Forwarded".<br><br>However, the result of the pass was:<br><br>
Information for alias set0:<br> pointer0=data_b<br> pointer1=data_d<br> pointer2=data_e<br> pointer3=data_f<br> pointer4=ptr_a.1.0<br> pointer5=ptr_b.0.2<br> Information for alias set1:<br> pointer0=data_c
<br>After I deleted "call void %__main( )" in %main(), the pass get the right answer.<br><br>So my question is:<br><br>1. What is the purpose for call to __main() ? __main() is just a empty function. My .c program only contains main().
<br>2. My explanation for this behavior is that the CallSite of "call void %__main( )" alias some pointers in the program,<br> however, __main() is obviously empty, why should the AliasAnalysis think that it may/must Mod/Ref any stack location of main()?
<br><br>btw: the AliasAnalysis pass I used is -steens-aa and it also the same with -anders-aa.<br><br>--<br>Regards,<br>Nai<br></blockquote></div><br>