3 ms·
> Instead of using φ nodes, MLIR uses a functional form of SSA where terminators pass values into block arguments defined by the successor block. Does anyone k
by tom_mellior 7y ago
> Instead of using φ nodes, MLIR uses a functional form of SSA where terminators pass values into block arguments defined by the successor block.
Does anyone know if this equivalent (or very similar) to SSI (static single information) form? It would be cool to see something like this in a real-world compiler, since it is strictly more powerful than SSA. For example:
if (x == 0) { f(x); } else { g(x); }
Here SSA doesn't help you express "x == 0, but only in the first branch, and x != 0, but only in the second branch", while with the automatic renaming you get with SSI/"functional form" you can express this as something like (ugly syntax I made up on the spot):
if (x == 0)
{ f(x1); }[x1 = x]
else
{ g(x2); }[x2 = x]
and then just record the (now flow-insensitive) facts that x1 == 0 and x2 != 0.
- neel_k 7y agoBasic blocks with arguments is purely an alternate syntax for SSA. From a teaching perspective, I like blocks-with-arguments a lot better, since it lets students reuse their intuitions about tail-calling functions. However, there's no difference in expressive power between it and the standard SSA representation.
- tom_mellior 7y agoSo it doesn't actually introduce new, separate names for the values in the different successor blocks? There's no good example in the paper how this is actually used in practice.
- matt_d 7y agoSee also: https://mlir.llvm.org/docs/LangRef/#blocks https://mlir.llvm.org/docs/LangRef/#blocks "Context: The “block argument” representation eliminates a number of special cases from the IR compared to traditional “PHI nodes are operations” SSA IRs (like LLVM). For example, the parallel copy semantics of SSA is immediately apparent, and function arguments are no longer a special case: they become arguments to the entry block [ more rationale ]." Block Arguments vs PHI nodes: https://mlir.llvm.org/docs/Rationale/#block-arguments-vs-phi-nodes https://mlir.llvm.org/docs/Rationale/#block-arguments-vs-phi...
- tom_mellior 7y agoThanks for these pointers. > https://mlir.llvm.org/docs/LangRef/#blocks https://mlir.llvm.org/docs/LangRef/#blocks From the example there it's clear that the same value can have copies with different names, which would allow one to associate extra infos with the value used under certain names. In ^bb4 the same value can be accessed as %c, %d, or %e. In addition, this example really cannot be represented in the SSA flavor used by LLVM because LLVM does not have a copy instruction. > Block Arguments vs PHI nodes: https://mlir.llvm.org/docs/Rationale/#block-arguments-vs-phi.. https://mlir.llvm.org/docs/Rationale/#block-arguments-vs-phi.... That contradicts itself: "This choice is representationally identical (the same constructs can be represented in either form) [...] LLVM has no way to represent values that are available only in one successor but not the other". I'm still not convinced that these are just different syntaxes for the same thing.
- chrislattner 7y agoYou're right - BB arguments are more general than LLVM-style PHI nodes. They are a strict superset, but are otherwise isomorphic for the cases they both support. The talk we gave at CGO yesterday includes a few slides talking about the tradeoffs here. Those slides should be public in the next day or three.
- tom_mellior 7y agoI will be sure to check those out, thank you!
- deleted 7y ago[deleted]