[ir] Add BuiltinCall base class.
This CL adds a base class of CoreBuiltinCall with leaves the
builtin::Function in CoreBuiltinCall. This will allow other backends to
create specific builtin call classes.
Bug: tint:1718
Change-Id: I84ac3eab3511f655980a8bdad4f4c92e2f723761
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/141240
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn
index 16546f2..467d112 100644
--- a/src/tint/BUILD.gn
+++ b/src/tint/BUILD.gn
@@ -1280,6 +1280,8 @@
"ir/break_if.h",
"ir/builder.cc",
"ir/builder.h",
+ "ir/builtin_call.cc",
+ "ir/builtin_call.h",
"ir/call.cc",
"ir/call.h",
"ir/constant.cc",
diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt
index 665f5ed..b53cffd 100644
--- a/src/tint/CMakeLists.txt
+++ b/src/tint/CMakeLists.txt
@@ -763,6 +763,8 @@
ir/break_if.h
ir/builder.cc
ir/builder.h
+ ir/builtin_call.cc
+ ir/builtin_call.h
ir/call.cc
ir/call.h
ir/constant.cc
diff --git a/src/tint/ir/builtin_call.cc b/src/tint/ir/builtin_call.cc
new file mode 100644
index 0000000..b8b2758
--- /dev/null
+++ b/src/tint/ir/builtin_call.cc
@@ -0,0 +1,32 @@
+// 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/ir/builtin_call.h"
+
+#include <utility>
+
+#include "src/tint/debug.h"
+
+TINT_INSTANTIATE_TYPEINFO(tint::ir::BuiltinCall);
+
+namespace tint::ir {
+
+BuiltinCall::BuiltinCall(InstructionResult* result, utils::VectorRef<Value*> arguments) {
+ AddOperands(BuiltinCall::kArgsOperandOffset, std::move(arguments));
+ AddResult(result);
+}
+
+BuiltinCall::~BuiltinCall() = default;
+
+} // namespace tint::ir
diff --git a/src/tint/ir/builtin_call.h b/src/tint/ir/builtin_call.h
new file mode 100644
index 0000000..06cf148
--- /dev/null
+++ b/src/tint/ir/builtin_call.h
@@ -0,0 +1,38 @@
+// 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_IR_BUILTIN_CALL_H_
+#define SRC_TINT_IR_BUILTIN_CALL_H_
+
+#include "src/tint/ir/call.h"
+#include "src/tint/utils/castable.h"
+
+namespace tint::ir {
+
+/// A builtin call instruction in the IR.
+class BuiltinCall : public utils::Castable<BuiltinCall, Call> {
+ public:
+ /// The base offset in Operands() for the args
+ static constexpr size_t kArgsOperandOffset = 0;
+
+ /// Constructor
+ /// @param result the result value
+ /// @param args the conversion arguments
+ explicit BuiltinCall(InstructionResult* result, utils::VectorRef<Value*> args = utils::Empty);
+ ~BuiltinCall() override;
+};
+
+} // namespace tint::ir
+
+#endif // SRC_TINT_IR_BUILTIN_CALL_H_
diff --git a/src/tint/ir/core_builtin_call.cc b/src/tint/ir/core_builtin_call.cc
index d6a6ab3..8fae040 100644
--- a/src/tint/ir/core_builtin_call.cc
+++ b/src/tint/ir/core_builtin_call.cc
@@ -25,12 +25,9 @@
CoreBuiltinCall::CoreBuiltinCall(InstructionResult* result,
builtin::Function func,
utils::VectorRef<Value*> arguments)
- : func_(func) {
+ : Base(result, arguments), func_(func) {
TINT_ASSERT(IR, func != builtin::Function::kNone);
TINT_ASSERT(IR, func != builtin::Function::kTintMaterialize);
-
- AddOperands(CoreBuiltinCall::kArgsOperandOffset, std::move(arguments));
- AddResult(result);
}
CoreBuiltinCall::~CoreBuiltinCall() = default;
diff --git a/src/tint/ir/core_builtin_call.h b/src/tint/ir/core_builtin_call.h
index 8b7228f..4157a41 100644
--- a/src/tint/ir/core_builtin_call.h
+++ b/src/tint/ir/core_builtin_call.h
@@ -16,17 +16,14 @@
#define SRC_TINT_IR_CORE_BUILTIN_CALL_H_
#include "src/tint/builtin/function.h"
-#include "src/tint/ir/call.h"
+#include "src/tint/ir/builtin_call.h"
#include "src/tint/utils/castable.h"
namespace tint::ir {
/// A core builtin call instruction in the IR.
-class CoreBuiltinCall : public utils::Castable<CoreBuiltinCall, Call> {
+class CoreBuiltinCall : public utils::Castable<CoreBuiltinCall, BuiltinCall> {
public:
- /// The base offset in Operands() for the args
- static constexpr size_t kArgsOperandOffset = 0;
-
/// Constructor
/// @param result the result value
/// @param func the builtin function