mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-18 17:35:30 +00:00
tint/resolver: Use utils::Vector in a few places
Use the new vector type in some of the hot code paths of the resolver. Bug: tint:1613 Change-Id: Ie56d8c96f73c9112f37934ad67e588513aafb982 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/96282 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com> Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
4b3d53d141
commit
958a4642f1
@@ -17,13 +17,25 @@
|
||||
|
||||
#include "src/tint/sem/builtin.h"
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "src/tint/utils/to_const_ptr_vec.h"
|
||||
#include "src/tint/utils/transform.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::sem::Builtin);
|
||||
|
||||
namespace tint::sem {
|
||||
namespace {
|
||||
|
||||
utils::VectorRef<const Parameter*> SetOwner(utils::VectorRef<Parameter*> parameters,
|
||||
const tint::sem::CallTarget* owner) {
|
||||
for (auto* parameter : parameters) {
|
||||
parameter->SetOwner(owner);
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const char* Builtin::str() const {
|
||||
return sem::str(type_);
|
||||
@@ -89,18 +101,14 @@ bool IsDP4aBuiltin(BuiltinType i) {
|
||||
|
||||
Builtin::Builtin(BuiltinType type,
|
||||
const sem::Type* return_type,
|
||||
std::vector<Parameter*> parameters,
|
||||
utils::VectorRef<Parameter*> parameters,
|
||||
EvaluationStage eval_stage,
|
||||
PipelineStageSet supported_stages,
|
||||
bool is_deprecated)
|
||||
: Base(return_type, utils::ToConstPtrVec(parameters), eval_stage),
|
||||
: Base(return_type, SetOwner(std::move(parameters), this), eval_stage),
|
||||
type_(type),
|
||||
supported_stages_(supported_stages),
|
||||
is_deprecated_(is_deprecated) {
|
||||
for (auto* parameter : parameters) {
|
||||
parameter->SetOwner(this);
|
||||
}
|
||||
}
|
||||
is_deprecated_(is_deprecated) {}
|
||||
|
||||
Builtin::~Builtin() = default;
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ class Builtin final : public Castable<Builtin, CallTarget> {
|
||||
/// deprecated
|
||||
Builtin(BuiltinType type,
|
||||
const sem::Type* return_type,
|
||||
std::vector<Parameter*> parameters,
|
||||
utils::VectorRef<Parameter*> parameters,
|
||||
EvaluationStage eval_stage,
|
||||
PipelineStageSet supported_stages,
|
||||
bool is_deprecated);
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace tint::sem {
|
||||
Call::Call(const ast::CallExpression* declaration,
|
||||
const CallTarget* target,
|
||||
EvaluationStage stage,
|
||||
std::vector<const sem::Expression*> arguments,
|
||||
utils::VectorRef<const sem::Expression*> arguments,
|
||||
const Statement* statement,
|
||||
const Constant* constant,
|
||||
bool has_side_effects)
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "src/tint/ast/call_expression.h"
|
||||
#include "src/tint/sem/builtin.h"
|
||||
#include "src/tint/sem/expression.h"
|
||||
#include "src/tint/utils/vector.h"
|
||||
|
||||
namespace tint::sem {
|
||||
|
||||
@@ -38,7 +39,7 @@ class Call final : public Castable<Call, Expression> {
|
||||
Call(const ast::CallExpression* declaration,
|
||||
const CallTarget* target,
|
||||
EvaluationStage stage,
|
||||
std::vector<const sem::Expression*> arguments,
|
||||
utils::VectorRef<const sem::Expression*> arguments,
|
||||
const Statement* statement,
|
||||
const Constant* constant,
|
||||
bool has_side_effects);
|
||||
@@ -50,7 +51,7 @@ class Call final : public Castable<Call, Expression> {
|
||||
const CallTarget* Target() const { return target_; }
|
||||
|
||||
/// @return the call arguments
|
||||
const std::vector<const sem::Expression*>& Arguments() const { return arguments_; }
|
||||
const auto& Arguments() const { return arguments_; }
|
||||
|
||||
/// @returns the AST node
|
||||
const ast::CallExpression* Declaration() const {
|
||||
@@ -59,7 +60,7 @@ class Call final : public Castable<Call, Expression> {
|
||||
|
||||
private:
|
||||
CallTarget const* const target_;
|
||||
std::vector<const sem::Expression*> arguments_;
|
||||
utils::Vector<const sem::Expression*, 8> arguments_;
|
||||
};
|
||||
|
||||
} // namespace tint::sem
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
#include "src/tint/sem/call_target.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "src/tint/symbol_table.h"
|
||||
#include "src/tint/utils/hash.h"
|
||||
|
||||
@@ -22,22 +24,23 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::CallTarget);
|
||||
namespace tint::sem {
|
||||
|
||||
CallTarget::CallTarget(const sem::Type* return_type,
|
||||
const ParameterList& parameters,
|
||||
utils::VectorRef<const Parameter*> parameters,
|
||||
EvaluationStage stage)
|
||||
: signature_{return_type, parameters}, stage_(stage) {
|
||||
: signature_{return_type, std::move(parameters)}, stage_(stage) {
|
||||
TINT_ASSERT(Semantic, return_type);
|
||||
}
|
||||
|
||||
CallTarget::CallTarget(const CallTarget&) = default;
|
||||
CallTarget::~CallTarget() = default;
|
||||
|
||||
CallTargetSignature::CallTargetSignature(const sem::Type* ret_ty, const ParameterList& params)
|
||||
: return_type(ret_ty), parameters(params) {}
|
||||
CallTargetSignature::CallTargetSignature(const sem::Type* ret_ty,
|
||||
utils::VectorRef<const Parameter*> params)
|
||||
: return_type(ret_ty), parameters(std::move(params)) {}
|
||||
CallTargetSignature::CallTargetSignature(const CallTargetSignature&) = default;
|
||||
CallTargetSignature::~CallTargetSignature() = default;
|
||||
|
||||
int CallTargetSignature::IndexOf(ParameterUsage usage) const {
|
||||
for (size_t i = 0; i < parameters.size(); i++) {
|
||||
for (size_t i = 0; i < parameters.Length(); i++) {
|
||||
if (parameters[i]->Usage() == usage) {
|
||||
return static_cast<int>(i);
|
||||
}
|
||||
@@ -46,10 +49,10 @@ int CallTargetSignature::IndexOf(ParameterUsage usage) const {
|
||||
}
|
||||
|
||||
bool CallTargetSignature::operator==(const CallTargetSignature& other) const {
|
||||
if (return_type != other.return_type || parameters.size() != other.parameters.size()) {
|
||||
if (return_type != other.return_type || parameters.Length() != other.parameters.Length()) {
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i < parameters.size(); i++) {
|
||||
for (size_t i = 0; i < parameters.Length(); i++) {
|
||||
auto* a = parameters[i];
|
||||
auto* b = other.parameters[i];
|
||||
if (a->Type() != b->Type() || a->Usage() != b->Usage()) {
|
||||
@@ -65,7 +68,7 @@ namespace std {
|
||||
|
||||
std::size_t hash<tint::sem::CallTargetSignature>::operator()(
|
||||
const tint::sem::CallTargetSignature& sig) const {
|
||||
size_t hash = tint::utils::Hash(sig.parameters.size());
|
||||
size_t hash = tint::utils::Hash(sig.parameters.Length());
|
||||
for (auto* p : sig.parameters) {
|
||||
tint::utils::HashCombine(&hash, p->Type(), p->Usage());
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "src/tint/sem/sampler.h"
|
||||
#include "src/tint/sem/variable.h"
|
||||
#include "src/tint/utils/hash.h"
|
||||
#include "src/tint/utils/vector.h"
|
||||
|
||||
// Forward declarations
|
||||
namespace tint::sem {
|
||||
@@ -34,7 +35,7 @@ struct CallTargetSignature {
|
||||
/// Constructor
|
||||
/// @param ret_ty the call target return type
|
||||
/// @param params the call target parameters
|
||||
CallTargetSignature(const sem::Type* ret_ty, const ParameterList& params);
|
||||
CallTargetSignature(const sem::Type* ret_ty, utils::VectorRef<const Parameter*> params);
|
||||
|
||||
/// Copy constructor
|
||||
CallTargetSignature(const CallTargetSignature&);
|
||||
@@ -45,7 +46,7 @@ struct CallTargetSignature {
|
||||
/// The type of the call target return value
|
||||
const sem::Type* const return_type = nullptr;
|
||||
/// The parameters of the call target
|
||||
const ParameterList parameters;
|
||||
const utils::Vector<const sem::Parameter*, 8> parameters;
|
||||
|
||||
/// Equality operator
|
||||
/// @param other the signature to compare this to
|
||||
@@ -67,7 +68,7 @@ class CallTarget : public Castable<CallTarget, Node> {
|
||||
/// @param return_type the return type of the call target
|
||||
/// @param parameters the parameters for the call target
|
||||
CallTarget(const sem::Type* return_type,
|
||||
const ParameterList& parameters,
|
||||
utils::VectorRef<const Parameter*> parameters,
|
||||
EvaluationStage stage);
|
||||
|
||||
/// Copy constructor
|
||||
@@ -80,7 +81,7 @@ class CallTarget : public Castable<CallTarget, Node> {
|
||||
const sem::Type* ReturnType() const { return signature_.return_type; }
|
||||
|
||||
/// @return the parameters of the call target
|
||||
const ParameterList& Parameters() const { return signature_.parameters; }
|
||||
auto& Parameters() const { return signature_.parameters; }
|
||||
|
||||
/// @return the signature of the call target
|
||||
const CallTargetSignature& Signature() const { return signature_; }
|
||||
|
||||
@@ -21,22 +21,29 @@
|
||||
#include "src/tint/sem/sampled_texture.h"
|
||||
#include "src/tint/sem/storage_texture.h"
|
||||
#include "src/tint/sem/variable.h"
|
||||
#include "src/tint/utils/to_const_ptr_vec.h"
|
||||
#include "src/tint/utils/transform.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::sem::Function);
|
||||
|
||||
namespace tint::sem {
|
||||
namespace {
|
||||
|
||||
utils::VectorRef<const Parameter*> SetOwner(utils::VectorRef<Parameter*> parameters,
|
||||
const tint::sem::CallTarget* owner) {
|
||||
for (auto* parameter : parameters) {
|
||||
parameter->SetOwner(owner);
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Function::Function(const ast::Function* declaration,
|
||||
Type* return_type,
|
||||
std::vector<Parameter*> parameters)
|
||||
: Base(return_type, utils::ToConstPtrVec(parameters), EvaluationStage::kRuntime),
|
||||
utils::VectorRef<Parameter*> parameters)
|
||||
: Base(return_type, SetOwner(std::move(parameters), this), EvaluationStage::kRuntime),
|
||||
declaration_(declaration),
|
||||
workgroup_size_{WorkgroupDimension{1}, WorkgroupDimension{1}, WorkgroupDimension{1}} {
|
||||
for (auto* parameter : parameters) {
|
||||
parameter->SetOwner(this);
|
||||
}
|
||||
}
|
||||
workgroup_size_{WorkgroupDimension{1}, WorkgroupDimension{1}, WorkgroupDimension{1}} {}
|
||||
|
||||
Function::~Function() = default;
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "src/tint/ast/variable.h"
|
||||
#include "src/tint/sem/call.h"
|
||||
#include "src/tint/utils/unique_vector.h"
|
||||
#include "src/tint/utils/vector.h"
|
||||
|
||||
// Forward declarations
|
||||
namespace tint::ast {
|
||||
@@ -62,7 +63,7 @@ class Function final : public Castable<Function, CallTarget> {
|
||||
/// @param parameters the parameters to the function
|
||||
Function(const ast::Function* declaration,
|
||||
Type* return_type,
|
||||
std::vector<Parameter*> parameters);
|
||||
utils::VectorRef<Parameter*> parameters);
|
||||
|
||||
/// Destructor
|
||||
~Function() override;
|
||||
|
||||
@@ -61,7 +61,7 @@ Swizzle::Swizzle(const ast::MemberAccessorExpression* declaration,
|
||||
const Statement* statement,
|
||||
const Constant* constant,
|
||||
const Expression* object,
|
||||
std::vector<uint32_t> indices,
|
||||
utils::VectorRef<uint32_t> indices,
|
||||
bool has_side_effects,
|
||||
const Variable* source_var /* = nullptr */)
|
||||
: Base(declaration,
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
#ifndef SRC_TINT_SEM_MEMBER_ACCESSOR_EXPRESSION_H_
|
||||
#define SRC_TINT_SEM_MEMBER_ACCESSOR_EXPRESSION_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "src/tint/sem/expression.h"
|
||||
#include "src/tint/utils/vector.h"
|
||||
|
||||
// Forward declarations
|
||||
namespace tint::ast {
|
||||
@@ -113,7 +112,7 @@ class Swizzle final : public Castable<Swizzle, MemberAccessorExpression> {
|
||||
const Statement* statement,
|
||||
const Constant* constant,
|
||||
const Expression* object,
|
||||
std::vector<uint32_t> indices,
|
||||
utils::VectorRef<uint32_t> indices,
|
||||
bool has_side_effects,
|
||||
const Variable* source_var = nullptr);
|
||||
|
||||
@@ -121,10 +120,10 @@ class Swizzle final : public Castable<Swizzle, MemberAccessorExpression> {
|
||||
~Swizzle() override;
|
||||
|
||||
/// @return the swizzle indices, if this is a vector swizzle
|
||||
const std::vector<uint32_t>& Indices() const { return indices_; }
|
||||
const auto& Indices() const { return indices_; }
|
||||
|
||||
private:
|
||||
std::vector<uint32_t> const indices_;
|
||||
utils::Vector<uint32_t, 4> const indices_;
|
||||
};
|
||||
|
||||
} // namespace tint::sem
|
||||
|
||||
@@ -14,14 +14,16 @@
|
||||
|
||||
#include "src/tint/sem/type_constructor.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::sem::TypeConstructor);
|
||||
|
||||
namespace tint::sem {
|
||||
|
||||
TypeConstructor::TypeConstructor(const sem::Type* type,
|
||||
const ParameterList& parameters,
|
||||
utils::VectorRef<const Parameter*> parameters,
|
||||
EvaluationStage stage)
|
||||
: Base(type, parameters, stage) {}
|
||||
: Base(type, std::move(parameters), stage) {}
|
||||
|
||||
TypeConstructor::~TypeConstructor() = default;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#define SRC_TINT_SEM_TYPE_CONSTRUCTOR_H_
|
||||
|
||||
#include "src/tint/sem/call_target.h"
|
||||
#include "src/tint/utils/vector.h"
|
||||
|
||||
namespace tint::sem {
|
||||
|
||||
@@ -26,7 +27,9 @@ class TypeConstructor final : public Castable<TypeConstructor, CallTarget> {
|
||||
/// @param type the type that's being constructed
|
||||
/// @param parameters the type constructor parameters
|
||||
/// @param stage the earliest evaluation stage for the expression
|
||||
TypeConstructor(const sem::Type* type, const ParameterList& parameters, EvaluationStage stage);
|
||||
TypeConstructor(const sem::Type* type,
|
||||
utils::VectorRef<const Parameter*> parameters,
|
||||
EvaluationStage stage);
|
||||
|
||||
/// Destructor
|
||||
~TypeConstructor() override;
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace tint::sem {
|
||||
TypeConversion::TypeConversion(const sem::Type* type,
|
||||
const sem::Parameter* parameter,
|
||||
EvaluationStage stage)
|
||||
: Base(type, ParameterList{parameter}, stage) {}
|
||||
: Base(type, utils::Vector<const sem::Parameter*, 1>{parameter}, stage) {}
|
||||
|
||||
TypeConversion::~TypeConversion() = default;
|
||||
|
||||
|
||||
@@ -222,9 +222,6 @@ class Parameter final : public Castable<Parameter, Variable> {
|
||||
const sem::Node* shadows_ = nullptr;
|
||||
};
|
||||
|
||||
/// ParameterList is a list of Parameter
|
||||
using ParameterList = std::vector<const Parameter*>;
|
||||
|
||||
/// VariableUser holds the semantic information for an identifier expression
|
||||
/// node that resolves to a variable.
|
||||
class VariableUser final : public Castable<VariableUser, Expression> {
|
||||
|
||||
Reference in New Issue
Block a user