changeset 9548:52353ed06cdf

Merge (fixed: 3fdbe6a68103 Pass fixed node into getMaterializedRepresentation.)
author Lukas Stadler <lukas.stadler@jku.at>
date Fri, 03 May 2013 20:24:49 +0200
parents 8b126a466917 (current diff) 3fdbe6a68103 (diff)
children c45c0bda3602
files
diffstat 11 files changed, 90 insertions(+), 137 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Register.java	Fri May 03 20:23:53 2013 +0200
+++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Register.java	Fri May 03 20:24:49 2013 +0200
@@ -23,7 +23,6 @@
 package com.oracle.graal.api.code;
 
 import java.io.*;
-import java.util.*;
 
 import com.oracle.graal.api.meta.*;
 
@@ -80,12 +79,6 @@
     private final RegisterCategory registerCategory;
 
     /**
-     * An array of {@link RegisterValue} objects, for this register, with one entry per {@link Kind}
-     * , indexed by {@link Kind#ordinal}.
-     */
-    private final HashMap<PlatformKind, RegisterValue> values;
-
-    /**
      * A platform specific register type that describes which values can be stored in a register.
      */
     public static class RegisterCategory {
@@ -115,7 +108,6 @@
         this.name = name;
         this.registerCategory = registerCategory;
         this.encoding = encoding;
-        this.values = new HashMap<>();
     }
 
     public RegisterCategory getRegisterCategory() {
@@ -129,13 +121,7 @@
      * @return the {@link RegisterValue}
      */
     public RegisterValue asValue(PlatformKind kind) {
-        if (values.containsKey(kind)) {
-            return values.get(kind);
-        } else {
-            RegisterValue ret = new RegisterValue(kind, this);
-            values.put(kind, ret);
-            return ret;
-        }
+        return new RegisterValue(kind, this);
     }
 
     /**
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/StackSlot.java	Fri May 03 20:23:53 2013 +0200
+++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/StackSlot.java	Fri May 03 20:24:49 2013 +0200
@@ -22,8 +22,6 @@
  */
 package com.oracle.graal.api.code;
 
-import java.util.*;
-
 import com.oracle.graal.api.meta.*;
 
 /**
@@ -48,21 +46,6 @@
      */
     public static StackSlot get(PlatformKind kind, int offset, boolean addFrameSize) {
         assert addFrameSize || offset >= 0;
-
-        if (offset % CACHE_GRANULARITY == 0) {
-            StackSlot slot;
-            if (!addFrameSize) {
-                slot = OUT_CACHE.lookup(kind, offset);
-            } else if (offset >= 0) {
-                slot = IN_CACHE.lookup(kind, offset);
-            } else {
-                slot = SPILL_CACHE.lookup(kind, offset);
-            }
-            if (slot != null) {
-                assert slot.getPlatformKind().equals(kind) && slot.offset == offset && slot.addFrameSize == addFrameSize;
-                return slot;
-            }
-        }
         return new StackSlot(kind, offset, addFrameSize);
     }
 
@@ -149,44 +132,4 @@
         }
         return this;
     }
-
-    private static final int SPILL_CACHE_PER_KIND_SIZE = 100;
-    private static final int PARAM_CACHE_PER_KIND_SIZE = 10;
-    private static final int CACHE_GRANULARITY = 8;
-
-    private static class Cache extends HashMap<PlatformKind, StackSlot[]> {
-
-        private static final long serialVersionUID = 4424132866289682843L;
-
-        private final int cachePerKindSize;
-        private final int sign;
-        private final boolean addFrameSize;
-
-        Cache(int cachePerKindSize, int sign, boolean addFrameSize) {
-            this.cachePerKindSize = cachePerKindSize;
-            this.sign = sign;
-            this.addFrameSize = addFrameSize;
-        }
-
-        StackSlot lookup(PlatformKind kind, int offset) {
-            int index = sign * offset / CACHE_GRANULARITY;
-            StackSlot[] slots = this.get(kind);
-            if (slots == null) {
-                slots = new StackSlot[cachePerKindSize];
-                for (int i = 0; i < cachePerKindSize; i++) {
-                    slots[i] = new StackSlot(kind, sign * i * CACHE_GRANULARITY, addFrameSize);
-                }
-                this.put(kind, slots);
-            }
-            if (index < slots.length) {
-                return slots[index];
-            } else {
-                return null;
-            }
-        }
-    }
-
-    private static final Cache SPILL_CACHE = new Cache(SPILL_CACHE_PER_KIND_SIZE, -1, true);
-    private static final Cache IN_CACHE = new Cache(PARAM_CACHE_PER_KIND_SIZE, 1, true);
-    private static final Cache OUT_CACHE = new Cache(PARAM_CACHE_PER_KIND_SIZE, 1, false);
 }
--- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java	Fri May 03 20:23:53 2013 +0200
+++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java	Fri May 03 20:24:49 2013 +0200
@@ -186,6 +186,16 @@
         super.emitCall(callTarget, result, arguments, temps, info);
     }
 
+    protected AMD64SaveRegistersOp emitSaveRegisters(Register[] savedRegisters, StackSlot[] savedRegisterLocations) {
+        AMD64SaveRegistersOp save = new AMD64SaveRegistersOp(savedRegisters, savedRegisterLocations);
+        append(save);
+        return save;
+    }
+
+    protected void emitRestoreRegisters(AMD64SaveRegistersOp save) {
+        append(new AMD64RestoreRegistersOp(save.getSlots().clone(), save));
+    }
+
     @Override
     public Variable emitCall(RuntimeCallTarget callTarget, CallingConvention cc, DeoptimizingNode info, Value... args) {
         Stub stub = runtime().asStub(method);
@@ -198,20 +208,13 @@
             if (stub.preservesRegisters()) {
                 Register[] savedRegisters = frameMap.registerConfig.getAllocatableRegisters();
                 savedRegisterLocations = new StackSlot[savedRegisters.length];
-                AMD64LIRInstruction[] savingMoves = new AMD64LIRInstruction[savedRegisters.length];
-                AMD64LIRInstruction[] restoringMoves = new AMD64LIRInstruction[savedRegisters.length];
                 for (int i = 0; i < savedRegisters.length; i++) {
                     PlatformKind kind = target.arch.getLargestStorableKind(savedRegisters[i].getRegisterCategory());
                     assert kind != Kind.Illegal;
                     StackSlot spillSlot = frameMap.allocateSpillSlot(kind);
                     savedRegisterLocations[i] = spillSlot;
-
-                    RegisterValue register = savedRegisters[i].asValue(kind);
-                    savingMoves[i] = createMove(spillSlot, register);
-                    restoringMoves[i] = createMove(register, spillSlot);
                 }
-                save = new AMD64SaveRegistersOp(savingMoves, restoringMoves, savedRegisterLocations);
-                append(save);
+                save = emitSaveRegisters(savedRegisters, savedRegisterLocations);
             }
             append(new AMD64HotSpotCRuntimeCallPrologueOp());
         }
@@ -224,7 +227,7 @@
                 assert !calleeSaveInfo.containsKey(currentRuntimeCallInfo);
                 calleeSaveInfo.put(currentRuntimeCallInfo, save);
 
-                append(new AMD64RestoreRegistersOp(savedRegisterLocations.clone(), save));
+                emitRestoreRegisters(save);
             } else {
                 assert zapRegisters();
             }
@@ -233,19 +236,21 @@
         return result;
     }
 
+    protected AMD64ZapRegistersOp emitZapRegisters(Register[] zappedRegisters, Constant[] zapValues) {
+        AMD64ZapRegistersOp zap = new AMD64ZapRegistersOp(zappedRegisters, zapValues);
+        append(zap);
+        return zap;
+    }
+
     protected boolean zapRegisters() {
         Register[] zappedRegisters = frameMap.registerConfig.getAllocatableRegisters();
-        AMD64LIRInstruction[] zappingMoves = new AMD64LIRInstruction[zappedRegisters.length];
+        Constant[] zapValues = new Constant[zappedRegisters.length];
         for (int i = 0; i < zappedRegisters.length; i++) {
             PlatformKind kind = target.arch.getLargestStorableKind(zappedRegisters[i].getRegisterCategory());
             assert kind != Kind.Illegal;
-
-            RegisterValue register = zappedRegisters[i].asValue(kind);
-            zappingMoves[i] = createMove(register, zapValueForKind(kind));
+            zapValues[i] = zapValueForKind(kind);
         }
-        AMD64ZapRegistersOp zap = new AMD64ZapRegistersOp(zappingMoves);
-        append(zap);
-        calleeSaveInfo.put(currentRuntimeCallInfo, zap);
+        calleeSaveInfo.put(currentRuntimeCallInfo, emitZapRegisters(zappedRegisters, zapValues));
         return true;
     }
 
--- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64RestoreRegistersOp.java	Fri May 03 20:23:53 2013 +0200
+++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64RestoreRegistersOp.java	Fri May 03 20:24:49 2013 +0200
@@ -33,7 +33,7 @@
  * Restores registers from stack slots.
  */
 @Opcode("RESTORE_REGISTER")
-public final class AMD64RestoreRegistersOp extends AMD64LIRInstruction {
+public class AMD64RestoreRegistersOp extends AMD64LIRInstruction {
 
     /**
      * The slots from which the registers are restored.
@@ -50,11 +50,21 @@
         this.save = save;
     }
 
+    protected Register[] getSavedRegisters() {
+        return save.savedRegisters;
+    }
+
+    protected void restoreRegister(TargetMethodAssembler tasm, AMD64MacroAssembler masm, Register register, StackSlot input) {
+        RegisterValue result = register.asValue(input.getKind());
+        AMD64Move.move(tasm, masm, result, input);
+    }
+
     @Override
     public void emitCode(TargetMethodAssembler tasm, AMD64MacroAssembler masm) {
-        for (AMD64LIRInstruction restoringMove : save.restoringMoves) {
-            if (restoringMove != null) {
-                restoringMove.emitCode(tasm, masm);
+        Register[] savedRegisters = getSavedRegisters();
+        for (int i = 0; i < savedRegisters.length; i++) {
+            if (savedRegisters[i] != null) {
+                restoreRegister(tasm, masm, savedRegisters[i], slots[i]);
             }
         }
     }
--- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64SaveRegistersOp.java	Fri May 03 20:23:53 2013 +0200
+++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64SaveRegistersOp.java	Fri May 03 20:24:49 2013 +0200
@@ -30,45 +30,47 @@
 import com.oracle.graal.asm.amd64.*;
 import com.oracle.graal.lir.*;
 import com.oracle.graal.lir.LIRInstruction.Opcode;
-import com.oracle.graal.lir.StandardOp.MoveOp;
 import com.oracle.graal.lir.asm.*;
 
 /**
  * Saves registers to stack slots.
  */
 @Opcode("SAVE_REGISTER")
-public final class AMD64SaveRegistersOp extends AMD64RegistersPreservationOp {
+public class AMD64SaveRegistersOp extends AMD64RegistersPreservationOp {
 
     /**
-     * The move instructions for saving the registers.
+     * The registers (potentially) saved by this operation.
      */
-    protected final AMD64LIRInstruction[] savingMoves;
-
-    /**
-     * The move instructions for restoring the registers.
-     */
-    protected final AMD64LIRInstruction[] restoringMoves;
+    protected final Register[] savedRegisters;
 
     /**
      * The slots to which the registers are saved.
      */
     @Def(STACK) protected final StackSlot[] slots;
 
-    public AMD64SaveRegistersOp(AMD64LIRInstruction[] savingMoves, AMD64LIRInstruction[] restoringMoves, StackSlot[] slots) {
-        this.savingMoves = savingMoves;
-        this.restoringMoves = restoringMoves;
+    public AMD64SaveRegistersOp(Register[] savedRegisters, StackSlot[] slots) {
+        this.savedRegisters = savedRegisters;
         this.slots = slots;
     }
 
+    protected void saveRegister(TargetMethodAssembler tasm, AMD64MacroAssembler masm, StackSlot result, Register register) {
+        RegisterValue input = register.asValue(result.getKind());
+        AMD64Move.move(tasm, masm, result, input);
+    }
+
     @Override
     public void emitCode(TargetMethodAssembler tasm, AMD64MacroAssembler masm) {
-        for (AMD64LIRInstruction savingMove : savingMoves) {
-            if (savingMove != null) {
-                savingMove.emitCode(tasm, masm);
+        for (int i = 0; i < savedRegisters.length; i++) {
+            if (savedRegisters[i] != null) {
+                saveRegister(tasm, masm, slots[i], savedRegisters[i]);
             }
         }
     }
 
+    public StackSlot[] getSlots() {
+        return slots;
+    }
+
     /**
      * Prunes the set of registers saved by this operation to exclude those in {@code ignored} and
      * updates {@code debugInfo} with a {@linkplain DebugInfo#getCalleeSaveInfo() description} of
@@ -77,12 +79,10 @@
     @Override
     public void update(Set<Register> ignored, DebugInfo debugInfo, FrameMap frameMap) {
         int preserved = 0;
-        for (int i = 0; i < savingMoves.length; i++) {
-            if (savingMoves[i] != null) {
-                Register register = ValueUtil.asRegister(((MoveOp) savingMoves[i]).getInput());
-                if (ignored.contains(register)) {
-                    savingMoves[i] = null;
-                    restoringMoves[i] = null;
+        for (int i = 0; i < savedRegisters.length; i++) {
+            if (savedRegisters[i] != null) {
+                if (ignored.contains(savedRegisters[i])) {
+                    savedRegisters[i] = null;
                 } else {
                     preserved++;
                 }
@@ -92,9 +92,9 @@
             Register[] keys = new Register[preserved];
             int[] values = new int[keys.length];
             int mapIndex = 0;
-            for (int i = 0; i < savingMoves.length; i++) {
-                if (savingMoves[i] != null) {
-                    keys[mapIndex] = ValueUtil.asRegister(((MoveOp) savingMoves[i]).getInput());
+            for (int i = 0; i < savedRegisters.length; i++) {
+                if (savedRegisters[i] != null) {
+                    keys[mapIndex] = savedRegisters[i];
                     values[mapIndex] = frameMap.indexForStackSlot(slots[i]);
                     mapIndex++;
                 }
--- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ZapRegistersOp.java	Fri May 03 20:23:53 2013 +0200
+++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ZapRegistersOp.java	Fri May 03 20:24:49 2013 +0200
@@ -22,13 +22,15 @@
  */
 package com.oracle.graal.lir.amd64;
 
+import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*;
+
 import java.util.*;
 
 import com.oracle.graal.api.code.*;
+import com.oracle.graal.api.meta.*;
 import com.oracle.graal.asm.amd64.*;
 import com.oracle.graal.lir.*;
 import com.oracle.graal.lir.LIRInstruction.Opcode;
-import com.oracle.graal.lir.StandardOp.MoveOp;
 import com.oracle.graal.lir.asm.*;
 
 /**
@@ -38,19 +40,26 @@
 public final class AMD64ZapRegistersOp extends AMD64RegistersPreservationOp {
 
     /**
-     * The move instructions for zapping the registers.
+     * The registers that are zapped.
      */
-    protected final AMD64LIRInstruction[] zappingMoves;
+    protected final Register[] zappedRegisters;
 
-    public AMD64ZapRegistersOp(AMD64LIRInstruction[] zappingMoves) {
-        this.zappingMoves = zappingMoves;
+    /**
+     * The garbage values that are written to the registers.
+     */
+    @Use({CONST}) protected Constant[] zapValues;
+
+    public AMD64ZapRegistersOp(Register[] zappedRegisters, Constant[] zapValues) {
+        this.zappedRegisters = zappedRegisters;
+        this.zapValues = zapValues;
     }
 
     @Override
     public void emitCode(TargetMethodAssembler tasm, AMD64MacroAssembler masm) {
-        for (AMD64LIRInstruction zappingMove : zappingMoves) {
-            if (zappingMove != null) {
-                zappingMove.emitCode(tasm, masm);
+        for (int i = 0; i < zappedRegisters.length; i++) {
+            if (zappedRegisters[i] != null) {
+                RegisterValue registerValue = zappedRegisters[i].asValue(zapValues[i].getPlatformKind());
+                AMD64Move.move(tasm, masm, registerValue, zapValues[i]);
             }
         }
     }
@@ -60,11 +69,10 @@
      */
     @Override
     public void update(Set<Register> ignored, DebugInfo debugInfo, FrameMap frameMap) {
-        for (int i = 0; i < zappingMoves.length; i++) {
-            if (zappingMoves[i] != null) {
-                Register register = ValueUtil.asRegister(((MoveOp) zappingMoves[i]).getResult());
-                if (ignored.contains(register)) {
-                    zappingMoves[i] = null;
+        for (int i = 0; i < zappedRegisters.length; i++) {
+            if (zappedRegisters[i] != null) {
+                if (ignored.contains(zappedRegisters[i])) {
+                    zappedRegisters[i] = null;
                 }
             }
         }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/virtual/VirtualArrayNode.java	Fri May 03 20:23:53 2013 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/virtual/VirtualArrayNode.java	Fri May 03 20:24:49 2013 +0200
@@ -140,7 +140,7 @@
     }
 
     @Override
-    public AllocatedObjectNode getMaterializedRepresentation(ValueNode[] entries, int[] locks) {
+    public AllocatedObjectNode getMaterializedRepresentation(FixedNode fixed, ValueNode[] entries, int[] locks) {
         return new AllocatedObjectNode(this);
     }
 }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/virtual/VirtualBoxingNode.java	Fri May 03 20:23:53 2013 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/virtual/VirtualBoxingNode.java	Fri May 03 20:24:49 2013 +0200
@@ -46,7 +46,7 @@
     }
 
     @Override
-    public ValueNode getMaterializedRepresentation(ValueNode[] entries, int[] locks) {
+    public ValueNode getMaterializedRepresentation(FixedNode fixed, ValueNode[] entries, int[] locks) {
         assert entries.length == 1;
         assert locks.length == 0;
         return new BoxNode(entries[0], type(), boxingKind);
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/virtual/VirtualInstanceNode.java	Fri May 03 20:23:53 2013 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/virtual/VirtualInstanceNode.java	Fri May 03 20:24:49 2013 +0200
@@ -96,7 +96,7 @@
     }
 
     @Override
-    public ValueNode getMaterializedRepresentation(ValueNode[] entries, int[] locks) {
+    public ValueNode getMaterializedRepresentation(FixedNode fixed, ValueNode[] entries, int[] locks) {
         return new AllocatedObjectNode(this);
     }
 }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/virtual/VirtualObjectNode.java	Fri May 03 20:23:53 2013 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/virtual/VirtualObjectNode.java	Fri May 03 20:24:49 2013 +0200
@@ -80,7 +80,7 @@
      * {@link AllocatedObjectNode} then this node will be attached to a {@link CommitAllocationNode}
      * , otherwise the node will just be added to the graph.
      */
-    public abstract ValueNode getMaterializedRepresentation(ValueNode[] entries, int[] locks);
+    public abstract ValueNode getMaterializedRepresentation(FixedNode fixed, ValueNode[] entries, int[] locks);
 
     @Override
     public void generate(LIRGeneratorTool gen) {
--- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/BlockState.java	Fri May 03 20:23:53 2013 +0200
+++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/BlockState.java	Fri May 03 20:24:49 2013 +0200
@@ -152,17 +152,18 @@
         List<ValueNode> values = new ArrayList<>(8);
         List<int[]> locks = new ArrayList<>(2);
         List<ValueNode> otherAllocations = new ArrayList<>(2);
-        materializeWithCommit(virtual, objects, locks, values, otherAllocations, state);
+        materializeWithCommit(fixed, virtual, objects, locks, values, otherAllocations, state);
 
         materializeEffects.addMaterializationBefore(fixed, objects, locks, values, otherAllocations);
     }
 
-    private void materializeWithCommit(VirtualObjectNode virtual, List<AllocatedObjectNode> objects, List<int[]> locks, List<ValueNode> values, List<ValueNode> otherAllocations, EscapeState state) {
+    private void materializeWithCommit(FixedNode fixed, VirtualObjectNode virtual, List<AllocatedObjectNode> objects, List<int[]> locks, List<ValueNode> values, List<ValueNode> otherAllocations,
+                    EscapeState state) {
         trace("materializing %s", virtual);
         ObjectState obj = getObjectState(virtual);
 
         ValueNode[] entries = obj.getEntries();
-        ValueNode representation = virtual.getMaterializedRepresentation(entries, obj.getLocks());
+        ValueNode representation = virtual.getMaterializedRepresentation(fixed, entries, obj.getLocks());
         obj.escape(representation, state);
         if (representation instanceof AllocatedObjectNode) {
             objects.add((AllocatedObjectNode) representation);
@@ -175,7 +176,7 @@
                 ObjectState entryObj = getObjectState(entries[i]);
                 if (entryObj != null) {
                     if (entryObj.isVirtual()) {
-                        materializeWithCommit(entryObj.getVirtualObject(), objects, locks, values, otherAllocations, state);
+                        materializeWithCommit(fixed, entryObj.getVirtualObject(), objects, locks, values, otherAllocations, state);
                     }
                     values.set(pos + i, entryObj.getMaterializedValue());
                 } else {