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      @Override
036      public boolean shouldPerform(OptOptions options) { return true; }
037    
038      @Override
039      public String getName() { return "RegAlloc"; }
040    
041      @Override
042      public boolean printingEnabled(OptOptions options, boolean before) {
043        return options.PRINT_REGALLOC;
044      }
045    
046      private static class RegisterAllocPreparation extends CompilerPhase {
047        @Override
048        public final boolean shouldPerform(OptOptions options) {
049          return true;
050        }
051    
052        /**
053         * Return this instance of this phase. This phase contains no
054         * per-compilation instance fields.
055         * @param ir not used
056         * @return this
057         */
058        @Override
059        public CompilerPhase newExecution(IR ir) {
060          return this;
061        }
062    
063        @Override
064        public final String getName() {
065          return "Register Allocation Preparation";
066        }
067    
068        /**
069         * create the stack manager
070         */
071        @Override
072        public final void perform(org.jikesrvm.compilers.opt.ir.IR ir) {
073          ir.stackManager.prepare(ir);
074        }
075      }
076    }