1 /* 2 * Copyright (c) 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.hotspot.nodes.profiling; 24 25 import org.graalvm.compiler.graph.NodeClass; 26 import org.graalvm.compiler.graph.iterators.NodeIterable; 27 import org.graalvm.compiler.nodeinfo.NodeInfo; 28 import org.graalvm.compiler.nodes.StructuredGraph; 29 import org.graalvm.compiler.nodes.ValueNode; 30 import org.graalvm.compiler.nodes.calc.ConditionalNode; 31 32 import jdk.vm.ci.meta.ResolvedJavaMethod; 33 34 @NodeInfo 35 public class ProfileBranchNode extends ProfileWithNotificationNode { 36 public static final NodeClass<ProfileBranchNode> TYPE = NodeClass.create(ProfileBranchNode.class); 37 38 @OptionalInput ValueNode branchCondition; 39 protected int bci; 40 protected int targetBci; 41 42 public ProfileBranchNode(ResolvedJavaMethod method, int freqLog, int probabilityLog, ConditionalNode branchCondition, int bci, int targetBci) { 43 super(TYPE, method, freqLog, probabilityLog); 44 assert targetBci <= bci; 45 this.branchCondition = branchCondition; 46 this.bci = bci; 47 this.targetBci = targetBci; 48 } 49 50 public ProfileBranchNode(ResolvedJavaMethod method, int freqLog, int probabilityLog, int bci, int targetBci) { 51 super(TYPE, method, freqLog, probabilityLog); 52 assert targetBci <= bci; 53 this.branchCondition = null; 54 this.bci = bci; 55 this.targetBci = targetBci; 56 } 57 58 public int bci() { 59 return bci; 60 } 61 62 public int targetBci() { 63 return targetBci; 64 } 65 66 public ValueNode branchCondition() { 67 return branchCondition; 68 } 69 70 public boolean hasCondition() { 71 return branchCondition != null; 72 } 73 74 /** 75 * Gathers all the {@link ProfileBranchNode}s that are inputs to the 76 * {@linkplain StructuredGraph#getNodes() live nodes} in a given graph. 77 */ 78 public static NodeIterable<ProfileBranchNode> getProfileBranchNodes(StructuredGraph graph) { 79 return graph.getNodes().filter(ProfileBranchNode.class); 80 } 81 }