Skip to content

Commit 30c31a9

Browse files
committed
[tint][ir] Pass ir::Module by reference, not pointer
This must never be never null. Bug: tint:1698 Change-Id: I9c297cd79665003ef316703d2118b7d8293cf6c1 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/152547 Reviewed-by: dan sinclair <[email protected]> Kokoro: Kokoro <[email protected]>
1 parent 16fb254 commit 30c31a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+247
-259
lines changed

src/tint/lang/core/ir/transform/add_empty_entry_point.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ namespace tint::core::ir::transform {
2424

2525
namespace {
2626

27-
void Run(ir::Module* ir) {
28-
for (auto* func : ir->functions) {
27+
void Run(ir::Module& ir) {
28+
for (auto* func : ir.functions) {
2929
if (func->Stage() != Function::PipelineStage::kUndefined) {
3030
return;
3131
}
3232
}
3333

34-
ir::Builder builder(*ir);
35-
auto* ep = builder.Function("unused_entry_point", ir->Types().void_(),
34+
ir::Builder builder{ir};
35+
auto* ep = builder.Function("unused_entry_point", ir.Types().void_(),
3636
Function::PipelineStage::kCompute, std::array{1u, 1u, 1u});
3737
ep->Block()->Append(builder.Return(ep));
3838
}
3939

4040
} // namespace
4141

42-
Result<SuccessType> AddEmptyEntryPoint(Module* ir) {
43-
auto result = ValidateAndDumpIfNeeded(*ir, "AddEmptyEntryPoint transform");
42+
Result<SuccessType> AddEmptyEntryPoint(Module& ir) {
43+
auto result = ValidateAndDumpIfNeeded(ir, "AddEmptyEntryPoint transform");
4444
if (!result) {
45-
return result;
45+
return result.Failure();
4646
}
4747

4848
Run(ir);

src/tint/lang/core/ir/transform/add_empty_entry_point.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace tint::core::ir::transform {
2929
/// Add an empty entry point to the module, if no other entry points exist.
3030
/// @param module the module to transform
3131
/// @returns success or failure
32-
Result<SuccessType> AddEmptyEntryPoint(Module* module);
32+
Result<SuccessType> AddEmptyEntryPoint(Module& module);
3333

3434
} // namespace tint::core::ir::transform
3535

src/tint/lang/core/ir/transform/bgra8unorm_polyfill.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ namespace {
3232
/// PIMPL state for the transform.
3333
struct State {
3434
/// The IR module.
35-
Module* ir = nullptr;
35+
Module& ir;
3636

3737
/// The IR builder.
38-
Builder b{*ir};
38+
Builder b{ir};
3939

4040
/// The type manager.
41-
core::type::Manager& ty{ir->Types()};
41+
core::type::Manager& ty{ir.Types()};
4242

4343
/// Process the module.
4444
void Process() {
4545
// Find module-scope variables that need to be replaced.
46-
if (ir->root_block) {
46+
if (ir.root_block) {
4747
Vector<Instruction*, 4> to_remove;
48-
for (auto inst : *ir->root_block) {
48+
for (auto inst : *ir.root_block) {
4949
auto* var = inst->As<Var>();
5050
if (!var) {
5151
continue;
@@ -67,7 +67,7 @@ struct State {
6767
}
6868

6969
// Find function parameters that need to be replaced.
70-
for (auto* func : ir->functions) {
70+
for (auto* func : ir.functions) {
7171
for (uint32_t index = 0; index < func->Params().Length(); index++) {
7272
auto* param = func->Params()[index];
7373
auto* storage_texture = param->Type()->As<core::type::StorageTexture>();
@@ -90,8 +90,8 @@ struct State {
9090
auto bp = old_var->BindingPoint();
9191
new_var->SetBindingPoint(bp->group, bp->binding);
9292
new_var->InsertBefore(old_var);
93-
if (auto name = ir->NameOf(old_var)) {
94-
ir->SetName(new_var, name.NameView());
93+
if (auto name = ir.NameOf(old_var)) {
94+
ir.SetName(new_var, name.NameView());
9595
}
9696

9797
// Replace all uses of the old variable with the new one.
@@ -111,8 +111,8 @@ struct State {
111111
auto* rgba8 = ty.Get<core::type::StorageTexture>(
112112
bgra8->dim(), core::TexelFormat::kRgba8Unorm, bgra8->access(), bgra8->type());
113113
auto* new_param = b.FunctionParam(rgba8);
114-
if (auto name = ir->NameOf(old_param)) {
115-
ir->SetName(new_param, name.NameView());
114+
if (auto name = ir.NameOf(old_param)) {
115+
ir.SetName(new_param, name.NameView());
116116
}
117117

118118
Vector<FunctionParam*, 4> new_params = func->Params();
@@ -170,8 +170,8 @@ struct State {
170170

171171
} // namespace
172172

173-
Result<SuccessType> Bgra8UnormPolyfill(Module* ir) {
174-
auto result = ValidateAndDumpIfNeeded(*ir, "Bgra8UnormPolyfill transform");
173+
Result<SuccessType> Bgra8UnormPolyfill(Module& ir) {
174+
auto result = ValidateAndDumpIfNeeded(ir, "Bgra8UnormPolyfill transform");
175175
if (!result) {
176176
return result;
177177
}

src/tint/lang/core/ir/transform/bgra8unorm_polyfill.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace tint::core::ir::transform {
3030
/// bgra8unorm to rgba8unorm, inserting swizzles before and after texture accesses as necessary.
3131
/// @param module the module to transform
3232
/// @returns success or failure
33-
Result<SuccessType> Bgra8UnormPolyfill(Module* module);
33+
Result<SuccessType> Bgra8UnormPolyfill(Module& module);
3434

3535
} // namespace tint::core::ir::transform
3636

src/tint/lang/core/ir/transform/binary_polyfill.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ struct State {
3333
const BinaryPolyfillConfig& config;
3434

3535
/// The IR module.
36-
Module* ir = nullptr;
36+
Module& ir;
3737

3838
/// The IR builder.
39-
Builder b{*ir};
39+
Builder b{ir};
4040

4141
/// The type manager.
42-
core::type::Manager& ty{ir->Types()};
42+
core::type::Manager& ty{ir.Types()};
4343

4444
/// The symbol table.
45-
SymbolTable& sym{ir->symbols};
45+
SymbolTable& sym{ir.symbols};
4646

4747
/// Map from integer type to its divide helper function.
4848
Hashmap<const type::Type*, Function*, 4> int_div_helpers{};
@@ -54,7 +54,7 @@ struct State {
5454
void Process() {
5555
// Find the binary instructions that need to be polyfilled.
5656
Vector<ir::Binary*, 64> worklist;
57-
for (auto* inst : ir->instructions.Objects()) {
57+
for (auto* inst : ir.instructions.Objects()) {
5858
if (!inst->Alive()) {
5959
continue;
6060
}
@@ -98,8 +98,8 @@ struct State {
9898

9999
if (replacement != binary->Result()) {
100100
// Replace the old binary instruction result with the new value.
101-
if (auto name = ir->NameOf(binary->Result())) {
102-
ir->SetName(replacement, name);
101+
if (auto name = ir.NameOf(binary->Result())) {
102+
ir.SetName(replacement, name);
103103
}
104104
binary->Result()->ReplaceAllUsesWith(replacement);
105105
binary->Destroy();
@@ -232,8 +232,8 @@ struct State {
232232

233233
} // namespace
234234

235-
Result<SuccessType> BinaryPolyfill(Module* ir, const BinaryPolyfillConfig& config) {
236-
auto result = ValidateAndDumpIfNeeded(*ir, "BinaryPolyfill transform");
235+
Result<SuccessType> BinaryPolyfill(Module& ir, const BinaryPolyfillConfig& config) {
236+
auto result = ValidateAndDumpIfNeeded(ir, "BinaryPolyfill transform");
237237
if (!result) {
238238
return result;
239239
}

src/tint/lang/core/ir/transform/binary_polyfill.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct BinaryPolyfillConfig {
3939
/// @param module the module to transform
4040
/// @param config the polyfill configuration
4141
/// @returns success or failure
42-
Result<SuccessType> BinaryPolyfill(Module* module, const BinaryPolyfillConfig& config);
42+
Result<SuccessType> BinaryPolyfill(Module& module, const BinaryPolyfillConfig& config);
4343

4444
} // namespace tint::core::ir::transform
4545

src/tint/lang/core/ir/transform/binding_remapper.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ namespace tint::core::ir::transform {
2828

2929
namespace {
3030

31-
Result<SuccessType> Run(ir::Module* ir, const BindingRemapperOptions& options) {
31+
Result<SuccessType> Run(ir::Module& ir, const BindingRemapperOptions& options) {
3232
if (!options.access_controls.empty()) {
3333
return Failure{"remapping access controls is currently unsupported"};
3434
}
3535
if (options.binding_points.empty()) {
3636
return Success;
3737
}
38-
if (!ir->root_block) {
38+
if (!ir.root_block) {
3939
return Success;
4040
}
4141

4242
// Find binding resources.
43-
for (auto inst : *ir->root_block) {
43+
for (auto inst : *ir.root_block) {
4444
auto* var = inst->As<Var>();
4545
if (!var || !var->Alive()) {
4646
continue;
@@ -63,8 +63,8 @@ Result<SuccessType> Run(ir::Module* ir, const BindingRemapperOptions& options) {
6363

6464
} // namespace
6565

66-
Result<SuccessType> BindingRemapper(Module* ir, const BindingRemapperOptions& options) {
67-
auto result = ValidateAndDumpIfNeeded(*ir, "BindingRemapper transform");
66+
Result<SuccessType> BindingRemapper(Module& ir, const BindingRemapperOptions& options) {
67+
auto result = ValidateAndDumpIfNeeded(ir, "BindingRemapper transform");
6868
if (!result) {
6969
return result;
7070
}

src/tint/lang/core/ir/transform/binding_remapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace tint::core::ir::transform {
3131
/// @param module the module to transform
3232
/// @param options the remapping options
3333
/// @returns success or failure
34-
Result<SuccessType> BindingRemapper(Module* module, const BindingRemapperOptions& options);
34+
Result<SuccessType> BindingRemapper(Module& module, const BindingRemapperOptions& options);
3535

3636
} // namespace tint::core::ir::transform
3737

src/tint/lang/core/ir/transform/block_decorated_structs.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ namespace tint::core::ir::transform {
2828

2929
namespace {
3030

31-
void Run(Module* ir) {
32-
Builder builder(*ir);
31+
void Run(Module& ir) {
32+
Builder builder{ir};
3333

34-
if (!ir->root_block) {
34+
if (!ir.root_block) {
3535
return;
3636
}
3737

3838
// Loop over module-scope declarations, looking for storage or uniform buffers.
3939
Vector<Var*, 8> buffer_variables;
40-
for (auto inst : *ir->root_block) {
40+
for (auto inst : *ir.root_block) {
4141
auto* var = inst->As<Var>();
4242
if (!var) {
4343
continue;
@@ -67,8 +67,8 @@ void Run(Module* ir) {
6767
} else {
6868
// The original struct might be used in other places, so create a new block-decorated
6969
// struct that wraps the original struct.
70-
members.Push(ir->Types().Get<core::type::StructMember>(
71-
/* name */ ir->symbols.New(),
70+
members.Push(ir.Types().Get<core::type::StructMember>(
71+
/* name */ ir.symbols.New(),
7272
/* type */ store_ty,
7373
/* index */ 0u,
7474
/* offset */ 0u,
@@ -79,8 +79,8 @@ void Run(Module* ir) {
7979
}
8080

8181
// Create the block-decorated struct.
82-
auto* block_struct = ir->Types().Get<core::type::Struct>(
83-
/* name */ ir->symbols.New(),
82+
auto* block_struct = ir.Types().Get<core::type::Struct>(
83+
/* name */ ir.symbols.New(),
8484
/* members */ members,
8585
/* align */ store_ty->Align(),
8686
/* size */ tint::RoundUp(store_ty->Align(), store_ty->Size()),
@@ -89,7 +89,7 @@ void Run(Module* ir) {
8989

9090
// Replace the old variable declaration with one that uses the block-decorated struct type.
9191
auto* new_var =
92-
builder.Var(ir->Types().ptr(ptr->AddressSpace(), block_struct, ptr->Access()));
92+
builder.Var(ir.Types().ptr(ptr->AddressSpace(), block_struct, ptr->Access()));
9393
if (var->BindingPoint()) {
9494
new_var->SetBindingPoint(var->BindingPoint()->group, var->BindingPoint()->binding);
9595
}
@@ -111,8 +111,8 @@ void Run(Module* ir) {
111111

112112
} // namespace
113113

114-
Result<SuccessType> BlockDecoratedStructs(Module* ir) {
115-
auto result = ValidateAndDumpIfNeeded(*ir, "BlockDecoratedStructs transform");
114+
Result<SuccessType> BlockDecoratedStructs(Module& ir) {
115+
auto result = ValidateAndDumpIfNeeded(ir, "BlockDecoratedStructs transform");
116116
if (!result) {
117117
return result;
118118
}

src/tint/lang/core/ir/transform/block_decorated_structs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace tint::core::ir::transform {
3131
/// existing store type in a new structure if necessary.
3232
/// @param module the module to transform
3333
/// @returns success or failure
34-
Result<SuccessType> BlockDecoratedStructs(Module* module);
34+
Result<SuccessType> BlockDecoratedStructs(Module& module);
3535

3636
} // namespace tint::core::ir::transform
3737

0 commit comments

Comments
 (0)