问题
Is it possible to translate an assembly language to LLVM IR, optimize it and then recompile it to a different architecture? How would you handle "push"es and "pop"s on the stack in the IR? This is the simplest objection I found, but I'm sure that there're tons like this.
I'm planning to build a dynamic recompiler, and it seems that this would be an excellent solution, since LLVM would automatically optimize my code for the new architecture. Is all this possible with LLVM?
Thanks
回答1:
This is a similar question: Recompile a x86 code with LLVM to some faster one x86
The answer is that LLVM can't do it directly, but could be used as part of a tool that does.
回答2:
It is possible.
But you need to develop some code base the LLVM to implement the process translating the assembly language to LLVM IR. Then the LLVM can help you to optimize and generator for new architecture.
So, the point is you need to develop the translator which can translate the assembly language to LLVM IR. I have seen someone already do that, you can search on the website.
来源:https://stackoverflow.com/questions/8288251/is-it-possible-to-translate-an-assembly-language-to-llvm-ir-optimize-it-and-the