On Thu, 11 Jan 2007, Nicolas Geoffray wrote:>> I think the question is how to branch to a location of which you do >> not have a label. >> > Yes, that was the original question. But actually, for my purpose, > Chris' solution is functional enough. However, I looked into llvm-gcc > code and the switch instruction switches for all possible labels defined > in the method. Does LLVM is smart enough to realize that it switches on > the address of a label, therefore only has to generate a jmp in x86 or a > {mtctr, bctr} couple in powerpc?I'm not sure what you mean. We do reasonable optimization of switch statements, but I'm sure there are cases we miss. If so, please let us know, so we can add them to lib/Target/README.txt -Chris -- http://nondot.org/sabre/ http://llvm.org/
Chris Lattner wrote:>> Yes, that was the original question. But actually, for my purpose, >> Chris' solution is functional enough. However, I looked into llvm-gcc >> code and the switch instruction switches for all possible labels defined >> in the method. Does LLVM is smart enough to realize that it switches on >> the address of a label, therefore only has to generate a jmp in x86 or a >> {mtctr, bctr} couple in powerpc? >> > > I'm not sure what you mean. We do reasonable optimization of switch > statements, but I'm sure there are cases we miss. If so, please let us > know, so we can add them to lib/Target/README.txt > >Two jumps are executed when using a switch statement for indirect branch: the first jump goes to the right switch case, the second jumps to the corresponding label. However, indirect branches need only one jump: jumping to the value contained in a register for example (which contains the address of a label). Nicolas
On Mon, 15 Jan 2007, Nicolas Geoffray wrote:>> statements, but I'm sure there are cases we miss. If so, please let us >> know, so we can add them to lib/Target/README.txt >> >> > Two jumps are executed when using a switch statement for indirect branch: > the first jump goes to the right switch case, the second jumps to the > corresponding > label. However, indirect branches need only one jump: jumping to the > value contained > in a register for example (which contains the address of a label).Can you give a compilable C function as an example? -Chris -- http://nondot.org/sabre/ http://llvm.org/