Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SandboxIR][NFC] Move Utils test to proper file #110763

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 0 additions & 42 deletions llvm/unittests/SandboxIR/SandboxIRTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1470,48 +1470,6 @@ define i32 @foo(i32 %arg0, i32 %arg1) {
EXPECT_EQ(Glob0->getOperand(0), Glob1);
}

TEST_F(SandboxIRTest, GetExpected) {
parseIR(C, R"IR(
define float @foo(float %v, ptr %ptr) {
%add = fadd float %v, %v
store float %v, ptr %ptr
ret float %v
}
define void @bar(float %v, ptr %ptr) {
ret void
}
)IR");
llvm::Function &Foo = *M->getFunction("foo");
sandboxir::Context Ctx(C);

Ctx.createFunction(&Foo);
auto *FooBB = cast<sandboxir::BasicBlock>(Ctx.getValue(&*Foo.begin()));
auto FooIt = FooBB->begin();
auto Add = cast<sandboxir::Instruction>(&*FooIt++);
auto *S0 = cast<sandboxir::Instruction>(&*FooIt++);
auto *RetF = cast<sandboxir::Instruction>(&*FooIt++);
// getExpectedValue
EXPECT_EQ(sandboxir::Utils::getExpectedValue(Add), Add);
EXPECT_EQ(sandboxir::Utils::getExpectedValue(S0),
cast<sandboxir::StoreInst>(S0)->getValueOperand());
EXPECT_EQ(sandboxir::Utils::getExpectedValue(RetF),
cast<sandboxir::ReturnInst>(RetF)->getReturnValue());
// getExpectedType
EXPECT_EQ(sandboxir::Utils::getExpectedType(Add), Add->getType());
EXPECT_EQ(sandboxir::Utils::getExpectedType(S0),
cast<sandboxir::StoreInst>(S0)->getValueOperand()->getType());
EXPECT_EQ(sandboxir::Utils::getExpectedType(RetF),
cast<sandboxir::ReturnInst>(RetF)->getReturnValue()->getType());

// getExpectedValue for void returns
llvm::Function &Bar = *M->getFunction("bar");
Ctx.createFunction(&Bar);
auto *BarBB = cast<sandboxir::BasicBlock>(Ctx.getValue(&*Bar.begin()));
auto BarIt = BarBB->begin();
auto *RetV = cast<sandboxir::Instruction>(&*BarIt++);
EXPECT_EQ(sandboxir::Utils::getExpectedValue(RetV), nullptr);
}

TEST_F(SandboxIRTest, RAUW_RUWIf) {
parseIR(C, R"IR(
define void @foo(ptr %ptr) {
Expand Down
42 changes: 42 additions & 0 deletions llvm/unittests/SandboxIR/UtilsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,48 @@ define void @foo(ptr %ptr) {
EXPECT_FALSE(sandboxir::Utils::atLowerAddress(L3, V3L3, SE, DL));
}

TEST_F(UtilsTest, GetExpected) {
parseIR(C, R"IR(
define float @foo(float %v, ptr %ptr) {
%add = fadd float %v, %v
store float %v, ptr %ptr
ret float %v
}
define void @bar(float %v, ptr %ptr) {
ret void
}
)IR");
llvm::Function &Foo = *M->getFunction("foo");
sandboxir::Context Ctx(C);

Ctx.createFunction(&Foo);
auto *FooBB = cast<sandboxir::BasicBlock>(Ctx.getValue(&*Foo.begin()));
auto FooIt = FooBB->begin();
auto Add = cast<sandboxir::Instruction>(&*FooIt++);
auto *S0 = cast<sandboxir::Instruction>(&*FooIt++);
auto *RetF = cast<sandboxir::Instruction>(&*FooIt++);
// getExpectedValue
EXPECT_EQ(sandboxir::Utils::getExpectedValue(Add), Add);
EXPECT_EQ(sandboxir::Utils::getExpectedValue(S0),
cast<sandboxir::StoreInst>(S0)->getValueOperand());
EXPECT_EQ(sandboxir::Utils::getExpectedValue(RetF),
cast<sandboxir::ReturnInst>(RetF)->getReturnValue());
// getExpectedType
EXPECT_EQ(sandboxir::Utils::getExpectedType(Add), Add->getType());
EXPECT_EQ(sandboxir::Utils::getExpectedType(S0),
cast<sandboxir::StoreInst>(S0)->getValueOperand()->getType());
EXPECT_EQ(sandboxir::Utils::getExpectedType(RetF),
cast<sandboxir::ReturnInst>(RetF)->getReturnValue()->getType());

// getExpectedValue for void returns
llvm::Function &Bar = *M->getFunction("bar");
Ctx.createFunction(&Bar);
auto *BarBB = cast<sandboxir::BasicBlock>(Ctx.getValue(&*Bar.begin()));
auto BarIt = BarBB->begin();
auto *RetV = cast<sandboxir::Instruction>(&*BarIt++);
EXPECT_EQ(sandboxir::Utils::getExpectedValue(RetV), nullptr);
}

TEST_F(UtilsTest, GetNumBits) {
parseIR(C, R"IR(
define void @foo(float %arg0, double %arg1, i8 %arg2, i64 %arg3, ptr %arg4) {
Expand Down
Loading