Package org.ek9lang.compiler.phase9


package org.ek9lang.compiler.phase9
M - Intermediate Representation Analysis and Optimization.

This phase is designed to analyse and optimize the Intermediate Representation of the developed code.

While this could take quite a bit of effort, it's probably worth doing the basics and then consider what the final code generation layer will be. This could be Java byte code or LVM code.

Both of the above potential output forms have very good optimizers built in, so it might be worth depending on those initially.

IRAnalysis and IROptimisation are the main entry points for this phase.

  • Class
    Description
    THE record of which scopes are entered in which ACTIVATION during an IRStructureWalk: the operation body is one activation, and every per-iteration list (CompositeInstr.Activation.PER_ITERATION) starts a new one for as long as it is walked.
    MULTI THREADED over sources.
    SINGLE THREADED.
    The two ownership rules that need to know which instruction lists run once per loop ITERATION (an activation), not just which scope ids exist - EK9_IR_OWNERSHIP_MODEL.md §12, stage 0, stated in today's opcodes: A value is owned by the activation that makes it (model V-F, the A11 rule).
    THE ownership lowering (EK9_IR_OWNERSHIP_MODEL.md §11.1): rewrites every ownership-form instruction into today's opcodes, so both back ends keep consuming exactly what they consume now.
    THE per-path rules of the ownership form (EK9_IR_OWNERSHIP_STAGE4_DESIGN.md): V-A - every OWNED value is consumed exactly once on every path to a normal exit and to every exceptional exit - and V-J - a path that ends in a Panic owes nothing.
    THE local rules of the ownership form (EK9_IR_OWNERSHIP_MODEL.md §11.2; stage-1 design §7) - the ones that need only the structured lists, not a per-path analysis: V-C only an OWNED value is consumed, not twice in one straight list, and a value MOVED on a path (by DROP or a [consume] assignment) is not used after it on that path - its count now belongs to where it went, which may release it (Swift's use-after-move rule); V-D a CAST forwards its operand's kind, and consumes an OWNED operand; V-E the arms of a chain hand back values of one kind; V-F DROP_AT_EXIT names a scope open in the current activation (the A11 rule); V-G a slot's owner is open (or the CALLER or OBJECT) where the slot is first filled - its declaration, or its first [init] assignment when it is declared before its owner is entered (Contract 3: a try's resources and its region's first failure) - a slot is declared once per activation, and a slot is never itself dropped; V-H a consumed argument is consumed by its call; an unmanaged result carries no count; V-M the IR is in the ownership form ONLY: RETAIN, RELEASE, RELEASE_FIELD and SCOPE_REGISTER are OwnershipLowering's output, never phase 7's, and REFERENCE / TYPED_REFERENCE declares only a compiler temporary that holds no count of its own - every named variable is a SLOT_DECLARE with its owner (stage 3).
    THE backend-independent verifier of the ARC RETAIN/RELEASE/SCOPE balance invariant for the +1 ownership-transfer convention, over the LOWERED form - model rule V-L, run by OwnershipLowering on every construct it lowers (EK9_IR_OWNERSHIP_MODEL.md §11.2, stage 3).
    A single balance finding for one construct/operation.