# HG changeset patch # User Doug Simon # Date 1386939948 -3600 # Node ID da085171251983ec2952de0edd070451563cdf56 # Parent 755645fa92d60bd15e4acc14baf000c13684f9fb moved emitting code for LIR and queries about whether an edge goes to its lexical successor "inside" CompilationResultBuilder diff -r 755645fa92d6 -r da0851712519 graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java Fri Dec 13 13:32:11 2013 +0100 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java Fri Dec 13 14:05:48 2013 +0100 @@ -278,7 +278,7 @@ * @param installedCodeOwner see {@link Backend#emitCode} */ public void emitCodeBody(ResolvedJavaMethod installedCodeOwner, CompilationResultBuilder crb, LIRGenerator lirGen) { - lirGen.lir.emitCode(crb); + crb.emit(lirGen.lir); } /** diff -r 755645fa92d6 -r da0851712519 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java Fri Dec 13 13:32:11 2013 +0100 +++ b/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java Fri Dec 13 14:05:48 2013 +0100 @@ -297,7 +297,7 @@ } } // Prologue done, Emit code for the LIR. - lirGen.lir.emitCode(crb); + crb.emit(lirGen.lir); // Now that code is emitted go back and figure out what the upper Bound stack size was. long maxStackSize = ((HSAILAssembler) crb.asm).upperBoundStackSize(); String spillsegStringFinal; diff -r 755645fa92d6 -r da0851712519 graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java Fri Dec 13 13:32:11 2013 +0100 +++ b/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java Fri Dec 13 14:05:48 2013 +0100 @@ -284,7 +284,7 @@ } // Emit code for the LIR try { - lirGen.lir.emitCode(crb); + crb.emit(lirGen.lir); } catch (GraalInternalError e) { e.printStackTrace(); // TODO : Better error handling needs to be done once diff -r 755645fa92d6 -r da0851712519 graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackend.java Fri Dec 13 13:32:11 2013 +0100 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackend.java Fri Dec 13 14:05:48 2013 +0100 @@ -207,7 +207,7 @@ crb.recordMark(Marks.MARK_VERIFIED_ENTRY); // Emit code for the LIR - lirGen.lir.emitCode(crb); + crb.emit(lirGen.lir); HotSpotFrameContext frameContext = (HotSpotFrameContext) crb.frameContext; HotSpotForeignCallsProvider foreignCalls = getProviders().getForeignCalls(); diff -r 755645fa92d6 -r da0851712519 graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ControlFlow.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ControlFlow.java Fri Dec 13 13:32:11 2013 +0100 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ControlFlow.java Fri Dec 13 14:05:48 2013 +0100 @@ -73,12 +73,11 @@ @Override public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) { - int sourceIndex = crb.getCurrentBlockIndex(); - if (trueDestination.isCodeEmittingOrderSuccessorEdge(sourceIndex)) { + if (crb.isSuccessorEdge(trueDestination)) { jcc(masm, true, falseDestination); } else { jcc(masm, false, trueDestination); - if (!falseDestination.isCodeEmittingOrderSuccessorEdge(sourceIndex)) { + if (!crb.isSuccessorEdge(falseDestination)) { masm.jmp(falseDestination.label()); } } diff -r 755645fa92d6 -r da0851712519 graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILControlFlow.java --- a/graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILControlFlow.java Fri Dec 13 13:32:11 2013 +0100 +++ b/graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILControlFlow.java Fri Dec 13 14:05:48 2013 +0100 @@ -188,14 +188,13 @@ @Override public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - int sourceIndex = crb.getCurrentBlockIndex(); - if (trueDestination.isCodeEmittingOrderSuccessorEdge(sourceIndex)) { + if (crb.isSuccessorEdge(trueDestination)) { HSAILCompare.emit(crb, masm, condition.negate(), x, y, z, !unordered); masm.cbr(masm.nameOf(falseDestination.label())); } else { HSAILCompare.emit(crb, masm, condition, x, y, z, unordered); masm.cbr(masm.nameOf(trueDestination.label())); - if (!falseDestination.isCodeEmittingOrderSuccessorEdge(sourceIndex)) { + if (!crb.isSuccessorEdge(falseDestination)) { masm.jmp(falseDestination.label()); } } diff -r 755645fa92d6 -r da0851712519 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 Fri Dec 13 13:32:11 2013 +0100 +++ b/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXControlFlow.java Fri Dec 13 14:05:48 2013 +0100 @@ -85,12 +85,11 @@ @Override public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - int sourceIndex = crb.getCurrentBlockIndex(); - if (trueDestination.isCodeEmittingOrderSuccessorEdge(sourceIndex)) { + if (crb.isSuccessorEdge(trueDestination)) { masm.bra(masm.nameOf(falseDestination.label()), predRegNum); } else { masm.bra(masm.nameOf(trueDestination.label())); - if (!falseDestination.isCodeEmittingOrderSuccessorEdge(sourceIndex)) { + if (!crb.isSuccessorEdge(falseDestination)) { masm.jmp(falseDestination.label()); } } diff -r 755645fa92d6 -r da0851712519 graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCControlFlow.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCControlFlow.java Fri Dec 13 13:32:11 2013 +0100 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCControlFlow.java Fri Dec 13 14:05:48 2013 +0100 @@ -73,18 +73,17 @@ @Override public void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm) { - int sourceIndex = crb.getCurrentBlockIndex(); Label actualTarget; Condition actualCondition; boolean needJump; - if (trueDestination.isCodeEmittingOrderSuccessorEdge(sourceIndex)) { + if (crb.isSuccessorEdge(trueDestination)) { actualCondition = condition.negate(); actualTarget = falseDestination.label(); needJump = false; } else { actualCondition = condition; actualTarget = trueDestination.label(); - needJump = !falseDestination.isCodeEmittingOrderSuccessorEdge(sourceIndex); + needJump = !crb.isSuccessorEdge(falseDestination); } assert kind == Kind.Int || kind == Kind.Long || kind == Kind.Object; CC cc = kind == Kind.Int ? CC.Icc : CC.Xcc; diff -r 755645fa92d6 -r da0851712519 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIR.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIR.java Fri Dec 13 13:32:11 2013 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LIR.java Fri Dec 13 14:05:48 2013 +0100 @@ -25,11 +25,8 @@ import java.util.*; import com.oracle.graal.api.meta.*; -import com.oracle.graal.debug.*; -import com.oracle.graal.graph.*; import com.oracle.graal.lir.LIRInstruction.StateProcedure; import com.oracle.graal.lir.StandardOp.BlockEndOp; -import com.oracle.graal.lir.asm.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.cfg.*; @@ -138,44 +135,6 @@ firstVariableNumber = num; } - public void emitCode(CompilationResultBuilder crb) { - crb.frameContext.enter(crb); - - int index = 0; - for (Block b : codeEmittingOrder) { - crb.setCurrentBlockIndex(index++); - emitBlock(crb, b); - } - } - - private void emitBlock(CompilationResultBuilder crb, Block block) { - if (Debug.isDumpEnabled()) { - crb.blockComment(String.format("block B%d %s", block.getId(), block.getLoop())); - } - - for (LIRInstruction op : lir(block)) { - if (Debug.isDumpEnabled()) { - crb.blockComment(String.format("%d %s", op.id(), op)); - } - - try { - emitOp(crb, op); - } catch (GraalInternalError e) { - throw e.addContext("lir instruction", block + "@" + op.id() + " " + op + "\n" + codeEmittingOrder); - } - } - } - - private static void emitOp(CompilationResultBuilder crb, LIRInstruction op) { - try { - op.emitCode(crb); - } catch (AssertionError t) { - throw new GraalInternalError(t); - } catch (RuntimeException t) { - throw new GraalInternalError(t); - } - } - public void setHasArgInCallerFrame() { hasArgInCallerFrame = true; } diff -r 755645fa92d6 -r da0851712519 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LabelRef.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LabelRef.java Fri Dec 13 13:32:11 2013 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/LabelRef.java Fri Dec 13 14:05:48 2013 +0100 @@ -22,8 +22,6 @@ */ package com.oracle.graal.lir; -import java.util.*; - import com.oracle.graal.asm.*; import com.oracle.graal.lir.StandardOp.BranchOp; import com.oracle.graal.lir.StandardOp.JumpOp; @@ -78,19 +76,6 @@ return ((StandardOp.LabelOp) lir.lir(getTargetBlock()).get(0)).getLabel(); } - /** - * Determines if the edge represented by this object is from a block to its lexical successor in - * the code emitting order of blocks. - * - * @param sourceIndex the index of this edge's {@linkplain #getSourceBlock() source} in the code - * emitting order - */ - public boolean isCodeEmittingOrderSuccessorEdge(int sourceIndex) { - List order = lir.codeEmittingOrder(); - assert order.get(sourceIndex) == block; - return sourceIndex < order.size() - 1 && order.get(sourceIndex + 1) == getTargetBlock(); - } - @Override public String toString() { return getSourceBlock() + " -> " + (suxIndex < block.getSuccessors().size() ? getTargetBlock() : "?"); diff -r 755645fa92d6 -r da0851712519 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/StandardOp.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/StandardOp.java Fri Dec 13 13:32:11 2013 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/StandardOp.java Fri Dec 13 14:05:48 2013 +0100 @@ -113,7 +113,7 @@ @Override public void emitCode(CompilationResultBuilder crb) { - if (!destination.isCodeEmittingOrderSuccessorEdge(crb.getCurrentBlockIndex())) { + if (!crb.isSuccessorEdge(destination)) { crb.asm.jmp(destination.label()); } } diff -r 755645fa92d6 -r da0851712519 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/SwitchStrategy.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/SwitchStrategy.java Fri Dec 13 13:32:11 2013 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/SwitchStrategy.java Fri Dec 13 14:05:48 2013 +0100 @@ -116,9 +116,9 @@ } public void conditionalJumpOrDefault(int index, Condition condition, boolean canFallThrough) { - if (canFallThrough && defaultTarget.isCodeEmittingOrderSuccessorEdge(crb.getCurrentBlockIndex())) { + if (canFallThrough && crb.isSuccessorEdge(defaultTarget)) { conditionalJump(index, condition, keyTargets[index].label()); - } else if (canFallThrough && keyTargets[index].isCodeEmittingOrderSuccessorEdge(crb.getCurrentBlockIndex())) { + } else if (canFallThrough && crb.isSuccessorEdge(keyTargets[index])) { conditionalJump(index, condition.negate(), defaultTarget.label()); } else { conditionalJump(index, condition, keyTargets[index].label()); diff -r 755645fa92d6 -r da0851712519 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/asm/CompilationResultBuilder.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/asm/CompilationResultBuilder.java Fri Dec 13 13:32:11 2013 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/asm/CompilationResultBuilder.java Fri Dec 13 14:05:48 2013 +0100 @@ -32,6 +32,7 @@ import com.oracle.graal.debug.*; import com.oracle.graal.graph.*; import com.oracle.graal.lir.*; +import com.oracle.graal.nodes.cfg.*; /** * Fills in a {@link CompilationResult} as its code is being assembled. @@ -59,7 +60,12 @@ public final FrameMap frameMap; /** - * The index of the block currently being processed in the code emitting block order. + * The LIR for which code is being generated. + */ + private LIR lir; + + /** + * The index of the block currently being emitted. */ private int currentBlockIndex; @@ -285,16 +291,58 @@ } /** - * Gets the index of the block currently being processed in the code emitting block order. + * Determines if a given edge from the block currently being emitted goes to its lexical + * successor. */ - public int getCurrentBlockIndex() { - return currentBlockIndex; + public boolean isSuccessorEdge(LabelRef edge) { + assert lir != null; + List order = lir.codeEmittingOrder(); + assert order.get(currentBlockIndex) == edge.getSourceBlock(); + return currentBlockIndex < order.size() - 1 && order.get(currentBlockIndex + 1) == edge.getTargetBlock(); } /** - * Sets the index of the block currently being processed in the code emitting block order. + * Emits code for {@code lir} in its {@linkplain LIR#codeEmittingOrder() code emitting order}. */ - public void setCurrentBlockIndex(int index) { - this.currentBlockIndex = index; + public void emit(@SuppressWarnings("hiding") LIR lir) { + assert this.lir == null; + assert currentBlockIndex == 0; + this.lir = lir; + this.currentBlockIndex = 0; + frameContext.enter(this); + for (Block b : lir.codeEmittingOrder()) { + emitBlock(b); + currentBlockIndex++; + } + this.lir = null; + this.currentBlockIndex = 0; + } + + private void emitBlock(Block block) { + if (Debug.isDumpEnabled()) { + blockComment(String.format("block B%d %s", block.getId(), block.getLoop())); + } + + for (LIRInstruction op : lir.lir(block)) { + if (Debug.isDumpEnabled()) { + blockComment(String.format("%d %s", op.id(), op)); + } + + try { + emitOp(this, op); + } catch (GraalInternalError e) { + throw e.addContext("lir instruction", block + "@" + op.id() + " " + op + "\n" + lir.codeEmittingOrder()); + } + } + } + + private static void emitOp(CompilationResultBuilder crb, LIRInstruction op) { + try { + op.emitCode(crb); + } catch (AssertionError t) { + throw new GraalInternalError(t); + } catch (RuntimeException t) { + throw new GraalInternalError(t); + } } }