[spirv-writer] Only add used variables to entry point.

This Cl updates the entry point code to only output Input/Output
variabes which are referenced by the function instead of all
Input/Output variables.

Bug: tint:28
Change-Id: Idc429e02cac8dac7fc7b609cbd7f88039695829e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23623
Reviewed-by: David Neto <dneto@google.com>
diff --git a/src/type_determiner.cc b/src/type_determiner.cc
index 23de278..fa6a03c 100644
--- a/src/type_determiner.cc
+++ b/src/type_determiner.cc
@@ -161,6 +161,19 @@
   error_ += msg;
 }
 
+void TypeDeterminer::set_referenced_from_function_if_needed(
+    ast::Variable* var) {
+  if (current_function_ == nullptr) {
+    return;
+  }
+  if (var->storage_class() == ast::StorageClass::kNone ||
+      var->storage_class() == ast::StorageClass::kFunction) {
+    return;
+  }
+
+  current_function_->add_referenced_module_variable(var);
+}
+
 bool TypeDeterminer::Determine() {
   for (const auto& var : mod_->global_variables()) {
     variable_stack_.set_global(var->name(), var.get());
@@ -190,6 +203,8 @@
 bool TypeDeterminer::DetermineFunction(ast::Function* func) {
   name_to_function_[func->name()] = func;
 
+  current_function_ = func;
+
   variable_stack_.push_scope();
   for (const auto& param : func->params()) {
     variable_stack_.set(param->name(), param.get());
@@ -200,6 +215,8 @@
   }
   variable_stack_.pop_scope();
 
+  current_function_ = nullptr;
+
   return true;
 }
 
@@ -567,6 +584,8 @@
           ctx_.type_mgr().Get(std::make_unique<ast::type::PointerType>(
               var->type(), var->storage_class())));
     }
+
+    set_referenced_from_function_if_needed(var);
     return true;
   }