Add GetConstantValueForVariable to constant-folder.

This can be used in places which simplify an expression at IR generation
time. e.g. `const bool x = true; @if (x) {...}` could be evaluated at
compile time by calling GetConstantValueForVariable before checking for
a BoolLiteral and flattening the if. It is also used at the top of
ConstantFolder::Simplify to reduce either side of the binary
expression being simplified, in case it's a const variable.

We don't use a lot of const variables in our tests, but this does
improve the code generation in ConstVariableComparison.sksl
when constant-propagation is disabled: http://screen/gnWPhQG8Jc5cER9

Change-Id: I26309769cd16a6833b74b11a115b87c3dc312514
Bug: skia:11343
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/378017
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2 files changed