Performance experiment: Disable SkSL optimization in nanobench/skpbench

Cloned from http://review.skia.org/369716
Re-running the experiment now that @switch is supported when
optimizations are disabled.

Change-Id: I428051d9c679a8084589fba428a637f36587be16
Bug: skia:11341
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/374516
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp
index 78b556d..ed04c20 100644
--- a/bench/nanobench.cpp
+++ b/bench/nanobench.cpp
@@ -65,6 +65,7 @@
 extern bool gUseSkVMBlitter;
 extern bool gSkVMAllowJIT;
 extern bool gSkVMJITViaDylib;
+extern bool gSkSLAllowOptimization;
 
 #ifndef SK_BUILD_FOR_WIN
     #include <unistd.h>
@@ -1240,6 +1241,7 @@
     gSkForceRasterPipelineBlitter = FLAGS_forceRasterPipeline;
     gUseSkVMBlitter = FLAGS_skvm;
     gSkVMAllowJIT = gSkVMJITViaDylib = FLAGS_jit;
+    gSkSLAllowOptimization = false;  // Temporary experiment
 
     int runs = 0;
     BenchmarkStream benchStream;
diff --git a/src/sksl/SkSLCompiler.cpp b/src/sksl/SkSLCompiler.cpp
index c4df182..1235754 100644
--- a/src/sksl/SkSLCompiler.cpp
+++ b/src/sksl/SkSLCompiler.cpp
@@ -70,6 +70,8 @@
 
 #endif
 
+bool gSkSLAllowOptimization = true;
+
 namespace SkSL {
 
 using RefKind = VariableReference::RefKind;
@@ -1474,7 +1476,7 @@
     bool success = false;
     if (fErrorCount) {
         // Do not return programs that failed to compile.
-    } else if (settings.fOptimize && !this->optimize(*program)) {
+    } else if (settings.fOptimize && gSkSLAllowOptimization && !this->optimize(*program)) {
         // Do not return programs that failed to optimize.
     } else {
         // We have a successful program!
diff --git a/tools/skpbench/skpbench.cpp b/tools/skpbench/skpbench.cpp
index 34ab43b..9388852 100644
--- a/tools/skpbench/skpbench.cpp
+++ b/tools/skpbench/skpbench.cpp
@@ -88,6 +88,8 @@
 
 static constexpr int kNumFlushesToPrimeCache = 3;
 
+extern bool gSkSLAllowOptimization;
+
 struct Sample {
     using duration = std::chrono::nanoseconds;
 
@@ -496,6 +498,8 @@
         exit(0); // This can be used to print the header and quit.
     }
 
+    gSkSLAllowOptimization = false;  // Temporary experiment
+
     // Parse the config.
     const SkCommandLineConfigGpu* config = nullptr; // Initialize for spurious warning.
     SkCommandLineConfigArray configs;