[ir] Rename instr.

This Cl renames the `instr` variables to `inst`.

Bug: tint:1718
Change-Id: Icf3b8c2f612c8dfe4b469d90327fef90ad813a0d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/129460
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair 2023-04-26 14:46:03 +00:00 committed by Dawn LUCI CQ
parent abfa45baa4
commit 135ab2b39f
19 changed files with 391 additions and 391 deletions

View File

@ -56,12 +56,12 @@ class Binary : public utils::Castable<Binary, Instruction> {
/// @param lhs the lhs of the instruction
/// @param rhs the rhs of the instruction
Binary(Kind kind, Value* result, Value* lhs, Value* rhs);
Binary(const Binary& instr) = delete;
Binary(Binary&& instr) = delete;
Binary(const Binary& inst) = delete;
Binary(Binary&& inst) = delete;
~Binary() override;
Binary& operator=(const Binary& instr) = delete;
Binary& operator=(Binary&& instr) = delete;
Binary& operator=(const Binary& inst) = delete;
Binary& operator=(Binary&& inst) = delete;
/// @returns the kind of instruction
Kind GetKind() const { return kind_; }

View File

@ -27,27 +27,27 @@ TEST_F(IR_InstructionTest, CreateAnd) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr = b.builder.And(b.builder.ir.types.Get<type::I32>(), b.builder.Constant(4_i),
b.builder.Constant(2_i));
const auto* inst = b.builder.And(b.builder.ir.types.Get<type::I32>(), b.builder.Constant(4_i),
b.builder.Constant(2_i));
EXPECT_EQ(instr->GetKind(), Binary::Kind::kAnd);
EXPECT_EQ(inst->GetKind(), Binary::Kind::kAnd);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
ASSERT_NE(instr->Result()->Type(), nullptr);
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
ASSERT_NE(inst->Result()->Type(), nullptr);
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->LHS()->Is<Constant>());
auto lhs = instr->LHS()->As<Constant>()->value;
ASSERT_TRUE(inst->LHS()->Is<Constant>());
auto lhs = inst->LHS()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
ASSERT_TRUE(instr->RHS()->Is<Constant>());
auto rhs = instr->RHS()->As<Constant>()->value;
ASSERT_TRUE(inst->RHS()->Is<Constant>());
auto rhs = inst->RHS()->As<Constant>()->value;
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = 4 & 2");
}
@ -55,26 +55,26 @@ TEST_F(IR_InstructionTest, CreateOr) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr = b.builder.Or(b.builder.ir.types.Get<type::I32>(), b.builder.Constant(4_i),
b.builder.Constant(2_i));
const auto* inst = b.builder.Or(b.builder.ir.types.Get<type::I32>(), b.builder.Constant(4_i),
b.builder.Constant(2_i));
EXPECT_EQ(instr->GetKind(), Binary::Kind::kOr);
EXPECT_EQ(inst->GetKind(), Binary::Kind::kOr);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->LHS()->Is<Constant>());
auto lhs = instr->LHS()->As<Constant>()->value;
ASSERT_TRUE(inst->LHS()->Is<Constant>());
auto lhs = inst->LHS()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
ASSERT_TRUE(instr->RHS()->Is<Constant>());
auto rhs = instr->RHS()->As<Constant>()->value;
ASSERT_TRUE(inst->RHS()->Is<Constant>());
auto rhs = inst->RHS()->As<Constant>()->value;
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = 4 | 2");
}
@ -82,26 +82,26 @@ TEST_F(IR_InstructionTest, CreateXor) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr = b.builder.Xor(b.builder.ir.types.Get<type::I32>(), b.builder.Constant(4_i),
b.builder.Constant(2_i));
const auto* inst = b.builder.Xor(b.builder.ir.types.Get<type::I32>(), b.builder.Constant(4_i),
b.builder.Constant(2_i));
EXPECT_EQ(instr->GetKind(), Binary::Kind::kXor);
EXPECT_EQ(inst->GetKind(), Binary::Kind::kXor);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->LHS()->Is<Constant>());
auto lhs = instr->LHS()->As<Constant>()->value;
ASSERT_TRUE(inst->LHS()->Is<Constant>());
auto lhs = inst->LHS()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
ASSERT_TRUE(instr->RHS()->Is<Constant>());
auto rhs = instr->RHS()->As<Constant>()->value;
ASSERT_TRUE(inst->RHS()->Is<Constant>());
auto rhs = inst->RHS()->As<Constant>()->value;
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = 4 ^ 2");
}
@ -109,26 +109,26 @@ TEST_F(IR_InstructionTest, CreateLogicalAnd) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr = b.builder.LogicalAnd(b.builder.ir.types.Get<type::Bool>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
const auto* inst = b.builder.LogicalAnd(b.builder.ir.types.Get<type::Bool>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
EXPECT_EQ(instr->GetKind(), Binary::Kind::kLogicalAnd);
EXPECT_EQ(inst->GetKind(), Binary::Kind::kLogicalAnd);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->LHS()->Is<Constant>());
auto lhs = instr->LHS()->As<Constant>()->value;
ASSERT_TRUE(inst->LHS()->Is<Constant>());
auto lhs = inst->LHS()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
ASSERT_TRUE(instr->RHS()->Is<Constant>());
auto rhs = instr->RHS()->As<Constant>()->value;
ASSERT_TRUE(inst->RHS()->Is<Constant>());
auto rhs = inst->RHS()->As<Constant>()->value;
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (bool) = 4 && 2");
}
@ -136,26 +136,26 @@ TEST_F(IR_InstructionTest, CreateLogicalOr) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr = b.builder.LogicalOr(b.builder.ir.types.Get<type::Bool>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
const auto* inst = b.builder.LogicalOr(b.builder.ir.types.Get<type::Bool>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
EXPECT_EQ(instr->GetKind(), Binary::Kind::kLogicalOr);
EXPECT_EQ(inst->GetKind(), Binary::Kind::kLogicalOr);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->LHS()->Is<Constant>());
auto lhs = instr->LHS()->As<Constant>()->value;
ASSERT_TRUE(inst->LHS()->Is<Constant>());
auto lhs = inst->LHS()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
ASSERT_TRUE(instr->RHS()->Is<Constant>());
auto rhs = instr->RHS()->As<Constant>()->value;
ASSERT_TRUE(inst->RHS()->Is<Constant>());
auto rhs = inst->RHS()->As<Constant>()->value;
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (bool) = 4 || 2");
}
@ -163,26 +163,26 @@ TEST_F(IR_InstructionTest, CreateEqual) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr = b.builder.Equal(b.builder.ir.types.Get<type::Bool>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
const auto* inst = b.builder.Equal(b.builder.ir.types.Get<type::Bool>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
EXPECT_EQ(instr->GetKind(), Binary::Kind::kEqual);
EXPECT_EQ(inst->GetKind(), Binary::Kind::kEqual);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->LHS()->Is<Constant>());
auto lhs = instr->LHS()->As<Constant>()->value;
ASSERT_TRUE(inst->LHS()->Is<Constant>());
auto lhs = inst->LHS()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
ASSERT_TRUE(instr->RHS()->Is<Constant>());
auto rhs = instr->RHS()->As<Constant>()->value;
ASSERT_TRUE(inst->RHS()->Is<Constant>());
auto rhs = inst->RHS()->As<Constant>()->value;
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (bool) = 4 == 2");
}
@ -190,26 +190,26 @@ TEST_F(IR_InstructionTest, CreateNotEqual) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr = b.builder.NotEqual(b.builder.ir.types.Get<type::Bool>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
const auto* inst = b.builder.NotEqual(b.builder.ir.types.Get<type::Bool>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
EXPECT_EQ(instr->GetKind(), Binary::Kind::kNotEqual);
EXPECT_EQ(inst->GetKind(), Binary::Kind::kNotEqual);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->LHS()->Is<Constant>());
auto lhs = instr->LHS()->As<Constant>()->value;
ASSERT_TRUE(inst->LHS()->Is<Constant>());
auto lhs = inst->LHS()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
ASSERT_TRUE(instr->RHS()->Is<Constant>());
auto rhs = instr->RHS()->As<Constant>()->value;
ASSERT_TRUE(inst->RHS()->Is<Constant>());
auto rhs = inst->RHS()->As<Constant>()->value;
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (bool) = 4 != 2");
}
@ -217,26 +217,26 @@ TEST_F(IR_InstructionTest, CreateLessThan) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr = b.builder.LessThan(b.builder.ir.types.Get<type::Bool>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
const auto* inst = b.builder.LessThan(b.builder.ir.types.Get<type::Bool>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
EXPECT_EQ(instr->GetKind(), Binary::Kind::kLessThan);
EXPECT_EQ(inst->GetKind(), Binary::Kind::kLessThan);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->LHS()->Is<Constant>());
auto lhs = instr->LHS()->As<Constant>()->value;
ASSERT_TRUE(inst->LHS()->Is<Constant>());
auto lhs = inst->LHS()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
ASSERT_TRUE(instr->RHS()->Is<Constant>());
auto rhs = instr->RHS()->As<Constant>()->value;
ASSERT_TRUE(inst->RHS()->Is<Constant>());
auto rhs = inst->RHS()->As<Constant>()->value;
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (bool) = 4 < 2");
}
@ -244,26 +244,26 @@ TEST_F(IR_InstructionTest, CreateGreaterThan) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr = b.builder.GreaterThan(b.builder.ir.types.Get<type::Bool>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
const auto* inst = b.builder.GreaterThan(b.builder.ir.types.Get<type::Bool>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
EXPECT_EQ(instr->GetKind(), Binary::Kind::kGreaterThan);
EXPECT_EQ(inst->GetKind(), Binary::Kind::kGreaterThan);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->LHS()->Is<Constant>());
auto lhs = instr->LHS()->As<Constant>()->value;
ASSERT_TRUE(inst->LHS()->Is<Constant>());
auto lhs = inst->LHS()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
ASSERT_TRUE(instr->RHS()->Is<Constant>());
auto rhs = instr->RHS()->As<Constant>()->value;
ASSERT_TRUE(inst->RHS()->Is<Constant>());
auto rhs = inst->RHS()->As<Constant>()->value;
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (bool) = 4 > 2");
}
@ -271,26 +271,26 @@ TEST_F(IR_InstructionTest, CreateLessThanEqual) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr = b.builder.LessThanEqual(b.builder.ir.types.Get<type::Bool>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
const auto* inst = b.builder.LessThanEqual(b.builder.ir.types.Get<type::Bool>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
EXPECT_EQ(instr->GetKind(), Binary::Kind::kLessThanEqual);
EXPECT_EQ(inst->GetKind(), Binary::Kind::kLessThanEqual);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->LHS()->Is<Constant>());
auto lhs = instr->LHS()->As<Constant>()->value;
ASSERT_TRUE(inst->LHS()->Is<Constant>());
auto lhs = inst->LHS()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
ASSERT_TRUE(instr->RHS()->Is<Constant>());
auto rhs = instr->RHS()->As<Constant>()->value;
ASSERT_TRUE(inst->RHS()->Is<Constant>());
auto rhs = inst->RHS()->As<Constant>()->value;
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (bool) = 4 <= 2");
}
@ -298,26 +298,26 @@ TEST_F(IR_InstructionTest, CreateGreaterThanEqual) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr = b.builder.GreaterThanEqual(
b.builder.ir.types.Get<type::Bool>(), b.builder.Constant(4_i), b.builder.Constant(2_i));
const auto* inst = b.builder.GreaterThanEqual(b.builder.ir.types.Get<type::Bool>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
EXPECT_EQ(instr->GetKind(), Binary::Kind::kGreaterThanEqual);
EXPECT_EQ(inst->GetKind(), Binary::Kind::kGreaterThanEqual);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->LHS()->Is<Constant>());
auto lhs = instr->LHS()->As<Constant>()->value;
ASSERT_TRUE(inst->LHS()->Is<Constant>());
auto lhs = inst->LHS()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
ASSERT_TRUE(instr->RHS()->Is<Constant>());
auto rhs = instr->RHS()->As<Constant>()->value;
ASSERT_TRUE(inst->RHS()->Is<Constant>());
auto rhs = inst->RHS()->As<Constant>()->value;
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (bool) = 4 >= 2");
}
@ -325,26 +325,26 @@ TEST_F(IR_InstructionTest, CreateShiftLeft) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr = b.builder.ShiftLeft(b.builder.ir.types.Get<type::I32>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
const auto* inst = b.builder.ShiftLeft(b.builder.ir.types.Get<type::I32>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
EXPECT_EQ(instr->GetKind(), Binary::Kind::kShiftLeft);
EXPECT_EQ(inst->GetKind(), Binary::Kind::kShiftLeft);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->LHS()->Is<Constant>());
auto lhs = instr->LHS()->As<Constant>()->value;
ASSERT_TRUE(inst->LHS()->Is<Constant>());
auto lhs = inst->LHS()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
ASSERT_TRUE(instr->RHS()->Is<Constant>());
auto rhs = instr->RHS()->As<Constant>()->value;
ASSERT_TRUE(inst->RHS()->Is<Constant>());
auto rhs = inst->RHS()->As<Constant>()->value;
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = 4 << 2");
}
@ -352,26 +352,26 @@ TEST_F(IR_InstructionTest, CreateShiftRight) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr = b.builder.ShiftRight(b.builder.ir.types.Get<type::I32>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
const auto* inst = b.builder.ShiftRight(b.builder.ir.types.Get<type::I32>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
EXPECT_EQ(instr->GetKind(), Binary::Kind::kShiftRight);
EXPECT_EQ(inst->GetKind(), Binary::Kind::kShiftRight);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->LHS()->Is<Constant>());
auto lhs = instr->LHS()->As<Constant>()->value;
ASSERT_TRUE(inst->LHS()->Is<Constant>());
auto lhs = inst->LHS()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
ASSERT_TRUE(instr->RHS()->Is<Constant>());
auto rhs = instr->RHS()->As<Constant>()->value;
ASSERT_TRUE(inst->RHS()->Is<Constant>());
auto rhs = inst->RHS()->As<Constant>()->value;
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = 4 >> 2");
}
@ -379,26 +379,26 @@ TEST_F(IR_InstructionTest, CreateAdd) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr = b.builder.Add(b.builder.ir.types.Get<type::I32>(), b.builder.Constant(4_i),
b.builder.Constant(2_i));
const auto* inst = b.builder.Add(b.builder.ir.types.Get<type::I32>(), b.builder.Constant(4_i),
b.builder.Constant(2_i));
EXPECT_EQ(instr->GetKind(), Binary::Kind::kAdd);
EXPECT_EQ(inst->GetKind(), Binary::Kind::kAdd);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->LHS()->Is<Constant>());
auto lhs = instr->LHS()->As<Constant>()->value;
ASSERT_TRUE(inst->LHS()->Is<Constant>());
auto lhs = inst->LHS()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
ASSERT_TRUE(instr->RHS()->Is<Constant>());
auto rhs = instr->RHS()->As<Constant>()->value;
ASSERT_TRUE(inst->RHS()->Is<Constant>());
auto rhs = inst->RHS()->As<Constant>()->value;
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = 4 + 2");
}
@ -406,26 +406,26 @@ TEST_F(IR_InstructionTest, CreateSubtract) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr = b.builder.Subtract(b.builder.ir.types.Get<type::I32>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
const auto* inst = b.builder.Subtract(b.builder.ir.types.Get<type::I32>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
EXPECT_EQ(instr->GetKind(), Binary::Kind::kSubtract);
EXPECT_EQ(inst->GetKind(), Binary::Kind::kSubtract);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->LHS()->Is<Constant>());
auto lhs = instr->LHS()->As<Constant>()->value;
ASSERT_TRUE(inst->LHS()->Is<Constant>());
auto lhs = inst->LHS()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
ASSERT_TRUE(instr->RHS()->Is<Constant>());
auto rhs = instr->RHS()->As<Constant>()->value;
ASSERT_TRUE(inst->RHS()->Is<Constant>());
auto rhs = inst->RHS()->As<Constant>()->value;
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = 4 - 2");
}
@ -433,26 +433,26 @@ TEST_F(IR_InstructionTest, CreateMultiply) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr = b.builder.Multiply(b.builder.ir.types.Get<type::I32>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
const auto* inst = b.builder.Multiply(b.builder.ir.types.Get<type::I32>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
EXPECT_EQ(instr->GetKind(), Binary::Kind::kMultiply);
EXPECT_EQ(inst->GetKind(), Binary::Kind::kMultiply);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->LHS()->Is<Constant>());
auto lhs = instr->LHS()->As<Constant>()->value;
ASSERT_TRUE(inst->LHS()->Is<Constant>());
auto lhs = inst->LHS()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
ASSERT_TRUE(instr->RHS()->Is<Constant>());
auto rhs = instr->RHS()->As<Constant>()->value;
ASSERT_TRUE(inst->RHS()->Is<Constant>());
auto rhs = inst->RHS()->As<Constant>()->value;
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = 4 * 2");
}
@ -460,26 +460,26 @@ TEST_F(IR_InstructionTest, CreateDivide) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr = b.builder.Divide(b.builder.ir.types.Get<type::I32>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
const auto* inst = b.builder.Divide(b.builder.ir.types.Get<type::I32>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
EXPECT_EQ(instr->GetKind(), Binary::Kind::kDivide);
EXPECT_EQ(inst->GetKind(), Binary::Kind::kDivide);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->LHS()->Is<Constant>());
auto lhs = instr->LHS()->As<Constant>()->value;
ASSERT_TRUE(inst->LHS()->Is<Constant>());
auto lhs = inst->LHS()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
ASSERT_TRUE(instr->RHS()->Is<Constant>());
auto rhs = instr->RHS()->As<Constant>()->value;
ASSERT_TRUE(inst->RHS()->Is<Constant>());
auto rhs = inst->RHS()->As<Constant>()->value;
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = 4 / 2");
}
@ -487,26 +487,26 @@ TEST_F(IR_InstructionTest, CreateModulo) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr = b.builder.Modulo(b.builder.ir.types.Get<type::I32>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
const auto* inst = b.builder.Modulo(b.builder.ir.types.Get<type::I32>(),
b.builder.Constant(4_i), b.builder.Constant(2_i));
EXPECT_EQ(instr->GetKind(), Binary::Kind::kModulo);
EXPECT_EQ(inst->GetKind(), Binary::Kind::kModulo);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->LHS()->Is<Constant>());
auto lhs = instr->LHS()->As<Constant>()->value;
ASSERT_TRUE(inst->LHS()->Is<Constant>());
auto lhs = inst->LHS()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
ASSERT_TRUE(instr->RHS()->Is<Constant>());
auto rhs = instr->RHS()->As<Constant>()->value;
ASSERT_TRUE(inst->RHS()->Is<Constant>());
auto rhs = inst->RHS()->As<Constant>()->value;
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = 4 % 2");
}
@ -514,22 +514,22 @@ TEST_F(IR_InstructionTest, Binary_Usage) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr = b.builder.And(b.builder.ir.types.Get<type::I32>(), b.builder.Constant(4_i),
b.builder.Constant(2_i));
const auto* inst = b.builder.And(b.builder.ir.types.Get<type::I32>(), b.builder.Constant(4_i),
b.builder.Constant(2_i));
EXPECT_EQ(instr->GetKind(), Binary::Kind::kAnd);
EXPECT_EQ(inst->GetKind(), Binary::Kind::kAnd);
ASSERT_NE(instr->Result(), nullptr);
ASSERT_EQ(instr->Result()->Usage().Length(), 1u);
EXPECT_EQ(instr->Result()->Usage()[0], instr);
ASSERT_NE(inst->Result(), nullptr);
ASSERT_EQ(inst->Result()->Usage().Length(), 1u);
EXPECT_EQ(inst->Result()->Usage()[0], inst);
ASSERT_NE(instr->LHS(), nullptr);
ASSERT_EQ(instr->LHS()->Usage().Length(), 1u);
EXPECT_EQ(instr->LHS()->Usage()[0], instr);
ASSERT_NE(inst->LHS(), nullptr);
ASSERT_EQ(inst->LHS()->Usage().Length(), 1u);
EXPECT_EQ(inst->LHS()->Usage()[0], inst);
ASSERT_NE(instr->RHS(), nullptr);
ASSERT_EQ(instr->RHS()->Usage().Length(), 1u);
EXPECT_EQ(instr->RHS()->Usage()[0], instr);
ASSERT_NE(inst->RHS(), nullptr);
ASSERT_EQ(inst->RHS()->Usage().Length(), 1u);
EXPECT_EQ(inst->RHS()->Usage()[0], inst);
}
TEST_F(IR_InstructionTest, Binary_Usage_DuplicateValue) {
@ -538,19 +538,19 @@ TEST_F(IR_InstructionTest, Binary_Usage_DuplicateValue) {
auto val = b.builder.Constant(4_i);
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr = b.builder.And(b.builder.ir.types.Get<type::I32>(), val, val);
const auto* inst = b.builder.And(b.builder.ir.types.Get<type::I32>(), val, val);
EXPECT_EQ(instr->GetKind(), Binary::Kind::kAnd);
EXPECT_EQ(inst->GetKind(), Binary::Kind::kAnd);
ASSERT_NE(instr->Result(), nullptr);
ASSERT_EQ(instr->Result()->Usage().Length(), 1u);
EXPECT_EQ(instr->Result()->Usage()[0], instr);
ASSERT_NE(inst->Result(), nullptr);
ASSERT_EQ(inst->Result()->Usage().Length(), 1u);
EXPECT_EQ(inst->Result()->Usage()[0], inst);
ASSERT_EQ(instr->LHS(), instr->RHS());
ASSERT_EQ(inst->LHS(), inst->RHS());
ASSERT_NE(instr->LHS(), nullptr);
ASSERT_EQ(instr->LHS()->Usage().Length(), 1u);
EXPECT_EQ(instr->LHS()->Usage()[0], instr);
ASSERT_NE(inst->LHS(), nullptr);
ASSERT_EQ(inst->LHS()->Usage().Length(), 1u);
EXPECT_EQ(inst->LHS()->Usage()[0], inst);
}
} // namespace

View File

@ -28,12 +28,12 @@ class Bitcast : public utils::Castable<Bitcast, Instruction> {
/// @param result the result value
/// @param val the value being bitcast
Bitcast(Value* result, Value* val);
Bitcast(const Bitcast& instr) = delete;
Bitcast(Bitcast&& instr) = delete;
Bitcast(const Bitcast& inst) = delete;
Bitcast(Bitcast&& inst) = delete;
~Bitcast() override;
Bitcast& operator=(const Bitcast& instr) = delete;
Bitcast& operator=(Bitcast&& instr) = delete;
Bitcast& operator=(const Bitcast& inst) = delete;
Bitcast& operator=(Bitcast&& inst) = delete;
/// @returns the left-hand-side value for the instruction
const Value* Val() const { return val_; }

View File

@ -27,20 +27,20 @@ TEST_F(IR_InstructionTest, Bitcast) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr =
const auto* inst =
b.builder.Bitcast(b.builder.ir.types.Get<type::I32>(), b.builder.Constant(4_i));
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_NE(instr->Result()->Type(), nullptr);
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_NE(inst->Result()->Type(), nullptr);
ASSERT_TRUE(instr->Val()->Is<Constant>());
auto val = instr->Val()->As<Constant>()->value;
ASSERT_TRUE(inst->Val()->Is<Constant>());
auto val = inst->Val()->As<Constant>()->value;
ASSERT_TRUE(val->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, val->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = bitcast(4)");
}
@ -48,16 +48,16 @@ TEST_F(IR_InstructionTest, Bitcast_Usage) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr =
const auto* inst =
b.builder.Bitcast(b.builder.ir.types.Get<type::I32>(), b.builder.Constant(4_i));
ASSERT_NE(instr->Result(), nullptr);
ASSERT_EQ(instr->Result()->Usage().Length(), 1u);
EXPECT_EQ(instr->Result()->Usage()[0], instr);
ASSERT_NE(inst->Result(), nullptr);
ASSERT_EQ(inst->Result()->Usage().Length(), 1u);
EXPECT_EQ(inst->Result()->Usage()[0], inst);
ASSERT_NE(instr->Val(), nullptr);
ASSERT_EQ(instr->Val()->Usage().Length(), 1u);
EXPECT_EQ(instr->Val()->Usage()[0], instr);
ASSERT_NE(inst->Val(), nullptr);
ASSERT_EQ(inst->Val()->Usage().Length(), 1u);
EXPECT_EQ(inst->Val()->Usage()[0], inst);
}
} // namespace

View File

@ -291,69 +291,69 @@ void BuilderImpl::EmitCompoundAssignment(const ast::CompoundAssignmentStatement*
}
auto* ty = lhs.Get()->Type();
Binary* instr = nullptr;
Binary* inst = nullptr;
switch (stmt->op) {
case ast::BinaryOp::kAnd:
instr = builder.And(ty, lhs.Get(), rhs.Get());
inst = builder.And(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kOr:
instr = builder.Or(ty, lhs.Get(), rhs.Get());
inst = builder.Or(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kXor:
instr = builder.Xor(ty, lhs.Get(), rhs.Get());
inst = builder.Xor(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kLogicalAnd:
instr = builder.LogicalAnd(ty, lhs.Get(), rhs.Get());
inst = builder.LogicalAnd(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kLogicalOr:
instr = builder.LogicalOr(ty, lhs.Get(), rhs.Get());
inst = builder.LogicalOr(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kEqual:
instr = builder.Equal(ty, lhs.Get(), rhs.Get());
inst = builder.Equal(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kNotEqual:
instr = builder.NotEqual(ty, lhs.Get(), rhs.Get());
inst = builder.NotEqual(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kLessThan:
instr = builder.LessThan(ty, lhs.Get(), rhs.Get());
inst = builder.LessThan(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kGreaterThan:
instr = builder.GreaterThan(ty, lhs.Get(), rhs.Get());
inst = builder.GreaterThan(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kLessThanEqual:
instr = builder.LessThanEqual(ty, lhs.Get(), rhs.Get());
inst = builder.LessThanEqual(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kGreaterThanEqual:
instr = builder.GreaterThanEqual(ty, lhs.Get(), rhs.Get());
inst = builder.GreaterThanEqual(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kShiftLeft:
instr = builder.ShiftLeft(ty, lhs.Get(), rhs.Get());
inst = builder.ShiftLeft(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kShiftRight:
instr = builder.ShiftRight(ty, lhs.Get(), rhs.Get());
inst = builder.ShiftRight(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kAdd:
instr = builder.Add(ty, lhs.Get(), rhs.Get());
inst = builder.Add(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kSubtract:
instr = builder.Subtract(ty, lhs.Get(), rhs.Get());
inst = builder.Subtract(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kMultiply:
instr = builder.Multiply(ty, lhs.Get(), rhs.Get());
inst = builder.Multiply(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kDivide:
instr = builder.Divide(ty, lhs.Get(), rhs.Get());
inst = builder.Divide(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kModulo:
instr = builder.Modulo(ty, lhs.Get(), rhs.Get());
inst = builder.Modulo(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kNone:
TINT_ICE(IR, diagnostics_) << "missing binary operand type";
return;
}
current_flow_block->instructions.Push(instr);
current_flow_block->instructions.Push(inst);
auto store = builder.Store(lhs.Get(), instr->Result());
auto store = builder.Store(lhs.Get(), inst->Result());
current_flow_block->instructions.Push(store);
}
@ -617,8 +617,8 @@ void BuilderImpl::EmitContinue(const ast::ContinueStatement*) {
// discard that would probably make sense as a FlowNode but would then require figuring out the
// multi-level exit that is triggered.
void BuilderImpl::EmitDiscard(const ast::DiscardStatement*) {
auto* instr = builder.Discard();
current_flow_block->instructions.Push(instr);
auto* inst = builder.Discard();
current_flow_block->instructions.Push(inst);
}
void BuilderImpl::EmitBreakIf(const ast::BreakIfStatement* stmt) {
@ -718,27 +718,27 @@ utils::Result<Value*> BuilderImpl::EmitUnary(const ast::UnaryOpExpression* expr)
auto* sem = program_->Sem().Get(expr);
auto* ty = sem->Type()->Clone(clone_ctx_.type_ctx);
Unary* instr = nullptr;
Unary* inst = nullptr;
switch (expr->op) {
case ast::UnaryOp::kAddressOf:
instr = builder.AddressOf(ty, val.Get());
inst = builder.AddressOf(ty, val.Get());
break;
case ast::UnaryOp::kComplement:
instr = builder.Complement(ty, val.Get());
inst = builder.Complement(ty, val.Get());
break;
case ast::UnaryOp::kIndirection:
instr = builder.Indirection(ty, val.Get());
inst = builder.Indirection(ty, val.Get());
break;
case ast::UnaryOp::kNegation:
instr = builder.Negation(ty, val.Get());
inst = builder.Negation(ty, val.Get());
break;
case ast::UnaryOp::kNot:
instr = builder.Not(ty, val.Get());
inst = builder.Not(ty, val.Get());
break;
}
current_flow_block->instructions.Push(instr);
return instr->Result();
current_flow_block->instructions.Push(inst);
return inst->Result();
}
utils::Result<Value*> BuilderImpl::EmitBinary(const ast::BinaryExpression* expr) {
@ -755,69 +755,69 @@ utils::Result<Value*> BuilderImpl::EmitBinary(const ast::BinaryExpression* expr)
auto* sem = program_->Sem().Get(expr);
auto* ty = sem->Type()->Clone(clone_ctx_.type_ctx);
Binary* instr = nullptr;
Binary* inst = nullptr;
switch (expr->op) {
case ast::BinaryOp::kAnd:
instr = builder.And(ty, lhs.Get(), rhs.Get());
inst = builder.And(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kOr:
instr = builder.Or(ty, lhs.Get(), rhs.Get());
inst = builder.Or(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kXor:
instr = builder.Xor(ty, lhs.Get(), rhs.Get());
inst = builder.Xor(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kLogicalAnd:
instr = builder.LogicalAnd(ty, lhs.Get(), rhs.Get());
inst = builder.LogicalAnd(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kLogicalOr:
instr = builder.LogicalOr(ty, lhs.Get(), rhs.Get());
inst = builder.LogicalOr(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kEqual:
instr = builder.Equal(ty, lhs.Get(), rhs.Get());
inst = builder.Equal(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kNotEqual:
instr = builder.NotEqual(ty, lhs.Get(), rhs.Get());
inst = builder.NotEqual(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kLessThan:
instr = builder.LessThan(ty, lhs.Get(), rhs.Get());
inst = builder.LessThan(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kGreaterThan:
instr = builder.GreaterThan(ty, lhs.Get(), rhs.Get());
inst = builder.GreaterThan(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kLessThanEqual:
instr = builder.LessThanEqual(ty, lhs.Get(), rhs.Get());
inst = builder.LessThanEqual(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kGreaterThanEqual:
instr = builder.GreaterThanEqual(ty, lhs.Get(), rhs.Get());
inst = builder.GreaterThanEqual(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kShiftLeft:
instr = builder.ShiftLeft(ty, lhs.Get(), rhs.Get());
inst = builder.ShiftLeft(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kShiftRight:
instr = builder.ShiftRight(ty, lhs.Get(), rhs.Get());
inst = builder.ShiftRight(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kAdd:
instr = builder.Add(ty, lhs.Get(), rhs.Get());
inst = builder.Add(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kSubtract:
instr = builder.Subtract(ty, lhs.Get(), rhs.Get());
inst = builder.Subtract(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kMultiply:
instr = builder.Multiply(ty, lhs.Get(), rhs.Get());
inst = builder.Multiply(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kDivide:
instr = builder.Divide(ty, lhs.Get(), rhs.Get());
inst = builder.Divide(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kModulo:
instr = builder.Modulo(ty, lhs.Get(), rhs.Get());
inst = builder.Modulo(ty, lhs.Get(), rhs.Get());
break;
case ast::BinaryOp::kNone:
TINT_ICE(IR, diagnostics_) << "missing binary operand type";
return utils::Failure;
}
current_flow_block->instructions.Push(instr);
return instr->Result();
current_flow_block->instructions.Push(inst);
return inst->Result();
}
utils::Result<Value*> BuilderImpl::EmitBitcast(const ast::BitcastExpression* expr) {
@ -828,10 +828,10 @@ utils::Result<Value*> BuilderImpl::EmitBitcast(const ast::BitcastExpression* exp
auto* sem = program_->Sem().Get(expr);
auto* ty = sem->Type()->Clone(clone_ctx_.type_ctx);
auto* instr = builder.Bitcast(ty, val.Get());
auto* inst = builder.Bitcast(ty, val.Get());
current_flow_block->instructions.Push(instr);
return instr->Result();
current_flow_block->instructions.Push(inst);
return inst->Result();
}
void BuilderImpl::EmitCall(const ast::CallStatement* stmt) {
@ -874,29 +874,29 @@ utils::Result<Value*> BuilderImpl::EmitCall(const ast::CallExpression* expr) {
auto* ty = sem->Target()->ReturnType()->Clone(clone_ctx_.type_ctx);
Instruction* instr = nullptr;
Instruction* inst = nullptr;
// If this is a builtin function, emit the specific builtin value
if (auto* b = sem->Target()->As<sem::Builtin>()) {
instr = builder.Builtin(ty, b->Type(), args);
inst = builder.Builtin(ty, b->Type(), args);
} else if (sem->Target()->As<sem::ValueConstructor>()) {
instr = builder.Construct(ty, std::move(args));
inst = builder.Construct(ty, std::move(args));
} else if (auto* conv = sem->Target()->As<sem::ValueConversion>()) {
auto* from = conv->Source()->Clone(clone_ctx_.type_ctx);
instr = builder.Convert(ty, from, std::move(args));
inst = builder.Convert(ty, from, std::move(args));
} else if (expr->target->identifier->Is<ast::TemplatedIdentifier>()) {
TINT_UNIMPLEMENTED(IR, diagnostics_) << "missing templated ident support";
return utils::Failure;
} else {
// Not a builtin and not a templated call, so this is a user function.
auto name = CloneSymbol(expr->target->identifier->symbol);
instr = builder.UserCall(ty, name, std::move(args));
inst = builder.UserCall(ty, name, std::move(args));
}
if (instr == nullptr) {
if (inst == nullptr) {
return utils::Failure;
}
current_flow_block->instructions.Push(instr);
return instr->Result();
current_flow_block->instructions.Push(inst);
return inst->Result();
}
utils::Result<Value*> BuilderImpl::EmitLiteral(const ast::LiteralExpression* lit) {

View File

@ -30,12 +30,12 @@ class Builtin : public utils::Castable<Builtin, Call> {
/// @param func the builtin function
/// @param args the conversion arguments
Builtin(Value* result, builtin::Function func, utils::VectorRef<Value*> args);
Builtin(const Builtin& instr) = delete;
Builtin(Builtin&& instr) = delete;
Builtin(const Builtin& inst) = delete;
Builtin(Builtin&& inst) = delete;
~Builtin() override;
Builtin& operator=(const Builtin& instr) = delete;
Builtin& operator=(Builtin&& instr) = delete;
Builtin& operator=(const Builtin& inst) = delete;
Builtin& operator=(Builtin&& inst) = delete;
/// @returns the builtin function
builtin::Function Func() const { return func_; }

View File

@ -28,12 +28,12 @@ class Call : public utils::Castable<Call, Instruction> {
/// @param result the result value
/// @param args the constructor arguments
Call(Value* result, utils::VectorRef<Value*> args);
Call(const Call& instr) = delete;
Call(Call&& instr) = delete;
Call(const Call& inst) = delete;
Call(Call&& inst) = delete;
~Call() override;
Call& operator=(const Call& instr) = delete;
Call& operator=(Call&& instr) = delete;
Call& operator=(const Call& inst) = delete;
Call& operator=(Call&& inst) = delete;
/// @returns the constructor arguments
utils::VectorRef<Value*> Args() const { return args_; }

View File

@ -28,12 +28,12 @@ class Construct : public utils::Castable<Construct, Call> {
/// @param result the result value
/// @param args the constructor arguments
Construct(Value* result, utils::VectorRef<Value*> args);
Construct(const Construct& instr) = delete;
Construct(Construct&& instr) = delete;
Construct(const Construct& inst) = delete;
Construct(Construct&& inst) = delete;
~Construct() override;
Construct& operator=(const Construct& instr) = delete;
Construct& operator=(Construct&& instr) = delete;
Construct& operator=(const Construct& inst) = delete;
Construct& operator=(Construct&& inst) = delete;
/// Write the instruction to the given stream
/// @param out the stream to write to

View File

@ -30,12 +30,12 @@ class Convert : public utils::Castable<Convert, Call> {
/// @param from the type being converted from
/// @param args the conversion arguments
Convert(Value* result, const type::Type* from, utils::VectorRef<Value*> args);
Convert(const Convert& instr) = delete;
Convert(Convert&& instr) = delete;
Convert(const Convert& inst) = delete;
Convert(Convert&& inst) = delete;
~Convert() override;
Convert& operator=(const Convert& instr) = delete;
Convert& operator=(Convert&& instr) = delete;
Convert& operator=(const Convert& inst) = delete;
Convert& operator=(Convert&& inst) = delete;
/// @returns the from type
const type::Type* From() const { return from_; }

View File

@ -62,9 +62,9 @@ utils::StringStream& Disassembler::Indent() {
}
void Disassembler::EmitBlockInstructions(const Block* b) {
for (const auto* instr : b->instructions) {
for (const auto* inst : b->instructions) {
Indent();
instr->ToString(out_) << std::endl;
inst->ToString(out_) << std::endl;
}
}

View File

@ -27,12 +27,12 @@ class Discard : public utils::Castable<Discard, Instruction> {
/// Constructor
/// @param result the result id
explicit Discard(Value* result);
Discard(const Discard& instr) = delete;
Discard(Discard&& instr) = delete;
Discard(const Discard& inst) = delete;
Discard(Discard&& inst) = delete;
~Discard() override;
Discard& operator=(const Discard& instr) = delete;
Discard& operator=(Discard&& instr) = delete;
Discard& operator=(const Discard& inst) = delete;
Discard& operator=(Discard&& inst) = delete;
/// Write the instruction to the given stream
/// @param out the stream to write to

View File

@ -25,15 +25,15 @@ TEST_F(IR_InstructionTest, Discard) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr = b.builder.Discard();
const auto* inst = b.builder.Discard();
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_NE(instr->Result()->Type(), nullptr);
ASSERT_NE(instr->Result()->Type()->As<type::Void>(), nullptr);
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_NE(inst->Result()->Type(), nullptr);
ASSERT_NE(inst->Result()->Type()->As<type::Void>(), nullptr);
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (void) = discard");
}

View File

@ -24,13 +24,13 @@ namespace tint::ir {
/// An instruction in the IR.
class Instruction : public utils::Castable<Instruction> {
public:
Instruction(const Instruction& instr) = delete;
Instruction(Instruction&& instr) = delete;
Instruction(const Instruction& inst) = delete;
Instruction(Instruction&& inst) = delete;
/// Destructor
~Instruction() override;
Instruction& operator=(const Instruction& instr) = delete;
Instruction& operator=(Instruction&& instr) = delete;
Instruction& operator=(const Instruction& inst) = delete;
Instruction& operator=(Instruction&& inst) = delete;
/// @returns the result value for the instruction
Value* Result() const { return result_; }

View File

@ -28,12 +28,12 @@ class Store : public utils::Castable<Store, Instruction> {
/// @param to the value to store too
/// @param from the value being stored from
Store(Value* to, Value* from);
Store(const Store& instr) = delete;
Store(Store&& instr) = delete;
Store(const Store& inst) = delete;
Store(Store&& inst) = delete;
~Store() override;
Store& operator=(const Store& instr) = delete;
Store& operator=(Store&& instr) = delete;
Store& operator=(const Store& inst) = delete;
Store& operator=(Store&& inst) = delete;
/// @returns the value being stored
const Value* from() const { return from_; }

View File

@ -29,19 +29,19 @@ TEST_F(IR_InstructionTest, CreateStore) {
b.builder.next_runtime_id = Runtime::Id(42);
auto* rt = b.builder.Runtime(b.builder.ir.types.Get<type::I32>());
const auto* instr = b.builder.Store(rt, b.builder.Constant(4_i));
const auto* inst = b.builder.Store(rt, b.builder.Constant(4_i));
ASSERT_TRUE(instr->Result()->Is<Runtime>());
ASSERT_NE(instr->Result()->Type(), nullptr);
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
ASSERT_NE(inst->Result()->Type(), nullptr);
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->from()->Is<Constant>());
auto lhs = instr->from()->As<Constant>()->value;
ASSERT_TRUE(inst->from()->Is<Constant>());
auto lhs = inst->from()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = 4");
}
@ -50,15 +50,15 @@ TEST_F(IR_InstructionTest, Store_Usage) {
b.builder.next_runtime_id = Runtime::Id(42);
auto* rt = b.builder.Runtime(b.builder.ir.types.Get<type::I32>());
const auto* instr = b.builder.Store(rt, b.builder.Constant(4_i));
const auto* inst = b.builder.Store(rt, b.builder.Constant(4_i));
ASSERT_NE(instr->Result(), nullptr);
ASSERT_EQ(instr->Result()->Usage().Length(), 1u);
EXPECT_EQ(instr->Result()->Usage()[0], instr);
ASSERT_NE(inst->Result(), nullptr);
ASSERT_EQ(inst->Result()->Usage().Length(), 1u);
EXPECT_EQ(inst->Result()->Usage()[0], inst);
ASSERT_NE(instr->from(), nullptr);
ASSERT_EQ(instr->from()->Usage().Length(), 1u);
EXPECT_EQ(instr->from()->Usage()[0], instr);
ASSERT_NE(inst->from(), nullptr);
ASSERT_EQ(inst->from()->Usage().Length(), 1u);
EXPECT_EQ(inst->from()->Usage()[0], inst);
}
} // namespace

View File

@ -38,12 +38,12 @@ class Unary : public utils::Castable<Unary, Instruction> {
/// @param result the result value
/// @param val the lhs of the instruction
Unary(Kind kind, Value* result, Value* val);
Unary(const Unary& instr) = delete;
Unary(Unary&& instr) = delete;
Unary(const Unary& inst) = delete;
Unary(Unary&& inst) = delete;
~Unary() override;
Unary& operator=(const Unary& instr) = delete;
Unary& operator=(Unary&& instr) = delete;
Unary& operator=(const Unary& inst) = delete;
Unary& operator=(Unary&& inst) = delete;
/// @returns the kind of instruction
Kind GetKind() const { return kind_; }

View File

@ -28,25 +28,25 @@ TEST_F(IR_InstructionTest, CreateAddressOf) {
b.builder.next_runtime_id = Runtime::Id(42);
// TODO(dsinclair): This would be better as an identifier, but works for now.
const auto* instr =
const auto* inst =
b.builder.AddressOf(b.builder.ir.types.Get<type::Pointer>(
b.builder.ir.types.Get<type::I32>(),
builtin::AddressSpace::kPrivate, builtin::Access::kReadWrite),
b.builder.Constant(4_i));
EXPECT_EQ(instr->GetKind(), Unary::Kind::kAddressOf);
EXPECT_EQ(inst->GetKind(), Unary::Kind::kAddressOf);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
ASSERT_NE(instr->Result()->Type(), nullptr);
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
ASSERT_NE(inst->Result()->Type(), nullptr);
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->Val()->Is<Constant>());
auto lhs = instr->Val()->As<Constant>()->value;
ASSERT_TRUE(inst->Val()->Is<Constant>());
auto lhs = inst->Val()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (ptr<private, i32, read_write>) = &4");
}
@ -54,21 +54,21 @@ TEST_F(IR_InstructionTest, CreateComplement) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr =
const auto* inst =
b.builder.Complement(b.builder.ir.types.Get<type::I32>(), b.builder.Constant(4_i));
EXPECT_EQ(instr->GetKind(), Unary::Kind::kComplement);
EXPECT_EQ(inst->GetKind(), Unary::Kind::kComplement);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->Val()->Is<Constant>());
auto lhs = instr->Val()->As<Constant>()->value;
ASSERT_TRUE(inst->Val()->Is<Constant>());
auto lhs = inst->Val()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = ~4");
}
@ -77,21 +77,21 @@ TEST_F(IR_InstructionTest, CreateIndirection) {
b.builder.next_runtime_id = Runtime::Id(42);
// TODO(dsinclair): This would be better as an identifier, but works for now.
const auto* instr =
const auto* inst =
b.builder.Indirection(b.builder.ir.types.Get<type::I32>(), b.builder.Constant(4_i));
EXPECT_EQ(instr->GetKind(), Unary::Kind::kIndirection);
EXPECT_EQ(inst->GetKind(), Unary::Kind::kIndirection);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->Val()->Is<Constant>());
auto lhs = instr->Val()->As<Constant>()->value;
ASSERT_TRUE(inst->Val()->Is<Constant>());
auto lhs = inst->Val()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = *4");
}
@ -99,21 +99,21 @@ TEST_F(IR_InstructionTest, CreateNegation) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr =
const auto* inst =
b.builder.Negation(b.builder.ir.types.Get<type::I32>(), b.builder.Constant(4_i));
EXPECT_EQ(instr->GetKind(), Unary::Kind::kNegation);
EXPECT_EQ(inst->GetKind(), Unary::Kind::kNegation);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->Val()->Is<Constant>());
auto lhs = instr->Val()->As<Constant>()->value;
ASSERT_TRUE(inst->Val()->Is<Constant>());
auto lhs = inst->Val()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<i32>>());
EXPECT_EQ(4_i, lhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = -4");
}
@ -121,21 +121,21 @@ TEST_F(IR_InstructionTest, CreateNot) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr =
const auto* inst =
b.builder.Not(b.builder.ir.types.Get<type::Bool>(), b.builder.Constant(true));
EXPECT_EQ(instr->GetKind(), Unary::Kind::kNot);
EXPECT_EQ(inst->GetKind(), Unary::Kind::kNot);
ASSERT_TRUE(instr->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), instr->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(inst->Result()->Is<Runtime>());
EXPECT_EQ(Runtime::Id(42), inst->Result()->As<Runtime>()->AsId());
ASSERT_TRUE(instr->Val()->Is<Constant>());
auto lhs = instr->Val()->As<Constant>()->value;
ASSERT_TRUE(inst->Val()->Is<Constant>());
auto lhs = inst->Val()->As<Constant>()->value;
ASSERT_TRUE(lhs->Is<constant::Scalar<bool>>());
EXPECT_TRUE(lhs->As<constant::Scalar<bool>>()->ValueAs<bool>());
utils::StringStream str;
instr->ToString(str);
inst->ToString(str);
EXPECT_EQ(str.str(), "%42 (bool) = !true");
}
@ -143,18 +143,18 @@ TEST_F(IR_InstructionTest, Unary_Usage) {
auto& b = CreateEmptyBuilder();
b.builder.next_runtime_id = Runtime::Id(42);
const auto* instr =
const auto* inst =
b.builder.Negation(b.builder.ir.types.Get<type::I32>(), b.builder.Constant(4_i));
EXPECT_EQ(instr->GetKind(), Unary::Kind::kNegation);
EXPECT_EQ(inst->GetKind(), Unary::Kind::kNegation);
ASSERT_NE(instr->Result(), nullptr);
ASSERT_EQ(instr->Result()->Usage().Length(), 1u);
EXPECT_EQ(instr->Result()->Usage()[0], instr);
ASSERT_NE(inst->Result(), nullptr);
ASSERT_EQ(inst->Result()->Usage().Length(), 1u);
EXPECT_EQ(inst->Result()->Usage()[0], inst);
ASSERT_NE(instr->Val(), nullptr);
ASSERT_EQ(instr->Val()->Usage().Length(), 1u);
EXPECT_EQ(instr->Val()->Usage()[0], instr);
ASSERT_NE(inst->Val(), nullptr);
ASSERT_EQ(inst->Val()->Usage().Length(), 1u);
EXPECT_EQ(inst->Val()->Usage()[0], inst);
}
} // namespace

View File

@ -30,12 +30,12 @@ class UserCall : public utils::Castable<UserCall, Call> {
/// @param name the function name
/// @param args the function arguments
UserCall(Value* result, Symbol name, utils::VectorRef<Value*> args);
UserCall(const UserCall& instr) = delete;
UserCall(UserCall&& instr) = delete;
UserCall(const UserCall& inst) = delete;
UserCall(UserCall&& inst) = delete;
~UserCall() override;
UserCall& operator=(const UserCall& instr) = delete;
UserCall& operator=(UserCall&& instr) = delete;
UserCall& operator=(const UserCall& inst) = delete;
UserCall& operator=(UserCall&& inst) = delete;
/// @returns the function name
Symbol Name() const { return name_; }

View File

@ -40,8 +40,8 @@ class Value : public utils::Castable<Value> {
Value& operator=(Value&&) = delete;
/// Adds an instruction which uses this value.
/// @param instr the instruction
void AddUsage(const Instruction* instr) { uses_.Add(instr); }
/// @param inst the instruction
void AddUsage(const Instruction* inst) { uses_.Add(inst); }
/// @returns the vector of instructions which use this value. An instruction will only be
/// returned once even if that instruction uses the given value multiple times.