9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.lir.alloc.lsra; 24 25 import org.graalvm.compiler.debug.Debug; 26 import org.graalvm.compiler.debug.Indent; 27 import org.graalvm.compiler.lir.gen.LIRGenerationResult; 28 import org.graalvm.compiler.lir.phases.AllocationPhase; 29 30 import jdk.vm.ci.code.TargetDescription; 31 32 public final class LinearScanRegisterAllocationPhase extends AllocationPhase { 33 34 private final LinearScan allocator; 35 36 LinearScanRegisterAllocationPhase(LinearScan allocator) { 37 this.allocator = allocator; 38 } 39 40 @Override 41 protected void run(TargetDescription target, LIRGenerationResult lirGenRes, AllocationContext context) { 42 allocator.printIntervals("Before register allocation"); 43 allocateRegisters(); 44 allocator.printIntervals("After register allocation"); 45 } 46 47 @SuppressWarnings("try") 48 void allocateRegisters() { 49 try (Indent indent = Debug.logAndIndent("allocate registers")) { 50 Interval precoloredIntervals; 51 Interval notPrecoloredIntervals; 52 53 Interval.Pair result = allocator.createUnhandledLists(LinearScan.IS_PRECOLORED_INTERVAL, LinearScan.IS_VARIABLE_INTERVAL); 54 precoloredIntervals = result.first; 55 notPrecoloredIntervals = result.second; 56 57 // allocate cpu registers 58 LinearScanWalker lsw; 59 if (OptimizingLinearScanWalker.Options.LSRAOptimization.getValue()) { 60 lsw = new OptimizingLinearScanWalker(allocator, precoloredIntervals, notPrecoloredIntervals); 61 } else { 62 lsw = new LinearScanWalker(allocator, precoloredIntervals, notPrecoloredIntervals); 63 } 64 lsw.walk(); 65 lsw.finishAllocation(); 66 } 67 } 68 69 } | 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.lir.alloc.lsra; 24 25 import org.graalvm.compiler.debug.Debug; 26 import org.graalvm.compiler.debug.Indent; 27 import org.graalvm.compiler.lir.gen.LIRGenerationResult; 28 import org.graalvm.compiler.lir.phases.AllocationPhase; 29 import org.graalvm.util.Pair; 30 31 import jdk.vm.ci.code.TargetDescription; 32 33 public final class LinearScanRegisterAllocationPhase extends AllocationPhase { 34 35 private final LinearScan allocator; 36 37 LinearScanRegisterAllocationPhase(LinearScan allocator) { 38 this.allocator = allocator; 39 } 40 41 @Override 42 protected void run(TargetDescription target, LIRGenerationResult result, AllocationContext context) { 43 allocator.printIntervals("Before register allocation"); 44 allocateRegisters(); 45 allocator.printIntervals("After register allocation"); 46 } 47 48 @SuppressWarnings("try") 49 void allocateRegisters() { 50 try (Indent indent = Debug.logAndIndent("allocate registers")) { 51 Interval precoloredIntervals; 52 Interval notPrecoloredIntervals; 53 54 Pair<Interval, Interval> result = allocator.createUnhandledLists(LinearScan.IS_PRECOLORED_INTERVAL, LinearScan.IS_VARIABLE_INTERVAL); 55 precoloredIntervals = result.getLeft(); 56 notPrecoloredIntervals = result.getRight(); 57 58 // allocate cpu registers 59 LinearScanWalker lsw; 60 if (OptimizingLinearScanWalker.Options.LSRAOptimization.getValue(allocator.getOptions())) { 61 lsw = new OptimizingLinearScanWalker(allocator, precoloredIntervals, notPrecoloredIntervals); 62 } else { 63 lsw = new LinearScanWalker(allocator, precoloredIntervals, notPrecoloredIntervals); 64 } 65 lsw.walk(); 66 lsw.finishAllocation(); 67 } 68 } 69 70 } |