Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions llvm/unittests/CodeGen/MIR2VecTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if T is valid, can TM not be?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just being conservative here to skip such tests, as I was not completely sure if TM cannot not be nullptr if T is valid.

if (!TM) {
GTEST_SKIP();
return;
}

// Create a dummy function to get subtarget info
FunctionType *FT = FunctionType::get(Type::getVoidTy(*Ctx), false);
Expand All @@ -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;
}
}
};

Expand Down
Loading