diff options
author | John Hodge <tpg@ucc.asn.au> | 2017-06-22 12:05:13 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2017-06-22 12:05:13 +0800 |
commit | 239b7826470dab3effc703b33d4d7a2a761c461e (patch) | |
tree | 7654b12ec446685d9696dad6916c8f4197331139 | |
parent | c7f4248191dce493cd43fecd808cf15015271408 (diff) | |
download | mrust-239b7826470dab3effc703b33d4d7a2a761c461e.tar.gz |
MIR Gen - Remove arguments that are just assigned from arguments
-rw-r--r-- | src/mir/from_hir.hpp | 5 | ||||
-rw-r--r-- | src/mir/mir_builder.cpp | 10 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/mir/from_hir.hpp b/src/mir/from_hir.hpp index 2730631f..ce310945 100644 --- a/src/mir/from_hir.hpp +++ b/src/mir/from_hir.hpp @@ -135,6 +135,8 @@ class MirBuilder ::std::vector<VarState> m_slot_states; size_t m_first_temp_idx; + ::std::map<unsigned,unsigned> m_var_arg_mappings; + struct ScopeDef { const Span& span; @@ -173,6 +175,9 @@ public: // - Values ::MIR::LValue get_variable(const Span& sp, unsigned idx) const { + auto it = m_var_arg_mappings.find(idx); + if(it != m_var_arg_mappings.end()) + return ::MIR::LValue::make_Argument({ it->second }); return ::MIR::LValue::make_Local( idx ); } ::MIR::LValue new_temporary(const ::HIR::TypeRef& ty); diff --git a/src/mir/mir_builder.cpp b/src/mir/mir_builder.cpp index 7dee2003..1549d39a 100644 --- a/src/mir/mir_builder.cpp +++ b/src/mir/mir_builder.cpp @@ -40,6 +40,16 @@ MirBuilder::MirBuilder(const Span& sp, const StaticTraitResolve& resolve, const DEBUG("First temporary will be " << m_first_temp_idx); m_if_cond_lval = this->new_temporary(::HIR::CoreType::Bool); + + // Determine which variables can be replaced by arguents + for(size_t i = 0; i < args.size(); i ++) + { + const auto& pat = args[i].first; + if( pat.m_binding.is_valid() && pat.m_binding.m_type == ::HIR::PatternBinding::Type::Move ) + { + m_var_arg_mappings[pat.m_binding.m_slot] = i; + } + } } MirBuilder::~MirBuilder() { |