package com.seaofnodes.simple.codegen; import com.seaofnodes.simple.node.*; import com.seaofnodes.simple.type.Type; import com.seaofnodes.simple.type.TypeMem; abstract public class BuildLRG { // Compute live ranges in a single forwards pass. Every def is a new live // range except live ranges are joined at Phi. Also, gather the // intersection of register masks in each live range. Example: "free // always zero" register forces register zero, and calling conventions // typically force registers. // Sets FAILED to the set of hard-conflicts (means no need for an IFG, // since it will not color, just split the conflicted ranges now). Returns // true if no hard-conflicts, although we still might not color. public static boolean run(int round, RegAlloc alloc) { FunNode fun = null; for( Node bb : alloc._code._cfg ) { if( bb instanceof FunNode fun2 ) fun = fun2; for( Node n : bb.outs() ) { // A synthetic never-exit value has no runtime definition. if( n._type==Type.TOP ) continue; if( n instanceof PhiNode phi && !(phi._type instanceof TypeMem) ) { if( phi instanceof MachNode mach && mach.outregmap()==null ) continue; // All real Phi inputs end up with the same LRG. // Pass 1: find any pre-existing LRG, to avoid make-then-Union a LRG LRG lrg = alloc.lrg(phi); if( lrg == null ) for( int i=1; i