dan sinclair | 0ebbc5c | 2023-11-29 17:53:24 +0000 | [diff] [blame] | 1 | // Copyright 2023 The Dawn & Tint Authors |
| 2 | // |
| 3 | // Redistribution and use in source and binary forms, with or without |
| 4 | // modification, are permitted provided that the following conditions are met: |
| 5 | // |
| 6 | // 1. Redistributions of source code must retain the above copyright notice, this |
| 7 | // list of conditions and the following disclaimer. |
| 8 | // |
| 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. |
| 27 | |
| 28 | #ifndef SRC_TINT_LANG_MSL_IR_BUILTIN_CALL_H_ |
| 29 | #define SRC_TINT_LANG_MSL_IR_BUILTIN_CALL_H_ |
| 30 | |
| 31 | #include <string> |
| 32 | |
| 33 | #include "src/tint/lang/core/intrinsic/table_data.h" |
| 34 | #include "src/tint/lang/core/ir/builtin_call.h" |
| 35 | #include "src/tint/lang/msl/builtin_fn.h" |
| 36 | #include "src/tint/lang/msl/intrinsic/dialect.h" |
| 37 | #include "src/tint/utils/rtti/castable.h" |
| 38 | |
| 39 | namespace tint::msl::ir { |
| 40 | |
| 41 | /// A msl builtin call instruction in the IR. |
| 42 | class BuiltinCall final : public Castable<BuiltinCall, core::ir::BuiltinCall> { |
| 43 | public: |
| 44 | /// Constructor |
dan sinclair | 9eeb7b1 | 2024-08-06 14:00:27 +0000 | [diff] [blame] | 45 | /// @param id the instruction id |
dan sinclair | 0ebbc5c | 2023-11-29 17:53:24 +0000 | [diff] [blame] | 46 | /// @param result the result value |
| 47 | /// @param func the builtin function |
| 48 | /// @param args the conversion arguments |
dan sinclair | 9eeb7b1 | 2024-08-06 14:00:27 +0000 | [diff] [blame] | 49 | BuiltinCall(Id id, |
| 50 | core::ir::InstructionResult* result, |
dan sinclair | 0ebbc5c | 2023-11-29 17:53:24 +0000 | [diff] [blame] | 51 | BuiltinFn func, |
| 52 | VectorRef<core::ir::Value*> args = tint::Empty); |
| 53 | ~BuiltinCall() override; |
| 54 | |
| 55 | /// @copydoc core::ir::Instruction::Clone() |
| 56 | BuiltinCall* Clone(core::ir::CloneContext& ctx) override; |
| 57 | |
| 58 | /// @returns the builtin function |
| 59 | BuiltinFn Func() const { return func_; } |
| 60 | |
| 61 | /// @returns the identifier for the function |
| 62 | size_t FuncId() const override { return static_cast<size_t>(func_); } |
| 63 | |
| 64 | /// @returns the friendly name for the instruction |
| 65 | std::string FriendlyName() const override { return std::string("msl.") + str(func_); } |
| 66 | |
| 67 | /// @returns the table data to validate this builtin |
| 68 | const core::intrinsic::TableData& TableData() const override { |
| 69 | return msl::intrinsic::Dialect::kData; |
| 70 | } |
| 71 | |
dan sinclair | 3d64565 | 2024-11-19 15:29:05 +0000 | [diff] [blame] | 72 | /// @returns an access information for the function |
| 73 | Accesses GetSideEffects() const override; |
| 74 | |
dan sinclair | 0ebbc5c | 2023-11-29 17:53:24 +0000 | [diff] [blame] | 75 | private: |
| 76 | BuiltinFn func_; |
| 77 | }; |
| 78 | |
| 79 | } // namespace tint::msl::ir |
| 80 | |
| 81 | #endif // SRC_TINT_LANG_MSL_IR_BUILTIN_CALL_H_ |