changeset 10661:b25a07ad3678

Merge.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 09 Jul 2013 01:27:40 +0200
parents 89efc9dd9f86 (current diff) dad6e7ff1f93 (diff)
children 4ef92b67aeae 41362ec88331
files
diffstat 3 files changed, 40 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/AbstractPTXAssembler.java	Tue Jul 09 01:27:33 2013 +0200
+++ b/graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/AbstractPTXAssembler.java	Tue Jul 09 01:27:40 2013 +0200
@@ -34,12 +34,10 @@
         super(target);
     }
 
-    public static final String UNBOUND_TARGET = "L" + Integer.MAX_VALUE;
-
     @Override
     public final void bind(Label l) {
         super.bind(l);
-        emitString0("L" + l.toString() + ":\n");
+        emitString0(l.name() + ":\n");
     }
 
     @Override
@@ -54,10 +52,7 @@
 
     @Override
     protected void patchJumpTarget(int branch, int jumpTarget) {
-        final int spaces = UNBOUND_TARGET.length();
-        String targetString = String.format("L%-" + spaces + "s", jumpTarget + ";");
-        int offset = "\tbra ".length();  // XXX we need a better way to figure this out
-        codeBuffer.emitString(targetString, branch + offset);
+        // Nothing to do. All branches already point to the right label.
     }
 
 }
--- a/graal/com.oracle.graal.asm/src/com/oracle/graal/asm/Label.java	Tue Jul 09 01:27:33 2013 +0200
+++ b/graal/com.oracle.graal.asm/src/com/oracle/graal/asm/Label.java	Tue Jul 09 01:27:40 2013 +0200
@@ -23,12 +23,26 @@
 package com.oracle.graal.asm;
 
 import java.util.ArrayList;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * This class represents a label within assembly code.
  */
 public final class Label {
 
+    /**
+     * Counter used for sequential numbering.
+     */
+    private static AtomicInteger globalId = new AtomicInteger(0);
+
+    /**
+     * Unique identifier of this label.
+     */
+    private int id;
+
+    /**
+     * Position of this label in the code buffer.
+     */
     private int position = -1;
 
     /**
@@ -38,6 +52,10 @@
      */
     private ArrayList<Integer> patchPositions = new ArrayList<>(4);
 
+    public Label() {
+        id = globalId.getAndIncrement();
+    }
+
     /**
      * Returns the position of this label in the code buffer.
      * 
@@ -48,7 +66,13 @@
         return position;
     }
 
-    public Label() {
+    /**
+     * Returns the unique identifier of this Label.
+     * 
+     * @return the unique identifier
+     */
+    public int id() {
+        return id;
     }
 
     /**
@@ -66,7 +90,7 @@
     }
 
     public void addPatchAt(int branchLocation) {
-        assert !isBound() : "Label is already bound";
+        assert !isBound() : "Label " + name() + " is already bound: position=" + position + ", branchLocation=" + branchLocation;
         patchPositions.add(branchLocation);
     }
 
@@ -83,4 +107,13 @@
     public String toString() {
         return isBound() ? String.valueOf(position()) : "?";
     }
+
+    /**
+     * Returns a unique name of this Label. The name is based on the unique identifier.
+     * 
+     * @return the unique name
+     */
+    public String name() {
+        return "L" + id();
+    }
 }
--- a/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXControlFlow.java	Tue Jul 09 01:27:33 2013 +0200
+++ b/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXControlFlow.java	Tue Jul 09 01:27:40 2013 +0200
@@ -35,7 +35,6 @@
 import com.oracle.graal.asm.Buffer;
 import com.oracle.graal.asm.Label;
 import com.oracle.graal.asm.NumUtil;
-import com.oracle.graal.asm.ptx.AbstractPTXAssembler;
 import com.oracle.graal.asm.ptx.PTXAssembler;
 import com.oracle.graal.graph.GraalInternalError;
 import com.oracle.graal.lir.LabelRef;
@@ -78,9 +77,7 @@
         public void emitCode(TargetMethodAssembler tasm, PTXAssembler masm) {
             masm.at();
             Label l = destination.label();
-            // l.addPatchAt(tasm.asm.codeBuffer.position());
-            String target = l.isBound() ? "L" + l.toString() : AbstractPTXAssembler.UNBOUND_TARGET;
-            masm.bra(target);
+            masm.bra(l.name());
         }
 
         @Override
@@ -173,9 +170,7 @@
                     masm.setp_eq_s32((int) lc, intKey);
                     masm.at();
                     Label l = keyTargets[i].label();
-                    l.addPatchAt(tasm.asm.codeBuffer.position());
-                    String target = l.isBound() ? "L" + l.toString() : AbstractPTXAssembler.UNBOUND_TARGET;
-                    masm.bra(target);
+                    masm.bra(l.name());
                 }
             } else if (key.getKind() == Kind.Long) {
                 Register longKey = asLongReg(key);
@@ -183,9 +178,7 @@
                     masm.setp_eq_s64(tasm.asLongConst(keyConstants[i]), longKey);
                     masm.at();
                     Label l = keyTargets[i].label();
-                    l.addPatchAt(tasm.asm.codeBuffer.position());
-                    String target = l.isBound() ? "L" + l.toString() : AbstractPTXAssembler.UNBOUND_TARGET;
-                    masm.bra(target);
+                    masm.bra(l.name());
                 }
             } else if (key.getKind() == Kind.Object) {
                 Register intKey = asObjectReg(key);