Stop cloning builtin functions

Previously, any builtin functions would be optimized as a side-effect of
optimizing programs that used them. Now that shared elements aren't
being optimized in that way, we explicitly optimize any shared modules
when they are first created. We don't remove dead elements, but we
we do substitute settings, simplify, and inline.

Bug: skia:10905
Change-Id: I701b5e9f52fb880ef3e6f4c67694d08602f47e95
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/336440
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
diff --git a/src/sksl/SkSLCompiler.h b/src/sksl/SkSLCompiler.h
index 47089b8..bf5a576 100644
--- a/src/sksl/SkSLCompiler.h
+++ b/src/sksl/SkSLCompiler.h
@@ -54,6 +54,7 @@
 class ProgramUsage;
 
 struct LoadedModule {
+    Program::Kind                                fKind;
     std::shared_ptr<SymbolTable>                 fSymbols;
     std::vector<std::unique_ptr<ProgramElement>> fElements;
 };
@@ -266,8 +267,11 @@
      */
     bool optimize(Program& program);
 
+    bool optimize(LoadedModule& module);
+
     Position position(int offset);
 
+    std::shared_ptr<Context> fContext;
     const ShaderCapsClass* fCaps = nullptr;
 
     std::shared_ptr<SymbolTable> fRootSymbolTable;
@@ -294,7 +298,6 @@
     int fFlags;
 
     const String* fSource;
-    std::shared_ptr<Context> fContext;
     int fErrorCount;
     String fErrorText;