Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Make Process::subprograms a std::unordered_map
authorGabriel Corona <gabriel.corona@loria.fr>
Mon, 20 Jul 2015 14:38:36 +0000 (16:38 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 21 Jul 2015 12:18:31 +0000 (14:18 +0200)
src/mc/mc_dwarf.cpp
src/mc/mc_object_info.cpp
src/mc/mc_object_info.h
src/mc/mcer_ignore.cpp
teshsuite/mc/dwarf/dwarf.cpp

index fb13031..2c10779 100644 (file)
@@ -899,13 +899,9 @@ static void MC_dwarf_handle_scope_die(mc_object_info_t info, Dwarf_Die * die,
   MC_dwarf_handle_children(info, die, unit, &frame, ns);
 
   // Register it:
   MC_dwarf_handle_children(info, die, unit, &frame, ns);
 
   // Register it:
-  if (klass == mc_tag_subprogram) {
-    char *key = bprintf("%" PRIx64, (uint64_t) frame.id);
-
-    xbt_dict_set(info->subprograms, key,
-      new simgrid::mc::Frame(std::move(frame)), NULL);
-    xbt_free(key);
-  } else if (klass == mc_tag_scope)
+  if (klass == mc_tag_subprogram)
+    info->subprograms[frame.id] = frame;
+  else if (klass == mc_tag_scope)
     parent_frame->scopes.push_back(std::move(frame));
 }
 
     parent_frame->scopes.push_back(std::move(frame));
 }
 
@@ -1027,17 +1023,13 @@ static void MC_make_functions_index(mc_object_info_t info)
 {
   xbt_dynar_t index = xbt_dynar_new(sizeof(s_mc_function_index_item_t), NULL);
 
 {
   xbt_dynar_t index = xbt_dynar_new(sizeof(s_mc_function_index_item_t), NULL);
 
-  // Populate the array:
-  mc_frame_t frame = NULL;
-  xbt_dict_cursor_t cursor;
-  char *key;
-  xbt_dict_foreach(info->subprograms, cursor, key, frame) {
-    if (frame->low_pc == NULL)
+  for (auto& e : info->subprograms) {
+    if (e.second.low_pc == nullptr)
       continue;
     s_mc_function_index_item_t entry;
       continue;
     s_mc_function_index_item_t entry;
-    entry.low_pc = frame->low_pc;
-    entry.high_pc = frame->high_pc;
-    entry.function = frame;
+    entry.low_pc = e.second.low_pc;
+    entry.high_pc = e.second.high_pc;
+    entry.function = &e.second;
     xbt_dynar_push(index, &entry);
   }
 
     xbt_dynar_push(index, &entry);
   }
 
@@ -1069,13 +1061,12 @@ static void mc_post_process_scope(mc_object_info_t info, mc_frame_t scope)
 {
 
   if (scope->tag == DW_TAG_inlined_subroutine) {
 {
 
   if (scope->tag == DW_TAG_inlined_subroutine) {
-
     // Attach correct namespaced name in inlined subroutine:
     // Attach correct namespaced name in inlined subroutine:
-    char *key = bprintf("%" PRIx64, (uint64_t) scope->abstract_origin_id);
-    mc_frame_t abstract_origin = (mc_frame_t) xbt_dict_get_or_null(info->subprograms, key);
-    xbt_assert(abstract_origin, "Could not lookup abstract origin %s", key);
-    xbt_free(key);
-    scope->name = abstract_origin->name;
+    auto i = info->subprograms.find(scope->abstract_origin_id);
+    xbt_assert(i != info->subprograms.end(),
+      "Could not lookup abstract origin %" PRIx64,
+      (uint64_t) scope->abstract_origin_id);
+    scope->name = i->second.name;
   }
 
   // Direct:
   }
 
   // Direct:
@@ -1096,12 +1087,8 @@ static void mc_post_process_scope(mc_object_info_t info, mc_frame_t scope)
 
 static void MC_post_process_functions(mc_object_info_t info)
 {
 
 static void MC_post_process_functions(mc_object_info_t info)
 {
-  xbt_dict_cursor_t cursor;
-  char *key;
-  mc_frame_t subprogram = NULL;
-  xbt_dict_foreach(info->subprograms, cursor, key, subprogram) {
-    mc_post_process_scope(info, subprogram);
-  }
+  for (auto& entry : info->subprograms)
+    mc_post_process_scope(info, &entry.second);
 }
 
 
 }
 
 
index 7324681..6edd005 100644 (file)
@@ -79,14 +79,12 @@ ObjectInformation::ObjectInformation()
   this->end_rw = nullptr;
   this->start_ro = nullptr;
   this->end_ro = nullptr;
   this->end_rw = nullptr;
   this->start_ro = nullptr;
   this->end_ro = nullptr;
-  this->subprograms = xbt_dict_new_homogeneous(mc_frame_free);
   this->functions_index = nullptr;
 }
 
 ObjectInformation::~ObjectInformation()
 {
   xbt_free(this->file_name);
   this->functions_index = nullptr;
 }
 
 ObjectInformation::~ObjectInformation()
 {
   xbt_free(this->file_name);
-  xbt_dict_free(&this->subprograms);
   xbt_dynar_free(&this->functions_index);
 }
 
   xbt_dynar_free(&this->functions_index);
 }
 
index bb0baad..019e5e7 100644 (file)
@@ -97,6 +97,41 @@ typedef int mc_object_info_flags;
 namespace simgrid {
 namespace mc {
 
 namespace simgrid {
 namespace mc {
 
+class Variable {
+public:
+  Variable();
+
+  Dwarf_Off dwarf_offset; /* Global offset of the field. */
+  int global;
+  std::string name;
+  std::uint64_t type_id;
+  mc_type_t type;
+
+  // Use either of:
+  simgrid::mc::LocationList location_list;
+  void* address;
+
+  size_t start_scope;
+  mc_object_info_t object_info;
+
+};
+
+class Frame {
+public:
+  Frame();
+
+  int tag;
+  std::string name;
+  void *low_pc;
+  void *high_pc;
+  simgrid::mc::LocationList frame_base;
+  std::vector<Variable> variables;
+  unsigned long int id; /* DWARF offset of the subprogram */
+  std::vector<Frame> scopes;
+  Dwarf_Off abstract_origin_id;
+  mc_object_info_t object_info;
+};
+
 class ObjectInformation {
 public:
   ObjectInformation();
 class ObjectInformation {
 public:
   ObjectInformation();
@@ -114,7 +149,7 @@ public:
   char *end_rw; // Read-write segment
   char *start_ro;
   char *end_ro; // read-only segment
   char *end_rw; // Read-write segment
   char *start_ro;
   char *end_ro; // read-only segment
-  xbt_dict_t subprograms; // xbt_dict_t<origin as hexadecimal string, mc_frame_t>
+  std::unordered_map<std::uint64_t, simgrid::mc::Frame> subprograms;
   // TODO, remove the mutable (to remove it we'll have to add a lot of const everywhere)
   mutable std::vector<simgrid::mc::Variable> global_variables;
   std::unordered_map<std::uint64_t, simgrid::mc::Type> types;
   // TODO, remove the mutable (to remove it we'll have to add a lot of const everywhere)
   mutable std::vector<simgrid::mc::Variable> global_variables;
   std::unordered_map<std::uint64_t, simgrid::mc::Type> types;
@@ -143,41 +178,6 @@ public:
 
 };
 
 
 };
 
-class Variable {
-public:
-  Variable();
-
-  Dwarf_Off dwarf_offset; /* Global offset of the field. */
-  int global;
-  std::string name;
-  std::uint64_t type_id;
-  mc_type_t type;
-
-  // Use either of:
-  simgrid::mc::LocationList location_list;
-  void* address;
-
-  size_t start_scope;
-  mc_object_info_t object_info;
-
-};
-
-class Frame {
-public:
-  Frame();
-
-  int tag;
-  std::string name;
-  void *low_pc;
-  void *high_pc;
-  simgrid::mc::LocationList frame_base;
-  std::vector<Variable> variables;
-  unsigned long int id; /* DWARF offset of the subprogram */
-  std::vector<Frame> scopes;
-  Dwarf_Off abstract_origin_id;
-  mc_object_info_t object_info;
-};
-
 }
 }
 
 }
 }
 
index bf75f7d..4c75203 100644 (file)
@@ -161,12 +161,9 @@ static void MC_ignore_local_variable_in_object(const char *var_name,
                                                const char *subprogram_name,
                                                mc_object_info_t info)
 {
                                                const char *subprogram_name,
                                                mc_object_info_t info)
 {
-  xbt_dict_cursor_t cursor2;
-  mc_frame_t frame;
-  char *key;
-  xbt_dict_foreach(info->subprograms, cursor2, key, frame) {
-    mc_ignore_local_variable_in_scope(var_name, subprogram_name, frame, frame);
-  }
+  for (auto& entry : info->subprograms)
+    mc_ignore_local_variable_in_scope(
+      var_name, subprogram_name, &entry.second, &entry.second);
 }
 
 /** \brief Ignore a local variable in a scope
 }
 
 /** \brief Ignore a local variable in a scope
index b8fb469..40f99bb 100644 (file)
@@ -32,12 +32,9 @@ static mc_type_t find_type_by_name(mc_object_info_t info, const char* name)
 static mc_frame_t find_function_by_name(
     mc_object_info_t info, const char* name)
 {
 static mc_frame_t find_function_by_name(
     mc_object_info_t info, const char* name)
 {
-  xbt_dict_cursor_t cursor = 0;
-  mc_frame_t subprogram;
-  char* key;
-  xbt_dict_foreach(info->subprograms, cursor, key, subprogram)
-    if(subprogram->name == name)
-      return subprogram;
+  for (auto& entry : info->subprograms)
+    if(entry.second.name == name)
+      return &entry.second;
   return nullptr;
 }
 
   return nullptr;
 }