summaryrefslogtreecommitdiff
path: root/compiler/optimizing
diff options
context:
space:
mode:
author Chris Jones <christopher.jones@arm.com> 2024-09-20 17:28:33 +0100
committer Santiago Aboy Solanes <solanes@google.com> 2024-10-15 16:29:45 +0000
commitb50d59f4ca5557a7719dc26157f8f2fd9006913a (patch)
tree5d0c3f9b14302aa128a96d838b0bb683374309fe /compiler/optimizing
parent8c67e8c9c176f19fc491bac796a59d9d77a6e41b (diff)
Verify hardware supports ISA features in tests
When running codegen tests, verify that the ISA features used in the codegen are supported by the hardware. This strengthens checks for gtests that may use ISA features which are not supported by the hardware and therefore should not be run on that hardware. Test: art/test.py --gtest art_compiler_tests Change-Id: I56ebd6e964947fe004f466010a18faceb019bfae
Diffstat (limited to 'compiler/optimizing')
-rw-r--r--compiler/optimizing/codegen_test.cc2
-rw-r--r--compiler/optimizing/codegen_test_utils.h31
-rw-r--r--compiler/optimizing/scheduler_test.cc2
3 files changed, 25 insertions, 10 deletions
diff --git a/compiler/optimizing/codegen_test.cc b/compiler/optimizing/codegen_test.cc
index 14a419fcd8..75b0ea2a08 100644
--- a/compiler/optimizing/codegen_test.cc
+++ b/compiler/optimizing/codegen_test.cc
@@ -56,7 +56,7 @@ static ::std::vector<CodegenTargetConfig> GetTargetConfigs() {
};
for (const CodegenTargetConfig& test_config : test_config_candidates) {
- if (CanExecute(test_config.GetInstructionSet())) {
+ if (CanExecuteISA(test_config.GetInstructionSet())) {
v.push_back(test_config);
}
}
diff --git a/compiler/optimizing/codegen_test_utils.h b/compiler/optimizing/codegen_test_utils.h
index a8425c9915..130c796652 100644
--- a/compiler/optimizing/codegen_test_utils.h
+++ b/compiler/optimizing/codegen_test_utils.h
@@ -167,15 +167,30 @@ class TestCodeGeneratorX86 : public x86::CodeGeneratorX86 {
};
#endif
-static bool CanExecuteOnHardware(InstructionSet target_isa) {
+// Check that the current runtime ISA matches the target ISA.
+static bool DoesHardwareSupportISA(InstructionSet target_isa) {
return (target_isa == kRuntimeISA)
// Handle the special case of ARM, with two instructions sets (ARM32 and Thumb-2).
|| (kRuntimeISA == InstructionSet::kArm && target_isa == InstructionSet::kThumb2);
}
-static bool CanExecute(InstructionSet target_isa) {
+// Check that the current runtime ISA matches the target ISA and the ISA features requested are
+// available on the hardware.
+static bool CanExecuteOnHardware(const CodeGenerator& codegen) {
+ const InstructionSetFeatures* isa_features =
+ codegen.GetCompilerOptions().GetInstructionSetFeatures();
+ return DoesHardwareSupportISA(codegen.GetInstructionSet())
+ && InstructionSetFeatures::FromHwcap()->HasAtLeast(isa_features);
+}
+
+static bool CanExecuteISA(InstructionSet target_isa) {
CodeSimulatorContainer simulator(target_isa);
- return CanExecuteOnHardware(target_isa) || simulator.CanSimulate();
+ return DoesHardwareSupportISA(target_isa) || simulator.CanSimulate();
+}
+
+static bool CanExecute(const CodeGenerator& codegen) {
+ CodeSimulatorContainer simulator(codegen.GetInstructionSet());
+ return CanExecuteOnHardware(codegen) || simulator.CanSimulate();
}
template <typename Expected>
@@ -200,14 +215,14 @@ inline int64_t SimulatorExecute<int64_t>(CodeSimulator* simulator, int64_t (*f)(
}
template <typename Expected>
-static void VerifyGeneratedCode(InstructionSet target_isa,
+static void VerifyGeneratedCode(const CodeGenerator& codegen,
Expected (*f)(),
bool has_result,
Expected expected) {
- ASSERT_TRUE(CanExecute(target_isa)) << "Target isa is not executable.";
+ ASSERT_TRUE(CanExecute(codegen)) << "Target isa is not executable.";
// Verify on simulator.
- CodeSimulatorContainer simulator(target_isa);
+ CodeSimulatorContainer simulator(codegen.GetInstructionSet());
if (simulator.CanSimulate()) {
Expected result = SimulatorExecute<Expected>(simulator.Get(), f);
if (has_result) {
@@ -216,7 +231,7 @@ static void VerifyGeneratedCode(InstructionSet target_isa,
}
// Verify on hardware.
- if (CanExecuteOnHardware(target_isa)) {
+ if (CanExecuteOnHardware(codegen)) {
Expected result = f();
if (has_result) {
ASSERT_EQ(expected, result);
@@ -241,7 +256,7 @@ static void Run(const CodeGenerator& codegen,
using fptr = Expected (*)();
fptr f = reinterpret_cast<fptr>(reinterpret_cast<uintptr_t>(method_code));
- VerifyGeneratedCode(target_isa, f, has_result, expected);
+ VerifyGeneratedCode(codegen, f, has_result, expected);
}
static void ValidateGraph(HGraph* graph) {
diff --git a/compiler/optimizing/scheduler_test.cc b/compiler/optimizing/scheduler_test.cc
index 182465aa54..7003bd2715 100644
--- a/compiler/optimizing/scheduler_test.cc
+++ b/compiler/optimizing/scheduler_test.cc
@@ -58,7 +58,7 @@ static ::std::vector<CodegenTargetConfig> GetTargetConfigs() {
};
for (const CodegenTargetConfig& test_config : test_config_candidates) {
- if (CanExecute(test_config.GetInstructionSet())) {
+ if (CanExecuteISA(test_config.GetInstructionSet())) {
v.push_back(test_config);
}
}