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>
diff --git a/src/resolver/resolver.cc b/src/resolver/resolver.cc
index 757da88..8058ab0 100644
--- a/src/resolver/resolver.cc
+++ b/src/resolver/resolver.cc
@@ -1653,6 +1653,8 @@
       }
       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 @@
         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);
   }
diff --git a/src/resolver/resolver.h b/src/resolver/resolver.h
index 402e051..f002f97 100644
--- a/src/resolver/resolver.h
+++ b/src/resolver/resolver.h
@@ -111,6 +111,7 @@
     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;
diff --git a/src/sem/function.cc b/src/sem/function.cc
index f33fc07..511c0a1 100644
--- a/src/sem/function.cc
+++ b/src/sem/function.cc
@@ -46,6 +46,7 @@
                    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 @@
       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)) {}
 
diff --git a/src/sem/function.h b/src/sem/function.h
index 94cc02e..d48047b 100644
--- a/src/sem/function.h
+++ b/src/sem/function.h
@@ -28,6 +28,7 @@
 namespace ast {
 class BindingDecoration;
 class BuiltinDecoration;
+class CallExpression;
 class Function;
 class GroupDecoration;
 class LocationDecoration;
@@ -62,7 +63,7 @@
   /// @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 @@
            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 @@
   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 @@
   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_;
 };