1 /*
2 * Copyright (c) 2011, 2018, 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 */
137 return (T) canonical(tool, getX(), getY());
138 }
139 }
140
141 /**
142 * This sub-interface of {@link Canonicalizable.Binary} is for nodes with two inputs where the
143 * operation is commutative. It is used to improve GVN by trying to merge nodes with the same
144 * inputs in different order.
145 */
146 public interface BinaryCommutative<T extends Node> extends Binary<T> {
147
148 /**
149 * Ensure a canonical ordering of inputs for commutative nodes to improve GVN results. Order
150 * the inputs by increasing {@link Node#id} and call {@link Graph#findDuplicate(Node)} on
151 * the node if it's currently in a graph. It's assumed that if there was a constant on the
152 * left it's been moved to the right by other code and that ordering is left alone.
153 *
154 * @return the original node or another node with the same input ordering
155 */
156 Node maybeCommuteInputs();
157 }
158 }
|
1 /*
2 * Copyright (c) 2011, 2019, 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 */
137 return (T) canonical(tool, getX(), getY());
138 }
139 }
140
141 /**
142 * This sub-interface of {@link Canonicalizable.Binary} is for nodes with two inputs where the
143 * operation is commutative. It is used to improve GVN by trying to merge nodes with the same
144 * inputs in different order.
145 */
146 public interface BinaryCommutative<T extends Node> extends Binary<T> {
147
148 /**
149 * Ensure a canonical ordering of inputs for commutative nodes to improve GVN results. Order
150 * the inputs by increasing {@link Node#id} and call {@link Graph#findDuplicate(Node)} on
151 * the node if it's currently in a graph. It's assumed that if there was a constant on the
152 * left it's been moved to the right by other code and that ordering is left alone.
153 *
154 * @return the original node or another node with the same input ordering
155 */
156 Node maybeCommuteInputs();
157 }
158
159 /**
160 * This sub-interface of {@link Canonicalizable} is intended for nodes that have exactly three
161 * inputs. It has an additional {@link #canonical(CanonicalizerTool, Node, Node, Node)} method
162 * that looks at the given inputs instead of the current inputs of the node - which can be used
163 * to ask "what if this input is changed to this node" - questions.
164 *
165 * @param <T> the common supertype of all inputs of this node
166 */
167 public interface Ternary<T extends Node> extends Canonicalizable {
168
169 /**
170 * Similar to {@link Canonicalizable#canonical(CanonicalizerTool)}, except that
171 * implementations should act as if the current input of the node was the given one, i.e.,
172 * they should never look at the inputs via the this pointer.
173 */
174 Node canonical(CanonicalizerTool tool, T forX, T forY, T forZ);
175
176 /**
177 * Gets the current value of the input, so that calling
178 * {@link #canonical(CanonicalizerTool, Node, Node, Node)} with the value returned from this
179 * method should behave exactly like {@link Canonicalizable#canonical(CanonicalizerTool)}.
180 */
181 T getX();
182
183 /**
184 * Gets the current value of the input, so that calling
185 * {@link #canonical(CanonicalizerTool, Node, Node, Node)} with the value returned from this
186 * method should behave exactly like {@link Canonicalizable#canonical(CanonicalizerTool)}.
187 */
188 T getY();
189
190 /**
191 * Gets the current value of the input, so that calling
192 * {@link #canonical(CanonicalizerTool, Node, Node, Node)} with the value returned from this
193 * method should behave exactly like {@link Canonicalizable#canonical(CanonicalizerTool)}.
194 */
195 T getZ();
196
197 @SuppressWarnings("unchecked")
198 @Override
199 default T canonical(CanonicalizerTool tool) {
200 return (T) canonical(tool, getX(), getY(), getZ());
201 }
202 }
203 }
|