Skip to content

Commit

Permalink
[ir] Remove std::optional from remapped_entry_point_name
Browse files Browse the repository at this point in the history
Use an empty string to indicate that no remapping should be performed
instead. This removes the need for additional checks around this
option.

Bug: 380043958
Change-Id: I678485d359cb6280f5cda6e85a6506752e8b0d35
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/219255
Reviewed-by: Antonio Maiorano <[email protected]>
Commit-Queue: James Price <[email protected]>
  • Loading branch information
jrprice authored and Dawn LUCI CQ committed Dec 16, 2024
1 parent afc9c13 commit c07449b
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/tint/lang/hlsl/writer/common/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ struct Options {
Options& operator=(const Options&);

/// An optional remapped name to use when emitting the entry point.
std::optional<std::string> remapped_entry_point_name = {};
std::string remapped_entry_point_name = {};

/// Set to `true` to strip all user-declared identifiers from the module.
bool strip_all_names = false;
Expand Down
6 changes: 3 additions & 3 deletions src/tint/lang/hlsl/writer/printer/printer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ class Printer : public tint::TextGenerator {
// Remap the entry point name if requested.
auto func_name = NameOf(func);
if (func->IsEntryPoint()) {
if (options_.remapped_entry_point_name) {
func_name = *options_.remapped_entry_point_name;
TINT_ASSERT(!IsKeyword(func_name) && !func_name.empty());
if (!options_.remapped_entry_point_name.empty()) {
func_name = options_.remapped_entry_point_name;
TINT_ASSERT(!IsKeyword(func_name));
}
result_.entry_points.push_back({func_name, ir_to_ast_stage(func->Stage())});
}
Expand Down
2 changes: 1 addition & 1 deletion src/tint/lang/msl/writer/common/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ struct Options {
Options& operator=(const Options&);

/// An optional remapped name to use when emitting the entry point.
std::optional<std::string> remapped_entry_point_name = {};
std::string remapped_entry_point_name = {};

/// Set to `true` to strip all user-declared identifiers from the module.
bool strip_all_names = false;
Expand Down
6 changes: 3 additions & 3 deletions src/tint/lang/msl/writer/printer/printer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ class Printer : public tint::TextGenerator {

// Remap the entry point name if requested.
auto func_name = NameOf(func);
if (func->IsEntryPoint() && options_.remapped_entry_point_name) {
func_name = *options_.remapped_entry_point_name;
TINT_ASSERT(!IsKeyword(func_name) && !func_name.empty());
if (func->IsEntryPoint() && !options_.remapped_entry_point_name.empty()) {
func_name = options_.remapped_entry_point_name;
TINT_ASSERT(!IsKeyword(func_name));
}

switch (func->Stage()) {
Expand Down
7 changes: 1 addition & 6 deletions src/tint/lang/msl/writer/writer_fuzz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@
namespace tint::msl::writer {
namespace {

bool CanRun(const core::ir::Module& module, const Options& options) {
// If a remapped entry point name is provided, it must not be empty.
if (options.remapped_entry_point_name && options.remapped_entry_point_name->empty()) {
return false;
}

bool CanRun(const core::ir::Module& module, const Options&) {
// Check for unsupported module-scope variable address spaces and types.
for (auto* inst : *module.root_block) {
auto* var = inst->As<core::ir::Var>();
Expand Down
2 changes: 1 addition & 1 deletion src/tint/lang/spirv/writer/common/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ struct Bindings {
/// Configuration options used for generating SPIR-V.
struct Options {
/// An optional remapped name to use when emitting the entry point.
std::optional<std::string> remapped_entry_point_name;
std::string remapped_entry_point_name = {};

/// The bindings
Bindings bindings;
Expand Down
4 changes: 2 additions & 2 deletions src/tint/lang/spirv/writer/printer/printer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,8 @@ class Printer {

// Use the remapped entry point name if requested, otherwise use the original name.
std::string name;
if (options_.remapped_entry_point_name) {
name = *options_.remapped_entry_point_name;
if (!options_.remapped_entry_point_name.empty()) {
name = options_.remapped_entry_point_name;
} else {
name = ir_.NameOf(func).Name();
}
Expand Down
7 changes: 2 additions & 5 deletions src/tint/lang/spirv/writer/writer_fuzz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ namespace {
bool CanRun(const core::ir::Module& module, const Options& options) {
// If a remapped entry point name is provided, it must not be empty, and must not contain
// embedded null characters.
if (options.remapped_entry_point_name) {
if (options.remapped_entry_point_name->empty()) {
return false;
}
if (options.remapped_entry_point_name->find('\0') != std::string::npos) {
if (!options.remapped_entry_point_name.empty()) {
if (options.remapped_entry_point_name.find('\0') != std::string::npos) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tint/lang/spirv/writer/writer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ TEST_F(SpirvWriterTest, EntryPointName_NotRemapped) {
});

Options options;
options.remapped_entry_point_name = {};
options.remapped_entry_point_name = "";
ASSERT_TRUE(Generate(options)) << Error() << output_;
EXPECT_INST("OpEntryPoint GLCompute %main \"main\"");
}
Expand Down

0 comments on commit c07449b

Please sign in to comment.