]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/optimize.h
Add generator ID for the SPIR-V compiler
[libs/gl.git] / source / glsl / optimize.h
index 249a859a03763c6e198b9c0f04020dc0589ea360..ea61b671d2e1ea2a68b10c4b4682e8cb6a560260 100644 (file)
@@ -27,7 +27,7 @@ private:
 
 /** Finds functions which are candidates for inlining.  Currently this means
 functions which have no flow control statements, no more than one return
-statement, and are only called once. */
+statement, and are either builtins or only called once. */
 class InlineableFunctionLocator: private TraversingVisitor
 {
 private:
@@ -227,6 +227,26 @@ private:
        virtual void visit(Iteration &);
 };
 
+class UnreachableCodeRemover: private TraversingVisitor
+{
+private:
+       bool reachable;
+       std::set<Node *> unreachable_nodes;
+
+public:
+       UnreachableCodeRemover();
+
+       virtual bool apply(Stage &);
+
+private:
+       virtual void visit(Block &);
+       virtual void visit(FunctionDeclaration &);
+       virtual void visit(Conditional &);
+       virtual void visit(Iteration &);
+       virtual void visit(Return &) { reachable = false; }
+       virtual void visit(Jump &) { reachable = false; }
+};
+
 /** Removes types which are not used anywhere. */
 class UnusedTypeRemover: private TraversingVisitor
 {
@@ -280,6 +300,7 @@ private:
        Assignment *r_assignment;
        bool assignment_target;
        bool r_side_effects;
+       bool in_struct;
        bool composite_reference;
        Assignment::Target r_reference;
        std::set<Node *> unused_nodes;
@@ -303,8 +324,7 @@ private:
        virtual void visit(FunctionCall &);
        void record_assignment(const Assignment::Target &, Node &);
        virtual void visit(ExpressionStatement &);
-       // Ignore structs because their members can't be accessed directly.
-       virtual void visit(StructDeclaration &) { }
+       virtual void visit(StructDeclaration &);
        virtual void visit(VariableDeclaration &);
        virtual void visit(InterfaceBlock &);
        void merge_variables(const BlockVariableMap &);