Search code examples
cllvmllvm-clangllvm-c++-api

Can LLVM be used to produce optimized C-code


Is it possible to use LLVM to read in C code and make it faster? I've seen many discussions on using LLVM to transform C++ to (unreadable) C code but I'm wondering if LLVM can read in C code, and produce a file (code, not an executable) with the same functionality that is faster.


Solution

  • No.

    There is a C backend for LLVM, so you can compile C via LLVM IR to C and apply optimisation passes on the way, but what you are asking about is neither a design goal of that backend nor of LLVM as a whole. If it works in any particular case, then that is just a happy coincidence.

    One of LLVM's goals is producing fast code using backends that resemble a variety of current hardware. C, however, does not even try to resemble a modern processor. Quite reasonably so, being fifty years older than the latest silicon miracles.