tint: Use ProgramBuilder::Bitcast()

Change-Id: I3187027c8d24cfc0a18ed317a6586037346c97a3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/118986
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Ben Clayton 2023-02-08 01:11:27 +00:00 committed by Dawn LUCI CQ
parent 9e03212925
commit 35089ee437
11 changed files with 29 additions and 37 deletions

View File

@ -1844,7 +1844,7 @@ TEST_F(IR_BuilderImplTest, EmitExpression_Binary_Compound) {
}
TEST_F(IR_BuilderImplTest, EmitExpression_Bitcast) {
auto* expr = Bitcast(ty.f32(), 3_u);
auto* expr = Bitcast<f32>(3_u);
WrapInFunction(expr);
auto& b = CreateBuilder();

View File

@ -1104,8 +1104,7 @@ bool FunctionEmitter::EmitPipelineInput(std::string var_name,
if (is_builtin && (tip_type != forced_param_type)) {
// The parameter will have the WGSL type, but we need bitcast to
// the variable store type.
param_value =
create<ast::BitcastExpression>(tip_type->Build(builder_), param_value);
param_value = builder_.Bitcast(tip_type->Build(builder_), param_value);
}
statements->Push(builder_.Assign(store_dest, param_value));
@ -1240,8 +1239,7 @@ bool FunctionEmitter::EmitPipelineOutput(std::string var_name,
if (is_builtin && (tip_type != forced_member_type)) {
// The member will have the WGSL type, but we need bitcast to
// the variable store type.
load_source = create<ast::BitcastExpression>(forced_member_type->Build(builder_),
load_source);
load_source = builder_.Bitcast(forced_member_type->Build(builder_), load_source);
}
return_exprs->Push(load_source);
@ -3847,8 +3845,8 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue(
}
if (op == spv::Op::OpBitcast) {
return {ast_type, create<ast::BitcastExpression>(Source{}, ast_type->Build(builder_),
MakeOperand(inst, 0).expr)};
return {ast_type,
builder_.Bitcast(Source{}, ast_type->Build(builder_), MakeOperand(inst, 0).expr)};
}
if (op == spv::Op::OpShiftLeftLogical || op == spv::Op::OpShiftRightLogical ||
@ -5168,8 +5166,7 @@ TypedExpression FunctionEmitter::MakeNumericConversion(const spvtools::opt::Inst
return result;
}
return {requested_type,
create<ast::BitcastExpression>(GetSourceForInst(inst), requested_type->Build(builder_),
result.expr)};
builder_.Bitcast(GetSourceForInst(inst), requested_type->Build(builder_), result.expr)};
}
bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) {
@ -5661,8 +5658,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
if (expected_component_type != result_component_type) {
// This occurs if one is signed integer and the other is unsigned integer,
// or vice versa. Perform a bitcast.
value =
create<ast::BitcastExpression>(Source{}, result_type->Build(builder_), call_expr);
value = builder_.Bitcast(Source{}, result_type->Build(builder_), call_expr);
}
if (!expected_component_type->Is<F32>() && IsSampledImageAccess(op)) {
// WGSL permits sampled image access only on float textures.

View File

@ -2098,14 +2098,13 @@ TypedExpression ParserImpl::RectifyOperandSignedness(const spvtools::opt::Instru
if (requires_unsigned) {
if (auto* unsigned_ty = UnsignedTypeFor(type)) {
// Conversion is required.
return {unsigned_ty, create<ast::BitcastExpression>(
Source{}, unsigned_ty->Build(builder_), expr.expr)};
return {unsigned_ty,
builder_.Bitcast(Source{}, unsigned_ty->Build(builder_), expr.expr)};
}
} else if (requires_signed) {
if (auto* signed_ty = SignedTypeFor(type)) {
// Conversion is required.
return {signed_ty, create<ast::BitcastExpression>(Source{}, signed_ty->Build(builder_),
expr.expr)};
return {signed_ty, builder_.Bitcast(Source{}, signed_ty->Build(builder_), expr.expr)};
}
}
// We should not reach here.
@ -2119,8 +2118,8 @@ TypedExpression ParserImpl::RectifySecondOperandSignedness(const spvtools::opt::
if ((target_type != second_operand_expr.type->UnwrapRef()) &&
AssumesSecondOperandSignednessMatchesFirstOperand(opcode(inst))) {
// Conversion is required.
return {target_type, create<ast::BitcastExpression>(Source{}, target_type->Build(builder_),
second_operand_expr.expr)};
return {target_type,
builder_.Bitcast(Source{}, target_type->Build(builder_), second_operand_expr.expr)};
}
// No conversion necessary.
return std::move(second_operand_expr);
@ -2178,15 +2177,13 @@ TypedExpression ParserImpl::RectifyForcedResultType(TypedExpression expr,
if ((!forced_result_ty) || (forced_result_ty == expr.type)) {
return expr;
}
return {expr.type,
create<ast::BitcastExpression>(Source{}, expr.type->Build(builder_), expr.expr)};
return {expr.type, builder_.Bitcast(Source{}, expr.type->Build(builder_), expr.expr)};
}
TypedExpression ParserImpl::AsUnsigned(TypedExpression expr) {
if (expr.type && expr.type->IsSignedScalarOrVector()) {
auto* new_type = GetUnsignedIntMatchingShape(expr.type);
return {new_type,
create<ast::BitcastExpression>(Source{}, new_type->Build(builder_), expr.expr)};
return {new_type, builder_.Bitcast(Source{}, new_type->Build(builder_), expr.expr)};
}
return expr;
}
@ -2194,8 +2191,7 @@ TypedExpression ParserImpl::AsUnsigned(TypedExpression expr) {
TypedExpression ParserImpl::AsSigned(TypedExpression expr) {
if (expr.type && expr.type->IsUnsignedScalarOrVector()) {
auto* new_type = GetSignedIntMatchingShape(expr.type);
return {new_type,
create<ast::BitcastExpression>(Source{}, new_type->Build(builder_), expr.expr)};
return {new_type, builder_.Bitcast(Source{}, new_type->Build(builder_), expr.expr)};
}
return expr;
}

View File

@ -2609,7 +2609,7 @@ Maybe<const ast::Expression*> ParserImpl::primary_expression() {
return Failure::kErrored;
}
return create<ast::BitcastExpression>(t.source(), type.value, params.value);
return builder_.Bitcast(t.source(), type.value, params.value);
}
auto call = callable();

View File

@ -1812,7 +1812,7 @@ TEST_F(ResolverConstEvalTest, ShortCircuit_And_Error_Bitcast) {
GlobalConst("one", Expr(1_a));
GlobalConst("a", Expr(0x7F800000_a));
auto* lhs = Equal("one", 0_a);
auto* rhs = Equal(Source{{12, 34}}, Bitcast(ty.f32(), "a"), 0_i);
auto* rhs = Equal(Source{{12, 34}}, Bitcast<f32>("a"), 0_i);
auto* binary = LogicalAnd(lhs, rhs);
GlobalConst("result", binary);
@ -1862,7 +1862,7 @@ TEST_F(ResolverConstEvalTest, ShortCircuit_Or_Error_Bitcast) {
GlobalConst("one", Expr(1_a));
GlobalConst("a", Expr(0x7F800000_a));
auto* lhs = Equal("one", 1_a);
auto* rhs = Equal(Source{{12, 34}}, Bitcast(ty.f32(), "a"), 0_i);
auto* rhs = Equal(Source{{12, 34}}, Bitcast<f32>("a"), 0_i);
auto* binary = LogicalOr(lhs, rhs);
GlobalConst("result", binary);

View File

@ -581,7 +581,7 @@ TEST_F(ResolverTest, ArraySize_UnamedOverride_Equivalence) {
TEST_F(ResolverTest, Expr_Bitcast) {
GlobalVar("name", ty.f32(), type::AddressSpace::kPrivate);
auto* bitcast = create<ast::BitcastExpression>(ty.f32(), Expr("name"));
auto* bitcast = Bitcast<f32>(Expr("name"));
WrapInFunction(bitcast);
EXPECT_TRUE(r()->Resolve()) << r()->error();

View File

@ -23,7 +23,7 @@ using GlslGeneratorImplTest_Bitcast = TestHelper;
TEST_F(GlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Float) {
auto* a = Let("a", Expr(1_i));
auto* bitcast = create<ast::BitcastExpression>(ty.f32(), Expr("a"));
auto* bitcast = Bitcast<f32>(Expr("a"));
WrapInFunction(a, bitcast);
GeneratorImpl& gen = Build();
@ -35,7 +35,7 @@ TEST_F(GlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Float) {
TEST_F(GlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) {
auto* a = Let("a", Expr(1_u));
auto* bitcast = create<ast::BitcastExpression>(ty.i32(), Expr("a"));
auto* bitcast = Bitcast<i32>(Expr("a"));
WrapInFunction(a, bitcast);
GeneratorImpl& gen = Build();
@ -47,7 +47,7 @@ TEST_F(GlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) {
TEST_F(GlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Uint) {
auto* a = Let("a", Expr(1_i));
auto* bitcast = create<ast::BitcastExpression>(ty.u32(), Expr("a"));
auto* bitcast = Bitcast<u32>(Expr("a"));
WrapInFunction(a, bitcast);
GeneratorImpl& gen = Build();

View File

@ -23,7 +23,7 @@ using HlslGeneratorImplTest_Bitcast = TestHelper;
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Float) {
auto* a = Let("a", Expr(1_i));
auto* bitcast = create<ast::BitcastExpression>(ty.f32(), Expr("a"));
auto* bitcast = Bitcast<f32>(Expr("a"));
WrapInFunction(a, bitcast);
GeneratorImpl& gen = Build();
@ -35,7 +35,7 @@ TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Float) {
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) {
auto* a = Let("a", Expr(1_u));
auto* bitcast = create<ast::BitcastExpression>(ty.i32(), Expr("a"));
auto* bitcast = Bitcast<i32>(Expr("a"));
WrapInFunction(a, bitcast);
GeneratorImpl& gen = Build();
@ -47,7 +47,7 @@ TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) {
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Uint) {
auto* a = Let("a", Expr(1_i));
auto* bitcast = create<ast::BitcastExpression>(ty.u32(), Expr("a"));
auto* bitcast = Bitcast<u32>(Expr("a"));
WrapInFunction(a, bitcast);
GeneratorImpl& gen = Build();

View File

@ -23,7 +23,7 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, EmitExpression_Bitcast) {
auto* a = Let("a", Expr(1_i));
auto* bitcast = create<ast::BitcastExpression>(ty.f32(), Expr("a"));
auto* bitcast = Bitcast<f32>(Expr("a"));
WrapInFunction(a, bitcast);
GeneratorImpl& gen = Build();

View File

@ -23,7 +23,7 @@ namespace {
using BuilderTest = TestHelper;
TEST_F(BuilderTest, Bitcast) {
auto* bitcast = create<ast::BitcastExpression>(ty.u32(), Expr(2.4_f));
auto* bitcast = Bitcast<u32>(Expr(2.4_f));
WrapInFunction(bitcast);
@ -42,7 +42,7 @@ TEST_F(BuilderTest, Bitcast) {
}
TEST_F(BuilderTest, Bitcast_DuplicateType) {
auto* bitcast = create<ast::BitcastExpression>(ty.f32(), Expr(2.4_f));
auto* bitcast = Bitcast<f32>(Expr(2.4_f));
WrapInFunction(bitcast);

View File

@ -22,7 +22,7 @@ namespace {
using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, EmitExpression_Bitcast) {
auto* bitcast = create<ast::BitcastExpression>(ty.f32(), Expr(1_i));
auto* bitcast = Bitcast<f32>(Expr(1_i));
WrapInFunction(bitcast);
GeneratorImpl& gen = Build();