HAL
group_by_control_signals.cpp
Go to the documentation of this file.
2 
7 
8 #include <list>
9 
10 namespace hal
11 {
12  namespace dataflow
13  {
14  namespace group_by_control_signals
15  {
16  std::shared_ptr<Grouping> process(const processing::Configuration& config, const std::shared_ptr<Grouping>& state)
17  {
18  auto new_state = std::make_shared<Grouping>(state->netlist_abstr);
19 
20  /* check characteristics */
21  std::map<std::set<u32>, std::unordered_set<u32>> characteristics_map;
22  for (const auto& [group_id, gates] : state->gates_of_group)
23  {
24  std::set<u32> candidate_characteristic_set;
25  for (const auto& [_, signals] : state->get_control_signals_of_group(group_id))
26  {
27  candidate_characteristic_set.insert(signals.begin(), signals.end());
28  }
29  characteristics_map[candidate_characteristic_set].insert(group_id);
30  }
31 
32  /* check if merge is allowed */
33  std::vector<std::vector<u32>> merge_sets;
34  for (auto& merge_candidates : characteristics_map)
35  {
36  auto& work_list = merge_candidates.second;
37  while (!work_list.empty())
38  {
39  auto it = work_list.begin();
40  auto group_id = *it;
41  it = work_list.erase(it);
42 
43  std::vector<u32> merge_set = {group_id};
44 
45  while (it != work_list.end())
46  {
47  auto test_group_id = *it;
48 
49  if (!state->are_groups_allowed_to_merge(group_id, test_group_id, config.enforce_type_consistency))
50  {
51  ++it;
52  continue;
53  }
54 
55  merge_set.push_back(test_group_id);
56  it = work_list.erase(it);
57  }
58  merge_sets.push_back(merge_set);
59  }
60  }
61 
62  /* merge groups */
63  u32 id_counter = -1;
64  for (const auto& groups_to_merge : merge_sets)
65  {
66  u32 new_group_id = ++id_counter;
67 
68  for (const auto& old_group : groups_to_merge)
69  {
70  auto gates = state->gates_of_group.at(old_group);
71  new_state->group_control_fingerprint_map[new_group_id] = new_state->netlist_abstr.gate_to_fingerprint.at(*gates.begin());
72  new_state->operations_on_group_allowed[new_group_id] = state->operations_on_group_allowed.at(old_group);
73  new_state->gates_of_group[new_group_id].insert(gates.begin(), gates.end());
74  for (const auto& sg : gates)
75  {
76  new_state->parent_group_of_gate[sg] = new_group_id;
77  }
78  }
79  }
80 
81  return new_state;
82  }
83  } // namespace group_by_control_signals
84  } // namespace dataflow
85 } // namespace hal
std::shared_ptr< Grouping > process(const processing::Configuration &config, const std::shared_ptr< Grouping > &state)
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.