sem: Track function callsites in sem::Function

This will soon be used by a new MSL sanitizing transform.

Change-Id: I254c0d26a843cf6153dc8d146389d09b615e8d89
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/51961
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: James Price <jrprice@google.com>
This commit is contained in:
James Price 2021-05-22 12:48:24 +00:00 committed by Tint LUCI CQ
parent 28ec968b4f
commit bcefe46f44
4 changed files with 15 additions and 2 deletions

View File

@ -1653,6 +1653,8 @@ bool Resolver::Call(ast::CallExpression* call) {
}
auto* callee_func = callee_func_it->second;
callee_func->callsites.push_back(call);
// Note: Requires called functions to be resolved first.
// This is currently guaranteed as functions must be declared before
// use.
@ -2574,7 +2576,8 @@ void Resolver::CreateSemanticNodes() const {
info->declaration, const_cast<sem::Type*>(info->return_type),
remap_vars(info->parameters), remap_vars(info->referenced_module_vars),
remap_vars(info->local_referenced_module_vars), info->return_statements,
ancestor_entry_points[func->symbol()], info->workgroup_size);
info->callsites, ancestor_entry_points[func->symbol()],
info->workgroup_size);
func_info_to_sem_func.emplace(info, sem_func);
sem.Add(func, sem_func);
}

View File

@ -111,6 +111,7 @@ class Resolver {
UniqueVector<VariableInfo*> referenced_module_vars;
UniqueVector<VariableInfo*> local_referenced_module_vars;
std::vector<const ast::ReturnStatement*> return_statements;
std::vector<const ast::CallExpression*> callsites;
sem::Type* return_type = nullptr;
std::string return_type_name;
std::array<sem::WorkgroupDimension, 3> workgroup_size;

View File

@ -46,6 +46,7 @@ Function::Function(ast::Function* declaration,
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, GetParameters(parameters)),
@ -54,6 +55,7 @@ Function::Function(ast::Function* 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)) {}

View File

@ -28,6 +28,7 @@ namespace tint {
namespace ast {
class BindingDecoration;
class BuiltinDecoration;
class CallExpression;
class Function;
class GroupDecoration;
class LocationDecoration;
@ -62,7 +63,7 @@ class Function : public Castable<Function, CallTarget> {
/// @param referenced_module_vars the referenced module variables
/// @param local_referenced_module_vars the locally referenced module
/// @param return_statements the function return statements
/// variables
/// @param callsites the callsites of the function
/// @param ancestor_entry_points the ancestor entry points
/// @param workgroup_size the workgroup size
Function(ast::Function* declaration,
@ -71,6 +72,7 @@ class Function : public Castable<Function, CallTarget> {
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);
@ -97,6 +99,10 @@ class Function : public Castable<Function, CallTarget> {
const std::vector<const ast::ReturnStatement*> ReturnStatements() const {
return return_statements_;
}
/// @returns the list of callsites of this function
std::vector<const ast::CallExpression*> CallSites() const {
return callsites_;
}
/// @returns the ancestor entry points
const std::vector<Symbol>& AncestorEntryPoints() const {
return ancestor_entry_points_;
@ -176,6 +182,7 @@ class Function : public Castable<Function, CallTarget> {
std::vector<const Variable*> const referenced_module_vars_;
std::vector<const Variable*> const local_referenced_module_vars_;
std::vector<const ast::ReturnStatement*> const return_statements_;
std::vector<const ast::CallExpression*> const callsites_;
std::vector<Symbol> const ancestor_entry_points_;
std::array<WorkgroupDimension, 3> workgroup_size_;
};