1 /*
   2  * Copyright (c) 2009, 2016, 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 package org.graalvm.compiler.nodes.memory;
  24 
  25 import org.graalvm.compiler.core.common.LocationIdentity;
  26 import org.graalvm.compiler.core.common.type.StampFactory;
  27 import org.graalvm.compiler.graph.NodeClass;
  28 import org.graalvm.compiler.graph.NodeInputList;
  29 import org.graalvm.compiler.nodeinfo.InputType;
  30 import org.graalvm.compiler.nodeinfo.NodeInfo;
  31 import org.graalvm.compiler.nodes.AbstractMergeNode;
  32 import org.graalvm.compiler.nodes.PhiNode;
  33 import org.graalvm.compiler.nodes.ValueNode;
  34 
  35 /**
  36  * Memory {@code PhiNode}s merge memory dependencies at control flow merges.
  37  */
  38 @NodeInfo(nameTemplate = "Phi({i#values}) {p#locationIdentity/s}", allowedUsageTypes = {InputType.Memory})
  39 public final class MemoryPhiNode extends PhiNode implements MemoryNode {
  40 
  41     public static final NodeClass<MemoryPhiNode> TYPE = NodeClass.create(MemoryPhiNode.class);
  42     @Input(InputType.Memory) NodeInputList<ValueNode> values;
  43     protected final LocationIdentity locationIdentity;
  44 
  45     public MemoryPhiNode(AbstractMergeNode merge, LocationIdentity locationIdentity) {
  46         super(TYPE, StampFactory.forVoid(), merge);
  47         this.locationIdentity = locationIdentity;
  48         this.values = new NodeInputList<>(this);
  49     }
  50 
  51     public MemoryPhiNode(AbstractMergeNode merge, LocationIdentity locationIdentity, ValueNode[] values) {
  52         super(TYPE, StampFactory.forVoid(), merge);
  53         this.locationIdentity = locationIdentity;
  54         this.values = new NodeInputList<>(this, values);
  55     }
  56 
  57     public LocationIdentity getLocationIdentity() {
  58         return locationIdentity;
  59     }
  60 
  61     @Override
  62     public NodeInputList<ValueNode> values() {
  63         return values;
  64     }
  65 }