[ir] Add scalar type helpers to type::Manager

Creating scalar types is extremely common when using builders.

Bug: tint:1718
Change-Id: I2c2f0f521af1384bd8dee344ddfa525583535911
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132284
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
James Price 2023-05-24 11:53:06 +00:00 committed by Dawn LUCI CQ
parent 028726497a
commit 23c0451377
19 changed files with 169 additions and 153 deletions

View File

@ -27,7 +27,7 @@ TEST_F(IR_InstructionTest, CreateAnd) {
Module mod;
Builder b{mod};
const auto* inst = b.And(b.ir.types.Get<type::I32>(), 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<Binary>());
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<type::I32>(), 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<Binary>());
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<type::I32>(), 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<Binary>());
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<type::Bool>(), 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<Binary>());
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<type::Bool>(), 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<Binary>());
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<type::Bool>(), 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<Binary>());
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<type::Bool>(), 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<Binary>());
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<type::Bool>(), 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<Binary>());
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<type::Bool>(), 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<Binary>());
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<type::Bool>(), b.Constant(true));
const auto* inst = b.Not(b.ir.types.bool_(), b.Constant(true));
ASSERT_TRUE(inst->Is<Binary>());
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<type::I32>(), 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<Binary>());
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<type::I32>(), 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<Binary>());
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<type::I32>(), 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<Binary>());
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<type::I32>(), 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<Binary>());
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<type::I32>(), 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<Binary>());
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<type::I32>(), 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<Binary>());
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<type::I32>(), 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<Binary>());
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<type::I32>(), 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<type::I32>(), 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());

View File

@ -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<type::I32>(), b.Constant(4_i));
const auto* inst = b.Bitcast(b.ir.types.i32(), b.Constant(4_i));
ASSERT_TRUE(inst->Is<ir::Bitcast>());
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<type::I32>(), 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);

View File

@ -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<std::array<uint32_t, 3>> 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<std::array<uint32_t, 3>> wg_size) {
TINT_ASSERT(IR, return_type);

View File

@ -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<std::array<uint32_t, 3>> 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<std::array<uint32_t, 3>> 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<constant::Scalar<bool>>(ir.types.Get<type::Bool>(), v))->Value();
return Constant(create<constant::Scalar<bool>>(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<constant::Scalar<u32>>(ir.types.Get<type::U32>(), u32(v)))->Value();
return Constant(create<constant::Scalar<u32>>(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<constant::Scalar<i32>>(ir.types.Get<type::I32>(), i32(v)))->Value();
return Constant(create<constant::Scalar<i32>>(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<constant::Scalar<f16>>(ir.types.Get<type::F16>(), f16(v)))->Value();
return Constant(create<constant::Scalar<f16>>(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<constant::Scalar<f32>>(ir.types.Get<type::F32>(), f32(v)))->Value();
return Constant(create<constant::Scalar<f32>>(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<constant::Scalar<i32>>(ir.types.Get<type::I32>(), v));
return Constant(create<constant::Scalar<i32>>(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<constant::Scalar<u32>>(ir.types.Get<type::U32>(), v));
return Constant(create<constant::Scalar<u32>>(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<constant::Scalar<f32>>(ir.types.Get<type::F32>(), v));
return Constant(create<constant::Scalar<f32>>(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<constant::Scalar<f16>>(ir.types.Get<type::F16>(), v));
return Constant(create<constant::Scalar<f16>>(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<constant::Scalar<bool>>(ir.types.Get<type::Bool>(), v));
return Constant(create<constant::Scalar<bool>>(ir.types.bool_(), v));
}
/// Creates an op for `lhs kind rhs`

View File

@ -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<type::Bool>());
auto* result = builder_.BlockParam(builder_.ir.types.bool_());
if_inst->Merge()->SetParams(utils::Vector{result});
utils::Result<Value*> rhs;

View File

@ -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<std::array<uint32_t, 3>> wg_size)
: Base(), name_(name), return_type_(rt), pipeline_stage_(stage), workgroup_size_(wg_size) {}

View File

@ -69,7 +69,7 @@ class Function : public utils::Castable<Function, FlowNode> {
/// @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<std::array<uint32_t, 3>> wg_size = {});
~Function() override;

View File

@ -27,7 +27,7 @@ TEST_F(IR_InstructionTest, CreateLoad) {
Module mod;
Builder b{mod};
auto* store_type = b.ir.types.Get<type::I32>();
auto* store_type = b.ir.types.i32();
auto* var = b.Declare(b.ir.types.Get<type::Pointer>(
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<type::I32>();
auto* store_type = b.ir.types.i32();
auto* var = b.Declare(b.ir.types.Get<type::Pointer>(
store_type, builtin::AddressSpace::kFunction, builtin::Access::kReadWrite));
const auto* inst = b.Load(var);

View File

@ -25,20 +25,20 @@ using IR_ModuleTest = TestHelper;
TEST_F(IR_ModuleTest, NameOfUnnamed) {
Module mod;
auto* v = mod.values.Create<ir::Var>(mod.types.Get<type::I32>());
auto* v = mod.values.Create<ir::Var>(mod.types.i32());
EXPECT_FALSE(mod.NameOf(v).IsValid());
}
TEST_F(IR_ModuleTest, SetName) {
Module mod;
auto* v = mod.values.Create<ir::Var>(mod.types.Get<type::I32>());
auto* v = mod.values.Create<ir::Var>(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<ir::Var>(mod.types.Get<type::I32>());
auto* v = mod.values.Create<ir::Var>(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<ir::Var>(mod.types.Get<type::I32>());
auto* b = mod.values.Create<ir::Var>(mod.types.Get<type::I32>());
auto* c = mod.values.Create<ir::Var>(mod.types.Get<type::I32>());
auto* a = mod.values.Create<ir::Var>(mod.types.i32());
auto* b = mod.values.Create<ir::Var>(mod.types.i32());
auto* c = mod.values.Create<ir::Var>(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");

View File

@ -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<type::Void>(),
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);
}

View File

@ -39,8 +39,7 @@ TEST_F(IR_AddEmptyEntryPointTest, EmptyModule) {
}
TEST_F(IR_AddEmptyEntryPointTest, ExistingEntryPoint) {
auto* ep =
b.CreateFunction("main", mod.types.Get<type::Void>(), 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);

View File

@ -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<type::I32>(), b.Constant(4_i));
auto* inst = b.Complement(b.ir.types.i32(), b.Constant(4_i));
ASSERT_TRUE(inst->Is<Unary>());
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<type::I32>(), b.Constant(4_i));
auto* inst = b.Negation(b.ir.types.i32(), b.Constant(4_i));
ASSERT_TRUE(inst->Is<Unary>());
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<type::I32>(), b.Constant(4_i));
auto* inst = b.Negation(b.ir.types.i32(), b.Constant(4_i));
EXPECT_EQ(inst->Kind(), Unary::Kind::kNegation);

View File

@ -17,8 +17,14 @@
#include <utility>
#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<TYPE>(std::forward<ARGS>(args)...);
}
/// @returns a void type
const type::Type* void_() { return Get<type::Void>(); }
/// @returns a bool type
const type::Type* bool_() { return Get<type::Bool>(); }
/// @returns an i32 type
const type::Type* i32() { return Get<type::I32>(); }
/// @returns a u32 type
const type::Type* u32() { return Get<type::U32>(); }
/// @returns an f32 type
const type::Type* f32() { return Get<type::F32>(); }
/// @returns an f16 type
const type::Type* f16() { return Get<type::F16>(); }
/// @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<type::Vector>(inner, size); }
const type::Type* vec(const type::Type* inner, uint32_t size) {
return Get<type::Vector>(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(); }

View File

@ -20,10 +20,9 @@ namespace tint::writer::spirv {
namespace {
TEST_F(SpvGeneratorImplTest, Binary_Add_I32) {
auto* func = b.CreateFunction("foo", mod.types.Get<type::Void>());
func->StartTarget()->SetInstructions(
utils::Vector{b.Add(mod.types.Get<type::I32>(), 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<type::Void>());
func->StartTarget()->SetInstructions(
utils::Vector{b.Add(mod.types.Get<type::U32>(), 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<type::Void>());
func->StartTarget()->SetInstructions(
utils::Vector{b.Add(mod.types.Get<type::F32>(), 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<type::Void>());
auto* func = b.CreateFunction("foo", mod.types.void_());
func->StartTarget()->SetInstructions(
utils::Vector{b.Subtract(mod.types.Get<type::I32>(), 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<type::Void>());
auto* func = b.CreateFunction("foo", mod.types.void_());
func->StartTarget()->SetInstructions(
utils::Vector{b.Subtract(mod.types.Get<type::U32>(), 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<type::Void>());
auto* func = b.CreateFunction("foo", mod.types.void_());
func->StartTarget()->SetInstructions(
utils::Vector{b.Subtract(mod.types.Get<type::F32>(), 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<type::Void>());
auto* lhs = b.create<constant::Composite>(mod.types.vec2(mod.types.Get<type::I32>()),
auto* func = b.CreateFunction("foo", mod.types.void_());
auto* lhs = b.create<constant::Composite>(mod.types.vec2(mod.types.i32()),
utils::Vector{b.I32(42), b.I32(-1)}, false, false);
auto* rhs = b.create<constant::Composite>(mod.types.vec2(mod.types.Get<type::I32>()),
auto* rhs = b.create<constant::Composite>(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<type::Vector>(mod.types.Get<type::I32>(), 2u),
b.Constant(lhs), b.Constant(rhs)),
utils::Vector{b.Subtract(mod.types.Get<type::Vector>(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<type::Void>());
auto* func = b.CreateFunction("foo", mod.types.void_());
auto* lhs = b.create<constant::Composite>(
mod.types.vec4(mod.types.Get<type::F32>()),
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<constant::Composite>(
mod.types.vec4(mod.types.Get<type::F32>()),
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<type::Vector>(mod.types.Get<type::F32>(), 4u),
b.Constant(lhs), b.Constant(rhs)),
utils::Vector{b.Subtract(mod.types.Get<type::Vector>(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<type::Void>());
auto* a = b.Subtract(mod.types.Get<type::I32>(), 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<type::I32>(), 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"

View File

@ -64,7 +64,7 @@ TEST_F(SpvGeneratorImplTest, Constant_F16) {
TEST_F(SpvGeneratorImplTest, Constant_Vec4Bool) {
auto* v = b.create<constant::Composite>(
mod.types.vec4(mod.types.Get<type::Bool>()),
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<constant::Composite>(mod.types.vec2(mod.types.Get<type::I32>()),
auto* v = b.create<constant::Composite>(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<constant::Composite>(mod.types.vec3(mod.types.Get<type::U32>()),
auto* v = b.create<constant::Composite>(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<constant::Composite>(
mod.types.vec4(mod.types.Get<type::F32>()),
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<constant::Composite>(mod.types.vec2(mod.types.Get<type::F16>()),
auto* v = b.create<constant::Composite>(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

View File

@ -18,7 +18,7 @@ namespace tint::writer::spirv {
namespace {
TEST_F(SpvGeneratorImplTest, Function_Empty) {
auto* func = b.CreateFunction("foo", mod.types.Get<type::Void>());
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<type::Void>());
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<type::Void>(),
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<type::Void>(),
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<type::Void>(), 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<type::Void>(),
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<type::Void>(),
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<type::Void>(),
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);

View File

@ -20,7 +20,7 @@ namespace tint::writer::spirv {
namespace {
TEST_F(SpvGeneratorImplTest, If_TrueEmpty_FalseEmpty) {
auto* func = b.CreateFunction("foo", mod.types.Get<type::Void>());
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<type::Void>());
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<type::I32>(), 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<type::Void>());
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<type::I32>(), 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<type::Void>());
auto* func = b.CreateFunction("foo", mod.types.void_());
auto* i = b.CreateIf(b.Constant(true));
i->True()->SetInstructions(utils::Vector{b.Branch(func->EndTarget())});

View File

@ -25,43 +25,43 @@ namespace tint::writer::spirv {
namespace {
TEST_F(SpvGeneratorImplTest, Type_Void) {
auto id = generator_.Type(mod.types.Get<type::Void>());
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<type::Bool>());
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<type::I32>());
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<type::U32>());
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<type::F32>());
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<type::F16>());
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<type::Vector>(b.ir.types.Get<type::I32>(), 2u);
auto* vec = b.ir.types.Get<type::Vector>(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<type::Vector>(b.ir.types.Get<type::U32>(), 3u);
auto* vec = b.ir.types.Get<type::Vector>(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<type::Vector>(b.ir.types.Get<type::F32>(), 4u);
auto* vec = b.ir.types.Get<type::Vector>(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<type::Vector>(b.ir.types.Get<type::F16>(), 2u);
auto* vec = b.ir.types.Get<type::Vector>(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<type::Vector>(b.ir.types.Get<type::Bool>(), 4u);
auto* vec = b.ir.types.Get<type::Vector>(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<type::I32>()), 1u);
EXPECT_EQ(generator_.Type(mod.types.Get<type::U32>()), 2u);
EXPECT_EQ(generator_.Type(mod.types.Get<type::F32>()), 3u);
EXPECT_EQ(generator_.Type(mod.types.Get<type::F16>()), 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<type::I32>();
auto* i32 = mod.types.i32();
EXPECT_EQ(generator_.Type(i32), 1u);
EXPECT_EQ(generator_.Type(i32), 1u);
EXPECT_EQ(generator_.Type(i32), 1u);

View File

@ -21,10 +21,10 @@ namespace tint::writer::spirv {
namespace {
TEST_F(SpvGeneratorImplTest, FunctionVar_NoInit) {
auto* func = b.CreateFunction("foo", mod.types.Get<type::Void>());
auto* func = b.CreateFunction("foo", mod.types.void_());
auto* ty = mod.types.Get<type::Pointer>(
mod.types.Get<type::I32>(), builtin::AddressSpace::kFunction, builtin::Access::kReadWrite);
auto* ty = mod.types.Get<type::Pointer>(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<type::Void>());
auto* func = b.CreateFunction("foo", mod.types.void_());
auto* ty = mod.types.Get<type::Pointer>(
mod.types.Get<type::I32>(), builtin::AddressSpace::kFunction, builtin::Access::kReadWrite);
auto* ty = mod.types.Get<type::Pointer>(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<type::Void>());
auto* func = b.CreateFunction("foo", mod.types.void_());
auto* ty = mod.types.Get<type::Pointer>(
mod.types.Get<type::I32>(), builtin::AddressSpace::kFunction, builtin::Access::kReadWrite);
auto* ty = mod.types.Get<type::Pointer>(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<type::Void>());
auto* func = b.CreateFunction("foo", mod.types.void_());
auto* ty = mod.types.Get<type::Pointer>(
mod.types.Get<type::I32>(), builtin::AddressSpace::kFunction, builtin::Access::kReadWrite);
auto* ty = mod.types.Get<type::Pointer>(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<type::Void>());
auto* func = b.CreateFunction("foo", mod.types.void_());
auto* store_ty = mod.types.Get<type::I32>();
auto* store_ty = mod.types.i32();
auto* ty = mod.types.Get<type::Pointer>(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<type::Void>());
auto* func = b.CreateFunction("foo", mod.types.void_());
auto* ty = mod.types.Get<type::Pointer>(
mod.types.Get<type::I32>(), builtin::AddressSpace::kFunction, builtin::Access::kReadWrite);
auto* ty = mod.types.Get<type::Pointer>(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())});