Mercurial > hg > graal-jvmci-8
view graal/com.oracle.graal.word/src/com/oracle/graal/word/nodes/SnippetLocationNode.java @ 18533:25a21e1794ec
modified SnippetReflectionProvider to support both VM-side and compiler-side constants in a compilation replay context
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 26 Nov 2014 17:14:49 +0100 |
parents | 9619ba4daf4c |
children | d138867d61c4 |
line wrap: on
line source
/* * Copyright (c) 2013, 2014, 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.oracle.graal.word.nodes; import static com.oracle.graal.api.meta.LocationIdentity.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.api.replacements.*; import com.oracle.graal.compiler.common.*; import com.oracle.graal.compiler.common.type.*; import com.oracle.graal.graph.*; import com.oracle.graal.graph.spi.*; import com.oracle.graal.lir.gen.*; import com.oracle.graal.nodeinfo.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.extended.*; import com.oracle.graal.nodes.spi.*; /** * Location node that can be used inside a snippet without having the elements (including the * location identity and kind) as a snippet constant. Can represent locations in the form of [base + * index * scale + disp]. When the location is created, all elements (base, index, scale, disp) are * nodes. Both scale and disp must eventually canonicalize to {@link ConstantNode constants} so that * this node can be canonicalized to a {@link IndexedLocationNode} or {@link ConstantLocationNode}. */ @NodeInfo public class SnippetLocationNode extends LocationNode implements Canonicalizable { protected final SnippetReflectionProvider snippetReflection; @Input ValueNode valueKind; @Input(InputType.Association) ValueNode locationIdentity; @Input ValueNode displacement; @Input ValueNode index; @Input ValueNode indexScaling; public static SnippetLocationNode create(@InjectedNodeParameter SnippetReflectionProvider snippetReflection, ValueNode identity, ValueNode kind, ValueNode displacement, ValueNode index, ValueNode indexScaling, Graph graph) { return graph.unique(SnippetLocationNode.create(snippetReflection, identity, kind, displacement, index, indexScaling)); } public static SnippetLocationNode create(@InjectedNodeParameter SnippetReflectionProvider snippetReflection, ValueNode locationIdentity, ValueNode kind, ValueNode displacement) { return new SnippetLocationNode(snippetReflection, locationIdentity, kind, displacement); } protected SnippetLocationNode(@InjectedNodeParameter SnippetReflectionProvider snippetReflection, ValueNode locationIdentity, ValueNode kind, ValueNode displacement) { this(snippetReflection, locationIdentity, kind, displacement, null, null); } public static SnippetLocationNode create(@InjectedNodeParameter SnippetReflectionProvider snippetReflection, ValueNode locationIdentity, ValueNode kind, ValueNode displacement, ValueNode index, ValueNode indexScaling) { return new SnippetLocationNode(snippetReflection, locationIdentity, kind, displacement, index, indexScaling); } protected SnippetLocationNode(SnippetReflectionProvider snippetReflection, ValueNode locationIdentity, ValueNode kind, ValueNode displacement, ValueNode index, ValueNode indexScaling) { super(StampFactory.object()); this.snippetReflection = snippetReflection; this.valueKind = kind; this.locationIdentity = locationIdentity; this.displacement = displacement; this.index = index; this.indexScaling = indexScaling; } @Override public Kind getValueKind() { if (valueKind.isConstant()) { return snippetReflection.asObject(Kind.class, valueKind.asJavaConstant()); } throw new GraalInternalError("Cannot access kind yet because it is not constant: " + valueKind); } @Override public LocationIdentity getLocationIdentity() { if (locationIdentity.isConstant()) { LocationIdentity identity = snippetReflection.asObject(LocationIdentity.class, locationIdentity.asJavaConstant()); return identity; } // We do not know our actual location identity yet, so be conservative. return ANY_LOCATION; } @Override public Node canonical(CanonicalizerTool tool) { if (valueKind.isConstant() && locationIdentity.isConstant() && displacement.isConstant() && (indexScaling == null || indexScaling.isConstant())) { Kind constKind = snippetReflection.asObject(Kind.class, valueKind.asJavaConstant()); LocationIdentity constLocation = snippetReflection.asObject(LocationIdentity.class, locationIdentity.asJavaConstant()); long constDisplacement = displacement.asJavaConstant().asLong(); int constIndexScaling = indexScaling == null ? 0 : indexScaling.asJavaConstant().asInt(); if (index == null || constIndexScaling == 0) { return ConstantLocationNode.create(constLocation, constKind, constDisplacement, graph()); } else if (index.isConstant()) { return ConstantLocationNode.create(constLocation, constKind, index.asJavaConstant().asLong() * constIndexScaling + constDisplacement, graph()); } else { return IndexedLocationNode.create(constLocation, constKind, constDisplacement, index, graph(), constIndexScaling); } } return this; } @Override public Value generateAddress(NodeMappableLIRBuilder builder, LIRGeneratorTool gen, Value base) { throw new GraalInternalError("locationIdentity must be a constant so that this node can be canonicalized: " + locationIdentity); } @Override public IntegerStamp getDisplacementStamp() { throw GraalInternalError.shouldNotReachHere(); } @NodeIntrinsic public static native Location constantLocation(LocationIdentity identity, Kind kind, long displacement); @NodeIntrinsic public static native Location indexedLocation(LocationIdentity identity, Kind kind, long displacement, int index, int indexScaling); }