changeset 6582:cc32ce37eddc

deleted Architecture.twoOperandMode() and encapsulated all public fields in Architecture with getters
author Doug Simon <doug.simon@oracle.com>
date Thu, 25 Oct 2012 20:08:32 +0200
parents 2a456986716b
children adb3879ffbe2
files graal/com.oracle.graal.amd64/src/com/oracle/graal/amd64/AMD64.java graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Architecture.java graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeUtil.java graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/TargetDescription.java graal/com.oracle.graal.asm/src/com/oracle/graal/asm/AbstractAssembler.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Call.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMap.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRVerifier.java graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CompilationPrinter.java
diffstat 11 files changed, 79 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.amd64/src/com/oracle/graal/amd64/AMD64.java	Thu Oct 25 14:50:14 2012 +0200
+++ b/graal/com.oracle.graal.amd64/src/com/oracle/graal/amd64/AMD64.java	Thu Oct 25 20:08:32 2012 +0200
@@ -114,9 +114,4 @@
               r15.encoding + 1,
               8);
     }
-
-    @Override
-    public boolean twoOperandMode() {
-        return true;
-    }
 }
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Architecture.java	Thu Oct 25 14:50:14 2012 +0200
+++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Architecture.java	Thu Oct 25 20:08:32 2012 +0200
@@ -45,60 +45,45 @@
      * The number of bits required in a bit map covering all the registers that may store references.
      * The bit position of a register in the map is the register's {@linkplain Register#number number}.
      */
-    public final int registerReferenceMapBitCount;
+    private final int registerReferenceMapBitCount;
 
     /**
      * Represents the natural size of words (typically registers and pointers) of this architecture, in bytes.
      */
-    public final int wordSize;
+    private final int wordSize;
 
     /**
      * The name of this architecture (e.g. "AMD64", "SPARCv9").
      */
-    public final String name;
+    private final String name;
 
     /**
      * Array of all available registers on this architecture. The index of each register in this
      * array is equal to its {@linkplain Register#number number}.
      */
-    public final Register[] registers;
-
-    /**
-     * Map of all registers keyed by their {@linkplain Register#name names}.
-     */
-    public final HashMap<String, Register> registersByName;
+    private final Register[] registers;
 
     /**
      * The byte ordering can be either little or big endian.
      */
-    public final ByteOrder byteOrder;
+    private final ByteOrder byteOrder;
 
     /**
      * Mask of the barrier constants denoting the barriers that
      * are not required to be explicitly inserted under this architecture.
      */
-    public final int implicitMemoryBarriers;
-
-    /**
-     * Determines the barriers in a given barrier mask that are explicitly required on this architecture.
-     *
-     * @param barriers a mask of the barrier constants
-     * @return the value of {@code barriers} minus the barriers unnecessary on this architecture
-     */
-    public final int requiredBarriers(int barriers) {
-        return barriers & ~implicitMemoryBarriers;
-    }
+    private final int implicitMemoryBarriers;
 
     /**
      * Offset in bytes from the beginning of a call instruction to the displacement.
      */
-    public final int machineCodeCallDisplacementOffset;
+    private final int machineCodeCallDisplacementOffset;
 
     /**
      * The size of the return address pushed to the stack by a call instruction.
      * A value of 0 denotes that call linkage uses registers instead (e.g. SPARC).
      */
-    public final int returnAddressSize;
+    private final int returnAddressSize;
 
     private final EnumMap<RegisterFlag, Register[]> registersByTypeAndEncoding;
 
@@ -133,12 +118,6 @@
         this.registerReferenceMapBitCount = registerReferenceMapBitCount;
         this.returnAddressSize = returnAddressSize;
 
-        registersByName = new HashMap<>(registers.length);
-        for (Register register : registers) {
-            registersByName.put(register.name, register);
-            assert registers[register.number] == register;
-        }
-
         registersByTypeAndEncoding = new EnumMap<>(RegisterFlag.class);
         EnumMap<RegisterFlag, Register[]> categorizedRegs = Register.categorize(registers);
         for (RegisterFlag type : RegisterFlag.values()) {
@@ -158,29 +137,69 @@
      */
     @Override
     public final String toString() {
-        return name.toLowerCase();
+        return getName().toLowerCase();
+    }
+
+    public int getRegisterReferenceMapBitCount() {
+        return registerReferenceMapBitCount;
     }
 
     /**
-     * Checks whether this is a 32-bit architecture.
-     * @return {@code true} if this architecture is 32-bit
+     * Gets the natural size of words (typically registers and pointers) of this architecture, in bytes.
      */
-    public final boolean is32bit() {
-        return wordSize == 4;
+    public int getWordSize() {
+        return wordSize;
+    }
+
+    /**
+     * Gets the name of this architecture.
+     */
+    public String getName() {
+        return name;
     }
 
     /**
-     * Checks whether this is a 64-bit architecture.
-     * @return {@code true} if this architecture is 64-bit
+     * Gets an array of all available registers on this architecture. The index of each register in this
+     * array is equal to its {@linkplain Register#number number}.
      */
-    public final boolean is64bit() {
-        return wordSize == 8;
+    public Register[] getRegisters() {
+        return registers.clone();
+    }
+
+    public ByteOrder getByteOrder() {
+        return byteOrder;
+    }
+
+    /**
+     * Gets a mask of the barrier constants denoting the barriers that
+     * are not required to be explicitly inserted under this architecture.
+     */
+    public int getImplicitMemoryBarriers() {
+        return implicitMemoryBarriers;
     }
 
     /**
-     * Checks whether this architecture's normal arithmetic instructions use a two-operand form
-     * (e.g. x86 which overwrites one operand register with the result when adding).
-     * @return {@code true} if this architecture uses two-operand mode
+     * Gets the size of the return address pushed to the stack by a call instruction.
+     * A value of 0 denotes that call linkage uses registers instead.
+     */
+    public int getReturnAddressSize() {
+        return returnAddressSize;
+    }
+
+    /**
+     * Gets the offset in bytes from the beginning of a call instruction to the displacement.
      */
-    public abstract boolean twoOperandMode();
+    public int getMachineCodeCallDisplacementOffset() {
+        return machineCodeCallDisplacementOffset;
+    }
+
+    /**
+     * Determines the barriers in a given barrier mask that are explicitly required on this architecture.
+     *
+     * @param barriers a mask of the barrier constants
+     * @return the value of {@code barriers} minus the barriers unnecessary on this architecture
+     */
+    public final int requiredBarriers(int barriers) {
+        return barriers & ~implicitMemoryBarriers;
+    }
 }
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeUtil.java	Thu Oct 25 14:50:14 2012 +0200
+++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeUtil.java	Thu Oct 25 20:08:32 2012 +0200
@@ -240,6 +240,8 @@
 
         public final Architecture arch;
 
+        private final Register[] registers;
+
         /**
          * The offset (in bytes) from the slot pointed to by {@link #fp} to the slot corresponding to bit 0 in the frame
          * reference map.
@@ -251,6 +253,7 @@
             this.slotSize = slotSize;
             this.fp = fp;
             this.refMapToFPOffset = refMapToFPOffset;
+            this.registers = arch.getRegisters();
         }
 
         public String formatStackSlot(int frameRefMapIndex) {
@@ -263,7 +266,7 @@
         }
 
         public String formatRegister(int regRefMapIndex) {
-            return arch.registers[regRefMapIndex].toString();
+            return registers[regRefMapIndex].toString();
         }
     }
 
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/TargetDescription.java	Thu Oct 25 14:50:14 2012 +0200
+++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/TargetDescription.java	Thu Oct 25 20:08:32 2012 +0200
@@ -101,7 +101,7 @@
         this.arch = arch;
         this.pageSize = pageSize;
         this.isMP = isMP;
-        this.wordSize = arch.wordSize;
+        this.wordSize = arch.getWordSize();
         if (wordSize == 8) {
             this.wordKind = Kind.Long;
         } else {
@@ -145,7 +145,7 @@
      * @return the aligned frame size
      */
     public int alignFrameSize(int frameSize) {
-        int x = frameSize + arch.returnAddressSize + (stackAlignment - 1);
-        return (x / stackAlignment) * stackAlignment - arch.returnAddressSize;
+        int x = frameSize + arch.getReturnAddressSize() + (stackAlignment - 1);
+        return (x / stackAlignment) * stackAlignment - arch.getReturnAddressSize();
     }
 }
--- a/graal/com.oracle.graal.asm/src/com/oracle/graal/asm/AbstractAssembler.java	Thu Oct 25 14:50:14 2012 +0200
+++ b/graal/com.oracle.graal.asm/src/com/oracle/graal/asm/AbstractAssembler.java	Thu Oct 25 20:08:32 2012 +0200
@@ -35,7 +35,7 @@
     public AbstractAssembler(TargetDescription target) {
         this.target = target;
 
-        if (target.arch.byteOrder == ByteOrder.BigEndian) {
+        if (target.arch.getByteOrder() == ByteOrder.BigEndian) {
             this.codeBuffer = new Buffer.BigEndian();
         } else {
             this.codeBuffer = new Buffer.LittleEndian();
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java	Thu Oct 25 14:50:14 2012 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java	Thu Oct 25 20:08:32 2012 +0200
@@ -163,7 +163,7 @@
         this.sortedBlocks = ir.linearScanOrder().toArray(new Block[ir.linearScanOrder().size()]);
         this.registerAttributes = frameMap.registerConfig.getAttributesMap();
 
-        this.registers = target.arch.registers;
+        this.registers = target.arch.getRegisters();
         this.firstVariableNumber = registers.length;
         this.variables = new ArrayList<>(ir.numVariables() * 3 / 2);
         this.blockData = new BlockMap<>(ir.cfg);
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Thu Oct 25 14:50:14 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Thu Oct 25 20:08:32 2012 +0200
@@ -228,7 +228,7 @@
     public String disassemble(CodeInfo info, CompilationResult tm) {
         byte[] code = info.getCode();
         TargetDescription target = graalRuntime.getTarget();
-        HexCodeFile hcf = new HexCodeFile(code, info.getStart(), target.arch.name, target.wordSize * 8);
+        HexCodeFile hcf = new HexCodeFile(code, info.getStart(), target.arch.getName(), target.wordSize * 8);
         if (tm != null) {
             HexCodeFile.addAnnotations(hcf, tm.getAnnotations());
             addExceptionHandlersComment(tm, hcf);
--- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Call.java	Thu Oct 25 14:50:14 2012 +0200
+++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Call.java	Thu Oct 25 20:08:32 2012 +0200
@@ -64,7 +64,7 @@
         protected void emitAlignmentForDirectCall(TargetMethodAssembler tasm, AMD64MacroAssembler masm) {
             // make sure that the displacement word of the call ends up word aligned
             int offset = masm.codeBuffer.position();
-            offset += tasm.target.arch.machineCodeCallDisplacementOffset;
+            offset += tasm.target.arch.getMachineCodeCallDisplacementOffset();
             while (offset++ % tasm.target.wordSize != 0) {
                 masm.nop();
             }
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMap.java	Thu Oct 25 14:50:14 2012 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMap.java	Thu Oct 25 20:08:32 2012 +0200
@@ -137,7 +137,7 @@
     }
 
     private int returnAddressSize() {
-        return target.arch.returnAddressSize;
+        return target.arch.getReturnAddressSize();
     }
 
     private int calleeSaveAreaSize() {
@@ -294,7 +294,7 @@
      * Initializes a reference map that covers all registers of the target architecture.
      */
     public BitSet initRegisterRefMap() {
-        return new BitSet(target.arch.registerReferenceMapBitCount);
+        return new BitSet(target.arch.getRegisterReferenceMapBitCount());
     }
 
     /**
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRVerifier.java	Thu Oct 25 14:50:14 2012 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIRVerifier.java	Thu Oct 25 20:08:32 2012 +0200
@@ -51,7 +51,7 @@
     }
 
     private int maxRegisterNum() {
-        return frameMap.target.arch.registers.length;
+        return frameMap.target.arch.getRegisters().length;
     }
 
     private boolean isAllocatableRegister(Value value) {
@@ -101,11 +101,12 @@
         ValueProcedure useProc = new ValueProcedure() { @Override public Value doValue(Value value, OperandMode mode, EnumSet<OperandFlag> flags) { return use(value, mode, flags); } };
         ValueProcedure defProc = new ValueProcedure() { @Override public Value doValue(Value value, OperandMode mode, EnumSet<OperandFlag> flags) { return def(value, mode, flags); } };
 
+        int maxRegisterNum = maxRegisterNum();
         curRegistersDefined = new BitSet();
         for (Block block : lir.linearScanOrder()) {
             curBlock = block;
             curVariablesLive = new BitSet();
-            curRegistersLive = new Value[maxRegisterNum()];
+            curRegistersLive = new Value[maxRegisterNum];
 
             if (block.getDominator() != null) {
                 curVariablesLive.or(liveOutFor(block.getDominator()));
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CompilationPrinter.java	Thu Oct 25 14:50:14 2012 +0200
+++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CompilationPrinter.java	Thu Oct 25 20:08:32 2012 +0200
@@ -117,8 +117,9 @@
 
         if (registerRefMap != null) {
             sb.append("reg-ref-map:");
+            Register[] registers = arch.getRegisters();
             for (int reg = registerRefMap.nextSetBit(0); reg >= 0; reg = registerRefMap.nextSetBit(reg + 1)) {
-                sb.append(' ').append(arch == null ? "r" + reg : arch.registers[reg]);
+                sb.append(' ').append(arch == null ? "r" + reg : registers[reg]);
             }
             sb.append("\n");
         }