// Copyright 2022 The Dawn & Tint Authors // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, this // list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // 3. Neither the name of the copyright holder nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "src/tint/lang/wgsl/resolver/uniformity.h" #include <limits> #include <string> #include <utility> #include <vector> #include "src/tint/lang/core/builtin_value.h" #include "src/tint/lang/wgsl/program/program_builder.h" #include "src/tint/lang/wgsl/resolver/dependency_graph.h" #include "src/tint/lang/wgsl/sem/block_statement.h" #include "src/tint/lang/wgsl/sem/builtin_fn.h" #include "src/tint/lang/wgsl/sem/for_loop_statement.h" #include "src/tint/lang/wgsl/sem/function.h" #include "src/tint/lang/wgsl/sem/if_statement.h" #include "src/tint/lang/wgsl/sem/info.h" #include "src/tint/lang/wgsl/sem/load.h" #include "src/tint/lang/wgsl/sem/loop_statement.h" #include "src/tint/lang/wgsl/sem/statement.h" #include "src/tint/lang/wgsl/sem/switch_statement.h" #include "src/tint/lang/wgsl/sem/value_constructor.h" #include "src/tint/lang/wgsl/sem/value_conversion.h" #include "src/tint/lang/wgsl/sem/variable.h" #include "src/tint/lang/wgsl/sem/while_statement.h" #include "src/tint/utils/containers/map.h" #include "src/tint/utils/containers/scope_stack.h" #include "src/tint/utils/containers/unique_vector.h" #include "src/tint/utils/macros/defer.h" #include "src/tint/utils/memory/block_allocator.h" #include "src/tint/utils/rtti/switch.h" #include "src/tint/utils/text/string_stream.h" // Set to `1` to dump the uniformity graph for each function in graphviz format. #define TINT_DUMP_UNIFORMITY_GRAPH … #if TINT_DUMP_UNIFORMITY_GRAPH #include <iostream> #endif namespace tint::resolver { namespace { /// Unwraps `u->expr`'s chain of indirect (*) and address-of (&) expressions, returning the first /// expression that is neither of these. /// E.g. If `u` is `*(&(*(&p)))`, returns `p`. const ast::Expression* UnwrapIndirectAndAddressOfChain(const ast::UnaryOpExpression* u) { … } /// CallSiteTag describes the uniformity requirements on the call sites of a function. struct CallSiteTag { … }; /// FunctionTag describes a functions effects on uniformity. enum FunctionTag { … }; /// ParameterTag describes the uniformity requirements of values passed to a function parameter. struct ParameterTag { … }; /// Node represents a node in the graph of control flow and value nodes within the analysis of a /// single function. struct Node { … }; /// ParameterInfo holds information about the uniformity requirements and effects for a particular /// function parameter. struct ParameterInfo { … }; /// FunctionInfo holds information about the uniformity requirements and effects for a particular /// function, as well as the control flow graph. struct FunctionInfo { … }; /// UniformityGraph is used to analyze the uniformity requirements and effects of functions in a /// module. class UniformityGraph { … }; } // namespace bool AnalyzeUniformity(ProgramBuilder& builder, const DependencyGraph& dependency_graph) { … } } // namespace tint::resolver