Skip to content

Commit

Permalink
[SandboxIR][NFC] Move Utils test to proper file (#110763)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sterling-Augustine authored Oct 2, 2024
1 parent 0f512d1 commit 906ffc4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 42 deletions.
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

0 comments on commit 906ffc4

Please sign in to comment.