[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:
parent
95edbb6ecc
commit
6ac51c1c57
|
@ -49,19 +49,13 @@ utils::StringStream& Binary::ToInstruction(utils::StringStream& out) const {
|
||||||
out << "mod";
|
out << "mod";
|
||||||
break;
|
break;
|
||||||
case Binary::Kind::kAnd:
|
case Binary::Kind::kAnd:
|
||||||
out << "bit_and";
|
out << "and";
|
||||||
break;
|
break;
|
||||||
case Binary::Kind::kOr:
|
case Binary::Kind::kOr:
|
||||||
out << "bit_or";
|
out << "or";
|
||||||
break;
|
break;
|
||||||
case Binary::Kind::kXor:
|
case Binary::Kind::kXor:
|
||||||
out << "bit_xor";
|
out << "xor";
|
||||||
break;
|
|
||||||
case Binary::Kind::kLogicalAnd:
|
|
||||||
out << "log_and";
|
|
||||||
break;
|
|
||||||
case Binary::Kind::kLogicalOr:
|
|
||||||
out << "log_or";
|
|
||||||
break;
|
break;
|
||||||
case Binary::Kind::kEqual:
|
case Binary::Kind::kEqual:
|
||||||
out << "eq";
|
out << "eq";
|
||||||
|
|
|
@ -36,9 +36,6 @@ class Binary : public utils::Castable<Binary, Instruction> {
|
||||||
kOr,
|
kOr,
|
||||||
kXor,
|
kXor,
|
||||||
|
|
||||||
kLogicalAnd,
|
|
||||||
kLogicalOr,
|
|
||||||
|
|
||||||
kEqual,
|
kEqual,
|
||||||
kNotEqual,
|
kNotEqual,
|
||||||
kLessThan,
|
kLessThan,
|
||||||
|
|
|
@ -45,7 +45,7 @@ TEST_F(IR_InstructionTest, CreateAnd) {
|
||||||
|
|
||||||
utils::StringStream str;
|
utils::StringStream str;
|
||||||
inst->ToInstruction(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) {
|
TEST_F(IR_InstructionTest, CreateOr) {
|
||||||
|
@ -69,7 +69,7 @@ TEST_F(IR_InstructionTest, CreateOr) {
|
||||||
|
|
||||||
utils::StringStream str;
|
utils::StringStream str;
|
||||||
inst->ToInstruction(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) {
|
TEST_F(IR_InstructionTest, CreateXor) {
|
||||||
|
@ -93,55 +93,7 @@ TEST_F(IR_InstructionTest, CreateXor) {
|
||||||
|
|
||||||
utils::StringStream str;
|
utils::StringStream str;
|
||||||
inst->ToInstruction(str);
|
inst->ToInstruction(str);
|
||||||
EXPECT_EQ(str.str(), "%1(i32) = bit_xor 4i, 2i");
|
EXPECT_EQ(str.str(), "%1(i32) = 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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(IR_InstructionTest, CreateEqual) {
|
TEST_F(IR_InstructionTest, CreateEqual) {
|
||||||
|
|
|
@ -118,14 +118,6 @@ Binary* Builder::Xor(const type::Type* type, Value* lhs, Value* rhs) {
|
||||||
return CreateBinary(Binary::Kind::kXor, type, lhs, 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) {
|
Binary* Builder::Equal(const type::Type* type, Value* lhs, Value* rhs) {
|
||||||
return CreateBinary(Binary::Kind::kEqual, type, lhs, rhs);
|
return CreateBinary(Binary::Kind::kEqual, type, lhs, rhs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,20 +170,6 @@ class Builder {
|
||||||
/// @returns the operation
|
/// @returns the operation
|
||||||
Binary* Xor(const type::Type* type, Value* lhs, Value* rhs);
|
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
|
/// Creates an Equal operation
|
||||||
/// @param type the result type of the expression
|
/// @param type the result type of the expression
|
||||||
/// @param lhs the lhs of the add
|
/// @param lhs the lhs of the add
|
||||||
|
|
|
@ -309,12 +309,6 @@ void BuilderImpl::EmitCompoundAssignment(const ast::CompoundAssignmentStatement*
|
||||||
case ast::BinaryOp::kXor:
|
case ast::BinaryOp::kXor:
|
||||||
inst = builder.Xor(ty, lhs.Get(), rhs.Get());
|
inst = builder.Xor(ty, lhs.Get(), rhs.Get());
|
||||||
break;
|
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:
|
case ast::BinaryOp::kEqual:
|
||||||
inst = builder.Equal(ty, lhs.Get(), rhs.Get());
|
inst = builder.Equal(ty, lhs.Get(), rhs.Get());
|
||||||
break;
|
break;
|
||||||
|
@ -354,6 +348,10 @@ void BuilderImpl::EmitCompoundAssignment(const ast::CompoundAssignmentStatement*
|
||||||
case ast::BinaryOp::kModulo:
|
case ast::BinaryOp::kModulo:
|
||||||
inst = builder.Modulo(ty, lhs.Get(), rhs.Get());
|
inst = builder.Modulo(ty, lhs.Get(), rhs.Get());
|
||||||
break;
|
break;
|
||||||
|
case ast::BinaryOp::kLogicalAnd:
|
||||||
|
case ast::BinaryOp::kLogicalOr:
|
||||||
|
TINT_ICE(IR, diagnostics_) << "invalid compound assignment";
|
||||||
|
return;
|
||||||
case ast::BinaryOp::kNone:
|
case ast::BinaryOp::kNone:
|
||||||
TINT_ICE(IR, diagnostics_) << "missing binary operand type";
|
TINT_ICE(IR, diagnostics_) << "missing binary operand type";
|
||||||
return;
|
return;
|
||||||
|
@ -790,11 +788,13 @@ utils::Result<Value*> BuilderImpl::EmitShortCircuit(const ast::BinaryExpression*
|
||||||
return utils::Failure;
|
return utils::Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Evaluate the LHS of the short-circuit
|
||||||
auto lhs = EmitExpression(expr->lhs);
|
auto lhs = EmitExpression(expr->lhs);
|
||||||
if (!lhs) {
|
if (!lhs) {
|
||||||
return utils::Failure;
|
return utils::Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate a variable to store the short-circut into
|
||||||
auto* ty = builder.ir.types.Get<type::Bool>();
|
auto* ty = builder.ir.types.Get<type::Bool>();
|
||||||
auto* result_var =
|
auto* result_var =
|
||||||
builder.Declare(ty, builtin::AddressSpace::kFunction, builtin::Access::kReadWrite);
|
builder.Declare(ty, builtin::AddressSpace::kFunction, builtin::Access::kReadWrite);
|
||||||
|
|
|
@ -1728,7 +1728,7 @@ TEST_F(IR_BuilderImplTest, EmitExpression_Binary_And) {
|
||||||
Disassembler d(b.builder.ir);
|
Disassembler d(b.builder.ir);
|
||||||
d.EmitBlockInstructions(b.current_flow_block->As<ir::Block>());
|
d.EmitBlockInstructions(b.current_flow_block->As<ir::Block>());
|
||||||
EXPECT_EQ(d.AsString(), R"(%1(u32) = call my_func
|
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);
|
Disassembler d(b.builder.ir);
|
||||||
d.EmitBlockInstructions(b.current_flow_block->As<ir::Block>());
|
d.EmitBlockInstructions(b.current_flow_block->As<ir::Block>());
|
||||||
EXPECT_EQ(d.AsString(), R"(%1(u32) = call my_func
|
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);
|
Disassembler d(b.builder.ir);
|
||||||
d.EmitBlockInstructions(b.current_flow_block->As<ir::Block>());
|
d.EmitBlockInstructions(b.current_flow_block->As<ir::Block>());
|
||||||
EXPECT_EQ(d.AsString(), R"(%1(u32) = call my_func
|
EXPECT_EQ(d.AsString(), R"(%1(u32) = call my_func
|
||||||
%2(u32) = bit_xor %1(u32), 4u
|
%2(u32) = xor %1(u32), 4u
|
||||||
)");
|
)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ utils::StringStream& Unary::ToInstruction(utils::StringStream& out) const {
|
||||||
out << "addr_of";
|
out << "addr_of";
|
||||||
break;
|
break;
|
||||||
case Unary::Kind::kComplement:
|
case Unary::Kind::kComplement:
|
||||||
out << "bit_complement";
|
out << "complement";
|
||||||
break;
|
break;
|
||||||
case Unary::Kind::kIndirection:
|
case Unary::Kind::kIndirection:
|
||||||
out << "indirection";
|
out << "indirection";
|
||||||
|
@ -43,7 +43,7 @@ utils::StringStream& Unary::ToInstruction(utils::StringStream& out) const {
|
||||||
out << "negation";
|
out << "negation";
|
||||||
break;
|
break;
|
||||||
case Unary::Kind::kNot:
|
case Unary::Kind::kNot:
|
||||||
out << "log_not";
|
out << "not";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
out << " ";
|
out << " ";
|
||||||
|
|
|
@ -63,7 +63,7 @@ TEST_F(IR_InstructionTest, CreateComplement) {
|
||||||
|
|
||||||
utils::StringStream str;
|
utils::StringStream str;
|
||||||
inst->ToInstruction(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) {
|
TEST_F(IR_InstructionTest, CreateIndirection) {
|
||||||
|
@ -119,7 +119,7 @@ TEST_F(IR_InstructionTest, CreateNot) {
|
||||||
|
|
||||||
utils::StringStream str;
|
utils::StringStream str;
|
||||||
inst->ToInstruction(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) {
|
TEST_F(IR_InstructionTest, Unary_Usage) {
|
||||||
|
|
Loading…
Reference in New Issue