[ir] Convert HandleMatrixArithmetic to a free function
Bug: tint:1718
Change-Id: I7b1a4bd2f97cb67123b2ed4b1459cba5c080b8ad
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/143823
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/tint/lang/core/ir/transform/handle_matrix_arithmetic.cc b/src/tint/lang/core/ir/transform/handle_matrix_arithmetic.cc
index 40d2190..67a86d0 100644
--- a/src/tint/lang/core/ir/transform/handle_matrix_arithmetic.cc
+++ b/src/tint/lang/core/ir/transform/handle_matrix_arithmetic.cc
@@ -18,20 +18,17 @@
#include "src/tint/lang/core/ir/builder.h"
#include "src/tint/lang/core/ir/module.h"
+#include "src/tint/lang/core/ir/validator.h"
#include "src/tint/lang/core/type/matrix.h"
#include "src/tint/utils/ice/ice.h"
-TINT_INSTANTIATE_TYPEINFO(tint::ir::transform::HandleMatrixArithmetic);
-
using namespace tint::number_suffixes; // NOLINT
namespace tint::ir::transform {
-HandleMatrixArithmetic::HandleMatrixArithmetic() = default;
+namespace {
-HandleMatrixArithmetic::~HandleMatrixArithmetic() = default;
-
-void HandleMatrixArithmetic::Run(ir::Module* ir) const {
+void Run(ir::Module* ir) {
ir::Builder b(*ir);
// Find the instructions that need to be modified.
@@ -146,4 +143,17 @@
}
}
+} // namespace
+
+Result<SuccessType, std::string> HandleMatrixArithmetic(Module* ir) {
+ auto result = ValidateAndDumpIfNeeded(*ir, "HandleMatrixArithmetic transform");
+ if (!result) {
+ return result;
+ }
+
+ Run(ir);
+
+ return Success;
+}
+
} // namespace tint::ir::transform
diff --git a/src/tint/lang/core/ir/transform/handle_matrix_arithmetic.h b/src/tint/lang/core/ir/transform/handle_matrix_arithmetic.h
index f55e919..aeec374 100644
--- a/src/tint/lang/core/ir/transform/handle_matrix_arithmetic.h
+++ b/src/tint/lang/core/ir/transform/handle_matrix_arithmetic.h
@@ -15,22 +15,22 @@
#ifndef SRC_TINT_LANG_CORE_IR_TRANSFORM_HANDLE_MATRIX_ARITHMETIC_H_
#define SRC_TINT_LANG_CORE_IR_TRANSFORM_HANDLE_MATRIX_ARITHMETIC_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 {
/// HandleMatrixArithmetic is a transform that converts arithmetic instruction that use matrix into
/// SPIR-V intrinsics or polyfills.
-class HandleMatrixArithmetic final : public Castable<HandleMatrixArithmetic, Transform> {
- public:
- /// Constructor
- HandleMatrixArithmetic();
- /// Destructor
- ~HandleMatrixArithmetic() 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> HandleMatrixArithmetic(Module* module);
} // namespace tint::ir::transform
diff --git a/src/tint/lang/core/ir/transform/handle_matrix_arithmetic_test.cc b/src/tint/lang/core/ir/transform/handle_matrix_arithmetic_test.cc
index 86fcbcc..e1dfce5 100644
--- a/src/tint/lang/core/ir/transform/handle_matrix_arithmetic_test.cc
+++ b/src/tint/lang/core/ir/transform/handle_matrix_arithmetic_test.cc
@@ -63,7 +63,7 @@
}
)";
- Run<HandleMatrixArithmetic>();
+ Run(HandleMatrixArithmetic);
EXPECT_EQ(expect, str());
}
@@ -110,7 +110,7 @@
}
)";
- Run<HandleMatrixArithmetic>();
+ Run(HandleMatrixArithmetic);
EXPECT_EQ(expect, str());
}
@@ -154,7 +154,7 @@
}
)";
- Run<HandleMatrixArithmetic>();
+ Run(HandleMatrixArithmetic);
EXPECT_EQ(expect, str());
}
@@ -195,7 +195,7 @@
}
)";
- Run<HandleMatrixArithmetic>();
+ Run(HandleMatrixArithmetic);
EXPECT_EQ(expect, str());
}
@@ -230,7 +230,7 @@
}
)";
- Run<HandleMatrixArithmetic>();
+ Run(HandleMatrixArithmetic);
EXPECT_EQ(expect, str());
}
@@ -265,7 +265,7 @@
}
)";
- Run<HandleMatrixArithmetic>();
+ Run(HandleMatrixArithmetic);
EXPECT_EQ(expect, str());
}
@@ -300,7 +300,7 @@
}
)";
- Run<HandleMatrixArithmetic>();
+ Run(HandleMatrixArithmetic);
EXPECT_EQ(expect, str());
}
@@ -335,7 +335,7 @@
}
)";
- Run<HandleMatrixArithmetic>();
+ Run(HandleMatrixArithmetic);
EXPECT_EQ(expect, str());
}
@@ -370,7 +370,7 @@
}
)";
- Run<HandleMatrixArithmetic>();
+ Run(HandleMatrixArithmetic);
EXPECT_EQ(expect, str());
}
@@ -405,7 +405,7 @@
}
)";
- Run<HandleMatrixArithmetic>();
+ Run(HandleMatrixArithmetic);
EXPECT_EQ(expect, str());
}
@@ -443,7 +443,7 @@
}
)";
- Run<HandleMatrixArithmetic>();
+ Run(HandleMatrixArithmetic);
EXPECT_EQ(expect, str());
}
@@ -485,7 +485,7 @@
}
)";
- Run<HandleMatrixArithmetic>();
+ Run(HandleMatrixArithmetic);
EXPECT_EQ(expect, str());
}
@@ -527,7 +527,7 @@
}
)";
- Run<HandleMatrixArithmetic>();
+ Run(HandleMatrixArithmetic);
EXPECT_EQ(expect, str());
}
@@ -565,7 +565,7 @@
}
)";
- Run<HandleMatrixArithmetic>();
+ Run(HandleMatrixArithmetic);
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 ecf24cb..1fff9fa 100644
--- a/src/tint/lang/spirv/writer/printer/printer.cc
+++ b/src/tint/lang/spirv/writer/printer/printer.cc
@@ -110,8 +110,8 @@
ir::transform::BuiltinPolyfillSpirv{}.Run(module);
ir::transform::DemoteToHelper{}.Run(module);
ir::transform::ExpandImplicitSplats{}.Run(module);
- ir::transform::HandleMatrixArithmetic{}.Run(module);
+ RUN_TRANSFORM(HandleMatrixArithmetic);
RUN_TRANSFORM(MergeReturn);
RUN_TRANSFORM(ShaderIOSpirv);
RUN_TRANSFORM(Std140);