gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rename_map.cc
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 #include "cpu/o3/rename_map.hh"
33 
34 #include <vector>
35 
36 #include "debug/Rename.hh"
37 
38 using namespace std;
39 
40 /**** SimpleRenameMap methods ****/
41 
43  : freeList(NULL), zeroReg(0)
44 {
45 }
46 
47 
48 void
50  RegIndex _zeroReg)
51 {
52  assert(freeList == NULL);
53  assert(map.empty());
54 
55  map.resize(size);
56  freeList = _freeList;
57  zeroReg = _zeroReg;
58 }
59 
62 {
63  PhysRegIndex renamed_reg;
64 
65  // Record the current physical register that is renamed to the
66  // requested architected register.
67  PhysRegIndex prev_reg = map[arch_reg];
68 
69  // If it's not referencing the zero register, then rename the
70  // register.
71  if (arch_reg != zeroReg) {
72  renamed_reg = freeList->getReg();
73 
74  map[arch_reg] = renamed_reg;
75  } else {
76  // Otherwise return the zero register so nothing bad happens.
77  assert(prev_reg == zeroReg);
78  renamed_reg = zeroReg;
79  }
80 
81  DPRINTF(Rename, "Renamed reg %d to physical reg %d old mapping was %d\n",
82  arch_reg, renamed_reg, prev_reg);
83 
84  return RenameInfo(renamed_reg, prev_reg);
85 }
86 
87 
88 /**** UnifiedRenameMap methods ****/
89 
90 void
92  RegIndex _intZeroReg,
93  RegIndex _floatZeroReg,
94  UnifiedFreeList *freeList)
95 {
96  regFile = _regFile;
97 
98  intMap.init(TheISA::NumIntRegs, &(freeList->intList), _intZeroReg);
99 
100  floatMap.init(TheISA::NumFloatRegs, &(freeList->floatList), _floatZeroReg);
101 
102  ccMap.init(TheISA::NumCCRegs, &(freeList->ccList), (RegIndex)-1);
103 }
104 
105 
108 {
109  RegIndex rel_arch_reg;
110 
111  switch (regIdxToClass(arch_reg, &rel_arch_reg)) {
112  case IntRegClass:
113  return renameInt(rel_arch_reg);
114 
115  case FloatRegClass:
116  return renameFloat(rel_arch_reg);
117 
118  case CCRegClass:
119  return renameCC(rel_arch_reg);
120 
121  case MiscRegClass:
122  return renameMisc(rel_arch_reg);
123 
124  default:
125  panic("rename rename(): unknown reg class %s\n",
126  RegClassStrings[regIdxToClass(arch_reg)]);
127  }
128 }
129 
130 
133 {
134  RegIndex rel_arch_reg;
135 
136  switch (regIdxToClass(arch_reg, &rel_arch_reg)) {
137  case IntRegClass:
138  return lookupInt(rel_arch_reg);
139 
140  case FloatRegClass:
141  return lookupFloat(rel_arch_reg);
142 
143  case CCRegClass:
144  return lookupCC(rel_arch_reg);
145 
146  case MiscRegClass:
147  return lookupMisc(rel_arch_reg);
148 
149  default:
150  panic("rename lookup(): unknown reg class %s\n",
151  RegClassStrings[regIdxToClass(arch_reg)]);
152  }
153 }
154 
155 void
157 {
158  RegIndex rel_arch_reg;
159 
160  switch (regIdxToClass(arch_reg, &rel_arch_reg)) {
161  case IntRegClass:
162  return setIntEntry(rel_arch_reg, phys_reg);
163 
164  case FloatRegClass:
165  return setFloatEntry(rel_arch_reg, phys_reg);
166 
167  case CCRegClass:
168  return setCCEntry(rel_arch_reg, phys_reg);
169 
170  case MiscRegClass:
171  // Misc registers do not actually rename, so don't change
172  // their mappings. We end up here when a commit or squash
173  // tries to update or undo a hardwired misc reg nmapping,
174  // which should always be setting it to what it already is.
175  assert(phys_reg == lookupMisc(rel_arch_reg));
176  return;
177 
178  default:
179  panic("rename setEntry(): unknown reg class %s\n",
180  RegClassStrings[regIdxToClass(arch_reg)]);
181  }
182 }
#define DPRINTF(x,...)
Definition: trace.hh:212
PhysRegIndex lookup(RegIndex arch_reg) const
Look up the physical register mapped to an architectural register.
Definition: rename_map.cc:132
SimpleFreeList floatList
The list of free floating point registers.
Definition: free_list.hh:107
Floating-point register.
Definition: reg_class.hh:43
RenameInfo rename(RegIndex arch_reg)
Tell rename map to get a new free physical register to remap the specified architectural register...
Definition: rename_map.cc:107
STL pair class.
Definition: stl.hh:61
#define panic(...)
Definition: misc.hh:153
Simple physical register file class.
Definition: regfile.hh:51
Control (misc) register.
Definition: reg_class.hh:45
RenameInfo renameFloat(RegIndex rel_arch_reg)
Perform rename() on a floating-point register, given a relative floating-point register index...
Definition: rename_map.hh:224
void setEntry(RegIndex arch_reg, PhysRegIndex phys_reg)
Update rename map with a specific mapping.
Definition: rename_map.cc:156
SimpleRenameMap ccMap
The condition-code register rename map.
Definition: rename_map.hh:179
const int NumFloatRegs
Definition: registers.hh:96
void setIntEntry(RegIndex arch_reg, PhysRegIndex phys_reg)
Perform setEntry() on an integer register, given a relative integer register index.
Definition: rename_map.hh:325
SimpleFreeList intList
The list of free integer registers.
Definition: free_list.hh:104
SimpleRenameMap floatMap
The floating-point register rename map.
Definition: rename_map.hh:167
RenameInfo renameInt(RegIndex rel_arch_reg)
Perform rename() on an integer register, given a relative integer register index. ...
Definition: rename_map.hh:213
RenameInfo renameCC(RegIndex rel_arch_reg)
Perform rename() on a condition-code register, given a relative condition-code register index...
Definition: rename_map.hh:235
PhysRegIndex getReg()
Get the next available register from the free list.
Definition: free_list.hh:66
RegIndex zeroReg
The architectural index of the zero register.
Definition: rename_map.hh:93
std::vector< PhysRegIndex > map
The acutal arch-to-phys register map.
Definition: rename_map.hh:78
Free list for a single class of registers (e.g., integer or floating point).
Definition: free_list.hh:51
RenameInfo renameMisc(RegIndex rel_arch_reg)
Perform rename() on a misc register, given a relative misc register index.
Definition: rename_map.hh:246
TheISA::RegIndex RegIndex
Definition: rename_map.hh:182
PhysRegIndex lookupMisc(RegIndex rel_arch_reg) const
Perform lookup() on a misc register, given a relative misc register index.
Definition: rename_map.hh:303
PhysRegIndex lookupFloat(RegIndex rel_arch_reg) const
Perform lookup() on a floating-point register, given a relative floating-point register index...
Definition: rename_map.hh:281
void setCCEntry(RegIndex arch_reg, PhysRegIndex phys_reg)
Perform setEntry() on a condition-code register, given a relative condition-code register index...
Definition: rename_map.hh:345
const int NumCCRegs
Definition: registers.hh:97
PhysRegIndex lookupInt(RegIndex rel_arch_reg) const
Perform lookup() on an integer register, given a relative integer register index. ...
Definition: rename_map.hh:270
Condition-code register.
Definition: reg_class.hh:44
SimpleRenameMap intMap
The integer register rename map.
Definition: rename_map.hh:164
PhysRegIndex lookupCC(RegIndex rel_arch_reg) const
Perform lookup() on a condition-code register, given a relative condition-code register index...
Definition: rename_map.hh:292
PhysRegFile * regFile
The register file object is used only to distinguish integer from floating-point physical register in...
Definition: rename_map.hh:176
SimpleFreeList * freeList
Pointer to the free list from which new physical registers should be allocated in rename() ...
Definition: rename_map.hh:84
RenameInfo rename(RegIndex arch_reg)
Tell rename map to get a new free physical register to remap the specified architectural register...
Definition: rename_map.cc:61
void init(unsigned size, SimpleFreeList *_freeList, RegIndex _zeroReg)
Because we have an array of rename maps (one per thread) in the CPU, it's awkward to initialize this ...
Definition: rename_map.cc:49
TheISA::RegIndex RegIndex
Definition: rename_map.hh:73
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
const char * RegClassStrings[]
Map enum values to strings for debugging.
Definition: reg_class.cc:33
int size()
Definition: pagetable.hh:146
std::pair< PhysRegIndex, PhysRegIndex > RenameInfo
Pair of a physical register and a physical register.
Definition: rename_map.hh:114
short int PhysRegIndex
Definition: comm.hh:57
void setFloatEntry(RegIndex arch_reg, PhysRegIndex phys_reg)
Perform setEntry() on a floating-point register, given a relative floating-point register index...
Definition: rename_map.hh:335
Integer register.
Definition: reg_class.hh:42
RegClass regIdxToClass(TheISA::RegIndex reg_idx, TheISA::RegIndex *rel_reg_idx=NULL)
Map a 'unified' architectural register index to its register class.
Definition: reg_class.hh:66
const int NumIntRegs
Definition: registers.hh:95
void init(PhysRegFile *_regFile, RegIndex _intZeroReg, RegIndex _floatZeroReg, UnifiedFreeList *freeList)
Initializes rename map with given parameters.
Definition: rename_map.cc:91

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