diff options
author | John Hodge <tpg@ucc.asn.au> | 2019-08-03 23:26:11 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2019-08-03 23:26:11 +0800 |
commit | 126900aa8e24523a23fcef11bcfca976e8afc120 (patch) | |
tree | c2d5c8f77e4d955fda39e70f342d7934aa3067cf /src | |
parent | 2612c15cc92a7b9331a2bf6970df506d92b9c48f (diff) | |
download | mrust-126900aa8e24523a23fcef11bcfca976e8afc120.tar.gz |
MIR Cleanup - Clean up constants more
Diffstat (limited to 'src')
-rw-r--r-- | src/mir/cleanup.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/mir/cleanup.cpp b/src/mir/cleanup.cpp index b535c7ce..ef2a24aa 100644 --- a/src/mir/cleanup.cpp +++ b/src/mir/cleanup.cpp @@ -956,6 +956,34 @@ void MIR_Cleanup_Param(const ::MIR::TypeResolve& state, MirMutator& mutator, ::M MIR_Cleanup_Constant(state, mutator, e); ) ) + + // Effectively a copy of the code that handles RValue::Constant below + if( p.is_Constant() && p.as_Constant().is_Const() ) + { + const auto& ce = p.as_Constant().as_Const(); + ::HIR::TypeRef c_ty; + const auto* lit_ptr = MIR_Cleanup_GetConstant(state, *ce.p, c_ty); + if( lit_ptr && !lit_ptr->is_Defer() ) + { + DEBUG("Replace constant " << *ce.p << " with " << *lit_ptr); + auto new_rval = MIR_Cleanup_LiteralToRValue(state, mutator, *lit_ptr, c_ty.clone(), mv$(*ce.p)); + if( auto* lv = new_rval.opt_Use() ) { + p = ::MIR::Param::make_LValue( ::std::move(*lv) ); + } + else if( auto* c = new_rval.opt_Constant() ) { + MIR_Cleanup_Constant(state, mutator, *c); + p = ::MIR::Param::make_Constant( ::std::move(*c) ); + } + else { + auto tmp_lv = mutator.in_temporary( mv$(c_ty), mv$(new_rval) ); + p = ::MIR::Param::make_LValue( ::std::move(tmp_lv) ); + } + } + else + { + DEBUG("No replacement for constant " << *ce.p); + } + } } void MIR_Cleanup(const StaticTraitResolve& resolve, const ::HIR::ItemPath& path, ::MIR::Function& fcn, const ::HIR::Function::args_t& args, const ::HIR::TypeRef& ret_type) |