diff options
author | John Hodge <tpg@mutabah.net> | 2017-01-30 23:13:23 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2017-01-30 23:13:23 +0800 |
commit | 85473b0da8f5e13c9601c9661ade61892d34ccd7 (patch) | |
tree | fd72be09fade475dc6108ac0454f07682260f420 /src/mir/optimise.cpp | |
parent | ccf8f384c9489a83121971d453f00c5f68cb7784 (diff) | |
download | mrust-85473b0da8f5e13c9601c9661ade61892d34ccd7.tar.gz |
MIR Optimise - Eliminate variable assignments too
Diffstat (limited to 'src/mir/optimise.cpp')
-rw-r--r-- | src/mir/optimise.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/mir/optimise.cpp b/src/mir/optimise.cpp index 323bd253..b8fbe20e 100644 --- a/src/mir/optimise.cpp +++ b/src/mir/optimise.cpp @@ -1559,14 +1559,22 @@ bool MIR_Optimise_PropagateSingleAssignments(::MIR::TypeResolve& state, ::MIR::F continue ; const auto& e = stmt.as_Assign(); // > Of a temporary from with a RValue::Use - // TODO: Variables too (can eliminate arguments) - if( e.dst.is_Temporary() ) + if( const auto* de = e.dst.opt_Temporary() ) { - const auto& vu = val_uses.tmp_uses[e.dst.as_Temporary().idx]; - DEBUG("VU " << e.dst << " R:" << vu.read << " W:" << vu.write); + const auto& vu = val_uses.tmp_uses[de->idx]; + DEBUG(e.dst << " - VU " << e.dst << " R:" << vu.read << " W:" << vu.write); // TODO: Allow write many? // > Where the temporary is written once and read once - if( !( vu.read == 1 && vu.write == 1 ) ) + if( !( vu.read == 1 && vu.write == 1 && vu.borrow == 0 ) ) + continue ; + } + else if( const auto* de = e.dst.opt_Variable() ) + { + const auto& vu = val_uses.var_uses[*de]; + DEBUG(e.dst << " - VU " << e.dst << " R:" << vu.read << " W:" << vu.write); + // TODO: Allow write many? + // > Where the variable is written once and read once + if( !( vu.read == 1 && vu.write == 1 && vu.borrow == 0 ) ) continue ; } else |