summaryrefslogtreecommitdiff
path: root/src/mir/from_hir.hpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2017-04-22 22:05:27 +0800
committerJohn Hodge <tpg@ucc.asn.au>2017-04-22 22:05:27 +0800
commitaea444c2dcceab61aa6632f014602bf7043e6a74 (patch)
tree802e954c838b837eb02791c6d984542107b41f81 /src/mir/from_hir.hpp
parent505090085f9264088963e724dc93edfde7e56b38 (diff)
downloadmrust-aea444c2dcceab61aa6632f014602bf7043e6a74.tar.gz
MIR Gen - Common lvalue for if
Diffstat (limited to 'src/mir/from_hir.hpp')
-rw-r--r--src/mir/from_hir.hpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/mir/from_hir.hpp b/src/mir/from_hir.hpp
index e124770c..07228688 100644
--- a/src/mir/from_hir.hpp
+++ b/src/mir/from_hir.hpp
@@ -159,6 +159,11 @@ class MirBuilder
::std::vector<ScopeDef> m_scopes;
::std::vector<unsigned int> m_scope_stack;
ScopeHandle m_fcn_scope;
+
+ // LValue used only for the condition of `if`
+ // - Using a fixed temporary simplifies parts of lowering (scope related) and reduces load on
+ // the optimiser.
+ ::MIR::LValue m_if_cond_lval;
public:
MirBuilder(const Span& sp, const StaticTraitResolve& resolve, const ::HIR::Function::args_t& args, ::MIR::Function& output);
~MirBuilder();
@@ -186,6 +191,17 @@ public:
/// Obtains a result in a param (or a lvalue)
::MIR::Param get_result_in_param(const Span& sp, const ::HIR::TypeRef& ty, bool allow_missing_value=false);
+ ::MIR::LValue get_if_cond() const {
+ return m_if_cond_lval.clone();
+ }
+ ::MIR::LValue get_rval_in_if_cond(const Span& sp, ::MIR::RValue val) {
+ push_stmt_assign(sp, m_if_cond_lval.clone(), mv$(val));
+ return m_if_cond_lval.clone();
+ }
+ ::MIR::LValue get_result_in_if_cond(const Span& sp) {
+ return get_rval_in_if_cond(sp, get_result(sp));
+ }
+
// - Statements
// Push an assignment. NOTE: This also marks the rvalue as moved
void push_stmt_assign(const Span& sp, ::MIR::LValue dst, ::MIR::RValue val);
@@ -215,6 +231,7 @@ public:
void set_cur_block(unsigned int new_block);
::MIR::BasicBlockId pause_cur_block();
+
void end_block(::MIR::Terminator term);
::MIR::BasicBlockId new_bb_linked();