namespace GL {
namespace SL {
+/** Assigns values to specialization constants, turning them into normal
+constants. */
+class ConstantSpecializer: private TraversingVisitor
+{
+private:
+ const std::map<std::string, int> *values;
+
+public:
+ ConstantSpecializer();
+
+ void apply(Stage &, const std::map<std::string, int> &);
+
+private:
+ virtual void visit(VariableDeclaration &);
+};
+
/** Finds functions which are candidates for inlining. Currently this means
-functions which have no parameters, contain no more than one return statement,
-and are only called once. */
+functions which have no flow control statements, no more than one return
+statement, and are only called once. */
class InlineableFunctionLocator: private TraversingVisitor
{
private:
class InlineContentInjector: private TraversingVisitor
{
private:
+ enum Pass
+ {
+ DEPENDS,
+ REFERENCED,
+ INLINE,
+ RENAME
+ };
+
FunctionDeclaration *source_func;
- Block *target_block;
- std::map<std::string, VariableDeclaration *> variable_map;
- std::string remap_prefix;
- unsigned remap_names;
- bool deps_only;
+ Block staging_block;
+ Pass pass;
RefPtr<Statement> r_inlined_statement;
std::set<Node *> dependencies;
std::set<std::string> referenced_names;
public:
InlineContentInjector();
- const std::string &apply(Stage &, FunctionDeclaration &, Block &, const NodeList<Statement>::iterator &, FunctionDeclaration &);
+ const std::string &apply(Stage &, FunctionDeclaration &, Block &, const NodeList<Statement>::iterator &, FunctionCall &);
private:
virtual void visit(VariableReference &);
NodeList<Statement>::iterator insert_point;
RefPtr<Expression> r_inline_result;
bool r_any_inlined;
+ bool r_inlined_here;
public:
FunctionInliner();