LLVM and the future of optimization

后端 未结 7 1855
被撕碎了的回忆
被撕碎了的回忆 2021-02-19 07:11

I realize that LLVM has a long way to go, but theoretically, can the optimizations that are in GCC/ICC/etc. for individual languages be applied to LLVM byte code? If so, does t

7条回答
  •  半阙折子戏
    2021-02-19 07:47

    It is an interesting question, but I am afraid that you are lacking some notions of what compilers do.

    There will always be several stages of optimizations within a compiler.

    • Some optimizations depend on languages rules, for example in C++ you may optimize away some copy/move constructors calls.
    • Some optimizations are broadly available (loop transforms, tail calls)
    • Some optimizations depend on the hardware (SSE, MMX)

    The LLVM compiler applies all 3... but starting from LLVM IR, not from C or Java or whatever.

    It is the job of the front-end to provide a suitable LLVM IR.

    For example, as noted by @Dietrich Epp, the IR is not really suitable for Functional Languages. A lot of Haskell optimizations must therefore be performed before the representation is lowered to the IR.

    Another source of non-optimization is that specific runtime may come with the languages. Haskell has a complicated runtime with sparks pool, lightweight-threads, preemption before system calls, work-stealing etc... The IR is not suitable to represent this rich environment, and no optimization is made on this organization.

提交回复
热议问题