Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 1 | // Copyright 2021 The Dawn & Tint Authors |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +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: |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +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. |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +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. |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 27 | |
dan sinclair | d3b1369 | 2023-07-20 01:14:15 +0000 | [diff] [blame] | 28 | #ifndef SRC_TINT_LANG_WGSL_SEM_FUNCTION_H_ |
| 29 | #define SRC_TINT_LANG_WGSL_SEM_FUNCTION_H_ |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 30 | |
| 31 | #include <array> |
dan sinclair | 766a458 | 2022-09-06 16:00:13 +0000 | [diff] [blame] | 32 | #include <optional> |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 33 | #include <utility> |
| 34 | #include <vector> |
| 35 | |
dan sinclair | 99181d8 | 2023-07-20 01:14:15 +0000 | [diff] [blame] | 36 | #include "src/tint/lang/wgsl/ast/diagnostic_control.h" |
| 37 | #include "src/tint/lang/wgsl/ast/variable.h" |
dan sinclair | d3b1369 | 2023-07-20 01:14:15 +0000 | [diff] [blame] | 38 | #include "src/tint/lang/wgsl/sem/call.h" |
dan sinclair | 22b4dd2 | 2023-07-21 00:40:07 +0000 | [diff] [blame] | 39 | #include "src/tint/utils/containers/unique_vector.h" |
| 40 | #include "src/tint/utils/containers/vector.h" |
Ben Clayton | dc68d5c | 2023-08-01 00:37:35 +0000 | [diff] [blame] | 41 | #include "src/tint/utils/symbol/symbol.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 42 | |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 43 | // Forward declarations |
Ben Clayton | a7230f0 | 2022-04-11 14:37:21 +0000 | [diff] [blame] | 44 | namespace tint::ast { |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 45 | class BuiltinAttribute; |
| 46 | class Function; |
| 47 | class LocationAttribute; |
| 48 | class ReturnStatement; |
Ben Clayton | a7230f0 | 2022-04-11 14:37:21 +0000 | [diff] [blame] | 49 | } // namespace tint::ast |
| 50 | namespace tint::sem { |
Ben Clayton | d9766dc | 2023-09-21 12:41:20 +0000 | [diff] [blame] | 51 | class BuiltinFn; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 52 | class Variable; |
Ben Clayton | a7230f0 | 2022-04-11 14:37:21 +0000 | [diff] [blame] | 53 | } // namespace tint::sem |
dan sinclair | c990b3c | 2022-04-07 16:04:35 +0000 | [diff] [blame] | 54 | |
| 55 | namespace tint::sem { |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 56 | |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 57 | /// WorkgroupSize is a three-dimensional array of WorkgroupDimensions. |
Ben Clayton | f10a579 | 2022-10-13 13:47:39 +0000 | [diff] [blame] | 58 | /// Each dimension is a std::optional as a workgroup size can be a const-expression or |
| 59 | /// override-expression. Override expressions are not known at compilation time, so these will be |
| 60 | /// std::nullopt. |
Ben Clayton | 490d988 | 2022-09-21 21:05:45 +0000 | [diff] [blame] | 61 | using WorkgroupSize = std::array<std::optional<uint32_t>, 3>; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 62 | |
| 63 | /// Function holds the semantic information for function nodes. |
dan sinclair | bae54e7 | 2023-07-28 15:01:54 +0000 | [diff] [blame] | 64 | class Function final : public Castable<Function, CallTarget> { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 65 | public: |
Ben Clayton | 1025258 | 2023-07-25 20:53:25 +0000 | [diff] [blame] | 66 | /// A vector of [Variable*, BindingPoint] pairs |
| 67 | using VariableBindings = std::vector<std::pair<const Variable*, BindingPoint>>; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 68 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 69 | /// Constructor |
| 70 | /// @param declaration the ast::Function |
Ben Clayton | 63d0fab | 2023-03-06 15:43:16 +0000 | [diff] [blame] | 71 | explicit Function(const ast::Function* declaration); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 72 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 73 | /// Destructor |
| 74 | ~Function() override; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 75 | |
Ben Clayton | 63d0fab | 2023-03-06 15:43:16 +0000 | [diff] [blame] | 76 | /// Sets the function's return location |
| 77 | /// @param return_location the location value |
| 78 | void SetReturnLocation(uint32_t return_location) { return_location_ = return_location; } |
| 79 | |
Brandon Jones | fbc2738 | 2023-06-22 21:51:30 +0000 | [diff] [blame] | 80 | // Sets the function's return index |
| 81 | /// @param return_index the index value |
| 82 | void SetReturnIndex(uint32_t return_index) { return_index_ = return_index; } |
| 83 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 84 | /// @returns the ast::Function declaration |
| 85 | const ast::Function* Declaration() const { return declaration_; } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 86 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 87 | /// @returns the workgroup size {x, y, z} for the function. |
| 88 | const sem::WorkgroupSize& WorkgroupSize() const { return workgroup_size_; } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 89 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 90 | /// Sets the workgroup size {x, y, z} for the function. |
| 91 | /// @param workgroup_size the new workgroup size of the function |
| 92 | void SetWorkgroupSize(sem::WorkgroupSize workgroup_size) { |
| 93 | workgroup_size_ = std::move(workgroup_size); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 94 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 95 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 96 | /// @returns all directly referenced global variables |
dan sinclair | bae54e7 | 2023-07-28 15:01:54 +0000 | [diff] [blame] | 97 | const UniqueVector<const GlobalVariable*, 4>& DirectlyReferencedGlobals() const { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 98 | return directly_referenced_globals_; |
| 99 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 100 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 101 | /// Records that this function directly references the given global variable. |
Ben Clayton | 535535b | 2023-10-09 15:14:34 +0000 | [diff] [blame] | 102 | /// Note: Implicitly adds this global to the transitively-called globals. |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 103 | /// @param global the module-scope variable |
| 104 | void AddDirectlyReferencedGlobal(const sem::GlobalVariable* global) { |
Ben Clayton | dce63f5 | 2022-08-17 18:07:20 +0000 | [diff] [blame] | 105 | directly_referenced_globals_.Add(global); |
Ben Clayton | 535535b | 2023-10-09 15:14:34 +0000 | [diff] [blame] | 106 | AddTransitivelyReferencedGlobal(global); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 107 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 108 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 109 | /// @returns all transitively referenced global variables |
dan sinclair | bae54e7 | 2023-07-28 15:01:54 +0000 | [diff] [blame] | 110 | const UniqueVector<const GlobalVariable*, 8>& TransitivelyReferencedGlobals() const { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 111 | return transitively_referenced_globals_; |
| 112 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 113 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 114 | /// Records that this function transitively references the given global |
| 115 | /// variable. |
| 116 | /// @param global the module-scoped variable |
Ben Clayton | 535535b | 2023-10-09 15:14:34 +0000 | [diff] [blame] | 117 | void AddTransitivelyReferencedGlobal(const sem::GlobalVariable* global); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 118 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 119 | /// @returns the list of functions that this function transitively calls. |
dan sinclair | bae54e7 | 2023-07-28 15:01:54 +0000 | [diff] [blame] | 120 | const UniqueVector<const Function*, 8>& TransitivelyCalledFunctions() const { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 121 | return transitively_called_functions_; |
| 122 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 123 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 124 | /// Records that this function transitively calls `function`. |
| 125 | /// @param function the function this function transitively calls |
| 126 | void AddTransitivelyCalledFunction(const Function* function) { |
Ben Clayton | dce63f5 | 2022-08-17 18:07:20 +0000 | [diff] [blame] | 127 | transitively_called_functions_.Add(function); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 128 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 129 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 130 | /// @returns the list of builtins that this function directly calls. |
Ben Clayton | d9766dc | 2023-09-21 12:41:20 +0000 | [diff] [blame] | 131 | const UniqueVector<const BuiltinFn*, 4>& DirectlyCalledBuiltins() const { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 132 | return directly_called_builtins_; |
| 133 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 134 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 135 | /// Records that this function transitively calls `builtin`. |
| 136 | /// @param builtin the builtin this function directly calls |
Ben Clayton | d9766dc | 2023-09-21 12:41:20 +0000 | [diff] [blame] | 137 | void AddDirectlyCalledBuiltin(const BuiltinFn* builtin) { |
Ben Clayton | dce63f5 | 2022-08-17 18:07:20 +0000 | [diff] [blame] | 138 | directly_called_builtins_.Add(builtin); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 139 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 140 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 141 | /// Adds the given texture/sampler pair to the list of unique pairs |
| 142 | /// that this function uses (directly or indirectly). These can only |
| 143 | /// be parameters to this function or global variables. Uniqueness is |
| 144 | /// ensured by texture_sampler_pairs_ being a UniqueVector. |
Stephen White | 1026cc1 | 2024-08-13 18:23:20 +0000 | [diff] [blame] | 145 | /// @param texture the texture (must be non-null) |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 146 | /// @param sampler the sampler (null indicates a texture-only reference) |
| 147 | void AddTextureSamplerPair(const sem::Variable* texture, const sem::Variable* sampler) { |
Stephen White | 1026cc1 | 2024-08-13 18:23:20 +0000 | [diff] [blame] | 148 | TINT_ASSERT(texture != nullptr); |
Ben Clayton | dce63f5 | 2022-08-17 18:07:20 +0000 | [diff] [blame] | 149 | texture_sampler_pairs_.Add(VariablePair(texture, sampler)); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 150 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 151 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 152 | /// @returns the list of texture/sampler pairs that this function uses |
| 153 | /// (directly or indirectly). |
dan sinclair | bae54e7 | 2023-07-28 15:01:54 +0000 | [diff] [blame] | 154 | VectorRef<VariablePair> TextureSamplerPairs() const { return texture_sampler_pairs_; } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 155 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 156 | /// @returns the list of direct calls to functions / builtins made by this |
| 157 | /// function |
Ben Clayton | 31a1592 | 2024-01-29 16:00:36 +0000 | [diff] [blame] | 158 | const Vector<const Call*, 1>& DirectCalls() const { return direct_calls_; } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 159 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 160 | /// Adds a record of the direct function / builtin calls made by this |
| 161 | /// function |
| 162 | /// @param call the call |
Ben Clayton | 31a1592 | 2024-01-29 16:00:36 +0000 | [diff] [blame] | 163 | void AddDirectCall(const Call* call) { direct_calls_.Push(call); } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 164 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 165 | /// @param target the target of a call |
| 166 | /// @returns the Call to the given CallTarget, or nullptr the target was not |
| 167 | /// called by this function. |
| 168 | const Call* FindDirectCallTo(const CallTarget* target) const { |
| 169 | for (auto* call : direct_calls_) { |
| 170 | if (call->Target() == target) { |
| 171 | return call; |
| 172 | } |
| 173 | } |
| 174 | return nullptr; |
| 175 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 176 | |
Ben Clayton | 4c593c3 | 2022-11-30 11:50:54 +0000 | [diff] [blame] | 177 | /// @returns the list of callsites to this function |
Ben Clayton | 31a1592 | 2024-01-29 16:00:36 +0000 | [diff] [blame] | 178 | const Vector<const Call*, 1>& CallSites() const { return callsites_; } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 179 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 180 | /// Adds a record of a callsite to this function |
| 181 | /// @param call the callsite |
Ben Clayton | 31a1592 | 2024-01-29 16:00:36 +0000 | [diff] [blame] | 182 | void AddCallSite(const Call* call) { callsites_.Push(call); } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 183 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 184 | /// @returns the ancestor entry points |
Ben Clayton | 31a1592 | 2024-01-29 16:00:36 +0000 | [diff] [blame] | 185 | const Vector<const Function*, 1>& AncestorEntryPoints() const { return ancestor_entry_points_; } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 186 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 187 | /// Adds a record that the given entry point transitively calls this function |
| 188 | /// @param entry_point the entry point that transtively calls this function |
| 189 | void AddAncestorEntryPoint(const sem::Function* entry_point) { |
Ben Clayton | 31a1592 | 2024-01-29 16:00:36 +0000 | [diff] [blame] | 190 | ancestor_entry_points_.Push(entry_point); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 191 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 192 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 193 | /// Retrieves any referenced location variables |
| 194 | /// @returns the <variable, attribute> pair. |
| 195 | std::vector<std::pair<const Variable*, const ast::LocationAttribute*>> |
| 196 | TransitivelyReferencedLocationVariables() const; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 197 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 198 | /// Retrieves any referenced builtin variables |
| 199 | /// @returns the <variable, attribute> pair. |
| 200 | std::vector<std::pair<const Variable*, const ast::BuiltinAttribute*>> |
| 201 | TransitivelyReferencedBuiltinVariables() const; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 202 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 203 | /// Retrieves any referenced uniform variables. Note, the variables must be |
| 204 | /// decorated with both binding and group attributes. |
| 205 | /// @returns the referenced uniforms |
| 206 | VariableBindings TransitivelyReferencedUniformVariables() const; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 207 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 208 | /// Retrieves any referenced storagebuffer variables. Note, the variables |
| 209 | /// must be decorated with both binding and group attributes. |
| 210 | /// @returns the referenced storagebuffers |
| 211 | VariableBindings TransitivelyReferencedStorageBufferVariables() const; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 212 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 213 | /// Retrieves any referenced regular Sampler variables. Note, the |
| 214 | /// variables must be decorated with both binding and group attributes. |
| 215 | /// @returns the referenced storagebuffers |
| 216 | VariableBindings TransitivelyReferencedSamplerVariables() const; |
| 217 | |
| 218 | /// Retrieves any referenced comparison Sampler variables. Note, the |
| 219 | /// variables must be decorated with both binding and group attributes. |
| 220 | /// @returns the referenced storagebuffers |
| 221 | VariableBindings TransitivelyReferencedComparisonSamplerVariables() const; |
| 222 | |
| 223 | /// Retrieves any referenced sampled textures variables. Note, the |
| 224 | /// variables must be decorated with both binding and group attributes. |
| 225 | /// @returns the referenced sampled textures |
| 226 | VariableBindings TransitivelyReferencedSampledTextureVariables() const; |
| 227 | |
| 228 | /// Retrieves any referenced multisampled textures variables. Note, the |
| 229 | /// variables must be decorated with both binding and group attributes. |
| 230 | /// @returns the referenced sampled textures |
| 231 | VariableBindings TransitivelyReferencedMultisampledTextureVariables() const; |
| 232 | |
| 233 | /// Retrieves any referenced variables of the given type. Note, the variables |
| 234 | /// must be decorated with both binding and group attributes. |
| 235 | /// @param type the type of the variables to find |
| 236 | /// @returns the referenced variables |
dan sinclair | bae54e7 | 2023-07-28 15:01:54 +0000 | [diff] [blame] | 237 | VariableBindings TransitivelyReferencedVariablesOfType(const tint::TypeInfo* type) const; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 238 | |
| 239 | /// Retrieves any referenced variables of the given type. Note, the variables |
| 240 | /// must be decorated with both binding and group attributes. |
| 241 | /// @returns the referenced variables |
| 242 | template <typename T> |
| 243 | VariableBindings TransitivelyReferencedVariablesOfType() const { |
dan sinclair | bae54e7 | 2023-07-28 15:01:54 +0000 | [diff] [blame] | 244 | return TransitivelyReferencedVariablesOfType(&tint::TypeInfo::Of<T>()); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | /// Checks if the given entry point is an ancestor |
| 248 | /// @param sym the entry point symbol |
| 249 | /// @returns true if `sym` is an ancestor entry point of this function |
| 250 | bool HasAncestorEntryPoint(Symbol sym) const; |
| 251 | |
Ben Clayton | d9222f4 | 2022-10-14 13:44:54 +0000 | [diff] [blame] | 252 | /// Records the first discard statement in the function |
| 253 | /// @param stmt the `discard` statement. |
| 254 | void SetDiscardStatement(const Statement* stmt) { |
| 255 | if (!discard_stmt_) { |
| 256 | discard_stmt_ = stmt; |
| 257 | } |
| 258 | } |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 259 | |
Ben Clayton | d9222f4 | 2022-10-14 13:44:54 +0000 | [diff] [blame] | 260 | /// @returns the first discard statement for the function, or nullptr if the function does not |
| 261 | /// use `discard`. |
| 262 | const Statement* DiscardStatement() const { return discard_stmt_; } |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 263 | |
| 264 | /// @return the behaviors of this function |
| 265 | const sem::Behaviors& Behaviors() const { return behaviors_; } |
| 266 | |
| 267 | /// @return the behaviors of this function |
| 268 | sem::Behaviors& Behaviors() { return behaviors_; } |
| 269 | |
dan sinclair | 766a458 | 2022-09-06 16:00:13 +0000 | [diff] [blame] | 270 | /// @return the location for the return, if provided |
| 271 | std::optional<uint32_t> ReturnLocation() const { return return_location_; } |
| 272 | |
Brandon Jones | fbc2738 | 2023-06-22 21:51:30 +0000 | [diff] [blame] | 273 | /// @return the index for the return, if provided |
| 274 | std::optional<uint32_t> ReturnIndex() const { return return_index_; } |
| 275 | |
James Price | 5853205 | 2023-01-25 01:24:46 +0000 | [diff] [blame] | 276 | /// Modifies the severity of a specific diagnostic rule for this function. |
| 277 | /// @param rule the diagnostic rule |
| 278 | /// @param severity the new diagnostic severity |
Ben Clayton | 8be957f | 2024-01-29 16:00:36 +0000 | [diff] [blame] | 279 | void SetDiagnosticSeverity(wgsl::DiagnosticRule rule, wgsl::DiagnosticSeverity severity); |
James Price | 5853205 | 2023-01-25 01:24:46 +0000 | [diff] [blame] | 280 | |
| 281 | /// @returns the diagnostic severity modifications applied to this function |
Ben Clayton | 1165389 | 2023-09-19 19:15:59 +0000 | [diff] [blame] | 282 | const wgsl::DiagnosticRuleSeverities& DiagnosticSeverities() const { |
James Price | 5853205 | 2023-01-25 01:24:46 +0000 | [diff] [blame] | 283 | return diagnostic_severities_; |
| 284 | } |
| 285 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 286 | private: |
Ben Clayton | dce63f5 | 2022-08-17 18:07:20 +0000 | [diff] [blame] | 287 | Function(const Function&) = delete; |
| 288 | Function(Function&&) = delete; |
| 289 | |
dan sinclair | cedcdf3 | 2023-08-10 02:39:48 +0000 | [diff] [blame] | 290 | VariableBindings TransitivelyReferencedSamplerVariablesImpl(core::type::SamplerKind kind) const; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 291 | VariableBindings TransitivelyReferencedSampledTextureVariablesImpl(bool multisampled) const; |
| 292 | |
| 293 | const ast::Function* const declaration_; |
| 294 | |
| 295 | sem::WorkgroupSize workgroup_size_; |
dan sinclair | bae54e7 | 2023-07-28 15:01:54 +0000 | [diff] [blame] | 296 | UniqueVector<const GlobalVariable*, 4> directly_referenced_globals_; |
| 297 | UniqueVector<const GlobalVariable*, 8> transitively_referenced_globals_; |
| 298 | UniqueVector<const Function*, 8> transitively_called_functions_; |
Ben Clayton | d9766dc | 2023-09-21 12:41:20 +0000 | [diff] [blame] | 299 | UniqueVector<const BuiltinFn*, 4> directly_called_builtins_; |
dan sinclair | bae54e7 | 2023-07-28 15:01:54 +0000 | [diff] [blame] | 300 | UniqueVector<VariablePair, 8> texture_sampler_pairs_; |
Ben Clayton | 31a1592 | 2024-01-29 16:00:36 +0000 | [diff] [blame] | 301 | Vector<const Call*, 1> direct_calls_; |
| 302 | Vector<const Call*, 1> callsites_; |
| 303 | Vector<const Function*, 1> ancestor_entry_points_; |
Ben Clayton | d9222f4 | 2022-10-14 13:44:54 +0000 | [diff] [blame] | 304 | const Statement* discard_stmt_ = nullptr; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 305 | sem::Behaviors behaviors_{sem::Behavior::kNext}; |
Ben Clayton | 1165389 | 2023-09-19 19:15:59 +0000 | [diff] [blame] | 306 | wgsl::DiagnosticRuleSeverities diagnostic_severities_; |
dan sinclair | 766a458 | 2022-09-06 16:00:13 +0000 | [diff] [blame] | 307 | |
| 308 | std::optional<uint32_t> return_location_; |
Brandon Jones | fbc2738 | 2023-06-22 21:51:30 +0000 | [diff] [blame] | 309 | std::optional<uint32_t> return_index_; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 310 | }; |
| 311 | |
dan sinclair | c990b3c | 2022-04-07 16:04:35 +0000 | [diff] [blame] | 312 | } // namespace tint::sem |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 313 | |
dan sinclair | d3b1369 | 2023-07-20 01:14:15 +0000 | [diff] [blame] | 314 | #endif // SRC_TINT_LANG_WGSL_SEM_FUNCTION_H_ |