Skip to content

Commit

Permalink
8294236: [IR Framework] CPU preconditions are overriden by regular pr…
Browse files Browse the repository at this point in the history
…econditions

Reviewed-by: chagedorn, pli, kvn
  • Loading branch information
robcasloz committed Oct 3, 2022
1 parent 8e9cfeb commit 5fe837a
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 65 deletions.
2 changes: 1 addition & 1 deletion test/hotspot/jtreg/compiler/lib/ir_framework/README.md
Expand Up @@ -64,7 +64,7 @@ An IR verification cannot always be performed. For example, a JTreg test could b

In general, the framework will only perform IR verification if the used VM flags allow a C2 compilation and if non-critical additional JTreg VM and Javaoptions are provided (see whiteflag list in [TestFramework](./TestFramework.java)). The user test code, however, can specify any flags which still allow an IR verification to be performed if a C2 compilation is done (expected flags by user defined `@IR` annotations).

An `@IR` annotation allows additional preconditions/restrictions on the currently present VM flags to enable or disable rules when certain flags are present or have a specific value (see `applyIfXX` properties of an `@IR` annotation).
An `@IR` annotation allows additional preconditions/restrictions on the currently present VM flags to enable or disable rules when certain flags are present or have a specific value (see `applyIfXX` properties of an `@IR` annotation). If a `@Test` annotated method has multiple preconditions (for example `applyIf` and `applyIfCPUFeature`), they are evaluated as a logical conjunction.

More information about IR matching can be found in the Javadocs of [IR](./IR.java). Concrete examples on how to specify IR constraint/rules can be found in [IRExample](../../../testlibrary_tests/ir_framework/examples/IRExample.java) and [TestIRMatching](../../../testlibrary_tests/ir_framework/tests/TestIRMatching.java) (an internal framework test).

Expand Down
Expand Up @@ -95,75 +95,40 @@ public void emitRuleEncoding(Method m, boolean skipped) {
}
}

private void printDisableReason(String method, String reason) {
TestFrameworkSocket.write("Disabling IR matching for " + method + ": " + reason + ".",
"[IREncodingPrinter]", true);
}

private boolean shouldApplyIrRule(IR irAnno, String m) {
checkIRAnnotations(irAnno);
if (isDefaultRegexUnsupported(irAnno)) {
return false;
} else if (irAnno.applyIf().length != 0 && !hasAllRequiredFlags(irAnno.applyIf(), "applyIf")) {
printDisableReason(m, "Flag constraint not met");
return false;
} else if (irAnno.applyIfNot().length != 0 && !hasNoRequiredFlags(irAnno.applyIfNot(), "applyIfNot")) {
printDisableReason(m, "Flag constraint not met");
return false;
} else if (irAnno.applyIfAnd().length != 0 && !hasAllRequiredFlags(irAnno.applyIfAnd(), "applyIfAnd")) {
printDisableReason(m, "All flag constraints not met");
return false;
} else if (irAnno.applyIfOr().length != 0 && hasNoRequiredFlags(irAnno.applyIfOr(), "applyIfOr")) {
printDisableReason(m, "None of the flag constraints met");
return false;
} else if (irAnno.applyIfCPUFeature().length != 0 && !hasAllRequiredCPUFeature(irAnno.applyIfCPUFeature())) {
printDisableReason(m, "Feature constraint not met");
return false;
} else if (irAnno.applyIfCPUFeatureAnd().length != 0 && !hasAllRequiredCPUFeature(irAnno.applyIfCPUFeatureAnd())) {
printDisableReason(m, "All feature constraints not met");
return false;
} else if (irAnno.applyIfCPUFeatureOr().length != 0 && !hasAnyRequiredCPUFeature(irAnno.applyIfCPUFeatureOr())) {
printDisableReason(m, "None of the feature constraints met");
return false;
} else {
// All preconditions satisfied: apply rule.
return true;
}
if (irAnno.applyIf().length != 0) {
boolean check = hasAllRequiredFlags(irAnno.applyIf(), "applyIf");
if (!check) {
TestFrameworkSocket.write("Disabling IR matching for " + m + ": Flag constraint not met.",
"[IREncodingPrinter]", true);
}
return check;
}

if (irAnno.applyIfNot().length != 0) {
boolean check = hasNoRequiredFlags(irAnno.applyIfNot(), "applyIfNot");
if (!check) {
TestFrameworkSocket.write("Disabling IR matching for " + m + ": Flag constraint not met.",
"[IREncodingPrinter]", true);
}
return check;
}

if (irAnno.applyIfAnd().length != 0) {
boolean check = hasAllRequiredFlags(irAnno.applyIfAnd(), "applyIfAnd");
if (!check) {
TestFrameworkSocket.write("Disabling IR matching for " + m + ": All flag constraints not met.",
"[IREncodingPrinter]", true);
}
return check;
}

if (irAnno.applyIfOr().length != 0) {
boolean check = hasNoRequiredFlags(irAnno.applyIfOr(), "applyIfOr");
if (check) {
TestFrameworkSocket.write("Disabling IR matching for " + m + ": None of the flag constraint met.",
"[IREncodingPrinter]", true);
}
return !check;
}

if (irAnno.applyIfCPUFeature().length != 0) {
boolean check = hasAllRequiredCPUFeature(irAnno.applyIfCPUFeature());
if (!check) {
TestFrameworkSocket.write("Disabling IR matching for " + m + ": Feature constraint not met.",
"[IREncodingPrinter]", true);
}
return check;
}

if (irAnno.applyIfCPUFeatureAnd().length != 0) {
boolean check = hasAllRequiredCPUFeature(irAnno.applyIfCPUFeatureAnd());
if (!check) {
TestFrameworkSocket.write("Disabling IR matching for " + m + ": All feature constraints not met.",
"[IREncodingPrinter]", true);
}
return check;
}

if (irAnno.applyIfCPUFeatureOr().length != 0) {
boolean check = hasAnyRequiredCPUFeature(irAnno.applyIfCPUFeatureOr());
if (!check) {
TestFrameworkSocket.write("Disabling IR matching for " + m + ": None of the feature constraint met.",
"[IREncodingPrinter]", true);
}
return check;
}
// No conditions, always apply.
return true;
}

private void checkIRAnnotations(IR irAnno) {
Expand Down
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/**
* @test 8294236
* @summary Tests different sources and combinations of preconditions.
* @library /test/lib /
* @requires vm.compiler2.enabled
* @run driver ir_framework.tests.TestPreconditions
*/

package ir_framework.tests;

import compiler.lib.ir_framework.*;

public class TestPreconditions {

public static void main(String[] args) {
TestFramework.runWithFlags("-XX:LoopMaxUnroll=8");
}

// The IR check should not be applied, since the VM is run with LoopMaxUnroll=8.
@Test
@IR(applyIf = {"LoopMaxUnroll", "= 0"},
counts = {IRNode.LOOP, ">= 1000"})
public static void testApplyIfOnly() {}

// The IR check should not be applied, since the CPU feature does not exist.
@Test
@IR(applyIfCPUFeature = {"this-feature-does-not-exist-at-all", "true"},
counts = {IRNode.LOOP, ">= 1000"})
public static void testApplyIfCPUFeatureOnly() {}

// The IR check should not be applied, since the CPU feature does not exist.
@Test
@IR(applyIfCPUFeature = {"this-feature-does-not-exist-at-all", "true"},
applyIf = {"LoopMaxUnroll", "= 8"},
counts = {IRNode.LOOP, ">= 1000"})
public static void testApplyBoth() {}

}

0 comments on commit 5fe837a

Please sign in to comment.