Seung Jae Lee
2007-Jul-15 01:23 UTC
[LLVMdev] not to break 'for' statement into basic blocks
According to the instruction manual of this target machine, 'goto' should not be used in C code. :-/ Could you tell me a little more about your advice as to using 'reg2mem', if you're fine? Thank you so much, Anton. Best, Seung J. Lee ---- Original message ---->Date: Sun, 15 Jul 2007 02:23:27 +0400 >From: Anton Korobeynikov <asl at math.spbu.ru> >Subject: Re: [LLVMdev] not to break 'for' statement into basic blocks >To: LLVM Developers Mailing List <llvmdev at cs.uiuc.edu> > >Hello, Seung J. Lee > >> LLVM optimization and other tools are really fantastic. >> However I don't want LLVM breaks my 'for' statement in C code into >> basic blocks during compiling. >> I'm sure this sounds really strange but there is a reason for me. >LLVM is 'low-level'. It doesn't contain any special instruction for >loops at all. > >> Furthermore, this assembly does not have the notion of >> 'br'instruction, phi-node and so on. Therefore, I have no choice >> without making 'for' in the assembly. >Maybe you can look, how code operates on phi-nodes in C & MSIL backends. > >> 1) First, I tried to re-unite basic blocks which llvm-gcc spits out to make 'for' again. >> But this is quite tricky. Generalizing it for the optimzed llvm bytecode is not easy. >I'd say 'is not possible at all'. > >In general, loop contain induction variable, which is being assigned >each iteration of loop. As LLVM IR is in SSA mode, there are only two >possibilities to operate on induction variable so: > >1. Use phi node >2. Use memory (memory is never in SSA form) > >So, if you don't want to deal with phi-node, you have to lower >everything to memory. 'reg2mem' pass is your friend in this case. This >will eliminate all phi nodes, but you have to resolve all branches. > >However, I really don't see, how you can transform C code (in general) >to your target, because C *has* explicit goto statement. Maybe you can >split the whole CFG into "cycles" and "paths" and try to "lower" them. >But this can be pretty complicated. > >-- >With best regards, Anton Korobeynikov. > >Faculty of Mathematics & Mechanics, Saint Petersburg State University. > > >_______________________________________________ >LLVM Developers mailing list >LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev