[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>
This commit is contained in:
dan sinclair 2023-05-03 16:25:44 +00:00 committed by Dawn LUCI CQ
parent 95edbb6ecc
commit 6ac51c1c57
9 changed files with 19 additions and 98 deletions

View File

@ -49,19 +49,13 @@ utils::StringStream& Binary::ToInstruction(utils::StringStream& out) const {
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";

View File

@ -36,9 +36,6 @@ class Binary : public utils::Castable<Binary, Instruction> {
kOr,
kXor,
kLogicalAnd,
kLogicalOr,
kEqual,
kNotEqual,
kLessThan,

View File

@ -45,7 +45,7 @@ TEST_F(IR_InstructionTest, CreateAnd) {
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 @@ TEST_F(IR_InstructionTest, CreateOr) {
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 @@ TEST_F(IR_InstructionTest, CreateXor) {
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) {

View File

@ -118,14 +118,6 @@ Binary* Builder::Xor(const type::Type* type, Value* lhs, Value* rhs) {
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);
}

View File

@ -170,20 +170,6 @@ class Builder {
/// @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

View File

@ -309,12 +309,6 @@ void BuilderImpl::EmitCompoundAssignment(const ast::CompoundAssignmentStatement*
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 @@ void BuilderImpl::EmitCompoundAssignment(const ast::CompoundAssignmentStatement*
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 @@ utils::Result<Value*> BuilderImpl::EmitShortCircuit(const ast::BinaryExpression*
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);

View File

@ -1728,7 +1728,7 @@ TEST_F(IR_BuilderImplTest, EmitExpression_Binary_And) {
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 @@ TEST_F(IR_BuilderImplTest, EmitExpression_Binary_Or) {
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 @@ TEST_F(IR_BuilderImplTest, EmitExpression_Binary_Xor) {
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
)");
}

View File

@ -34,7 +34,7 @@ utils::StringStream& Unary::ToInstruction(utils::StringStream& out) const {
out << "addr_of";
break;
case Unary::Kind::kComplement:
out << "bit_complement";
out << "complement";
break;
case Unary::Kind::kIndirection:
out << "indirection";
@ -43,7 +43,7 @@ utils::StringStream& Unary::ToInstruction(utils::StringStream& out) const {
out << "negation";
break;
case Unary::Kind::kNot:
out << "log_not";
out << "not";
break;
}
out << " ";

View File

@ -63,7 +63,7 @@ TEST_F(IR_InstructionTest, CreateComplement) {
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 @@ TEST_F(IR_InstructionTest, CreateNot) {
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) {