Skip to content

Commit 7f82996

Browse files
authored
[MIR2Vec] Fixing non x86 unittest failures (#162381)
Fixing failures due to #161463
1 parent 198f294 commit 7f82996

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

llvm/unittests/CodeGen/MIR2VecTest.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,32 @@ class MIR2VecVocabTestFixture : public ::testing::Test {
5454
std::unique_ptr<TargetMachine> TM;
5555
const TargetInstrInfo *TII;
5656

57+
static void SetUpTestCase() {
58+
InitializeAllTargets();
59+
InitializeAllTargetMCs();
60+
}
61+
5762
void SetUp() override {
58-
LLVMInitializeX86TargetInfo();
59-
LLVMInitializeX86Target();
60-
LLVMInitializeX86TargetMC();
63+
Triple TargetTriple("x86_64-unknown-linux-gnu");
64+
std::string Error;
65+
const Target *T = TargetRegistry::lookupTarget("", TargetTriple, Error);
66+
if (!T) {
67+
GTEST_SKIP() << "x86_64-unknown-linux-gnu target triple not available; "
68+
"Skipping test";
69+
return;
70+
}
6171

6272
Ctx = std::make_unique<LLVMContext>();
6373
M = std::make_unique<Module>("test", *Ctx);
64-
65-
// Set up X86 target
66-
Triple TargetTriple("x86_64-unknown-linux-gnu");
6774
M->setTargetTriple(TargetTriple);
6875

69-
std::string Error;
70-
const Target *TheTarget =
71-
TargetRegistry::lookupTarget(M->getTargetTriple(), Error);
72-
ASSERT_TRUE(TheTarget) << "Failed to lookup target: " << Error;
73-
7476
TargetOptions Options;
75-
TM = std::unique_ptr<TargetMachine>(TheTarget->createTargetMachine(
76-
M->getTargetTriple(), "", "", Options, Reloc::Model::Static));
77-
ASSERT_TRUE(TM);
77+
TM = std::unique_ptr<TargetMachine>(
78+
T->createTargetMachine(TargetTriple, "", "", Options, std::nullopt));
79+
if (!TM) {
80+
GTEST_SKIP() << "Failed to create X86 target machine; Skipping test";
81+
return;
82+
}
7883

7984
// Create a dummy function to get subtarget info
8085
FunctionType *FT = FunctionType::get(Type::getVoidTy(*Ctx), false);
@@ -83,7 +88,10 @@ class MIR2VecVocabTestFixture : public ::testing::Test {
8388

8489
// Get the target instruction info
8590
TII = TM->getSubtargetImpl(*F)->getInstrInfo();
86-
ASSERT_TRUE(TII);
91+
if (!TII) {
92+
GTEST_SKIP() << "Failed to get target instruction info; Skipping test";
93+
return;
94+
}
8795
}
8896
};
8997

0 commit comments

Comments
 (0)