diff options
author | John Hodge <tpg@mutabah.net> | 2018-03-05 09:54:04 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2018-05-05 17:16:33 +0800 |
commit | 104c46f56e1d691e76f27fc3a0f8ca088da9130b (patch) | |
tree | a3b970586a7972aec78ea2ec7519994ba0dcd70a /src/mir/optimise.cpp | |
parent | 173dfa9fea9e65ec49fa4def9117b01c0a485ab5 (diff) | |
download | mrust-104c46f56e1d691e76f27fc3a0f8ca088da9130b.tar.gz |
MIR Optimise - Short-circuit fail CommonStatements to hopefully avoid excessive runtime
Diffstat (limited to 'src/mir/optimise.cpp')
-rw-r--r-- | src/mir/optimise.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/mir/optimise.cpp b/src/mir/optimise.cpp index 2cc81258..a3368cd9 100644 --- a/src/mir/optimise.cpp +++ b/src/mir/optimise.cpp @@ -1540,7 +1540,7 @@ bool MIR_Optimise_CommonStatements(::MIR::TypeResolve& state, ::MIR::Function& f bool skip = false; ::std::vector<size_t> sources; // Find source blocks - for(size_t bb2_idx = 0; bb2_idx < fcn.blocks.size(); bb2_idx ++) + for(size_t bb2_idx = 0; bb2_idx < fcn.blocks.size() && !skip; bb2_idx ++) { const auto& blk = fcn.blocks[bb2_idx]; // TODO: Handle non-Goto branches? (e.g. calls) @@ -1566,6 +1566,7 @@ bool MIR_Optimise_CommonStatements(::MIR::TypeResolve& state, ::MIR::Function& f else { visit_terminator_target(blk.terminator, [&](const auto& dst_idx) { + // If this terminator points to the current BB, don't attempt to merge if( dst_idx == bb_idx ) { DEBUG(state << " BB" << bb2_idx << " doesn't end Goto - instead " << blk.terminator); skip = true; @@ -1576,6 +1577,8 @@ bool MIR_Optimise_CommonStatements(::MIR::TypeResolve& state, ::MIR::Function& f if( !skip && sources.size() > 1 ) { + // TODO: Should this search for any common statements? + // Found a common assignment, add to the start and remove from sources. auto stmt = ::std::move(fcn.blocks[sources.front()].statements.back()); MIR_DEBUG(state, "Move common final statements from " << sources << " to " << bb_idx << " - " << stmt); |