[LLVMdev] Eliminating gotos

Benedict Gaster benedict.gaster at amd.com
Thu Aug 14 11:35:55 PDT 2008


Hi Mon Ping,
>>>  
>> [bg] Ok so I think I¹m starting to get it. You are correct in your assertion
>> that we need to insert the end-if instruction at some point and of course
>> else in the case of if-then-else constructs. But we also need to reconstruct
>> while-loops and it is unclear to me if you approach works for all cases of
>> gotos. The other concern here is that as we are targeting an instruction set
>> with virtual registers and register allocation and scheduling will be
>> performed by our assembler not within LLVM and so we are planning on
>> implementing a language style backend, similar in style to the MSIL backend,
>> and as such it is possible to use a  machine-level pass?
>>  
>>> [ Deleted Text]
> 
> I don't see why not as you have only a different target.  Assuming the
> incoming graph doesn't have improper intervals, I would think that Owen's
> approach to have a structural fixup machine level pass to run over the CFG
> seems to be the right way to go.  I assume that the requirement is to end up
> with structured control flow and its not required (though it might be
> desirable) that the incoming source graph is preserved. If the incoming code
> have improper intervals, I think we could reconstruct it but as other people
> indicated, the CFG could be quite a bit larger (see [1]).
> 
[bg] I¹ve been thinking about this some more and was thinking of
implementing some along the following lines:
> 
* translate into machine-level SSA representation;
* do phi removal (as we have virtual register set conventional register
allocation is not important for us; this happens much later down the tool
flow); I was initially planning to do phi removal as described in [1] but it
has been pointed out to me that this is not correct in all cases and so now
plan to implement the algorithm given in [2].
* do high-level control flow reconstruction
* insert if-then-else-endif/while-endwhile blocks
* finish code generation

Does this make sense?

I agree that it in general conversion of irreducible graphs could be
expensive but in our case gotos are not allowed in the original source,
break and continue are supported in the target language, and so this implies
that we should, in theory, be reconstructing the high-level source that was
originally compiled.

[1] Efficiently computing static single assignment form and control
dependence graph, Cytron, et. al., 1991.
[2] Practical Improvements to the Construction and Destruction of Static
Single Assignment Form, Briggs, et. al., 1997

Regards,

Ben

>   -- Mon Ping
> 
> 
> [1] Folklore confirmed: reducible flow graphs are exponentially larger
> Proc. of the 30 th ACM SIGPLANSIGACT Symposium on Principles of Programming
> Languages
> 
> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080814/3c4551a9/attachment.html>


More information about the llvm-dev mailing list