1 /*
   2  * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   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.sparc;
  24 
  25 public interface SPARCLIRInstructionMixin {
  26 
  27     default boolean leavesRegisterWindow() {
  28         return false;
  29     }
  30 
  31     default SizeEstimate estimateSize() {
  32         return getSPARCLIRInstructionStore().estimate;
  33     }
  34 
  35     SPARCLIRInstructionMixinStore getSPARCLIRInstructionStore();
  36 
  37     /**
  38      * This class represents a size estimation of a particular LIR instruction. It contains a
  39      * pessimistic estimate of emitted SPARC instructions and emitted bytes into the constant
  40      * section.
  41      */
  42     class SizeEstimate {
  43         /**
  44          * Cache the first size definition (with just 0 as constant size).
  45          */
  46         private static final SizeEstimate[] cache = new SizeEstimate[5];
  47 
  48         static {
  49             for (int i = 0; i < cache.length; i++) {
  50                 cache[i] = new SizeEstimate(i, 0);
  51             }
  52         }
  53 
  54         public final int instructionSize;
  55         public final int constantSize;
  56 
  57         public SizeEstimate(int instructionSize, int constantSize) {
  58             this.instructionSize = instructionSize;
  59             this.constantSize = constantSize;
  60         }
  61 
  62         public static SizeEstimate create(int instructionSize, int constantSize) {
  63             if (constantSize == 0 && instructionSize < cache.length) {
  64                 return cache[instructionSize];
  65             } else {
  66                 return new SizeEstimate(instructionSize, constantSize);
  67             }
  68         }
  69 
  70         public static SizeEstimate create(int instructionSize) {
  71             if (instructionSize < cache.length) {
  72                 return cache[instructionSize];
  73             } else {
  74                 return new SizeEstimate(instructionSize, 0);
  75             }
  76         }
  77 
  78         @Override
  79         public String toString() {
  80             return "SE[i=" + instructionSize + ", c=" + constantSize + "]";
  81         }
  82     }
  83 
  84     class SPARCLIRInstructionMixinStore {
  85         public final SizeEstimate estimate;
  86         public SPARCDelayedControlTransfer delayedControlTransfer = SPARCDelayedControlTransfer.DUMMY;
  87 
  88         public SPARCLIRInstructionMixinStore(SizeEstimate estimate) {
  89             this.estimate = estimate;
  90         }
  91 
  92         @Override
  93         public String toString() {
  94             return estimate != null ? estimate.toString() : "";
  95         }
  96     }
  97 }