mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Rename expression inliner.
This commit is contained in:
parent
a7ae7c6d04
commit
3960f4184d
@ -15,12 +15,12 @@
|
|||||||
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
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/Substitution.h>
|
||||||
#include <libjulia/optimiser/Semantics.h>
|
#include <libjulia/optimiser/Semantics.h>
|
||||||
|
|
||||||
@ -33,17 +33,22 @@ using namespace dev;
|
|||||||
using namespace dev::julia;
|
using namespace dev::julia;
|
||||||
using namespace dev::solidity;
|
using namespace dev::solidity;
|
||||||
|
|
||||||
void FunctionalInliner::run()
|
void ExpressionInliner::run()
|
||||||
{
|
{
|
||||||
InlinableFunctionFilter filter;
|
InlinableExpressionFunctionFinder funFinder;
|
||||||
filter(m_block);
|
funFinder(m_block);
|
||||||
m_inlinableFunctions = filter.inlinableFunctions();
|
m_inlinableFunctions = funFinder.inlinableFunctions();
|
||||||
|
|
||||||
(*this)(m_block);
|
(*this)(m_block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FunctionalInliner::visit(Expression& _expression)
|
void ExpressionInliner::operator()(FunctionDefinition& _fun)
|
||||||
|
{
|
||||||
|
ASTModifier::operator()(_fun);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExpressionInliner::visit(Expression& _expression)
|
||||||
{
|
{
|
||||||
ASTModifier::visit(_expression);
|
ASTModifier::visit(_expression);
|
||||||
if (_expression.type() == typeid(FunctionCall))
|
if (_expression.type() == typeid(FunctionCall))
|
||||||
@ -62,10 +67,8 @@ void FunctionalInliner::visit(Expression& _expression)
|
|||||||
substitutions[fun.parameters[i].name] = &funCall.arguments[i];
|
substitutions[fun.parameters[i].name] = &funCall.arguments[i];
|
||||||
_expression = Substitution(substitutions).translate(*boost::get<Assignment>(fun.body.statements.front()).value);
|
_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
|
// TODO Add metric! This metric should perform well on a pair of functions who
|
||||||
// because it could now call itself
|
// call each other recursively.
|
||||||
|
|
||||||
// If two functions call each other, we have to exit after some iterations.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -46,20 +46,25 @@ namespace julia
|
|||||||
*
|
*
|
||||||
* This component can only be used on sources with unique names.
|
* This component can only be used on sources with unique names.
|
||||||
*/
|
*/
|
||||||
class FunctionalInliner: public ASTModifier
|
class ExpressionInliner: public ASTModifier
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FunctionalInliner(Block& _block):
|
ExpressionInliner(Block& _block):
|
||||||
m_block(_block)
|
m_block(_block)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
private:
|
using ASTModifier::operator();
|
||||||
|
virtual void operator()(FunctionDefinition& _fun) override;
|
||||||
|
|
||||||
virtual void visit(Expression& _expression) override;
|
virtual void visit(Expression& _expression) override;
|
||||||
|
|
||||||
|
private:
|
||||||
std::map<std::string, FunctionDefinition const*> m_inlinableFunctions;
|
std::map<std::string, FunctionDefinition const*> m_inlinableFunctions;
|
||||||
std::map<std::string, std::string> m_varReplacements;
|
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;
|
Block& m_block;
|
||||||
};
|
};
|
@ -18,7 +18,7 @@
|
|||||||
* Optimiser component that identifies functions to be inlined.
|
* Optimiser component that identifies functions to be inlined.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <libjulia/optimiser/InlinableFunctionFilter.h>
|
#include <libjulia/optimiser/InlinableExpressionFunctionFinder.h>
|
||||||
|
|
||||||
#include <libsolidity/inlineasm/AsmData.h>
|
#include <libsolidity/inlineasm/AsmData.h>
|
||||||
|
|
||||||
@ -28,19 +28,19 @@ using namespace std;
|
|||||||
using namespace dev;
|
using namespace dev;
|
||||||
using namespace dev::julia;
|
using namespace dev::julia;
|
||||||
|
|
||||||
void InlinableFunctionFilter::operator()(Identifier const& _identifier)
|
void InlinableExpressionFunctionFinder::operator()(Identifier const& _identifier)
|
||||||
{
|
{
|
||||||
checkAllowed(_identifier.name);
|
checkAllowed(_identifier.name);
|
||||||
ASTWalker::operator()(_identifier);
|
ASTWalker::operator()(_identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InlinableFunctionFilter::operator()(FunctionCall const& _funCall)
|
void InlinableExpressionFunctionFinder::operator()(FunctionCall const& _funCall)
|
||||||
{
|
{
|
||||||
checkAllowed(_funCall.functionName.name);
|
checkAllowed(_funCall.functionName.name);
|
||||||
ASTWalker::operator()(_funCall);
|
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)
|
if (_function.returnVariables.size() == 1 && _function.body.statements.size() == 1)
|
||||||
{
|
{
|
@ -41,7 +41,7 @@ namespace julia
|
|||||||
*
|
*
|
||||||
* This component can only be used on sources with unique names.
|
* This component can only be used on sources with unique names.
|
||||||
*/
|
*/
|
||||||
class InlinableFunctionFilter: public ASTWalker
|
class InlinableExpressionFunctionFinder: public ASTWalker
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user