Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 1 | // Copyright 2023 The Dawn & Tint Authors |
dan sinclair | bdbbffb | 2023-05-26 11:42:22 +0000 | [diff] [blame] | 2 | // |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 3 | // Redistribution and use in source and binary forms, with or without |
| 4 | // modification, are permitted provided that the following conditions are met: |
dan sinclair | bdbbffb | 2023-05-26 11:42:22 +0000 | [diff] [blame] | 5 | // |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 6 | // 1. Redistributions of source code must retain the above copyright notice, this |
| 7 | // list of conditions and the following disclaimer. |
dan sinclair | bdbbffb | 2023-05-26 11:42:22 +0000 | [diff] [blame] | 8 | // |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 9 | // 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 sinclair | bdbbffb | 2023-05-26 11:42:22 +0000 | [diff] [blame] | 27 | |
dan sinclair | 97c3727 | 2023-07-24 17:11:53 +0000 | [diff] [blame] | 28 | #ifndef SRC_TINT_LANG_CORE_IR_EXIT_SWITCH_H_ |
| 29 | #define SRC_TINT_LANG_CORE_IR_EXIT_SWITCH_H_ |
dan sinclair | bdbbffb | 2023-05-26 11:42:22 +0000 | [diff] [blame] | 30 | |
dan sinclair | d8a06ae | 2023-09-06 19:26:56 +0000 | [diff] [blame] | 31 | #include <string> |
| 32 | |
dan sinclair | 97c3727 | 2023-07-24 17:11:53 +0000 | [diff] [blame] | 33 | #include "src/tint/lang/core/ir/exit.h" |
dan sinclair | 22b4dd2 | 2023-07-21 00:40:07 +0000 | [diff] [blame] | 34 | #include "src/tint/utils/rtti/castable.h" |
dan sinclair | bdbbffb | 2023-05-26 11:42:22 +0000 | [diff] [blame] | 35 | |
| 36 | // Forward declarations |
dan sinclair | 6f138fe | 2023-08-15 21:29:34 +0000 | [diff] [blame] | 37 | namespace tint::core::ir { |
dan sinclair | bdbbffb | 2023-05-26 11:42:22 +0000 | [diff] [blame] | 38 | class Switch; |
dan sinclair | 6f138fe | 2023-08-15 21:29:34 +0000 | [diff] [blame] | 39 | } // namespace tint::core::ir |
dan sinclair | bdbbffb | 2023-05-26 11:42:22 +0000 | [diff] [blame] | 40 | |
dan sinclair | 6f138fe | 2023-08-15 21:29:34 +0000 | [diff] [blame] | 41 | namespace tint::core::ir { |
dan sinclair | bdbbffb | 2023-05-26 11:42:22 +0000 | [diff] [blame] | 42 | |
| 43 | /// A exit switch instruction. |
dan sinclair | 16cb4bd | 2023-09-21 08:52:11 +0000 | [diff] [blame] | 44 | class ExitSwitch final : public Castable<ExitSwitch, Exit> { |
dan sinclair | bdbbffb | 2023-05-26 11:42:22 +0000 | [diff] [blame] | 45 | public: |
dan sinclair | 4934dc0 | 2023-06-16 12:11:56 +0000 | [diff] [blame] | 46 | /// The base offset in Operands() for the args |
| 47 | static constexpr size_t kArgsOperandOffset = 0; |
| 48 | |
Ben Clayton | f8db1ec | 2023-12-13 10:04:25 +0000 | [diff] [blame] | 49 | /// Constructor (no operands, no switch) |
| 50 | ExitSwitch(); |
| 51 | |
dan sinclair | bdbbffb | 2023-05-26 11:42:22 +0000 | [diff] [blame] | 52 | /// Constructor |
| 53 | /// @param sw the switch being exited |
Ben Clayton | b274678 | 2023-06-21 10:25:50 +0000 | [diff] [blame] | 54 | /// @param args the target MultiInBlock arguments |
dan sinclair | bae54e7 | 2023-07-28 15:01:54 +0000 | [diff] [blame] | 55 | explicit ExitSwitch(ir::Switch* sw, VectorRef<Value*> args = tint::Empty); |
dan sinclair | bdbbffb | 2023-05-26 11:42:22 +0000 | [diff] [blame] | 56 | ~ExitSwitch() override; |
| 57 | |
dan sinclair | 16cb4bd | 2023-09-21 08:52:11 +0000 | [diff] [blame] | 58 | /// @copydoc Instruction::Clone() |
| 59 | ExitSwitch* Clone(CloneContext& ctx) override; |
| 60 | |
Ben Clayton | c8f0708 | 2023-06-20 16:42:21 +0000 | [diff] [blame] | 61 | /// 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 sinclair | bdbbffb | 2023-05-26 11:42:22 +0000 | [diff] [blame] | 64 | |
Ben Clayton | c8f0708 | 2023-06-20 16:42:21 +0000 | [diff] [blame] | 65 | /// @returns the switch being exited |
| 66 | ir::Switch* Switch(); |
dan sinclair | 4bf1d07 | 2023-07-13 20:18:59 +0000 | [diff] [blame] | 67 | |
Ben Clayton | ead8a04 | 2023-11-18 09:45:32 +0000 | [diff] [blame] | 68 | /// @returns the switch being exited |
| 69 | const ir::Switch* Switch() const; |
| 70 | |
dan sinclair | 4bf1d07 | 2023-07-13 20:18:59 +0000 | [diff] [blame] | 71 | /// @returns the friendly name for the instruction |
Ben Clayton | ead8a04 | 2023-11-18 09:45:32 +0000 | [diff] [blame] | 72 | std::string FriendlyName() const override { return "exit_switch"; } |
dan sinclair | bdbbffb | 2023-05-26 11:42:22 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
dan sinclair | 6f138fe | 2023-08-15 21:29:34 +0000 | [diff] [blame] | 75 | } // namespace tint::core::ir |
dan sinclair | bdbbffb | 2023-05-26 11:42:22 +0000 | [diff] [blame] | 76 | |
dan sinclair | 97c3727 | 2023-07-24 17:11:53 +0000 | [diff] [blame] | 77 | #endif // SRC_TINT_LANG_CORE_IR_EXIT_SWITCH_H_ |