diff options
-rw-r--r-- | src/mir/helpers.cpp | 21 | ||||
-rw-r--r-- | src/mir/helpers.hpp | 2 | ||||
-rw-r--r-- | src/mir/optimise.cpp | 18 |
3 files changed, 28 insertions, 13 deletions
diff --git a/src/mir/helpers.cpp b/src/mir/helpers.cpp index 1e43e361..2cb55e4a 100644 --- a/src/mir/helpers.cpp +++ b/src/mir/helpers.cpp @@ -557,7 +557,7 @@ namespace #if 1 void MIR_Helper_GetLifetimes_DetermineValueLifetime(::MIR::TypeResolve& state, const ::MIR::Function& fcn, size_t bb_idx, size_t stmt_idx, const ::MIR::LValue& lv, const ::std::vector<size_t>& block_offsets, ValueLifetime& vl); -::MIR::ValueLifetimes MIR_Helper_GetLifetimes(::MIR::TypeResolve& state, const ::MIR::Function& fcn, bool dump_debug) +::MIR::ValueLifetimes MIR_Helper_GetLifetimes(::MIR::TypeResolve& state, const ::MIR::Function& fcn, bool dump_debug, const ::std::vector<bool>* mask/*=nullptr*/) { TRACE_FUNCTION_F(state); @@ -580,8 +580,11 @@ void MIR_Helper_GetLifetimes_DetermineValueLifetime(::MIR::TypeResolve& state, c // NOTE: Fills the first statement after running, just to ensure that any assigned value has _a_ lifetime if( const auto* de = lv.opt_Local() ) { - MIR_Helper_GetLifetimes_DetermineValueLifetime(state, fcn, bb_idx, stmt_idx, lv, block_offsets, slot_lifetimes[*de]); - slot_lifetimes[*de].fill(block_offsets, bb_idx, stmt_idx, stmt_idx); + if( !mask || mask->at(*de) ) + { + MIR_Helper_GetLifetimes_DetermineValueLifetime(state, fcn, bb_idx, stmt_idx, lv, block_offsets, slot_lifetimes[*de]); + slot_lifetimes[*de].fill(block_offsets, bb_idx, stmt_idx, stmt_idx); + } } else { @@ -591,8 +594,11 @@ void MIR_Helper_GetLifetimes_DetermineValueLifetime(::MIR::TypeResolve& state, c { if( vu == ValUsage::Write ) { - MIR_Helper_GetLifetimes_DetermineValueLifetime(state, fcn, bb_idx, stmt_idx, lv, block_offsets, slot_lifetimes[*de]); - slot_lifetimes[*de].fill(block_offsets, bb_idx, stmt_idx, stmt_idx); + if( !mask || mask->at(*de) ) + { + MIR_Helper_GetLifetimes_DetermineValueLifetime(state, fcn, bb_idx, stmt_idx, lv, block_offsets, slot_lifetimes[*de]); + slot_lifetimes[*de].fill(block_offsets, bb_idx, stmt_idx, stmt_idx); + } } } return false; @@ -622,7 +628,10 @@ void MIR_Helper_GetLifetimes_DetermineValueLifetime(::MIR::TypeResolve& state, c // HACK: Mark values as valid wherever there's a drop (prevents confusion by simple validator) if( const auto* de = se->slot.opt_Local() ) { - slot_lifetimes[*de].fill(block_offsets, bb_idx, stmt_idx,stmt_idx); + if( !mask || mask->at(*de) ) + { + slot_lifetimes[*de].fill(block_offsets, bb_idx, stmt_idx,stmt_idx); + } } } } diff --git a/src/mir/helpers.hpp b/src/mir/helpers.hpp index 12fd4ddf..f845e790 100644 --- a/src/mir/helpers.hpp +++ b/src/mir/helpers.hpp @@ -184,4 +184,4 @@ namespace visit { } // namespace MIR -extern ::MIR::ValueLifetimes MIR_Helper_GetLifetimes(::MIR::TypeResolve& state, const ::MIR::Function& fcn, bool dump_debug); +extern ::MIR::ValueLifetimes MIR_Helper_GetLifetimes(::MIR::TypeResolve& state, const ::MIR::Function& fcn, bool dump_debug, const ::std::vector<bool>* mask=nullptr); diff --git a/src/mir/optimise.cpp b/src/mir/optimise.cpp index dc3967b4..6601c03b 100644 --- a/src/mir/optimise.cpp +++ b/src/mir/optimise.cpp @@ -574,11 +574,16 @@ void MIR_Optimise(const StaticTraitResolve& resolve, const ::HIR::ItemPath& path // >> Unify duplicate temporaries // If two temporaries don't overlap in lifetime (blocks in which they're valid), unify the two - // TODO: Only run this when nothing else happened. (It's VERY expensive) - change_happened |= MIR_Optimise_UnifyTemporaries(state, fcn); - #if CHECK_AFTER_ALL - MIR_Validate(resolve, path, fcn, args, ret_type); - #endif + // Only run this when nothing else happened. (It's VERY expensive) +#if 1 + if( !change_happened ) + { + change_happened |= MIR_Optimise_UnifyTemporaries(state, fcn); +# if CHECK_AFTER_ALL + MIR_Validate(resolve, path, fcn, args, ret_type); +# endif + } +#endif // >> Combine Duplicate Blocks change_happened |= MIR_Optimise_UnifyBlocks(state, fcn); @@ -1254,7 +1259,8 @@ bool MIR_Optimise_UnifyTemporaries(::MIR::TypeResolve& state, ::MIR::Function& f return false; } - auto lifetimes = MIR_Helper_GetLifetimes(state, fcn, /*dump_debug=*/true); + // TODO: Only calculate lifetimes for replacable locals + auto lifetimes = MIR_Helper_GetLifetimes(state, fcn, /*dump_debug=*/true, /*mask=*/&replacable); ::std::vector<::MIR::ValueLifetime> slot_lifetimes = mv$(lifetimes.m_slots); // 2. Unify variables of the same type with distinct non-overlapping lifetimes |