changeset 3118:ce12808b8ff2

Changed the way the compare instructions are generated in the LIRGenerator.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Thu, 30 Jun 2011 16:07:18 +0200
parents f02897fb8c9e
children 00ad6539b7dc
files graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/ControlFlowOptimizer.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IsType.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/LIRAssembler.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/LIRBlock.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/LIRBranch.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/LIRXirInstruction.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/DeadCodeEliminationPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRAssembler.java
diffstat 10 files changed, 111 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java	Wed Jun 29 16:19:51 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java	Thu Jun 30 16:07:18 2011 +0200
@@ -73,9 +73,13 @@
             @Override
             public void verificationFailed(Node n, String message) {
                 GraalCompiler.this.fireCompilationEvent(new CompilationEvent(currentCompilation, "Verification Error on Node " + n.id(), currentCompilation.graph, true, false));
+                TTY.println(n.toString());
                 for (Node p : n.predecessors()) {
                     TTY.println("predecessor: " + p);
                 }
+                for (Node p : n.usages()) {
+                    TTY.println("usage: " + p);
+                }
                 assert false : "Verification of node " + n + " failed: " + message;
             }
         });
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/ControlFlowOptimizer.java	Wed Jun 29 16:19:51 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/ControlFlowOptimizer.java	Thu Jun 30 16:07:18 2011 +0200
@@ -246,8 +246,8 @@
             for (LIRInstruction instr : instructions) {
                 if (instr instanceof LIRBranch) {
                     LIRBranch opBranch = (LIRBranch) instr;
-                    assert opBranch.block() == null || code.contains(opBranch.block()) : "missing successor branch from: " + block + " to: " + opBranch.block();
-                    assert opBranch.unorderedBlock() == null || code.contains(opBranch.unorderedBlock()) : "missing successor branch from: " + block + " to: " + opBranch.unorderedBlock();
+                    assert opBranch.block() == null || opBranch.block().blockID() == -1 || code.contains(opBranch.block()) : "missing successor branch from: " + block + " to: " + opBranch.block();
+                    assert opBranch.unorderedBlock() == null || opBranch.unorderedBlock().blockID() == -1 || code.contains(opBranch.unorderedBlock()) : "missing successor branch from: " + block + " to: " + opBranch.unorderedBlock();
                 }
             }
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Wed Jun 29 16:19:51 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Thu Jun 30 16:07:18 2011 +0200
@@ -461,12 +461,8 @@
 
     @Override
     public void visitIf(If x) {
-        Condition cond = emitBooleanBranch(x.compare());
-        emitBranch(x.compare(), cond, getLIRBlock(x.trueSuccessor()), getLIRBlock(x.falseSuccessor()));
-        assert x.defaultSuccessor() == x.falseSuccessor() : "wrong destination above";
-        LIRBlock block = getLIRBlock(x.defaultSuccessor());
-        assert block != null : x;
-        lir.jump(block);
+        assert x.defaultSuccessor() == x.falseSuccessor() : "wrong destination";
+        emitBooleanBranch(x.compare(), getLIRBlock(x.trueSuccessor()),  getLIRBlock(x.falseSuccessor()));
     }
 
     public void emitBranch(BooleanNode n, Condition cond, LIRBlock trueSuccessor, LIRBlock falseSucc) {
@@ -484,18 +480,26 @@
         lir.branch(cond, trueSuccessor);
     }
 
-    public Condition emitBooleanBranch(BooleanNode node) {
+    public void emitBooleanBranch(BooleanNode node, LIRBlock trueSuccessor, LIRBlock falseSuccessor) {
         if (node instanceof Compare) {
-            return emitCompare((Compare) node);
+            emitCompare((Compare) node, trueSuccessor, falseSuccessor);
         } else {
             throw Util.unimplemented(node.toString());
         }
     }
 
-    public Condition emitCompare(Compare compare) {
+    public void emitCompare(Compare compare, LIRBlock trueSuccessorBlock, LIRBlock falseSuccessorBlock) {
         CiKind kind = compare.x().kind;
 
         Condition cond = compare.condition();
+        boolean unorderedIsTrue = compare.unorderedIsTrue();
+
+        if (trueSuccessorBlock == null) {
+            cond = cond.negate();
+            unorderedIsTrue = !unorderedIsTrue;
+            trueSuccessorBlock = falseSuccessorBlock;
+            falseSuccessorBlock = null;
+        }
 
         LIRItem xitem = new LIRItem(compare.x(), this);
         LIRItem yitem = new LIRItem(compare.y(), this);
@@ -523,7 +527,20 @@
         CiValue left = xin.result();
         CiValue right = yin.result();
         lir.cmp(cond, left, right);
-        return cond;
+
+        if (compare.x().kind.isFloat() || compare.x().kind.isDouble()) {
+            LIRBlock unorderedSuccBlock = falseSuccessorBlock;
+            if (unorderedIsTrue) {
+                unorderedSuccBlock = trueSuccessorBlock;
+            }
+            lir.branch(cond, trueSuccessorBlock, unorderedSuccBlock);
+        } else {
+            lir.branch(cond, trueSuccessorBlock);
+        }
+
+        if (falseSuccessorBlock != null) {
+            lir.jump(falseSuccessorBlock);
+        }
     }
 
     @Override
@@ -743,12 +760,10 @@
             if (deoptimizationStubs == null) {
                 deoptimizationStubs = new ArrayList<DeoptimizationStub>();
             }
-
             DeoptimizationStub stub = new DeoptimizationStub(DeoptAction.InvalidateReprofile, state);
             deoptimizationStubs.add(stub);
 
-            Condition cond = emitBooleanBranch(comp);
-            lir.branch(cond.negate(), stub.label, stub.info);
+            emitBooleanBranch(comp, null, new LIRBlock(stub.label, stub.info));
         }
     }
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IsType.java	Wed Jun 29 16:19:51 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IsType.java	Thu Jun 30 16:07:18 2011 +0200
@@ -95,7 +95,7 @@
     public boolean valueEqual(Node i) {
         if (i instanceof IsType) {
             IsType o = (IsType) i;
-            return type == o.type() && object() == o.object();
+            return type == o.type();
         }
         return false;
     }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/LIRAssembler.java	Wed Jun 29 16:19:51 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/LIRAssembler.java	Thu Jun 30 16:07:18 2011 +0200
@@ -49,7 +49,6 @@
     public int registerRestoreEpilogueOffset = -1;
 
     protected final List<SlowPath> xirSlowPath;
-    protected final List<LIRBlock> branchTargetBlocks;
 
     private int lastDecodeStart;
 
@@ -70,7 +69,6 @@
         this.tasm = compilation.assembler();
         this.asm = tasm.asm;
         this.frameMap = compilation.frameMap();
-        this.branchTargetBlocks = new ArrayList<LIRBlock>();
         this.xirSlowPath = new ArrayList<SlowPath>();
     }
 
@@ -164,12 +162,12 @@
     }
 
     boolean checkNoUnboundLabels() {
-        for (int i = 0; i < branchTargetBlocks.size() - 1; i++) {
-            if (!branchTargetBlocks.get(i).label().isBound()) {
-                TTY.println(String.format("label of block B%d is not bound", branchTargetBlocks.get(i).blockID()));
-                assert false : "unbound label";
-            }
-        }
+//        for (int i = 0; i < branchTargetBlocks.size() - 1; i++) {
+//            if (!branchTargetBlocks.get(i).label().isBound()) {
+//                TTY.println(String.format("label of block B%d is not bound", branchTargetBlocks.get(i).blockID()));
+//                assert false : "unbound label";
+//            }
+//        }
 
         return true;
     }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/LIRBlock.java	Wed Jun 29 16:19:51 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/LIRBlock.java	Thu Jun 30 16:07:18 2011 +0200
@@ -36,13 +36,14 @@
  */
 public final class LIRBlock {
 
-    public final Label label = new Label();
+    public final Label label;
     private LIRList lir;
     private final int blockID;
     private FrameState lastState;
     private List<Node> instructions = new ArrayList<Node>(4);
     private List<LIRBlock> predecessors = new ArrayList<LIRBlock>(4);
     private List<LIRBlock> successors = new ArrayList<LIRBlock>(4);
+    private LIRDebugInfo debugInfo;
 
     /**
      * Bit map specifying which {@linkplain OperandPool operands} are live upon entry to this block.
@@ -77,10 +78,24 @@
     private int lastLirInstructionID;
     public int blockEntryPco;
 
+    public LIRBlock(Label label, LIRDebugInfo debugInfo) {
+        this.label = label;
+        blockID = -1;
+        this.debugInfo = debugInfo;
+    }
+
+    public LIRDebugInfo debugInfo() {
+        return this.debugInfo;
+    }
+
     public LIRBlock(int blockID) {
         this.blockID = blockID;
+        label = new Label();
         loopIndex = -1;
         linearScanNumber = blockID;
+        instructions = new ArrayList<Node>(4);
+        predecessors = new ArrayList<LIRBlock>(4);
+        successors = new ArrayList<LIRBlock>(4);
     }
 
     public List<Node> getInstructions() {
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/LIRBranch.java	Wed Jun 29 16:19:51 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/LIRBranch.java	Thu Jun 30 16:07:18 2011 +0200
@@ -73,7 +73,7 @@
      *
      */
     public LIRBranch(Condition cond, LIRBlock block) {
-        super(LIROpcode.Branch, CiValue.IllegalValue, null, false);
+        super(LIROpcode.Branch, CiValue.IllegalValue, block.debugInfo(), false);
         this.cond = cond;
         this.label = block.label();
         this.block = block;
@@ -81,7 +81,7 @@
     }
 
     public LIRBranch(Condition cond, LIRBlock block, LIRBlock ublock) {
-        super(LIROpcode.CondFloatBranch, CiValue.IllegalValue, null, false);
+        super(LIROpcode.CondFloatBranch, CiValue.IllegalValue, (block.debugInfo() != null ? block.debugInfo() : (ublock != null ? ublock.debugInfo() : null)), false);
         this.cond = cond;
         this.label = block.label();
         this.block = block;
@@ -116,11 +116,6 @@
         this.label = b.label();
     }
 
-    public void changeUblock(LIRBlock b) {
-        assert unorderedBlock != null : "must have old block";
-        this.unorderedBlock = b;
-    }
-
     public void negateCondition() {
         cond = cond.negate();
     }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/LIRXirInstruction.java	Wed Jun 29 16:19:51 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/LIRXirInstruction.java	Thu Jun 30 16:07:18 2011 +0200
@@ -42,6 +42,8 @@
     public final int inputCount;
     public final List<CiValue> pointerSlots;
     public final LIRDebugInfo infoAfter;
+    private LIRBlock trueSuccessor;
+    private LIRBlock falseSuccessor;
 
     public LIRXirInstruction(XirSnippet snippet,
                              CiValue[] originalOperands,
@@ -71,6 +73,24 @@
         GraalMetrics.LIRXIRInstructions++;
     }
 
+
+    public void setFalseSuccessor(LIRBlock falseSuccessor) {
+        this.falseSuccessor = falseSuccessor;
+    }
+
+
+    public void setTrueSuccessor(LIRBlock trueSuccessor) {
+        this.trueSuccessor = trueSuccessor;
+    }
+
+    public LIRBlock falseSuccessor() {
+        return falseSuccessor;
+    }
+
+    public LIRBlock trueSuccessor() {
+        return trueSuccessor;
+    }
+
     public CiValue[] getOperands() {
         for (int i = 0; i < operandIndices.length; i++) {
             originalOperands[operandIndices[i]] = operand(i);
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/DeadCodeEliminationPhase.java	Wed Jun 29 16:19:51 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/DeadCodeEliminationPhase.java	Thu Jun 30 16:07:18 2011 +0200
@@ -52,8 +52,10 @@
         for (Merge merge : graph.getNodes(Merge.class)) {
             if (merge.endCount() == 1 && !(merge instanceof LoopBegin)) {
                 replacePhis(merge);
-                merge.endAt(0).replaceAndDelete(merge.next());
+                EndNode endNode = merge.endAt(0);
+                FixedNode next = merge.next();
                 merge.delete();
+                endNode.replaceAndDelete(next);
             }
         }
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRAssembler.java	Wed Jun 29 16:19:51 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRAssembler.java	Thu Jun 30 16:07:18 2011 +0200
@@ -439,22 +439,11 @@
 
     private boolean assertEmitBranch(LIRBranch op) {
         assert op.block() == null || op.block().label() == op.label() : "wrong label";
-        if (op.block() != null) {
-            branchTargetBlocks.add(op.block());
-        }
-        if (op.unorderedBlock() != null) {
-            branchTargetBlocks.add(op.unorderedBlock());
-        }
         return true;
     }
 
     private boolean assertEmitTableSwitch(LIRTableSwitch op) {
         assert op.defaultTarget != null;
-        branchTargetBlocks.add(op.defaultTarget);
-        for (LIRBlock target : op.targets) {
-            assert target != null;
-            branchTargetBlocks.add(target);
-        }
         return true;
     }
 
@@ -537,9 +526,14 @@
             masm.jmp(op.label());
         } else {
             ConditionFlag acond = ConditionFlag.zero;
+            Label unorderedLabel = null;
             if (op.code == LIROpcode.CondFloatBranch) {
-                assert op.unorderedBlock() != null : "must have unordered successor";
-                masm.jcc(ConditionFlag.parity, op.unorderedBlock().label());
+                if (op.unorderedBlock() == null) {
+                    unorderedLabel = new Label();
+                } else {
+                    unorderedLabel = op.unorderedBlock().label;
+                }
+                masm.jcc(ConditionFlag.parity, unorderedLabel);
                 // Checkstyle: off
                 switch (op.cond()) {
                     case EQ : acond = ConditionFlag.equal; break;
@@ -565,6 +559,9 @@
                 // Checkstyle: on
             }
             masm.jcc(acond, op.label());
+            if (unorderedLabel != null) {
+                masm.bind(unorderedLabel);
+            }
         }
     }
 
@@ -1597,11 +1594,30 @@
     protected void emitXir(LIRXirInstruction instruction) {
         XirSnippet snippet = instruction.snippet;
 
+
+        Label endLabel = null;
         Label[] labels = new Label[snippet.template.labels.length];
         for (int i = 0; i < labels.length; i++) {
             labels[i] = new Label();
+            if (snippet.template.labels[i].name == XirLabel.TrueSuccessor) {
+                labels[i] = instruction.trueSuccessor().label;
+                if (labels[i] == null) {
+                    assert endLabel == null;
+                    endLabel = new Label();
+                }
+            } else if (snippet.template.labels[i].name == XirLabel.FalseSuccessor) {
+                labels[i] = instruction.falseSuccessor().label;
+                if (labels[i] == null) {
+                    assert endLabel == null;
+                    endLabel = new Label();
+                }
+            }
         }
         emitXirInstructions(instruction, snippet.template.fastPath, labels, instruction.getOperands(), snippet.marks);
+        if (endLabel != null) {
+            masm.bind(endLabel);
+        }
+
         if (snippet.template.slowPath != null) {
             addSlowPath(new SlowPath(instruction, labels, snippet.marks));
         }