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
24 package compiler.lib.ir_framework;
25
26 import compiler.lib.ir_framework.driver.irmatching.mapping.*;
27 import compiler.lib.ir_framework.driver.irmatching.parser.VMInfo;
28 import compiler.lib.ir_framework.shared.CheckedTestFrameworkException;
29 import compiler.lib.ir_framework.shared.TestFormat;
30 import compiler.lib.ir_framework.shared.TestFormatException;
31 import jdk.test.lib.Platform;
32 import jdk.test.whitebox.WhiteBox;
33
34 import java.util.HashMap;
35 import java.util.Map;
36
37 /**
38 * This class specifies IR node placeholder strings (also referred to as just "IR nodes") with mappings to regexes
39 * depending on the selected compile phases. The mappings are stored in {@link #IR_NODE_MAPPINGS}. Each IR node
40 * placeholder string is mapped to a {@link IRNodeMapEntry} instance defined in
41 * {@link compiler.lib.ir_framework.driver.irmatching.mapping}.
42 *
43 * <p>
44 * IR node placeholder strings can be used in {@link IR#failOn()} and/or {@link IR#counts()} attributes to define IR
45 * constraints. They usually represent a single C2 IR node or a group of them.
46 *
47 * <p>
48 * Each IR node placeholder string is accompanied by a static block that defines an IR node placeholder to regex(es)
49 * mapping. The IR framework will automatically replace each IR node placeholder string in a user defined test with a
50 * regex depending on the selected compile phases in {@link IR#phase} and the provided mapping.
135 /**
136 * Map every vectorNode to a type string.
137 */
138 private static final Map<String, String> VECTOR_NODE_TYPE = new HashMap<>();
139
140 /*
141 * Start of IR placeholder string definitions followed by a static block defining the regex-for-compile-phase mapping.
142 * An IR node placeholder string must start with PREFIX for normal IR nodes or COMPOSITE_PREFIX for composite IR
143 * nodes, or VECTOR_PREFIX for vector nodes (see class description above).
144 *
145 * An IR node definition looks like this:
146 *
147 * public static final String IR_NODE = [PREFIX|COMPOSITE_PREFIX|VECTOR_PREFIX] + "IR_NODE" + POSTFIX;
148 * static {
149 * // Define IR_NODE to regex-for-compile-phase mapping. Create a new IRNodeMapEntry object and add it to
150 * // IR_NODE_MAPPINGS. This can be done by using the helper methods defined after all IR node placeholder string
151 * // definitions.
152 * }
153 */
154
155 public static final String ABS_D = PREFIX + "ABS_D" + POSTFIX;
156 static {
157 beforeMatchingNameRegex(ABS_D, "AbsD");
158 }
159
160 public static final String ABS_F = PREFIX + "ABS_F" + POSTFIX;
161 static {
162 beforeMatchingNameRegex(ABS_F, "AbsF");
163 }
164
165 public static final String ABS_I = PREFIX + "ABS_I" + POSTFIX;
166 static {
167 beforeMatchingNameRegex(ABS_I, "AbsI");
168 }
169
170 public static final String ABS_L = PREFIX + "ABS_L" + POSTFIX;
171 static {
172 beforeMatchingNameRegex(ABS_L, "AbsL");
173 }
174
805 String regex = START + "g1StoreN\\S*" + MID + "barrier\\(\\s*" + IS_REPLACED + "\\s*\\)" + END;
806 machOnly(G1_STORE_N_WITH_BARRIER_FLAG, regex);
807 }
808
809 public static final String G1_STORE_P = PREFIX + "G1_STORE_P" + POSTFIX;
810 static {
811 machOnlyNameRegex(G1_STORE_P, "g1StoreP");
812 }
813
814 public static final String G1_STORE_P_WITH_BARRIER_FLAG = COMPOSITE_PREFIX + "G1_STORE_P_WITH_BARRIER_FLAG" + POSTFIX;
815 static {
816 String regex = START + "g1StoreP\\S*" + MID + "barrier\\(\\s*" + IS_REPLACED + "\\s*\\)" + END;
817 machOnly(G1_STORE_P_WITH_BARRIER_FLAG, regex);
818 }
819
820 public static final String IF = PREFIX + "IF" + POSTFIX;
821 static {
822 beforeMatchingNameRegex(IF, "If\\b");
823 }
824
825 // Does not work for VM builds without JVMCI like x86_32 (a rule containing this regex will be skipped without having JVMCI built).
826 public static final String INTRINSIC_OR_TYPE_CHECKED_INLINING_TRAP = PREFIX + "INTRINSIC_OR_TYPE_CHECKED_INLINING_TRAP" + POSTFIX;
827 static {
828 trapNodes(INTRINSIC_OR_TYPE_CHECKED_INLINING_TRAP, "intrinsic_or_type_checked_inlining");
829 }
830
831 public static final String INTRINSIC_TRAP = PREFIX + "INTRINSIC_TRAP" + POSTFIX;
832 static {
833 trapNodes(INTRINSIC_TRAP, "intrinsic");
834 }
835
836 // Is only supported on riscv64.
837 public static final String IS_FINITE_D = PREFIX + "IS_FINITE_D" + POSTFIX;
838 static {
839 beforeMatchingNameRegex(IS_FINITE_D, "IsFiniteD");
840 }
841
842 // Is only supported on riscv64.
843 public static final String IS_FINITE_F = PREFIX + "IS_FINITE_F" + POSTFIX;
844 static {
1941 vectorNode(SUB_VI, "SubVI", TYPE_INT);
1942 }
1943
1944 public static final String SUB_VL = VECTOR_PREFIX + "SUB_VL" + POSTFIX;
1945 static {
1946 vectorNode(SUB_VL, "SubVL", TYPE_LONG);
1947 }
1948
1949 public static final String SUB_VF = VECTOR_PREFIX + "SUB_VF" + POSTFIX;
1950 static {
1951 vectorNode(SUB_VF, "SubVF", TYPE_FLOAT);
1952 }
1953
1954 public static final String SUB_VD = VECTOR_PREFIX + "SUB_VD" + POSTFIX;
1955 static {
1956 vectorNode(SUB_VD, "SubVD", TYPE_DOUBLE);
1957 }
1958
1959 public static final String SUBTYPE_CHECK = PREFIX + "SUBTYPE_CHECK" + POSTFIX;
1960 static {
1961 beforeMatchingNameRegex(SUBTYPE_CHECK, "SubTypeCheck");
1962 }
1963
1964 public static final String TRAP = PREFIX + "TRAP" + POSTFIX;
1965 static {
1966 trapNodes(TRAP, "reason");
1967 }
1968
1969 public static final String DIV_HF = PREFIX + "DIV_HF" + POSTFIX;
1970 static {
1971 beforeMatchingNameRegex(DIV_HF, "DivHF");
1972 }
1973
1974 public static final String UDIV_I = PREFIX + "UDIV_I" + POSTFIX;
1975 static {
1976 beforeMatchingNameRegex(UDIV_I, "UDivI");
1977 }
1978
1979 public static final String UDIV_L = PREFIX + "UDIV_L" + POSTFIX;
1980 static {
1981 beforeMatchingNameRegex(UDIV_L, "UDivL");
2658 public static final String MOD_F = PREFIX + "MOD_F" + POSTFIX;
2659 static {
2660 String regex = START + "ModF" + MID + END;
2661 macroNodes(MOD_F, regex);
2662 }
2663
2664 public static final String MOD_D = PREFIX + "MOD_D" + POSTFIX;
2665 static {
2666 String regex = START + "ModD" + MID + END;
2667 macroNodes(MOD_D, regex);
2668 }
2669
2670 /*
2671 * Utility methods to set up IR_NODE_MAPPINGS.
2672 */
2673
2674 /**
2675 * Apply {@code regex} on all machine independent ideal graph phases up to and including
2676 * {@link CompilePhase#BEFORE_MATCHING}.
2677 */
2678 private static void beforeMatching(String irNodePlaceholder, String regex) {
2679 IR_NODE_MAPPINGS.put(irNodePlaceholder, new RegexTypeEntry(RegexType.IDEAL_INDEPENDENT, regex));
2680 }
2681
2682 /**
2683 * Apply {@code irNodeRegex} as regex for the IR node name on all machine independent ideal graph phases up to and
2684 * including {@link CompilePhase#BEFORE_MATCHING}.
2685 */
2686 private static void beforeMatchingNameRegex(String irNodePlaceholder, String irNodeRegex) {
2687 String regex = START + irNodeRegex + MID + END;
2688 IR_NODE_MAPPINGS.put(irNodePlaceholder, new RegexTypeEntry(RegexType.IDEAL_INDEPENDENT, regex));
2689 }
2690
2691 /**
2692 * Apply {@code irNodeRegex} as regex for the IR vector node name on all machine independent ideal graph phases up to and
2693 * including {@link CompilePhase#BEFORE_MATCHING}. Since this is a vector node, we can also check the vector element
2694 * type {@code typeString} and the vector size (number of elements), {@see VECTOR_SIZE}.
2695 */
2696 private static void vectorNode(String irNodePlaceholder, String irNodeRegex, String typeString) {
2697 TestFramework.check(isVectorIRNode(irNodePlaceholder), "vectorNode: failed prefix check for irNodePlaceholder "
2698 + irNodePlaceholder + " -> did you use VECTOR_PREFIX?");
2703 }
2704
2705 /**
2706 * Apply {@code regex} on all ideal graph phases up to and including {@link CompilePhase#BEFORE_MACRO_EXPANSION}.
2707 */
2708 private static void macroNodes(String irNodePlaceholder, String regex) {
2709 IR_NODE_MAPPINGS.put(irNodePlaceholder, new SinglePhaseRangeEntry(CompilePhase.BEFORE_MACRO_EXPANSION, regex,
2710 CompilePhase.BEFORE_STRINGOPTS,
2711 CompilePhase.BEFORE_MACRO_EXPANSION));
2712 }
2713
2714 private static void callOfNodes(String irNodePlaceholder, String callRegex) {
2715 String regex = START + callRegex + MID + IS_REPLACED + " " + END;
2716 IR_NODE_MAPPINGS.put(irNodePlaceholder, new RegexTypeEntry(RegexType.IDEAL_INDEPENDENT, regex));
2717 }
2718
2719 /**
2720 * Apply {@code regex} on all machine dependant ideal graph phases (i.e. on the mach graph) starting from
2721 * {@link CompilePhase#MATCHING}.
2722 */
2723 private static void optoOnly(String irNodePlaceholder, String regex) {
2724 IR_NODE_MAPPINGS.put(irNodePlaceholder, new RegexTypeEntry(RegexType.OPTO_ASSEMBLY, regex));
2725 }
2726
2727 private static void machOnly(String irNodePlaceholder, String regex) {
2728 IR_NODE_MAPPINGS.put(irNodePlaceholder, new RegexTypeEntry(RegexType.MACH, regex));
2729 }
2730
2731 private static void machOnlyNameRegex(String irNodePlaceholder, String irNodeRegex) {
2732 String regex = START + irNodeRegex + MID + END;
2733 IR_NODE_MAPPINGS.put(irNodePlaceholder, new RegexTypeEntry(RegexType.MACH, regex));
2734 }
2735
2736 /**
2737 * Apply {@code regex} on all ideal graph phases starting from {@link CompilePhase#AFTER_CLOOPS}.
2738 */
2739 private static void fromAfterCountedLoops(String irNodePlaceholder, String regex) {
2740 IR_NODE_MAPPINGS.put(irNodePlaceholder, new SinglePhaseRangeEntry(CompilePhase.PRINT_IDEAL, regex,
2741 CompilePhase.AFTER_CLOOPS,
2742 CompilePhase.FINAL_CODE));
2743 }
|
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
24 package compiler.lib.ir_framework;
25
26 import compiler.lib.ir_framework.driver.irmatching.mapping.*;
27 import compiler.lib.ir_framework.driver.irmatching.parser.VMInfo;
28 import compiler.lib.ir_framework.shared.CheckedTestFrameworkException;
29 import compiler.lib.ir_framework.shared.TestFormat;
30 import compiler.lib.ir_framework.shared.TestFormatException;
31 import compiler.valhalla.inlinetypes.InlineTypeIRNode;
32 import jdk.test.lib.Platform;
33 import jdk.test.whitebox.WhiteBox;
34
35 import java.util.HashMap;
36 import java.util.Map;
37
38 /**
39 * This class specifies IR node placeholder strings (also referred to as just "IR nodes") with mappings to regexes
40 * depending on the selected compile phases. The mappings are stored in {@link #IR_NODE_MAPPINGS}. Each IR node
41 * placeholder string is mapped to a {@link IRNodeMapEntry} instance defined in
42 * {@link compiler.lib.ir_framework.driver.irmatching.mapping}.
43 *
44 * <p>
45 * IR node placeholder strings can be used in {@link IR#failOn()} and/or {@link IR#counts()} attributes to define IR
46 * constraints. They usually represent a single C2 IR node or a group of them.
47 *
48 * <p>
49 * Each IR node placeholder string is accompanied by a static block that defines an IR node placeholder to regex(es)
50 * mapping. The IR framework will automatically replace each IR node placeholder string in a user defined test with a
51 * regex depending on the selected compile phases in {@link IR#phase} and the provided mapping.
136 /**
137 * Map every vectorNode to a type string.
138 */
139 private static final Map<String, String> VECTOR_NODE_TYPE = new HashMap<>();
140
141 /*
142 * Start of IR placeholder string definitions followed by a static block defining the regex-for-compile-phase mapping.
143 * An IR node placeholder string must start with PREFIX for normal IR nodes or COMPOSITE_PREFIX for composite IR
144 * nodes, or VECTOR_PREFIX for vector nodes (see class description above).
145 *
146 * An IR node definition looks like this:
147 *
148 * public static final String IR_NODE = [PREFIX|COMPOSITE_PREFIX|VECTOR_PREFIX] + "IR_NODE" + POSTFIX;
149 * static {
150 * // Define IR_NODE to regex-for-compile-phase mapping. Create a new IRNodeMapEntry object and add it to
151 * // IR_NODE_MAPPINGS. This can be done by using the helper methods defined after all IR node placeholder string
152 * // definitions.
153 * }
154 */
155
156 // Valhalla: Make sure that all Valhalla specific IR nodes are also properly initialized. Doing it here also
157 // ensures that the Flag VM is able to pick up the correct compile phases.
158 static {
159 InlineTypeIRNode.forceStaticInitialization();
160 }
161
162 public static final String ABS_D = PREFIX + "ABS_D" + POSTFIX;
163 static {
164 beforeMatchingNameRegex(ABS_D, "AbsD");
165 }
166
167 public static final String ABS_F = PREFIX + "ABS_F" + POSTFIX;
168 static {
169 beforeMatchingNameRegex(ABS_F, "AbsF");
170 }
171
172 public static final String ABS_I = PREFIX + "ABS_I" + POSTFIX;
173 static {
174 beforeMatchingNameRegex(ABS_I, "AbsI");
175 }
176
177 public static final String ABS_L = PREFIX + "ABS_L" + POSTFIX;
178 static {
179 beforeMatchingNameRegex(ABS_L, "AbsL");
180 }
181
812 String regex = START + "g1StoreN\\S*" + MID + "barrier\\(\\s*" + IS_REPLACED + "\\s*\\)" + END;
813 machOnly(G1_STORE_N_WITH_BARRIER_FLAG, regex);
814 }
815
816 public static final String G1_STORE_P = PREFIX + "G1_STORE_P" + POSTFIX;
817 static {
818 machOnlyNameRegex(G1_STORE_P, "g1StoreP");
819 }
820
821 public static final String G1_STORE_P_WITH_BARRIER_FLAG = COMPOSITE_PREFIX + "G1_STORE_P_WITH_BARRIER_FLAG" + POSTFIX;
822 static {
823 String regex = START + "g1StoreP\\S*" + MID + "barrier\\(\\s*" + IS_REPLACED + "\\s*\\)" + END;
824 machOnly(G1_STORE_P_WITH_BARRIER_FLAG, regex);
825 }
826
827 public static final String IF = PREFIX + "IF" + POSTFIX;
828 static {
829 beforeMatchingNameRegex(IF, "If\\b");
830 }
831
832 public static final String INLINE_TYPE = PREFIX + "INLINE_TYPE" + POSTFIX;
833 static {
834 beforeMatchingNameRegex(INLINE_TYPE, "InlineType");
835 }
836
837 // Does not work for VM builds without JVMCI like x86_32 (a rule containing this regex will be skipped without having JVMCI built).
838 public static final String INTRINSIC_OR_TYPE_CHECKED_INLINING_TRAP = PREFIX + "INTRINSIC_OR_TYPE_CHECKED_INLINING_TRAP" + POSTFIX;
839 static {
840 trapNodes(INTRINSIC_OR_TYPE_CHECKED_INLINING_TRAP, "intrinsic_or_type_checked_inlining");
841 }
842
843 public static final String INTRINSIC_TRAP = PREFIX + "INTRINSIC_TRAP" + POSTFIX;
844 static {
845 trapNodes(INTRINSIC_TRAP, "intrinsic");
846 }
847
848 // Is only supported on riscv64.
849 public static final String IS_FINITE_D = PREFIX + "IS_FINITE_D" + POSTFIX;
850 static {
851 beforeMatchingNameRegex(IS_FINITE_D, "IsFiniteD");
852 }
853
854 // Is only supported on riscv64.
855 public static final String IS_FINITE_F = PREFIX + "IS_FINITE_F" + POSTFIX;
856 static {
1953 vectorNode(SUB_VI, "SubVI", TYPE_INT);
1954 }
1955
1956 public static final String SUB_VL = VECTOR_PREFIX + "SUB_VL" + POSTFIX;
1957 static {
1958 vectorNode(SUB_VL, "SubVL", TYPE_LONG);
1959 }
1960
1961 public static final String SUB_VF = VECTOR_PREFIX + "SUB_VF" + POSTFIX;
1962 static {
1963 vectorNode(SUB_VF, "SubVF", TYPE_FLOAT);
1964 }
1965
1966 public static final String SUB_VD = VECTOR_PREFIX + "SUB_VD" + POSTFIX;
1967 static {
1968 vectorNode(SUB_VD, "SubVD", TYPE_DOUBLE);
1969 }
1970
1971 public static final String SUBTYPE_CHECK = PREFIX + "SUBTYPE_CHECK" + POSTFIX;
1972 static {
1973 macroNodes(SUBTYPE_CHECK, "SubTypeCheck");
1974 }
1975
1976 public static final String TRAP = PREFIX + "TRAP" + POSTFIX;
1977 static {
1978 trapNodes(TRAP, "reason");
1979 }
1980
1981 public static final String DIV_HF = PREFIX + "DIV_HF" + POSTFIX;
1982 static {
1983 beforeMatchingNameRegex(DIV_HF, "DivHF");
1984 }
1985
1986 public static final String UDIV_I = PREFIX + "UDIV_I" + POSTFIX;
1987 static {
1988 beforeMatchingNameRegex(UDIV_I, "UDivI");
1989 }
1990
1991 public static final String UDIV_L = PREFIX + "UDIV_L" + POSTFIX;
1992 static {
1993 beforeMatchingNameRegex(UDIV_L, "UDivL");
2670 public static final String MOD_F = PREFIX + "MOD_F" + POSTFIX;
2671 static {
2672 String regex = START + "ModF" + MID + END;
2673 macroNodes(MOD_F, regex);
2674 }
2675
2676 public static final String MOD_D = PREFIX + "MOD_D" + POSTFIX;
2677 static {
2678 String regex = START + "ModD" + MID + END;
2679 macroNodes(MOD_D, regex);
2680 }
2681
2682 /*
2683 * Utility methods to set up IR_NODE_MAPPINGS.
2684 */
2685
2686 /**
2687 * Apply {@code regex} on all machine independent ideal graph phases up to and including
2688 * {@link CompilePhase#BEFORE_MATCHING}.
2689 */
2690 public static void beforeMatching(String irNodePlaceholder, String regex) {
2691 IR_NODE_MAPPINGS.put(irNodePlaceholder, new RegexTypeEntry(RegexType.IDEAL_INDEPENDENT, regex));
2692 }
2693
2694 /**
2695 * Apply {@code irNodeRegex} as regex for the IR node name on all machine independent ideal graph phases up to and
2696 * including {@link CompilePhase#BEFORE_MATCHING}.
2697 */
2698 private static void beforeMatchingNameRegex(String irNodePlaceholder, String irNodeRegex) {
2699 String regex = START + irNodeRegex + MID + END;
2700 IR_NODE_MAPPINGS.put(irNodePlaceholder, new RegexTypeEntry(RegexType.IDEAL_INDEPENDENT, regex));
2701 }
2702
2703 /**
2704 * Apply {@code irNodeRegex} as regex for the IR vector node name on all machine independent ideal graph phases up to and
2705 * including {@link CompilePhase#BEFORE_MATCHING}. Since this is a vector node, we can also check the vector element
2706 * type {@code typeString} and the vector size (number of elements), {@see VECTOR_SIZE}.
2707 */
2708 private static void vectorNode(String irNodePlaceholder, String irNodeRegex, String typeString) {
2709 TestFramework.check(isVectorIRNode(irNodePlaceholder), "vectorNode: failed prefix check for irNodePlaceholder "
2710 + irNodePlaceholder + " -> did you use VECTOR_PREFIX?");
2715 }
2716
2717 /**
2718 * Apply {@code regex} on all ideal graph phases up to and including {@link CompilePhase#BEFORE_MACRO_EXPANSION}.
2719 */
2720 private static void macroNodes(String irNodePlaceholder, String regex) {
2721 IR_NODE_MAPPINGS.put(irNodePlaceholder, new SinglePhaseRangeEntry(CompilePhase.BEFORE_MACRO_EXPANSION, regex,
2722 CompilePhase.BEFORE_STRINGOPTS,
2723 CompilePhase.BEFORE_MACRO_EXPANSION));
2724 }
2725
2726 private static void callOfNodes(String irNodePlaceholder, String callRegex) {
2727 String regex = START + callRegex + MID + IS_REPLACED + " " + END;
2728 IR_NODE_MAPPINGS.put(irNodePlaceholder, new RegexTypeEntry(RegexType.IDEAL_INDEPENDENT, regex));
2729 }
2730
2731 /**
2732 * Apply {@code regex} on all machine dependant ideal graph phases (i.e. on the mach graph) starting from
2733 * {@link CompilePhase#MATCHING}.
2734 */
2735 public static void optoOnly(String irNodePlaceholder, String regex) {
2736 IR_NODE_MAPPINGS.put(irNodePlaceholder, new RegexTypeEntry(RegexType.OPTO_ASSEMBLY, regex));
2737 }
2738
2739 private static void machOnly(String irNodePlaceholder, String regex) {
2740 IR_NODE_MAPPINGS.put(irNodePlaceholder, new RegexTypeEntry(RegexType.MACH, regex));
2741 }
2742
2743 private static void machOnlyNameRegex(String irNodePlaceholder, String irNodeRegex) {
2744 String regex = START + irNodeRegex + MID + END;
2745 IR_NODE_MAPPINGS.put(irNodePlaceholder, new RegexTypeEntry(RegexType.MACH, regex));
2746 }
2747
2748 /**
2749 * Apply {@code regex} on all ideal graph phases starting from {@link CompilePhase#AFTER_CLOOPS}.
2750 */
2751 private static void fromAfterCountedLoops(String irNodePlaceholder, String regex) {
2752 IR_NODE_MAPPINGS.put(irNodePlaceholder, new SinglePhaseRangeEntry(CompilePhase.PRINT_IDEAL, regex,
2753 CompilePhase.AFTER_CLOOPS,
2754 CompilePhase.FINAL_CODE));
2755 }
|