HAL
grouping.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4 // Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
5 // Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
6 // Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 
31 #pragma once
32 
34 #include "hal_core/defines.h"
35 
36 #include <map>
37 #include <set>
38 #include <shared_mutex>
39 #include <unordered_map>
40 #include <unordered_set>
41 #include <vector>
42 
43 namespace hal
44 {
45  namespace dataflow
46  {
54  struct Grouping
55  {
61  Grouping(const NetlistAbstraction& na);
62 
69  Grouping(const NetlistAbstraction& na, const std::vector<std::vector<Gate*>>& groups);
70 
74  Grouping(const Grouping& other);
75 
80 
84  std::unordered_map<u32, std::vector<u32>> group_control_fingerprint_map;
85 
89  std::unordered_map<u32, std::unordered_set<u32>> gates_of_group;
90 
94  std::unordered_map<u32, u32> parent_group_of_gate;
95 
99  std::map<u32, bool> operations_on_group_allowed;
100 
109  bool operator==(const Grouping& other) const;
110 
119  bool operator!=(const Grouping& other) const;
120 
127  std::map<PinType, std::unordered_set<u32>> get_control_signals_of_group(u32 group_id) const;
128 
135  std::unordered_set<u32> get_successor_groups_of_group(u32 group_id) const;
136 
143  std::unordered_set<u32> get_predecessor_groups_of_group(u32 group_id) const;
144 
153  std::unordered_set<u32> get_known_successor_groups_of_group(u32 group_id) const;
154 
163  std::unordered_set<u32> get_known_predecessor_groups_of_group(u32 group_id) const;
164 
171  std::set<u32> get_register_stage_intersect_of_group(u32 group_id) const;
172 
181  bool are_groups_allowed_to_merge(u32 group_1_id, u32 group_2_id, bool enforce_type_consistency) const;
182 
189  bool is_group_allowed_to_split(u32 group_id) const;
190 
191  private:
192  /* caches */
193  mutable struct
194  {
195  std::shared_mutex mutex;
196  std::unordered_map<u32, std::unordered_set<u32>> suc_cache;
197  std::unordered_map<u32, std::unordered_set<u32>> pred_cache;
198  std::unordered_map<u32, std::unordered_set<u32>> suc_known_group_cache;
199  std::unordered_map<u32, std::unordered_set<u32>> pred_known_group_cache;
200  std::set<std::set<u32>> comparison_cache;
201  } cache;
202 
203  const std::set<std::set<u32>>& get_comparison_data() const;
204 
205  std::unordered_set<u32> get_signals_of_group(u32 group_id, const std::unordered_map<u32, std::unordered_set<u32>>& signals) const;
206  };
207  } // namespace dataflow
208 } // namespace hal
quint32 u32
This file contains the struct that holds all information on the netlist abstraction used for dataflow...
Grouping used during dataflow analysis.
Definition: grouping.h:55
std::unordered_map< u32, std::vector< u32 > > group_control_fingerprint_map
Definition: grouping.h:84
std::unordered_map< u32, std::unordered_set< u32 > > gates_of_group
Definition: grouping.h:89
std::set< std::set< u32 > > comparison_cache
Definition: grouping.h:200
std::unordered_map< u32, u32 > parent_group_of_gate
Definition: grouping.h:94
std::unordered_map< u32, std::unordered_set< u32 > > suc_known_group_cache
Definition: grouping.h:198
std::unordered_set< u32 > get_known_predecessor_groups_of_group(u32 group_id) const
Get the known predecessor groups of a group.
Definition: grouping.cpp:266
std::unordered_map< u32, std::unordered_set< u32 > > pred_cache
Definition: grouping.h:197
const NetlistAbstraction & netlist_abstr
Definition: grouping.h:79
bool operator!=(const Grouping &other) const
Check two groupings for inequality.
Definition: grouping.cpp:104
std::unordered_set< u32 > get_predecessor_groups_of_group(u32 group_id) const
Get the predecessor groups of a group.
Definition: grouping.cpp:204
std::unordered_set< u32 > get_known_successor_groups_of_group(u32 group_id) const
Get the known successor groups of a group.
Definition: grouping.cpp:235
std::unordered_map< u32, std::unordered_set< u32 > > pred_known_group_cache
Definition: grouping.h:199
Grouping(const NetlistAbstraction &na)
Construct a new (empty) grouping from a netlist abstraction.
Definition: grouping.cpp:12
bool are_groups_allowed_to_merge(u32 group_1_id, u32 group_2_id, bool enforce_type_consistency) const
Check if two groups are allowed to be merged.
Definition: grouping.cpp:297
bool operator==(const Grouping &other) const
Check two groupings for equality.
Definition: grouping.cpp:94
std::unordered_map< u32, std::unordered_set< u32 > > suc_cache
Definition: grouping.h:196
std::unordered_set< u32 > get_successor_groups_of_group(u32 group_id) const
Get the successor groups of a group.
Definition: grouping.cpp:173
std::map< PinType, std::unordered_set< u32 > > get_control_signals_of_group(u32 group_id) const
Get the control signals of a group as a map from the control pin type to the connected net IDs.
Definition: grouping.cpp:109
std::set< u32 > get_register_stage_intersect_of_group(u32 group_id) const
Get the intersection of the register stages of all gates of the group.
Definition: grouping.cpp:139
std::shared_mutex mutex
Definition: grouping.h:195
std::map< u32, bool > operations_on_group_allowed
Definition: grouping.h:99
bool is_group_allowed_to_split(u32 group_id) const
Check if the group is allowed to be split.
Definition: grouping.cpp:328
The abstraction of the netlist that only contains gates of a specified type, e.g.,...