[ir] Remove type from Not builder. Remove the type parameter from the IR `Not` builder and infer from the value. Remove the `Unary` builder which takes a type as it is no longer necessary. Change-Id: Ib2fe3f959bd547e3de94c1bb2fc822fa5a8eaf2b Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/274395 Reviewed-by: James Price <jrprice@google.com> Commit-Queue: dan sinclair <dsinclair@chromium.org>
diff --git a/src/tint/lang/core/ir/binary/roundtrip_test.cc b/src/tint/lang/core/ir/binary/roundtrip_test.cc index 3c6f7e0..c771c93 100644 --- a/src/tint/lang/core/ir/binary/roundtrip_test.cc +++ b/src/tint/lang/core/ir/binary/roundtrip_test.cc
@@ -534,7 +534,7 @@ auto* x = b.FunctionParam<bool>("x"); auto* fn = b.Function("Function", ty.bool_()); fn->SetParams({x}); - b.Append(fn->Block(), [&] { b.Return(fn, b.Not<bool>(x)); }); + b.Append(fn->Block(), [&] { b.Return(fn, b.Not(x)); }); RUN_TEST(); } @@ -551,9 +551,8 @@ auto* x = b.FunctionParam<vec4<f32>>("x"); auto* fn = b.Function("Function", ty.vec3<f32>()); fn->SetParams({x}); - b.Append(fn->Block(), [&] { - b.Return(fn, b.Swizzle<vec3<f32>>(x, Vector<uint32_t, 3>{1, 0, 2})); - }); + b.Append(fn->Block(), + [&] { b.Return(fn, b.Swizzle<vec3<f32>>(x, Vector<uint32_t, 3>{1, 0, 2})); }); RUN_TEST(); }
diff --git a/src/tint/lang/core/ir/builder.h b/src/tint/lang/core/ir/builder.h index 8b710109..d59d744 100644 --- a/src/tint/lang/core/ir/builder.h +++ b/src/tint/lang/core/ir/builder.h
@@ -991,17 +991,6 @@ /// Creates an op for `op val` /// @param op the unary operator - /// @param type the result type of the binary expression - /// @param val the value of the operation - /// @returns the operation - template <typename VAL> - ir::CoreUnary* Unary(UnaryOp op, const core::type::Type* type, VAL&& val) { - auto* value = Value(std::forward<VAL>(val)); - return Append(ir.CreateInstruction<ir::CoreUnary>(InstructionResult(type), op, value)); - } - - /// Creates an op for `op val` - /// @param op the unary operator /// @param val the value of the operation /// @returns the operation template <typename VAL> @@ -1032,22 +1021,11 @@ } /// Creates a Not operation - /// @param type the result type of the expression /// @param val the value /// @returns the operation template <typename VAL> - ir::CoreUnary* Not(const core::type::Type* type, VAL&& val) { - return Unary(UnaryOp::kNot, type, std::forward<VAL>(val)); - } - - /// Creates a Not operation - /// @tparam TYPE the result type of the expression - /// @param val the value - /// @returns the operation - template <typename TYPE, typename VAL> ir::CoreUnary* Not(VAL&& val) { - auto* type = ir.Types().Get<TYPE>(); - return Not(type, std::forward<VAL>(val)); + return Unary(UnaryOp::kNot, std::forward<VAL>(val)); } /// Creates a bitcast instruction
diff --git a/src/tint/lang/core/ir/core_unary_test.cc b/src/tint/lang/core/ir/core_unary_test.cc index aadef60..59bb202 100644 --- a/src/tint/lang/core/ir/core_unary_test.cc +++ b/src/tint/lang/core/ir/core_unary_test.cc
@@ -65,7 +65,7 @@ } TEST_F(IR_UnaryTest, CreateNot) { - auto* inst = b.Not(mod.Types().bool_(), true); + auto* inst = b.Not(true); ASSERT_TRUE(inst->Is<Unary>()); EXPECT_EQ(inst->Op(), UnaryOp::kNot);
diff --git a/src/tint/lang/core/ir/transform/demote_to_helper.cc b/src/tint/lang/core/ir/transform/demote_to_helper.cc index a7c09d9..4b5f122 100644 --- a/src/tint/lang/core/ir/transform/demote_to_helper.cc +++ b/src/tint/lang/core/ir/transform/demote_to_helper.cc
@@ -192,7 +192,7 @@ if (ret->Func()->IsFragment()) { b.InsertBefore(ret, [&] { auto* cond = b.Load(continue_execution); - auto* ifelse = b.If(b.Not<bool>(cond)); + auto* ifelse = b.If(b.Not(cond)); b.Append(ifelse->True(), [&] { // b.TerminateInvocation(); });
diff --git a/src/tint/lang/glsl/writer/unary_test.cc b/src/tint/lang/glsl/writer/unary_test.cc index 7a2ded0..fd85b5a 100644 --- a/src/tint/lang/glsl/writer/unary_test.cc +++ b/src/tint/lang/glsl/writer/unary_test.cc
@@ -58,7 +58,7 @@ auto* func = b.ComputeFunction("main"); b.Append(func->Block(), [&] { auto* l = b.Let("left", b.Constant(false)); - auto* op = b.Not(ty.bool_(), l); + auto* op = b.Not(l); b.Let("val", op); b.Return(func); }); @@ -77,7 +77,7 @@ auto* func = b.ComputeFunction("main"); b.Append(func->Block(), [&] { auto* l = b.Let("left", b.Splat(ty.vec3<bool>(), false)); - auto* op = b.Not(ty.vec3<bool>(), l); + auto* op = b.Not(l); b.Let("val", op); b.Return(func); });
diff --git a/src/tint/lang/hlsl/writer/unary_test.cc b/src/tint/lang/hlsl/writer/unary_test.cc index cd692e6..31bb575 100644 --- a/src/tint/lang/hlsl/writer/unary_test.cc +++ b/src/tint/lang/hlsl/writer/unary_test.cc
@@ -58,7 +58,7 @@ auto* func = b.ComputeFunction("main"); b.Append(func->Block(), [&] { auto* a = b.Var("a", b.Zero<bool>()); - b.Var("b", b.Not<bool>(b.Load(a))); + b.Var("b", b.Not(b.Load(a))); b.Return(func); });
diff --git a/src/tint/lang/spirv/reader/parser/parser.cc b/src/tint/lang/spirv/reader/parser/parser.cc index baff4be..e2ced54 100644 --- a/src/tint/lang/spirv/reader/parser/parser.cc +++ b/src/tint/lang/spirv/reader/parser/parser.cc
@@ -3540,7 +3540,7 @@ return true; } if (false_id == merge_id && true_is_header) { - auto* val = b_.Not(cond->Type(), cond); + auto* val = b_.Not(cond); EmitWithoutSpvResult(val); EmitWithoutResult(b_.BreakIf(loop, val)); return true; @@ -4168,7 +4168,7 @@ core::UnaryOp op, uint32_t first_operand_idx = 2) { auto* val = Value(inst.GetSingleWordOperand(first_operand_idx)); - auto* unary = b_.Unary(op, Type(inst.type_id()), val); + auto* unary = b_.Unary(op, val); Emit(unary, inst.result_id()); } @@ -4192,7 +4192,7 @@ auto* binary = b_.Binary(op, Type(inst.type_id()), lhs, rhs); EmitWithoutSpvResult(binary); - auto* res = b_.Not(Type(inst.type_id()), binary); + auto* res = b_.Not(binary); Emit(res, inst.result_id()); }
diff --git a/src/tint/lang/spirv/writer/loop_test.cc b/src/tint/lang/spirv/writer/loop_test.cc index cbce8cf..74ef722 100644 --- a/src/tint/lang/spirv/writer/loop_test.cc +++ b/src/tint/lang/spirv/writer/loop_test.cc
@@ -704,7 +704,7 @@ loop->Continuing()->SetParams({cont_param_a, cont_param_b}); b.Append(loop->Continuing(), [&] { auto* cmp = b.GreaterThan(ty.bool_(), cont_param_a, 5_i); - auto* not_b = b.Not(ty.bool_(), cont_param_b); + auto* not_b = b.Not(cont_param_b); b.BreakIf(loop, cmp, b.Values(cont_param_a, not_b), Empty); });
diff --git a/src/tint/lang/spirv/writer/raise/merge_return.cc b/src/tint/lang/spirv/writer/raise/merge_return.cc index 7058558..d9d7d0c 100644 --- a/src/tint/lang/spirv/writer/raise/merge_return.cc +++ b/src/tint/lang/spirv/writer/raise/merge_return.cc
@@ -181,7 +181,7 @@ if (exit_target->IsAnyOf<core::ir::Loop, core::ir::Switch>()) { b.InsertBefore(next, [&] { auto* load = b.Load(continue_execution); - auto* cond = b.If(b.Not<bool>(load)); + auto* cond = b.If(b.Not(load)); b.Append(cond->True(), [&] { // ExitFromControl(exit_target); });
diff --git a/src/tint/lang/spirv/writer/unary_test.cc b/src/tint/lang/spirv/writer/unary_test.cc index 91ad1d1..f44280a 100644 --- a/src/tint/lang/spirv/writer/unary_test.cc +++ b/src/tint/lang/spirv/writer/unary_test.cc
@@ -55,7 +55,7 @@ auto* func = b.Function("foo", ty.void_()); func->SetParams({arg}); b.Append(func->Block(), [&] { - auto* result = b.Unary(params.op, MakeScalarType(params.type), arg); + auto* result = b.Unary(params.op, arg); mod.SetName(result, "result"); b.Return(func); }); @@ -77,7 +77,7 @@ auto* func = b.Function("foo", ty.void_()); func->SetParams({arg}); b.Append(func->Block(), [&] { - auto* result = b.Unary(params.op, MakeVectorType(params.type), arg); + auto* result = b.Unary(params.op, arg); mod.SetName(result, "result"); b.Return(func); }); @@ -104,7 +104,7 @@ auto* func = b.Function("foo", ty.void_()); func->SetParams({arg}); b.Append(func->Block(), [&] { - auto* result = b.Unary(core::UnaryOp::kNegation, MakeVectorType(kI32), arg); + auto* result = b.Unary(core::UnaryOp::kNegation, arg); b.Return(func); mod.SetName(result, "result"); }); @@ -153,7 +153,7 @@ auto* func = b.Function("foo", ty.void_()); func->SetParams({arg}); b.Append(func->Block(), [&] { - auto* result = b.Unary(core::UnaryOp::kNegation, MakeScalarType(kI32), arg); + auto* result = b.Unary(core::UnaryOp::kNegation, arg); b.Return(func); mod.SetName(result, "result"); });
diff --git a/src/tint/lang/wgsl/reader/program_to_ir/program_to_ir.cc b/src/tint/lang/wgsl/reader/program_to_ir/program_to_ir.cc index 92e089a..9583c45 100644 --- a/src/tint/lang/wgsl/reader/program_to_ir/program_to_ir.cc +++ b/src/tint/lang/wgsl/reader/program_to_ir/program_to_ir.cc
@@ -937,7 +937,6 @@ return; } core::ir::Instruction* inst = nullptr; - auto* sem = impl.program_.Sem().Get(expr); switch (expr->op) { case core::UnaryOp::kAddressOf: case core::UnaryOp::kIndirection: @@ -954,8 +953,7 @@ break; } case core::UnaryOp::kNot: { - auto* ty = sem->Type()->Clone(impl.clone_ctx_.type_ctx); - inst = impl.builder_.Not(ty, val); + inst = impl.builder_.Not(val); break; } }
diff --git a/src/tint/lang/wgsl/writer/ir_to_program/ir_to_program_test.cc b/src/tint/lang/wgsl/writer/ir_to_program/ir_to_program_test.cc index 5a0f9f9..e6c202a 100644 --- a/src/tint/lang/wgsl/writer/ir_to_program/ir_to_program_test.cc +++ b/src/tint/lang/wgsl/writer/ir_to_program/ir_to_program_test.cc
@@ -1051,7 +1051,7 @@ auto* i = b.FunctionParam("b", ty.bool_()); fn->SetParams({i}); - b.Append(fn->Block(), [&] { b.Return(fn, b.Not(ty.bool_(), i)); }); + b.Append(fn->Block(), [&] { b.Return(fn, b.Not(i)); }); EXPECT_WGSL(R"( fn f(b : bool) -> bool { @@ -3483,7 +3483,7 @@ auto* lhs = b.Override("cond", true); lhs->SetOverrideId(OverrideId{10}); - o = b.Override("o", b.Not<bool>(lhs)); + o = b.Override("o", b.Not(lhs)); }); auto* fn = b.Function("f", ty.bool_());