gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
free_list.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2018 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2004-2005 The Regents of The University of Michigan
15  * Copyright (c) 2013 Advanced Micro Devices, Inc.
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions are
20  * met: redistributions of source code must retain the above copyright
21  * notice, this list of conditions and the following disclaimer;
22  * redistributions in binary form must reproduce the above copyright
23  * notice, this list of conditions and the following disclaimer in the
24  * documentation and/or other materials provided with the distribution;
25  * neither the name of the copyright holders nor the names of its
26  * contributors may be used to endorse or promote products derived from
27  * this software without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Authors: Kevin Lim
42  */
43 
44 #ifndef __CPU_O3_FREE_LIST_HH__
45 #define __CPU_O3_FREE_LIST_HH__
46 
47 #include <iostream>
48 #include <queue>
49 #include <vector>
50 
51 #include "base/logging.hh"
52 #include "base/trace.hh"
53 #include "cpu/o3/comm.hh"
54 #include "cpu/o3/regfile.hh"
55 #include "debug/FreeList.hh"
56 
65 {
66  private:
67 
69  std::queue<PhysRegIdPtr> freeRegs;
70 
71  public:
72 
74 
76  void addReg(PhysRegIdPtr reg) { freeRegs.push(reg); }
77 
79  template<class InputIt>
80  void
81  addRegs(InputIt first, InputIt last) {
82  std::for_each(first, last, [this](typename InputIt::value_type& reg) {
83  this->freeRegs.push(&reg);
84  });
85  }
86 
89  {
90  assert(!freeRegs.empty());
91  PhysRegIdPtr free_reg = freeRegs.front();
92  freeRegs.pop();
93  return free_reg;
94  }
95 
97  unsigned numFreeRegs() const { return freeRegs.size(); }
98 
100  bool hasFreeRegs() const { return !freeRegs.empty(); }
101 };
102 
103 
118 {
119  private:
120 
123  const std::string _name;
124 
127 
130 
135 
142 
145 
151 
152  /*
153  * We give UnifiedRenameMap internal access so it can get at the
154  * internal per-class free lists and associate those with its
155  * per-class rename maps. See UnifiedRenameMap::init().
156  */
157  friend class UnifiedRenameMap;
158 
159  public:
168  UnifiedFreeList(const std::string &_my_name, PhysRegFile *_regFile);
169 
171  std::string name() const { return _name; };
172 
174  SimpleFreeList *getCCList() { return &ccList; }
175 
177  PhysRegIdPtr getIntReg() { return intList.getReg(); }
178 
180  PhysRegIdPtr getFloatReg() { return floatList.getReg(); }
181 
183  PhysRegIdPtr getVecReg() { return vecList.getReg(); }
184 
186  PhysRegIdPtr getVecElem() { return vecElemList.getReg(); }
187 
189  PhysRegIdPtr getVecPredReg() { return predList.getReg(); }
190 
192  PhysRegIdPtr getCCReg() { return ccList.getReg(); }
193 
195  void addReg(PhysRegIdPtr freed_reg);
196 
198  template<class InputIt>
199  void addRegs(InputIt first, InputIt last);
200 
202  void addIntReg(PhysRegIdPtr freed_reg) { intList.addReg(freed_reg); }
203 
205  void addFloatReg(PhysRegIdPtr freed_reg) { floatList.addReg(freed_reg); }
206 
208  void addVecReg(PhysRegIdPtr freed_reg) { vecList.addReg(freed_reg); }
209 
211  void addVecElem(PhysRegIdPtr freed_reg) {
212  vecElemList.addReg(freed_reg);
213  }
214 
216  void addVecPredReg(PhysRegIdPtr freed_reg) { predList.addReg(freed_reg); }
217 
219  void addCCReg(PhysRegIdPtr freed_reg) { ccList.addReg(freed_reg); }
220 
222  bool hasFreeIntRegs() const { return intList.hasFreeRegs(); }
223 
225  bool hasFreeFloatRegs() const { return floatList.hasFreeRegs(); }
226 
228  bool hasFreeVecRegs() const { return vecList.hasFreeRegs(); }
229 
231  bool hasFreeVecElems() const { return vecElemList.hasFreeRegs(); }
232 
234  bool hasFreeVecPredRegs() const { return predList.hasFreeRegs(); }
235 
237  bool hasFreeCCRegs() const { return ccList.hasFreeRegs(); }
238 
240  unsigned numFreeIntRegs() const { return intList.numFreeRegs(); }
241 
243  unsigned numFreeFloatRegs() const { return floatList.numFreeRegs(); }
244 
246  unsigned numFreeVecRegs() const { return vecList.numFreeRegs(); }
247 
249  unsigned numFreeVecElems() const { return vecElemList.numFreeRegs(); }
250 
252  unsigned numFreeVecPredRegs() const { return predList.numFreeRegs(); }
253 
255  unsigned numFreeCCRegs() const { return ccList.numFreeRegs(); }
256 };
257 
258 template<class InputIt>
259 inline void
260 UnifiedFreeList::addRegs(InputIt first, InputIt last)
261 {
262  // Are there any registers to add?
263  if (first == last)
264  return;
265 
266  panic_if((first != last) &&
267  first->classValue() != (last-1)->classValue(),
268  "Attempt to add mixed type regs: %s and %s",
269  first->className(),
270  (last-1)->className());
271  switch (first->classValue()) {
272  case IntRegClass:
273  intList.addRegs(first, last);
274  break;
275  case FloatRegClass:
276  floatList.addRegs(first, last);
277  break;
278  case VecRegClass:
279  vecList.addRegs(first, last);
280  break;
281  case VecElemClass:
282  vecElemList.addRegs(first, last);
283  break;
284  case VecPredRegClass:
285  predList.addRegs(first, last);
286  break;
287  case CCRegClass:
288  ccList.addRegs(first, last);
289  break;
290  default:
291  panic("Unexpected RegClass (%s)",
292  first->className());
293  }
294 
295 }
296 
297 inline void
299 {
300  DPRINTF(FreeList,"Freeing register %i (%s).\n", freed_reg->index(),
301  freed_reg->className());
302  //Might want to add in a check for whether or not this register is
303  //already in there. A bit vector or something similar would be useful.
304  switch (freed_reg->classValue()) {
305  case IntRegClass:
306  intList.addReg(freed_reg);
307  break;
308  case FloatRegClass:
309  floatList.addReg(freed_reg);
310  break;
311  case VecRegClass:
312  vecList.addReg(freed_reg);
313  break;
314  case VecElemClass:
315  vecElemList.addReg(freed_reg);
316  break;
317  case VecPredRegClass:
318  predList.addReg(freed_reg);
319  break;
320  case CCRegClass:
321  ccList.addReg(freed_reg);
322  break;
323  default:
324  panic("Unexpected RegClass (%s)",
325  freed_reg->className());
326  }
327 
328  // These assert conditions ensure that the number of free
329  // registers are not more than the # of total Physical Registers.
330  // If this were false, it would mean that registers
331  // have been freed twice, overflowing the free register
332  // pool and potentially crashing SMT workloads.
333  // ----
334  // Comment out for now so as to not potentially break
335  // CMP and single-threaded workloads
336  // ----
337  // assert(freeIntRegs.size() <= numPhysicalIntRegs);
338  // assert(freeFloatRegs.size() <= numPhysicalFloatRegs);
339 }
340 
341 
342 #endif // __CPU_O3_FREE_LIST_HH__
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
#define DPRINTF(x,...)
Definition: trace.hh:229
SimpleFreeList predList
The list of free predicate registers.
Definition: free_list.hh:141
std::queue< PhysRegIdPtr > freeRegs
The actual free list.
Definition: free_list.hh:69
Bitfield< 5, 3 > reg
Definition: types.hh:89
SimpleFreeList floatList
The list of free floating point registers.
Definition: free_list.hh:129
Floating-point register.
Definition: reg_class.hh:58
bool hasFreeRegs() const
True iff there are free registers on the list.
Definition: free_list.hh:100
Simple physical register file class.
Definition: regfile.hh:63
std::string name() const
Gives the name of the freelist.
Definition: free_list.hh:171
bool hasFreeVecRegs() const
Checks if there are any free vector registers.
Definition: free_list.hh:228
SimpleFreeList intList
The list of free integer registers.
Definition: free_list.hh:126
PhysRegIdPtr getIntReg()
Gets a free integer register.
Definition: free_list.hh:177
unsigned numFreeVecRegs() const
Returns the number of free vector registers.
Definition: free_list.hh:246
PhysRegIdPtr getCCReg()
Gets a free cc register.
Definition: free_list.hh:192
bool hasFreeCCRegs() const
Checks if there are any free cc registers.
Definition: free_list.hh:237
SimpleFreeList * getCCList()
Returns a pointer to the condition-code free list.
Definition: free_list.hh:174
SimpleFreeList vecList
The following two are exclusive interfaces.
Definition: free_list.hh:134
bool hasFreeFloatRegs() const
Checks if there are any free fp registers.
Definition: free_list.hh:225
Free list for a single class of registers (e.g., integer or floating point).
Definition: free_list.hh:64
Vector Register Native Elem lane.
Definition: reg_class.hh:62
void addReg(PhysRegIdPtr freed_reg)
Adds a register back to the free list.
Definition: free_list.hh:298
void addRegs(InputIt first, InputIt last)
Adds a register back to the free list.
Definition: free_list.hh:260
PhysRegIdPtr getVecReg()
Gets a free vector register.
Definition: free_list.hh:183
void addVecElem(PhysRegIdPtr freed_reg)
Adds a vector element register back to the free list.
Definition: free_list.hh:211
void addRegs(InputIt first, InputIt last)
Add physical registers to the free list.
Definition: free_list.hh:81
void addCCReg(PhysRegIdPtr freed_reg)
Adds a cc register back to the free list.
Definition: free_list.hh:219
Condition-code register.
Definition: reg_class.hh:64
Unified register rename map for all classes of registers.
Definition: rename_map.hh:170
void addFloatReg(PhysRegIdPtr freed_reg)
Adds a fp register back to the free list.
Definition: free_list.hh:205
PhysRegFile * regFile
The register file object is used only to distinguish integer from floating-point physical register in...
Definition: free_list.hh:150
bool hasFreeIntRegs() const
Checks if there are any free integer registers.
Definition: free_list.hh:222
void addIntReg(PhysRegIdPtr freed_reg)
Adds an integer register back to the free list.
Definition: free_list.hh:202
PhysRegIdPtr getVecElem()
Gets a free vector elemenet register.
Definition: free_list.hh:186
SimpleFreeList vecElemList
The list of free vector element registers.
Definition: free_list.hh:137
void addReg(PhysRegIdPtr reg)
Add a physical register to the free list.
Definition: free_list.hh:76
unsigned numFreeRegs() const
Return the number of free registers on the list.
Definition: free_list.hh:97
unsigned numFreeCCRegs() const
Returns the number of free cc registers.
Definition: free_list.hh:255
const std::string _name
The object name, for DPRINTF.
Definition: free_list.hh:123
bool hasFreeVecPredRegs() const
Checks if there are any free predicate registers.
Definition: free_list.hh:234
unsigned numFreeFloatRegs() const
Returns the number of free fp registers.
Definition: free_list.hh:243
FreeList class that simply holds the list of free integer and floating point registers.
Definition: free_list.hh:117
SimpleFreeList ccList
The list of free condition-code registers.
Definition: free_list.hh:144
Physical register ID.
Definition: reg_class.hh:229
PhysRegIdPtr getFloatReg()
Gets a free fp register.
Definition: free_list.hh:180
const RegClass & classValue() const
Class accessor.
Definition: reg_class.hh:206
unsigned numFreeIntRegs() const
Returns the number of free integer registers.
Definition: free_list.hh:240
unsigned numFreeVecPredRegs() const
Returns the number of free predicate registers.
Definition: free_list.hh:252
const RegIndex & index() const
Index accessors.
Definition: reg_class.hh:179
Integer register.
Definition: reg_class.hh:57
Vector Register.
Definition: reg_class.hh:60
PhysRegIdPtr getReg()
Get the next available register from the free list.
Definition: free_list.hh:88
unsigned numFreeVecElems() const
Returns the number of free vector registers.
Definition: free_list.hh:249
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:185
bool hasFreeVecElems() const
Checks if there are any free vector registers.
Definition: free_list.hh:231
PhysRegIdPtr getVecPredReg()
Gets a free predicate register.
Definition: free_list.hh:189
void addVecReg(PhysRegIdPtr freed_reg)
Adds a vector register back to the free list.
Definition: free_list.hh:208
const char * className() const
Return a const char* with the register class name.
Definition: reg_class.hh:208
void addVecPredReg(PhysRegIdPtr freed_reg)
Adds a predicate register back to the free list.
Definition: free_list.hh:216

Generated on Fri Feb 28 2020 16:26:59 for gem5 by doxygen 1.8.13