[llvm] [llvm-exegesis] Use TestBase for TargetTest (PR #121895)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 6 23:35:25 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-tools-llvm-exegesis
Author: Aiden Grossman (boomanaiden154)
<details>
<summary>Changes</summary>
This patch makes the PPC and X86 Exegesis TargetTests use TestBase to provide initial setup rather than doing it themselves. This promotes code reuse a little bit and makes the tests a bit more consistent (with MIPS and with the initial RISC-V tests landing soon).
---
Full diff: https://github.com/llvm/llvm-project/pull/121895.diff
3 Files Affected:
- (modified) llvm/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp (+2-7)
- (modified) llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp (+3-14)
- (modified) llvm/unittests/tools/llvm-exegesis/X86/TestBase.h (+4-2)
``````````diff
diff --git a/llvm/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp b/llvm/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp
index c3107ee4ec0eb2..da24ae8cae2a4c 100644
--- a/llvm/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp
+++ b/llvm/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp
@@ -12,6 +12,7 @@
#include <memory>
#include "MCTargetDesc/PPCMCTargetDesc.h"
+#include "TestBase.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "gmock/gmock.h"
@@ -30,7 +31,7 @@ using testing::Not;
constexpr const char kTriple[] = "powerpc64le-unknown-linux";
-class PowerPCTargetTest : public ::testing::Test {
+class PowerPCTargetTest : public PPCTestBase {
protected:
PowerPCTargetTest()
: ExegesisTarget_(ExegesisTarget::lookup(Triple(kTriple))) {
@@ -39,12 +40,6 @@ class PowerPCTargetTest : public ::testing::Test {
Target_ = TargetRegistry::lookupTarget(kTriple, error);
EXPECT_THAT(Target_, NotNull());
}
- static void SetUpTestCase() {
- LLVMInitializePowerPCTargetInfo();
- LLVMInitializePowerPCTarget();
- LLVMInitializePowerPCTargetMC();
- InitializePowerPCExegesisTarget();
- }
const Target *Target_;
const ExegesisTarget *const ExegesisTarget_;
diff --git a/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp b/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
index 3dff50c44798d7..846729c6f85ee4 100644
--- a/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
+++ b/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
@@ -14,6 +14,7 @@
#include "MCTargetDesc/X86MCTargetDesc.h"
#include "MmapUtils.h"
#include "SubprocessMemory.h"
+#include "TestBase.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "gmock/gmock.h"
@@ -112,19 +113,9 @@ Matcher<MCInst> IsStackDeallocate(unsigned Size) {
ElementsAre(IsReg(X86::RSP), IsReg(X86::RSP), IsImm(Size)));
}
-constexpr const char kTriple[] = "x86_64-unknown-linux";
-
-class X86TargetTest : public ::testing::Test {
+class X86TargetTest : public X86TestBase {
protected:
- X86TargetTest(const char *Features)
- : State(cantFail(LLVMState::Create(kTriple, "core2", Features))) {}
-
- static void SetUpTestCase() {
- LLVMInitializeX86TargetInfo();
- LLVMInitializeX86Target();
- LLVMInitializeX86TargetMC();
- InitializeX86ExegesisTarget();
- }
+ X86TargetTest(const char *Features) : X86TestBase("core2", Features) {}
std::vector<MCInst> setRegTo(unsigned Reg, const APInt &Value) {
return State.getExegesisTarget().setRegTo(State.getSubtargetInfo(), Reg,
@@ -134,8 +125,6 @@ class X86TargetTest : public ::testing::Test {
const Instruction &getInstr(unsigned OpCode) {
return State.getIC().getInstr(OpCode);
}
-
- LLVMState State;
};
class X86Core2TargetTest : public X86TargetTest {
diff --git a/llvm/unittests/tools/llvm-exegesis/X86/TestBase.h b/llvm/unittests/tools/llvm-exegesis/X86/TestBase.h
index ea8063ee44d2c7..4122726aef94a6 100644
--- a/llvm/unittests/tools/llvm-exegesis/X86/TestBase.h
+++ b/llvm/unittests/tools/llvm-exegesis/X86/TestBase.h
@@ -22,10 +22,12 @@ namespace exegesis {
void InitializeX86ExegesisTarget();
+constexpr const char kTriple[] = "x86_64-unknown-linux";
+
class X86TestBase : public ::testing::Test {
protected:
- X86TestBase()
- : State(cantFail(LLVMState::Create("x86_64-unknown-linux", "haswell"))) {}
+ X86TestBase(std::string CPUName = "haswell", const char *Features = "")
+ : State(cantFail(LLVMState::Create(kTriple, CPUName, Features))) {}
static void SetUpTestCase() {
LLVMInitializeX86TargetInfo();
``````````
</details>
https://github.com/llvm/llvm-project/pull/121895
More information about the llvm-commits
mailing list