blob: 9181a4c5124738ca4446f0e297d9646da9b79f0c [file] [log] [blame]
Austin Engcc2516a2023-10-17 20:57:54 +00001// Copyright 2023 The Dawn & Tint Authors
James Price90b8cc12023-05-17 18:41:27 +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:
James Price90b8cc12023-05-17 18:41:27 +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.
James Price90b8cc12023-05-17 18:41:27 +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.
James Price90b8cc12023-05-17 18:41:27 +000027
dan sinclair97c37272023-07-24 17:11:53 +000028#ifndef SRC_TINT_LANG_CORE_IR_LOAD_H_
29#define SRC_TINT_LANG_CORE_IR_LOAD_H_
James Price90b8cc12023-05-17 18:41:27 +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/operand_instruction.h"
dan sinclair22b4dd22023-07-21 00:40:07 +000034#include "src/tint/utils/rtti/castable.h"
James Price90b8cc12023-05-17 18:41:27 +000035
dan sinclair6f138fe2023-08-15 21:29:34 +000036namespace tint::core::ir {
James Price90b8cc12023-05-17 18:41:27 +000037
38/// A load instruction in the IR.
dan sinclair16cb4bd2023-09-21 08:52:11 +000039class Load final : public Castable<Load, OperandInstruction<1, 1>> {
James Price90b8cc12023-05-17 18:41:27 +000040 public:
dan sinclair4934dc02023-06-16 12:11:56 +000041 /// The offset in Operands() for the from value
42 static constexpr size_t kFromOperandOffset = 0;
43
Ryan Harrison23c42fc2024-07-12 02:32:25 +000044 /// 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 Claytoncba30d22023-12-07 13:17:53 +000050 /// Constructor (no results, no operands)
dan sinclair9eeb7b12024-08-06 14:00:27 +000051 /// @param id the instruction id
52 explicit Load(Id id);
Ben Claytoncba30d22023-12-07 13:17:53 +000053
James Price87a211c2024-01-11 15:11:17 +000054 /// Constructor
dan sinclair9eeb7b12024-08-06 14:00:27 +000055 /// @param id the instruction id
dan sinclair0d80c3d2023-06-19 13:32:03 +000056 /// @param result the result value
Ben Clayton039ffdc2023-06-09 22:58:09 +000057 /// @param from the value being loaded from
dan sinclair9eeb7b12024-08-06 14:00:27 +000058 Load(Id id, InstructionResult* result, Value* from);
Ben Clayton039ffdc2023-06-09 22:58:09 +000059
James Price90b8cc12023-05-17 18:41:27 +000060 ~Load() override;
61
dan sinclair16cb4bd2023-09-21 08:52:11 +000062 /// @copydoc Instruction::Clone()
63 Load* Clone(CloneContext& ctx) override;
64
James Priceae8a9f92023-06-06 19:37:51 +000065 /// @returns the value being loaded from
Ben Claytondff17072024-05-27 22:01:03 +000066 Value* From() { return Operand(kFromOperandOffset); }
dan sinclair4bf1d072023-07-13 20:18:59 +000067
Ben Claytonead8a042023-11-18 09:45:32 +000068 /// @returns the value being loaded from
Ben Claytondff17072024-05-27 22:01:03 +000069 const Value* From() const { return Operand(kFromOperandOffset); }
Ben Claytonead8a042023-11-18 09:45:32 +000070
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 "load"; }
dan sinclair3d645652024-11-19 15:29:05 +000073
74 /// @returns the side effects for this instruction
75 Accesses GetSideEffects() const override;
James Price90b8cc12023-05-17 18:41:27 +000076};
77
dan sinclair6f138fe2023-08-15 21:29:34 +000078} // namespace tint::core::ir
James Price90b8cc12023-05-17 18:41:27 +000079
dan sinclair97c37272023-07-24 17:11:53 +000080#endif // SRC_TINT_LANG_CORE_IR_LOAD_H_