diff options
author | chriseth <chris@ethereum.org> | 2018-10-19 01:02:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-19 01:02:04 +0800 |
commit | 7dffb0f3eecdd1dac75482db2c59207ded7a2dfa (patch) | |
tree | 5604ecec4aeb4f2000abc51d7752c3a865e5dab2 /libyul | |
parent | 52ffe5262edb3bd1fcb2477d8f3339f135f85563 (diff) | |
parent | b2725aa913564d48a31718e14e94f00c137eb8de (diff) | |
download | dexon-solidity-7dffb0f3eecdd1dac75482db2c59207ded7a2dfa.tar.gz dexon-solidity-7dffb0f3eecdd1dac75482db2c59207ded7a2dfa.tar.zst dexon-solidity-7dffb0f3eecdd1dac75482db2c59207ded7a2dfa.zip |
Merge pull request #5270 from ethereum/inlineFlexible
Make full inliner more flexible.
Diffstat (limited to 'libyul')
-rw-r--r-- | libyul/optimiser/FullInliner.cpp | 19 | ||||
-rw-r--r-- | libyul/optimiser/FullInliner.h | 4 |
2 files changed, 11 insertions, 12 deletions
diff --git a/libyul/optimiser/FullInliner.cpp b/libyul/optimiser/FullInliner.cpp index ce71eda5..280d625a 100644 --- a/libyul/optimiser/FullInliner.cpp +++ b/libyul/optimiser/FullInliner.cpp @@ -40,12 +40,9 @@ using namespace dev; using namespace dev::yul; using namespace dev::solidity; -FullInliner::FullInliner(Block& _ast): - m_ast(_ast), m_nameDispenser(_ast) +FullInliner::FullInliner(Block& _ast, NameDispenser& _dispenser): + m_ast(_ast), m_nameDispenser(_dispenser) { - assertThrow(m_ast.statements.size() >= 1, OptimizerException, ""); - assertThrow(m_ast.statements.front().type() == typeid(Block), OptimizerException, ""); - // Determine constants SSAValueTracker tracker; tracker(m_ast); @@ -54,10 +51,11 @@ FullInliner::FullInliner(Block& _ast): m_constants.insert(ssaValue.first); map<string, size_t> references = ReferencesCounter::countReferences(m_ast); - for (size_t i = 1; i < m_ast.statements.size(); ++i) + for (auto& statement: m_ast.statements) { - assertThrow(m_ast.statements.at(i).type() == typeid(FunctionDefinition), OptimizerException, ""); - FunctionDefinition& fun = boost::get<FunctionDefinition>(m_ast.statements.at(i)); + if (statement.type() != typeid(FunctionDefinition)) + continue; + FunctionDefinition& fun = boost::get<FunctionDefinition>(statement); m_functions[fun.name] = &fun; // Always inline functions that are only called once. if (references[fun.name] == 1) @@ -68,9 +66,10 @@ FullInliner::FullInliner(Block& _ast): void FullInliner::run() { - assertThrow(m_ast.statements[0].type() == typeid(Block), OptimizerException, ""); + for (auto& statement: m_ast.statements) + if (statement.type() == typeid(Block)) + handleBlock("", boost::get<Block>(statement)); - handleBlock("", boost::get<Block>(m_ast.statements[0])); // TODO it might be good to determine a visiting order: // first handle functions that are called from many places. for (auto const& fun: m_functions) diff --git a/libyul/optimiser/FullInliner.h b/libyul/optimiser/FullInliner.h index cd59ab46..5ecfb57a 100644 --- a/libyul/optimiser/FullInliner.h +++ b/libyul/optimiser/FullInliner.h @@ -71,7 +71,7 @@ class NameCollector; class FullInliner: public ASTModifier { public: - explicit FullInliner(Block& _ast); + explicit FullInliner(Block& _ast, NameDispenser& _dispenser); void run(); @@ -94,7 +94,7 @@ private: /// Variables that are constants (used for inlining heuristic) std::set<std::string> m_constants; std::map<std::string, size_t> m_functionSizes; - NameDispenser m_nameDispenser; + NameDispenser& m_nameDispenser; }; /** |