From ad07450e5650c42dbbe5fba4fb70d9ea9547a39f Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 16 Apr 2020 10:59:15 -0400
Subject: [PATCH 46/96] FIXME: avoid passing manager ptr around; rename
 canonicalization tests to 'equality' and start porting them

---
 gcc/analyzer/engine.cc        |   4 +-
 gcc/analyzer/program-state.cc |  15 +-
 gcc/analyzer/region-model2.cc | 432 ++++++++++++++++------------------
 gcc/analyzer/region-model2.h  |  71 +++---
 4 files changed, 234 insertions(+), 288 deletions(-)

diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index a4b37e84dd8..dd41d040faf 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -1031,9 +1031,7 @@ exploded_node::on_stmt (exploded_graph &eg,
      }
   else if (state->m_region_model2)
     {
-      engine2 *eng2 = eg.get_ext_state ().get_engine2 ();
-      region_model2_manager *mgr = eng2->get_model_manager ();
-      if (state->m_region_model2->on_stmt (mgr, snode, stmt))
+      if (state->m_region_model2->on_stmt (snode, stmt))
 	return on_stmt_flags (false);
       else
 	return on_stmt_flags::terminate_path ();
diff --git a/gcc/analyzer/program-state.cc b/gcc/analyzer/program-state.cc
index fa3f47fdb0d..2592ebd5e1b 100644
--- a/gcc/analyzer/program-state.cc
+++ b/gcc/analyzer/program-state.cc
@@ -605,7 +605,11 @@ program_state::program_state (const extrinsic_state &ext_state)
   if (ext_state.get_engine ())
     m_revamp_state = new revamp_state (ext_state);
   else if (ext_state.get_engine2 ())
-    m_region_model2 = new region_model2 ();
+    {
+      engine2 *eng2 = ext_state.get_engine2 ();
+      region_model2_manager *mgr = eng2->get_model_manager ();
+      m_region_model2 = new region_model2 (mgr);
+    }
   else
     m_region_model = new region_model ();
   int num_states = ext_state.get_num_checkers ();
@@ -854,10 +858,8 @@ program_state::push_frame (const extrinsic_state &ext_state,
     }
   else if (m_region_model2)
     {
-      engine2 *eng2 = ext_state.get_engine2 ();
-      region_model2_manager *mgr = eng2->get_model_manager ();
       region_model2_context *ctxt = NULL; // FIXME
-      m_region_model2->push_frame (mgr, fun, NULL, ctxt);
+      m_region_model2->push_frame (fun, NULL, ctxt);
     }
   else if (m_region_model)
     {
@@ -903,10 +905,7 @@ program_state::on_edge (exploded_graph &eg,
     }
   else if (m_region_model2)
     {
-      engine2 *eng2 = eg.get_ext_state ().get_engine2 ();
-      region_model2_manager *mgr = eng2->get_model_manager ();
-      return m_region_model2->maybe_update_for_edge (mgr,
-						     *succ,
+      return m_region_model2->maybe_update_for_edge (*succ,
 						     last_stmt,
 						     NULL); // FIXME: ctxt!
     }
diff --git a/gcc/analyzer/region-model2.cc b/gcc/analyzer/region-model2.cc
index a2ca9784eb3..e46d71011a1 100644
--- a/gcc/analyzer/region-model2.cc
+++ b/gcc/analyzer/region-model2.cc
@@ -2083,7 +2083,7 @@ frame_region2::add_to_hash (inchash::hash &hstate) const
 region2 *
 frame_region2::get_region_for_local (region_model2_manager *mgr,
 				     tree expr,
-				     region_model2_context *ctxt)
+				     region_model2_context */*ctxt*/)
 {
   if (region2 **slot = m_locals.get (expr))
     return *slot;
@@ -2869,7 +2869,7 @@ binding_cluster2::dump_to_pp (pretty_printer *pp, bool simple) const
 
 void
 binding_cluster2::bind (region_model2_manager *mgr,
-		       region2 *reg, svalue2 *val)
+			region2 *reg, svalue2 *val)
 {
   const binding_key2 *binding
     = binding_key2::make (mgr, reg, binding_key2::BK_direct);
@@ -3038,10 +3038,10 @@ region_model2_manager::get_ptr_svalue2 (tree ptr_type, region2 *pointee)
 
 /* class region_model2.  */
 
-/* region_model2's default ctor.  */
+/* FIXME: region_model2's default ctor.  */
 
-region_model2::region_model2 ()
-: m_current_frame (NULL)
+region_model2::region_model2 (region_model2_manager *mgr)
+: m_mgr (mgr), m_current_frame (NULL)
 {
   //m_root_reg = add_region2 (new root_region2 ());
   //m_constraints = new impl_constraint_manager (this);
@@ -3051,7 +3051,7 @@ region_model2::region_model2 ()
 /* region_model2's copy ctor.  */
 
 region_model2::region_model2 (const region_model2 &other)
-: m_current_frame (other.m_current_frame)
+: m_mgr (other.m_mgr), m_current_frame (other.m_current_frame)
 {
   // TODO: deep copy of m_cluster_map
 }
@@ -3103,42 +3103,35 @@ region_model2::operator= (const region_model2 &other)
 
 /* Equality operator for region_model2.
 
+   FIXME:
    Amongst other things this directly compares the svalue2 and region2
    vectors and so for this to be meaningful both this and OTHER should
    have been canonicalized.  */
 
-#if 0
 bool
 region_model2::operator== (const region_model2 &other) const
 {
-  if (m_root_reg != other.m_root_reg)
-    return false;
-
-  if (m_svalue2s.length () != other.m_svalue2s.length ())
-    return false;
+  /* We can only compare instances that use the same manager.  */
+  gcc_assert (m_mgr == other.m_mgr);
 
-  if (m_region2s.length () != other.m_region2s.length ())
+  // TODO:
+#if 0
+  if (m_cluster_map != other.m_cluster_map)
     return false;
+#endif
 
+#if 0
   if (*m_constraints != *other.m_constraints)
     return false;
+#endif
 
-  unsigned i;
-  svalue2 *svalue2;
-  FOR_EACH_VEC_ELT (other.m_svalue2s, i, svalue2)
-    if (!(*m_svalue2s[i] == *other.m_svalue2s[i]))
-      return false;
-
-  region2 *region2;
-  FOR_EACH_VEC_ELT (other.m_region2s, i, region2)
-    if (!(*m_region2s[i] == *other.m_region2s[i]))
-      return false;
+  if (m_current_frame != other.m_current_frame)
+    return false;
 
-  gcc_checking_assert (hash () == other.hash ());
+  //gcc_checking_assert (hash () == other.hash ());
 
   return true;
 }
-#endif
 
 /* Generate a hash value for this region_model2.  */
 
@@ -3579,8 +3572,7 @@ region_model2::validate () const
 /* FIXME.  */
 
 bool
-region_model2::on_stmt (region_model2_manager *mgr,
-			const supernode *snode,
+region_model2::on_stmt (const supernode *snode,
 			const gimple *stmt)
 {
 #if 0
@@ -3598,10 +3590,10 @@ region_model2::on_stmt (region_model2_manager *mgr,
       return true;
 
     case GIMPLE_ASSIGN:
-      return on_gassign (mgr, snode, as_a <const gassign *> (stmt));
+      return on_gassign (snode, as_a <const gassign *> (stmt));
 
     case GIMPLE_RETURN:
-      return on_greturn (mgr, snode, as_a <const greturn *> (stmt));
+      return on_greturn (snode, as_a <const greturn *> (stmt));
 
     default:
       sorry_at (stmt->location, "unhandled stmt: %qs",
@@ -3615,15 +3607,14 @@ region_model2::on_stmt (region_model2_manager *mgr,
    diagnostics.  */
 
 bool
-region_model2::on_gassign (region_model2_manager *mgr,
-			   const supernode */*snode*/,
+region_model2::on_gassign (const supernode */*snode*/,
 			   const gassign *assign)
 {
   region_model2_context *ctxt = NULL; // FIXME
   tree lhs = gimple_assign_lhs (assign);
   tree rhs1 = gimple_assign_rhs1 (assign);
 
-  region2 *lhs_reg = get_lvalue (mgr, lhs, ctxt);
+  region2 *lhs_reg = get_lvalue (lhs, ctxt);
 
   enum tree_code op = gimple_assign_rhs_code (assign);
   switch (op)
@@ -3703,8 +3694,8 @@ region_model2::on_gassign (region_model2_manager *mgr,
     case ARRAY_REF:
       {
 	/* LHS = RHS;  */
-	svalue2 *rhs_sval = get_rvalue (mgr, rhs1, ctxt);
-	set_value (mgr, lhs_reg, rhs_sval, ctxt);
+	svalue2 *rhs_sval = get_rvalue (rhs1, ctxt);
+	set_value (lhs_reg, rhs_sval, ctxt);
       }
       break;
 
@@ -4182,8 +4173,7 @@ region_model2::handle_unrecognized_call (const gcall *call,
    diagnostics.  */
 
 bool
-region_model2::on_greturn (region_model2_manager *mgr,
-			   const supernode */*snode*/,
+region_model2::on_greturn (const supernode */*snode*/,
 			   const greturn *return_stmt)
 {
   region_model2_context *ctxt = NULL; // FIXME
@@ -4192,8 +4182,8 @@ region_model2::on_greturn (region_model2_manager *mgr,
   tree rhs = gimple_return_retval (return_stmt);
 
   if (lhs && rhs)
-    copy_region (get_lvalue (mgr, lhs, ctxt),
-		 get_lvalue (mgr, rhs, ctxt),
+    copy_region (get_lvalue (lhs, ctxt),
+		 get_lvalue (rhs, ctxt),
 		 ctxt);
   return true;
 }
@@ -4290,8 +4280,7 @@ region_model2::on_longjmp (const gcall *longjmp_call, const gcall *setjmp_call,
    where RHS is for the appropriate edge.  */
 
 void
-region_model2::handle_phi (region_model2_manager *mgr,
-			   const gphi *phi,
+region_model2::handle_phi (const gphi *phi,
 			   tree lhs, tree rhs, bool is_back_edge,
 			   region_model2_context *ctxt)
 {
@@ -4301,7 +4290,7 @@ region_model2::handle_phi (region_model2_manager *mgr,
       if (VAR_DECL_IS_VIRTUAL_OPERAND (var))
 	return;
 
-  svalue2 *rhs_sval = get_rvalue (mgr, rhs, ctxt);
+  svalue2 *rhs_sval = get_rvalue (rhs, ctxt);
 
   if (is_back_edge && rhs_sval->get_kind () != svalue2::SK_UNKNOWN)
     {
@@ -4316,12 +4305,12 @@ region_model2::handle_phi (region_model2_manager *mgr,
 #if 1
       gcc_unreachable (); // FIXME
 #else
-      set_to_new_unknown_value (get_lvalue (mgr, lhs, ctxt),
+      set_to_new_unknown_value (get_lvalue (lhs, ctxt),
 				TREE_TYPE (lhs), ctxt);
 #endif
     }
   else
-    set_value (mgr, get_lvalue (mgr, lhs, ctxt), rhs_sval, ctxt);
+    set_value (get_lvalue (lhs, ctxt), rhs_sval, ctxt);
 
   if (ctxt)
     ctxt->on_phi (phi, rhs);
@@ -4332,7 +4321,7 @@ region_model2::handle_phi (region_model2_manager *mgr,
    Get the id of the region2 for PV within this region_model2,
    emitting any diagnostics to CTXT.  */
 region2 *
-region_model2::get_lvalue_1 (region_model2_manager *mgr, path_var pv,
+region_model2::get_lvalue_1 (path_var pv,
 			     region_model2_context *ctxt)
 {
   tree expr = pv.m_tree;
@@ -4359,11 +4348,11 @@ region_model2::get_lvalue_1 (region_model2_manager *mgr, path_var pv,
 	gcc_assert (TREE_OPERAND (expr, 3) == NULL_TREE);
 #endif
 
-	region2 *array_reg = get_lvalue (mgr, array, ctxt);
-	svalue2 *index_sval = get_rvalue (mgr, index, ctxt);
-	return mgr->get_element_region (array_reg,
-					TREE_TYPE (TREE_TYPE (array)),
-					index_sval, ctxt);
+	region2 *array_reg = get_lvalue (array, ctxt);
+	svalue2 *index_sval = get_rvalue (index, ctxt);
+	return m_mgr->get_element_region (array_reg,
+					  TREE_TYPE (TREE_TYPE (array)),
+					  index_sval, ctxt);
 #if 0
 	region2 *base_array_reg = get_region2 (array_reg);
 	array_region2 *array_reg  = base_array_reg->dyn_cast_array_region2 ();
@@ -4406,7 +4395,7 @@ region_model2::get_lvalue_1 (region_model2_manager *mgr, path_var pv,
     case VAR_DECL:
       /* Handle globals.  */
       if (is_global_var (expr))
-	return mgr->get_region_for_global (expr, ctxt);
+	return m_mgr->get_region_for_global (expr, ctxt);
 
       /* Fall through.  */
 
@@ -4421,7 +4410,7 @@ region_model2::get_lvalue_1 (region_model2_manager *mgr, path_var pv,
 
 	frame_region2 *frame = get_current_frame ();
 	gcc_assert (frame);
-	return frame->get_region_for_local (mgr, expr, ctxt);
+	return frame->get_region_for_local (m_mgr, expr, ctxt);
       }
 
     case COMPONENT_REF:
@@ -4437,8 +4426,8 @@ region_model2::get_lvalue_1 (region_model2_manager *mgr, path_var pv,
 	  return make_region2_for_unexpected_tree_code (ctxt, obj_type,
 						       dump_location_t ());
 #endif
-	region2 *obj_reg = get_lvalue (mgr, obj, ctxt);
-	return mgr->get_field_region (obj_reg, field, ctxt);
+	region2 *obj_reg = get_lvalue (obj, ctxt);
+	return m_mgr->get_field_region (obj_reg, field, ctxt);
       }
       break;
 #if 0
@@ -4511,13 +4500,13 @@ assert_compat_types (tree src_type, tree dst_type)
    emitting any diagnostics to CTXT.  */
 
 region2 *
-region_model2::get_lvalue (region_model2_manager *mgr, path_var pv,
+region_model2::get_lvalue (path_var pv,
 			   region_model2_context *ctxt)
 {
   if (pv.m_tree == NULL_TREE)
     return NULL;
 
-  region2 *result_reg = get_lvalue_1 (mgr, pv, ctxt);
+  region2 *result_reg = get_lvalue_1 (pv, ctxt);
   assert_compat_types (result_reg->get_type (), TREE_TYPE (pv.m_tree));
   return result_reg;
 }
@@ -4526,10 +4515,10 @@ region_model2::get_lvalue (region_model2_manager *mgr, path_var pv,
    recent stack frame if it's a local).  */
 
 region2 *
-region_model2::get_lvalue (region_model2_manager *mgr, tree expr,
+region_model2::get_lvalue (tree expr,
 			   region_model2_context *ctxt)
 {
-  return get_lvalue (mgr, path_var (expr, get_stack_depth () - 1), ctxt);
+  return get_lvalue (path_var (expr, get_stack_depth () - 1), ctxt);
 }
 
 /* Implementation of region_model2::get_rvalue; the latter adds type-checking.
@@ -4538,7 +4527,7 @@ region_model2::get_lvalue (region_model2_manager *mgr, tree expr,
    emitting any diagnostics to CTXT.  */
 
 svalue2 *
-region_model2::get_rvalue_1 (region_model2_manager *mgr, path_var pv,
+region_model2::get_rvalue_1 (path_var pv,
 			     region_model2_context *ctxt)
 {
   gcc_assert (pv.m_tree);
@@ -4577,14 +4566,14 @@ region_model2::get_rvalue_1 (region_model2_manager *mgr, path_var pv,
     case RESULT_DECL:
     case ARRAY_REF:
       {
-	region2 *element_reg = get_lvalue (mgr, pv, ctxt);
-	return get_store_value (mgr, element_reg);
+	region2 *element_reg = get_lvalue (pv, ctxt);
+	return get_store_value (element_reg);
       }
 
     case INTEGER_CST:
     case REAL_CST:
     case STRING_CST:
-      return mgr->get_or_create_constant_svalue2 (pv.m_tree);
+      return m_mgr->get_or_create_constant_svalue2 (pv.m_tree);
 #if 0
     case COMPONENT_REF:
     case MEM_REF:
@@ -4600,13 +4589,13 @@ region_model2::get_rvalue_1 (region_model2_manager *mgr, path_var pv,
    emitting any diagnostics to CTXT.  */
 
 svalue2 *
-region_model2::get_rvalue (region_model2_manager *mgr, path_var pv,
+region_model2::get_rvalue (path_var pv,
 			   region_model2_context *ctxt)
 {
   if (pv.m_tree == NULL_TREE)
     return NULL;
 
-  svalue2 *result_sval = get_rvalue_1 (mgr, pv, ctxt);
+  svalue2 *result_sval = get_rvalue_1 (pv, ctxt);
 
   assert_compat_types (result_sval->get_type (), TREE_TYPE (pv.m_tree));
 
@@ -4617,46 +4606,46 @@ region_model2::get_rvalue (region_model2_manager *mgr, path_var pv,
    recent stack frame if it's a local).  */
 
 svalue2 *
-region_model2::get_rvalue (region_model2_manager *mgr, tree expr,
+region_model2::get_rvalue (tree expr,
 			   region_model2_context *ctxt)
 {
-  return get_rvalue (mgr, path_var (expr, get_stack_depth () - 1), ctxt);
+  return get_rvalue (path_var (expr, get_stack_depth () - 1), ctxt);
 }
 
 /* FIXME.  */
 
 svalue2 *
-region_model2::get_store_value (region_model2_manager *mgr, region2 *reg)
+region_model2::get_store_value (region2 *reg)
 {
-  svalue2 *sval = get_direct_binding (mgr, reg);
+  svalue2 *sval = get_direct_binding (reg);
   if (sval)
     return sval;
 
   /* FIXME: symbolic value. */
-  return mgr->get_or_create_initial_value (reg);
+  return m_mgr->get_or_create_initial_value (reg);
 }
 
 svalue2 *
-region_model2::get_direct_binding (region_model2_manager *mgr, region2 *reg)
+region_model2::get_direct_binding (region2 *reg)
 {
-  return get_binding (mgr, reg, binding_key2::BK_direct);
+  return get_binding (reg, binding_key2::BK_direct);
 }
 
 svalue2 *
-region_model2::get_default_binding (region_model2_manager *mgr, region2 *reg)
+region_model2::get_default_binding (region2 *reg)
 {
-  return get_binding (mgr, reg, binding_key2::BK_direct);
+  return get_binding (reg, binding_key2::BK_direct);
 }
 
 svalue2 *
-region_model2::get_binding (region_model2_manager *mgr, region2 *reg,
+region_model2::get_binding (region2 *reg,
 			    binding_key2::kind kind)
 {
   const region2 *base_reg = reg->get_base_region ();
   binding_cluster2 **cluster_slot = m_cluster_map.get (base_reg);
   if (!cluster_slot)
     return NULL;
-  return (*cluster_slot)->get_binding (mgr, reg, kind);
+  return (*cluster_slot)->get_binding (m_mgr, reg, kind);
 }
 
 /* Return an svalue2 *for a pointer to RID of type PTR_TYPE, reusing
@@ -4986,15 +4975,14 @@ region_model2::deref_rvalue (tree ptr, region_model2_context *ctxt)
    by RHS_SVAL.  */
 
 void
-region_model2::set_value (region_model2_manager *mgr,
-			  region2 *lhs_reg, svalue2 *rhs_sval,
+region_model2::set_value (region2 *lhs_reg, svalue2 *rhs_sval,
 			  region_model2_context */*ctxt*/)
 {
   gcc_assert (lhs_reg);
   gcc_assert (rhs_sval);
 
 #if 1
-  remove_overlapping_bindings (mgr, lhs_reg);
+  remove_overlapping_bindings (lhs_reg);
 
   const region2 *base_reg = lhs_reg->get_base_region ();
   binding_cluster2 *cluster = NULL;
@@ -5006,7 +4994,7 @@ region_model2::set_value (region_model2_manager *mgr,
       cluster = new binding_cluster2 ();
       m_cluster_map.put (base_reg, cluster);
     }
-  cluster->bind (mgr, lhs_reg, rhs_sval);
+  cluster->bind (m_mgr, lhs_reg, rhs_sval);
 #else
   m_store_map.put (lhs_reg, rhs_sval);
   // TODO: various kinds of invalidation etc
@@ -5016,8 +5004,7 @@ region_model2::set_value (region_model2_manager *mgr,
 /* FIXME.  */
 
 void
-region_model2::remove_overlapping_bindings (region_model2_manager *mgr,
-					    region2 *reg)
+region_model2::remove_overlapping_bindings (region2 *reg)
 {
   const region2 *base_reg = reg->get_base_region ();
   if (reg == base_reg)
@@ -5027,21 +5014,20 @@ region_model2::remove_overlapping_bindings (region_model2_manager *mgr,
       return;
     }
   if (binding_cluster2 **cluster_slot = m_cluster_map.get (base_reg))
-    (*cluster_slot)->remove_overlapping_bindings (mgr, reg);
+    (*cluster_slot)->remove_overlapping_bindings (m_mgr, reg);
 }
 
 /* Set the value of the region2 given by LHS to the value given
    by RHS.  */
 
 void
-region_model2::set_value (region_model2_manager *mgr,
-			  tree lhs, tree rhs, region_model2_context *ctxt)
+region_model2::set_value (tree lhs, tree rhs, region_model2_context *ctxt)
 {
-  region2 *lhs_reg = get_lvalue (mgr, lhs, ctxt);
-  svalue2 *rhs_sval = get_rvalue (mgr, rhs, ctxt);
+  region2 *lhs_reg = get_lvalue (lhs, ctxt);
+  svalue2 *rhs_sval = get_rvalue (rhs, ctxt);
   gcc_assert (lhs_reg);
   gcc_assert (rhs_sval);
-  set_value (mgr, lhs_reg, rhs_sval, ctxt);
+  set_value (lhs_reg, rhs_sval, ctxt);
 }
 
 /* Determine what is known about the condition "LHS_SVAL OP RHS_SVAL" within
@@ -5174,8 +5160,7 @@ region_model2::eval_condition_without_cm (svalue2 *lhs_sval,
    Use CTXT for reporting any diagnostics associated with the accesses.  */
 
 bool
-region_model2::add_constraint (region_model2_manager *mgr,
-			       tree lhs, enum tree_code op, tree rhs,
+region_model2::add_constraint (tree lhs, enum tree_code op, tree rhs,
 			       region_model2_context *ctxt)
 {
   /* For now, make no attempt to capture constraints on floating-point
@@ -5183,8 +5168,8 @@ region_model2::add_constraint (region_model2_manager *mgr,
   if (FLOAT_TYPE_P (TREE_TYPE (lhs)) || FLOAT_TYPE_P (TREE_TYPE (rhs)))
     return true;
 
-  svalue2 *lhs_sval = get_rvalue (mgr, lhs, ctxt);
-  svalue2 *rhs_sval = get_rvalue (mgr, rhs, ctxt);
+  svalue2 *lhs_sval = get_rvalue (lhs, ctxt);
+  svalue2 *rhs_sval = get_rvalue (rhs, ctxt);
 
   tristate t_cond = eval_condition (lhs_sval, op, rhs_sval);
 
@@ -5362,8 +5347,7 @@ region_model2::add_any_constraints_from_gcall (enum tree_code op,
    Use CTXT for reporting any diagnostics associated with the accesses.  */
 
 tristate
-region_model2::eval_condition (region_model2_manager *mgr,
-			       tree lhs,
+region_model2::eval_condition (tree lhs,
 			       enum tree_code op,
 			       tree rhs,
 			       region_model2_context *ctxt)
@@ -5373,9 +5357,9 @@ region_model2::eval_condition (region_model2_manager *mgr,
   if (FLOAT_TYPE_P (TREE_TYPE (lhs)) || FLOAT_TYPE_P (TREE_TYPE (rhs)))
     return tristate::unknown ();
 
-  return eval_condition (get_rvalue (mgr, lhs, ctxt),
+  return eval_condition (get_rvalue (lhs, ctxt),
 			 op,
-			 get_rvalue (mgr, rhs, ctxt));
+			 get_rvalue (rhs, ctxt));
 }
 
 /* If SID is a constant value, return the underlying tree constant.
@@ -5601,8 +5585,7 @@ region_model2::update_for_phis (const supernode *snode,
    than program state).  */
 
 bool
-region_model2::maybe_update_for_edge (region_model2_manager *mgr,
-				      const superedge &edge,
+region_model2::maybe_update_for_edge (const superedge &edge,
 				      const gimple *last_stmt,
 				      region_model2_context *ctxt)
 {
@@ -5615,7 +5598,7 @@ region_model2::maybe_update_for_edge (region_model2_manager *mgr,
     case SUPEREDGE_CALL:
       {
 	const call_superedge *call_edge = as_a <const call_superedge *> (&edge);
-	update_for_call_superedge (mgr, *call_edge, ctxt);
+	update_for_call_superedge (*call_edge, ctxt);
       }
       break;
 
@@ -5644,14 +5627,14 @@ region_model2::maybe_update_for_edge (region_model2_manager *mgr,
   if (const gcond *cond_stmt = dyn_cast <const gcond *> (last_stmt))
     {
       const cfg_superedge *cfg_sedge = as_a <const cfg_superedge *> (&edge);
-      return apply_constraints_for_gcond (mgr, *cfg_sedge, cond_stmt, ctxt);
+      return apply_constraints_for_gcond (*cfg_sedge, cond_stmt, ctxt);
     }
 
   if (const gswitch *switch_stmt = dyn_cast <const gswitch *> (last_stmt))
     {
       const switch_cfg_superedge *switch_sedge
 	= as_a <const switch_cfg_superedge *> (&edge);
-      return apply_constraints_for_gswitch (mgr, *switch_sedge, switch_stmt,
+      return apply_constraints_for_gswitch (*switch_sedge, switch_stmt,
 					    ctxt);
     }
 
@@ -5664,8 +5647,7 @@ region_model2::maybe_update_for_edge (region_model2_manager *mgr,
    caller's frame.  */
 
 void
-region_model2::update_for_call_superedge (region_model2_manager *mgr,
-					  const call_superedge &call_edge,
+region_model2::update_for_call_superedge (const call_superedge &call_edge,
 					  region_model2_context *ctxt)
 {
   /* Build a vec of argument svalue2_id, using the current top
@@ -5676,10 +5658,10 @@ region_model2::update_for_call_superedge (region_model2_manager *mgr,
   for (unsigned i = 0; i < gimple_call_num_args (call_stmt); i++)
     {
       tree arg = gimple_call_arg (call_stmt, i);
-      arg_svals.quick_push (get_rvalue (mgr, arg, ctxt));
+      arg_svals.quick_push (get_rvalue (arg, ctxt));
     }
 
-  push_frame (mgr, call_edge.get_callee_function (), &arg_svals, ctxt);
+  push_frame (call_edge.get_callee_function (), &arg_svals, ctxt);
 }
 
 /* Pop the top-most frame_region2 from the stack, and copy the return
@@ -5751,8 +5733,7 @@ region_model2::update_for_call_summary (const callgraph_superedge &/*cg_sedge*/,
    (and so the edge should not be taken).  */
 
 bool
-region_model2::apply_constraints_for_gcond (region_model2_manager *mgr,
-					    const cfg_superedge &sedge,
+region_model2::apply_constraints_for_gcond (const cfg_superedge &sedge,
 					    const gcond *cond_stmt,
 					    region_model2_context *ctxt)
 {
@@ -5765,7 +5746,7 @@ region_model2::apply_constraints_for_gcond (region_model2_manager *mgr,
   tree rhs = gimple_cond_rhs (cond_stmt);
   if (cfg_edge->flags & EDGE_FALSE_VALUE)
     op = invert_tree_comparison (op, false /* honor_nans */);
-  return add_constraint (mgr, lhs, op, rhs, ctxt);
+  return add_constraint (lhs, op, rhs, ctxt);
 }
 
 /* Given an EDGE guarded by SWITCH_STMT, determine appropriate constraints
@@ -5777,8 +5758,7 @@ region_model2::apply_constraints_for_gcond (region_model2_manager *mgr,
    (and so the edge should not be taken).  */
 
 bool
-region_model2::apply_constraints_for_gswitch (region_model2_manager *mgr,
-					      const switch_cfg_superedge &edge,
+region_model2::apply_constraints_for_gswitch (const switch_cfg_superedge &edge,
 					      const gswitch *switch_stmt,
 					      region_model2_context *ctxt)
 {
@@ -5792,13 +5772,13 @@ region_model2::apply_constraints_for_gswitch (region_model2_manager *mgr,
       if (upper_bound)
 	{
 	  /* Range.  */
-	  if (!add_constraint (mgr, index, GE_EXPR, lower_bound, ctxt))
+	  if (!add_constraint (index, GE_EXPR, lower_bound, ctxt))
 	    return false;
-	  return add_constraint (mgr, index, LE_EXPR, upper_bound, ctxt);
+	  return add_constraint (index, LE_EXPR, upper_bound, ctxt);
 	}
       else
 	/* Single-value.  */
-	return add_constraint (mgr, index, EQ_EXPR, lower_bound, ctxt);
+	return add_constraint (index, EQ_EXPR, lower_bound, ctxt);
     }
   else
     {
@@ -5818,16 +5798,16 @@ region_model2::apply_constraints_for_gswitch (region_model2_manager *mgr,
 	      /* Exclude this range-valued case.
 		 For now, we just exclude the boundary values.
 		 TODO: exclude the values within the region2.  */
-	      if (!add_constraint (mgr, index, NE_EXPR, other_lower_bound,
+	      if (!add_constraint (index, NE_EXPR, other_lower_bound,
 				   ctxt))
 		return false;
-	      if (!add_constraint (mgr, index, NE_EXPR, other_upper_bound,
+	      if (!add_constraint (index, NE_EXPR, other_upper_bound,
 				   ctxt))
 		return false;
 	    }
 	  else
 	    /* Exclude this single-valued case.  */
-	    if (!add_constraint (mgr, index, NE_EXPR, other_lower_bound, ctxt))
+	    if (!add_constraint (index, NE_EXPR, other_lower_bound, ctxt))
 	      return false;
 	}
       return true;
@@ -5862,11 +5842,10 @@ region_model2::get_stack_region2 *() const
    Return the region2 *of the new frame_region2.  */
 
 region2 *
-region_model2::push_frame (region_model2_manager *mgr,
-			   function *fun, vec<svalue2 *> *arg_svals,
+region_model2::push_frame (function *fun, vec<svalue2 *> *arg_svals,
 			   region_model2_context */*ctxt*/)
 {
-  m_current_frame = mgr->get_frame_region (m_current_frame, fun);
+  m_current_frame = m_mgr->get_frame_region (m_current_frame, fun);
   if (arg_svals)
     {
       gcc_unreachable ();
@@ -5913,7 +5892,7 @@ region_model2::pop_frame (region2 *result_dst_reg,
 	  gcc_unreachable ();
 #if 0
 	  copy_region2 (result_dst_reg,
-			get_lvalue (mgr, result, ctxt),
+			get_lvalue (result, ctxt),
 			ctxt);
 #endif
 	}
@@ -5981,15 +5960,6 @@ region_model2::get_function_at_depth (unsigned depth) const
 }
 #endif
 
-/* Get the region2 *of this model's globals region2 (if any).  */
-#if 0
-region2_id
-region_model2::get_globals_region2 *() const
-{
-  return get_root_region2 ()->get_globals_region2 *();
-}
-#endif
-
 /* Change the meaning of SID to be NEW_SVAL
    (e.g. when deferencing an unknown pointer, the pointer
    becomes a pointer to a symbolic region2, so that all users
@@ -6868,12 +6838,11 @@ test_tree_cmp_on_constants ()
 
 void
 assert_condition (const location &loc,
-		  region_model2_manager *mgr,
 		  region_model2 &model,
 		  tree lhs, tree_code op, tree rhs,
 		  tristate expected)
 {
-  tristate actual = model.eval_condition (mgr, lhs, op, rhs, NULL);
+  tristate actual = model.eval_condition (lhs, op, rhs, NULL);
   ASSERT_EQ_AT (loc, actual, expected);
 }
 
@@ -6924,9 +6893,8 @@ assert_dump_eq (const location &loc,
 static void
 test_dump ()
 {
-  // FIXME:
-  //region_model2_manager mgr;
-  region_model2 model;
+  region_model2_manager mgr;
+  region_model2 model (&mgr);
 
   ASSERT_DUMP_EQ (model, false, "");
   ASSERT_DUMP_EQ (model, true, "");
@@ -7014,25 +6982,25 @@ test_dump_2 ()
   tree int_m3 = build_int_cst (integer_type_node, -3);
 
   region_model2_manager mgr;
-  region_model2 model;
-  model.set_value (&mgr, c_x, int_17, NULL);
-  model.set_value (&mgr, c_y, int_m3, NULL);
+  region_model2 model (&mgr);
+  model.set_value (c_x, int_17, NULL);
+  model.set_value (c_y, int_m3, NULL);
 
   // TODO: test get_value
 
   /* Verify get_offset for "c.x".  */
   {
-    region2 *c_x_reg = model.get_lvalue (&mgr, c_x, NULL);
+    region2 *c_x_reg = model.get_lvalue (c_x, NULL);
     region_offset offset = c_x_reg->get_offset ();
-    ASSERT_EQ (offset.get_base_region (), model.get_lvalue (&mgr, c, NULL));
+    ASSERT_EQ (offset.get_base_region (), model.get_lvalue (c, NULL));
     ASSERT_EQ (offset.get_bit_offset (), 0);
   }
 
   /* Verify get_offset for "c.y".  */
   {
-    region2 *c_y_reg = model.get_lvalue (&mgr, c_y, NULL);
+    region2 *c_y_reg = model.get_lvalue (c_y, NULL);
     region_offset offset = c_y_reg->get_offset ();
-    ASSERT_EQ (offset.get_base_region (), model.get_lvalue (&mgr, c, NULL));
+    ASSERT_EQ (offset.get_base_region (), model.get_lvalue (c, NULL));
     ASSERT_EQ (offset.get_bit_offset (), INT_TYPE_SIZE);
   }
 
@@ -7122,7 +7090,7 @@ test_get_representative_tree ()
     ASSERT_DUMP_TREE_EQ (rep, "&\"foo\"[0]");
   }
 }
-
+#endif
 /* Verify that calling region_model2::get_rvalue repeatedly on the same
    tree constant retrieves the same svalue2_id.  */
 
@@ -7133,14 +7101,15 @@ test_unique_constants ()
   tree int_42 = build_int_cst (integer_type_node, 42);
 
   test_region_model2_context ctxt;
-  region_model2 model;
+  region_model2_manager mgr;
+  region_model2 model (&mgr);
   ASSERT_EQ (model.get_rvalue (int_0, &ctxt), model.get_rvalue (int_0, &ctxt));
   ASSERT_EQ (model.get_rvalue (int_42, &ctxt),
 	     model.get_rvalue (int_42, &ctxt));
   ASSERT_NE (model.get_rvalue (int_0, &ctxt), model.get_rvalue (int_42, &ctxt));
   ASSERT_EQ (ctxt.get_num_diagnostics (), 0);
 }
-
+#if 0
 /* Check that operator== and hashing works as expected for the
    various svalue2 subclasses.  */
 
@@ -7422,14 +7391,13 @@ test_assignment ()
 
   /* "x == 0", then use of y, then "y = 0;".  */
   region_model2_manager mgr;
-  region_model2 model;
+  region_model2 model (&mgr);
 #if 0
   ADD_SAT_CONSTRAINT (model, x, EQ_EXPR, int_0);
   ASSERT_CONDITION_UNKNOWN (model, y, EQ_EXPR, int_0);
 #endif
-  model.set_value (&mgr,
-		   model.get_lvalue (&mgr, y, NULL),
-		   model.get_rvalue (&mgr, int_0, NULL),
+  model.set_value (model.get_lvalue (y, NULL),
+		   model.get_rvalue (int_0, NULL),
 		   NULL);
 #if 0
   ASSERT_CONDITION_TRUE (model, y, EQ_EXPR, int_0);
@@ -7522,54 +7490,50 @@ test_stack_frames ()
 
   region_model2_manager mgr;
   test_region_model2_context ctxt;
-  region_model2 model;
+  region_model2 model (&mgr);
 
   /* Push stack frame for "parent_fn".  */
   region2 *parent_frame_reg
-    = model.push_frame (&mgr, DECL_STRUCT_FUNCTION (parent_fndecl),
+    = model.push_frame (DECL_STRUCT_FUNCTION (parent_fndecl),
 			NULL, &ctxt);
   ASSERT_EQ (model.get_current_frame (), parent_frame_reg);
-  region2 *a_in_parent_reg = model.get_lvalue (&mgr, a, &ctxt);
-  model.set_value (&mgr,
-		   a_in_parent_reg,
-		   model.get_rvalue (&mgr, int_42, &ctxt),
+  region2 *a_in_parent_reg = model.get_lvalue (a, &ctxt);
+  model.set_value (a_in_parent_reg,
+		   model.get_rvalue (int_42, &ctxt),
 		   &ctxt);
 #if 0
-  model.set_to_new_unknown_value (model.get_lvalue (&mgr, b, &ctxt),
+  model.set_to_new_unknown_value (model.get_lvalue (b, &ctxt),
 				  integer_type_node, &ctxt);
-  model.add_constraint (&mgr, b, LT_EXPR, int_10, &ctxt);
-  ASSERT_EQ (model.eval_condition (&mgr, b, LT_EXPR, int_10, &ctxt),
+  model.add_constraint (b, LT_EXPR, int_10, &ctxt);
+  ASSERT_EQ (model.eval_condition (b, LT_EXPR, int_10, &ctxt),
 	     tristate (tristate::TS_TRUE));
 #endif
 
   /* Push stack frame for "child_fn".  */
   region2 *child_frame_reg
-    = model.push_frame (&mgr, DECL_STRUCT_FUNCTION (child_fndecl), NULL, &ctxt);
+    = model.push_frame (DECL_STRUCT_FUNCTION (child_fndecl), NULL, &ctxt);
   ASSERT_EQ (model.get_current_frame (), child_frame_reg);
-  region2 *x_in_child_reg = model.get_lvalue (&mgr, x, &ctxt);
-  model.set_value (&mgr,
-		   x_in_child_reg,
-		   model.get_rvalue (&mgr, int_0, &ctxt),
+  region2 *x_in_child_reg = model.get_lvalue (x, &ctxt);
+  model.set_value (x_in_child_reg,
+		   model.get_rvalue (int_0, &ctxt),
 		   &ctxt);
 #if 0
-  model.set_to_new_unknown_value (model.get_lvalue (&mgr, y, &ctxt),
+  model.set_to_new_unknown_value (model.get_lvalue (y, &ctxt),
 				  integer_type_node, &ctxt);
-  model.add_constraint (&mgr, y, NE_EXPR, int_5, &ctxt);
-  ASSERT_EQ (model.eval_condition (&mgr, y, NE_EXPR, int_5, &ctxt),
+  model.add_constraint (y, NE_EXPR, int_5, &ctxt);
+  ASSERT_EQ (model.eval_condition (y, NE_EXPR, int_5, &ctxt),
 	     tristate (tristate::TS_TRUE));
 #endif
 
   /* Point a global pointer at a local in the child frame:  p = &x.  */
-  region2 *p_in_globals_reg = model.get_lvalue (&mgr, p, &ctxt);
-  model.set_value (&mgr,
-		   p_in_globals_reg,
+  region2 *p_in_globals_reg = model.get_lvalue (p, &ctxt);
+  model.set_value (p_in_globals_reg,
 		   mgr.get_ptr_svalue2 (ptr_type_node, x_in_child_reg),
 		   &ctxt);
 
   /* Point another global pointer at p: q = &p.  */
-  region2 *q_in_globals_reg = model.get_lvalue (&mgr, q, &ctxt);
-  model.set_value (&mgr,
-		   q_in_globals_reg,
+  region2 *q_in_globals_reg = model.get_lvalue (q, &ctxt);
+  model.set_value (q_in_globals_reg,
 		   mgr.get_ptr_svalue2 (ptr_type_node, p_in_globals_reg),
 		   &ctxt);
 
@@ -7615,7 +7579,7 @@ test_stack_frames ()
 
   /* Verify that p (which was pointing at the local "x" in the popped
      frame) has been poisoned.  */
-  svalue2 *new_p_sval = model.get_rvalue (&mgr, p, &ctxt);
+  svalue2 *new_p_sval = model.get_rvalue (p, &ctxt);
 #if 0
   ASSERT_EQ (new_p_sval->get_kind (), svalue2::SK_POISONED);
   ASSERT_EQ (new_p_sval->dyn_cast_poisoned_svalue2 ()->get_poison_kind (),
@@ -7624,23 +7588,23 @@ test_stack_frames ()
 
   /* Verify that q still points to p, in spite of the region2
      renumbering.  */
-  svalue2 *new_q_sval = model.get_rvalue (&mgr, q, &ctxt);
+  svalue2 *new_q_sval = model.get_rvalue (q, &ctxt);
   ASSERT_EQ (new_q_sval->get_kind (), svalue2::SK_REGION);
   ASSERT_EQ (new_q_sval->dyn_cast_region_svalue2 ()->get_pointee (),
-	     model.get_lvalue (&mgr, p, &ctxt));
+	     model.get_lvalue (p, &ctxt));
 
   /* Verify that top of stack has been updated.  */
   ASSERT_EQ (model.get_current_frame (), parent_frame_reg);
 
   /* Verify locals in parent frame.  */
   /* Verify "a" still has its value.  */
-  svalue2 *new_a_sval = model.get_rvalue (&mgr, a, &ctxt);
+  svalue2 *new_a_sval = model.get_rvalue (a, &ctxt);
   ASSERT_EQ (new_a_sval->get_kind (), svalue2::SK_CONSTANT);
   ASSERT_EQ (new_a_sval->dyn_cast_constant_svalue2 ()->get_constant (),
 	     int_42);
   /* Verify "b" still has its constraint.  */
 #if 0
-  ASSERT_EQ (model.eval_condition (&mgr, b, LT_EXPR, int_10, &ctxt),
+  ASSERT_EQ (model.eval_condition (b, LT_EXPR, int_10, &ctxt),
 	     tristate (tristate::TS_TRUE));
 #endif
 }
@@ -7700,23 +7664,16 @@ test_get_representative_path_var ()
       ASSERT_EQ (pvs[0], path_var (n, depth));
     }
 }
+#endif
 
-/* Verify that the core region2s within a region_model2 are in a consistent
-   order after canonicalization.  */
+/* Verify that "empty" region_model2 instances are equal to each other.  */
 
 static void
-test_canonicalization_1 ()
+test_model_equality_1 ()
 {
-  region_model2 model0;
-  model0.get_root_region2 ()->ensure_stack_region2 (&model0);
-  model0.get_root_region2 ()->ensure_globals_region2 (&model0);
-
-  region_model2 model1;
-  model1.get_root_region2 ()->ensure_globals_region2 (&model1);
-  model1.get_root_region2 ()->ensure_stack_region2 (&model1);
-
-  model0.canonicalize (NULL);
-  model1.canonicalize (NULL);
+  region_model2_manager mgr;
+  region_model2 model0 (&mgr);
+  region_model2 model1 (&mgr);
   ASSERT_EQ (model0, model1);
 }
 
@@ -7724,17 +7681,18 @@ test_canonicalization_1 ()
       x = 42; y = 113;
    and
       y = 113; x = 42;
-   are equal after canonicalization.  */
+   are equal.  */
 
 static void
-test_canonicalization_2 ()
+test_model_equality_2 ()
 {
   tree int_42 = build_int_cst (integer_type_node, 42);
   tree int_113 = build_int_cst (integer_type_node, 113);
   tree x = build_global_decl ("x", integer_type_node);
   tree y = build_global_decl ("y", integer_type_node);
 
-  region_model2 model0;
+  region_model2_manager mgr;
+  region_model2 model0 (&mgr);
   model0.set_value (model0.get_lvalue (x, NULL),
 		    model0.get_rvalue (int_42, NULL),
 		    NULL);
@@ -7742,7 +7700,7 @@ test_canonicalization_2 ()
 		    model0.get_rvalue (int_113, NULL),
 		    NULL);
 
-  region_model2 model1;
+  region_model2 model1 (&mgr);
   model1.set_value (model1.get_lvalue (y, NULL),
 		    model1.get_rvalue (int_113, NULL),
 		    NULL);
@@ -7750,8 +7708,6 @@ test_canonicalization_2 ()
 		    model1.get_rvalue (int_42, NULL),
 		    NULL);
 
-  model0.canonicalize (NULL);
-  model1.canonicalize (NULL);
   ASSERT_EQ (model0, model1);
 }
 
@@ -7759,34 +7715,38 @@ test_canonicalization_2 ()
      x > 3 && y > 42
    and
      y > 42 && x > 3
-   are equal after canonicalization.  */
+   are equal.  */
 
 static void
-test_canonicalization_3 ()
+test_model_equality_3 ()
 {
   tree int_3 = build_int_cst (integer_type_node, 3);
   tree int_42 = build_int_cst (integer_type_node, 42);
   tree x = build_global_decl ("x", integer_type_node);
   tree y = build_global_decl ("y", integer_type_node);
 
-  region_model2 model0;
+  region_model2_manager mgr;
+  region_model2 model0 (&mgr);
+#if 0
   model0.add_constraint (x, GT_EXPR, int_3, NULL);
   model0.add_constraint (y, GT_EXPR, int_42, NULL);
+#endif
 
-  region_model2 model1;
+  region_model2 model1 (&mgr);
+#if 0
   model1.add_constraint (y, GT_EXPR, int_42, NULL);
   model1.add_constraint (x, GT_EXPR, int_3, NULL);
+#endif
 
-  model0.canonicalize (NULL);
-  model1.canonicalize (NULL);
   ASSERT_EQ (model0, model1);
 }
 
+#if 0
 /* Verify that we can canonicalize a model containing NaN and other real
    constants.  */
 
 static void
-test_canonicalization_4 ()
+test_model_equality_4 ()
 {
   auto_vec<tree> csts;
   append_interesting_constants (&csts);
@@ -8286,27 +8246,27 @@ test_var ()
   tree int_m3 = build_int_cst (integer_type_node, -3);
 
   region_model2_manager mgr;
-  region_model2 model;
+  region_model2 model (&mgr);
 
-  region2 *i_reg = model.get_lvalue (&mgr, i, NULL);
+  region2 *i_reg = model.get_lvalue (i, NULL);
   ASSERT_EQ (i_reg->get_kind (), region2::RK_DECL);
 
   /* Reading "i" should give a symbolic "initial value".  */
-  svalue2 *sval_init = model.get_rvalue (&mgr, i, NULL);
+  svalue2 *sval_init = model.get_rvalue (i, NULL);
   ASSERT_EQ (sval_init->get_kind (), svalue2::SK_INITIAL);
   ASSERT_EQ (sval_init->dyn_cast_initial_svalue2 ()->get_region (), i_reg);
   /* ..and doing it again should give the same "initial value".  */
-  ASSERT_EQ (model.get_rvalue (&mgr, i, NULL), sval_init);
+  ASSERT_EQ (model.get_rvalue (i, NULL), sval_init);
 
   /* "i = 17;".  */
-  model.set_value (&mgr, i, int_17, NULL);
-  ASSERT_EQ (model.get_rvalue (&mgr, i, NULL),
-	     model.get_rvalue (&mgr, int_17, NULL));
+  model.set_value (i, int_17, NULL);
+  ASSERT_EQ (model.get_rvalue (i, NULL),
+	     model.get_rvalue (int_17, NULL));
 
   /* "i = -3;".  */
-  model.set_value (&mgr, i, int_m3, NULL);
-  ASSERT_EQ (model.get_rvalue (&mgr, i, NULL),
-	     model.get_rvalue (&mgr, int_m3, NULL));
+  model.set_value (i, int_m3, NULL);
+  ASSERT_EQ (model.get_rvalue (i, NULL),
+	     model.get_rvalue (int_m3, NULL));
 
   /* Verify get_offset for "i".  */
   {
@@ -8355,51 +8315,51 @@ test_array ()
   tree int_m3 = build_int_cst (integer_type_node, -3);
 
   region_model2_manager mgr;
-  region_model2 model;
+  region_model2 model (&mgr);
   /* "arr[0] = 17;".  */
-  model.set_value (&mgr, arr_0, int_17, NULL);
+  model.set_value (arr_0, int_17, NULL);
   /* "arr[1] = -3;".  */
-  model.set_value (&mgr, arr_1, int_m3, NULL);
+  model.set_value (arr_1, int_m3, NULL);
 
-  ASSERT_EQ (model.get_rvalue (&mgr, arr_0, NULL),
-	     model.get_rvalue (&mgr, int_17, NULL));
-  ASSERT_EQ (model.get_rvalue (&mgr, arr_1, NULL),
-	     model.get_rvalue (&mgr, int_m3, NULL));
+  ASSERT_EQ (model.get_rvalue (arr_0, NULL),
+	     model.get_rvalue (int_17, NULL));
+  ASSERT_EQ (model.get_rvalue (arr_1, NULL),
+	     model.get_rvalue (int_m3, NULL));
 
   /* Overwrite a pre-existing binding: "arr[1] = 42;".  */
-  model.set_value (&mgr, arr_1, int_42, NULL);
-  ASSERT_EQ (model.get_rvalue (&mgr, arr_1, NULL),
-	     model.get_rvalue (&mgr, int_42, NULL));
+  model.set_value (arr_1, int_42, NULL);
+  ASSERT_EQ (model.get_rvalue (arr_1, NULL),
+	     model.get_rvalue (int_42, NULL));
 
   /* Verify get_offset for "arr[0]".  */
   {
-    region2 *arr_0_reg = model.get_lvalue (&mgr, arr_0, NULL);
+    region2 *arr_0_reg = model.get_lvalue (arr_0, NULL);
     region_offset offset = arr_0_reg->get_offset ();
-    ASSERT_EQ (offset.get_base_region (), model.get_lvalue (&mgr, arr, NULL));
+    ASSERT_EQ (offset.get_base_region (), model.get_lvalue (arr, NULL));
     ASSERT_EQ (offset.get_bit_offset (), 0);
   }
 
   /* Verify get_offset for "arr[1]".  */
   {
-    region2 *arr_1_reg = model.get_lvalue (&mgr, arr_1, NULL);
+    region2 *arr_1_reg = model.get_lvalue (arr_1, NULL);
     region_offset offset = arr_1_reg->get_offset ();
-    ASSERT_EQ (offset.get_base_region (), model.get_lvalue (&mgr, arr, NULL));
+    ASSERT_EQ (offset.get_base_region (), model.get_lvalue (arr, NULL));
     ASSERT_EQ (offset.get_bit_offset (), INT_TYPE_SIZE);
   }
 
 #if 0
   /* "arr[i] = i;" - this should remove the earlier bindings.  */
-  model.set_value (&mgr, arr_i, i, NULL);
-  ASSERT_EQ (model.get_rvalue (&mgr, arr_i, NULL),
-	     model.get_rvalue (&mgr, i, NULL));
+  model.set_value (arr_i, i, NULL);
+  ASSERT_EQ (model.get_rvalue (arr_i, NULL),
+	     model.get_rvalue (i, NULL));
   // TODO: get_value for other bindings
   // TODO: assert that there is now no binding for the other indices
 
 
   /* "arr[0] = 17;" - this should remove the arr[i] binding.  */
-  model.set_value (&mgr, arr_0, int_17, NULL);
-  ASSERT_EQ (model.get_rvalue (&mgr, arr_0, NULL),
-	     model.get_rvalue (&mgr, int_17, NULL));
+  model.set_value (arr_0, int_17, NULL);
+  ASSERT_EQ (model.get_rvalue (arr_0, NULL),
+	     model.get_rvalue (int_17, NULL));
 #endif
 
   /* Simplified dump.  */
@@ -8426,7 +8386,9 @@ analyzer_region_model2_cc_tests ()
 #if 0
   test_dump_3 ();
   test_get_representative_tree ();
+#endif
   test_unique_constants ();
+#if 0
   test_svalue2_equality ();
   test_region2_equality ();
   test_purging_by_criteria ();
@@ -8439,10 +8401,12 @@ analyzer_region_model2_cc_tests ()
   test_stack_frames ();
 #if 0
   test_get_representative_path_var ();
-  test_canonicalization_1 ();
-  test_canonicalization_2 ();
-  test_canonicalization_3 ();
-  test_canonicalization_4 ();
+#endif
+  test_model_equality_1 ();
+  test_model_equality_2 ();
+  test_model_equality_3 ();
+#if 0
+  test_model_equality_4 ();
   test_state_merging ();
   test_constraint_merging ();
   test_malloc_constraints ();
diff --git a/gcc/analyzer/region-model2.h b/gcc/analyzer/region-model2.h
index 4b4a34fe5dc..e2104c51176 100644
--- a/gcc/analyzer/region-model2.h
+++ b/gcc/analyzer/region-model2.h
@@ -1534,7 +1534,7 @@ private:
 class region_model2
 {
  public:
-  region_model2 ();
+  region_model2 (region_model2_manager *mgr);
   region_model2 (const region_model2 &other);
   ~region_model2 ();
 
@@ -1568,11 +1568,9 @@ class region_model2
 
   void validate () const;
 
-  bool on_stmt (region_model2_manager *mgr,
-		const supernode *snode,
+  bool on_stmt (const supernode *snode,
 		const gimple *stmt);
-  bool on_gassign (region_model2_manager *mgr,
-		   const supernode *snode,
+  bool on_gassign (const supernode *snode,
 		   const gassign *stmt);
   bool on_call_pre (const gcall *stmt, region_model2_context *ctxt);
   void on_call_post (const gcall *stmt,
@@ -1580,8 +1578,7 @@ class region_model2
 		     region_model2_context *ctxt);
   void handle_unrecognized_call (const gcall *call,
 				 region_model2_context *ctxt);
-  bool on_greturn (region_model2_manager *mgr,
-		   const supernode *snode,
+  bool on_greturn (const supernode *snode,
 		   const greturn *stmt);
   void on_setjmp (const gcall *stmt, const exploded_node *enode,
 		  region_model2_context *ctxt);
@@ -1592,13 +1589,11 @@ class region_model2
 			const cfg_superedge *last_cfg_superedge,
 			region_model2_context *ctxt);
 
-  void handle_phi (region_model2_manager *mgr,
-		   const gphi *phi,
+  void handle_phi (const gphi *phi,
 		   tree lhs, tree rhs, bool is_back_edge,
 		   region_model2_context *ctxt);
 
-  bool maybe_update_for_edge (region_model2_manager *mgr,
-			      const superedge &edge,
+  bool maybe_update_for_edge (const superedge &edge,
 			      const gimple *last_stmt,
 			      region_model2_context *ctxt);
 
@@ -1608,8 +1603,7 @@ class region_model2
 
   region2_id get_stack_region2_id () const;
 #endif
-  region2 *push_frame (region_model2_manager *mgr,
-		       function *fun, vec<svalue2 *> *arg_sids,
+  region2 *push_frame (function *fun, vec<svalue2 *> *arg_sids,
 		       region_model2_context *ctxt);
   frame_region2 *get_current_frame () const { return m_current_frame; }
   function * get_current_function () const;
@@ -1624,14 +1618,10 @@ class region_model2
   void replace_svalue2 (svalue2_id sid, svalue2 *new_sval);
 #endif
 
-  region2 *get_lvalue (region_model2_manager *mgr,
-		       path_var pv, region_model2_context *ctxt);
-  region2 *get_lvalue (region_model2_manager *mgr,
-		       tree expr, region_model2_context *ctxt);
-  svalue2 *get_rvalue (region_model2_manager *mgr,
-		       path_var pv, region_model2_context *ctxt);
-  svalue2 *get_rvalue (region_model2_manager *mgr,
-		       tree expr, region_model2_context *ctxt);
+  region2 *get_lvalue (path_var pv, region_model2_context *ctxt);
+  region2 *get_lvalue (tree expr, region_model2_context *ctxt);
+  svalue2 *get_rvalue (path_var pv, region_model2_context *ctxt);
+  svalue2 *get_rvalue (tree expr, region_model2_context *ctxt);
 
 #if 0
   svalue2_id get_or_create_ptr_svalue2 (tree ptr_type, region2_id id);
@@ -1650,11 +1640,9 @@ class region_model2
   region2_id deref_rvalue (tree ptr, region_model2_context *ctxt);
 
 #endif
-  void set_value (region_model2_manager *mgr,
-		  region2 *lhs_reg, svalue2 *rhs_sval,
+  void set_value (region2 *lhs_reg, svalue2 *rhs_sval,
 		  region_model2_context *ctxt);
-  void set_value (region_model2_manager *mgr,
-		  tree lhs, tree rhs, region_model2_context *ctxt);
+  void set_value (tree lhs, tree rhs, region_model2_context *ctxt);
   svalue2 *set_to_new_unknown_value (region2 *dst_reg, tree type,
 				     region_model2_context *ctxt);
   void copy_region (region2 *dst_reg, region2 *src_reg,
@@ -1667,13 +1655,11 @@ class region_model2
 				      enum tree_code op,
 				      svalue2_id rhs) const;
 #endif
-  tristate eval_condition (region_model2_manager *mgr,
-			   tree lhs,
+  tristate eval_condition (tree lhs,
 			   enum tree_code op,
 			   tree rhs,
 			   region_model2_context *ctxt);
-  bool add_constraint (region_model2_manager *mgr,
-		       tree lhs, enum tree_code op, tree rhs,
+  bool add_constraint (tree lhs, enum tree_code op, tree rhs,
 		       region_model2_context *ctxt);
 #if 0
   tree maybe_get_constant (svalue2_id sid) const;
@@ -1735,18 +1721,17 @@ class region_model2
 #endif
 
  private:
-  region2 *get_lvalue_1 (region_model2_manager *mgr, path_var pv,
+  region2 *get_lvalue_1 (path_var pv,
 			 region_model2_context *ctxt);
-  svalue2 *get_rvalue_1 (region_model2_manager *mgr, path_var pv,
+  svalue2 *get_rvalue_1 (path_var pv,
 			 region_model2_context *ctxt);
-  svalue2 *get_store_value (region_model2_manager *mgr, region2 *reg);
+  svalue2 *get_store_value (region2 *reg);
 
-  svalue2 *get_direct_binding (region_model2_manager *mgr, region2 *reg);
-  svalue2 *get_default_binding (region_model2_manager *mgr, region2 *reg);
-  svalue2 *get_binding (region_model2_manager *mgr, region2 *reg,
-			binding_key2::kind kind);
+  svalue2 *get_direct_binding (region2 *reg);
+  svalue2 *get_default_binding (region2 *reg);
+  svalue2 *get_binding (region2 *reg, binding_key2::kind kind);
 
-  void remove_overlapping_bindings (region_model2_manager *mgr, region2 *reg);
+  void remove_overlapping_bindings (region2 *reg);
 
 #if 0
   void copy_struct_region2 (region2_id dst_rid, struct_region2 *dst_reg,
@@ -1772,19 +1757,16 @@ class region_model2
 				       const gcall *call,
 				       region_model2_context *ctxt);
 #endif
-  void update_for_call_superedge (region_model2_manager *mgr,
-				  const call_superedge &call_edge,
+  void update_for_call_superedge (const call_superedge &call_edge,
 				  region_model2_context *ctxt);
   void update_for_return_superedge (const return_superedge &return_edge,
 				    region_model2_context *ctxt);
   void update_for_call_summary (const callgraph_superedge &cg_sedge,
 				region_model2_context *ctxt);
-  bool apply_constraints_for_gcond (region_model2_manager *mgr,
-				    const cfg_superedge &edge,
+  bool apply_constraints_for_gcond (const cfg_superedge &edge,
 				    const gcond *cond_stmt,
 				    region_model2_context *ctxt);
-  bool apply_constraints_for_gswitch (region_model2_manager *mgr,
-				      const switch_cfg_superedge &edge,
+  bool apply_constraints_for_gswitch (const switch_cfg_superedge &edge,
 				      const gswitch *switch_stmt,
 				      region_model2_context *ctxt);
 #if 0
@@ -1797,6 +1779,9 @@ class region_model2
 #endif
 
 
+  /* Storing this here to avoid passing it around everywhere.  */
+  region_model2_manager *const m_mgr;
+
 #if 1
   typedef hash_map <const region2 *, binding_cluster2 *> cluster_map_t;
   cluster_map_t m_cluster_map; // TODO: deep copy of this!
-- 
2.21.0

