[ir] Convert ExpandImplicitSplats to a free function
Bug: tint:1718
Change-Id: I84e3378d3428ffcc1a332a3131187c64290a84ce
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/143824
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
diff --git a/src/tint/lang/core/ir/transform/expand_implicit_splats.cc b/src/tint/lang/core/ir/transform/expand_implicit_splats.cc
index 81eb5a6..d516999 100644
--- a/src/tint/lang/core/ir/transform/expand_implicit_splats.cc
+++ b/src/tint/lang/core/ir/transform/expand_implicit_splats.cc
@@ -18,18 +18,15 @@
#include "src/tint/lang/core/ir/builder.h"
#include "src/tint/lang/core/ir/module.h"
-
-TINT_INSTANTIATE_TYPEINFO(tint::ir::transform::ExpandImplicitSplats);
+#include "src/tint/lang/core/ir/validator.h"
using namespace tint::number_suffixes; // NOLINT
namespace tint::ir::transform {
-ExpandImplicitSplats::ExpandImplicitSplats() = default;
+namespace {
-ExpandImplicitSplats::~ExpandImplicitSplats() = default;
-
-void ExpandImplicitSplats::Run(ir::Module* ir) const {
+void Run(ir::Module* ir) {
ir::Builder b(*ir);
// Find the instructions that use implicit splats and either modify them in place or record them
@@ -129,4 +126,17 @@
}
}
+} // namespace
+
+Result<SuccessType, std::string> ExpandImplicitSplats(Module* ir) {
+ auto result = ValidateAndDumpIfNeeded(*ir, "ExpandImplicitSplats transform");
+ if (!result) {
+ return result;
+ }
+
+ Run(ir);
+
+ return Success;
+}
+
} // namespace tint::ir::transform
diff --git a/src/tint/lang/core/ir/transform/expand_implicit_splats.h b/src/tint/lang/core/ir/transform/expand_implicit_splats.h
index 37fb887..ee3b0c5 100644
--- a/src/tint/lang/core/ir/transform/expand_implicit_splats.h
+++ b/src/tint/lang/core/ir/transform/expand_implicit_splats.h
@@ -15,22 +15,22 @@
#ifndef SRC_TINT_LANG_CORE_IR_TRANSFORM_EXPAND_IMPLICIT_SPLATS_H_
#define SRC_TINT_LANG_CORE_IR_TRANSFORM_EXPAND_IMPLICIT_SPLATS_H_
-#include "src/tint/lang/core/ir/transform/transform.h"
+#include <string>
+
+#include "src/tint/utils/result/result.h"
+
+// Forward declarations.
+namespace tint::ir {
+class Module;
+}
namespace tint::ir::transform {
/// ExpandImplicitSplats is a transform that expands implicit vector splat operands in construct
/// instructions and binary instructions where not supported by SPIR-V.
-class ExpandImplicitSplats final : public Castable<ExpandImplicitSplats, Transform> {
- public:
- /// Constructor
- ExpandImplicitSplats();
- /// Destructor
- ~ExpandImplicitSplats() override;
-
- /// @copydoc Transform::Run
- void Run(ir::Module* module) const override;
-};
+/// @param module the module to transform
+/// @returns an error string on failure
+Result<SuccessType, std::string> ExpandImplicitSplats(Module* module);
} // namespace tint::ir::transform
diff --git a/src/tint/lang/core/ir/transform/expand_implicit_splats_test.cc b/src/tint/lang/core/ir/transform/expand_implicit_splats_test.cc
index 8aacea6..0f69610 100644
--- a/src/tint/lang/core/ir/transform/expand_implicit_splats_test.cc
+++ b/src/tint/lang/core/ir/transform/expand_implicit_splats_test.cc
@@ -45,7 +45,7 @@
}
)";
- Run<ExpandImplicitSplats>();
+ Run(ExpandImplicitSplats);
EXPECT_EQ(expect, str());
}
@@ -70,7 +70,7 @@
}
)";
- Run<ExpandImplicitSplats>();
+ Run(ExpandImplicitSplats);
EXPECT_EQ(expect, str());
}
@@ -94,7 +94,7 @@
}
)";
- Run<ExpandImplicitSplats>();
+ Run(ExpandImplicitSplats);
EXPECT_EQ(expect, str());
}
@@ -128,7 +128,7 @@
}
)";
- Run<ExpandImplicitSplats>();
+ Run(ExpandImplicitSplats);
EXPECT_EQ(expect, str());
}
@@ -162,7 +162,7 @@
}
)";
- Run<ExpandImplicitSplats>();
+ Run(ExpandImplicitSplats);
EXPECT_EQ(expect, str());
}
@@ -196,7 +196,7 @@
}
)";
- Run<ExpandImplicitSplats>();
+ Run(ExpandImplicitSplats);
EXPECT_EQ(expect, str());
}
@@ -232,7 +232,7 @@
}
)";
- Run<ExpandImplicitSplats>();
+ Run(ExpandImplicitSplats);
EXPECT_EQ(expect, str());
}
@@ -268,7 +268,7 @@
}
)";
- Run<ExpandImplicitSplats>();
+ Run(ExpandImplicitSplats);
EXPECT_EQ(expect, str());
}
@@ -304,7 +304,7 @@
}
)";
- Run<ExpandImplicitSplats>();
+ Run(ExpandImplicitSplats);
EXPECT_EQ(expect, str());
}
@@ -340,7 +340,7 @@
}
)";
- Run<ExpandImplicitSplats>();
+ Run(ExpandImplicitSplats);
EXPECT_EQ(expect, str());
}
@@ -376,7 +376,7 @@
}
)";
- Run<ExpandImplicitSplats>();
+ Run(ExpandImplicitSplats);
EXPECT_EQ(expect, str());
}
@@ -412,7 +412,7 @@
}
)";
- Run<ExpandImplicitSplats>();
+ Run(ExpandImplicitSplats);
EXPECT_EQ(expect, str());
}
@@ -448,7 +448,7 @@
}
)";
- Run<ExpandImplicitSplats>();
+ Run(ExpandImplicitSplats);
EXPECT_EQ(expect, str());
}
@@ -484,7 +484,7 @@
}
)";
- Run<ExpandImplicitSplats>();
+ Run(ExpandImplicitSplats);
EXPECT_EQ(expect, str());
}
@@ -519,7 +519,7 @@
}
)";
- Run<ExpandImplicitSplats>();
+ Run(ExpandImplicitSplats);
EXPECT_EQ(expect, str());
}
@@ -554,7 +554,7 @@
}
)";
- Run<ExpandImplicitSplats>();
+ Run(ExpandImplicitSplats);
EXPECT_EQ(expect, str());
}
@@ -590,7 +590,7 @@
}
)";
- Run<ExpandImplicitSplats>();
+ Run(ExpandImplicitSplats);
EXPECT_EQ(expect, str());
}
@@ -626,7 +626,7 @@
}
)";
- Run<ExpandImplicitSplats>();
+ Run(ExpandImplicitSplats);
EXPECT_EQ(expect, str());
}
@@ -663,7 +663,7 @@
}
)";
- Run<ExpandImplicitSplats>();
+ Run(ExpandImplicitSplats);
EXPECT_EQ(expect, str());
}
diff --git a/src/tint/lang/spirv/writer/printer/printer.cc b/src/tint/lang/spirv/writer/printer/printer.cc
index 1fff9fa..b29f5aa 100644
--- a/src/tint/lang/spirv/writer/printer/printer.cc
+++ b/src/tint/lang/spirv/writer/printer/printer.cc
@@ -109,8 +109,8 @@
ir::transform::BlockDecoratedStructs{}.Run(module);
ir::transform::BuiltinPolyfillSpirv{}.Run(module);
ir::transform::DemoteToHelper{}.Run(module);
- ir::transform::ExpandImplicitSplats{}.Run(module);
+ RUN_TRANSFORM(ExpandImplicitSplats);
RUN_TRANSFORM(HandleMatrixArithmetic);
RUN_TRANSFORM(MergeReturn);
RUN_TRANSFORM(ShaderIOSpirv);