Sunil via llvm-dev
2020-Feb-04 16:24 UTC
[llvm-dev] How to distinguish between user defined function in a program and library functions
Say, I have the following program: #include <iostream> int main(){ std::cout << "hello\n"; return 0; } After generating llvm bitcode using the following command: $ clang++ -c -emit-llvm -O -Xclang -disable-llvm-passes a.cpp the bitcode has the following function with define. __cxx_global_var_init main _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc _ZNSt9basic_iosIcSt11char_traitsIcEE8setstateESt12_Ios_Iostate _ZNSt11char_traitsIcE6lengthEPKc _ZStorSt12_Ios_IostateS_ _ZNKSt9basic_iosIcSt11char_traitsIcEE7rdstateEv _GLOBAL__sub_I_a.cpp In a pass, I want to know what are the functions defined by the user e.g 'main' and what are not e.g. other than 'main'. Regards, Sunil -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200204/7c8fe52a/attachment.html>
David Blaikie via llvm-dev
2020-Feb-04 23:53 UTC
[llvm-dev] How to distinguish between user defined function in a program and library functions
Generally, you can't - and optimizations/the compiler shouldn't differentiate between them. On Tue, Feb 4, 2020 at 3:25 PM Sunil via llvm-dev <llvm-dev at lists.llvm.org> wrote:> Say, I have the following program: > #include <iostream> > int main(){ > std::cout << "hello\n"; > return 0; > } > > After generating llvm bitcode using the following command: > $ clang++ -c -emit-llvm -O -Xclang -disable-llvm-passes a.cpp > the bitcode has the following function with define. > __cxx_global_var_init > main > _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc > _ZNSt9basic_iosIcSt11char_traitsIcEE8setstateESt12_Ios_Iostate > _ZNSt11char_traitsIcE6lengthEPKc > _ZStorSt12_Ios_IostateS_ > _ZNKSt9basic_iosIcSt11char_traitsIcEE7rdstateEv > _GLOBAL__sub_I_a.cpp > > In a pass, I want to know what are the functions defined by the user e.g > 'main' and what are not e.g. other than 'main'. > > Regards, > Sunil > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200204/3dc43f73/attachment.html>
sunilps via llvm-dev
2020-Feb-05 04:01 UTC
[llvm-dev] How to distinguish between user defined function in a program and library functions
<div dir="ltr"><br> </div><div dir="ltr">Actually I want to run some analysis pass only on the user defined functions but not on the library functions. Is there any boolean method that can tell which is a library function and which is not? </div><div class="wps_quotion">On 5 Feb 2020 5:23 a.m., David Blaikie <dblaikie@gmail.com> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Generally, you can't - and optimizations/the compiler shouldn't differentiate between them.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Feb 4, 2020 at 3:25 PM Sunil via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <div> <p>Say, I have the following program:</p> <div><font face="Courier New, Courier, monospace"> #include <iostream><br> int main(){<br> std::cout << "hello\n";<br> return 0;</font></div> <div><font face="Courier New, Courier, monospace"> }</font><br> </div> <div><br> </div> <div>After generating llvm bitcode using the following command: </div> <div> $ <font face="Courier New, Courier, monospace">clang++ -c -emit-llvm -O -Xclang -disable-llvm-passes a.cpp</font><br> </div> <div>the bitcode has the following function with define.</div> <div> <font face="Courier New, Courier, monospace">__cxx_global_var_init<br> main<br> _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc<br> _ZNSt9basic_iosIcSt11char_traitsIcEE8setstateESt12_Ios_Iostate<br> _ZNSt11char_traitsIcE6lengthEPKc<br> _ZStorSt12_Ios_IostateS_<br> _ZNKSt9basic_iosIcSt11char_traitsIcEE7rdstateEv<br> _GLOBAL__sub_I_a.cpp<br> </font></div> <div><br> </div> <div>In a pass, I want to know what are the functions defined by the user e.g 'main' and what are not e.g. other than 'main'.</div> <div><br> </div> <div>Regards,</div> <div> Sunil</div> </div> _______________________________________________<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="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br> </blockquote></div> </blockquote></div>
Jacob Carlborg via llvm-dev
2020-Feb-05 18:16 UTC
[llvm-dev] How to distinguish between user defined function in a program and library functions
On 2020-02-04 17:24, Sunil via llvm-dev wrote:> Say, I have the following program: > > #include <iostream> > int main(){ > std::cout << "hello\n"; > return 0; > } > > After generating llvm bitcode using the following command: > $ clang++ -c -emit-llvm -O -Xclang -disable-llvm-passes a.cpp > the bitcode has the following function with define. > __cxx_global_var_init > main > _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc > _ZNSt9basic_iosIcSt11char_traitsIcEE8setstateESt12_Ios_Iostate > _ZNSt11char_traitsIcE6lengthEPKc > _ZStorSt12_Ios_IostateS_ > _ZNKSt9basic_iosIcSt11char_traitsIcEE7rdstateEv > _GLOBAL__sub_I_a.cpp > > In a pass, I want to know what are the functions defined by the user e.g > 'main' and what are not e.g. other than 'main'.Perhaps you can check where a function is defined and treat all functions defined in a file passed to the compiler as user defined and all other as system defined. Not sure if that's good enough for you. -- /Jacob Carlborg
George Burgess IV via llvm-dev
2020-Feb-08 00:04 UTC
[llvm-dev] How to distinguish between user defined function in a program and library functions
I'd imagine you can tweak clang's CodeGen to add a Metadata node to all `llvm::Function`s clang emits that basically says whether or not the code appeared in a system header. SourceManager::isInSystemHeader should help you figure out what's where. You'll probably need special handling for generated code, like `__cxx_global_var_init` I offer no guarantees about the LLVM community accepting this patch, though :) To Mehdi's point, inlining can make things materially more difficult. On Wed, Feb 5, 2020 at 10:16 AM Jacob Carlborg via llvm-dev < llvm-dev at lists.llvm.org> wrote:> On 2020-02-04 17:24, Sunil via llvm-dev wrote: > > Say, I have the following program: > > > > #include <iostream> > > int main(){ > > std::cout << "hello\n"; > > return 0; > > } > > > > After generating llvm bitcode using the following command: > > $ clang++ -c -emit-llvm -O -Xclang -disable-llvm-passes a.cpp > > the bitcode has the following function with define. > > __cxx_global_var_init > > main > > _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc > > _ZNSt9basic_iosIcSt11char_traitsIcEE8setstateESt12_Ios_Iostate > > _ZNSt11char_traitsIcE6lengthEPKc > > _ZStorSt12_Ios_IostateS_ > > _ZNKSt9basic_iosIcSt11char_traitsIcEE7rdstateEv > > _GLOBAL__sub_I_a.cpp > > > > In a pass, I want to know what are the functions defined by the user e.g > > 'main' and what are not e.g. other than 'main'. > > Perhaps you can check where a function is defined and treat all > functions defined in a file passed to the compiler as user defined and > all other as system defined. Not sure if that's good enough for you. > > -- > /Jacob Carlborg > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200207/5d1b9975/attachment.html>