# HG changeset patch # User Thomas Wuerthinger # Date 1373326060 -7200 # Node ID b25a07ad3678784d1b7cf224bd9b82a892a27791 # Parent 89efc9dd9f8664844e82ea7b710fe977bae75179# Parent dad6e7ff1f93a489eb53c74c16f244a6c18a2de8 Merge. diff -r 89efc9dd9f86 -r b25a07ad3678 graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/AbstractPTXAssembler.java --- 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. } } diff -r 89efc9dd9f86 -r b25a07ad3678 graal/com.oracle.graal.asm/src/com/oracle/graal/asm/Label.java --- 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 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(); + } } diff -r 89efc9dd9f86 -r b25a07ad3678 graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXControlFlow.java --- 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);