<div dir="ltr">The intention of the API is that you iterate until LLVMGetNextFunction returns NULL, not the last function. See their implementations:<div><br></div><div><div>LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M) {</div><div> Module *Mod = unwrap(M);</div><div> Module::iterator I = Mod->end();</div><div> if (I == Mod->begin())</div><div> return nullptr;</div><div> return wrap(&*--I);</div><div>}</div><div><br></div><div>LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn) {</div><div> Function *Func = unwrap<Function>(Fn);</div><div> Module::iterator I(Func);</div><div> if (++I == Func->getParent()->end())</div><div> return nullptr;</div><div> return wrap(&*I);</div><div>}</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 28, 2017 at 1:23 PM, Toshiyasu Morita 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><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div>Hi, I have a problem - looking for advice.<br><br></div>I have a source code file with two functions which are compiled into a .bc file.<br></div>When the bitcode file is loaded, I can dump the module and see the two functions:<br><br>...<br>; Materializable<br>; Function Attrs: noinline nounwind uwtable<br>define void @matmul(double*, double*, double*, i32, i32, i32) #0 {}<br><br>; Materializable<br>; Function Attrs: noinline nounwind uwtable<br>define i32 @main() #0 {}<br>...<br><br></div>However, when I use LLVMGetirstFunction() and LLVMGetNextFunction() to iterate through the functions in the module, it only iterates through the function "matmul".<br></div>It never finds main().<br><br>50 first_func = LLVMGetFirstFunction(module);<br>(gdb) next<br>151 last_func = LLVMGetLastFunction(module);<br>(gdb) <br>154 for (func = first_func; func != last_func; func = LLVMGetNextFunction(func)) {<br>(gdb) <br>155 func_name = LLVMGetValueName(func);<br>(gdb) <br>156 func_addr = LLVMGetFunctionAddress(engine, func_name);<br>(gdb) print func_name<br>$9 = 0x1efe180 "matmul"<br>(gdb) next<br>159 if (!func_addr) continue;<br>(gdb) <br>161 symbol_table_add(symbol_table, func_name, func_addr);<br>(gdb) <br>164 if ((size = mem_region_lookup(mem_region_<wbr>anchor, func_addr))) { symbol_table_add(symbol_table, "dummy_symbol", func_addr + size); }<br>(gdb) <br>154 for (func = first_func; func != last_func; func = LLVMGetNextFunction(func)) {<br>(gdb) <br>168 symbol_table_calc_symbol_<wbr>sizes(symbol_table);<br><br></div><div>Any suggestions appreciated.<br><br></div><div>Toshi<br><br></div><div><div><br><br></div></div></div>
<br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">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>
<br></blockquote></div><br></div>