gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
42#ifndef __CPU_O3_FREE_LIST_HH__
43#define __CPU_O3_FREE_LIST_HH__
44
45#include <algorithm>
46#include <array>
47#include <iostream>
48#include <queue>
49
50#include "base/logging.hh"
51#include "base/trace.hh"
52#include "cpu/o3/comm.hh"
53#include "cpu/o3/regfile.hh"
54#include "debug/FreeList.hh"
55
56namespace gem5
57{
58
59namespace o3
60{
61
62class UnifiedRenameMap;
63
72{
73 private:
74
76 std::queue<PhysRegIdPtr> freeRegs;
77
78 public:
79
81
84
86 template<class InputIt>
87 void
88 addRegs(InputIt first, InputIt last) {
89 std::for_each(first, last, [this](typename InputIt::value_type& reg) {
90 freeRegs.push(&reg);
91 });
92 }
93
96 {
97 assert(!freeRegs.empty());
98 PhysRegIdPtr free_reg = freeRegs.front();
99 freeRegs.pop();
100 return free_reg;
101 }
102
104 unsigned numFreeRegs() const { return freeRegs.size(); }
105
107 bool hasFreeRegs() const { return !freeRegs.empty(); }
108};
109
110
125{
126 private:
127
130 const std::string _name;
131
132 std::array<SimpleFreeList, CCRegClass + 1> freeLists;
133
139
140 /*
141 * We give UnifiedRenameMap internal access so it can get at the
142 * internal per-class free lists and associate those with its
143 * per-class rename maps. See UnifiedRenameMap::init().
144 */
145 friend class UnifiedRenameMap;
146
147 public:
156 UnifiedFreeList(const std::string &_my_name, PhysRegFile *_regFile);
157
159 std::string name() const { return _name; };
160
163
165 template<class InputIt>
166 void
167 addRegs(InputIt first, InputIt last)
168 {
169 std::for_each(first, last, [this](auto &reg) { addReg(&reg); });
170 }
171
173 void
175 {
176 freeLists[freed_reg->classValue()].addReg(freed_reg);
177 }
178
180 bool
182 {
183 return freeLists[type].hasFreeRegs();
184 }
185
187 unsigned
189 {
190 return freeLists[type].numFreeRegs();
191 }
192};
193
194} // namespace o3
195} // namespace gem5
196
197#endif // __CPU_O3_FREE_LIST_HH__
Physical register ID.
Definition reg_class.hh:415
constexpr RegClassType classValue() const
Definition reg_class.hh:280
Simple physical register file class.
Definition regfile.hh:66
Free list for a single class of registers (e.g., integer or floating point).
Definition free_list.hh:72
void addReg(PhysRegIdPtr reg)
Add a physical register to the free list.
Definition free_list.hh:83
std::queue< PhysRegIdPtr > freeRegs
The actual free list.
Definition free_list.hh:76
unsigned numFreeRegs() const
Return the number of free registers on the list.
Definition free_list.hh:104
PhysRegIdPtr getReg()
Get the next available register from the free list.
Definition free_list.hh:95
bool hasFreeRegs() const
True iff there are free registers on the list.
Definition free_list.hh:107
void addRegs(InputIt first, InputIt last)
Add physical registers to the free list.
Definition free_list.hh:88
FreeList class that simply holds the list of free integer and floating point registers.
Definition free_list.hh:125
std::array< SimpleFreeList, CCRegClass+1 > freeLists
Definition free_list.hh:132
std::string name() const
Gives the name of the freelist.
Definition free_list.hh:159
PhysRegFile * regFile
The register file object is used only to distinguish integer from floating-point physical register in...
Definition free_list.hh:138
UnifiedFreeList(const std::string &_my_name, PhysRegFile *_regFile)
Constructs a free list.
Definition free_list.cc:41
unsigned numFreeRegs(RegClassType type) const
Returns the number of free registers of type type.
Definition free_list.hh:188
PhysRegIdPtr getReg(RegClassType type)
Gets a free register of type type.
Definition free_list.hh:162
const std::string _name
The object name, for DPRINTF.
Definition free_list.hh:130
bool hasFreeRegs(RegClassType type) const
Checks if there are any free registers of type type.
Definition free_list.hh:181
void addRegs(InputIt first, InputIt last)
Adds a register back to the free list.
Definition free_list.hh:167
void addReg(PhysRegIdPtr freed_reg)
Adds a register back to the free list.
Definition free_list.hh:174
Unified register rename map for all classes of registers.
Bitfield< 5, 3 > reg
Definition types.hh:92
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
RegClassType
Enumerate the classes of registers.
Definition reg_class.hh:60

Generated on Tue Jun 18 2024 16:24:01 for gem5 by doxygen 1.11.0