[LLVMdev] Are there implicit rules or conventions for an llvm frontend to generate llvm IR?

Hongxu Chen leftcopy.chx at gmail.com
Thu Oct 10 08:43:41 PDT 2013


Hi, this question might be a bit silly: apart from the language
reference(http://llvm.org/docs/LangRef.html#switch-instruction) page, are
there additional rules for a regular llvm frontend to generate llvm IRs?

There are a few cases that I got from clang/llvm-gcc/dragonegg when
compiling *C* source code into llvm IR:

1. It seems that there is ONLY ONE ReturnInst(and NO InvokeInst) for such
llvm IR; is it legal to add other *ReturnInst*s when transforming?

2. Is it possible for a frontend to generate a function whose CFG is
something like:

            bb0
       /           \
     bb1          bb2
   /      \       /      \
bb3         bb4        bb5
   \           |          /
     \         |        /
       \       |      /
              bb6

(In this case, if I understand correctly, bb4 is control dependent on both
bb1 and bb2.)
I think it at least possible in theory, and there is a simple case:

int foo(int i) {
  if (i < 0) {
    if (i % 2 == 0) {
      i += 1;
    } else {
      i += 2;
    }
  } else {
    if (i % 2 == 0) {
      i += 1;
    } else {
      i += 2;
    }
  }
return 0;
}

However none of the frontends I used generate the basicblocks like
that(there is always one or more basicblocks generated) /without any
optimizations/. So is there any implicit rules for these frontends?

And can I rely on these cases when I ONLY deal with C source code?

Thanks!



--
View this message in context: http://llvm.1065342.n5.nabble.com/Are-there-implicit-rules-or-conventions-for-an-llvm-frontend-to-generate-llvm-IR-tp61938.html
Sent from the LLVM - Dev mailing list archive at Nabble.com.



More information about the llvm-dev mailing list