Yul: Remove obsoleted FunctionalInstruction.

This commit is contained in:
Christian Parpart
2019-11-11 16:04:39 +01:00
parent 147120ba47
commit f15d47f165
41 changed files with 35 additions and 304 deletions
-9
View File
@@ -62,15 +62,6 @@ Expression ASTCopier::operator()(FunctionCall const& _call)
};
}
Expression ASTCopier::operator()(FunctionalInstruction const& _instruction)
{
return FunctionalInstruction{
_instruction.location,
_instruction.instruction,
translateVector(_instruction.arguments)
};
}
Expression ASTCopier::operator()(Identifier const& _identifier)
{
return translate(_identifier);
-2
View File
@@ -40,7 +40,6 @@ public:
virtual ~ExpressionCopier() = default;
virtual Expression operator()(Literal const& _literal) = 0;
virtual Expression operator()(Identifier const& _identifier) = 0;
virtual Expression operator()(FunctionalInstruction const& _instr) = 0;
virtual Expression operator()(FunctionCall const&) = 0;
};
@@ -71,7 +70,6 @@ public:
virtual ~ASTCopier() = default;
Expression operator()(Literal const& _literal) override;
Expression operator()(Identifier const& _identifier) override;
Expression operator()(FunctionalInstruction const& _instr) override;
Expression operator()(FunctionCall const&) override;
Statement operator()(ExpressionStatement const& _statement) override;
Statement operator()(Assignment const& _assignment) override;
-10
View File
@@ -28,11 +28,6 @@ using namespace std;
using namespace dev;
using namespace yul;
void ASTWalker::operator()(FunctionalInstruction const& _instr)
{
walkVector(_instr.arguments | boost::adaptors::reversed);
}
void ASTWalker::operator()(FunctionCall const& _funCall)
{
// Does not visit _funCall.functionName on purpose
@@ -102,11 +97,6 @@ void ASTWalker::visit(Expression const& _e)
boost::apply_visitor(*this, _e);
}
void ASTModifier::operator()(FunctionalInstruction& _instr)
{
walkVector(_instr.arguments | boost::adaptors::reversed);
}
void ASTModifier::operator()(FunctionCall& _funCall)
{
// Does not visit _funCall.functionName on purpose
-2
View File
@@ -44,7 +44,6 @@ public:
virtual ~ASTWalker() = default;
virtual void operator()(Literal const&) {}
virtual void operator()(Identifier const&) {}
virtual void operator()(FunctionalInstruction const& _instr);
virtual void operator()(FunctionCall const& _funCall);
virtual void operator()(ExpressionStatement const& _statement);
virtual void operator()(Assignment const& _assignment);
@@ -79,7 +78,6 @@ public:
virtual ~ASTModifier() = default;
virtual void operator()(Literal&) {}
virtual void operator()(Identifier&) {}
virtual void operator()(FunctionalInstruction& _instr);
virtual void operator()(FunctionCall& _funCall);
virtual void operator()(ExpressionStatement& _statement);
virtual void operator()(Assignment& _assignment);
-8
View File
@@ -76,14 +76,6 @@ void BlockHasher::operator()(Identifier const& _identifier)
hash64(it->second.id);
}
void BlockHasher::operator()(FunctionalInstruction const& _instr)
{
hash64(compileTimeLiteralHash("FunctionalInstruction"));
hash8(static_cast<std::underlying_type_t<eth::Instruction>>(_instr.instruction));
hash64(_instr.arguments.size());
ASTWalker::operator()(_instr);
}
void BlockHasher::operator()(FunctionCall const& _funCall)
{
hash64(compileTimeLiteralHash("FunctionCall"));
-1
View File
@@ -49,7 +49,6 @@ public:
void operator()(Literal const&) override;
void operator()(Identifier const&) override;
void operator()(FunctionalInstruction const& _instr) override;
void operator()(FunctionCall const& _funCall) override;
void operator()(ExpressionStatement const& _statement) override;
void operator()(Assignment const& _assignment) override;
-8
View File
@@ -36,14 +36,6 @@ map<YulString, set<YulString>> CallGraphGenerator::callGraph(Block const& _ast)
return std::move(gen.m_callGraph);
}
void CallGraphGenerator::operator()(FunctionalInstruction const& _functionalInstruction)
{
string name = dev::eth::instructionInfo(_functionalInstruction.instruction).name;
std::transform(name.begin(), name.end(), name.begin(), [](unsigned char _c) { return tolower(_c); });
m_callGraph[m_currentFunction].insert(YulString{name});
ASTWalker::operator()(_functionalInstruction);
}
void CallGraphGenerator::operator()(FunctionCall const& _functionCall)
{
m_callGraph[m_currentFunction].insert(_functionCall.functionName.name);
-1
View File
@@ -42,7 +42,6 @@ public:
static std::map<YulString, std::set<YulString>> callGraph(Block const& _ast);
using ASTWalker::operator();
void operator()(FunctionalInstruction const& _functionalInstruction) override;
void operator()(FunctionCall const& _functionCall) override;
void operator()(FunctionDefinition const& _functionDefinition) override;
-5
View File
@@ -40,11 +40,6 @@ void ExpressionJoiner::run(OptimiserStepContext&, Block& _ast)
}
void ExpressionJoiner::operator()(FunctionalInstruction& _instruction)
{
handleArguments(_instruction.arguments);
}
void ExpressionJoiner::operator()(FunctionCall& _funCall)
{
handleArguments(_funCall.arguments);
-1
View File
@@ -78,7 +78,6 @@ private:
explicit ExpressionJoiner(Block& _ast);
void operator()(Block& _block) override;
void operator()(FunctionalInstruction&) override;
void operator()(FunctionCall&) override;
using ASTModifier::visit;
-6
View File
@@ -41,12 +41,6 @@ void ExpressionSplitter::run(OptimiserStepContext& _context, Block& _ast)
ExpressionSplitter{_context.dialect, _context.dispenser}(_ast);
}
void ExpressionSplitter::operator()(FunctionalInstruction& _instruction)
{
for (auto& arg: _instruction.arguments | boost::adaptors::reversed)
outlineExpression(arg);
}
void ExpressionSplitter::operator()(FunctionCall& _funCall)
{
if (BuiltinFunction const* builtin = m_dialect.builtin(_funCall.functionName.name))
-1
View File
@@ -61,7 +61,6 @@ public:
static constexpr char const* name{"ExpressionSplitter"};
static void run(OptimiserStepContext&, Block& _ast);
void operator()(FunctionalInstruction&) override;
void operator()(FunctionCall&) override;
void operator()(If&) override;
void operator()(Switch&) override;
-3
View File
@@ -77,9 +77,6 @@ Expression KnowledgeBase::simplify(Expression _expression)
if (_expression.type() == typeid(FunctionCall))
for (Expression& arg: boost::get<FunctionCall>(_expression).arguments)
arg = simplify(arg);
else if (_expression.type() == typeid(FunctionalInstruction))
for (Expression& arg: boost::get<FunctionalInstruction>(_expression).arguments)
arg = simplify(arg);
if (auto match = SimplificationRules::findFirstMatch(_expression, m_dialect, m_variableValues))
return simplify(match->action().toExpression(locationOf(_expression)));
-5
View File
@@ -55,11 +55,6 @@ void LoadResolver::visit(Expression& _e)
if (builtin->instruction)
tryResolve(_e, *builtin->instruction, funCall.arguments);
}
else if (_e.type() == typeid(FunctionalInstruction))
{
FunctionalInstruction const& instruction = boost::get<FunctionalInstruction>(_e);
tryResolve(_e, instruction.instruction, instruction.arguments);
}
}
void LoadResolver::tryResolve(
-7
View File
@@ -120,13 +120,6 @@ void CodeCost::operator()(FunctionCall const& _funCall)
m_cost += 49;
}
void CodeCost::operator()(FunctionalInstruction const& _instr)
{
yulAssert(m_cost >= 1, "Should assign cost one in visit(Expression).");
addInstructionCost(_instr.instruction);
ASTWalker::operator()(_instr);
}
void CodeCost::operator()(Literal const& _literal)
{
yulAssert(m_cost >= 1, "Should assign cost one in visit(Expression).");
-1
View File
@@ -81,7 +81,6 @@ private:
CodeCost(Dialect const& _dialect): m_dialect(_dialect) {}
void operator()(FunctionCall const& _funCall) override;
void operator()(FunctionalInstruction const& _instr) override;
void operator()(Literal const& _literal) override;
void visit(Statement const& _statement) override;
void visit(Expression const& _expression) override;
+1 -20
View File
@@ -61,13 +61,6 @@ SideEffectsCollector::SideEffectsCollector(
operator()(_ast);
}
void SideEffectsCollector::operator()(FunctionalInstruction const& _instr)
{
ASTWalker::operator()(_instr);
m_sideEffects += EVMDialect::sideEffectsOfInstruction(_instr.instruction);
}
void SideEffectsCollector::operator()(FunctionCall const& _functionCall)
{
ASTWalker::operator()(_functionCall);
@@ -88,14 +81,6 @@ bool MSizeFinder::containsMSize(Dialect const& _dialect, Block const& _ast)
return finder.m_msizeFound;
}
void MSizeFinder::operator()(FunctionalInstruction const& _instr)
{
ASTWalker::operator()(_instr);
if (_instr.instruction == eth::Instruction::MSIZE)
m_msizeFound = true;
}
void MSizeFinder::operator()(FunctionCall const& _functionCall)
{
ASTWalker::operator()(_functionCall);
@@ -181,11 +166,7 @@ TerminationFinder::ControlFlow TerminationFinder::controlFlowKind(Statement cons
bool TerminationFinder::isTerminatingBuiltin(ExpressionStatement const& _exprStmnt)
{
if (_exprStmnt.expression.type() == typeid(FunctionalInstruction))
return eth::SemanticInformation::terminatesControlFlow(
boost::get<FunctionalInstruction>(_exprStmnt.expression).instruction
);
else if (_exprStmnt.expression.type() == typeid(FunctionCall))
if (_exprStmnt.expression.type() == typeid(FunctionCall))
if (auto const* dialect = dynamic_cast<EVMDialect const*>(&m_dialect))
if (auto const* builtin = dialect->builtin(boost::get<FunctionCall>(_exprStmnt.expression).functionName.name))
if (builtin->instruction)
-2
View File
@@ -54,7 +54,6 @@ public:
);
using ASTWalker::operator();
void operator()(FunctionalInstruction const& _functionalInstruction) override;
void operator()(FunctionCall const& _functionCall) override;
bool movable() const { return m_sideEffects.movable; }
@@ -104,7 +103,6 @@ public:
static bool containsMSize(Dialect const& _dialect, Block const& _ast);
using ASTWalker::operator();
void operator()(FunctionalInstruction const& _instr);
void operator()(FunctionCall const& _funCall);
private:
+10 -5
View File
@@ -67,9 +67,7 @@ bool SimplificationRules::isInitialized() const
std::optional<std::pair<dev::eth::Instruction, vector<Expression> const*>>
SimplificationRules::instructionAndArguments(Dialect const& _dialect, Expression const& _expr)
{
if (_expr.type() == typeid(FunctionalInstruction))
return make_pair(boost::get<FunctionalInstruction>(_expr).instruction, &boost::get<FunctionalInstruction>(_expr).arguments);
else if (_expr.type() == typeid(FunctionCall))
if (_expr.type() == typeid(FunctionCall))
if (auto const* dialect = dynamic_cast<EVMDialect const*>(&_dialect))
if (auto const* builtin = dialect->builtin(boost::get<FunctionCall>(_expr).functionName.name))
if (builtin->instruction)
@@ -225,8 +223,15 @@ Expression Pattern::toExpression(SourceLocation const& _location) const
vector<Expression> arguments;
for (auto const& arg: m_arguments)
arguments.emplace_back(arg.toExpression(_location));
// TODO convert to FunctionCall
return FunctionalInstruction{_location, m_instruction, std::move(arguments)};
string name = instructionInfo(m_instruction).name;
transform(begin(name), end(name), begin(name), [](auto _c) { return tolower(_c); });
return FunctionCall{
_location,
Identifier{_location, YulString{name}},
std::move(arguments)
};
}
assertThrow(false, OptimizerException, "Pattern of kind 'any', but no match group.");
}
-9
View File
@@ -46,15 +46,6 @@ bool SyntacticallyEqual::operator()(Statement const& _lhs, Statement const& _rhs
}, _lhs, _rhs);
}
bool SyntacticallyEqual::expressionEqual(FunctionalInstruction const& _lhs, FunctionalInstruction const& _rhs)
{
return
_lhs.instruction == _rhs.instruction &&
containerEqual(_lhs.arguments, _rhs.arguments, [this](Expression const& _lhsExpr, Expression const& _rhsExpr) -> bool {
return (*this)(_lhsExpr, _rhsExpr);
});
}
bool SyntacticallyEqual::expressionEqual(FunctionCall const& _lhs, FunctionCall const& _rhs)
{
return
-1
View File
@@ -42,7 +42,6 @@ public:
bool operator()(Expression const& _lhs, Expression const& _rhs);
bool operator()(Statement const& _lhs, Statement const& _rhs);
bool expressionEqual(FunctionalInstruction const& _lhs, FunctionalInstruction const& _rhs);
bool expressionEqual(FunctionCall const& _lhs, FunctionCall const& _rhs);
bool expressionEqual(Identifier const& _lhs, Identifier const& _rhs);
bool expressionEqual(Literal const& _lhs, Literal const& _rhs);