dep_graph.hh (2669:f2b336e89d2a) dep_graph.hh (2674:6d4afef73a20)
1
2#ifndef __CPU_O3_DEP_GRAPH_HH__
3#define __CPU_O3_DEP_GRAPH_HH__
4
5#include "cpu/o3/comm.hh"
6
1
2#ifndef __CPU_O3_DEP_GRAPH_HH__
3#define __CPU_O3_DEP_GRAPH_HH__
4
5#include "cpu/o3/comm.hh"
6
7/** Node in a linked list. */
7template <class DynInstPtr>
8class DependencyEntry
9{
10 public:
11 DependencyEntry()
12 : inst(NULL), next(NULL)
13 { }
14
15 DynInstPtr inst;
16 //Might want to include data about what arch. register the
17 //dependence is waiting on.
18 DependencyEntry<DynInstPtr> *next;
19};
20
8template <class DynInstPtr>
9class DependencyEntry
10{
11 public:
12 DependencyEntry()
13 : inst(NULL), next(NULL)
14 { }
15
16 DynInstPtr inst;
17 //Might want to include data about what arch. register the
18 //dependence is waiting on.
19 DependencyEntry<DynInstPtr> *next;
20};
21
22/** Array of linked list that maintains the dependencies between
23 * producing instructions and consuming instructions. Each linked
24 * list represents a single physical register, having the future
25 * producer of the register's value, and all consumers waiting on that
26 * value on the list. The head node of each linked list represents
27 * the producing instruction of that register. Instructions are put
28 * on the list upon reaching the IQ, and are removed from the list
29 * either when the producer completes, or the instruction is squashed.
30*/
21template <class DynInstPtr>
22class DependencyGraph
23{
24 public:
25 typedef DependencyEntry<DynInstPtr> DepEntry;
26
31template <class DynInstPtr>
32class DependencyGraph
33{
34 public:
35 typedef DependencyEntry<DynInstPtr> DepEntry;
36
37 /** Default construction. Must call resize() prior to use. */
27 DependencyGraph()
28 : numEntries(0), memAllocCounter(0), nodesTraversed(0), nodesRemoved(0)
29 { }
30
38 DependencyGraph()
39 : numEntries(0), memAllocCounter(0), nodesTraversed(0), nodesRemoved(0)
40 { }
41
42 /** Resize the dependency graph to have num_entries registers. */
31 void resize(int num_entries);
32
43 void resize(int num_entries);
44
45 /** Clears all of the linked lists. */
33 void reset();
34
46 void reset();
47
48 /** Inserts an instruction to be dependent on the given index. */
35 void insert(PhysRegIndex idx, DynInstPtr &new_inst);
36
49 void insert(PhysRegIndex idx, DynInstPtr &new_inst);
50
51 /** Sets the producing instruction of a given register. */
37 void setInst(PhysRegIndex idx, DynInstPtr &new_inst)
38 { dependGraph[idx].inst = new_inst; }
39
52 void setInst(PhysRegIndex idx, DynInstPtr &new_inst)
53 { dependGraph[idx].inst = new_inst; }
54
55 /** Clears the producing instruction. */
40 void clearInst(PhysRegIndex idx)
41 { dependGraph[idx].inst = NULL; }
42
56 void clearInst(PhysRegIndex idx)
57 { dependGraph[idx].inst = NULL; }
58
59 /** Removes an instruction from a single linked list. */
43 void remove(PhysRegIndex idx, DynInstPtr &inst_to_remove);
44
60 void remove(PhysRegIndex idx, DynInstPtr &inst_to_remove);
61
62 /** Removes and returns the newest dependent of a specific register. */
45 DynInstPtr pop(PhysRegIndex idx);
46
63 DynInstPtr pop(PhysRegIndex idx);
64
65 /** Checks if there are any dependents on a specific register. */
47 bool empty(PhysRegIndex idx) { return !dependGraph[idx].next; }
48
49 /** Debugging function to dump out the dependency graph.
50 */
51 void dump();
52
53 private:
54 /** Array of linked lists. Each linked list is a list of all the
55 * instructions that depend upon a given register. The actual
56 * register's index is used to index into the graph; ie all
57 * instructions in flight that are dependent upon r34 will be
58 * in the linked list of dependGraph[34].
59 */
60 DepEntry *dependGraph;
61
66 bool empty(PhysRegIndex idx) { return !dependGraph[idx].next; }
67
68 /** Debugging function to dump out the dependency graph.
69 */
70 void dump();
71
72 private:
73 /** Array of linked lists. Each linked list is a list of all the
74 * instructions that depend upon a given register. The actual
75 * register's index is used to index into the graph; ie all
76 * instructions in flight that are dependent upon r34 will be
77 * in the linked list of dependGraph[34].
78 */
79 DepEntry *dependGraph;
80
81 /** Number of linked lists; identical to the number of registers. */
62 int numEntries;
63
64 // Debug variable, remove when done testing.
65 unsigned memAllocCounter;
66
67 public:
82 int numEntries;
83
84 // Debug variable, remove when done testing.
85 unsigned memAllocCounter;
86
87 public:
88 // Debug variable, remove when done testing.
68 uint64_t nodesTraversed;
89 uint64_t nodesTraversed;
90 // Debug variable, remove when done testing.
69 uint64_t nodesRemoved;
70};
71
72template <class DynInstPtr>
73void
74DependencyGraph<DynInstPtr>::resize(int num_entries)
75{
76 numEntries = num_entries;

--- 137 unchanged lines hidden ---
91 uint64_t nodesRemoved;
92};
93
94template <class DynInstPtr>
95void
96DependencyGraph<DynInstPtr>::resize(int num_entries)
97{
98 numEntries = num_entries;

--- 137 unchanged lines hidden ---