问题描述
是否可以使用x86 32位代码的输入来运行LLVM编译器?有一个巨大的算法,我没有源代码,我想使其在同一硬件上运行得更快.我可以通过优化将其从x86转换回x86.
Is it possible to run LLVM compiler with input of x86 32bit code? There is a huge algorithm which I have no source code and I want to make it run faster on the same hardware. Can I translate it from x86 back to x86 with optimizations.
此代码运行很长时间,因此我想对其进行静态重新编译.另外,我可以对其进行运行时配置文件并提供LLVM提示,哪些分支更有可能.
This Code runs a long time, so I want to do static recompilation of it. Also, I can do a runtime profile of it and give to LLVM hints, which branches are more probable.
原始代码是为x86 + x87编写的,不使用SSE/MMX/SSE2.重新编译后,它有机会使用x86_64和/或SSE3.而且,代码将以更优化的方式重新生成到硬件解码器.
The original Code is written for x86 + x87, and uses no SSE/MMX/SSE2. After recompilation It has chances to use x86_64 and/or SSE3. Also, the code will be regenerated in more optimal way to hardware decoder.
谢谢.
推荐答案
LLVM无法做到这一点.您必须编写一个x86二进制到LLVM中间表示(IR)转换器.那将是非常不平凡的任务.如果x86代码足够简单,它可能会非常接近IR映射,但是某些x86指令不会直接映射,例如堆栈指针操作.
LLVM can't do this out of the box. You'd have to write an x86 binary to LLVM intermediate representation (IR) converter. That would be a very non-trivial task. If the x86 code was simple enough it might map pretty closely to IR, but some x86 instructions won't map directly, e.g. stack pointer manipulations.
您也可以考虑尝试一种与QEMU相似的方法. QEMU可以即时转换二进制文件,在我运行PowerPC代码时,它会在执行之前将每个基本块都转换为X86代码.您可以弄清楚如何将目标文件分解为基本块,并为每个块生成LLVM IR,如何丢弃东西(例如传递参数等),并用直接的LLVM IR代替.
You could also consider trying an approach similar to what QEMU does. QEMU translates the binaries on the fly, that it when I run PowerPC code, each basic block is translated into X86 code before it is executed. You could figure out how to break your object file into the basic blocks and generate LLVM IR for each block, discarding stuff (like parameter passing, etc.) and replacing that with straight LLVM IR.
尽管如此,它仍然是一项大工作.从头开始重写算法可能更容易.
Still a BIG job, though. Probably easier to rewrite the algorithm from scratch.
这篇关于使用LLVM将x86代码重新编译为更快的x86的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!