sem: Add Owner() to sem::Parameter

Change-Id: I3de1e2437b9604378b8368494363e19070443670
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/59201
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton
2021-07-22 13:24:59 +00:00
parent 0f2d95dea3
commit 4ffcf067a3
10 changed files with 110 additions and 28 deletions

View File

@@ -21,6 +21,7 @@
#include "src/sem/sampled_texture_type.h"
#include "src/sem/storage_texture_type.h"
#include "src/sem/variable.h"
#include "src/utils/to_const_ptr_vec.h"
TINT_INSTANTIATE_TYPEINFO(tint::sem::Function);
@@ -29,21 +30,25 @@ namespace sem {
Function::Function(ast::Function* declaration,
Type* return_type,
ParameterList parameters,
std::vector<Parameter*> parameters,
std::vector<const Variable*> referenced_module_vars,
std::vector<const Variable*> local_referenced_module_vars,
std::vector<const ast::ReturnStatement*> return_statements,
std::vector<const ast::CallExpression*> callsites,
std::vector<Symbol> ancestor_entry_points,
std::array<WorkgroupDimension, 3> workgroup_size)
: Base(return_type, std::move(parameters)),
: Base(return_type, utils::ToConstPtrVec(parameters)),
declaration_(declaration),
referenced_module_vars_(std::move(referenced_module_vars)),
local_referenced_module_vars_(std::move(local_referenced_module_vars)),
return_statements_(std::move(return_statements)),
callsites_(callsites),
ancestor_entry_points_(std::move(ancestor_entry_points)),
workgroup_size_(std::move(workgroup_size)) {}
workgroup_size_(std::move(workgroup_size)) {
for (auto* parameter : parameters) {
parameter->SetOwner(this);
}
}
Function::~Function() = default;

View File

@@ -68,7 +68,7 @@ class Function : public Castable<Function, CallTarget> {
/// @param workgroup_size the workgroup size
Function(ast::Function* declaration,
Type* return_type,
ParameterList parameters,
std::vector<Parameter*> parameters,
std::vector<const Variable*> referenced_module_vars,
std::vector<const Variable*> local_referenced_module_vars,
std::vector<const ast::ReturnStatement*> return_statements,

View File

@@ -14,6 +14,10 @@
#include "src/sem/intrinsic.h"
#include <vector>
#include "src/utils/to_const_ptr_vec.h"
TINT_INSTANTIATE_TYPEINFO(tint::sem::Intrinsic);
namespace tint {
@@ -98,13 +102,17 @@ bool IsAtomicIntrinsic(IntrinsicType i) {
Intrinsic::Intrinsic(IntrinsicType type,
sem::Type* return_type,
ParameterList parameters,
std::vector<Parameter*> parameters,
PipelineStageSet supported_stages,
bool is_deprecated)
: Base(return_type, parameters),
: Base(return_type, utils::ToConstPtrVec(parameters)),
type_(type),
supported_stages_(supported_stages),
is_deprecated_(is_deprecated) {}
is_deprecated_(is_deprecated) {
for (auto* parameter : parameters) {
parameter->SetOwner(this);
}
}
Intrinsic::~Intrinsic() = default;

View File

@@ -16,6 +16,7 @@
#define SRC_SEM_INTRINSIC_H_
#include <string>
#include <vector>
#include "src/sem/call_target.h"
#include "src/sem/intrinsic_type.h"
@@ -88,7 +89,7 @@ class Intrinsic : public Castable<Intrinsic, CallTarget> {
/// deprecated
Intrinsic(IntrinsicType type,
sem::Type* return_type,
ParameterList parameters,
std::vector<Parameter*> parameters,
PipelineStageSet supported_stages,
bool is_deprecated);

View File

@@ -69,11 +69,14 @@ GlobalVariable::GlobalVariable(const ast::Variable* declaration,
GlobalVariable::~GlobalVariable() = default;
Parameter::Parameter(const ast::Variable* declaration,
uint32_t index,
const sem::Type* type,
ast::StorageClass storage_class,
ast::Access access,
const ParameterUsage usage /* = ParameterUsage::kNone */)
: Base(declaration, type, storage_class, access), usage_(usage) {}
: Base(declaration, type, storage_class, access),
index_(index),
usage_(usage) {}
Parameter::~Parameter() = default;

View File

@@ -34,6 +34,7 @@ class Variable;
namespace sem {
// Forward declarations
class CallTarget;
class Type;
class VariableUser;
@@ -143,27 +144,37 @@ class Parameter : public Castable<Parameter, Variable> {
public:
/// Constructor for function parameters
/// @param declaration the AST declaration node
/// @param index the index of the parmeter in the function
/// @param type the variable type
/// @param storage_class the variable storage class
/// @param access the variable access control type
/// @param usage the semantic usage for the parameter
Parameter(const ast::Variable* declaration,
uint32_t index,
const sem::Type* type,
ast::StorageClass storage_class,
ast::Access access,
const ParameterUsage usage = ParameterUsage::kNone);
/// Copy constructor
Parameter(const Parameter&);
/// Destructor
~Parameter() override;
/// @return the index of the parmeter in the function
uint32_t Index() const { return index_; }
/// @returns the semantic usage for the parameter
ParameterUsage Usage() const { return usage_; }
/// @returns the CallTarget owner of this parameter
CallTarget const* Owner() const { return owner_; }
/// @param owner the CallTarget owner of this parameter
void SetOwner(CallTarget const* owner) { owner_ = owner; }
private:
uint32_t const index_;
ParameterUsage const usage_;
CallTarget const* owner_;
};
/// ParameterList is a list of Parameter