Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 1 | // Copyright 2023 The Dawn & Tint Authors |
James Price | 90b8cc1 | 2023-05-17 18:41:27 +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: |
James Price | 90b8cc1 | 2023-05-17 18:41:27 +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. |
James Price | 90b8cc1 | 2023-05-17 18:41:27 +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. |
James Price | 90b8cc1 | 2023-05-17 18:41:27 +0000 | [diff] [blame] | 27 | |
dan sinclair | 97c3727 | 2023-07-24 17:11:53 +0000 | [diff] [blame] | 28 | #ifndef SRC_TINT_LANG_CORE_IR_LOAD_H_ |
| 29 | #define SRC_TINT_LANG_CORE_IR_LOAD_H_ |
James Price | 90b8cc1 | 2023-05-17 18:41:27 +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/operand_instruction.h" |
dan sinclair | 22b4dd2 | 2023-07-21 00:40:07 +0000 | [diff] [blame] | 34 | #include "src/tint/utils/rtti/castable.h" |
James Price | 90b8cc1 | 2023-05-17 18:41:27 +0000 | [diff] [blame] | 35 | |
dan sinclair | 6f138fe | 2023-08-15 21:29:34 +0000 | [diff] [blame] | 36 | namespace tint::core::ir { |
James Price | 90b8cc1 | 2023-05-17 18:41:27 +0000 | [diff] [blame] | 37 | |
| 38 | /// A load instruction in the IR. |
dan sinclair | 16cb4bd | 2023-09-21 08:52:11 +0000 | [diff] [blame] | 39 | class Load final : public Castable<Load, OperandInstruction<1, 1>> { |
James Price | 90b8cc1 | 2023-05-17 18:41:27 +0000 | [diff] [blame] | 40 | public: |
dan sinclair | 4934dc0 | 2023-06-16 12:11:56 +0000 | [diff] [blame] | 41 | /// The offset in Operands() for the from value |
| 42 | static constexpr size_t kFromOperandOffset = 0; |
| 43 | |
Ryan Harrison | 23c42fc | 2024-07-12 02:32:25 +0000 | [diff] [blame] | 44 | /// The fixed number of results returned by this instruction |
| 45 | static constexpr size_t kNumResults = 1; |
| 46 | |
| 47 | /// The fixed number of operands used by this instruction |
| 48 | static constexpr size_t kNumOperands = 1; |
| 49 | |
Ben Clayton | cba30d2 | 2023-12-07 13:17:53 +0000 | [diff] [blame] | 50 | /// Constructor (no results, no operands) |
dan sinclair | 9eeb7b1 | 2024-08-06 14:00:27 +0000 | [diff] [blame] | 51 | /// @param id the instruction id |
| 52 | explicit Load(Id id); |
Ben Clayton | cba30d2 | 2023-12-07 13:17:53 +0000 | [diff] [blame] | 53 | |
James Price | 87a211c | 2024-01-11 15:11:17 +0000 | [diff] [blame] | 54 | /// Constructor |
dan sinclair | 9eeb7b1 | 2024-08-06 14:00:27 +0000 | [diff] [blame] | 55 | /// @param id the instruction id |
dan sinclair | 0d80c3d | 2023-06-19 13:32:03 +0000 | [diff] [blame] | 56 | /// @param result the result value |
Ben Clayton | 039ffdc | 2023-06-09 22:58:09 +0000 | [diff] [blame] | 57 | /// @param from the value being loaded from |
dan sinclair | 9eeb7b1 | 2024-08-06 14:00:27 +0000 | [diff] [blame] | 58 | Load(Id id, InstructionResult* result, Value* from); |
Ben Clayton | 039ffdc | 2023-06-09 22:58:09 +0000 | [diff] [blame] | 59 | |
James Price | 90b8cc1 | 2023-05-17 18:41:27 +0000 | [diff] [blame] | 60 | ~Load() override; |
| 61 | |
dan sinclair | 16cb4bd | 2023-09-21 08:52:11 +0000 | [diff] [blame] | 62 | /// @copydoc Instruction::Clone() |
| 63 | Load* Clone(CloneContext& ctx) override; |
| 64 | |
James Price | ae8a9f9 | 2023-06-06 19:37:51 +0000 | [diff] [blame] | 65 | /// @returns the value being loaded from |
Ben Clayton | dff1707 | 2024-05-27 22:01:03 +0000 | [diff] [blame] | 66 | Value* From() { return Operand(kFromOperandOffset); } |
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 value being loaded from |
Ben Clayton | dff1707 | 2024-05-27 22:01:03 +0000 | [diff] [blame] | 69 | const Value* From() const { return Operand(kFromOperandOffset); } |
Ben Clayton | ead8a04 | 2023-11-18 09:45:32 +0000 | [diff] [blame] | 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 "load"; } |
dan sinclair | 3d64565 | 2024-11-19 15:29:05 +0000 | [diff] [blame] | 73 | |
| 74 | /// @returns the side effects for this instruction |
| 75 | Accesses GetSideEffects() const override; |
James Price | 90b8cc1 | 2023-05-17 18:41:27 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
dan sinclair | 6f138fe | 2023-08-15 21:29:34 +0000 | [diff] [blame] | 78 | } // namespace tint::core::ir |
James Price | 90b8cc1 | 2023-05-17 18:41:27 +0000 | [diff] [blame] | 79 | |
dan sinclair | 97c3727 | 2023-07-24 17:11:53 +0000 | [diff] [blame] | 80 | #endif // SRC_TINT_LANG_CORE_IR_LOAD_H_ |