diff options
-rw-r--r-- | libjulia/optimiser/ExpressionInliner.cpp (renamed from libjulia/optimiser/FunctionalInliner.cpp) | 27 | ||||
-rw-r--r-- | libjulia/optimiser/ExpressionInliner.h (renamed from libjulia/optimiser/FunctionalInliner.h) | 11 | ||||
-rw-r--r-- | libjulia/optimiser/InlinableExpressionFunctionFinder.cpp (renamed from libjulia/optimiser/InlinableFunctionFilter.cpp) | 8 | ||||
-rw-r--r-- | libjulia/optimiser/InlinableExpressionFunctionFinder.h (renamed from libjulia/optimiser/InlinableFunctionFilter.h) | 2 |
4 files changed, 28 insertions, 20 deletions
diff --git a/libjulia/optimiser/FunctionalInliner.cpp b/libjulia/optimiser/ExpressionInliner.cpp index 0544ee5d..450769fd 100644 --- a/libjulia/optimiser/FunctionalInliner.cpp +++ b/libjulia/optimiser/ExpressionInliner.cpp @@ -15,12 +15,12 @@ along with solidity. If not, see <http://www.gnu.org/licenses/>. */ /** - * Optimiser component that performs function inlining. + * Optimiser component that performs function inlining inside expressions. */ -#include <libjulia/optimiser/FunctionalInliner.h> +#include <libjulia/optimiser/ExpressionInliner.h> -#include <libjulia/optimiser/InlinableFunctionFilter.h> +#include <libjulia/optimiser/InlinableExpressionFunctionFinder.h> #include <libjulia/optimiser/Substitution.h> #include <libjulia/optimiser/Semantics.h> @@ -33,17 +33,22 @@ using namespace dev; using namespace dev::julia; using namespace dev::solidity; -void FunctionalInliner::run() +void ExpressionInliner::run() { - InlinableFunctionFilter filter; - filter(m_block); - m_inlinableFunctions = filter.inlinableFunctions(); + InlinableExpressionFunctionFinder funFinder; + funFinder(m_block); + m_inlinableFunctions = funFinder.inlinableFunctions(); (*this)(m_block); } -void FunctionalInliner::visit(Expression& _expression) +void ExpressionInliner::operator()(FunctionDefinition& _fun) +{ + ASTModifier::operator()(_fun); +} + +void ExpressionInliner::visit(Expression& _expression) { ASTModifier::visit(_expression); if (_expression.type() == typeid(FunctionCall)) @@ -62,10 +67,8 @@ void FunctionalInliner::visit(Expression& _expression) substitutions[fun.parameters[i].name] = &funCall.arguments[i]; _expression = Substitution(substitutions).translate(*boost::get<Assignment>(fun.body.statements.front()).value); - // TODO actually in the process of inlining, we could also make a function non-inlinable - // because it could now call itself - - // If two functions call each other, we have to exit after some iterations. + // TODO Add metric! This metric should perform well on a pair of functions who + // call each other recursively. } } } diff --git a/libjulia/optimiser/FunctionalInliner.h b/libjulia/optimiser/ExpressionInliner.h index 30c972ff..10d7659c 100644 --- a/libjulia/optimiser/FunctionalInliner.h +++ b/libjulia/optimiser/ExpressionInliner.h @@ -46,20 +46,25 @@ namespace julia * * This component can only be used on sources with unique names. */ -class FunctionalInliner: public ASTModifier +class ExpressionInliner: public ASTModifier { public: - FunctionalInliner(Block& _block): + ExpressionInliner(Block& _block): m_block(_block) {} void run(); -private: + using ASTModifier::operator(); + virtual void operator()(FunctionDefinition& _fun) override; + virtual void visit(Expression& _expression) override; +private: std::map<std::string, FunctionDefinition const*> m_inlinableFunctions; std::map<std::string, std::string> m_varReplacements; + /// Set of functions we are currently visiting inside. + std::set<std::string> m_currentFunctions; Block& m_block; }; diff --git a/libjulia/optimiser/InlinableFunctionFilter.cpp b/libjulia/optimiser/InlinableExpressionFunctionFinder.cpp index 37e21f0d..2097e091 100644 --- a/libjulia/optimiser/InlinableFunctionFilter.cpp +++ b/libjulia/optimiser/InlinableExpressionFunctionFinder.cpp @@ -18,7 +18,7 @@ * Optimiser component that identifies functions to be inlined. */ -#include <libjulia/optimiser/InlinableFunctionFilter.h> +#include <libjulia/optimiser/InlinableExpressionFunctionFinder.h> #include <libsolidity/inlineasm/AsmData.h> @@ -28,19 +28,19 @@ using namespace std; using namespace dev; using namespace dev::julia; -void InlinableFunctionFilter::operator()(Identifier const& _identifier) +void InlinableExpressionFunctionFinder::operator()(Identifier const& _identifier) { checkAllowed(_identifier.name); ASTWalker::operator()(_identifier); } -void InlinableFunctionFilter::operator()(FunctionCall const& _funCall) +void InlinableExpressionFunctionFinder::operator()(FunctionCall const& _funCall) { checkAllowed(_funCall.functionName.name); ASTWalker::operator()(_funCall); } -void InlinableFunctionFilter::operator()(FunctionDefinition const& _function) +void InlinableExpressionFunctionFinder::operator()(FunctionDefinition const& _function) { if (_function.returnVariables.size() == 1 && _function.body.statements.size() == 1) { diff --git a/libjulia/optimiser/InlinableFunctionFilter.h b/libjulia/optimiser/InlinableExpressionFunctionFinder.h index e0265059..36cb557a 100644 --- a/libjulia/optimiser/InlinableFunctionFilter.h +++ b/libjulia/optimiser/InlinableExpressionFunctionFinder.h @@ -41,7 +41,7 @@ namespace julia * * This component can only be used on sources with unique names. */ -class InlinableFunctionFilter: public ASTWalker +class InlinableExpressionFunctionFinder: public ASTWalker { public: |