LLVM and the future of optimization

后端 未结 7 1871
被撕碎了的回忆
被撕碎了的回忆 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:53

    Coming back to the your question "is it theoretically possible?" , let's imagine/assume - Just for a sake of discussion - following :

    • we have bytecode, or even machinecode
    • we know it's produced with given compiler X
    • source language was L
    • that input program had finite size.

    IMHO - from computer science point of view, it's mostly question of resources, to apply almost anything.

    Now let's try following

    function machinecode_to_sourcecode( given_machinecode ){
      it = all_posibble_strings_iterator()
      while (true) {
        possible_sourcecode = it->get_string()
        machine_code = compile possible_sourcecode with X
        if (compilation succeeded)
            if(machine_code == given_machinecode)
               return possible_sourcecode;
        else
           it = it->next_string()
      }
    }
    

    So we try all possible strings, as input for compiler X, in case of success compilation - ones results equal, we have source.

    Once we have source, we have as much information about program as we can, so we are able to apply all possible optimizations.

    All looks very costly, but as you've asked "theoretically", I will say

    • it will take finite amount of time

    because

    • input sourcecode have finite length

    so

    • iterating at all such strings takes finite amount of time
    • I assumed, that compiler process any sourcecode in finite time (That's what we usually assume when we think about compiler ;) ).

    whole operation is going to take finite amount of computation time.

提交回复
热议问题