mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
WasmCodeTransform: Convert Yul 'if's with i32 argument directly to wasm 'if' without an extra comparison with zero
This commit is contained in:
parent
50b426e37b
commit
06e1b38d1d
@ -178,18 +178,23 @@ wasm::Expression WasmCodeTransform::operator()(Literal const& _literal)
|
|||||||
wasm::Expression WasmCodeTransform::operator()(If const& _if)
|
wasm::Expression WasmCodeTransform::operator()(If const& _if)
|
||||||
{
|
{
|
||||||
yul::Type conditionType = m_typeInfo.typeOf(*_if.condition);
|
yul::Type conditionType = m_typeInfo.typeOf(*_if.condition);
|
||||||
YulString ne_instruction = YulString(conditionType.str() + ".ne");
|
|
||||||
yulAssert(WasmDialect::instance().builtin(ne_instruction), "");
|
|
||||||
|
|
||||||
// TODO converting i64 to i32 might not always be needed.
|
wasm::Expression condition;
|
||||||
vector<wasm::Expression> args;
|
if (conditionType == "i32"_yulstring)
|
||||||
args.emplace_back(visitReturnByValue(*_if.condition));
|
condition = visitReturnByValue(*_if.condition);
|
||||||
args.emplace_back(makeLiteral(translatedType(conditionType), 0));
|
else if (conditionType == "i64"_yulstring)
|
||||||
return wasm::If{
|
{
|
||||||
make_unique<wasm::Expression>(wasm::BuiltinCall{ne_instruction.str(), std::move(args)}),
|
vector<wasm::Expression> args;
|
||||||
visit(_if.body.statements),
|
args.emplace_back(visitReturnByValue(*_if.condition));
|
||||||
{}
|
args.emplace_back(makeLiteral(translatedType("i64"_yulstring), 0));
|
||||||
};
|
|
||||||
|
// NOTE: `if` in wasm requires an i32 argument
|
||||||
|
condition = wasm::BuiltinCall{"i64.ne", std::move(args)};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
yulAssert(false, "Invalid condition type");
|
||||||
|
|
||||||
|
return wasm::If{make_unique<wasm::Expression>(move(condition)), visit(_if.body.statements), {}};
|
||||||
}
|
}
|
||||||
|
|
||||||
wasm::Expression WasmCodeTransform::operator()(Switch const& _switch)
|
wasm::Expression WasmCodeTransform::operator()(Switch const& _switch)
|
||||||
|
Loading…
Reference in New Issue
Block a user