gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
free_list.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004-2005 The Regents of The University of Michigan
3  * Copyright (c) 2013 Advanced Micro Devices, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Authors: Kevin Lim
30  */
31 
32 #ifndef __CPU_O3_FREE_LIST_HH__
33 #define __CPU_O3_FREE_LIST_HH__
34 
35 #include <iostream>
36 #include <queue>
37 
38 #include "base/misc.hh"
39 #include "base/trace.hh"
40 #include "cpu/o3/comm.hh"
41 #include "cpu/o3/regfile.hh"
42 #include "debug/FreeList.hh"
43 
52 {
53  private:
54 
56  std::queue<PhysRegIndex> freeRegs;
57 
58  public:
59 
61 
63  void addReg(PhysRegIndex reg) { freeRegs.push(reg); }
64 
67  {
68  assert(!freeRegs.empty());
69  PhysRegIndex free_reg = freeRegs.front();
70  freeRegs.pop();
71  return free_reg;
72  }
73 
75  unsigned numFreeRegs() const { return freeRegs.size(); }
76 
78  bool hasFreeRegs() const { return !freeRegs.empty(); }
79 };
80 
81 
96 {
97  private:
98 
101  const std::string _name;
102 
105 
108 
111 
117 
118  /*
119  * We give UnifiedRenameMap internal access so it can get at the
120  * internal per-class free lists and associate those with its
121  * per-class rename maps. See UnifiedRenameMap::init().
122  */
123  friend class UnifiedRenameMap;
124 
125  public:
134  UnifiedFreeList(const std::string &_my_name, PhysRegFile *_regFile);
135 
137  std::string name() const { return _name; };
138 
141 
144 
147 
150 
152  void addReg(PhysRegIndex freed_reg);
153 
155  void addIntReg(PhysRegIndex freed_reg) { intList.addReg(freed_reg); }
156 
158  void addFloatReg(PhysRegIndex freed_reg) { floatList.addReg(freed_reg); }
159 
161  void addCCReg(PhysRegIndex freed_reg) { ccList.addReg(freed_reg); }
162 
164  bool hasFreeIntRegs() const { return intList.hasFreeRegs(); }
165 
167  bool hasFreeFloatRegs() const { return floatList.hasFreeRegs(); }
168 
170  bool hasFreeCCRegs() const { return ccList.hasFreeRegs(); }
171 
173  unsigned numFreeIntRegs() const { return intList.numFreeRegs(); }
174 
176  unsigned numFreeFloatRegs() const { return floatList.numFreeRegs(); }
177 
179  unsigned numFreeCCRegs() const { return ccList.numFreeRegs(); }
180 };
181 
182 inline void
184 {
185  DPRINTF(FreeList,"Freeing register %i.\n", freed_reg);
186  //Might want to add in a check for whether or not this register is
187  //already in there. A bit vector or something similar would be useful.
188  if (regFile->isIntPhysReg(freed_reg)) {
189  intList.addReg(freed_reg);
190  } else if (regFile->isFloatPhysReg(freed_reg)) {
191  floatList.addReg(freed_reg);
192  } else {
193  assert(regFile->isCCPhysReg(freed_reg));
194  ccList.addReg(freed_reg);
195  }
196 
197  // These assert conditions ensure that the number of free
198  // registers are not more than the # of total Physical Registers.
199  // If this were false, it would mean that registers
200  // have been freed twice, overflowing the free register
201  // pool and potentially crashing SMT workloads.
202  // ----
203  // Comment out for now so as to not potentially break
204  // CMP and single-threaded workloads
205  // ----
206  // assert(freeIntRegs.size() <= numPhysicalIntRegs);
207  // assert(freeFloatRegs.size() <= numPhysicalFloatRegs);
208 }
209 
210 
211 #endif // __CPU_O3_FREE_LIST_HH__
#define DPRINTF(x,...)
Definition: trace.hh:212
std::queue< PhysRegIndex > freeRegs
The actual free list.
Definition: free_list.hh:56
bool hasFreeIntRegs() const
Checks if there are any free integer registers.
Definition: free_list.hh:164
PhysRegIndex getCCReg()
Gets a free cc register.
Definition: free_list.hh:149
unsigned numFreeIntRegs() const
Returns the number of free integer registers.
Definition: free_list.hh:173
Bitfield< 5, 3 > reg
Definition: types.hh:89
std::string name() const
Gives the name of the freelist.
Definition: free_list.hh:137
SimpleFreeList floatList
The list of free floating point registers.
Definition: free_list.hh:107
Simple physical register file class.
Definition: regfile.hh:51
UnifiedFreeList(const std::string &_my_name, PhysRegFile *_regFile)
Constructs a free list.
Definition: free_list.cc:39
void addIntReg(PhysRegIndex freed_reg)
Adds an integer register back to the free list.
Definition: free_list.hh:155
bool hasFreeCCRegs() const
Checks if there are any free cc registers.
Definition: free_list.hh:170
void addReg(PhysRegIndex freed_reg)
Adds a register back to the free list.
Definition: free_list.hh:183
PhysRegIndex getIntReg()
Gets a free integer register.
Definition: free_list.hh:143
SimpleFreeList intList
The list of free integer registers.
Definition: free_list.hh:104
PhysRegIndex getReg()
Get the next available register from the free list.
Definition: free_list.hh:66
SimpleFreeList * getCCList()
Returns a pointer to the condition-code free list.
Definition: free_list.hh:140
unsigned numFreeRegs() const
Return the number of free registers on the list.
Definition: free_list.hh:75
Free list for a single class of registers (e.g., integer or floating point).
Definition: free_list.hh:51
Unified register rename map for all classes of registers.
Definition: rename_map.hh:159
PhysRegFile * regFile
The register file object is used only to distinguish integer from floating-point physical register in...
Definition: free_list.hh:116
bool isIntPhysReg(PhysRegIndex reg_idx) const
Definition: regfile.hh:134
const std::string _name
The object name, for DPRINTF.
Definition: free_list.hh:101
FreeList class that simply holds the list of free integer and floating point registers.
Definition: free_list.hh:95
SimpleFreeList ccList
The list of free condition-code registers.
Definition: free_list.hh:110
void addReg(PhysRegIndex reg)
Add a physical register to the free list.
Definition: free_list.hh:63
bool hasFreeFloatRegs() const
Checks if there are any free fp registers.
Definition: free_list.hh:167
unsigned numFreeFloatRegs() const
Returns the number of free fp registers.
Definition: free_list.hh:176
short int PhysRegIndex
Definition: comm.hh:57
bool isFloatPhysReg(PhysRegIndex reg_idx) const
Definition: regfile.hh:143
void addCCReg(PhysRegIndex freed_reg)
Adds a cc register back to the free list.
Definition: free_list.hh:161
bool hasFreeRegs() const
True iff there are free registers on the list.
Definition: free_list.hh:78
bool isCCPhysReg(PhysRegIndex reg_idx)
Return true if the specified physical register index corresponds to a condition-code physical registe...
Definition: regfile.hh:152
unsigned numFreeCCRegs() const
Returns the number of free cc registers.
Definition: free_list.hh:179
PhysRegIndex getFloatReg()
Gets a free fp register.
Definition: free_list.hh:146
void addFloatReg(PhysRegIndex freed_reg)
Adds a fp register back to the free list.
Definition: free_list.hh:158

Generated on Fri Jun 9 2017 13:03:43 for gem5 by doxygen 1.8.6