Skip to content
  • Erik Verbruggen's avatar
    V4: Split arguments/locals from temps. · 75c22465
    Erik Verbruggen authored
    
    
    There are a couple of reasons to split the temporaries off from the
    arguments and locals:
    
    Temporaries are invisible, and changes to them cannot be observed.
    On the other hand, arguments and locals are visible, and writes to them
    can be seen from other places (nested functions), or by using the
    arguments array. So, in practice these correspond to memory locations.
    (One could argue that if neither nested functions, nor eval(), nor
    arguments[] is used, the loads/stores are invisible too. But that's an
    optimization, and changing locals/arguments to temporaries can be done
    in a separate pass.)
    
    Because of the "volatile" nature of arguments and locals, their usage
    cannot be optimized. All optimizations (SSA construction, register
    allocation, copy elimination, etc.) work on temporaries. Being able to
    easily ignore all non-temporaries has the benefit that optimizations can
    be faster.
    
    Previously, Temps were not uniquely numbered: argument 1, local 1, and
    temporary 1 all had the same number and were distinguishable by their
    type. So, for any mapping from Temp to something else, a QHash was used.
    Now that Temps only hold proper temporaries, the indexes do uniquely
    identify them. Add to that the fact that after transforming to SSA form
    all temporaries are renumbered starting from 0 and without any holes in
    the numbering, many of those datastructures can be changed to simple
    vectors. That change gives a noticeable performance improvement.
    
    One implication of this change is that a number of functions that took
    a Temp as their argument, now need to take Temp-or-ArgLocal, so Expr.
    However, it turns out that there are very few places where that applies,
    as many of those places also need to take constants or names. However,
    explicitly separating memory loads/stores for arguments/locals from
    temporaries adds the benefit that it's now easier to do a peep-hole
    optimizer for those load/store operations in the future: when a load is
    directly preceded by a store, it can be eliminated if the value is
    still available in a temporary.
    
    Change-Id: I4114006b076795d9ea9fe3649cdb3b9d7b7508f0
    Reviewed-by: default avatarSimon Hausmann <simon.hausmann@digia.com>
    75c22465