001    /*
002     *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003     *
004     *  This file is licensed to You under the Eclipse Public License (EPL);
005     *  You may not use this file except in compliance with the License. You
006     *  may obtain a copy of the License at
007     *
008     *      http://www.opensource.org/licenses/eclipse-1.0.php
009     *
010     *  See the COPYRIGHT.txt file distributed with this work for information
011     *  regarding copyright ownership.
012     */
013    package org.jikesrvm.compilers.opt.regalloc;
014    
015    import org.jikesrvm.compilers.opt.OptOptions;
016    import org.jikesrvm.compilers.opt.driver.CompilerPhase;
017    import org.jikesrvm.compilers.opt.driver.OptimizationPlanAtomicElement;
018    import org.jikesrvm.compilers.opt.driver.OptimizationPlanCompositeElement;
019    import org.jikesrvm.compilers.opt.driver.OptimizationPlanElement;
020    import org.jikesrvm.compilers.opt.ir.IR;
021    
022    /**
023     * Driver routine for register allocation
024     */
025    public final class RegisterAllocator extends OptimizationPlanCompositeElement {
026    
027      public RegisterAllocator() {
028        super("Register Allocation", new OptimizationPlanElement[]{
029            // 1. Prepare for the allocation
030            new OptimizationPlanAtomicElement(new RegisterAllocPreparation()),
031            // 2. Perform the allocation, using the live information
032            new LinearScan()});
033      }
034    
035      public boolean shouldPerform(OptOptions options) { return true; }
036    
037      public String getName() { return "RegAlloc"; }
038    
039      public boolean printingEnabled(OptOptions options, boolean before) {
040        return options.PRINT_REGALLOC;
041      }
042    
043      private static class RegisterAllocPreparation extends CompilerPhase {
044        public final boolean shouldPerform(OptOptions options) {
045          return true;
046        }
047    
048        /**
049         * Return this instance of this phase. This phase contains no
050         * per-compilation instance fields.
051         * @param ir not used
052         * @return this
053         */
054        public CompilerPhase newExecution(IR ir) {
055          return this;
056        }
057    
058        public final String getName() {
059          return "Register Allocation Preparation";
060        }
061    
062        /**
063         * create the stack manager
064         */
065        public final void perform(org.jikesrvm.compilers.opt.ir.IR ir) {
066          ir.stackManager.prepare(ir);
067        }
068      }
069    }