src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.amd64/src/org/graalvm/compiler/core/amd64/AMD64AddressNode.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.amd64/src/org/graalvm/compiler/core/amd64

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.amd64/src/org/graalvm/compiler/core/amd64/AMD64AddressNode.java

Print this page




   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 org.graalvm.compiler.asm.amd64.AMD64Address.Scale;
  27 import org.graalvm.compiler.core.common.LIRKind;
  28 import org.graalvm.compiler.graph.NodeClass;


  29 import org.graalvm.compiler.lir.amd64.AMD64AddressValue;
  30 import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
  31 import org.graalvm.compiler.nodeinfo.NodeInfo;



  32 import org.graalvm.compiler.nodes.ValueNode;

  33 import org.graalvm.compiler.nodes.memory.address.AddressNode;
  34 import org.graalvm.compiler.nodes.spi.LIRLowerable;
  35 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
  36 
  37 import jdk.vm.ci.meta.AllocatableValue;
  38 import jdk.vm.ci.meta.Value;
  39 
  40 /**
  41  * Represents an address of the form [base + index*scale + displacement]. Both base and index are
  42  * optional.
  43  */
  44 @NodeInfo
  45 public class AMD64AddressNode extends AddressNode implements LIRLowerable {
  46 
  47     public static final NodeClass<AMD64AddressNode> TYPE = NodeClass.create(AMD64AddressNode.class);
  48 
  49     @OptionalInput private ValueNode base;
  50 
  51     @OptionalInput private ValueNode index;
  52     private Scale scale;
  53 
  54     private int displacement;
  55 
  56     public AMD64AddressNode(ValueNode base) {
  57         this(base, null);
  58     }
  59 
  60     public AMD64AddressNode(ValueNode base, ValueNode index) {
  61         super(TYPE);
  62         this.base = base;
  63         this.index = index;
  64         this.scale = Scale.Times1;
  65     }
  66 






















  67     @Override
  68     public void generate(NodeLIRBuilderTool gen) {
  69         LIRGeneratorTool tool = gen.getLIRGeneratorTool();
  70 
  71         AllocatableValue baseValue = base == null ? Value.ILLEGAL : tool.asAllocatable(gen.operand(base));
  72         AllocatableValue indexValue = index == null ? Value.ILLEGAL : tool.asAllocatable(gen.operand(index));
  73 
  74         AllocatableValue baseReference = LIRKind.derivedBaseFromValue(baseValue);
  75         AllocatableValue indexReference;
  76         if (index == null) {
  77             indexReference = null;
  78         } else if (scale.equals(Scale.Times1)) {
  79             indexReference = LIRKind.derivedBaseFromValue(indexValue);
  80         } else {
  81             if (LIRKind.isValue(indexValue)) {
  82                 indexReference = null;
  83             } else {
  84                 indexReference = Value.ILLEGAL;
  85             }
  86         }


 118     public Scale getScale() {
 119         return scale;
 120     }
 121 
 122     public void setScale(Scale scale) {
 123         this.scale = scale;
 124     }
 125 
 126     public int getDisplacement() {
 127         return displacement;
 128     }
 129 
 130     public void setDisplacement(int displacement) {
 131         this.displacement = displacement;
 132     }
 133 
 134     @Override
 135     public long getMaxConstantDisplacement() {
 136         return displacement;
 137     }





 138 }


   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 org.graalvm.compiler.asm.amd64.AMD64Address.Scale;
  27 import org.graalvm.compiler.core.common.LIRKind;
  28 import org.graalvm.compiler.graph.NodeClass;
  29 import org.graalvm.compiler.graph.spi.Simplifiable;
  30 import org.graalvm.compiler.graph.spi.SimplifierTool;
  31 import org.graalvm.compiler.lir.amd64.AMD64AddressValue;
  32 import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
  33 import org.graalvm.compiler.nodeinfo.NodeInfo;
  34 import org.graalvm.compiler.nodes.ConstantNode;
  35 import org.graalvm.compiler.nodes.LoopBeginNode;
  36 import org.graalvm.compiler.nodes.PhiNode;
  37 import org.graalvm.compiler.nodes.ValueNode;
  38 import org.graalvm.compiler.nodes.calc.AddNode;
  39 import org.graalvm.compiler.nodes.memory.address.AddressNode;
  40 import org.graalvm.compiler.nodes.spi.LIRLowerable;
  41 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
  42 
  43 import jdk.vm.ci.meta.AllocatableValue;
  44 import jdk.vm.ci.meta.Value;
  45 
  46 /**
  47  * Represents an address of the form [base + index*scale + displacement]. Both base and index are
  48  * optional.
  49  */
  50 @NodeInfo
  51 public class AMD64AddressNode extends AddressNode implements Simplifiable, LIRLowerable {
  52 
  53     public static final NodeClass<AMD64AddressNode> TYPE = NodeClass.create(AMD64AddressNode.class);
  54 
  55     @OptionalInput private ValueNode base;
  56 
  57     @OptionalInput private ValueNode index;
  58     private Scale scale;
  59 
  60     private int displacement;
  61 
  62     public AMD64AddressNode(ValueNode base) {
  63         this(base, null);
  64     }
  65 
  66     public AMD64AddressNode(ValueNode base, ValueNode index) {
  67         super(TYPE);
  68         this.base = base;
  69         this.index = index;
  70         this.scale = Scale.Times1;
  71     }
  72 
  73     public void canonicalizeIndex(SimplifierTool tool) {
  74         if (index instanceof AddNode) {
  75             AddNode add = (AddNode) index;
  76             ValueNode valX = add.getX();
  77             if (valX instanceof PhiNode) {
  78                 PhiNode phi = (PhiNode) valX;
  79                 if (phi.merge() instanceof LoopBeginNode) {
  80                     LoopBeginNode loopNode = (LoopBeginNode) phi.merge();
  81                     if (!loopNode.isSimpleLoop()) {
  82                         ValueNode valY = add.getY();
  83                         if (valY instanceof ConstantNode) {
  84                             int addBy = valY.asJavaConstant().asInt();
  85                             displacement = displacement + scale.value * addBy;
  86                             replaceFirstInput(index, phi);
  87                             tool.addToWorkList(index);
  88                         }
  89                     }
  90                 }
  91             }
  92         }
  93     }
  94 
  95     @Override
  96     public void generate(NodeLIRBuilderTool gen) {
  97         LIRGeneratorTool tool = gen.getLIRGeneratorTool();
  98 
  99         AllocatableValue baseValue = base == null ? Value.ILLEGAL : tool.asAllocatable(gen.operand(base));
 100         AllocatableValue indexValue = index == null ? Value.ILLEGAL : tool.asAllocatable(gen.operand(index));
 101 
 102         AllocatableValue baseReference = LIRKind.derivedBaseFromValue(baseValue);
 103         AllocatableValue indexReference;
 104         if (index == null) {
 105             indexReference = null;
 106         } else if (scale.equals(Scale.Times1)) {
 107             indexReference = LIRKind.derivedBaseFromValue(indexValue);
 108         } else {
 109             if (LIRKind.isValue(indexValue)) {
 110                 indexReference = null;
 111             } else {
 112                 indexReference = Value.ILLEGAL;
 113             }
 114         }


 146     public Scale getScale() {
 147         return scale;
 148     }
 149 
 150     public void setScale(Scale scale) {
 151         this.scale = scale;
 152     }
 153 
 154     public int getDisplacement() {
 155         return displacement;
 156     }
 157 
 158     public void setDisplacement(int displacement) {
 159         this.displacement = displacement;
 160     }
 161 
 162     @Override
 163     public long getMaxConstantDisplacement() {
 164         return displacement;
 165     }
 166 
 167     @Override
 168     public void simplify(SimplifierTool tool) {
 169         canonicalizeIndex(tool);
 170     }
 171 }
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.amd64/src/org/graalvm/compiler/core/amd64/AMD64AddressNode.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File