return any_inlined;
}
+void ExpressionInliner::visit(Block &block)
+{
+ TraversingVisitor::visit(block);
+
+ /* Block inlining of any assignments from the scope as we leave it. They
+ may depend on local variables or might not always be executed. */
+ for(ExpressionInfo &e: expressions)
+ if(e.assign_scope==&block)
+ e.blocked = true;
+}
+
void ExpressionInliner::visit(NodePtr<Expression> &expr)
{
r_ref_info = nullptr;
for(Block *i=iteration_body->parent; (!use.blocked && i); i=i->parent)
use.blocked = (i==r_ref_info->assign_scope);
}
-
- /* Block inlining assignments from from inner scopes. The assignment may
- depend on local variables of that scope or may not always be executed. */
- for(Block *i=r_ref_info->assign_scope->parent; (!use.blocked && i); i=i->parent)
- use.blocked = (i==current_block);
}
r_oper = expr->oper;
r_ref_info = nullptr;
for(; (i!=assignments.end() && i->first.declaration==assign.target.declaration); ++i)
if(targets_overlap(i->first, assign.target))
+ {
i->second->blocked = true;
+ /* Block further inlining of any expressions which used the
+ previous value of this variable. */
+ for(const ExpressionUse &u: i->second->uses)
+ if(u.containing_expr)
+ u.containing_expr->blocked = true;
+ }
+
info->trivial = r_trivial;
assignments[assign.target] = info;
}
bool apply(Stage &);
private:
+ void visit(Block &) override;
void visit(NodePtr<Expression> &) override;
void visit(VariableReference &) override;
void visit(MemberAccess &) override;
--- /dev/null
+#pragma MSP stage(vertex)
+layout(location=0) in vec4 vertex;
+void main()
+{
+ float x = vertex.x;
+ float y = vertex.y;
+ float z = vertex.z;
+ if(x>y)
+ {
+ float temp = x;
+ x = y;
+ y = temp;
+ }
+ if(y>z)
+ {
+ float temp = y;
+ y = z;
+ z = temp;
+ }
+ if(x>y)
+ {
+ float temp = x;
+ x = y;
+ y = temp;
+ }
+ gl_Position = vec4(x, y, z, 1.0);
+}
+
+/* Expected output: vertex
+layout(location=0) in vec4 vertex;
+void main()
+{
+ float x = vertex.x;
+ float y = vertex.y;
+ float z = vertex.z;
+ if(x>y)
+ {
+ float temp = x;
+ x = y;
+ y = temp;
+ }
+ if(y>z)
+ {
+ float temp = y;
+ y = z;
+ z = temp;
+ }
+ if(x>y)
+ {
+ float temp = x;
+ x = y;
+ y = temp;
+ }
+ gl_Position = vec4(x, y, z, 1.0);
+ gl_Position.z = gl_Position.z*2.0-gl_Position.w;
+}
+*/