Reland "Revert "Omit dead SkSL functions""

This reverts commit fd1173ac71.

Reason for revert: TSAN failure: https://chromium-swarm.appspot.com/task?id=4c93823229fa6a10

Original change's description:
> Revert "Revert "Omit dead SkSL functions""
> 
> This reverts commit 7c969f26bc.
> 
> Change-Id: I8fb99f271e2ecaeb83d570cc2d2cf8851bc776f0
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/293338
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>

TBR=bsalomon@google.com,brianosman@google.com,ethannicholas@google.com

# Not skipping CQ checks because this is a reland.

Change-Id: Iab3ee5a336074676ebd0b761922ececf189752ef
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/293843
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
Ethan Nicholas 2020-06-03 16:41:22 +00:00 committed by Skia Commit-Bot
parent 59e087ef3f
commit a15f2bfb6f
9 changed files with 25 additions and 48 deletions

View File

@ -121,7 +121,6 @@ void SkParticleEffectParams::prepare(const skresources::ResourceProvider* resour
auto buildProgram = [this](const SkSL::String& code, Program* p) {
SkSL::Compiler compiler;
SkSL::Program::Settings settings;
settings.fRemoveDeadFunctions = false;
SkTArray<std::unique_ptr<SkParticleExternalValue>> externalValues;

View File

@ -1448,20 +1448,6 @@ bool Compiler::optimize(Program& program) {
this->scanCFG((FunctionDefinition&) element);
}
}
// we wait until after analysis to remove dead functions so that we still report errors
// even in unused code
if (program.fSettings.fRemoveDeadFunctions) {
for (auto iter = program.fElements.begin(); iter != program.fElements.end(); ) {
if ((*iter)->fKind == ProgramElement::kFunction_Kind) {
const FunctionDefinition& f = (const FunctionDefinition&) **iter;
if (!f.fDeclaration.fCallCount && f.fDeclaration.fName != "main") {
iter = program.fElements.erase(iter);
continue;
}
}
++iter;
}
}
if (program.fKind != Program::kFragmentProcessor_Kind) {
for (auto iter = program.fElements.begin(); iter != program.fElements.end();) {
if ((*iter)->fKind == ProgramElement::kVar_Kind) {

View File

@ -2061,16 +2061,9 @@ std::unique_ptr<Statement> IRGenerator::inlineStatement(int offset,
}
std::unique_ptr<Expression> initialValue = expr(decl.fValue);
const Variable* old = decl.fVar;
// need to copy the var name in case the originating function is discarded and we lose
// its symbols
std::unique_ptr<String> name(new String(old->fName));
String* namePtr = (String*) fSymbolTable->takeOwnership(std::move(name));
std::unique_ptr<Symbol> type(new Type(old->fType));
Type* typePtr = (Type*) fSymbolTable->takeOwnership(std::move(type));
Variable* clone = (Variable*) fSymbolTable->takeOwnership(std::unique_ptr<Symbol>(
new Variable(offset, old->fModifiers,
namePtr->c_str(), *typePtr,
old->fStorage,
new Variable(offset, old->fModifiers, old->fName,
old->fType, old->fStorage,
initialValue.get())));
(*varMap)[old] = clone;
return std::unique_ptr<Statement>(new VarDeclaration(clone, std::move(sizes),
@ -2082,10 +2075,8 @@ std::unique_ptr<Statement> IRGenerator::inlineStatement(int offset,
for (const auto& var : decls.fVars) {
vars.emplace_back((VarDeclaration*) stmt(var).release());
}
std::unique_ptr<Symbol> type(new Type(decls.fBaseType));
Type* typePtr = (Type*) fSymbolTable->takeOwnership(std::move(type));
return std::unique_ptr<Statement>(new VarDeclarationsStatement(
std::unique_ptr<VarDeclarations>(new VarDeclarations(offset, typePtr,
std::unique_ptr<VarDeclarations>(new VarDeclarations(offset, &decls.fBaseType,
std::move(vars)))));
}
case Statement::kWhile_Kind: {

View File

@ -21,13 +21,7 @@ struct FunctionCall : public Expression {
std::vector<std::unique_ptr<Expression>> arguments)
: INHERITED(offset, kFunctionCall_Kind, type)
, fFunction(std::move(function))
, fArguments(std::move(arguments)) {
++fFunction.fCallCount;
}
~FunctionCall() override {
--fFunction.fCallCount;
}
, fArguments(std::move(arguments)) {}
bool hasProperty(Property property) const override {
if (property == Property::kSideEffects && (fFunction.fModifiers.fFlags &

View File

@ -114,7 +114,6 @@ struct FunctionDeclaration : public Symbol {
Modifiers fModifiers;
const std::vector<const Variable*> fParameters;
const Type& fReturnType;
mutable int fCallCount = 0;
typedef Symbol INHERITED;
};

View File

@ -111,9 +111,6 @@ struct Program {
// binding and set number of the uniform buffer.
int fRTHeightBinding = -1;
int fRTHeightSet = -1;
// If true, remove any uncalled functions other than main(). Note that a function which
// starts out being used may end up being uncalled after optimization.
bool fRemoveDeadFunctions = true;
std::unordered_map<String, Value> fArgs;
};

View File

@ -14,7 +14,6 @@ static void test(skiatest::Reporter* r, const char* src, const GrShaderCaps& cap
std::vector<const char*> expectedH, std::vector<const char*> expectedCPP) {
SkSL::Program::Settings settings;
settings.fCaps = &caps;
settings.fRemoveDeadFunctions = false;
SkSL::Compiler compiler;
SkSL::StringStream output;
std::unique_ptr<SkSL::Program> program = compiler.convertProgram(

View File

@ -104,6 +104,22 @@ DEF_TEST(SkSLFunctions, r) {
*SkSL::ShaderCapsFactory::Default(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"float foo(float v[2]) {\n"
" return v[0] * v[1];\n"
"}\n"
"void bar(inout float x) {\n"
" float y[2], z;\n"
" y[0] = x;\n"
" y[1] = x * 2.0;\n"
" float inlineResult117;\n"
" float[2] inlineArg117_0 = y;\n"
" {\n"
" inlineResult117 = inlineArg117_0[0] * inlineArg117_0[1];\n"
" }\n"
" z = inlineResult117;\n"
"\n"
" x = z;\n"
"}\n"
"void main() {\n"
" float x = 10.0;\n"
" float inlineArg161_0 = x;\n"
@ -1780,7 +1796,6 @@ DEF_TEST(SkSLGeometryShaders, r) {
"EmitVertex();"
"}"
"void main() {"
"test();"
"sk_Position = sk_in[0].sk_Position + float4(-0.5, 0, 0, sk_InvocationID);"
"EmitVertex();"
"}",
@ -1789,12 +1804,11 @@ DEF_TEST(SkSLGeometryShaders, r) {
"int sk_InvocationID;\n"
"layout (points) in ;\n"
"layout (line_strip, max_vertices = 4) out ;\n"
"void _invoke() {\n"
" {\n"
"void test() {\n"
" gl_Position = gl_in[0].gl_Position + vec4(0.5, 0.0, 0.0, float(sk_InvocationID));\n"
" EmitVertex();\n"
" }\n"
"\n"
"}\n"
"void _invoke() {\n"
" gl_Position = gl_in[0].gl_Position + vec4(-0.5, 0.0, 0.0, float(sk_InvocationID));\n"
" EmitVertex();\n"
"}\n"

View File

@ -622,7 +622,6 @@ DEF_TEST(SkSLInterpreterCompound, r) {
SkSL::Compiler compiler;
SkSL::Program::Settings settings;
settings.fRemoveDeadFunctions = false;
std::unique_ptr<SkSL::Program> program = compiler.convertProgram(
SkSL::Program::kGeneric_Kind,
SkSL::String(src), settings);
@ -764,7 +763,6 @@ DEF_TEST(SkSLInterpreterFunctions, r) {
SkSL::Compiler compiler;
SkSL::Program::Settings settings;
settings.fRemoveDeadFunctions = false;
std::unique_ptr<SkSL::Program> program = compiler.convertProgram(
SkSL::Program::kGeneric_Kind,
SkSL::String(src), settings);