Search code examples
javascriptcompilationv8jit

Questions about the uniqueness of turbofan IR execution


I'm doing some research on the turbofan of the V8, and I've got a few questions about Turbofan IR:

  1. Is the order of execution of the turbofan IR unique? Tf not unique, what is the reason?
  2. Is there any property that holds in terms of uniqueness? (e.g. uniqueness is preserved in some kind of block units.)
  3. Are there cases where there is no side-effect edge between two operations where side-effect actually exists?

+) Is there any document that describes the semantics of the Turbofan IR? I've found out that this IR originates from Sea-of-Node(by Cliff Click), and so gained some hints from his papers. However, the IR of the turbofan seems to be a little different from the original. For example, there is no effect edge at the original Sea-of-Node. So if there is any document explaining the Turbofan IR, it would be really helpful.

Thanks.


Solution

    1. The observable order of operations must (of course!) not be changed by the compiler. Considering the example you mentioned in comments:
    console.log(1);
    console.log(2);
    

    the compiler must not reorder the two calls, because that would change the program's behavior, and that's not something compilers are allowed to do (for obvious reasons).
    Non-observable instructions can be reordered in any way the compiler wants. For example, 1 + x + 2 could be reordered to x + 1 + 2 and then simplified to x + 3.
    (Note that this has nothing to do with Turbofan (or even JavaScript), it's a general statement that applies to all compilers for all languages.)

    1. Turbofan uses "effect" edges between Nodes to ensure that the observable order of operations is always preserved.

    2. That would be a bug.

    You can find some documentation here: https://v8.dev/docs/turbofan