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

Side by Side Diff: runtime/vm/locations.h

Issue 10805053: Add spill slot locations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 months 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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_LOCATIONS_H_ 5 #ifndef VM_LOCATIONS_H_
6 #define VM_LOCATIONS_H_ 6 #define VM_LOCATIONS_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/bitfield.h" 10 #include "vm/bitfield.h"
11 11
12 namespace dart { 12 namespace dart {
13 13
14 class BufferFormatter; 14 class BufferFormatter;
15 15
16 // Location objects are used to connect register allocator and code generator. 16 // Location objects are used to connect register allocator and code generator.
17 // Instruction templates used by code generator have a corresponding 17 // Instruction templates used by code generator have a corresponding
18 // LocationSummary object which specifies expected location for every input 18 // LocationSummary object which specifies expected location for every input
19 // and output. 19 // and output.
20 // Each location is encoded as a single word: low 2 bits denote location kind, 20 // Each location is encoded as a single word: low 3 bits denote location kind,
Kevin Millikin (Google) 2012/07/23 12:52:30 Not entirely true: tag is variable sized (alternat
Vyacheslav Egorov (Google) 2012/07/23 14:06:10 Rephrased to make it more clear.
21 // rest is kind specific location payload e.g. for REGISTER kind payload is 21 // rest is kind specific location payload e.g. for REGISTER kind payload is
22 // register code (value of the Register enumeration). 22 // register code (value of the Register enumeration).
23 class Location : public ValueObject { 23 class Location : public ValueObject {
24 public: 24 public:
25 // Constant payload can overlap with kind field so Kind values 25 // Constant payload can overlap with kind field so Kind values
26 // have to be chosen in a way that their last 2 bits are never 26 // have to be chosen in a way that their last 2 bits are never
27 // the same as kConstant. 27 // the same as kConstant.
28 enum Kind { 28 enum Kind {
29 // This location is invalid. Payload must be zero.
29 kInvalid = 0, 30 kInvalid = 0,
30 31
32 // Constant value. This location contains a tagged Object handle.
31 kConstant = 1, 33 kConstant = 1,
32 34
33 // Unallocated location represents a location that is not fixed and can be 35 // Unallocated location represents a location that is not fixed and can be
34 // allocated by a register allocator. Each unallocated location has 36 // allocated by a register allocator. Each unallocated location has
35 // a policy that specifies what kind of location is suitable. 37 // a policy that specifies what kind of location is suitable. Payload
38 // contains register allocation policy.
36 kUnallocated = 2, 39 kUnallocated = 2,
37 40
38 // Register location represents a fixed register. 41 // Register location represents a fixed register. Payload contains
39 kRegister = 3 42 // register code.
43 kRegister = 3,
44
45 // Spill slot allocated by the register allocator. Payload contains
46 // a spill index.
47 kSpillSlot = 4
40 }; 48 };
41 49
42 static const uword kInvalidLocation = 0; 50 static const uword kInvalidLocation = 0;
43 static const uword kConstantMask = 0x3; 51 static const uword kConstantMask = 0x3;
44 52
45 Location() : value_(kInvalidLocation) { 53 Location() : value_(kInvalidLocation) {
46 ASSERT(IsInvalid()); 54 ASSERT(IsInvalid());
47 } 55 }
48 56
49 bool IsInvalid() const { 57 bool IsInvalid() const {
50 return value_ == kInvalidLocation; 58 return value_ == kInvalidLocation;
51 } 59 }
52 60
53 // Constants. 61 // Constants.
54 bool IsConstant() const { 62 bool IsConstant() const {
55 ASSERT((kConstant & kConstantMask) == kConstant); 63 ASSERT((kConstant & kConstantMask) == kConstant);
Kevin Millikin (Google) 2012/07/23 12:52:30 I wonder why we don't have STATIC_ASSERT. Here we
Vyacheslav Egorov (Google) 2012/07/23 14:06:10 (kind() == kConstant) <- this is incorrect.
56 return (value_ & kConstantMask) == kConstant; 64 return (value_ & kConstantMask) == kConstant;
57 } 65 }
58 66
59 static Location Constant(const Object& obj) { 67 static Location Constant(const Object& obj) {
60 Location loc(reinterpret_cast<uword>(&obj) | kConstant); 68 Location loc(reinterpret_cast<uword>(&obj) | kConstant);
61 ASSERT(&obj == &loc.constant()); 69 ASSERT(&obj == &loc.constant());
62 return loc; 70 return loc;
63 } 71 }
64 72
65 const Object& constant() const { 73 const Object& constant() const {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 117
110 bool IsRegister() const { 118 bool IsRegister() const {
111 return kind() == kRegister; 119 return kind() == kRegister;
112 } 120 }
113 121
114 Register reg() const { 122 Register reg() const {
115 ASSERT(IsRegister()); 123 ASSERT(IsRegister());
116 return static_cast<Register>(payload()); 124 return static_cast<Register>(payload());
117 } 125 }
118 126
127 // Spill slots.
128 static Location SpillSlot(intptr_t spill_index) {
129 return Location(kSpillSlot, static_cast<uword>(spill_index));
130 }
131
132 bool IsSpillSlot() const {
133 return kind() == kSpillSlot;
134 }
135
136 intptr_t spill_index() const {
137 ASSERT(IsSpillSlot());
138 return static_cast<uword>(payload());
Kevin Millikin (Google) 2012/07/23 12:52:30 payload() is a uword already.
Vyacheslav Egorov (Google) 2012/07/23 14:06:10 I guess I wanted cast to intptr_t
139 }
140
119 const char* Name() const; 141 const char* Name() const;
142 void PrintTo(BufferFormatter* f) const;
120 143
121 // Compare two non-constant locations. 144 // Compare two non-constant locations.
122 bool Equals(Location other) const { 145 bool Equals(Location other) const {
123 ASSERT(!IsConstant() && !other.IsConstant()); 146 ASSERT(!IsConstant() && !other.IsConstant());
124 return value_ == other.value_; 147 return value_ == other.value_;
125 } 148 }
126 149
127 private: 150 private:
128 explicit Location(uword value) : value_(value) { } 151 explicit Location(uword value) : value_(value) { }
129 152
130 Location(Kind kind, uword payload) 153 Location(Kind kind, uword payload)
131 : value_(KindField::encode(kind) | PayloadField::encode(payload)) { } 154 : value_(KindField::encode(kind) | PayloadField::encode(payload)) { }
132 155
133 uword payload() const { 156 uword payload() const {
134 return PayloadField::decode(value_); 157 return PayloadField::decode(value_);
135 } 158 }
136 159
137 // If current location is constant might return something that 160 // If current location is constant might return something that
138 // is not equal to any Kind. 161 // is not equal to any Kind.
139 Kind kind() const { 162 Kind kind() const {
140 return KindField::decode(value_); 163 return KindField::decode(value_);
141 } 164 }
142 165
143 typedef BitField<Kind, 0, 2> KindField; 166 typedef BitField<Kind, 0, 3> KindField;
144 typedef BitField<uword, 2, kWordSize * kBitsPerByte - 2> PayloadField; 167 typedef BitField<uword, 3, kWordSize * kBitsPerByte - 2> PayloadField;
145 168
146 // Layout for kUnallocated locations payload. 169 // Layout for kUnallocated locations payload.
147 typedef BitField<Policy, 0, 1> PolicyField; 170 typedef BitField<Policy, 0, 1> PolicyField;
148 171
149 // Location either contains kind and payload fields or a tagged handle for 172 // Location either contains kind and payload fields or a tagged handle for
150 // a constant locations. Values of enumeration Kind are selected in such a 173 // a constant locations. Values of enumeration Kind are selected in such a
151 // way that none of them can be interpreted as a kConstant tag. 174 // way that none of them can be interpreted as a kConstant tag.
152 uword value_; 175 uword value_;
153 }; 176 };
154 177
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 GrowableArray<Location> temp_locations_; 250 GrowableArray<Location> temp_locations_;
228 Location output_location_; 251 Location output_location_;
229 252
230 const bool is_call_; 253 const bool is_call_;
231 }; 254 };
232 255
233 256
234 } // namespace dart 257 } // namespace dart
235 258
236 #endif // VM_LOCATIONS_H_ 259 #endif // VM_LOCATIONS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698