Path: blob/master/test/hotspot/jtreg/compiler/lib/ir_framework/IR.java
64507 views
/*1* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package compiler.lib.ir_framework;2425import compiler.lib.ir_framework.driver.IRViolationException;2627import java.lang.annotation.Repeatable;28import java.lang.annotation.Retention;29import java.lang.annotation.RetentionPolicy;3031/**32* This annotation is used to define a constraint/rule/check on the resulting IR of a test method (method with33* {@link Test @Test} annotation). A test method can define multiple {@code @IR} rules.34* <p>35* There are two kinds of checks that can be specified:36* <ul>37* <li><p>{@link #failOn()}: Specify a list of (node) regexes that should not be matched on the {@code PrintIdeal} or38* {@code PrintOptoAssembly} output.</li>39* <li><p>{@link #counts()}: Specify a list of ({@code regex,count}) pairs: The (node) {@code regex} should be matched40* for the specified amount in {@code count} on the {@code PrintIdeal} or {@code PrintOptoAssembly} output.</li>41* </ul>42* An IR rule must specify either or both of these two checks. If one or both of the checks fails, an43* {@link IRViolationException} is thrown. A user can provide a custom regex string or specify any of the default node44* regexes defined in {@link IRNode}.45* <p>46* Sometimes, the shape of the resulting IR is changed by commonly used VM flags in such a way that an IR rule no longer47* applies. Generally, the framework does <b>not</b> apply any IR rules when any of the following flags are used:48* {@code -Xint, -XX:-UseCompiler, -XX:TieredStopAtLevel={1,2,3}, -DExcludeRandom=true, -DFlipC1C2=true}.49* Furthermore, a JTreg test could be run with additional VM and Javaoptions flags. The IR verification is <b>not</b>50* performed in this case if any of these JTreg flags is used that is not part of the whitelist specified by51* {@link TestFramework#JTREG_WHITELIST_FLAGS}.52* <p>53* For any other flag specified either by user code (e.g. {@link Scenario#Scenario(int, String...)},54* {@link TestFramework#runWithFlags(String...) etc.} or as part of the JTreg whitelist, IR verification is applied.55* To restrict the application of IR rules when certain flags are present that could change the IR, each {@code @IR}56* annotation can specify additional preconditions on the allowed test VM flags that must hold when an IR rule is applied.57* If the specified preconditions fail, then the framework does not apply the IR rule. These preconditions can be58* set with {@link #applyIf()}, {@link #applyIfNot()}, {@link #applyIfAnd()}, or {@link #applyIfOr()}.59* <p>60* Examples on how to write tests with IR rules can be found in {@link jdk.test.lib.hotspot.ir_framework.examples.IRExample}61* and also as part of the internal testing in {@link jdk.test.lib.hotspot.ir_framework.tests.TestIRMatching}.62*63* @see Test64* @see IRNode65*/66@Retention(RetentionPolicy.RUNTIME)67@Repeatable(IRs.class)68public @interface IR {69/**70* Define a list of (node) regexes. If any of these regexes are matched on the PrintIdeal or PrintOptoAssembly, the71* IR rule fails and an {@link IRViolationException} is thrown.72*/73String[] failOn() default {};7475/**76* Define a list of ((node) regexes,count) string pairs: A regex to be matched on the PrintIdeal or PrintOptoAssembly77* is immediately followed by a number specifying how often the regex should be matched. The number can be proceeded78* by comparators ({@code =, !=, <, <=, =>, >}) where the equality operator is optional (default if no comparator is79* specified).80* <p>81* If any constraint on the number of regexes cannot be met, the IR rule fails and an82* {@link IRViolationException} is thrown.83*/84String[] counts() default {};8586/**87* Define a single VM flag precondition which <i>must hold</i> when applying the IR rule. If the VM flag precondition88* fails, then the IR rule is not applied. This is useful if a commonly used flag alters the IR in such a way that an IR rule89* would fail.90* <p>91* The precondition is a (flag, value) string pair where the flag must be a valid VM flag and the value must conform92* with the type of the VM flag. A number based flag value can be proceeded with an additional comparator93* ({@code =, !=, <, <=, =>, >}) where the equality operator is optional (default if no comparator is specified).94* <p>95* This is the inverse of {@link #applyIfNot()}. For multiple preconditions, use {@link #applyIfAnd()} or96* {@link #applyIfOr()} depending on the use case.97*/98String[] applyIf() default {};99100/**101* Define a single VM flag precondition which <i>must <b>not</b> hold</i> when applying the IR rule. If, however,102* the VM flag precondition holds, then the IR rule is not applied. This could also be defined as <i>negative</i>103* precondition. This is useful if a commonly used flag alters the IR in such a way that an IR rule would fail.104* <p>105* The precondition is a (flag, value) string pair where the flag must be a valid VM flag and the value must conform106* with the type of the VM flag. A number based flag value can be proceeded with an additional comparator107* ({@code =, !=, <, <=, =>, >}) where the equality operator is optional (default if no comparator is specified).108* <p>109* This is the inverse of {@link #applyIf()}. For multiple preconditions, use {@link #applyIfAnd()} or110* {@link #applyIfOr()} depending on the use case.111*/112String[] applyIfNot() default {};113114/**115* Define a list of at least two VM flag precondition which <i><b>all</b> must hold</i> when applying the IR rule.116* If the one of the VM flag preconditions does not hold, then the IR rule is not applied. This is useful if117* commonly used flags alter the IR in such a way that an IR rule would fail. This can also be defined as conjunction118* of preconditions.119* <p>120* A precondition is a (flag, value) string pair where the flag must be a valid VM flag and the value must conform121* with the type of the VM flag. A number based flag value can be proceeded with an additional comparator122* ({@code =, !=, <, <=, =>, >}) where the equality operator is optional (default if no comparator is specified).123* <p>124* Use {@link #applyIfOr()} for disjunction and for single precondition constraints use {@link #applyIf()} or125* {@link #applyIfNot()} depending on the use case.126*/127String[] applyIfAnd() default {};128129/**130* Define a list of at least two VM flag precondition from which <i><b>at least one</b> must hold</i> when applying131* the IR rule. If none of the VM flag preconditions holds, then the IR rule is not applied. This is useful if132* commonly used flags alter the IR in such a way that an IR rule would fail. This can also be defined as disjunction133* of preconditions.134* <p>135* A precondition is a (flag, value) string pair where the flag must be a valid VM flag and the value must conform136* with the type of the VM flag. A number based flag value can be proceeded with an additional comparator137* ({@code =, !=, <, <=, =>, >}) where the equality operator is optional (default if no comparator is specified).138* <p>139* Use {@link #applyIfAnd()} for conjunction and for single precondition constraints use {@link #applyIf()} or140* {@link #applyIfNot()} depending on the use case.141*/142String[] applyIfOr() default {};143}144145146