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>
This commit is contained in:
Ben Clayton
2023-02-04 21:20:26 +00:00
committed by Dawn LUCI CQ
parent 3f5ae2bc54
commit 3fb9a3fba1
68 changed files with 305 additions and 293 deletions

View File

@@ -240,14 +240,14 @@ struct CombineSamplers::State {
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 @@ struct CombineSamplers::State {
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();
}

View File

@@ -305,10 +305,10 @@ DecomposeMemoryAccess::Intrinsic* IntrinsicAtomicFor(ProgramBuilder* builder,
/// 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

View File

@@ -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"

View File

@@ -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"

View File

@@ -151,7 +151,7 @@ bool operator!=(const AccessShape& a, const AccessShape& b) {
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 @@ struct DirectVariableAccess::State {
// 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 @@ struct DirectVariableAccess::State {
/// 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 @@ struct DirectVariableAccess::State {
/// 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 @@ struct DirectVariableAccess::State {
/// 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 @@ struct DirectVariableAccess::State {
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 @@ struct DirectVariableAccess::State {
/// * 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 @@ struct DirectVariableAccess::State {
/// @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 @@ struct DirectVariableAccess::State {
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.

View File

@@ -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);

View File

@@ -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"

View File

@@ -72,11 +72,11 @@ struct PackedVec3::State {
// 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 @@ struct PackedVec3::State {
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) {

View File

@@ -41,7 +41,7 @@ Transform::ApplyResult PromoteInitializersToLet::Apply(const Program* src,
// 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 @@ Transform::ApplyResult PromoteInitializersToLet::Apply(const Program* src,
};
// 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

View File

@@ -107,7 +107,7 @@ class DecomposeSideEffects::CollectHoistsState : public StateBase {
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.

View File

@@ -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);

View File

@@ -54,7 +54,7 @@ struct SpirvAtomic::State {
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 @@ struct SpirvAtomic::State {
[&](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 @@ struct SpirvAtomic::State {
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

View File

@@ -251,7 +251,7 @@ struct Std140::State {
/// 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 @@ struct Std140::State {
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 @@ struct Std140::State {
});
// 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()));
});

View File

@@ -36,7 +36,7 @@ struct HoistToDeclBefore::State {
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 @@ struct HoistToDeclBefore::State {
}
/// @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(CloneContext& ctx) : state_(std::make_uniqu
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 @@ bool HoistToDeclBefore::InsertBefore(const sem::Statement* before_stmt,
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);
}

View File

@@ -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 @@ class HoistToDeclBefore {
/// @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 @@ class HoistToDeclBefore {
/// 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;

View File

@@ -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 @@ namespace {
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();

View File

@@ -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"