[llvm-dev] Generating a loop from llvm bitcode
David Greene via llvm-dev
llvm-dev at lists.llvm.org
Tue Aug 7 11:18:26 PDT 2018
"Ejjeh, Adel via llvm-dev" <llvm-dev at lists.llvm.org> writes:
> Hello
>
> I am developing a backend that generates OpenCL from llvm bitcode. I
> start with a revived fork of the original LLVM C-Backend and have been
> modifying it.
How far do you intend to take this? Reconstructing high-level control
flow from a CFG is not possible in the general case without code
duplication. One can do quite a lot but the nature of low-level
optimization means that at some point you'll likely need gotos, unless
code expansion is not a concern. And even then, the result won't look
much like the source program (though you probably don't care).
Beyond that, reconstructing high-level characteristics of values
(finding induction variables, getting proper array dimensions, etc.) is
even more challenging. One can't reconstruct original C struct types,
for example, because many of them get merged into a single LLVM type.
One might be able to do a bit better with TBAA but frontends would have
to save a lot more information in the IR to allow general translation.
There are many things in LLVM that cannot be expressed in C. C has no
"shufflevector" operation, for example. At best one can try to emit
(non-portable) intrinsics which may or may not be acceptable. Or emit
some kind of awful loop, I guess.
The C backend was riddled with problems even beyond the above issues.
If I were going to attempt something like this I don't think I'd start
with that.
It's not a hopeless project as long as you manage your expectations. :)
-David
More information about the llvm-dev
mailing list