MergeableState.java revision 12651:6ef01bd40ce2
1/*
2 * Copyright (c) 2011, 2011, 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 */
23package org.graalvm.compiler.phases.graph;
24
25import java.util.List;
26
27import org.graalvm.compiler.nodes.AbstractBeginNode;
28import org.graalvm.compiler.nodes.AbstractMergeNode;
29import org.graalvm.compiler.nodes.ControlSplitNode;
30import org.graalvm.compiler.nodes.LoopBeginNode;
31import org.graalvm.compiler.nodes.LoopEndNode;
32
33public abstract class MergeableState<T> {
34
35    @Override
36    public abstract T clone();
37
38    /**
39     * This method is called on merge on the state of the first branch. The {@code withStates} list
40     * contains the states of the of the other branches in the order of the merge's end nodes.
41     *
42     * @param merge the merge node
43     * @param withStates the state at the the merge's end node except the first one.
44     */
45    public abstract boolean merge(AbstractMergeNode merge, List<T> withStates);
46
47    /**
48     * This method is called before a loop is entered (before the {@link LoopBeginNode} is visited).
49     *
50     * @param loopBegin the begin node of the loop
51     */
52    public void loopBegin(LoopBeginNode loopBegin) {
53        // empty default implementation
54    }
55
56    /**
57     * This method is called after all {@link LoopEndNode}s belonging to a loop have been visited.
58     *
59     * @param loopBegin the begin node of the loop
60     * @param loopEndStates the states at the loop ends, sorted according to
61     *            {@link LoopBeginNode#orderedLoopEnds()}
62     */
63    public void loopEnds(LoopBeginNode loopBegin, List<T> loopEndStates) {
64        // empty default implementation
65    }
66
67    /**
68     * This method is called before the successors of a {@link ControlSplitNode} are visited.
69     *
70     * @param node the successor of the control split that is about to be visited
71     */
72    public void afterSplit(AbstractBeginNode node) {
73        // empty default implementation
74    }
75}
76