HAL
group_by_input_output_size.cpp
Go to the documentation of this file.
2 
6 
7 #include <list>
8 #include <map>
9 #include <set>
10 
11 namespace hal
12 {
13  namespace dataflow
14  {
15  namespace group_by_input_output_size
16  {
17  std::shared_ptr<Grouping> process(const processing::Configuration& config, const std::shared_ptr<Grouping>& state, bool successors)
18  {
19  auto new_state = std::make_shared<Grouping>(state->netlist_abstr);
20 
21  /* check characteristics */
22  std::map<std::pair<u32, u32>, std::list<u32>> characteristics_map;
23  for (const auto& [group_id, gates] : state->gates_of_group)
24  {
25  std::pair<u32, u32> min_max_connections;
26  bool first = true;
27  for (auto g : gates)
28  {
29  u32 val;
30  if (successors)
31  {
32  val = state->netlist_abstr.gate_to_successors.at(g).size();
33  }
34  else
35  {
36  val = state->netlist_abstr.gate_to_predecessors.at(g).size();
37  }
38 
39  if (first)
40  {
41  min_max_connections.first = val;
42  min_max_connections.second = val;
43  }
44  else
45  {
46  min_max_connections.first = std::min(min_max_connections.first, val);
47  min_max_connections.second = std::max(min_max_connections.second, val);
48  }
49  first = false;
50  }
51 
52  characteristics_map[min_max_connections].push_back(group_id);
53  }
54 
55  /* check if merge is allowed */
56  std::vector<std::vector<u32>> merge_sets;
57  for (auto& merge_candidates : characteristics_map)
58  {
59  auto& work_list = merge_candidates.second;
60  while (!work_list.empty())
61  {
62  auto it = work_list.begin();
63  auto group_id = *it;
64  it = work_list.erase(it);
65 
66  std::vector<u32> merge_set = {group_id};
67 
68  while (it != work_list.end())
69  {
70  auto test_group_id = *it;
71 
72  if (!state->are_groups_allowed_to_merge(group_id, test_group_id, config.enforce_type_consistency))
73  {
74  ++it;
75  continue;
76  }
77 
78  merge_set.push_back(test_group_id);
79  it = work_list.erase(it);
80  }
81  merge_sets.push_back(merge_set);
82  }
83  }
84 
85  /* merge groups */
86  u32 id_counter = -1;
87  for (const auto& groups_to_merge : merge_sets)
88  {
89  u32 new_group_id = ++id_counter;
90 
91  for (const auto& old_group : groups_to_merge)
92  {
93  auto gates = state->gates_of_group.at(old_group);
94  new_state->group_control_fingerprint_map[new_group_id] = new_state->netlist_abstr.gate_to_fingerprint.at(*gates.begin());
95  new_state->operations_on_group_allowed[new_group_id] = state->operations_on_group_allowed.at(old_group);
96  new_state->gates_of_group[new_group_id].insert(gates.begin(), gates.end());
97  for (const auto& sg : gates)
98  {
99  new_state->parent_group_of_gate[sg] = new_group_id;
100  }
101  }
102  }
103 
104  return new_state;
105  }
106 
107  } // namespace group_by_input_output_size
108  } // namespace dataflow
109 } // namespace hal
std::shared_ptr< Grouping > process(const processing::Configuration &config, const std::shared_ptr< Grouping > &state, bool successors)
quint32 u32
This file contains the struct that holds all information on the netlist abstraction used for dataflow...
This file contains the class that holds all information of a dataflow analysis grouping.