[llvm] [MIR2Vec] Fixing non x86 unittest failures (PR #162381)
S. VenkataKeerthy via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 7 14:54:29 PDT 2025
https://github.com/svkeerthy created https://github.com/llvm/llvm-project/pull/162381
Fixing failures due to #161463
>From 052117b96c3ed70396f7417d4034d91f88822308 Mon Sep 17 00:00:00 2001
From: svkeerthy <venkatakeerthy at google.com>
Date: Tue, 7 Oct 2025 21:51:26 +0000
Subject: [PATCH] Fixing non x86 test failures
---
llvm/unittests/CodeGen/MIR2VecTest.cpp | 37 +++++++++++++++-----------
1 file changed, 22 insertions(+), 15 deletions(-)
diff --git a/llvm/unittests/CodeGen/MIR2VecTest.cpp b/llvm/unittests/CodeGen/MIR2VecTest.cpp
index 01f2eadbf4068..56220cbbeb767 100644
--- a/llvm/unittests/CodeGen/MIR2VecTest.cpp
+++ b/llvm/unittests/CodeGen/MIR2VecTest.cpp
@@ -54,27 +54,31 @@ class MIR2VecVocabTestFixture : public ::testing::Test {
std::unique_ptr<TargetMachine> TM;
const TargetInstrInfo *TII;
+ static void SetUpTestCase() {
+ InitializeAllTargets();
+ InitializeAllTargetMCs();
+ }
+
void SetUp() override {
- LLVMInitializeX86TargetInfo();
- LLVMInitializeX86Target();
- LLVMInitializeX86TargetMC();
+ Triple TargetTriple("x86_64-unknown-linux-gnu");
+ std::string Error;
+ const Target *T = TargetRegistry::lookupTarget("", TargetTriple, Error);
+ if (!T) {
+ GTEST_SKIP();
+ return;
+ }
Ctx = std::make_unique<LLVMContext>();
M = std::make_unique<Module>("test", *Ctx);
-
- // Set up X86 target
- Triple TargetTriple("x86_64-unknown-linux-gnu");
M->setTargetTriple(TargetTriple);
- std::string Error;
- const Target *TheTarget =
- TargetRegistry::lookupTarget(M->getTargetTriple(), Error);
- ASSERT_TRUE(TheTarget) << "Failed to lookup target: " << Error;
-
TargetOptions Options;
- TM = std::unique_ptr<TargetMachine>(TheTarget->createTargetMachine(
- M->getTargetTriple(), "", "", Options, Reloc::Model::Static));
- ASSERT_TRUE(TM);
+ TM = std::unique_ptr<TargetMachine>(
+ T->createTargetMachine(TargetTriple, "", "", Options, std::nullopt));
+ if (!TM) {
+ GTEST_SKIP();
+ return;
+ }
// Create a dummy function to get subtarget info
FunctionType *FT = FunctionType::get(Type::getVoidTy(*Ctx), false);
@@ -83,7 +87,10 @@ class MIR2VecVocabTestFixture : public ::testing::Test {
// Get the target instruction info
TII = TM->getSubtargetImpl(*F)->getInstrInfo();
- ASSERT_TRUE(TII);
+ if (!TII) {
+ GTEST_SKIP();
+ return;
+ }
}
};
More information about the llvm-commits
mailing list