XiaoGuang Wang
2014-Oct-05 20:47 UTC
[LLVMdev] Question about jumptable and indirect function call.
Hi all, I'm a beginner in LLVM. I read a paper recently, and I'm trying to use LLVM jumptable in 3.5. When I compile the .bc file into .s file, I tried to use the different jumptable type: all, single, ... e.g. clang -c -emit-llvm test.c llc test.bc -jump-table-type=full -o test-full.s llc test.bc -jump-table-type=single -o test-single.s The tested C source code is like: void foo() { printf("foo...\n"); } void bar() { printf("bar...\n"); } void foo1(int arg) { printf("foo1... %d..\n", arg); } void bar1(int arg) { printf("bar1... %d..\n", arg); } // function pointer void (*fp)() = 0; void (*fp1)(int) = 0; int main(int argc, char* argv[]) { int input = 0; printf("Hello\n"); fp = foo; fp(); fp = bar; fp(); fp1 = foo1; fp1(1); fp1 = bar1; fp1(2); } However, they produced the same .s assembly (test-full.s, test-single.s). I think the llc will produce difference .s files, since I choose the jumptable options. And according to my understanding, the jumptable contains the destination address of each indirect function call. So what's going on with my test. Is there something I did wrong with jumptable options? Or is the jumptable tried to address other problem, not indirect call? Thanks! Sincerely, Xiaoguang Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141005/94ee35c2/attachment.html>
Tim Northover
2014-Oct-06 15:36 UTC
[LLVMdev] Question about jumptable and indirect function call.
Hi, On 5 October 2014 13:47, XiaoGuang Wang <xjtuwxg at gmail.com> wrote:> So what's going on with my test. Is there something I did wrong with > jumptable options? Or is the jumptable tried to address other problem, not > indirect call?I think LLVM's jump table pass requires explicit function annotations in the IR for functions that should go via the table, which Clang doesn't create. Something like this in its simplest form: define void @foo() unnamed_addr jumptable { ret void } define void @main() { %var = alloca void()* store void()* @foo, void()** %var %func = load void()** %var call void %func() ret void } Cheers. Tim.
XiaoGuang Wang
2014-Oct-06 16:14 UTC
[LLVMdev] Question about jumptable and indirect function call.
Thanks Tim,> On 5 October 2014 13:47, XiaoGuang Wang <xjtuwxg at gmail.com> wrote: > > So what's going on with my test. Is there something I did wrong with > > jumptable options? Or is the jumptable tried to address other problem, > not > > indirect call? > > I think LLVM's jump table pass requires explicit function annotations > in the IR for functions that should go via the table, which Clang > doesn't create. Something like this in its simplest form: > > define void @foo() unnamed_addr jumptable { > ret void > } > > define void @main() { > %var = alloca void()* > store void()* @foo, void()** %var > %func = load void()** %var > call void %func() > ret void > } >You're right. It seems we need to manually annotate the IR function in this case. I just found a clang patch which Tom Roeder provided ( http://comments.gmane.org/gmane.comp.compilers.clang.scm/102395). And I tried it, it works with clang -ffcif test.c. I'm trying to read source code to see how jump table pass works. Thanks again! Xiaoguang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141006/7ffbd778/attachment.html>