[glsl] Remove Ternary instruction
We do not use this as it short-circuits.
Change-Id: I0e5c9bc0f5e7b9af71646885474c054c21f0a17c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/213875
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Auto-Submit: James Price <jrprice@google.com>
diff --git a/src/tint/lang/glsl/ir/BUILD.bazel b/src/tint/lang/glsl/ir/BUILD.bazel
index 22db5c1..4625de0 100644
--- a/src/tint/lang/glsl/ir/BUILD.bazel
+++ b/src/tint/lang/glsl/ir/BUILD.bazel
@@ -41,12 +41,10 @@
srcs = [
"builtin_call.cc",
"member_builtin_call.cc",
- "ternary.cc",
],
hdrs = [
"builtin_call.h",
"member_builtin_call.h",
- "ternary.h",
],
deps = [
"//src/tint/api/common",
@@ -81,7 +79,6 @@
srcs = [
"builtin_call_test.cc",
"member_builtin_call_test.cc",
- "ternary_test.cc",
],
deps = [
"//src/tint/api/common",
diff --git a/src/tint/lang/glsl/ir/BUILD.cmake b/src/tint/lang/glsl/ir/BUILD.cmake
index 7a70465..39c78a8 100644
--- a/src/tint/lang/glsl/ir/BUILD.cmake
+++ b/src/tint/lang/glsl/ir/BUILD.cmake
@@ -43,8 +43,6 @@
lang/glsl/ir/builtin_call.h
lang/glsl/ir/member_builtin_call.cc
lang/glsl/ir/member_builtin_call.h
- lang/glsl/ir/ternary.cc
- lang/glsl/ir/ternary.h
)
tint_target_add_dependencies(tint_lang_glsl_ir lib
@@ -82,7 +80,6 @@
tint_add_target(tint_lang_glsl_ir_test test
lang/glsl/ir/builtin_call_test.cc
lang/glsl/ir/member_builtin_call_test.cc
- lang/glsl/ir/ternary_test.cc
)
tint_target_add_dependencies(tint_lang_glsl_ir_test test
diff --git a/src/tint/lang/glsl/ir/BUILD.gn b/src/tint/lang/glsl/ir/BUILD.gn
index b8e7399..b756977 100644
--- a/src/tint/lang/glsl/ir/BUILD.gn
+++ b/src/tint/lang/glsl/ir/BUILD.gn
@@ -49,8 +49,6 @@
"builtin_call.h",
"member_builtin_call.cc",
"member_builtin_call.h",
- "ternary.cc",
- "ternary.h",
]
deps = [
"${dawn_root}/src/utils:utils",
@@ -82,7 +80,6 @@
sources = [
"builtin_call_test.cc",
"member_builtin_call_test.cc",
- "ternary_test.cc",
]
deps = [
"${dawn_root}/src/utils:utils",
diff --git a/src/tint/lang/glsl/ir/ternary.cc b/src/tint/lang/glsl/ir/ternary.cc
deleted file mode 100644
index ac6d579..0000000
--- a/src/tint/lang/glsl/ir/ternary.cc
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2024 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/lang/glsl/ir/ternary.h"
-
-#include "src/tint/lang/core/ir/module.h"
-
-TINT_INSTANTIATE_TYPEINFO(tint::glsl::ir::Ternary);
-
-namespace tint::glsl::ir {
-
-Ternary::Ternary(Id id, core::ir::InstructionResult* result, VectorRef<core::ir::Value*> args)
- : Base(id) {
- AddResult(result);
- AddOperands(ArgsOperandOffset(), args);
-}
-
-Ternary::~Ternary() = default;
-
-Ternary* Ternary::Clone(core::ir::CloneContext& ctx) {
- auto new_result = ctx.Clone(Result(0));
- auto new_args = ctx.Remap<Ternary::kDefaultNumOperands>(operands_);
- return ctx.ir.CreateInstruction<Ternary>(new_result, new_args);
-}
-
-} // namespace tint::glsl::ir
diff --git a/src/tint/lang/glsl/ir/ternary.h b/src/tint/lang/glsl/ir/ternary.h
deleted file mode 100644
index 7450aca..0000000
--- a/src/tint/lang/glsl/ir/ternary.h
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright 2024 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef SRC_TINT_LANG_GLSL_IR_TERNARY_H_
-#define SRC_TINT_LANG_GLSL_IR_TERNARY_H_
-
-#include <string>
-
-#include "src/tint/lang/core/ir/call.h"
-#include "src/tint/lang/core/ir/clone_context.h"
-#include "src/tint/lang/core/ir/instruction_result.h"
-#include "src/tint/lang/core/ir/value.h"
-#include "src/tint/utils/rtti/castable.h"
-
-namespace tint::glsl::ir {
-
-/// A ternary instruction in the IR.
-class Ternary final : public Castable<Ternary, core::ir::Call> {
- public:
- /// Constructor
- ///
- /// Note, the args are in the order of (`false`, `true`, `compare`) to match select.
- /// Note, the ternary evaluates all branches, not just the selected branch.
- Ternary(Id id, core::ir::InstructionResult* result, VectorRef<core::ir::Value*> args);
-
- ~Ternary() override;
-
- /// @copydoc Instruction::Clone()
- Ternary* Clone(core::ir::CloneContext& ctx) override;
-
- /// @returns the false value
- core::ir::Value* False() const { return operands_[ArgsOperandOffset() + 0]; }
-
- /// @returns the true value
- core::ir::Value* True() const { return operands_[ArgsOperandOffset() + 1]; }
-
- /// @returns the compare value
- core::ir::Value* Cmp() const { return operands_[ArgsOperandOffset() + 2]; }
-
- /// @returns the friendly name for the instruction
- std::string FriendlyName() const override { return "glsl.ternary"; }
-};
-
-} // namespace tint::glsl::ir
-
-#endif // SRC_TINT_LANG_GLSL_IR_TERNARY_H_
diff --git a/src/tint/lang/glsl/ir/ternary_test.cc b/src/tint/lang/glsl/ir/ternary_test.cc
deleted file mode 100644
index 3ec251a..0000000
--- a/src/tint/lang/glsl/ir/ternary_test.cc
+++ /dev/null
@@ -1,95 +0,0 @@
-// Copyright 2024 The Dawn & Tint Authors
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this
-// list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "src/tint/lang/glsl/ir/ternary.h"
-
-#include "gmock/gmock.h"
-#include "src/tint/lang/core/ir/ir_helper_test.h"
-
-using namespace tint::core::fluent_types; // NOLINT
-using namespace tint::core::number_suffixes; // NOLINT
-
-namespace tint::glsl::ir {
-namespace {
-
-using HlslIRTest = core::ir::IRTestHelper;
-using HlslIRDeathTest = HlslIRTest;
-
-TEST_F(HlslIRTest, SetsUsage) {
- auto* true_ = b.Constant(u32(1));
- auto* false_ = b.Constant(u32(2));
- auto* cmp = b.Constant(true);
-
- Vector<core::ir::Value*, 3> args = {false_, true_, cmp};
- auto* t = b.ir.CreateInstruction<Ternary>(b.InstructionResult(ty.u32()), args);
-
- EXPECT_THAT(false_->UsagesUnsorted(), testing::UnorderedElementsAre(core::ir::Usage{t, 0u}));
- EXPECT_THAT(true_->UsagesUnsorted(), testing::UnorderedElementsAre(core::ir::Usage{t, 1u}));
- EXPECT_THAT(cmp->UsagesUnsorted(), testing::UnorderedElementsAre(core::ir::Usage{t, 2u}));
-}
-
-TEST_F(HlslIRTest, Result) {
- auto* true_ = b.Constant(u32(1));
- auto* false_ = b.Constant(u32(2));
- auto* cmp = b.Constant(true);
-
- Vector<core::ir::Value*, 3> args = {false_, true_, cmp};
- auto* t = b.ir.CreateInstruction<Ternary>(b.InstructionResult(ty.u32()), args);
-
- EXPECT_EQ(t->Results().Length(), 1u);
-
- EXPECT_TRUE(t->Result(0)->Is<core::ir::InstructionResult>());
- EXPECT_EQ(t, t->Result(0)->Instruction());
-}
-
-TEST_F(HlslIRTest, Clone) {
- auto* true_ = b.Constant(u32(1));
- auto* false_ = b.Constant(u32(2));
- auto* cmp = b.Constant(true);
-
- Vector<core::ir::Value*, 3> args = {false_, true_, cmp};
- auto* t = b.ir.CreateInstruction<Ternary>(b.InstructionResult(ty.u32()), args);
-
- auto* new_t = clone_ctx.Clone(t);
-
- EXPECT_NE(t, new_t);
-
- EXPECT_NE(t->Result(0), new_t->Result(0));
- EXPECT_EQ(ty.u32(), new_t->Result(0)->Type());
-
- EXPECT_NE(nullptr, new_t->True());
- EXPECT_EQ(t->True(), new_t->True());
-
- EXPECT_NE(nullptr, new_t->False());
- EXPECT_EQ(t->False(), new_t->False());
-
- EXPECT_NE(nullptr, new_t->Cmp());
- EXPECT_EQ(t->Cmp(), new_t->Cmp());
-}
-
-} // namespace
-} // namespace tint::glsl::ir
diff --git a/src/tint/lang/glsl/writer/printer/printer.cc b/src/tint/lang/glsl/writer/printer/printer.cc
index f067abb..a2a1eec 100644
--- a/src/tint/lang/glsl/writer/printer/printer.cc
+++ b/src/tint/lang/glsl/writer/printer/printer.cc
@@ -82,7 +82,6 @@
#include "src/tint/lang/core/type/void.h"
#include "src/tint/lang/glsl/ir/builtin_call.h"
#include "src/tint/lang/glsl/ir/member_builtin_call.h"
-#include "src/tint/lang/glsl/ir/ternary.h"
#include "src/tint/lang/glsl/writer/common/printer_support.h"
#include "src/tint/lang/glsl/writer/common/version.h"
#include "src/tint/utils/containers/map.h"
@@ -1208,7 +1207,6 @@
[&](const glsl::ir::MemberBuiltinCall* mbc) {
EmitGlslMemberBuiltinCall(out, mbc);
},
- [&](const glsl::ir::Ternary* t) { EmitTernary(out, t); }, //
TINT_ICE_ON_NO_MATCH);
},
@@ -1284,17 +1282,6 @@
out << ")";
}
- void EmitTernary(StringStream& out, const glsl::ir::Ternary* t) {
- out << "((";
- EmitValue(out, t->Cmp());
- out << ") ? (";
- EmitValue(out, t->True());
- out << ") : (";
- EmitValue(out, t->False());
- out << "))";
- return;
- }
-
/// Emit a convert instruction
void EmitConvert(StringStream& out, const core::ir::Convert* c) {
EmitType(out, c->Result(0)->Type());
diff --git a/src/tint/lang/glsl/writer/raise/builtin_polyfill.cc b/src/tint/lang/glsl/writer/raise/builtin_polyfill.cc
index b82c366..df1ec1d 100644
--- a/src/tint/lang/glsl/writer/raise/builtin_polyfill.cc
+++ b/src/tint/lang/glsl/writer/raise/builtin_polyfill.cc
@@ -43,7 +43,6 @@
#include "src/tint/lang/glsl/builtin_fn.h"
#include "src/tint/lang/glsl/ir/builtin_call.h"
#include "src/tint/lang/glsl/ir/member_builtin_call.h"
-#include "src/tint/lang/glsl/ir/ternary.h"
namespace tint::glsl::writer::raise {
namespace {