Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Side by Side Diff: src/register-allocator-ia32.h

Issue 15037: Experimental: use the Result class to manage the lifetime of registers... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/toiger/
Patch Set: '' Created 12 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 14 matching lines...) Expand all
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #ifndef V8_REGISTER_ALLOCATOR_IA32_H_ 28 #ifndef V8_REGISTER_ALLOCATOR_IA32_H_
29 #define V8_REGISTER_ALLOCATOR_IA32_H_ 29 #define V8_REGISTER_ALLOCATOR_IA32_H_
30 30
31 #include "macro-assembler.h" 31 #include "macro-assembler.h"
32 32
33 namespace v8 { namespace internal { 33 namespace v8 { namespace internal {
34 34
35
36 // -------------------------------------------------------------------------
37 // Results
38 //
39 // Results encapsulate the compile-time values manipulated by the code
40 // generator. They can represent registers or constants.
41
42 class Result BASE_EMBEDDED {
43 public:
44 // Construct an invalid result.
45 explicit Result(CodeGenerator* cgen) : type_(INVALID), cgen_(cgen) {}
46
47 // Construct a register Result.
48 Result(Register reg, CodeGenerator* cgen);
49
50 // Construct a Result whose value is a compile-time constant.
51 Result(Handle<Object> value, CodeGenerator * cgen)
52 : type_(CONSTANT),
53 cgen_(cgen) {
54 data_.handle_ = value.location();
55 }
56
57 // The copy constructor and assignment operators could each create a new
58 // register reference.
59 Result(const Result& other) {
60 other.CopyTo(this);
61 }
62
63 Result& operator=(Result& other) {
64 if (this != &other) {
65 Unuse();
66 other.CopyTo(this);
67 other.Unuse();
68 }
69 return *this;
70 }
71
72 ~Result() { Unuse(); }
73
74 void Unuse();
75
76 bool is_valid() const { return type() != INVALID; }
77 bool is_register() const { return type() == REGISTER; }
78 bool is_constant() const { return type() == CONSTANT; }
79
80 Register reg() const {
81 ASSERT(type() == REGISTER);
82 return data_.reg_;
83 }
84
85 Handle<Object> handle() const {
86 ASSERT(type() == CONSTANT);
87 return Handle<Object>(data_.handle_);
88 }
89
90 // Change a result to a register result. If the result is not already
91 // in a register, allocate a register from the code generator, and emit
92 // code to move the value into that register.
93 void ToRegister();
94
William Hesse 2008/12/19 08:41:03 Do we also want ToRegister(Register target)?
Kevin Millikin (Chromium) 2008/12/19 08:48:11 Ultimately, yes. It was in a withdrawn change I s
95 private:
96 enum Type {
97 INVALID,
98 REGISTER,
99 CONSTANT
100 };
101
102 Type type_;
103
104 union {
105 Register reg_;
106 Object** handle_;
107 } data_;
108
109 CodeGenerator* cgen_;
110
111 Type type() const { return type_; }
112
113 void CopyTo(Result* destination) const;
114 };
115
116
35 // ------------------------------------------------------------------------- 117 // -------------------------------------------------------------------------
36 // Register file 118 // Register file
37 // 119 //
38 // The register file tracks reference counts for the processor registers. 120 // The register file tracks reference counts for the processor registers.
39 // It is used by both the register allocator and the virtual frame. 121 // It is used by both the register allocator and the virtual frame.
40 122
41 class RegisterFile BASE_EMBEDDED { 123 class RegisterFile BASE_EMBEDDED {
42 public: 124 public:
43 RegisterFile() { Reset(); } 125 RegisterFile() { Reset(); }
44 126
(...skipping 29 matching lines...) Expand all
74 int ref_counts_[kNumRegisters]; 156 int ref_counts_[kNumRegisters];
75 }; 157 };
76 158
77 159
78 // ------------------------------------------------------------------------- 160 // -------------------------------------------------------------------------
79 // Register allocator 161 // Register allocator
80 // 162 //
81 163
82 class RegisterAllocator BASE_EMBEDDED { 164 class RegisterAllocator BASE_EMBEDDED {
83 public: 165 public:
84 explicit RegisterAllocator(CodeGenerator* cgen) : code_generator_(cgen) {} 166 explicit RegisterAllocator(CodeGenerator* cgen) : cgen_(cgen) {}
85 167
86 int num_registers() const { return RegisterFile::kNumRegisters; } 168 int num_registers() const { return RegisterFile::kNumRegisters; }
87 169
170 // Predicates and accessors for the registers' reference counts.
171 bool is_used(int reg_code) const { return registers_.is_used(reg_code); }
88 int count(int reg_code) { return registers_.count(reg_code); } 172 int count(int reg_code) { return registers_.count(reg_code); }
89 173
90 // Explicitly record a reference to a register. 174 // Explicitly record a reference to a register.
91 void Use(Register reg) { registers_.Use(reg); } 175 void Use(Register reg) { registers_.Use(reg); }
92 176
93 // Explicitly record that a register will no longer be used. 177 // Explicitly record that a register will no longer be used.
94 void Unuse(Register reg) { registers_.Unuse(reg); } 178 void Unuse(Register reg) { registers_.Unuse(reg); }
95 179
96 // Initialize the register allocator for entry to a JS function. On 180 // Initialize the register allocator for entry to a JS function. On
97 // entry, esp, ebp, esi, and edi are externally referenced (ie, outside 181 // entry, esp, ebp, esi, and edi are externally referenced (ie, outside
98 // the virtual frame); and the other registers are free. 182 // the virtual frame); and the other registers are free.
99 void Initialize(); 183 void Initialize();
100 184
101 // Allocate a free register if possible or fail by returning no_reg. 185 // Allocate a free register and return a register result if possible or
102 Register Allocate(); 186 // fail and return an invalid result.
187 Result Allocate();
103 188
104 // Allocate a free register without spilling any or fail and return 189 // Allocate a free register without spilling any from the current frame or
105 // no_reg. 190 // fail and return an invalid result.
106 Register AllocateWithoutSpilling(); 191 Result AllocateWithoutSpilling();
107 192
108 private: 193 private:
109 CodeGenerator* code_generator_; 194 CodeGenerator* cgen_;
110 RegisterFile registers_; 195 RegisterFile registers_;
111 }; 196 };
112 197
113 } } // namespace v8::internal 198 } } // namespace v8::internal
114 199
115 #endif // V8_REGISTER_ALLOCATOR_IA32_H_ 200 #endif // V8_REGISTER_ALLOCATOR_IA32_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698