diff --git a/src/tint/ir/binary_test.cc b/src/tint/ir/binary_test.cc index dc359781c3..2435936f15 100644 --- a/src/tint/ir/binary_test.cc +++ b/src/tint/ir/binary_test.cc @@ -27,7 +27,7 @@ TEST_F(IR_InstructionTest, CreateAnd) { Module mod; Builder b{mod}; - const auto* inst = b.And(b.ir.types.Get(), b.Constant(4_i), b.Constant(2_i)); + const auto* inst = b.And(b.ir.types.i32(), b.Constant(4_i), b.Constant(2_i)); ASSERT_TRUE(inst->Is()); EXPECT_EQ(inst->Kind(), Binary::Kind::kAnd); @@ -48,7 +48,7 @@ TEST_F(IR_InstructionTest, CreateOr) { Module mod; Builder b{mod}; - const auto* inst = b.Or(b.ir.types.Get(), b.Constant(4_i), b.Constant(2_i)); + const auto* inst = b.Or(b.ir.types.i32(), b.Constant(4_i), b.Constant(2_i)); ASSERT_TRUE(inst->Is()); EXPECT_EQ(inst->Kind(), Binary::Kind::kOr); @@ -68,7 +68,7 @@ TEST_F(IR_InstructionTest, CreateXor) { Module mod; Builder b{mod}; - const auto* inst = b.Xor(b.ir.types.Get(), b.Constant(4_i), b.Constant(2_i)); + const auto* inst = b.Xor(b.ir.types.i32(), b.Constant(4_i), b.Constant(2_i)); ASSERT_TRUE(inst->Is()); EXPECT_EQ(inst->Kind(), Binary::Kind::kXor); @@ -88,7 +88,7 @@ TEST_F(IR_InstructionTest, CreateEqual) { Module mod; Builder b{mod}; - const auto* inst = b.Equal(b.ir.types.Get(), b.Constant(4_i), b.Constant(2_i)); + const auto* inst = b.Equal(b.ir.types.bool_(), b.Constant(4_i), b.Constant(2_i)); ASSERT_TRUE(inst->Is()); EXPECT_EQ(inst->Kind(), Binary::Kind::kEqual); @@ -108,7 +108,7 @@ TEST_F(IR_InstructionTest, CreateNotEqual) { Module mod; Builder b{mod}; - const auto* inst = b.NotEqual(b.ir.types.Get(), b.Constant(4_i), b.Constant(2_i)); + const auto* inst = b.NotEqual(b.ir.types.bool_(), b.Constant(4_i), b.Constant(2_i)); ASSERT_TRUE(inst->Is()); EXPECT_EQ(inst->Kind(), Binary::Kind::kNotEqual); @@ -128,7 +128,7 @@ TEST_F(IR_InstructionTest, CreateLessThan) { Module mod; Builder b{mod}; - const auto* inst = b.LessThan(b.ir.types.Get(), b.Constant(4_i), b.Constant(2_i)); + const auto* inst = b.LessThan(b.ir.types.bool_(), b.Constant(4_i), b.Constant(2_i)); ASSERT_TRUE(inst->Is()); EXPECT_EQ(inst->Kind(), Binary::Kind::kLessThan); @@ -148,8 +148,7 @@ TEST_F(IR_InstructionTest, CreateGreaterThan) { Module mod; Builder b{mod}; - const auto* inst = - b.GreaterThan(b.ir.types.Get(), b.Constant(4_i), b.Constant(2_i)); + const auto* inst = b.GreaterThan(b.ir.types.bool_(), b.Constant(4_i), b.Constant(2_i)); ASSERT_TRUE(inst->Is()); EXPECT_EQ(inst->Kind(), Binary::Kind::kGreaterThan); @@ -169,8 +168,7 @@ TEST_F(IR_InstructionTest, CreateLessThanEqual) { Module mod; Builder b{mod}; - const auto* inst = - b.LessThanEqual(b.ir.types.Get(), b.Constant(4_i), b.Constant(2_i)); + const auto* inst = b.LessThanEqual(b.ir.types.bool_(), b.Constant(4_i), b.Constant(2_i)); ASSERT_TRUE(inst->Is()); EXPECT_EQ(inst->Kind(), Binary::Kind::kLessThanEqual); @@ -190,8 +188,7 @@ TEST_F(IR_InstructionTest, CreateGreaterThanEqual) { Module mod; Builder b{mod}; - const auto* inst = - b.GreaterThanEqual(b.ir.types.Get(), b.Constant(4_i), b.Constant(2_i)); + const auto* inst = b.GreaterThanEqual(b.ir.types.bool_(), b.Constant(4_i), b.Constant(2_i)); ASSERT_TRUE(inst->Is()); EXPECT_EQ(inst->Kind(), Binary::Kind::kGreaterThanEqual); @@ -210,7 +207,7 @@ TEST_F(IR_InstructionTest, CreateGreaterThanEqual) { TEST_F(IR_InstructionTest, CreateNot) { Module mod; Builder b{mod}; - const auto* inst = b.Not(b.ir.types.Get(), b.Constant(true)); + const auto* inst = b.Not(b.ir.types.bool_(), b.Constant(true)); ASSERT_TRUE(inst->Is()); EXPECT_EQ(inst->Kind(), Binary::Kind::kEqual); @@ -230,7 +227,7 @@ TEST_F(IR_InstructionTest, CreateShiftLeft) { Module mod; Builder b{mod}; - const auto* inst = b.ShiftLeft(b.ir.types.Get(), b.Constant(4_i), b.Constant(2_i)); + const auto* inst = b.ShiftLeft(b.ir.types.i32(), b.Constant(4_i), b.Constant(2_i)); ASSERT_TRUE(inst->Is()); EXPECT_EQ(inst->Kind(), Binary::Kind::kShiftLeft); @@ -250,7 +247,7 @@ TEST_F(IR_InstructionTest, CreateShiftRight) { Module mod; Builder b{mod}; - const auto* inst = b.ShiftRight(b.ir.types.Get(), b.Constant(4_i), b.Constant(2_i)); + const auto* inst = b.ShiftRight(b.ir.types.i32(), b.Constant(4_i), b.Constant(2_i)); ASSERT_TRUE(inst->Is()); EXPECT_EQ(inst->Kind(), Binary::Kind::kShiftRight); @@ -270,7 +267,7 @@ TEST_F(IR_InstructionTest, CreateAdd) { Module mod; Builder b{mod}; - const auto* inst = b.Add(b.ir.types.Get(), b.Constant(4_i), b.Constant(2_i)); + const auto* inst = b.Add(b.ir.types.i32(), b.Constant(4_i), b.Constant(2_i)); ASSERT_TRUE(inst->Is()); EXPECT_EQ(inst->Kind(), Binary::Kind::kAdd); @@ -290,7 +287,7 @@ TEST_F(IR_InstructionTest, CreateSubtract) { Module mod; Builder b{mod}; - const auto* inst = b.Subtract(b.ir.types.Get(), b.Constant(4_i), b.Constant(2_i)); + const auto* inst = b.Subtract(b.ir.types.i32(), b.Constant(4_i), b.Constant(2_i)); ASSERT_TRUE(inst->Is()); EXPECT_EQ(inst->Kind(), Binary::Kind::kSubtract); @@ -310,7 +307,7 @@ TEST_F(IR_InstructionTest, CreateMultiply) { Module mod; Builder b{mod}; - const auto* inst = b.Multiply(b.ir.types.Get(), b.Constant(4_i), b.Constant(2_i)); + const auto* inst = b.Multiply(b.ir.types.i32(), b.Constant(4_i), b.Constant(2_i)); ASSERT_TRUE(inst->Is()); EXPECT_EQ(inst->Kind(), Binary::Kind::kMultiply); @@ -330,7 +327,7 @@ TEST_F(IR_InstructionTest, CreateDivide) { Module mod; Builder b{mod}; - const auto* inst = b.Divide(b.ir.types.Get(), b.Constant(4_i), b.Constant(2_i)); + const auto* inst = b.Divide(b.ir.types.i32(), b.Constant(4_i), b.Constant(2_i)); ASSERT_TRUE(inst->Is()); EXPECT_EQ(inst->Kind(), Binary::Kind::kDivide); @@ -350,7 +347,7 @@ TEST_F(IR_InstructionTest, CreateModulo) { Module mod; Builder b{mod}; - const auto* inst = b.Modulo(b.ir.types.Get(), b.Constant(4_i), b.Constant(2_i)); + const auto* inst = b.Modulo(b.ir.types.i32(), b.Constant(4_i), b.Constant(2_i)); ASSERT_TRUE(inst->Is()); EXPECT_EQ(inst->Kind(), Binary::Kind::kModulo); @@ -369,7 +366,7 @@ TEST_F(IR_InstructionTest, CreateModulo) { TEST_F(IR_InstructionTest, Binary_Usage) { Module mod; Builder b{mod}; - const auto* inst = b.And(b.ir.types.Get(), b.Constant(4_i), b.Constant(2_i)); + const auto* inst = b.And(b.ir.types.i32(), b.Constant(4_i), b.Constant(2_i)); EXPECT_EQ(inst->Kind(), Binary::Kind::kAnd); @@ -386,7 +383,7 @@ TEST_F(IR_InstructionTest, Binary_Usage_DuplicateValue) { Module mod; Builder b{mod}; auto val = b.Constant(4_i); - const auto* inst = b.And(b.ir.types.Get(), val, val); + const auto* inst = b.And(b.ir.types.i32(), val, val); EXPECT_EQ(inst->Kind(), Binary::Kind::kAnd); ASSERT_EQ(inst->LHS(), inst->RHS()); diff --git a/src/tint/ir/bitcast_test.cc b/src/tint/ir/bitcast_test.cc index 6eda56216c..157769c039 100644 --- a/src/tint/ir/bitcast_test.cc +++ b/src/tint/ir/bitcast_test.cc @@ -27,7 +27,7 @@ using IR_InstructionTest = TestHelper; TEST_F(IR_InstructionTest, Bitcast) { Module mod; Builder b{mod}; - const auto* inst = b.Bitcast(b.ir.types.Get(), b.Constant(4_i)); + const auto* inst = b.Bitcast(b.ir.types.i32(), b.Constant(4_i)); ASSERT_TRUE(inst->Is()); ASSERT_NE(inst->Type(), nullptr); @@ -43,7 +43,7 @@ TEST_F(IR_InstructionTest, Bitcast) { TEST_F(IR_InstructionTest, Bitcast_Usage) { Module mod; Builder b{mod}; - const auto* inst = b.Bitcast(b.ir.types.Get(), b.Constant(4_i)); + const auto* inst = b.Bitcast(b.ir.types.i32(), b.Constant(4_i)); const auto args = inst->Args(); ASSERT_EQ(args.Length(), 1u); diff --git a/src/tint/ir/builder.cc b/src/tint/ir/builder.cc index 205754b482..92999324c7 100644 --- a/src/tint/ir/builder.cc +++ b/src/tint/ir/builder.cc @@ -46,14 +46,14 @@ FunctionTerminator* Builder::CreateFunctionTerminator() { } Function* Builder::CreateFunction(std::string_view name, - type::Type* return_type, + const type::Type* return_type, Function::PipelineStage stage, std::optional> wg_size) { return CreateFunction(ir.symbols.Register(name), return_type, stage, wg_size); } Function* Builder::CreateFunction(Symbol name, - type::Type* return_type, + const type::Type* return_type, Function::PipelineStage stage, std::optional> wg_size) { TINT_ASSERT(IR, return_type); diff --git a/src/tint/ir/builder.h b/src/tint/ir/builder.h index 78bcb9b4a9..9e74c3d942 100644 --- a/src/tint/ir/builder.h +++ b/src/tint/ir/builder.h @@ -76,7 +76,7 @@ class Builder { /// @param wg_size the workgroup_size /// @returns the flow node Function* CreateFunction(std::string_view name, - type::Type* return_type, + const type::Type* return_type, Function::PipelineStage stage = Function::PipelineStage::kUndefined, std::optional> wg_size = {}); @@ -87,7 +87,7 @@ class Builder { /// @param wg_size the workgroup_size /// @returns the flow node Function* CreateFunction(Symbol name, - type::Type* return_type, + const type::Type* return_type, Function::PipelineStage stage = Function::PipelineStage::kUndefined, std::optional> wg_size = {}); @@ -124,35 +124,35 @@ class Builder { /// @returns the constant value const constant::Value* Bool(bool v) { // TODO(dsinclair): Replace when constant::Value is uniqed by the arena. - return Constant(create>(ir.types.Get(), v))->Value(); + return Constant(create>(ir.types.bool_(), v))->Value(); } /// @param v the value /// @returns the constant value const constant::Value* U32(uint32_t v) { // TODO(dsinclair): Replace when constant::Value is uniqed by the arena. - return Constant(create>(ir.types.Get(), u32(v)))->Value(); + return Constant(create>(ir.types.u32(), u32(v)))->Value(); } /// @param v the value /// @returns the constant value const constant::Value* I32(int32_t v) { // TODO(dsinclair): Replace when constant::Value is uniqed by the arena. - return Constant(create>(ir.types.Get(), i32(v)))->Value(); + return Constant(create>(ir.types.i32(), i32(v)))->Value(); } /// @param v the value /// @returns the constant value const constant::Value* F16(float v) { // TODO(dsinclair): Replace when constant::Value is uniqed by the arena. - return Constant(create>(ir.types.Get(), f16(v)))->Value(); + return Constant(create>(ir.types.f16(), f16(v)))->Value(); } /// @param v the value /// @returns the constant value const constant::Value* F32(float v) { // TODO(dsinclair): Replace when constant::Value is uniqed by the arena. - return Constant(create>(ir.types.Get(), f32(v)))->Value(); + return Constant(create>(ir.types.f32(), f32(v)))->Value(); } /// Creates a new ir::Constant @@ -166,35 +166,35 @@ class Builder { /// @param v the value /// @returns the new constant ir::Constant* Constant(i32 v) { - return Constant(create>(ir.types.Get(), v)); + return Constant(create>(ir.types.i32(), v)); } /// Creates a ir::Constant for a u32 Scalar /// @param v the value /// @returns the new constant ir::Constant* Constant(u32 v) { - return Constant(create>(ir.types.Get(), v)); + return Constant(create>(ir.types.u32(), v)); } /// Creates a ir::Constant for a f32 Scalar /// @param v the value /// @returns the new constant ir::Constant* Constant(f32 v) { - return Constant(create>(ir.types.Get(), v)); + return Constant(create>(ir.types.f32(), v)); } /// Creates a ir::Constant for a f16 Scalar /// @param v the value /// @returns the new constant ir::Constant* Constant(f16 v) { - return Constant(create>(ir.types.Get(), v)); + return Constant(create>(ir.types.f16(), v)); } /// Creates a ir::Constant for a bool Scalar /// @param v the value /// @returns the new constant ir::Constant* Constant(bool v) { - return Constant(create>(ir.types.Get(), v)); + return Constant(create>(ir.types.bool_(), v)); } /// Creates an op for `lhs kind rhs` diff --git a/src/tint/ir/from_program.cc b/src/tint/ir/from_program.cc index 212efea613..52e6b5a0d2 100644 --- a/src/tint/ir/from_program.cc +++ b/src/tint/ir/from_program.cc @@ -964,7 +964,7 @@ class Impl { auto* if_inst = builder_.CreateIf(lhs.Get()); current_flow_block_->Instructions().Push(if_inst); - auto* result = builder_.BlockParam(builder_.ir.types.Get()); + auto* result = builder_.BlockParam(builder_.ir.types.bool_()); if_inst->Merge()->SetParams(utils::Vector{result}); utils::Result rhs; diff --git a/src/tint/ir/function.cc b/src/tint/ir/function.cc index d6cd6fc17c..d60376f6bc 100644 --- a/src/tint/ir/function.cc +++ b/src/tint/ir/function.cc @@ -19,7 +19,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ir::Function); namespace tint::ir { Function::Function(Symbol name, - type::Type* rt, + const type::Type* rt, PipelineStage stage, std::optional> wg_size) : Base(), name_(name), return_type_(rt), pipeline_stage_(stage), workgroup_size_(wg_size) {} diff --git a/src/tint/ir/function.h b/src/tint/ir/function.h index e966e14c82..4dd222ccdc 100644 --- a/src/tint/ir/function.h +++ b/src/tint/ir/function.h @@ -69,7 +69,7 @@ class Function : public utils::Castable { /// @param stage the function stage /// @param wg_size the workgroup_size Function(Symbol n, - type::Type* rt, + const type::Type* rt, PipelineStage stage = PipelineStage::kUndefined, std::optional> wg_size = {}); ~Function() override; diff --git a/src/tint/ir/load_test.cc b/src/tint/ir/load_test.cc index 9881e98a2c..e920a6ce1d 100644 --- a/src/tint/ir/load_test.cc +++ b/src/tint/ir/load_test.cc @@ -27,7 +27,7 @@ TEST_F(IR_InstructionTest, CreateLoad) { Module mod; Builder b{mod}; - auto* store_type = b.ir.types.Get(); + auto* store_type = b.ir.types.i32(); auto* var = b.Declare(b.ir.types.Get( store_type, builtin::AddressSpace::kFunction, builtin::Access::kReadWrite)); const auto* inst = b.Load(var); @@ -45,7 +45,7 @@ TEST_F(IR_InstructionTest, Load_Usage) { Module mod; Builder b{mod}; - auto* store_type = b.ir.types.Get(); + auto* store_type = b.ir.types.i32(); auto* var = b.Declare(b.ir.types.Get( store_type, builtin::AddressSpace::kFunction, builtin::Access::kReadWrite)); const auto* inst = b.Load(var); diff --git a/src/tint/ir/module_test.cc b/src/tint/ir/module_test.cc index 9cd36aec10..c9343d9e9a 100644 --- a/src/tint/ir/module_test.cc +++ b/src/tint/ir/module_test.cc @@ -25,20 +25,20 @@ using IR_ModuleTest = TestHelper; TEST_F(IR_ModuleTest, NameOfUnnamed) { Module mod; - auto* v = mod.values.Create(mod.types.Get()); + auto* v = mod.values.Create(mod.types.i32()); EXPECT_FALSE(mod.NameOf(v).IsValid()); } TEST_F(IR_ModuleTest, SetName) { Module mod; - auto* v = mod.values.Create(mod.types.Get()); + auto* v = mod.values.Create(mod.types.i32()); EXPECT_EQ(mod.SetName(v, "a").Name(), "a"); EXPECT_EQ(mod.NameOf(v).Name(), "a"); } TEST_F(IR_ModuleTest, SetNameRename) { Module mod; - auto* v = mod.values.Create(mod.types.Get()); + auto* v = mod.values.Create(mod.types.i32()); EXPECT_EQ(mod.SetName(v, "a").Name(), "a"); EXPECT_EQ(mod.SetName(v, "b").Name(), "b"); EXPECT_EQ(mod.NameOf(v).Name(), "b"); @@ -46,9 +46,9 @@ TEST_F(IR_ModuleTest, SetNameRename) { TEST_F(IR_ModuleTest, SetNameCollision) { Module mod; - auto* a = mod.values.Create(mod.types.Get()); - auto* b = mod.values.Create(mod.types.Get()); - auto* c = mod.values.Create(mod.types.Get()); + auto* a = mod.values.Create(mod.types.i32()); + auto* b = mod.values.Create(mod.types.i32()); + auto* c = mod.values.Create(mod.types.i32()); EXPECT_EQ(mod.SetName(a, "x").Name(), "x"); EXPECT_EQ(mod.SetName(b, "x_1").Name(), "x_1"); EXPECT_EQ(mod.SetName(c, "x").Name(), "x_2"); diff --git a/src/tint/ir/transform/add_empty_entry_point.cc b/src/tint/ir/transform/add_empty_entry_point.cc index f40c60e524..c69532698c 100644 --- a/src/tint/ir/transform/add_empty_entry_point.cc +++ b/src/tint/ir/transform/add_empty_entry_point.cc @@ -35,9 +35,8 @@ void AddEmptyEntryPoint::Run(ir::Module* ir, const DataMap&, DataMap&) const { } ir::Builder builder(*ir); - auto* ep = - builder.CreateFunction(ir->symbols.New("unused_entry_point"), ir->types.Get(), - Function::PipelineStage::kCompute, std::array{1u, 1u, 1u}); + auto* ep = builder.CreateFunction(ir->symbols.New("unused_entry_point"), ir->types.void_(), + Function::PipelineStage::kCompute, std::array{1u, 1u, 1u}); ep->StartTarget()->SetInstructions(utils::Vector{builder.Branch(ep->EndTarget())}); ir->functions.Push(ep); } diff --git a/src/tint/ir/transform/add_empty_entry_point_test.cc b/src/tint/ir/transform/add_empty_entry_point_test.cc index c86c09cd66..afef5a9fc1 100644 --- a/src/tint/ir/transform/add_empty_entry_point_test.cc +++ b/src/tint/ir/transform/add_empty_entry_point_test.cc @@ -39,8 +39,7 @@ TEST_F(IR_AddEmptyEntryPointTest, EmptyModule) { } TEST_F(IR_AddEmptyEntryPointTest, ExistingEntryPoint) { - auto* ep = - b.CreateFunction("main", mod.types.Get(), Function::PipelineStage::kFragment); + auto* ep = b.CreateFunction("main", mod.types.void_(), Function::PipelineStage::kFragment); ep->StartTarget()->SetInstructions(utils::Vector{b.Branch(ep->EndTarget())}); mod.functions.Push(ep); diff --git a/src/tint/ir/unary_test.cc b/src/tint/ir/unary_test.cc index bb0b4f2921..14de464851 100644 --- a/src/tint/ir/unary_test.cc +++ b/src/tint/ir/unary_test.cc @@ -26,7 +26,7 @@ using IR_InstructionTest = TestHelper; TEST_F(IR_InstructionTest, CreateComplement) { Module mod; Builder b{mod}; - auto* inst = b.Complement(b.ir.types.Get(), b.Constant(4_i)); + auto* inst = b.Complement(b.ir.types.i32(), b.Constant(4_i)); ASSERT_TRUE(inst->Is()); EXPECT_EQ(inst->Kind(), Unary::Kind::kComplement); @@ -40,7 +40,7 @@ TEST_F(IR_InstructionTest, CreateComplement) { TEST_F(IR_InstructionTest, CreateNegation) { Module mod; Builder b{mod}; - auto* inst = b.Negation(b.ir.types.Get(), b.Constant(4_i)); + auto* inst = b.Negation(b.ir.types.i32(), b.Constant(4_i)); ASSERT_TRUE(inst->Is()); EXPECT_EQ(inst->Kind(), Unary::Kind::kNegation); @@ -54,7 +54,7 @@ TEST_F(IR_InstructionTest, CreateNegation) { TEST_F(IR_InstructionTest, Unary_Usage) { Module mod; Builder b{mod}; - auto* inst = b.Negation(b.ir.types.Get(), b.Constant(4_i)); + auto* inst = b.Negation(b.ir.types.i32(), b.Constant(4_i)); EXPECT_EQ(inst->Kind(), Unary::Kind::kNegation); diff --git a/src/tint/type/manager.h b/src/tint/type/manager.h index 4eb48bb1dc..c2a82c61cd 100644 --- a/src/tint/type/manager.h +++ b/src/tint/type/manager.h @@ -17,8 +17,14 @@ #include +#include "src/tint/type/bool.h" +#include "src/tint/type/f16.h" +#include "src/tint/type/f32.h" +#include "src/tint/type/i32.h" #include "src/tint/type/type.h" +#include "src/tint/type/u32.h" #include "src/tint/type/vector.h" +#include "src/tint/type/void.h" #include "src/tint/utils/hash.h" #include "src/tint/utils/unique_allocator.h" @@ -85,22 +91,42 @@ class Manager final { return types_.Find(std::forward(args)...); } + /// @returns a void type + const type::Type* void_() { return Get(); } + + /// @returns a bool type + const type::Type* bool_() { return Get(); } + + /// @returns an i32 type + const type::Type* i32() { return Get(); } + + /// @returns a u32 type + const type::Type* u32() { return Get(); } + + /// @returns an f32 type + const type::Type* f32() { return Get(); } + + /// @returns an f16 type + const type::Type* f16() { return Get(); } + /// @param inner the inner type /// @param size the vector size /// @returns the vector type - type::Type* vec(type::Type* inner, uint32_t size) { return Get(inner, size); } + const type::Type* vec(const type::Type* inner, uint32_t size) { + return Get(inner, size); + } /// @param inner the inner type /// @returns the vector type - type::Type* vec2(type::Type* inner) { return vec(inner, 2); } + const type::Type* vec2(const type::Type* inner) { return vec(inner, 2); } /// @param inner the inner type /// @returns the vector type - type::Type* vec3(type::Type* inner) { return vec(inner, 3); } + const type::Type* vec3(const type::Type* inner) { return vec(inner, 3); } /// @param inner the inner type /// @returns the vector type - type::Type* vec4(type::Type* inner) { return vec(inner, 4); } + const type::Type* vec4(const type::Type* inner) { return vec(inner, 4); } /// @returns an iterator to the beginning of the types TypeIterator begin() const { return types_.begin(); } diff --git a/src/tint/writer/spirv/ir/generator_impl_ir_binary_test.cc b/src/tint/writer/spirv/ir/generator_impl_ir_binary_test.cc index 879223952d..fd1d41a135 100644 --- a/src/tint/writer/spirv/ir/generator_impl_ir_binary_test.cc +++ b/src/tint/writer/spirv/ir/generator_impl_ir_binary_test.cc @@ -20,10 +20,9 @@ namespace tint::writer::spirv { namespace { TEST_F(SpvGeneratorImplTest, Binary_Add_I32) { - auto* func = b.CreateFunction("foo", mod.types.Get()); - func->StartTarget()->SetInstructions( - utils::Vector{b.Add(mod.types.Get(), b.Constant(1_i), b.Constant(2_i)), - b.Branch(func->EndTarget())}); + auto* func = b.CreateFunction("foo", mod.types.void_()); + func->StartTarget()->SetInstructions(utils::Vector{ + b.Add(mod.types.i32(), b.Constant(1_i), b.Constant(2_i)), b.Branch(func->EndTarget())}); generator_.EmitFunction(func); EXPECT_EQ(DumpModule(generator_.Module()), R"(OpName %1 "foo" @@ -41,10 +40,9 @@ OpFunctionEnd } TEST_F(SpvGeneratorImplTest, Binary_Add_U32) { - auto* func = b.CreateFunction("foo", mod.types.Get()); - func->StartTarget()->SetInstructions( - utils::Vector{b.Add(mod.types.Get(), b.Constant(1_u), b.Constant(2_u)), - b.Branch(func->EndTarget())}); + auto* func = b.CreateFunction("foo", mod.types.void_()); + func->StartTarget()->SetInstructions(utils::Vector{ + b.Add(mod.types.u32(), b.Constant(1_u), b.Constant(2_u)), b.Branch(func->EndTarget())}); generator_.EmitFunction(func); EXPECT_EQ(DumpModule(generator_.Module()), R"(OpName %1 "foo" @@ -62,10 +60,9 @@ OpFunctionEnd } TEST_F(SpvGeneratorImplTest, Binary_Add_F32) { - auto* func = b.CreateFunction("foo", mod.types.Get()); - func->StartTarget()->SetInstructions( - utils::Vector{b.Add(mod.types.Get(), b.Constant(1_f), b.Constant(2_f)), - b.Branch(func->EndTarget())}); + auto* func = b.CreateFunction("foo", mod.types.void_()); + func->StartTarget()->SetInstructions(utils::Vector{ + b.Add(mod.types.f32(), b.Constant(1_f), b.Constant(2_f)), b.Branch(func->EndTarget())}); generator_.EmitFunction(func); EXPECT_EQ(DumpModule(generator_.Module()), R"(OpName %1 "foo" @@ -83,9 +80,9 @@ OpFunctionEnd } TEST_F(SpvGeneratorImplTest, Binary_Sub_I32) { - auto* func = b.CreateFunction("foo", mod.types.Get()); + auto* func = b.CreateFunction("foo", mod.types.void_()); func->StartTarget()->SetInstructions( - utils::Vector{b.Subtract(mod.types.Get(), b.Constant(1_i), b.Constant(2_i)), + utils::Vector{b.Subtract(mod.types.i32(), b.Constant(1_i), b.Constant(2_i)), b.Branch(func->EndTarget())}); generator_.EmitFunction(func); @@ -104,9 +101,9 @@ OpFunctionEnd } TEST_F(SpvGeneratorImplTest, Binary_Sub_U32) { - auto* func = b.CreateFunction("foo", mod.types.Get()); + auto* func = b.CreateFunction("foo", mod.types.void_()); func->StartTarget()->SetInstructions( - utils::Vector{b.Subtract(mod.types.Get(), b.Constant(1_u), b.Constant(2_u)), + utils::Vector{b.Subtract(mod.types.u32(), b.Constant(1_u), b.Constant(2_u)), b.Branch(func->EndTarget())}); generator_.EmitFunction(func); @@ -125,9 +122,9 @@ OpFunctionEnd } TEST_F(SpvGeneratorImplTest, Binary_Sub_F32) { - auto* func = b.CreateFunction("foo", mod.types.Get()); + auto* func = b.CreateFunction("foo", mod.types.void_()); func->StartTarget()->SetInstructions( - utils::Vector{b.Subtract(mod.types.Get(), b.Constant(1_f), b.Constant(2_f)), + utils::Vector{b.Subtract(mod.types.f32(), b.Constant(1_f), b.Constant(2_f)), b.Branch(func->EndTarget())}); generator_.EmitFunction(func); @@ -146,14 +143,14 @@ OpFunctionEnd } TEST_F(SpvGeneratorImplTest, Binary_Sub_Vec2i) { - auto* func = b.CreateFunction("foo", mod.types.Get()); - auto* lhs = b.create(mod.types.vec2(mod.types.Get()), + auto* func = b.CreateFunction("foo", mod.types.void_()); + auto* lhs = b.create(mod.types.vec2(mod.types.i32()), utils::Vector{b.I32(42), b.I32(-1)}, false, false); - auto* rhs = b.create(mod.types.vec2(mod.types.Get()), + auto* rhs = b.create(mod.types.vec2(mod.types.i32()), utils::Vector{b.I32(0), b.I32(-43)}, false, false); func->StartTarget()->SetInstructions( - utils::Vector{b.Subtract(mod.types.Get(mod.types.Get(), 2u), - b.Constant(lhs), b.Constant(rhs)), + utils::Vector{b.Subtract(mod.types.Get(mod.types.i32(), 2u), b.Constant(lhs), + b.Constant(rhs)), b.Branch(func->EndTarget())}); generator_.EmitFunction(func); @@ -177,16 +174,16 @@ OpFunctionEnd } TEST_F(SpvGeneratorImplTest, Binary_Sub_Vec4f) { - auto* func = b.CreateFunction("foo", mod.types.Get()); + auto* func = b.CreateFunction("foo", mod.types.void_()); auto* lhs = b.create( - mod.types.vec4(mod.types.Get()), - utils::Vector{b.F32(42), b.F32(-1), b.F32(0), b.F32(1.25)}, false, false); + mod.types.vec4(mod.types.f32()), utils::Vector{b.F32(42), b.F32(-1), b.F32(0), b.F32(1.25)}, + false, false); auto* rhs = b.create( - mod.types.vec4(mod.types.Get()), - utils::Vector{b.F32(0), b.F32(1.25), b.F32(-42), b.F32(1)}, false, false); + mod.types.vec4(mod.types.f32()), utils::Vector{b.F32(0), b.F32(1.25), b.F32(-42), b.F32(1)}, + false, false); func->StartTarget()->SetInstructions( - utils::Vector{b.Subtract(mod.types.Get(mod.types.Get(), 4u), - b.Constant(lhs), b.Constant(rhs)), + utils::Vector{b.Subtract(mod.types.Get(mod.types.f32(), 4u), b.Constant(lhs), + b.Constant(rhs)), b.Branch(func->EndTarget())}); generator_.EmitFunction(func); @@ -212,10 +209,10 @@ OpFunctionEnd } TEST_F(SpvGeneratorImplTest, Binary_Chain) { - auto* func = b.CreateFunction("foo", mod.types.Get()); - auto* a = b.Subtract(mod.types.Get(), b.Constant(1_i), b.Constant(2_i)); + auto* func = b.CreateFunction("foo", mod.types.void_()); + auto* a = b.Subtract(mod.types.i32(), b.Constant(1_i), b.Constant(2_i)); func->StartTarget()->SetInstructions( - utils::Vector{a, b.Add(mod.types.Get(), a, a), b.Branch(func->EndTarget())}); + utils::Vector{a, b.Add(mod.types.i32(), a, a), b.Branch(func->EndTarget())}); generator_.EmitFunction(func); EXPECT_EQ(DumpModule(generator_.Module()), R"(OpName %1 "foo" diff --git a/src/tint/writer/spirv/ir/generator_impl_ir_constant_test.cc b/src/tint/writer/spirv/ir/generator_impl_ir_constant_test.cc index 75775ff9a2..8c7778f2b9 100644 --- a/src/tint/writer/spirv/ir/generator_impl_ir_constant_test.cc +++ b/src/tint/writer/spirv/ir/generator_impl_ir_constant_test.cc @@ -64,7 +64,7 @@ TEST_F(SpvGeneratorImplTest, Constant_F16) { TEST_F(SpvGeneratorImplTest, Constant_Vec4Bool) { auto* v = b.create( - mod.types.vec4(mod.types.Get()), + mod.types.vec4(mod.types.bool_()), utils::Vector{b.Bool(true), b.Bool(false), b.Bool(false), b.Bool(true)}, false, true); generator_.Constant(b.Constant(v)); @@ -77,7 +77,7 @@ TEST_F(SpvGeneratorImplTest, Constant_Vec4Bool) { } TEST_F(SpvGeneratorImplTest, Constant_Vec2i) { - auto* v = b.create(mod.types.vec2(mod.types.Get()), + auto* v = b.create(mod.types.vec2(mod.types.i32()), utils::Vector{b.I32(42), b.I32(-1)}, false, false); generator_.Constant(b.Constant(v)); EXPECT_EQ(DumpTypes(), R"(%3 = OpTypeInt 32 1 @@ -89,7 +89,7 @@ TEST_F(SpvGeneratorImplTest, Constant_Vec2i) { } TEST_F(SpvGeneratorImplTest, Constant_Vec3u) { - auto* v = b.create(mod.types.vec3(mod.types.Get()), + auto* v = b.create(mod.types.vec3(mod.types.u32()), utils::Vector{b.U32(42), b.U32(0), b.U32(4000000000)}, false, true); generator_.Constant(b.Constant(v)); @@ -104,8 +104,8 @@ TEST_F(SpvGeneratorImplTest, Constant_Vec3u) { TEST_F(SpvGeneratorImplTest, Constant_Vec4f) { auto* v = b.create( - mod.types.vec4(mod.types.Get()), - utils::Vector{b.F32(42), b.F32(0), b.F32(0.25), b.F32(-1)}, false, true); + mod.types.vec4(mod.types.f32()), utils::Vector{b.F32(42), b.F32(0), b.F32(0.25), b.F32(-1)}, + false, true); generator_.Constant(b.Constant(v)); EXPECT_EQ(DumpTypes(), R"(%3 = OpTypeFloat 32 %2 = OpTypeVector %3 4 @@ -118,7 +118,7 @@ TEST_F(SpvGeneratorImplTest, Constant_Vec4f) { } TEST_F(SpvGeneratorImplTest, Constant_Vec2h) { - auto* v = b.create(mod.types.vec2(mod.types.Get()), + auto* v = b.create(mod.types.vec2(mod.types.f16()), utils::Vector{b.F16(42), b.F16(0.25)}, false, false); generator_.Constant(b.Constant(v)); EXPECT_EQ(DumpTypes(), R"(%3 = OpTypeFloat 16 diff --git a/src/tint/writer/spirv/ir/generator_impl_ir_function_test.cc b/src/tint/writer/spirv/ir/generator_impl_ir_function_test.cc index 722196312c..80f8c06204 100644 --- a/src/tint/writer/spirv/ir/generator_impl_ir_function_test.cc +++ b/src/tint/writer/spirv/ir/generator_impl_ir_function_test.cc @@ -18,7 +18,7 @@ namespace tint::writer::spirv { namespace { TEST_F(SpvGeneratorImplTest, Function_Empty) { - auto* func = b.CreateFunction("foo", mod.types.Get()); + auto* func = b.CreateFunction("foo", mod.types.void_()); func->StartTarget()->SetInstructions(utils::Vector{b.Branch(func->EndTarget())}); generator_.EmitFunction(func); @@ -34,7 +34,7 @@ OpFunctionEnd // Test that we do not emit the same function type more than once. TEST_F(SpvGeneratorImplTest, Function_DeduplicateType) { - auto* func = b.CreateFunction("foo", mod.types.Get()); + auto* func = b.CreateFunction("foo", mod.types.void_()); func->StartTarget()->SetInstructions(utils::Vector{b.Branch(func->EndTarget())}); generator_.EmitFunction(func); @@ -46,8 +46,8 @@ TEST_F(SpvGeneratorImplTest, Function_DeduplicateType) { } TEST_F(SpvGeneratorImplTest, Function_EntryPoint_Compute) { - auto* func = b.CreateFunction("main", mod.types.Get(), - ir::Function::PipelineStage::kCompute, {{32, 4, 1}}); + auto* func = b.CreateFunction("main", mod.types.void_(), ir::Function::PipelineStage::kCompute, + {{32, 4, 1}}); func->StartTarget()->SetInstructions(utils::Vector{b.Branch(func->EndTarget())}); generator_.EmitFunction(func); @@ -64,8 +64,8 @@ OpFunctionEnd } TEST_F(SpvGeneratorImplTest, Function_EntryPoint_Fragment) { - auto* func = b.CreateFunction("main", mod.types.Get(), - ir::Function::PipelineStage::kFragment); + auto* func = + b.CreateFunction("main", mod.types.void_(), ir::Function::PipelineStage::kFragment); func->StartTarget()->SetInstructions(utils::Vector{b.Branch(func->EndTarget())}); generator_.EmitFunction(func); @@ -82,8 +82,7 @@ OpFunctionEnd } TEST_F(SpvGeneratorImplTest, Function_EntryPoint_Vertex) { - auto* func = - b.CreateFunction("main", mod.types.Get(), ir::Function::PipelineStage::kVertex); + auto* func = b.CreateFunction("main", mod.types.void_(), ir::Function::PipelineStage::kVertex); func->StartTarget()->SetInstructions(utils::Vector{b.Branch(func->EndTarget())}); generator_.EmitFunction(func); @@ -99,16 +98,15 @@ OpFunctionEnd } TEST_F(SpvGeneratorImplTest, Function_EntryPoint_Multiple) { - auto* f1 = b.CreateFunction("main1", mod.types.Get(), - ir::Function::PipelineStage::kCompute, {{32, 4, 1}}); + auto* f1 = b.CreateFunction("main1", mod.types.void_(), ir::Function::PipelineStage::kCompute, + {{32, 4, 1}}); f1->StartTarget()->SetInstructions(utils::Vector{b.Branch(f1->EndTarget())}); - auto* f2 = b.CreateFunction("main2", mod.types.Get(), - ir::Function::PipelineStage::kCompute, {{8, 2, 16}}); + auto* f2 = b.CreateFunction("main2", mod.types.void_(), ir::Function::PipelineStage::kCompute, + {{8, 2, 16}}); f2->StartTarget()->SetInstructions(utils::Vector{b.Branch(f2->EndTarget())}); - auto* f3 = b.CreateFunction("main3", mod.types.Get(), - ir::Function::PipelineStage::kFragment); + auto* f3 = b.CreateFunction("main3", mod.types.void_(), ir::Function::PipelineStage::kFragment); f3->StartTarget()->SetInstructions(utils::Vector{b.Branch(f3->EndTarget())}); generator_.EmitFunction(f1); diff --git a/src/tint/writer/spirv/ir/generator_impl_ir_if_test.cc b/src/tint/writer/spirv/ir/generator_impl_ir_if_test.cc index dc312d1c38..4c18ec1013 100644 --- a/src/tint/writer/spirv/ir/generator_impl_ir_if_test.cc +++ b/src/tint/writer/spirv/ir/generator_impl_ir_if_test.cc @@ -20,7 +20,7 @@ namespace tint::writer::spirv { namespace { TEST_F(SpvGeneratorImplTest, If_TrueEmpty_FalseEmpty) { - auto* func = b.CreateFunction("foo", mod.types.Get()); + auto* func = b.CreateFunction("foo", mod.types.void_()); auto* i = b.CreateIf(b.Constant(true)); i->True()->SetInstructions(utils::Vector{b.Branch(i->Merge())}); @@ -46,7 +46,7 @@ OpFunctionEnd } TEST_F(SpvGeneratorImplTest, If_FalseEmpty) { - auto* func = b.CreateFunction("foo", mod.types.Get()); + auto* func = b.CreateFunction("foo", mod.types.void_()); auto* i = b.CreateIf(b.Constant(true)); i->False()->SetInstructions(utils::Vector{b.Branch(i->Merge())}); @@ -54,7 +54,7 @@ TEST_F(SpvGeneratorImplTest, If_FalseEmpty) { auto* true_block = i->True(); true_block->SetInstructions(utils::Vector{ - b.Add(mod.types.Get(), b.Constant(1_i), b.Constant(1_i)), b.Branch(i->Merge())}); + b.Add(mod.types.i32(), b.Constant(1_i), b.Constant(1_i)), b.Branch(i->Merge())}); func->StartTarget()->SetInstructions(utils::Vector{i}); @@ -80,7 +80,7 @@ OpFunctionEnd } TEST_F(SpvGeneratorImplTest, If_TrueEmpty) { - auto* func = b.CreateFunction("foo", mod.types.Get()); + auto* func = b.CreateFunction("foo", mod.types.void_()); auto* i = b.CreateIf(b.Constant(true)); i->True()->SetInstructions(utils::Vector{b.Branch(i->Merge())}); @@ -88,7 +88,7 @@ TEST_F(SpvGeneratorImplTest, If_TrueEmpty) { auto* false_block = i->False(); false_block->SetInstructions(utils::Vector{ - b.Add(mod.types.Get(), b.Constant(1_i), b.Constant(1_i)), b.Branch(i->Merge())}); + b.Add(mod.types.i32(), b.Constant(1_i), b.Constant(1_i)), b.Branch(i->Merge())}); func->StartTarget()->SetInstructions(utils::Vector{i}); @@ -114,7 +114,7 @@ OpFunctionEnd } TEST_F(SpvGeneratorImplTest, If_BothBranchesReturn) { - auto* func = b.CreateFunction("foo", mod.types.Get()); + auto* func = b.CreateFunction("foo", mod.types.void_()); auto* i = b.CreateIf(b.Constant(true)); i->True()->SetInstructions(utils::Vector{b.Branch(func->EndTarget())}); diff --git a/src/tint/writer/spirv/ir/generator_impl_ir_type_test.cc b/src/tint/writer/spirv/ir/generator_impl_ir_type_test.cc index 38bf1f0754..a8b6f5587c 100644 --- a/src/tint/writer/spirv/ir/generator_impl_ir_type_test.cc +++ b/src/tint/writer/spirv/ir/generator_impl_ir_type_test.cc @@ -25,43 +25,43 @@ namespace tint::writer::spirv { namespace { TEST_F(SpvGeneratorImplTest, Type_Void) { - auto id = generator_.Type(mod.types.Get()); + auto id = generator_.Type(mod.types.void_()); EXPECT_EQ(id, 1u); EXPECT_EQ(DumpTypes(), "%1 = OpTypeVoid\n"); } TEST_F(SpvGeneratorImplTest, Type_Bool) { - auto id = generator_.Type(mod.types.Get()); + auto id = generator_.Type(mod.types.bool_()); EXPECT_EQ(id, 1u); EXPECT_EQ(DumpTypes(), "%1 = OpTypeBool\n"); } TEST_F(SpvGeneratorImplTest, Type_I32) { - auto id = generator_.Type(mod.types.Get()); + auto id = generator_.Type(mod.types.i32()); EXPECT_EQ(id, 1u); EXPECT_EQ(DumpTypes(), "%1 = OpTypeInt 32 1\n"); } TEST_F(SpvGeneratorImplTest, Type_U32) { - auto id = generator_.Type(mod.types.Get()); + auto id = generator_.Type(mod.types.u32()); EXPECT_EQ(id, 1u); EXPECT_EQ(DumpTypes(), "%1 = OpTypeInt 32 0\n"); } TEST_F(SpvGeneratorImplTest, Type_F32) { - auto id = generator_.Type(mod.types.Get()); + auto id = generator_.Type(mod.types.f32()); EXPECT_EQ(id, 1u); EXPECT_EQ(DumpTypes(), "%1 = OpTypeFloat 32\n"); } TEST_F(SpvGeneratorImplTest, Type_F16) { - auto id = generator_.Type(mod.types.Get()); + auto id = generator_.Type(mod.types.f16()); EXPECT_EQ(id, 1u); EXPECT_EQ(DumpTypes(), "%1 = OpTypeFloat 16\n"); } TEST_F(SpvGeneratorImplTest, Type_Vec2i) { - auto* vec = b.ir.types.Get(b.ir.types.Get(), 2u); + auto* vec = b.ir.types.Get(b.ir.types.i32(), 2u); auto id = generator_.Type(vec); EXPECT_EQ(id, 1u); EXPECT_EQ(DumpTypes(), @@ -70,7 +70,7 @@ TEST_F(SpvGeneratorImplTest, Type_Vec2i) { } TEST_F(SpvGeneratorImplTest, Type_Vec3u) { - auto* vec = b.ir.types.Get(b.ir.types.Get(), 3u); + auto* vec = b.ir.types.Get(b.ir.types.u32(), 3u); auto id = generator_.Type(vec); EXPECT_EQ(id, 1u); EXPECT_EQ(DumpTypes(), @@ -79,7 +79,7 @@ TEST_F(SpvGeneratorImplTest, Type_Vec3u) { } TEST_F(SpvGeneratorImplTest, Type_Vec4f) { - auto* vec = b.ir.types.Get(b.ir.types.Get(), 4u); + auto* vec = b.ir.types.Get(b.ir.types.f32(), 4u); auto id = generator_.Type(vec); EXPECT_EQ(id, 1u); EXPECT_EQ(DumpTypes(), @@ -88,7 +88,7 @@ TEST_F(SpvGeneratorImplTest, Type_Vec4f) { } TEST_F(SpvGeneratorImplTest, Type_Vec4h) { - auto* vec = b.ir.types.Get(b.ir.types.Get(), 2u); + auto* vec = b.ir.types.Get(b.ir.types.f16(), 2u); auto id = generator_.Type(vec); EXPECT_EQ(id, 1u); EXPECT_EQ(DumpTypes(), @@ -97,7 +97,7 @@ TEST_F(SpvGeneratorImplTest, Type_Vec4h) { } TEST_F(SpvGeneratorImplTest, Type_Vec4Bool) { - auto* vec = b.ir.types.Get(b.ir.types.Get(), 4u); + auto* vec = b.ir.types.Get(b.ir.types.bool_(), 4u); auto id = generator_.Type(vec); EXPECT_EQ(id, 1u); EXPECT_EQ(DumpTypes(), @@ -108,10 +108,10 @@ TEST_F(SpvGeneratorImplTest, Type_Vec4Bool) { // Test that we can emit multiple types. // Includes types with the same opcode but different parameters. TEST_F(SpvGeneratorImplTest, Type_Multiple) { - EXPECT_EQ(generator_.Type(mod.types.Get()), 1u); - EXPECT_EQ(generator_.Type(mod.types.Get()), 2u); - EXPECT_EQ(generator_.Type(mod.types.Get()), 3u); - EXPECT_EQ(generator_.Type(mod.types.Get()), 4u); + EXPECT_EQ(generator_.Type(mod.types.i32()), 1u); + EXPECT_EQ(generator_.Type(mod.types.u32()), 2u); + EXPECT_EQ(generator_.Type(mod.types.f32()), 3u); + EXPECT_EQ(generator_.Type(mod.types.f16()), 4u); EXPECT_EQ(DumpTypes(), R"(%1 = OpTypeInt 32 1 %2 = OpTypeInt 32 0 %3 = OpTypeFloat 32 @@ -121,7 +121,7 @@ TEST_F(SpvGeneratorImplTest, Type_Multiple) { // Test that we do not emit the same type more than once. TEST_F(SpvGeneratorImplTest, Type_Deduplicate) { - auto* i32 = mod.types.Get(); + auto* i32 = mod.types.i32(); EXPECT_EQ(generator_.Type(i32), 1u); EXPECT_EQ(generator_.Type(i32), 1u); EXPECT_EQ(generator_.Type(i32), 1u); diff --git a/src/tint/writer/spirv/ir/generator_impl_ir_var_test.cc b/src/tint/writer/spirv/ir/generator_impl_ir_var_test.cc index 6c9fbc3757..814ef05295 100644 --- a/src/tint/writer/spirv/ir/generator_impl_ir_var_test.cc +++ b/src/tint/writer/spirv/ir/generator_impl_ir_var_test.cc @@ -21,10 +21,10 @@ namespace tint::writer::spirv { namespace { TEST_F(SpvGeneratorImplTest, FunctionVar_NoInit) { - auto* func = b.CreateFunction("foo", mod.types.Get()); + auto* func = b.CreateFunction("foo", mod.types.void_()); - auto* ty = mod.types.Get( - mod.types.Get(), builtin::AddressSpace::kFunction, builtin::Access::kReadWrite); + auto* ty = mod.types.Get(mod.types.i32(), builtin::AddressSpace::kFunction, + builtin::Access::kReadWrite); func->StartTarget()->SetInstructions(utils::Vector{b.Declare(ty), b.Branch(func->EndTarget())}); generator_.EmitFunction(func); @@ -42,10 +42,10 @@ OpFunctionEnd } TEST_F(SpvGeneratorImplTest, FunctionVar_WithInit) { - auto* func = b.CreateFunction("foo", mod.types.Get()); + auto* func = b.CreateFunction("foo", mod.types.void_()); - auto* ty = mod.types.Get( - mod.types.Get(), builtin::AddressSpace::kFunction, builtin::Access::kReadWrite); + auto* ty = mod.types.Get(mod.types.i32(), builtin::AddressSpace::kFunction, + builtin::Access::kReadWrite); auto* v = b.Declare(ty); v->SetInitializer(b.Constant(42_i)); @@ -68,10 +68,10 @@ OpFunctionEnd } TEST_F(SpvGeneratorImplTest, FunctionVar_Name) { - auto* func = b.CreateFunction("foo", mod.types.Get()); + auto* func = b.CreateFunction("foo", mod.types.void_()); - auto* ty = mod.types.Get( - mod.types.Get(), builtin::AddressSpace::kFunction, builtin::Access::kReadWrite); + auto* ty = mod.types.Get(mod.types.i32(), builtin::AddressSpace::kFunction, + builtin::Access::kReadWrite); auto* v = b.Declare(ty); func->StartTarget()->SetInstructions(utils::Vector{v, b.Branch(func->EndTarget())}); mod.SetName(v, "myvar"); @@ -92,10 +92,10 @@ OpFunctionEnd } TEST_F(SpvGeneratorImplTest, FunctionVar_DeclInsideBlock) { - auto* func = b.CreateFunction("foo", mod.types.Get()); + auto* func = b.CreateFunction("foo", mod.types.void_()); - auto* ty = mod.types.Get( - mod.types.Get(), builtin::AddressSpace::kFunction, builtin::Access::kReadWrite); + auto* ty = mod.types.Get(mod.types.i32(), builtin::AddressSpace::kFunction, + builtin::Access::kReadWrite); auto* v = b.Declare(ty); v->SetInitializer(b.Constant(42_i)); @@ -132,9 +132,9 @@ OpFunctionEnd } TEST_F(SpvGeneratorImplTest, FunctionVar_Load) { - auto* func = b.CreateFunction("foo", mod.types.Get()); + auto* func = b.CreateFunction("foo", mod.types.void_()); - auto* store_ty = mod.types.Get(); + auto* store_ty = mod.types.i32(); auto* ty = mod.types.Get(store_ty, builtin::AddressSpace::kFunction, builtin::Access::kReadWrite); auto* v = b.Declare(ty); @@ -156,10 +156,10 @@ OpFunctionEnd } TEST_F(SpvGeneratorImplTest, FunctionVar_Store) { - auto* func = b.CreateFunction("foo", mod.types.Get()); + auto* func = b.CreateFunction("foo", mod.types.void_()); - auto* ty = mod.types.Get( - mod.types.Get(), builtin::AddressSpace::kFunction, builtin::Access::kReadWrite); + auto* ty = mod.types.Get(mod.types.i32(), builtin::AddressSpace::kFunction, + builtin::Access::kReadWrite); auto* v = b.Declare(ty); func->StartTarget()->SetInstructions( utils::Vector{v, b.Store(v, b.Constant(42_i)), b.Branch(func->EndTarget())});