<div dir="ltr">Thank You David and Mats for the reply, <div><br></div><div>The reason I need to know that main is the entry point is as follows :</div><div><br></div><div>I have a dead code elimination pass that removes the function call for boo. boo was initially called from the main function , but since the return in the main function has no dependency on boo, boo function call is removed. </div><div><br></div><div>Now I want to remove the function definition of the functions that are not called. Notice that boo and main , both do not have any function calls to them . </div><div>So, if I were to traverse all the functions over the entire module and use the API F->use_empty() to check for functions calls both boo and main return true and be deleted. I want to save main function definition from being deleted. </div><div><br></div><div>As correctly mentioned by you above, there could be more functions similar to main , which can be called externally and I do not want them to be deleted. I am looking for a solution which tells me that this particular function is an entry point to the program and will have no function calls to it. </div><div><br></div><div>Thanks</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 23, 2017 at 4:42 PM, mats petersson <span dir="ltr"><<a href="mailto:mats@planetcatfish.com" target="_blank">mats@planetcatfish.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>If you want to know which functions are (or may be) called from where, in the entire program, then you will need to do some sort of "LLVM-IR Linking" (there are tools that will do that for you, such as "llvm-link"). <br><br>Of course, even then, there's possible cases where it's impossible to know whether a function is ACTUALLY called until at runtime - function pointers, including those in vtables, may or may not actually get called, depending on the exact dynamic behaviour of the code. <br><br>Then there will be functions implemented outside of the LLVM-IR for the program anyway. atexit is a good example of a function that takes a function pointer. Your code will not know what (if anything) atexit does with that function pointer, or if/when that function gets called. Of course, we, as humans, know how atexit works and when the function gets called, but some code will not know that unless you write code to understand it's behaviour - and there are many types of functions that take a pointer to a function, some of which are much more complex than atexit - for example signal handlers or call-backs that gets called on errors. Imagine a function being called only when a memory allocation fails... <br><br></div><div>As David says, it's of course highly dependent on what you are trying to achieve, exactly what approach you should take (or if there is an approach that is meaningful at all).<br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On 23 October 2017 at 09:03, David Chisnall via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><span>On 21 Oct 2017, at 12:51, mohie pokhriyal via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
> I want to be able to find out that main is the entry point function of the program.<br>
> main and boo both do not have any predecessors or successors , such that I can make a cfg to figure out who’s calling whom ?<br>
><br>
> Is there a way I can achieve this ?<br>
<br>
</span>The fact that main is the entry point is not known to LLVM (except in a couple of places that special-case main, such as the internalise pass), because it is an artefact of C/C++, not a generic property. On most *NIX platforms, the real entry point for a program is something like __start or _start, which then call main. In most compilation units, there is no single entry point, because they do not contain the program entry point and so can be entered by any externally visible function.<br>
<br>
It might help if you explained why you need this.<br>
<br>
David<br>
<br></div></div>
______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br></div>
</blockquote></div><br></div>