tint/sem: Rename Expression to ValueExpression ast::IdentifierExpression may also resolve to a type or core enumerator Bug: tint:1810 Change-Id: I85e3bea67e1146215079ec47430784f2fb39043d Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/118402 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: James Price <jrprice@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/src/tint/transform/combine_samplers.cc b/src/tint/transform/combine_samplers.cc index 65bf161..7a39d6e 100644 --- a/src/tint/transform/combine_samplers.cc +++ b/src/tint/transform/combine_samplers.cc
@@ -240,14 +240,14 @@ if (texture_index == -1) { return nullptr; } - const sem::Expression* texture = + const sem::ValueExpression* texture = call->Arguments()[static_cast<size_t>(texture_index)]; // We don't want to combine storage textures with anything, since // they never have associated samplers in GLSL. if (texture->Type()->UnwrapRef()->Is<type::StorageTexture>()) { return nullptr; } - const sem::Expression* sampler = + const sem::ValueExpression* sampler = sampler_index != -1 ? call->Arguments()[static_cast<size_t>(sampler_index)] : nullptr; auto* texture_var = texture->UnwrapLoad()->As<sem::VariableUser>()->Variable(); @@ -296,13 +296,14 @@ const sem::Variable* texture_var = pair.first; const sem::Variable* sampler_var = pair.second; if (auto* param = texture_var->As<sem::Parameter>()) { - const sem::Expression* texture = call->Arguments()[param->Index()]; + const sem::ValueExpression* texture = call->Arguments()[param->Index()]; texture_var = texture->UnwrapLoad()->As<sem::VariableUser>()->Variable(); } if (sampler_var) { if (auto* param = sampler_var->As<sem::Parameter>()) { - const sem::Expression* sampler = call->Arguments()[param->Index()]; + const sem::ValueExpression* sampler = + call->Arguments()[param->Index()]; sampler_var = sampler->UnwrapLoad()->As<sem::VariableUser>()->Variable(); }
diff --git a/src/tint/transform/decompose_memory_access.cc b/src/tint/transform/decompose_memory_access.cc index abb78b2..0d5f709 100644 --- a/src/tint/transform/decompose_memory_access.cc +++ b/src/tint/transform/decompose_memory_access.cc
@@ -305,10 +305,10 @@ /// BufferAccess describes a single storage or uniform buffer access struct BufferAccess { - sem::Expression const* var = nullptr; // Storage buffer variable - Offset const* offset = nullptr; // The byte offset on var - type::Type const* type = nullptr; // The type of the access - operator bool() const { return var; } // Returns true if valid + sem::ValueExpression const* var = nullptr; // Storage buffer variable + Offset const* offset = nullptr; // The byte offset on var + type::Type const* type = nullptr; // The type of the access + operator bool() const { return var; } // Returns true if valid }; /// Store describes a single storage or uniform buffer write
diff --git a/src/tint/transform/decompose_strided_array.cc b/src/tint/transform/decompose_strided_array.cc index 129e417..c441df8 100644 --- a/src/tint/transform/decompose_strided_array.cc +++ b/src/tint/transform/decompose_strided_array.cc
@@ -20,9 +20,9 @@ #include "src/tint/program_builder.h" #include "src/tint/sem/call.h" -#include "src/tint/sem/expression.h" #include "src/tint/sem/member_accessor_expression.h" #include "src/tint/sem/type_initializer.h" +#include "src/tint/sem/value_expression.h" #include "src/tint/transform/simplify_pointers.h" #include "src/tint/utils/hash.h" #include "src/tint/utils/map.h"
diff --git a/src/tint/transform/decompose_strided_matrix.cc b/src/tint/transform/decompose_strided_matrix.cc index 15cdf62..773cfdf 100644 --- a/src/tint/transform/decompose_strided_matrix.cc +++ b/src/tint/transform/decompose_strided_matrix.cc
@@ -19,8 +19,8 @@ #include <vector> #include "src/tint/program_builder.h" -#include "src/tint/sem/expression.h" #include "src/tint/sem/member_accessor_expression.h" +#include "src/tint/sem/value_expression.h" #include "src/tint/transform/simplify_pointers.h" #include "src/tint/utils/hash.h" #include "src/tint/utils/map.h"
diff --git a/src/tint/transform/direct_variable_access.cc b/src/tint/transform/direct_variable_access.cc index c2a4234..2d1b514 100644 --- a/src/tint/transform/direct_variable_access.cc +++ b/src/tint/transform/direct_variable_access.cc
@@ -151,7 +151,7 @@ struct AccessChain : AccessShape { /// The array accessor index expressions. This vector is indexed by the `DynamicIndex`s in /// #indices. - tint::utils::Vector<const tint::sem::Expression*, 8> dynamic_indices; + tint::utils::Vector<const tint::sem::ValueExpression*, 8> dynamic_indices; /// If true, then this access chain is used as an argument to call a variant. bool used_in_call = false; }; @@ -216,7 +216,7 @@ // are grown and moved up the expression tree. After this stage, we are left with all the // expression access chains to variables that we may need to transform. for (auto* node : ctx.src->ASTNodes().Objects()) { - if (auto* expr = sem.Get<sem::Expression>(node)) { + if (auto* expr = sem.Get<sem::ValueExpression>(node)) { AppendAccessChain(expr); } } @@ -361,7 +361,7 @@ /// A map of variant signature to the variant data. utils::Hashmap<FnVariant::Signature, FnVariant, 8> variants; /// A map of expressions that have been hoisted to a 'let' declaration in the function. - utils::Hashmap<const sem::Expression*, Symbol, 8> hoisted_exprs; + utils::Hashmap<const sem::ValueExpression*, Symbol, 8> hoisted_exprs; /// @returns the variants of the function in a deterministically ordered vector. utils::Vector<std::pair<const FnVariant::Signature*, FnVariant*>, 8> SortedVariants() { @@ -392,7 +392,7 @@ /// pointer parameter. utils::Hashmap<AccessShape, Symbol, 8> dynamic_index_array_aliases; /// Map of semantic expression to AccessChain - utils::Hashmap<const sem::Expression*, AccessChain*, 32> access_chains; + utils::Hashmap<const sem::ValueExpression*, AccessChain*, 32> access_chains; /// Allocator for FnInfo utils::BlockAllocator<FnInfo> fn_info_allocator; /// Allocator for AccessChain @@ -418,10 +418,10 @@ /// AppendAccessChain creates or extends an existing AccessChain for the given expression, /// modifying the #access_chains map. - void AppendAccessChain(const sem::Expression* expr) { + void AppendAccessChain(const sem::ValueExpression* expr) { // take_chain moves the AccessChain from the expression `from` to the expression `expr`. // Returns nullptr if `from` did not hold an access chain. - auto take_chain = [&](const sem::Expression* from) -> AccessChain* { + auto take_chain = [&](const sem::ValueExpression* from) -> AccessChain* { if (auto* chain = AccessChainFor(from)) { access_chains.Remove(from); access_chains.Add(expr, chain); @@ -492,7 +492,7 @@ chain->dynamic_indices.Push(a->Index()); } }, - [&](const sem::Expression* e) { + [&](const sem::ValueExpression* e) { if (auto* unary = e->Declaration()->As<ast::UnaryOpExpression>()) { // Unary op. // If this is a '&' or '*', simply move the chain to the unary op expression. @@ -556,7 +556,7 @@ /// * Casts the resulting expression to a u32 if @p cast_to_u32 is true, and the expression type /// isn't implicitly usable as a u32. This is to help feed the expression into a /// `array<u32, N>` argument passed to a callee variant function. - const ast::Expression* BuildDynamicIndex(const sem::Expression* idx, bool cast_to_u32) { + const ast::Expression* BuildDynamicIndex(const sem::ValueExpression* idx, bool cast_to_u32) { if (auto* val = idx->ConstantValue()) { // Expression evaluated to a constant value. Just emit that constant. return b.Expr(val->ValueAs<AInt>()); @@ -766,7 +766,7 @@ /// @returns the AccessChain for the expression @p expr, or nullptr if the expression does /// not hold an access chain. - AccessChain* AccessChainFor(const sem::Expression* expr) const { + AccessChain* AccessChainFor(const sem::ValueExpression* expr) const { if (auto chain = access_chains.Find(expr)) { return *chain; } @@ -990,7 +990,7 @@ return nullptr; // Just clone the expression. } - auto* expr = sem.Get<sem::Expression>(ast_expr); + auto* expr = sem.Get<sem::ValueExpression>(ast_expr); if (!expr) { // No semantic node for the expression. return nullptr; // Just clone the expression.
diff --git a/src/tint/transform/expand_compound_assignment.cc b/src/tint/transform/expand_compound_assignment.cc index 3d62f23..c208601 100644 --- a/src/tint/transform/expand_compound_assignment.cc +++ b/src/tint/transform/expand_compound_assignment.cc
@@ -20,9 +20,9 @@ #include "src/tint/ast/increment_decrement_statement.h" #include "src/tint/program_builder.h" #include "src/tint/sem/block_statement.h" -#include "src/tint/sem/expression.h" #include "src/tint/sem/for_loop_statement.h" #include "src/tint/sem/statement.h" +#include "src/tint/sem/value_expression.h" #include "src/tint/transform/utils/hoist_to_decl_before.h" TINT_INSTANTIATE_TYPEINFO(tint::transform::ExpandCompoundAssignment);
diff --git a/src/tint/transform/localize_struct_array_assignment.cc b/src/tint/transform/localize_struct_array_assignment.cc index 6ed16b3..0d40ccf 100644 --- a/src/tint/transform/localize_struct_array_assignment.cc +++ b/src/tint/transform/localize_struct_array_assignment.cc
@@ -20,9 +20,9 @@ #include "src/tint/ast/assignment_statement.h" #include "src/tint/ast/traverse_expressions.h" #include "src/tint/program_builder.h" -#include "src/tint/sem/expression.h" #include "src/tint/sem/member_accessor_expression.h" #include "src/tint/sem/statement.h" +#include "src/tint/sem/value_expression.h" #include "src/tint/sem/variable.h" #include "src/tint/transform/simplify_pointers.h" #include "src/tint/type/reference.h"
diff --git a/src/tint/transform/packed_vec3.cc b/src/tint/transform/packed_vec3.cc index af95161..26cad63 100644 --- a/src/tint/transform/packed_vec3.cc +++ b/src/tint/transform/packed_vec3.cc
@@ -72,11 +72,11 @@ // Walk the nodes, starting with the most deeply nested, finding all the AST expressions // that load a whole packed vector (not a scalar / swizzle of the vector). - utils::Hashset<const sem::Expression*, 16> refs; + utils::Hashset<const sem::ValueExpression*, 16> refs; for (auto* node : ctx.src->ASTNodes().Objects()) { auto* sem_node = sem.Get(node); if (sem_node) { - if (auto* expr = sem_node->As<sem::Expression>()) { + if (auto* expr = sem_node->As<sem::ValueExpression>()) { sem_node = expr->UnwrapLoad(); } } @@ -104,7 +104,7 @@ refs.Add(user); // then propagate tracking to pointer usage } }, - [&](const sem::Expression* expr) { + [&](const sem::ValueExpression* expr) { if (auto* unary = expr->Declaration()->As<ast::UnaryOpExpression>()) { if (unary->op == ast::UnaryOp::kAddressOf || unary->op == ast::UnaryOp::kIndirection) {
diff --git a/src/tint/transform/promote_initializers_to_let.cc b/src/tint/transform/promote_initializers_to_let.cc index 391a7f2..0ad37de 100644 --- a/src/tint/transform/promote_initializers_to_let.cc +++ b/src/tint/transform/promote_initializers_to_let.cc
@@ -41,7 +41,7 @@ // Returns true if the expression should be hoisted to a new let statement before the // expression's statement. - auto should_hoist = [&](const sem::Expression* expr) { + auto should_hoist = [&](const sem::ValueExpression* expr) { if (!expr->Type()->IsAnyOf<type::Array, type::Struct>()) { // We only care about array and struct initializers return false; @@ -77,13 +77,13 @@ }; // A list of expressions that should be hoisted. - utils::Vector<const sem::Expression*, 32> to_hoist; + utils::Vector<const sem::ValueExpression*, 32> to_hoist; // A set of expressions that are constant, which _may_ need to be hoisted. utils::Hashset<const ast::Expression*, 32> const_chains; // Walk the AST nodes. This order guarantees that leaf-expressions are visited first. for (auto* node : src->ASTNodes().Objects()) { - if (auto* sem = src->Sem().Get<sem::Expression>(node)) { + if (auto* sem = src->Sem().Get<sem::ValueExpression>(node)) { auto* stmt = sem->Stmt(); if (!stmt) { // Expression is outside of a statement. This usually means the expression is part
diff --git a/src/tint/transform/promote_side_effects_to_decl.cc b/src/tint/transform/promote_side_effects_to_decl.cc index 2d4b059..632d57b 100644 --- a/src/tint/transform/promote_side_effects_to_decl.cc +++ b/src/tint/transform/promote_side_effects_to_decl.cc
@@ -107,7 +107,7 @@ std::unordered_set<const ast::Expression*> no_side_effects; // Returns true if `expr` has side-effects. Unlike invoking - // sem::Expression::HasSideEffects(), this function takes into account whether + // sem::ValueExpression::HasSideEffects(), this function takes into account whether // `expr` has been hoisted, returning false in that case. Furthermore, it // returns the correct result on parent expression nodes by traversing the // expression tree, memoizing the results to ensure O(1) amortized lookup.
diff --git a/src/tint/transform/robustness.cc b/src/tint/transform/robustness.cc index 1d624df..4680939 100644 --- a/src/tint/transform/robustness.cc +++ b/src/tint/transform/robustness.cc
@@ -21,9 +21,9 @@ #include "src/tint/program_builder.h" #include "src/tint/sem/block_statement.h" #include "src/tint/sem/call.h" -#include "src/tint/sem/expression.h" #include "src/tint/sem/index_accessor_expression.h" #include "src/tint/sem/statement.h" +#include "src/tint/sem/value_expression.h" #include "src/tint/type/reference.h" TINT_INSTANTIATE_TYPEINFO(tint::transform::Robustness);
diff --git a/src/tint/transform/spirv_atomic.cc b/src/tint/transform/spirv_atomic.cc index 9ad5b3e..07879e8 100644 --- a/src/tint/transform/spirv_atomic.cc +++ b/src/tint/transform/spirv_atomic.cc
@@ -54,7 +54,7 @@ CloneContext ctx = {&b, src, /* auto_clone_symbols */ true}; std::unordered_map<const ast::Struct*, ForkedStruct> forked_structs; std::unordered_set<const sem::Variable*> atomic_variables; - utils::UniqueVector<const sem::Expression*, 8> atomic_expressions; + utils::UniqueVector<const sem::ValueExpression*, 8> atomic_expressions; public: /// Constructor @@ -184,7 +184,7 @@ [&](const sem::IndexAccessorExpression* index) { atomic_expressions.Add(index->Object()); }, - [&](const sem::Expression* e) { + [&](const sem::ValueExpression* e) { if (auto* unary = e->Declaration()->As<ast::UnaryOpExpression>()) { atomic_expressions.Add(ctx.src->Sem().Get(unary->expr)); } @@ -226,7 +226,7 @@ void ReplaceLoadsAndStores() { // Returns true if 'e' is a reference to an atomic variable or struct member - auto is_ref_to_atomic_var = [&](const sem::Expression* e) { + auto is_ref_to_atomic_var = [&](const sem::ValueExpression* e) { if (tint::Is<type::Reference>(e->Type()) && e->RootIdentifier() && (atomic_variables.count(e->RootIdentifier()) != 0)) { // If it's a struct member, make sure it's one we marked as atomic
diff --git a/src/tint/transform/std140.cc b/src/tint/transform/std140.cc index c66e396..cde4a3f 100644 --- a/src/tint/transform/std140.cc +++ b/src/tint/transform/std140.cc
@@ -251,7 +251,7 @@ /// The chain of access indices, starting with the first access on #var. AccessIndices indices; /// The runtime-evaluated expressions. This vector is indexed by the DynamicIndex::slot - utils::Vector<const sem::Expression*, 8> dynamic_indices; + utils::Vector<const sem::ValueExpression*, 8> dynamic_indices; /// The type of the std140-decomposed matrix being accessed. /// May be nullptr if the chain does not pass through a std140-decomposed matrix. const type::Matrix* std140_mat_ty = nullptr; @@ -573,7 +573,7 @@ expr = s->Object(); return Action::kContinue; }, - [&](const sem::Expression* e) { + [&](const sem::ValueExpression* e) { // Walk past indirection and address-of unary ops. return Switch(e->Declaration(), // [&](const ast::UnaryOpExpression* u) { @@ -797,7 +797,7 @@ }); // Build the arguments - auto args = utils::Transform(access.dynamic_indices, [&](const sem::Expression* e) { + auto args = utils::Transform(access.dynamic_indices, [&](const sem::ValueExpression* e) { return b.Construct(b.ty.u32(), ctx.Clone(e->Declaration())); });
diff --git a/src/tint/transform/utils/hoist_to_decl_before.cc b/src/tint/transform/utils/hoist_to_decl_before.cc index 5852573..fd7402e 100644 --- a/src/tint/transform/utils/hoist_to_decl_before.cc +++ b/src/tint/transform/utils/hoist_to_decl_before.cc
@@ -36,7 +36,7 @@ explicit State(CloneContext& ctx_in) : ctx(ctx_in), b(*ctx_in.dst) {} /// @copydoc HoistToDeclBefore::Add() - bool Add(const sem::Expression* before_expr, + bool Add(const sem::ValueExpression* before_expr, const ast::Expression* expr, VariableKind kind, const char* decl_name) { @@ -94,7 +94,7 @@ } /// @copydoc HoistToDeclBefore::Prepare() - bool Prepare(const sem::Expression* before_expr) { + bool Prepare(const sem::ValueExpression* before_expr) { return InsertBefore(before_expr->Stmt(), nullptr); } @@ -376,7 +376,7 @@ HoistToDeclBefore::~HoistToDeclBefore() {} -bool HoistToDeclBefore::Add(const sem::Expression* before_expr, +bool HoistToDeclBefore::Add(const sem::ValueExpression* before_expr, const ast::Expression* expr, VariableKind kind, const char* decl_name) { @@ -393,7 +393,7 @@ return state_->InsertBefore(before_stmt, builder); } -bool HoistToDeclBefore::Prepare(const sem::Expression* before_expr) { +bool HoistToDeclBefore::Prepare(const sem::ValueExpression* before_expr) { return state_->Prepare(before_expr); }
diff --git a/src/tint/transform/utils/hoist_to_decl_before.h b/src/tint/transform/utils/hoist_to_decl_before.h index 4d6a808..81c255f 100644 --- a/src/tint/transform/utils/hoist_to_decl_before.h +++ b/src/tint/transform/utils/hoist_to_decl_before.h
@@ -18,7 +18,7 @@ #include <functional> #include <memory> -#include "src/tint/sem/expression.h" +#include "src/tint/sem/value_expression.h" #include "src/tint/transform/transform.h" namespace tint::transform { @@ -52,7 +52,7 @@ /// @param kind variable kind to hoist to /// @param decl_name optional name to use for the variable/constant name /// @return true on success - bool Add(const sem::Expression* before_expr, + bool Add(const sem::ValueExpression* before_expr, const ast::Expression* expr, VariableKind kind, const char* decl_name = ""); @@ -81,7 +81,7 @@ /// needed. /// @param before_expr expression we would hoist a decl before /// @return true on success - bool Prepare(const sem::Expression* before_expr); + bool Prepare(const sem::ValueExpression* before_expr); private: struct State;
diff --git a/src/tint/transform/vectorize_matrix_conversions.cc b/src/tint/transform/vectorize_matrix_conversions.cc index 26f27c3..f22e32d 100644 --- a/src/tint/transform/vectorize_matrix_conversions.cc +++ b/src/tint/transform/vectorize_matrix_conversions.cc
@@ -20,8 +20,8 @@ #include "src/tint/program_builder.h" #include "src/tint/sem/call.h" -#include "src/tint/sem/expression.h" #include "src/tint/sem/type_conversion.h" +#include "src/tint/sem/value_expression.h" #include "src/tint/type/abstract_numeric.h" #include "src/tint/utils/hash.h" #include "src/tint/utils/map.h" @@ -34,7 +34,7 @@ bool ShouldRun(const Program* program) { for (auto* node : program->ASTNodes().Objects()) { - if (auto* sem = program->Sem().Get<sem::Expression>(node)) { + if (auto* sem = program->Sem().Get<sem::ValueExpression>(node)) { if (auto* call = sem->UnwrapMaterialize()->As<sem::Call>()) { if (call->Target()->Is<sem::TypeConversion>() && call->Type()->Is<type::Matrix>()) { auto& args = call->Arguments();
diff --git a/src/tint/transform/vectorize_scalar_matrix_initializers.cc b/src/tint/transform/vectorize_scalar_matrix_initializers.cc index 9e989bc..60d4d13 100644 --- a/src/tint/transform/vectorize_scalar_matrix_initializers.cc +++ b/src/tint/transform/vectorize_scalar_matrix_initializers.cc
@@ -19,8 +19,8 @@ #include "src/tint/program_builder.h" #include "src/tint/sem/call.h" -#include "src/tint/sem/expression.h" #include "src/tint/sem/type_initializer.h" +#include "src/tint/sem/value_expression.h" #include "src/tint/type/abstract_numeric.h" #include "src/tint/utils/map.h"