[ir] Update binary and unary names.
This CL removes the LogicalAnd and LogicalOr binary kinds, and updates
the names in binary and unary to drop `bit_` and `log_` prefixes.
Bug: tint:1718
Change-Id: Ie180549ee5ecfad65fff9e4b4db86dd8a8b54833
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/130800
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
diff --git a/src/tint/ir/binary.cc b/src/tint/ir/binary.cc
index d3e3548..cde8533 100644
--- a/src/tint/ir/binary.cc
+++ b/src/tint/ir/binary.cc
@@ -49,19 +49,13 @@
out << "mod";
break;
case Binary::Kind::kAnd:
- out << "bit_and";
+ out << "and";
break;
case Binary::Kind::kOr:
- out << "bit_or";
+ out << "or";
break;
case Binary::Kind::kXor:
- out << "bit_xor";
- break;
- case Binary::Kind::kLogicalAnd:
- out << "log_and";
- break;
- case Binary::Kind::kLogicalOr:
- out << "log_or";
+ out << "xor";
break;
case Binary::Kind::kEqual:
out << "eq";
diff --git a/src/tint/ir/binary.h b/src/tint/ir/binary.h
index 92a1998..8ce3b48 100644
--- a/src/tint/ir/binary.h
+++ b/src/tint/ir/binary.h
@@ -36,9 +36,6 @@
kOr,
kXor,
- kLogicalAnd,
- kLogicalOr,
-
kEqual,
kNotEqual,
kLessThan,
diff --git a/src/tint/ir/binary_test.cc b/src/tint/ir/binary_test.cc
index e03a61d..056e02f 100644
--- a/src/tint/ir/binary_test.cc
+++ b/src/tint/ir/binary_test.cc
@@ -45,7 +45,7 @@
utils::StringStream str;
inst->ToInstruction(str);
- EXPECT_EQ(str.str(), "%1(i32) = bit_and 4i, 2i");
+ EXPECT_EQ(str.str(), "%1(i32) = and 4i, 2i");
}
TEST_F(IR_InstructionTest, CreateOr) {
@@ -69,7 +69,7 @@
utils::StringStream str;
inst->ToInstruction(str);
- EXPECT_EQ(str.str(), "%1(i32) = bit_or 4i, 2i");
+ EXPECT_EQ(str.str(), "%1(i32) = or 4i, 2i");
}
TEST_F(IR_InstructionTest, CreateXor) {
@@ -93,55 +93,7 @@
utils::StringStream str;
inst->ToInstruction(str);
- EXPECT_EQ(str.str(), "%1(i32) = bit_xor 4i, 2i");
-}
-
-TEST_F(IR_InstructionTest, CreateLogicalAnd) {
- auto& b = CreateEmptyBuilder();
-
- const auto* inst = b.builder.LogicalAnd(b.builder.ir.types.Get<type::Bool>(),
- b.builder.Constant(4_i), b.builder.Constant(2_i));
-
- ASSERT_TRUE(inst->Is<Binary>());
- EXPECT_EQ(inst->GetKind(), Binary::Kind::kLogicalAnd);
-
- 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(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;
- inst->ToInstruction(str);
- EXPECT_EQ(str.str(), "%1(bool) = log_and 4i, 2i");
-}
-
-TEST_F(IR_InstructionTest, CreateLogicalOr) {
- auto& b = CreateEmptyBuilder();
-
- const auto* inst = b.builder.LogicalOr(b.builder.ir.types.Get<type::Bool>(),
- b.builder.Constant(4_i), b.builder.Constant(2_i));
-
- ASSERT_TRUE(inst->Is<Binary>());
- EXPECT_EQ(inst->GetKind(), Binary::Kind::kLogicalOr);
-
- 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(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;
- inst->ToInstruction(str);
- EXPECT_EQ(str.str(), "%1(bool) = log_or 4i, 2i");
+ EXPECT_EQ(str.str(), "%1(i32) = xor 4i, 2i");
}
TEST_F(IR_InstructionTest, CreateEqual) {
diff --git a/src/tint/ir/builder.cc b/src/tint/ir/builder.cc
index 2c97737..7090cb6 100644
--- a/src/tint/ir/builder.cc
+++ b/src/tint/ir/builder.cc
@@ -118,14 +118,6 @@
return CreateBinary(Binary::Kind::kXor, type, lhs, rhs);
}
-Binary* Builder::LogicalAnd(const type::Type* type, Value* lhs, Value* rhs) {
- return CreateBinary(Binary::Kind::kLogicalAnd, type, lhs, rhs);
-}
-
-Binary* Builder::LogicalOr(const type::Type* type, Value* lhs, Value* rhs) {
- return CreateBinary(Binary::Kind::kLogicalOr, type, lhs, rhs);
-}
-
Binary* Builder::Equal(const type::Type* type, Value* lhs, Value* rhs) {
return CreateBinary(Binary::Kind::kEqual, type, lhs, rhs);
}
diff --git a/src/tint/ir/builder.h b/src/tint/ir/builder.h
index d509c06..618679b 100644
--- a/src/tint/ir/builder.h
+++ b/src/tint/ir/builder.h
@@ -170,20 +170,6 @@
/// @returns the operation
Binary* Xor(const type::Type* type, Value* lhs, Value* rhs);
- /// Creates an LogicalAnd operation
- /// @param type the result type of the expression
- /// @param lhs the lhs of the add
- /// @param rhs the rhs of the add
- /// @returns the operation
- Binary* LogicalAnd(const type::Type* type, Value* lhs, Value* rhs);
-
- /// Creates an LogicalOr operation
- /// @param type the result type of the expression
- /// @param lhs the lhs of the add
- /// @param rhs the rhs of the add
- /// @returns the operation
- Binary* LogicalOr(const type::Type* type, Value* lhs, Value* rhs);
-
/// Creates an Equal operation
/// @param type the result type of the expression
/// @param lhs the lhs of the add
diff --git a/src/tint/ir/builder_impl.cc b/src/tint/ir/builder_impl.cc
index fd6f500..cce89a4 100644
--- a/src/tint/ir/builder_impl.cc
+++ b/src/tint/ir/builder_impl.cc
@@ -309,12 +309,6 @@
case ast::BinaryOp::kXor:
inst = builder.Xor(ty, lhs.Get(), rhs.Get());
break;
- case ast::BinaryOp::kLogicalAnd:
- inst = builder.LogicalAnd(ty, lhs.Get(), rhs.Get());
- break;
- case ast::BinaryOp::kLogicalOr:
- inst = builder.LogicalOr(ty, lhs.Get(), rhs.Get());
- break;
case ast::BinaryOp::kEqual:
inst = builder.Equal(ty, lhs.Get(), rhs.Get());
break;
@@ -354,6 +348,10 @@
case ast::BinaryOp::kModulo:
inst = builder.Modulo(ty, lhs.Get(), rhs.Get());
break;
+ case ast::BinaryOp::kLogicalAnd:
+ case ast::BinaryOp::kLogicalOr:
+ TINT_ICE(IR, diagnostics_) << "invalid compound assignment";
+ return;
case ast::BinaryOp::kNone:
TINT_ICE(IR, diagnostics_) << "missing binary operand type";
return;
@@ -790,11 +788,13 @@
return utils::Failure;
}
+ // Evaluate the LHS of the short-circuit
auto lhs = EmitExpression(expr->lhs);
if (!lhs) {
return utils::Failure;
}
+ // Generate a variable to store the short-circut into
auto* ty = builder.ir.types.Get<type::Bool>();
auto* result_var =
builder.Declare(ty, builtin::AddressSpace::kFunction, builtin::Access::kReadWrite);
diff --git a/src/tint/ir/builder_impl_test.cc b/src/tint/ir/builder_impl_test.cc
index bcba641..4df35bf 100644
--- a/src/tint/ir/builder_impl_test.cc
+++ b/src/tint/ir/builder_impl_test.cc
@@ -1728,7 +1728,7 @@
Disassembler d(b.builder.ir);
d.EmitBlockInstructions(b.current_flow_block->As<ir::Block>());
EXPECT_EQ(d.AsString(), R"(%1(u32) = call my_func
-%2(u32) = bit_and %1(u32), 4u
+%2(u32) = and %1(u32), 4u
)");
}
@@ -1746,7 +1746,7 @@
Disassembler d(b.builder.ir);
d.EmitBlockInstructions(b.current_flow_block->As<ir::Block>());
EXPECT_EQ(d.AsString(), R"(%1(u32) = call my_func
-%2(u32) = bit_or %1(u32), 4u
+%2(u32) = or %1(u32), 4u
)");
}
@@ -1764,7 +1764,7 @@
Disassembler d(b.builder.ir);
d.EmitBlockInstructions(b.current_flow_block->As<ir::Block>());
EXPECT_EQ(d.AsString(), R"(%1(u32) = call my_func
-%2(u32) = bit_xor %1(u32), 4u
+%2(u32) = xor %1(u32), 4u
)");
}
diff --git a/src/tint/ir/unary.cc b/src/tint/ir/unary.cc
index f3c4f24..86c06af 100644
--- a/src/tint/ir/unary.cc
+++ b/src/tint/ir/unary.cc
@@ -34,7 +34,7 @@
out << "addr_of";
break;
case Unary::Kind::kComplement:
- out << "bit_complement";
+ out << "complement";
break;
case Unary::Kind::kIndirection:
out << "indirection";
@@ -43,7 +43,7 @@
out << "negation";
break;
case Unary::Kind::kNot:
- out << "log_not";
+ out << "not";
break;
}
out << " ";
diff --git a/src/tint/ir/unary_test.cc b/src/tint/ir/unary_test.cc
index ff247a2..c36e3ee 100644
--- a/src/tint/ir/unary_test.cc
+++ b/src/tint/ir/unary_test.cc
@@ -63,7 +63,7 @@
utils::StringStream str;
inst->ToInstruction(str);
- EXPECT_EQ(str.str(), "%1(i32) = bit_complement 4i");
+ EXPECT_EQ(str.str(), "%1(i32) = complement 4i");
}
TEST_F(IR_InstructionTest, CreateIndirection) {
@@ -119,7 +119,7 @@
utils::StringStream str;
inst->ToInstruction(str);
- EXPECT_EQ(str.str(), "%1(bool) = log_not true");
+ EXPECT_EQ(str.str(), "%1(bool) = not true");
}
TEST_F(IR_InstructionTest, Unary_Usage) {