src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.amd64/src/org/graalvm/compiler/core/amd64/AMD64CompressAddressLowering.java
changeset 48861 47f19ff9903c
child 50858 2d3e99a72541
equal deleted inserted replaced
48860:5bce1b7e7800 48861:47f19ff9903c
       
     1 /*
       
     2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 package org.graalvm.compiler.core.amd64;
       
    25 
       
    26 import jdk.vm.ci.code.Register;
       
    27 import org.graalvm.compiler.asm.amd64.AMD64Address;
       
    28 import org.graalvm.compiler.core.common.LIRKind;
       
    29 import org.graalvm.compiler.core.common.type.StampFactory;
       
    30 import org.graalvm.compiler.debug.CounterKey;
       
    31 import org.graalvm.compiler.debug.DebugContext;
       
    32 import org.graalvm.compiler.graph.NodeClass;
       
    33 import org.graalvm.compiler.nodeinfo.NodeInfo;
       
    34 import org.graalvm.compiler.nodes.CompressionNode;
       
    35 import org.graalvm.compiler.nodes.NodeView;
       
    36 import org.graalvm.compiler.nodes.StructuredGraph;
       
    37 import org.graalvm.compiler.nodes.ValueNode;
       
    38 import org.graalvm.compiler.nodes.calc.FloatingNode;
       
    39 import org.graalvm.compiler.nodes.spi.LIRLowerable;
       
    40 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
       
    41 
       
    42 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_0;
       
    43 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_0;
       
    44 
       
    45 public abstract class AMD64CompressAddressLowering extends AMD64AddressLowering {
       
    46     private static final CounterKey counterFoldedUncompressDuringAddressLowering = DebugContext.counter("FoldedUncompressDuringAddressLowering");
       
    47 
       
    48     @Override
       
    49     protected final boolean improve(StructuredGraph graph, DebugContext debug, AMD64AddressNode addr, boolean isBaseNegated, boolean isIndexNegated) {
       
    50         if (super.improve(graph, debug, addr, isBaseNegated, isIndexNegated)) {
       
    51             return true;
       
    52         }
       
    53 
       
    54         if (!isBaseNegated && !isIndexNegated && addr.getScale() == AMD64Address.Scale.Times1) {
       
    55             ValueNode base = addr.getBase();
       
    56             ValueNode index = addr.getIndex();
       
    57 
       
    58             if (tryToImproveUncompression(addr, index, base) || tryToImproveUncompression(addr, base, index)) {
       
    59                 counterFoldedUncompressDuringAddressLowering.increment(debug);
       
    60                 return true;
       
    61             }
       
    62         }
       
    63 
       
    64         return false;
       
    65     }
       
    66 
       
    67     private boolean tryToImproveUncompression(AMD64AddressNode addr, ValueNode value, ValueNode other) {
       
    68         if (value instanceof CompressionNode) {
       
    69             CompressionNode compression = (CompressionNode) value;
       
    70             if (compression.getOp() == CompressionNode.CompressionOp.Uncompress && improveUncompression(addr, compression, other)) {
       
    71                 return true;
       
    72             }
       
    73         }
       
    74 
       
    75         return false;
       
    76     }
       
    77 
       
    78     protected abstract boolean improveUncompression(AMD64AddressNode addr, CompressionNode compression, ValueNode other);
       
    79 
       
    80     @NodeInfo(cycles = CYCLES_0, size = SIZE_0)
       
    81     public static class HeapBaseNode extends FloatingNode implements LIRLowerable {
       
    82 
       
    83         public static final NodeClass<HeapBaseNode> TYPE = NodeClass.create(HeapBaseNode.class);
       
    84 
       
    85         private final Register heapBaseRegister;
       
    86 
       
    87         public HeapBaseNode(Register heapBaseRegister) {
       
    88             super(TYPE, StampFactory.pointer());
       
    89             this.heapBaseRegister = heapBaseRegister;
       
    90         }
       
    91 
       
    92         @Override
       
    93         public void generate(NodeLIRBuilderTool generator) {
       
    94             LIRKind kind = generator.getLIRGeneratorTool().getLIRKind(stamp(NodeView.DEFAULT));
       
    95             generator.setResult(this, heapBaseRegister.asValue(kind));
       
    96         }
       
    97     }
       
    98 }