[llvm-dev] LLVMGetFirstFunction() / LLVMGetNextFunction( ) problem
Reid Kleckner via llvm-dev
llvm-dev at lists.llvm.org
Fri Apr 28 13:39:00 PDT 2017
The intention of the API is that you iterate until LLVMGetNextFunction
returns NULL, not the last function. See their implementations:
LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M) {
Module *Mod = unwrap(M);
Module::iterator I = Mod->end();
if (I == Mod->begin())
return nullptr;
return wrap(&*--I);
}
LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn) {
Function *Func = unwrap<Function>(Fn);
Module::iterator I(Func);
if (++I == Func->getParent()->end())
return nullptr;
return wrap(&*I);
}
On Fri, Apr 28, 2017 at 1:23 PM, Toshiyasu Morita via llvm-dev <
llvm-dev at lists.llvm.org> wrote:
> Hi, I have a problem - looking for advice.
>
> I have a source code file with two functions which are compiled into a .bc
> file.
> When the bitcode file is loaded, I can dump the module and see the two
> functions:
>
> ...
> ; Materializable
> ; Function Attrs: noinline nounwind uwtable
> define void @matmul(double*, double*, double*, i32, i32, i32) #0 {}
>
> ; Materializable
> ; Function Attrs: noinline nounwind uwtable
> define i32 @main() #0 {}
> ...
>
> However, when I use LLVMGetirstFunction() and LLVMGetNextFunction() to
> iterate through the functions in the module, it only iterates through the
> function "matmul".
> It never finds main().
>
> 50 first_func = LLVMGetFirstFunction(module);
> (gdb) next
> 151 last_func = LLVMGetLastFunction(module);
> (gdb)
> 154 for (func = first_func; func != last_func; func =
> LLVMGetNextFunction(func)) {
> (gdb)
> 155 func_name = LLVMGetValueName(func);
> (gdb)
> 156 func_addr = LLVMGetFunctionAddress(engine, func_name);
> (gdb) print func_name
> $9 = 0x1efe180 "matmul"
> (gdb) next
> 159 if (!func_addr) continue;
> (gdb)
> 161 symbol_table_add(symbol_table, func_name, func_addr);
> (gdb)
> 164 if ((size = mem_region_lookup(mem_region_anchor, func_addr)))
> { symbol_table_add(symbol_table, "dummy_symbol", func_addr + size); }
> (gdb)
> 154 for (func = first_func; func != last_func; func =
> LLVMGetNextFunction(func)) {
> (gdb)
> 168 symbol_table_calc_symbol_sizes(symbol_table);
>
> Any suggestions appreciated.
>
> Toshi
>
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://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/20170428/1badf6fa/attachment.html>
More information about the llvm-dev
mailing list