[ir] Test cleanup
Add a builder helper function to create a `Function` with a `string_view` name instead of requiring the creation of a symbol. Bug: tint:1718 Change-Id: I5d85736b49719246cb31825c3f4ad7a25131cb77 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/133900 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: James Price <jrprice@google.com> Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
68b4e6460f
commit
c4722c2f0b
|
@ -45,6 +45,13 @@ FunctionTerminator* Builder::CreateFunctionTerminator() {
|
|||
return ir.flow_nodes.Create<FunctionTerminator>();
|
||||
}
|
||||
|
||||
Function* Builder::CreateFunction(std::string_view name,
|
||||
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,
|
||||
Function::PipelineStage stage,
|
||||
|
|
|
@ -68,6 +68,17 @@ class Builder {
|
|||
/// @returns a new function terminator flow node
|
||||
FunctionTerminator* CreateFunctionTerminator();
|
||||
|
||||
/// Creates a function flow node
|
||||
/// @param name the function name
|
||||
/// @param return_type the function return type
|
||||
/// @param stage the function stage
|
||||
/// @param wg_size the workgroup_size
|
||||
/// @returns the flow node
|
||||
Function* CreateFunction(std::string_view name,
|
||||
type::Type* return_type,
|
||||
Function::PipelineStage stage = Function::PipelineStage::kUndefined,
|
||||
std::optional<std::array<uint32_t, 3>> wg_size = {});
|
||||
|
||||
/// Creates a function flow node
|
||||
/// @param name the function name
|
||||
/// @param return_type the function return type
|
||||
|
|
|
@ -39,8 +39,8 @@ TEST_F(IR_AddEmptyEntryPointTest, EmptyModule) {
|
|||
}
|
||||
|
||||
TEST_F(IR_AddEmptyEntryPointTest, ExistingEntryPoint) {
|
||||
auto* ep = b.CreateFunction(mod.symbols.New("main"), mod.types.Get<type::Void>(),
|
||||
Function::PipelineStage::kFragment);
|
||||
auto* ep =
|
||||
b.CreateFunction("main", mod.types.Get<type::Void>(), Function::PipelineStage::kFragment);
|
||||
ep->StartTarget()->SetInstructions(utils::Vector{b.Branch(ep->EndTarget())});
|
||||
mod.functions.Push(ep);
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace tint::writer::spirv {
|
|||
namespace {
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, Binary_Add_I32) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||
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())});
|
||||
|
@ -41,7 +41,7 @@ OpFunctionEnd
|
|||
}
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, Binary_Add_U32) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||
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())});
|
||||
|
@ -62,7 +62,7 @@ OpFunctionEnd
|
|||
}
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, Binary_Add_F32) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||
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())});
|
||||
|
@ -83,7 +83,7 @@ OpFunctionEnd
|
|||
}
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, Binary_Sub_I32) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||
auto* func = b.CreateFunction("foo", mod.types.Get<type::Void>());
|
||||
func->StartTarget()->SetInstructions(
|
||||
utils::Vector{b.Subtract(mod.types.Get<type::I32>(), b.Constant(1_i), b.Constant(2_i)),
|
||||
b.Branch(func->EndTarget())});
|
||||
|
@ -104,7 +104,7 @@ OpFunctionEnd
|
|||
}
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, Binary_Sub_U32) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||
auto* func = b.CreateFunction("foo", mod.types.Get<type::Void>());
|
||||
func->StartTarget()->SetInstructions(
|
||||
utils::Vector{b.Subtract(mod.types.Get<type::U32>(), b.Constant(1_u), b.Constant(2_u)),
|
||||
b.Branch(func->EndTarget())});
|
||||
|
@ -125,7 +125,7 @@ OpFunctionEnd
|
|||
}
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, Binary_Sub_F32) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||
auto* func = b.CreateFunction("foo", mod.types.Get<type::Void>());
|
||||
func->StartTarget()->SetInstructions(
|
||||
utils::Vector{b.Subtract(mod.types.Get<type::F32>(), b.Constant(1_f), b.Constant(2_f)),
|
||||
b.Branch(func->EndTarget())});
|
||||
|
@ -146,7 +146,7 @@ OpFunctionEnd
|
|||
}
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, Binary_Sub_Vec2i) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||
auto* func = b.CreateFunction("foo", mod.types.Get<type::Void>());
|
||||
auto* lhs = mod.constants_arena.Create<constant::Composite>(
|
||||
mod.types.Get<type::Vector>(mod.types.Get<type::I32>(), 2u),
|
||||
utils::Vector{b.Constant(42_i)->Value(), b.Constant(-1_i)->Value()}, false, false);
|
||||
|
@ -179,7 +179,7 @@ OpFunctionEnd
|
|||
}
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, Binary_Sub_Vec4f) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||
auto* func = b.CreateFunction("foo", mod.types.Get<type::Void>());
|
||||
auto* lhs = mod.constants_arena.Create<constant::Composite>(
|
||||
mod.types.Get<type::Vector>(mod.types.Get<type::F32>(), 4u),
|
||||
utils::Vector{b.Constant(42_f)->Value(), b.Constant(-1_f)->Value(),
|
||||
|
@ -218,7 +218,7 @@ OpFunctionEnd
|
|||
}
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, Binary_Chain) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||
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));
|
||||
func->StartTarget()->SetInstructions(
|
||||
utils::Vector{a, b.Add(mod.types.Get<type::I32>(), a, a), b.Branch(func->EndTarget())});
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace tint::writer::spirv {
|
|||
namespace {
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, Function_Empty) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||
auto* func = b.CreateFunction("foo", mod.types.Get<type::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(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||
auto* func = b.CreateFunction("foo", mod.types.Get<type::Void>());
|
||||
func->StartTarget()->SetInstructions(utils::Vector{b.Branch(func->EndTarget())});
|
||||
|
||||
generator_.EmitFunction(func);
|
||||
|
@ -46,7 +46,7 @@ TEST_F(SpvGeneratorImplTest, Function_DeduplicateType) {
|
|||
}
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, Function_EntryPoint_Compute) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("main"), mod.types.Get<type::Void>(),
|
||||
auto* func = b.CreateFunction("main", mod.types.Get<type::Void>(),
|
||||
ir::Function::PipelineStage::kCompute, {{32, 4, 1}});
|
||||
func->StartTarget()->SetInstructions(utils::Vector{b.Branch(func->EndTarget())});
|
||||
|
||||
|
@ -64,7 +64,7 @@ OpFunctionEnd
|
|||
}
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, Function_EntryPoint_Fragment) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("main"), mod.types.Get<type::Void>(),
|
||||
auto* func = b.CreateFunction("main", mod.types.Get<type::Void>(),
|
||||
ir::Function::PipelineStage::kFragment);
|
||||
func->StartTarget()->SetInstructions(utils::Vector{b.Branch(func->EndTarget())});
|
||||
|
||||
|
@ -82,8 +82,8 @@ OpFunctionEnd
|
|||
}
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, Function_EntryPoint_Vertex) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("main"), mod.types.Get<type::Void>(),
|
||||
ir::Function::PipelineStage::kVertex);
|
||||
auto* func =
|
||||
b.CreateFunction("main", mod.types.Get<type::Void>(), ir::Function::PipelineStage::kVertex);
|
||||
func->StartTarget()->SetInstructions(utils::Vector{b.Branch(func->EndTarget())});
|
||||
|
||||
generator_.EmitFunction(func);
|
||||
|
@ -99,15 +99,15 @@ OpFunctionEnd
|
|||
}
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, Function_EntryPoint_Multiple) {
|
||||
auto* f1 = b.CreateFunction(mod.symbols.Register("main1"), mod.types.Get<type::Void>(),
|
||||
auto* f1 = b.CreateFunction("main1", mod.types.Get<type::Void>(),
|
||||
ir::Function::PipelineStage::kCompute, {{32, 4, 1}});
|
||||
f1->StartTarget()->SetInstructions(utils::Vector{b.Branch(f1->EndTarget())});
|
||||
|
||||
auto* f2 = b.CreateFunction(mod.symbols.Register("main2"), mod.types.Get<type::Void>(),
|
||||
auto* f2 = b.CreateFunction("main2", mod.types.Get<type::Void>(),
|
||||
ir::Function::PipelineStage::kCompute, {{8, 2, 16}});
|
||||
f2->StartTarget()->SetInstructions(utils::Vector{b.Branch(f2->EndTarget())});
|
||||
|
||||
auto* f3 = b.CreateFunction(mod.symbols.Register("main3"), mod.types.Get<type::Void>(),
|
||||
auto* f3 = b.CreateFunction("main3", mod.types.Get<type::Void>(),
|
||||
ir::Function::PipelineStage::kFragment);
|
||||
f3->StartTarget()->SetInstructions(utils::Vector{b.Branch(f3->EndTarget())});
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace tint::writer::spirv {
|
|||
namespace {
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, If_TrueEmpty_FalseEmpty) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||
auto* func = b.CreateFunction("foo", mod.types.Get<type::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(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||
auto* func = b.CreateFunction("foo", mod.types.Get<type::Void>());
|
||||
|
||||
auto* i = b.CreateIf(b.Constant(true));
|
||||
i->False()->SetInstructions(utils::Vector{b.Branch(i->Merge())});
|
||||
|
@ -80,7 +80,7 @@ OpFunctionEnd
|
|||
}
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, If_TrueEmpty) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||
auto* func = b.CreateFunction("foo", mod.types.Get<type::Void>());
|
||||
|
||||
auto* i = b.CreateIf(b.Constant(true));
|
||||
i->True()->SetInstructions(utils::Vector{b.Branch(i->Merge())});
|
||||
|
@ -114,7 +114,7 @@ OpFunctionEnd
|
|||
}
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, If_BothBranchesReturn) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||
auto* func = b.CreateFunction("foo", mod.types.Get<type::Void>());
|
||||
|
||||
auto* i = b.CreateIf(b.Constant(true));
|
||||
i->True()->SetInstructions(utils::Vector{b.Branch(func->EndTarget())});
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace tint::writer::spirv {
|
|||
namespace {
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, FunctionVar_NoInit) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||
auto* func = b.CreateFunction("foo", mod.types.Get<type::Void>());
|
||||
|
||||
auto* ty = mod.types.Get<type::Pointer>(
|
||||
mod.types.Get<type::I32>(), builtin::AddressSpace::kFunction, builtin::Access::kReadWrite);
|
||||
|
@ -42,7 +42,7 @@ OpFunctionEnd
|
|||
}
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, FunctionVar_WithInit) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||
auto* func = b.CreateFunction("foo", mod.types.Get<type::Void>());
|
||||
|
||||
auto* ty = mod.types.Get<type::Pointer>(
|
||||
mod.types.Get<type::I32>(), builtin::AddressSpace::kFunction, builtin::Access::kReadWrite);
|
||||
|
@ -68,7 +68,7 @@ OpFunctionEnd
|
|||
}
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, FunctionVar_Name) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||
auto* func = b.CreateFunction("foo", mod.types.Get<type::Void>());
|
||||
|
||||
auto* ty = mod.types.Get<type::Pointer>(
|
||||
mod.types.Get<type::I32>(), builtin::AddressSpace::kFunction, builtin::Access::kReadWrite);
|
||||
|
@ -92,7 +92,7 @@ OpFunctionEnd
|
|||
}
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, FunctionVar_DeclInsideBlock) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||
auto* func = b.CreateFunction("foo", mod.types.Get<type::Void>());
|
||||
|
||||
auto* ty = mod.types.Get<type::Pointer>(
|
||||
mod.types.Get<type::I32>(), builtin::AddressSpace::kFunction, builtin::Access::kReadWrite);
|
||||
|
@ -132,7 +132,7 @@ OpFunctionEnd
|
|||
}
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, FunctionVar_Load) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||
auto* func = b.CreateFunction("foo", mod.types.Get<type::Void>());
|
||||
|
||||
auto* store_ty = mod.types.Get<type::I32>();
|
||||
auto* ty = mod.types.Get<type::Pointer>(store_ty, builtin::AddressSpace::kFunction,
|
||||
|
@ -156,7 +156,7 @@ OpFunctionEnd
|
|||
}
|
||||
|
||||
TEST_F(SpvGeneratorImplTest, FunctionVar_Store) {
|
||||
auto* func = b.CreateFunction(mod.symbols.Register("foo"), mod.types.Get<type::Void>());
|
||||
auto* func = b.CreateFunction("foo", mod.types.Get<type::Void>());
|
||||
|
||||
auto* ty = mod.types.Get<type::Pointer>(
|
||||
mod.types.Get<type::I32>(), builtin::AddressSpace::kFunction, builtin::Access::kReadWrite);
|
||||
|
|
Loading…
Reference in New Issue