aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/SkSLCFGGenerator.h
diff options
context:
space:
mode:
authorGravatar Ethan Nicholas <ethannicholas@google.com>2017-02-02 16:11:39 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-02-03 14:37:55 +0000
commit113628d76176a1ab3e6719c59efff23cd10ab213 (patch)
tree89c7815c9b7e86a4b9b573ee8ecc6bb7a946de2d /src/sksl/SkSLCFGGenerator.h
parent3f36369a94d2c49c91bcd0249bf351da36a6d40d (diff)
Added dead variable / code elimination to skslc.
BUG=skia: Change-Id: Ib037730803a8f222f099de0e001fe06ad452a22c Reviewed-on: https://skia-review.googlesource.com/7584 Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Reviewed-by: Ben Wagner <benjaminwagner@google.com>
Diffstat (limited to 'src/sksl/SkSLCFGGenerator.h')
-rw-r--r--src/sksl/SkSLCFGGenerator.h51
1 files changed, 48 insertions, 3 deletions
diff --git a/src/sksl/SkSLCFGGenerator.h b/src/sksl/SkSLCFGGenerator.h
index 337fdfac35..3fb7acbc17 100644
--- a/src/sksl/SkSLCFGGenerator.h
+++ b/src/sksl/SkSLCFGGenerator.h
@@ -26,6 +26,15 @@ struct BasicBlock {
kExpression_Kind
};
+ SkString description() const {
+ if (fKind == kStatement_Kind) {
+ return (*fStatement)->description();
+ } else {
+ ASSERT(fKind == kExpression_Kind);
+ return (*fExpression)->description();
+ }
+ }
+
Kind fKind;
// if false, this node should not be subject to constant propagation. This happens with
// compound assignment (i.e. x *= 2), in which the value x is used as an rvalue for
@@ -35,10 +44,46 @@ struct BasicBlock {
// assignment if the target is constant (i.e. x = 1; x *= 2; should become x = 1; x = 1 * 2;
// and then collapse down to a simple x = 2;).
bool fConstantPropagation;
+ // we store pointers to the unique_ptrs so that we can replace expressions or statements
+ // during optimization without having to regenerate the entire tree
std::unique_ptr<Expression>* fExpression;
- const Statement* fStatement;
+ std::unique_ptr<Statement>* fStatement;
};
+ /**
+ * Attempts to remove the expression (and its subexpressions) pointed to by the iterator. If the
+ * expression can be cleanly removed, returns true and updates the iterator to point to the
+ * expression after the deleted expression. Otherwise returns false (and the CFG will need to be
+ * regenerated).
+ */
+ bool SK_WARN_UNUSED_RESULT tryRemoveExpression(std::vector<BasicBlock::Node>::iterator* iter);
+
+ /**
+ * Locates and attempts remove an expression occurring before the expression pointed to by iter.
+ * If the expression can be cleanly removed, returns true and resets iter to a valid iterator
+ * pointing to the same expression it did initially. Otherwise returns false (and the CFG will
+ * need to be regenerated).
+ */
+ bool SK_WARN_UNUSED_RESULT tryRemoveExpressionBefore(
+ std::vector<BasicBlock::Node>::iterator* iter,
+ Expression* e);
+
+ /**
+ * As tryRemoveExpressionBefore, but for lvalues. As lvalues are at most partially evaluated
+ * (for instance, x[i] = 0 evaluates i but not x) this will only look for the parts of the
+ * lvalue that are actually evaluated.
+ */
+ bool SK_WARN_UNUSED_RESULT tryRemoveLValueBefore(std::vector<BasicBlock::Node>::iterator* iter,
+ Expression* lvalue);
+
+ /**
+ * Attempts to inserts a new expression before the node pointed to by iter. If the
+ * expression can be cleanly inserted, returns true and updates the iterator to point to the
+ * newly inserted expression. Otherwise returns false (and the CFG will need to be regenerated).
+ */
+ bool SK_WARN_UNUSED_RESULT tryInsertExpression(std::vector<BasicBlock::Node>::iterator* iter,
+ std::unique_ptr<Expression>* expr);
+
std::vector<Node> fNodes;
std::set<BlockId> fEntrances;
std::set<BlockId> fExits;
@@ -81,10 +126,10 @@ class CFGGenerator {
public:
CFGGenerator() {}
- CFG getCFG(const FunctionDefinition& f);
+ CFG getCFG(FunctionDefinition& f);
private:
- void addStatement(CFG& cfg, const Statement* s);
+ void addStatement(CFG& cfg, std::unique_ptr<Statement>* s);
void addExpression(CFG& cfg, std::unique_ptr<Expression>* e, bool constantPropagate);