| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 150 |
| 151 // Record that a register will no longer be used by decrementing its | 151 // Record that a register will no longer be used by decrementing its |
| 152 // reference count. | 152 // reference count. |
| 153 void Unuse(Register reg) { | 153 void Unuse(Register reg) { |
| 154 ASSERT(is_used(reg.code())); | 154 ASSERT(is_used(reg.code())); |
| 155 if (is_used(reg.code())) { | 155 if (is_used(reg.code())) { |
| 156 ref_counts_[reg.code()]--; | 156 ref_counts_[reg.code()]--; |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 // Copy the reference counts from this register file to the other. |
| 161 void CopyTo(RegisterFile* other); |
| 162 |
| 160 static const int kNumRegisters = 8; | 163 static const int kNumRegisters = 8; |
| 161 | 164 |
| 162 private: | 165 private: |
| 163 int ref_counts_[kNumRegisters]; | 166 int ref_counts_[kNumRegisters]; |
| 164 }; | 167 }; |
| 165 | 168 |
| 166 | 169 |
| 167 // ------------------------------------------------------------------------- | 170 // ------------------------------------------------------------------------- |
| 168 // Register allocator | 171 // Register allocator |
| 169 // | 172 // |
| (...skipping 14 matching lines...) Expand all Loading... |
| 184 void Use(Register reg) { registers_.Use(reg); } | 187 void Use(Register reg) { registers_.Use(reg); } |
| 185 | 188 |
| 186 // Explicitly record that a register will no longer be used. | 189 // Explicitly record that a register will no longer be used. |
| 187 void Unuse(Register reg) { registers_.Unuse(reg); } | 190 void Unuse(Register reg) { registers_.Unuse(reg); } |
| 188 | 191 |
| 189 // Initialize the register allocator for entry to a JS function. On | 192 // Initialize the register allocator for entry to a JS function. On |
| 190 // entry, esp, ebp, esi, and edi are externally referenced (ie, outside | 193 // entry, esp, ebp, esi, and edi are externally referenced (ie, outside |
| 191 // the virtual frame); and the other registers are free. | 194 // the virtual frame); and the other registers are free. |
| 192 void Initialize(); | 195 void Initialize(); |
| 193 | 196 |
| 197 // Reset the register reference counts to free all non-reserved registers. |
| 198 // A frame-external reference is kept to each of the reserved registers |
| 199 // (esp, ebp, and esi). |
| 200 void Reset(); |
| 201 |
| 194 // Allocate a free register and return a register result if possible or | 202 // Allocate a free register and return a register result if possible or |
| 195 // fail and return an invalid result. | 203 // fail and return an invalid result. |
| 196 Result Allocate(); | 204 Result Allocate(); |
| 197 | 205 |
| 198 // Allocate a specific register if possible, spilling it from the frame if | 206 // Allocate a specific register if possible, spilling it from the frame if |
| 199 // necessary, or else fail and return an invalid result. | 207 // necessary, or else fail and return an invalid result. |
| 200 Result Allocate(Register target); | 208 Result Allocate(Register target); |
| 201 | 209 |
| 202 // Allocate a free register without spilling any from the current frame or | 210 // Allocate a free register without spilling any from the current frame or |
| 203 // fail and return an invalid result. | 211 // fail and return an invalid result. |
| 204 Result AllocateWithoutSpilling(); | 212 Result AllocateWithoutSpilling(); |
| 205 | 213 |
| 214 // Copy the internal state to a register file, to be restored later by |
| 215 // RestoreFrom. |
| 216 void SaveTo(RegisterFile* register_file) { |
| 217 registers_.CopyTo(register_file); |
| 218 } |
| 219 |
| 220 void RestoreFrom(RegisterFile* register_file) { |
| 221 register_file->CopyTo(®isters_); |
| 222 } |
| 223 |
| 206 private: | 224 private: |
| 207 CodeGenerator* cgen_; | 225 CodeGenerator* cgen_; |
| 208 RegisterFile registers_; | 226 RegisterFile registers_; |
| 209 }; | 227 }; |
| 210 | 228 |
| 211 } } // namespace v8::internal | 229 } } // namespace v8::internal |
| 212 | 230 |
| 213 #endif // V8_REGISTER_ALLOCATOR_IA32_H_ | 231 #endif // V8_REGISTER_ALLOCATOR_IA32_H_ |
| OLD | NEW |