[ir][msl] Add a Raise to the MSL IR printer
This CL moves the sanitize call into a MSL Raise to raise the IR up to
the MSL dialect.
Bug: tint:1967
Change-Id: Id4ff46f699423c70b97b9a7b494726cf5b0f3b0c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/146683
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn
index cd1937d..2e78452 100644
--- a/src/tint/BUILD.gn
+++ b/src/tint/BUILD.gn
@@ -1180,6 +1180,8 @@
sources += [
"lang/msl/writer/printer/printer.cc",
"lang/msl/writer/printer/printer.h",
+ "lang/msl/writer/raise/raise.cc",
+ "lang/msl/writer/raise/raise.h",
]
deps += [
":libtint_ir_src",
diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt
index b6ebe9d..60eb510 100644
--- a/src/tint/CMakeLists.txt
+++ b/src/tint/CMakeLists.txt
@@ -742,6 +742,8 @@
list(APPEND TINT_LIB_SRCS
lang/msl/writer/printer/printer.cc
lang/msl/writer/printer/printer.h
+ lang/msl/writer/raise/raise.cc
+ lang/msl/writer/raise/raise.h
)
endif()
endif()
diff --git a/src/tint/lang/msl/writer/printer/helper_test.h b/src/tint/lang/msl/writer/printer/helper_test.h
index e4ca774..49c1535 100644
--- a/src/tint/lang/msl/writer/printer/helper_test.h
+++ b/src/tint/lang/msl/writer/printer/helper_test.h
@@ -22,6 +22,7 @@
#include "src/tint/lang/core/ir/builder.h"
#include "src/tint/lang/core/ir/validator.h"
#include "src/tint/lang/msl/writer/printer/printer.h"
+#include "src/tint/lang/msl/writer/raise/raise.h"
namespace tint::msl::writer {
@@ -69,11 +70,11 @@
/// Run the writer on the IR module and validate the result.
/// @returns true if generation and validation succeeded
bool Generate() {
- // auto raised = raise::Raise(&mod);
- // if (!raised) {
- // err_ = raised.Failure();
- // return false;
- // }
+ auto raised = raise::Raise(&mod);
+ if (!raised) {
+ err_ = raised.Failure();
+ return false;
+ }
auto result = writer_.Generate();
if (!result) {
diff --git a/src/tint/lang/msl/writer/printer/printer.cc b/src/tint/lang/msl/writer/printer/printer.cc
index 3e1c9f9..99a25ce 100644
--- a/src/tint/lang/msl/writer/printer/printer.cc
+++ b/src/tint/lang/msl/writer/printer/printer.cc
@@ -57,11 +57,6 @@
using namespace tint::core::fluent_types; // NOLINT
namespace tint::msl::writer {
-namespace {
-
-void Sanitize(ir::Module*) {}
-
-} // namespace
// Helper for calling TINT_UNIMPLEMENTED() from a Switch(object_ptr) default case.
#define UNHANDLED_CASE(object_ptr) \
@@ -78,9 +73,6 @@
return std::move(valid.Failure());
}
- // Run the IR transformations to prepare for MSL emission.
- Sanitize(ir_);
-
{
TINT_SCOPED_ASSIGNMENT(current_buffer_, &preamble_buffer_);
Line() << "#include <metal_stdlib>";
diff --git a/src/tint/lang/msl/writer/raise/raise.cc b/src/tint/lang/msl/writer/raise/raise.cc
new file mode 100644
index 0000000..646322b
--- /dev/null
+++ b/src/tint/lang/msl/writer/raise/raise.cc
@@ -0,0 +1,33 @@
+// Copyright 2023 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "src/tint/lang/msl/writer/raise/raise.h"
+
+#include <utility>
+
+namespace tint::msl::raise {
+
+Result<SuccessType, std::string> Raise(ir::Module*) {
+ // #define RUN_TRANSFORM(name)
+ // do {
+ // auto result = ir::transform::name(module);
+ // if (!result) {
+ // return result;
+ // }
+ // } while (false)
+
+ return Success;
+}
+
+} // namespace tint::msl::raise
diff --git a/src/tint/lang/msl/writer/raise/raise.h b/src/tint/lang/msl/writer/raise/raise.h
new file mode 100644
index 0000000..b460675
--- /dev/null
+++ b/src/tint/lang/msl/writer/raise/raise.h
@@ -0,0 +1,36 @@
+// Copyright 2023 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef SRC_TINT_LANG_MSL_WRITER_RAISE_RAISE_H_
+#define SRC_TINT_LANG_MSL_WRITER_RAISE_RAISE_H_
+
+#include <string>
+
+#include "src/tint/utils/result/result.h"
+
+// Forward declarations
+namespace tint::ir {
+class Module;
+} // namespace tint::ir
+
+namespace tint::msl::raise {
+
+/// Raise a core IR module to the MSL dialect of the IR.
+/// @param mod the core IR module to raise to MSL dialect
+/// @returns success or an error string
+Result<SuccessType, std::string> Raise(ir::Module* mod);
+
+} // namespace tint::msl::raise
+
+#endif // SRC_TINT_LANG_MSL_WRITER_RAISE_RAISE_H_
diff --git a/src/tint/lang/msl/writer/writer.cc b/src/tint/lang/msl/writer/writer.cc
index 3da7728..20d1df7 100644
--- a/src/tint/lang/msl/writer/writer.cc
+++ b/src/tint/lang/msl/writer/writer.cc
@@ -21,6 +21,7 @@
#if TINT_BUILD_IR
#include "src/tint/lang/msl/writer/printer/printer.h" // nogncheck
+#include "src/tint/lang/msl/writer/raise/raise.h" // nogncheck
#include "src/tint/lang/wgsl/reader/program_to_ir/program_to_ir.h" // nogncheck
#endif // TINT_BUILD_IR
@@ -40,8 +41,15 @@
return std::string("IR converter: " + converted.Failure());
}
- // Generate the MSL code.
auto ir = converted.Move();
+
+ // Raise the IR to the MSL dialect.
+ auto raised = raise::Raise(&ir);
+ if (!raised) {
+ return std::move(raised.Failure());
+ }
+
+ // Generate the MSL code.
auto impl = std::make_unique<Printer>(&ir);
auto result = impl->Generate();
if (!result) {