Make Program owned-elements public.
Change-Id: I7680376d0f0a7bbaa7cb845e2223b9ce4d29c96f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/456797
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
diff --git a/src/sksl/SkSLAnalysis.cpp b/src/sksl/SkSLAnalysis.cpp
index d637fbb..7d7978a 100644
--- a/src/sksl/SkSLAnalysis.cpp
+++ b/src/sksl/SkSLAnalysis.cpp
@@ -582,7 +582,7 @@
// Check all of the program's owned elements. (Built-in elements are assumed to be valid.)
TestsAndExpressions visitor{*program.fContext};
- for (const std::unique_ptr<ProgramElement>& element : program.ownedElements()) {
+ for (const std::unique_ptr<ProgramElement>& element : program.fOwnedElements) {
visitor.visitProgramElement(*element);
}
}
diff --git a/src/sksl/SkSLCompiler.cpp b/src/sksl/SkSLCompiler.cpp
index a3f9ede..4d429b6 100644
--- a/src/sksl/SkSLCompiler.cpp
+++ b/src/sksl/SkSLCompiler.cpp
@@ -477,12 +477,12 @@
return true;
};
- program.fElements.erase(std::remove_if(program.fElements.begin(),
- program.fElements.end(),
- [&](const std::unique_ptr<ProgramElement>& element) {
- return isDeadFunction(element.get());
- }),
- program.fElements.end());
+ program.fOwnedElements.erase(std::remove_if(program.fOwnedElements.begin(),
+ program.fOwnedElements.end(),
+ [&](const std::unique_ptr<ProgramElement>& pe) {
+ return isDeadFunction(pe.get());
+ }),
+ program.fOwnedElements.end());
program.fSharedElements.erase(std::remove_if(program.fSharedElements.begin(),
program.fSharedElements.end(),
isDeadFunction),
@@ -508,12 +508,12 @@
return true;
};
- program.fElements.erase(std::remove_if(program.fElements.begin(),
- program.fElements.end(),
- [&](const std::unique_ptr<ProgramElement>& element) {
- return isDeadVariable(element.get());
- }),
- program.fElements.end());
+ program.fOwnedElements.erase(std::remove_if(program.fOwnedElements.begin(),
+ program.fOwnedElements.end(),
+ [&](const std::unique_ptr<ProgramElement>& pe) {
+ return isDeadVariable(pe.get());
+ }),
+ program.fOwnedElements.end());
program.fSharedElements.erase(std::remove_if(program.fSharedElements.begin(),
program.fSharedElements.end(),
isDeadVariable),
@@ -523,7 +523,7 @@
}
void Compiler::removeUnreachableCode(Program& program, ProgramUsage* usage) {
- for (std::unique_ptr<ProgramElement>& pe : program.ownedElements()) {
+ for (std::unique_ptr<ProgramElement>& pe : program.fOwnedElements) {
if (pe->is<FunctionDefinition>()) {
Transform::EliminateUnreachableCode(pe->as<FunctionDefinition>().body(), usage);
}
@@ -542,7 +542,7 @@
if (this->errorCount() == 0) {
// Run the inliner only once; it is expensive! Multiple passes can occasionally shake out
// more wins, but it's diminishing returns.
- this->runInliner(program.ownedElements(), program.fSymbols, usage);
+ this->runInliner(program.fOwnedElements, program.fSymbols, usage);
// Unreachable code can confuse some drivers, so it's worth removing. (skia:12012)
this->removeUnreachableCode(program, usage);
@@ -589,7 +589,7 @@
if (fContext->fConfig->strictES2Mode() && this->errorCount() == 0) {
// Enforce Appendix A, Section 5 of the GLSL ES 1.00 spec -- Indexing. This logic assumes
// that all loops meet the criteria of Section 4, and if they don't, could crash.
- for (const auto& pe : program.ownedElements()) {
+ for (const auto& pe : program.fOwnedElements) {
Analysis::ValidateIndexingForES2(*pe, this->errorReporter());
}
// Verify that the program size is reasonable after unrolling and inlining. This also
diff --git a/src/sksl/analysis/SkSLCheckProgramUnrolledSize.cpp b/src/sksl/analysis/SkSLCheckProgramUnrolledSize.cpp
index 6a8032a..16d28da 100644
--- a/src/sksl/analysis/SkSLCheckProgramUnrolledSize.cpp
+++ b/src/sksl/analysis/SkSLCheckProgramUnrolledSize.cpp
@@ -190,7 +190,7 @@
// Process every function in our program.
ProgramSizeVisitor visitor{context};
- for (const std::unique_ptr<ProgramElement>& element : program.ownedElements()) {
+ for (const std::unique_ptr<ProgramElement>& element : program.fOwnedElements) {
if (element->is<FunctionDefinition>()) {
// Visit every function--we want to detect static recursion and report it as an error,
// even in unreferenced functions.
diff --git a/src/sksl/ir/SkSLProgram.h b/src/sksl/ir/SkSLProgram.h
index 6ebcb62..67ee592 100644
--- a/src/sksl/ir/SkSLProgram.h
+++ b/src/sksl/ir/SkSLProgram.h
@@ -87,9 +87,9 @@
, fContext(context)
, fSymbols(symbols)
, fPool(std::move(pool))
- , fInputs(inputs)
- , fElements(std::move(elements))
+ , fOwnedElements(std::move(elements))
, fSharedElements(std::move(sharedElements))
+ , fInputs(inputs)
, fModifiers(std::move(modifiers)) {
fUsage = Analysis::GetUsage(*this);
}
@@ -100,7 +100,7 @@
// delete on a pooled node.)
AutoAttachPoolToThread attach(fPool.get());
- fElements.clear();
+ fOwnedElements.clear();
fContext.reset();
fSymbols.reset();
fModifiers.reset();
@@ -150,12 +150,12 @@
};
iterator begin() const {
- return iterator(fProgram.fElements.begin(), fProgram.fElements.end(),
+ return iterator(fProgram.fOwnedElements.begin(), fProgram.fOwnedElements.end(),
fProgram.fSharedElements.begin(), fProgram.fSharedElements.end());
}
iterator end() const {
- return iterator(fProgram.fElements.end(), fProgram.fElements.end(),
+ return iterator(fProgram.fOwnedElements.end(), fProgram.fOwnedElements.end(),
fProgram.fSharedElements.end(), fProgram.fSharedElements.end());
}
@@ -171,11 +171,6 @@
// modify anything (as you might be mutating shared data).
ElementsCollection elements() const { return ElementsCollection(*this); }
- // Can be used to iterate over *just* the elements owned by the Program, not shared builtins.
- // The iterator's value type is 'std::unique_ptr<ProgramElement>', and mutation is allowed.
- std::vector<std::unique_ptr<ProgramElement>>& ownedElements() { return fElements; }
- const std::vector<std::unique_ptr<ProgramElement>>& ownedElements() const { return fElements; }
-
String description() const {
String result;
for (const ProgramElement* e : this->elements()) {
@@ -189,15 +184,18 @@
std::unique_ptr<String> fSource;
std::unique_ptr<ProgramConfig> fConfig;
std::shared_ptr<Context> fContext;
- // it's important to keep fElements defined after (and thus destroyed before) fSymbols,
+ // it's important to keep fOwnedElements defined after (and thus destroyed before) fSymbols,
// because destroying elements can modify reference counts in symbols
std::shared_ptr<SymbolTable> fSymbols;
std::unique_ptr<Pool> fPool;
+ // Contains *only* elements owned exclusively by this program.
+ std::vector<std::unique_ptr<ProgramElement>> fOwnedElements;
+ // Contains *only* elements owned by a built-in module that are included in this program.
+ // Use elements() to iterate over the combined set of owned + shared elements.
+ std::vector<const ProgramElement*> fSharedElements;
Inputs fInputs;
private:
- std::vector<std::unique_ptr<ProgramElement>> fElements;
- std::vector<const ProgramElement*> fSharedElements;
std::unique_ptr<ModifiersPool> fModifiers;
std::unique_ptr<ProgramUsage> fUsage;
diff --git a/src/sksl/transform/SkSLEliminateDeadLocalVariables.cpp b/src/sksl/transform/SkSLEliminateDeadLocalVariables.cpp
index 3373b14d..2acc668 100644
--- a/src/sksl/transform/SkSLEliminateDeadLocalVariables.cpp
+++ b/src/sksl/transform/SkSLEliminateDeadLocalVariables.cpp
@@ -83,7 +83,7 @@
if (DeadLocalVariableEliminator::CanEliminate(var, counts)) {
// This program contains at least one dead local variable.
// Scan the program for any dead local variables and eliminate them all.
- for (std::unique_ptr<ProgramElement>& pe : program.ownedElements()) {
+ for (std::unique_ptr<ProgramElement>& pe : program.fOwnedElements) {
if (pe->is<FunctionDefinition>()) {
visitor.visitProgramElement(*pe);
}