Skip to content

Commit 1cee30f

Browse files
dj2Dawn LUCI CQ
authored andcommitted
[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 <[email protected]> Kokoro: Kokoro <[email protected]> Reviewed-by: James Price <[email protected]> Commit-Queue: Dan Sinclair <[email protected]>
1 parent 7d78e3c commit 1cee30f

File tree

7 files changed

+88
-14
lines changed

7 files changed

+88
-14
lines changed

src/tint/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,8 @@ libtint_source_set("libtint_msl_writer_src") {
11801180
sources += [
11811181
"lang/msl/writer/printer/printer.cc",
11821182
"lang/msl/writer/printer/printer.h",
1183+
"lang/msl/writer/raise/raise.cc",
1184+
"lang/msl/writer/raise/raise.h",
11831185
]
11841186
deps += [
11851187
":libtint_ir_src",

src/tint/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,8 @@ if(${TINT_BUILD_MSL_WRITER})
742742
list(APPEND TINT_LIB_SRCS
743743
lang/msl/writer/printer/printer.cc
744744
lang/msl/writer/printer/printer.h
745+
lang/msl/writer/raise/raise.cc
746+
lang/msl/writer/raise/raise.h
745747
)
746748
endif()
747749
endif()

src/tint/lang/msl/writer/printer/helper_test.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "src/tint/lang/core/ir/builder.h"
2323
#include "src/tint/lang/core/ir/validator.h"
2424
#include "src/tint/lang/msl/writer/printer/printer.h"
25+
#include "src/tint/lang/msl/writer/raise/raise.h"
2526

2627
namespace tint::msl::writer {
2728

@@ -69,11 +70,11 @@ class MslPrinterTestHelperBase : public BASE {
6970
/// Run the writer on the IR module and validate the result.
7071
/// @returns true if generation and validation succeeded
7172
bool Generate() {
72-
// auto raised = raise::Raise(&mod);
73-
// if (!raised) {
74-
// err_ = raised.Failure();
75-
// return false;
76-
// }
73+
auto raised = raise::Raise(&mod);
74+
if (!raised) {
75+
err_ = raised.Failure();
76+
return false;
77+
}
7778

7879
auto result = writer_.Generate();
7980
if (!result) {

src/tint/lang/msl/writer/printer/printer.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@
5757
using namespace tint::core::fluent_types; // NOLINT
5858

5959
namespace tint::msl::writer {
60-
namespace {
61-
62-
void Sanitize(ir::Module*) {}
63-
64-
} // namespace
6560

6661
// Helper for calling TINT_UNIMPLEMENTED() from a Switch(object_ptr) default case.
6762
#define UNHANDLED_CASE(object_ptr) \
@@ -78,9 +73,6 @@ tint::Result<SuccessType, std::string> Printer::Generate() {
7873
return std::move(valid.Failure());
7974
}
8075

81-
// Run the IR transformations to prepare for MSL emission.
82-
Sanitize(ir_);
83-
8476
{
8577
TINT_SCOPED_ASSIGNMENT(current_buffer_, &preamble_buffer_);
8678
Line() << "#include <metal_stdlib>";
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2023 The Tint Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "src/tint/lang/msl/writer/raise/raise.h"
16+
17+
#include <utility>
18+
19+
namespace tint::msl::raise {
20+
21+
Result<SuccessType, std::string> Raise(ir::Module*) {
22+
// #define RUN_TRANSFORM(name)
23+
// do {
24+
// auto result = ir::transform::name(module);
25+
// if (!result) {
26+
// return result;
27+
// }
28+
// } while (false)
29+
30+
return Success;
31+
}
32+
33+
} // namespace tint::msl::raise
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2023 The Tint Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef SRC_TINT_LANG_MSL_WRITER_RAISE_RAISE_H_
16+
#define SRC_TINT_LANG_MSL_WRITER_RAISE_RAISE_H_
17+
18+
#include <string>
19+
20+
#include "src/tint/utils/result/result.h"
21+
22+
// Forward declarations
23+
namespace tint::ir {
24+
class Module;
25+
} // namespace tint::ir
26+
27+
namespace tint::msl::raise {
28+
29+
/// Raise a core IR module to the MSL dialect of the IR.
30+
/// @param mod the core IR module to raise to MSL dialect
31+
/// @returns success or an error string
32+
Result<SuccessType, std::string> Raise(ir::Module* mod);
33+
34+
} // namespace tint::msl::raise
35+
36+
#endif // SRC_TINT_LANG_MSL_WRITER_RAISE_RAISE_H_

src/tint/lang/msl/writer/writer.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#if TINT_BUILD_IR
2323
#include "src/tint/lang/msl/writer/printer/printer.h" // nogncheck
24+
#include "src/tint/lang/msl/writer/raise/raise.h" // nogncheck
2425
#include "src/tint/lang/wgsl/reader/program_to_ir/program_to_ir.h" // nogncheck
2526
#endif // TINT_BUILD_IR
2627

@@ -40,8 +41,15 @@ Result<Output, std::string> Generate(const Program* program, const Options& opti
4041
return std::string("IR converter: " + converted.Failure());
4142
}
4243

43-
// Generate the MSL code.
4444
auto ir = converted.Move();
45+
46+
// Raise the IR to the MSL dialect.
47+
auto raised = raise::Raise(&ir);
48+
if (!raised) {
49+
return std::move(raised.Failure());
50+
}
51+
52+
// Generate the MSL code.
4553
auto impl = std::make_unique<Printer>(&ir);
4654
auto result = impl->Generate();
4755
if (!result) {

0 commit comments

Comments
 (0)