blob: d7d3032837dd8fa82789f30ee458c4b3097e5277 [file] [log] [blame]
Austin Engcc2516a2023-10-17 20:57:54 +00001// Copyright 2023 The Dawn & Tint Authors
dan sinclairbdbbffb2023-05-26 11:42:22 +00002//
Austin Engcc2516a2023-10-17 20:57:54 +00003// Redistribution and use in source and binary forms, with or without
4// modification, are permitted provided that the following conditions are met:
dan sinclairbdbbffb2023-05-26 11:42:22 +00005//
Austin Engcc2516a2023-10-17 20:57:54 +00006// 1. Redistributions of source code must retain the above copyright notice, this
7// list of conditions and the following disclaimer.
dan sinclairbdbbffb2023-05-26 11:42:22 +00008//
Austin Engcc2516a2023-10-17 20:57:54 +00009// 2. Redistributions in binary form must reproduce the above copyright notice,
10// this list of conditions and the following disclaimer in the documentation
11// and/or other materials provided with the distribution.
12//
13// 3. Neither the name of the copyright holder nor the names of its
14// contributors may be used to endorse or promote products derived from
15// this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dan sinclairbdbbffb2023-05-26 11:42:22 +000027
dan sinclair97c37272023-07-24 17:11:53 +000028#ifndef SRC_TINT_LANG_CORE_IR_EXIT_SWITCH_H_
29#define SRC_TINT_LANG_CORE_IR_EXIT_SWITCH_H_
dan sinclairbdbbffb2023-05-26 11:42:22 +000030
dan sinclaird8a06ae2023-09-06 19:26:56 +000031#include <string>
32
dan sinclair97c37272023-07-24 17:11:53 +000033#include "src/tint/lang/core/ir/exit.h"
dan sinclair22b4dd22023-07-21 00:40:07 +000034#include "src/tint/utils/rtti/castable.h"
dan sinclairbdbbffb2023-05-26 11:42:22 +000035
36// Forward declarations
dan sinclair6f138fe2023-08-15 21:29:34 +000037namespace tint::core::ir {
dan sinclairbdbbffb2023-05-26 11:42:22 +000038class Switch;
dan sinclair6f138fe2023-08-15 21:29:34 +000039} // namespace tint::core::ir
dan sinclairbdbbffb2023-05-26 11:42:22 +000040
dan sinclair6f138fe2023-08-15 21:29:34 +000041namespace tint::core::ir {
dan sinclairbdbbffb2023-05-26 11:42:22 +000042
43/// A exit switch instruction.
dan sinclair16cb4bd2023-09-21 08:52:11 +000044class ExitSwitch final : public Castable<ExitSwitch, Exit> {
dan sinclairbdbbffb2023-05-26 11:42:22 +000045 public:
dan sinclair4934dc02023-06-16 12:11:56 +000046 /// The base offset in Operands() for the args
47 static constexpr size_t kArgsOperandOffset = 0;
48
Ben Claytonf8db1ec2023-12-13 10:04:25 +000049 /// Constructor (no operands, no switch)
50 ExitSwitch();
51
dan sinclairbdbbffb2023-05-26 11:42:22 +000052 /// Constructor
53 /// @param sw the switch being exited
Ben Claytonb2746782023-06-21 10:25:50 +000054 /// @param args the target MultiInBlock arguments
dan sinclairbae54e72023-07-28 15:01:54 +000055 explicit ExitSwitch(ir::Switch* sw, VectorRef<Value*> args = tint::Empty);
dan sinclairbdbbffb2023-05-26 11:42:22 +000056 ~ExitSwitch() override;
57
dan sinclair16cb4bd2023-09-21 08:52:11 +000058 /// @copydoc Instruction::Clone()
59 ExitSwitch* Clone(CloneContext& ctx) override;
60
Ben Claytonc8f07082023-06-20 16:42:21 +000061 /// Re-associates the exit with the given switch instruction
62 /// @param s the new switch to exit from
63 void SetSwitch(ir::Switch* s);
dan sinclairbdbbffb2023-05-26 11:42:22 +000064
Ben Claytonc8f07082023-06-20 16:42:21 +000065 /// @returns the switch being exited
66 ir::Switch* Switch();
dan sinclair4bf1d072023-07-13 20:18:59 +000067
Ben Claytonead8a042023-11-18 09:45:32 +000068 /// @returns the switch being exited
69 const ir::Switch* Switch() const;
70
dan sinclair4bf1d072023-07-13 20:18:59 +000071 /// @returns the friendly name for the instruction
Ben Claytonead8a042023-11-18 09:45:32 +000072 std::string FriendlyName() const override { return "exit_switch"; }
dan sinclairbdbbffb2023-05-26 11:42:22 +000073};
74
dan sinclair6f138fe2023-08-15 21:29:34 +000075} // namespace tint::core::ir
dan sinclairbdbbffb2023-05-26 11:42:22 +000076
dan sinclair97c37272023-07-24 17:11:53 +000077#endif // SRC_TINT_LANG_CORE_IR_EXIT_SWITCH_H_