29  Legality

Legality is the explicit rule that determines whether IR is permitted at a particular conversion stage. It is not a statement that an operation is well-formed in general. An operation can be valid MLIR and still be illegal because a target stage requires it to be lowered away.

29.2 Legality Is Not Profitability

A legal operation need not be the best form for performance. A conversion target answers what the next stage can accept; a cost model answers which legal option is preferable. Mixing these decisions leads to conversion rules that sometimes fail based on optimization heuristics, making pipelines unreliable.

Dynamic legality should express a real boundary, not hide uncertainty. If a predicate cannot explain why an operation is legal, the conversion is probably missing an explicit representation or a later stage.