changeset 2546:e1b3db8031ee

Removed liveness marking.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 27 Apr 2011 21:54:31 +0200
parents bb050fe2901d
children b6cd17226aad
files graal/GraalCompiler/src/com/sun/c1x/alloc/LinearScan.java graal/GraalCompiler/src/com/sun/c1x/debug/BlockPrinter.java graal/GraalCompiler/src/com/sun/c1x/debug/InstructionPrinter.java graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java graal/GraalCompiler/src/com/sun/c1x/graph/IR.java graal/GraalCompiler/src/com/sun/c1x/ir/BlockEnd.java graal/GraalCompiler/src/com/sun/c1x/ir/CompareOp.java graal/GraalCompiler/src/com/sun/c1x/ir/ExceptionObject.java graal/GraalCompiler/src/com/sun/c1x/ir/StoreField.java graal/GraalCompiler/src/com/sun/c1x/ir/StoreIndexed.java graal/GraalCompiler/src/com/sun/c1x/ir/Value.java graal/GraalCompiler/src/com/sun/c1x/opt/LivenessMarker.java graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java
diffstat 13 files changed, 14 insertions(+), 262 deletions(-) [+]
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/alloc/LinearScan.java	Wed Apr 27 21:38:22 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/alloc/LinearScan.java	Wed Apr 27 21:54:31 2011 +0200
@@ -2045,13 +2045,6 @@
 
             assert con == null || operand.isVariable() || operand.isConstant() || operand.isIllegal() : "Constant instructions have only constant operands (or illegal if constant is optimized away)";
 
-            if (con != null && !con.isLive() && !operand.isConstant()) {
-                // Unpinned constants may have a variable operand for a part of the lifetime
-                // or may be illegal when it was optimized away,
-                // so always use a constant operand
-                operand = con.asConstant();
-            }
-
             if (operand.isVariable()) {
                 OperandMode mode = OperandMode.Input;
                 BlockBegin block = blockForId(opId);
--- a/graal/GraalCompiler/src/com/sun/c1x/debug/BlockPrinter.java	Wed Apr 27 21:38:22 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/debug/BlockPrinter.java	Wed Apr 27 21:54:31 2011 +0200
@@ -29,19 +29,15 @@
 
 /**
  * Prints a listing for a {@linkplain BlockBegin block}.
- *
- * @author Doug Simon
  */
 public class BlockPrinter implements BlockClosure {
 
     private final InstructionPrinter ip;
     private final boolean cfgOnly;
-    private final boolean liveOnly;
 
-    public BlockPrinter(IR ir, InstructionPrinter ip, boolean cfgOnly, boolean liveOnly) {
+    public BlockPrinter(IR ir, InstructionPrinter ip, boolean cfgOnly) {
         this.ip = ip;
         this.cfgOnly = cfgOnly;
-        this.liveOnly = liveOnly;
     }
 
     public void apply(BlockBegin block) {
@@ -49,11 +45,11 @@
             ip.printInstruction(block);
             ip.out().println();
         } else {
-            printBlock(block, liveOnly);
+            printBlock(block);
         }
     }
 
-    public void printBlock(BlockBegin block, boolean liveOnly) {
+    public void printBlock(BlockBegin block) {
         ip.printInstruction(block);
         LogStream out = ip.out();
         out.println();
@@ -65,9 +61,7 @@
         ip.printInstructionListingHeader();
 
         for (Instruction i = block.next(); i != null; i = i.next()) {
-            if (!liveOnly || i.isLive()) {
-                ip.printInstructionListing(i);
-            }
+            ip.printInstructionListing(i);
         }
         out.println();
 
--- a/graal/GraalCompiler/src/com/sun/c1x/debug/InstructionPrinter.java	Wed Apr 27 21:38:22 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/debug/InstructionPrinter.java	Wed Apr 27 21:54:31 2011 +0200
@@ -129,10 +129,6 @@
      * @param instruction the instruction to print
      */
     public void printInstructionListing(Value instruction) {
-        if (instruction.isLive()) {
-            out.print('.');
-        }
-
         int indentation = out.indentationLevel();
         out.fillTo(BCI.position + indentation, ' ').
              print(instruction instanceof Instruction ? ((Instruction) instruction).bci() : 0).
--- a/graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java	Wed Apr 27 21:38:22 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java	Wed Apr 27 21:54:31 2011 +0200
@@ -205,10 +205,6 @@
         this.operands = new OperandPool(compilation.target);
 
         new PhiSimplifier(ir);
-
-        // mark the liveness of all instructions if it hasn't already been done by the optimizer
-        LivenessMarker livenessMarker = new LivenessMarker(ir);
-        C1XMetrics.LiveHIRInstructions += livenessMarker.liveCount();
     }
 
     public ArrayList<DeoptimizationStub> deoptimizationStubs() {
@@ -229,7 +225,7 @@
         this.currentBlock = block;
 
         for (Instruction instr = block; instr != null; instr = instr.next()) {
-            if (instr.isLive()) {
+            if (!(instr instanceof BlockBegin)) {
                 walkState(instr, instr.stateBefore());
                 doRoot(instr);
             }
@@ -277,9 +273,7 @@
             Local local = ((Local) instr);
             CiKind kind = src.kind.stackKind();
             assert kind == local.kind.stackKind() : "local type check failed";
-            if (local.isLive()) {
-                setResult(local, dest);
-            }
+            setResult(local, dest);
             javaIndex += kind.jvmSlots;
         }
     }
@@ -365,21 +359,14 @@
 
     @Override
     public void visitConstant(Constant x) {
-        if (canInlineAsConstant(x)) {
-            //setResult(x, loadConstant(x));
-        } else {
+        if (!canInlineAsConstant(x)) {
             CiValue res = x.operand();
             if (!(res.isLegal())) {
                 res = x.asConstant();
             }
             if (res.isConstant()) {
-                if (isUsedForValue(x)) {
-                    CiVariable reg = createResultVariable(x);
-                    lir.move(res, reg);
-                } else {
-                    assert x.checkFlag(Value.Flag.LiveDeopt);
-                    x.setOperand(res);
-                }
+                CiVariable reg = createResultVariable(x);
+                lir.move(res, reg);
             } else {
                 setResult(x, (CiVariable) res);
             }
@@ -1220,7 +1207,6 @@
 
     void doRoot(Instruction instr) {
         currentInstruction = instr;
-        assert instr.isLive() : "use only with roots";
         assert !instr.hasSubst() : "shouldn't have missed substitution";
 
         if (C1XOptions.TraceLIRVisit) {
@@ -1230,12 +1216,6 @@
         if (C1XOptions.TraceLIRVisit) {
             TTY.println("Operand for " + instr + " = " + instr.operand());
         }
-
-        assert (instr.operand().isLegal()) || !isUsedForValue(instr) || instr.isConstant() : "operand was not set for live instruction";
-    }
-
-    private boolean isUsedForValue(Instruction instr) {
-        return instr.checkFlag(Value.Flag.LiveValue);
     }
 
     protected void logicOp(int code, CiValue resultOp, CiValue leftOp, CiValue rightOp) {
@@ -1271,8 +1251,7 @@
         if (suxVal instanceof Phi) {
             Phi phi = (Phi) suxVal;
             // curVal can be null without phi being null in conjunction with inlining
-            if (phi.isLive() && !phi.isDeadPhi() && curVal != null && curVal != phi) {
-                assert curVal.isLive() : "value not live: " + curVal + ", suxVal=" + suxVal;
+            if (!phi.isDeadPhi() && curVal != null && curVal != phi) {
                 assert !phi.isIllegal() : "illegal phi cannot be marked as live";
                 if (curVal instanceof Phi) {
                     operandForPhi((Phi) curVal);
@@ -1365,7 +1344,6 @@
     }
 
     protected void setNoResult(Instruction x) {
-        assert !isUsedForValue(x) : "can't have use";
         x.clearOperand();
     }
 
@@ -1419,7 +1397,7 @@
                 assert x instanceof ExceptionObject ||
                        x instanceof Throw ||
                        x instanceof MonitorEnter ||
-                       x instanceof MonitorExit;
+                       x instanceof MonitorExit : x + ", " + x.getClass();
             }
 
             for (int index = 0; index < s.localsSize(); index++) {
@@ -1438,7 +1416,6 @@
     private void walkStateValue(Value value) {
         if (value != null) {
             assert !value.hasSubst() : "missed substitution";
-            assert value.isLive() : "value must be marked live in frame state";
             if (value instanceof Phi && !value.isIllegal()) {
                 // phi's are special
                 operandForPhi((Phi) value);
@@ -1513,7 +1490,6 @@
         if (instruction == null) {
             return CiValue.IllegalValue;
         }
-        assert instruction.isLive();
         CiValue operand = instruction.operand();
         if (operand.isIllegal()) {
             if (instruction instanceof Phi) {
--- a/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java	Wed Apr 27 21:38:22 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java	Wed Apr 27 21:54:31 2011 +0200
@@ -138,7 +138,7 @@
         if (!TTY.isSuppressed()) {
             TTY.println("IR for " + compilation.method);
             final InstructionPrinter ip = new InstructionPrinter(TTY.out());
-            final BlockPrinter bp = new BlockPrinter(this, ip, cfgOnly, false);
+            final BlockPrinter bp = new BlockPrinter(this, ip, cfgOnly);
             startBlock.iteratePreOrder(bp);
         }
     }
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/BlockEnd.java	Wed Apr 27 21:38:22 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/BlockEnd.java	Wed Apr 27 21:54:31 2011 +0200
@@ -31,8 +31,6 @@
 /**
  * The {@code BlockEnd} instruction is a base class for all instructions that end a basic
  * block, including branches, switches, throws, and goto's.
- *
- * @author Ben L. Titzer
  */
 public abstract class BlockEnd extends Instruction {
 
@@ -53,7 +51,6 @@
         this.successors = successors == null ? new ArrayList<BlockBegin>(2) : successors;
         setStateAfter(stateAfter);
         this.isSafepoint = isSafepoint;
-        setFlag(Flag.LiveSideEffect);
     }
 
     public BlockEnd(CiKind kind, FrameState stateAfter, boolean isSafepoint) {
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/CompareOp.java	Wed Apr 27 21:38:22 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/CompareOp.java	Wed Apr 27 21:54:31 2011 +0200
@@ -28,8 +28,6 @@
 
 /**
  * The {@code CompareOp} instruction represents comparisons such as equals, not equal, etc.
- *
- * @author Ben L. Titzer
  */
 public final class CompareOp extends Op2 {
 
@@ -42,10 +40,6 @@
      */
     public CompareOp(int opcode, CiKind kind, Value x, Value y) {
         super(kind, opcode, x, y);
-        if (kind.isVoid()) {
-            // A compare that does not produce a value exists soley for it's side effect (i.e. setting condition codes)
-            setFlag(Flag.LiveSideEffect);
-        }
     }
 
     @Override
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/ExceptionObject.java	Wed Apr 27 21:38:22 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/ExceptionObject.java	Wed Apr 27 21:54:31 2011 +0200
@@ -28,8 +28,6 @@
 
 /**
  * The {@code ExceptionObject} instruction represents the incoming exception object to an exception handler.
- *
- * @author Ben L. Titzer
  */
 public final class ExceptionObject extends Instruction {
 
@@ -45,7 +43,6 @@
     public ExceptionObject(FrameState stateBefore) {
         super(CiKind.Object);
         setFlag(Flag.NonNull);
-        setFlag(Flag.LiveSideEffect);
         this.stateBefore = stateBefore;
     }
 
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/StoreField.java	Wed Apr 27 21:38:22 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/StoreField.java	Wed Apr 27 21:54:31 2011 +0200
@@ -49,7 +49,6 @@
     public StoreField(Value object, RiField field, Value value, FrameState stateBefore) {
         super(CiKind.Void, object, field, stateBefore);
         this.value = value;
-        setFlag(Flag.LiveSideEffect);
     }
 
     /**
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/StoreIndexed.java	Wed Apr 27 21:38:22 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/StoreIndexed.java	Wed Apr 27 21:54:31 2011 +0200
@@ -50,7 +50,6 @@
     public StoreIndexed(Value array, Value index, Value length, CiKind elementType, Value value, FrameState stateBefore) {
         super(CiKind.Void, array, index, length, elementType, stateBefore);
         this.value = value;
-        setFlag(Flag.LiveSideEffect);
     }
 
     /**
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/Value.java	Wed Apr 27 21:38:22 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Value.java	Wed Apr 27 21:54:31 2011 +0200
@@ -37,10 +37,6 @@
     public enum Flag {
         NonNull,            // this value is non-null
 
-        LiveValue,          // live because value is used
-        LiveDeopt,          // live for deoptimization
-        LiveSideEffect,     // live for possible side-effects only
-
         PhiDead,            // phi is illegal because local is dead
         PhiCannotSimplify,  // phi cannot be simplified
         PhiVisited;         // phi has been visited during simplification
@@ -48,9 +44,6 @@
         public final int mask = 1 << ordinal();
     }
 
-    private static final int LIVE_FLAGS = Flag.LiveValue.mask |
-                                          Flag.LiveDeopt.mask |
-                                          Flag.LiveSideEffect.mask;
     /**
      * The kind of this value. This is {@link CiKind#Void} for instructions that produce no value.
      * This kind is guaranteed to be a {@linkplain CiKind#stackKind() stack kind}.
@@ -86,25 +79,6 @@
     }
 
     /**
-     * Checks whether this instruction is live (i.e. code should be generated for it).
-     * This is computed in a dedicated pass by {@link LivenessMarker}.
-     * An instruction is live because its value is needed by another live instruction,
-     * because its value is needed for deoptimization, or the program is control dependent
-     * upon it.
-     * @return {@code true} if this instruction should be considered live
-     */
-    public final boolean isLive() {
-        return C1XOptions.PinAllInstructions || (flags & LIVE_FLAGS) != 0;
-    }
-
-    /**
-     * Clears all liveness flags.
-     */
-    public final void clearLive() {
-        flags = flags & ~LIVE_FLAGS;
-    }
-
-    /**
      * Gets the instruction that should be substituted for this one. Note that this
      * method is recursive; if the substituted instruction has a substitution, then
      * the final substituted instruction will be returned. If there is no substitution
--- a/graal/GraalCompiler/src/com/sun/c1x/opt/LivenessMarker.java	Wed Apr 27 21:38:22 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,167 +0,0 @@
-/*
- * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.sun.c1x.opt;
-
-import static com.sun.c1x.ir.Value.Flag.*;
-
-import com.sun.c1x.graph.*;
-import com.sun.c1x.ir.*;
-import com.sun.c1x.value.*;
-
-/**
- * The {@code LivenessMarker} class walks over an IR graph and marks instructions
- * whose values are live, either because they are needed to compute the method's result,
- * may produce a side-effect, or are needed for deoptimization.
- *
- * @author Ben L. Titzer
- */
-public final class LivenessMarker {
-
-    final IR ir;
-
-    final InstructionMarker deoptMarker = new InstructionMarker(LiveDeopt);
-    final InstructionMarker valueMarker = new InstructionMarker(LiveValue);
-
-    int count;
-
-    /**
-     * Creates a new liveness marking instance and marks live instructions.
-     * @param ir the IR to mark
-     */
-    public LivenessMarker(IR ir) {
-        this.ir = ir;
-        markRoots();
-    }
-
-    private void markRoots() {
-        // first pass: mark root instructions and their inputs
-        ir.startBlock.iteratePreOrder(new BlockClosure() {
-            public void apply(BlockBegin block) {
-                block.stateBefore().valuesDo(deoptMarker);
-                if (block.stateAfter() != null) {
-                    block.stateAfter().valuesDo(deoptMarker);
-                }
-                Instruction i = block;
-                while ((i = i.next()) != null) {
-                    // visit all instructions first, marking control dependent and side-effects
-                    markRootInstr(i);
-                }
-            }
-        });
-
-        // propagate liveness flags to inputs of instructions
-        valueMarker.markAll();
-        deoptMarker.markAll();
-    }
-
-    public int liveCount() {
-        return count;
-    }
-
-    private static class Link {
-        final Value value;
-        Link next;
-
-        Link(Value v) {
-            this.value = v;
-        }
-    }
-
-    private final class InstructionMarker implements ValueClosure {
-        final Value.Flag reason;
-        Link head;
-        Link tail;
-
-        public InstructionMarker(Value.Flag reason) {
-            this.reason = reason;
-        }
-
-        public Value apply(Value i) {
-            if (!i.checkFlag(reason) && !i.isDeadPhi()) {
-                // set the flag and add to the queue
-                setFlag(i, reason);
-                if (head == null) {
-                    head = tail = new Link(i);
-                } else {
-                    tail.next = new Link(i);
-                    tail = tail.next;
-                }
-            }
-            return i;
-        }
-
-        private void markAll() {
-            Link cursor = head;
-            while (cursor != null) {
-                markInputs(cursor.value);
-                cursor = cursor.next;
-            }
-        }
-
-        private void clearAll() {
-            Link cursor = head;
-            while (cursor != null) {
-                cursor.value.clearLive();
-                cursor = cursor.next;
-            }
-        }
-
-        private void markInputs(Value i) {
-            if (!i.isDeadPhi()) {
-                i.inputValuesDo(this);
-                if (i instanceof Phi) {
-                    // phis are special
-                    Phi phi = (Phi) i;
-                    int max = phi.inputCount();
-                    for (int j = 0; j < max; j++) {
-                        apply(phi.inputAt(j));
-                    }
-                }
-            }
-        }
-    }
-
-    void markRootInstr(Instruction i) {
-        FrameState stateBefore = i.stateBefore();
-        if (stateBefore != null) {
-            // stateBefore != null implies that this instruction may have side effects
-            stateBefore.valuesDo(deoptMarker);
-            i.inputValuesDo(valueMarker);
-            setFlag(i, LiveSideEffect);
-        } else if (i.checkFlag(LiveSideEffect)) {
-            // instruction has a side effect
-            i.inputValuesDo(valueMarker);
-        }
-        FrameState stateAfter = i.stateAfter();
-        if (stateAfter != null) {
-            stateAfter.valuesDo(deoptMarker);
-        }
-    }
-
-    void setFlag(Value i, Value.Flag flag) {
-        if (!i.isLive()) {
-            count++;
-        }
-        i.setFlag(flag);
-    }
-}
--- a/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java	Wed Apr 27 21:38:22 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java	Wed Apr 27 21:54:31 2011 +0200
@@ -486,7 +486,7 @@
         int max = this.valuesSize();
         for (int i = 0; i < max; i++) {
             Value instr = values[i];
-            if (instr instanceof Phi && instr.isLive() && !instr.isDeadPhi()) {
+            if (instr instanceof Phi && !instr.isDeadPhi()) {
                 Phi phi = (Phi) instr;
                 if (block == null || phi.block() == block) {
                     if (!proc.doPhi(phi)) {
@@ -563,7 +563,7 @@
             final int max = state.valuesSize();
             for (int i = 0; i < max; i++) {
                 Value value = state.values[i];
-                if (value != null && value.isLive()) {
+                if (value != null) {
                     proc.doValue(value);
                 }
             }