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

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

Issue 10382234: Introduce locations based code generation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: addressed Srdjan comments Created 8 years, 7 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #ifndef VM_LOCATIONS_H_
6 #define VM_LOCATIONS_H_
7
8 #include "vm/allocation.h"
9 #include "vm/assembler.h"
10 #include "vm/bitfield.h"
11
12 namespace dart {
13
14
15 class UnallocatedLocation;
16
17 // Location objects are used to connect register allocator and code generator.
18 // Instruction templates used by code generator have a corresponding
19 // LocationSummary object which specifies expected location for every input
20 // and output.
21 // Each location is encoded as a single word: low 2 bits denote location kind,
22 // rest is kind specific location payload (e.g. for REGISTER kind payload is
23 // register number).
srdjan 2012/05/21 16:05:22 What is register number? CPU register-number, for
Vyacheslav Egorov (Google) 2012/05/21 19:53:46 changed to register code and added reference to Re
24 class Location : public ValueObject {
25 public:
26 enum Kind {
27 kInvalid,
28 kUnallocated,
29 kRegister
30 };
31
32 Location() : value_(KindField::encode(kInvalid)) { }
33
34 Kind kind() const { return KindField::decode(value_); }
35
36 uword value() const { return value_; }
37
38 inline Register AsRegister() const;
39
40 protected:
41 explicit Location(uword value) : value_(value) { }
42
43 Location(Kind kind, uword payload)
44 : value_(KindField::encode(kind) | PayloadField::encode(payload)) { }
45
46 uword payload() const { return PayloadField::decode(value_); }
47
48 private:
49 typedef BitField<Kind, 0, 2> KindField;
50 typedef BitField<uword, 2, kWordSize * kBitsPerByte - 2> PayloadField;
51
52 uword value_;
Florian Schneider 2012/05/21 18:33:38 I think Location should be the same size on all pl
srdjan 2012/05/21 19:49:43 What is the advantage of having them the same size
Vyacheslav Egorov (Google) 2012/05/21 19:53:46 Added a TODO, we will select size once we know the
Vyacheslav Egorov (Google) 2012/05/21 19:53:46 Fixed size is less error prone (it is easier to re
53 };
54
55
56 // UnallocatedLocation represents a location that is not fixed and can be
57 // allocated by a register allocator. Each unallocated location has
58 // a policy that specifies what kind of location is suitable.
59 class UnallocatedLocation : public Location {
60 public:
61 enum Policy {
62 kRegister,
63 kSameAsFirstInput
64 };
65
66 explicit UnallocatedLocation(Policy policy)
67 : Location(kUnallocated, PolicyField::encode(policy)) {
68 }
69
70 Policy policy() { return PolicyField::decode(payload()); }
srdjan 2012/05/21 16:05:22 const?
Vyacheslav Egorov (Google) 2012/05/21 19:53:46 Done.
71
72 static UnallocatedLocation Cast(Location loc) {
73 ASSERT(loc.kind() == kUnallocated);
74 return UnallocatedLocation(loc.value());
75 }
76
77 // Any free register is suitable to replace this unallocated location.
78 static UnallocatedLocation Register() {
79 return UnallocatedLocation(kRegister);
80 }
81
82 // The location of the first input to the instruction will be
83 // used to replace this unallocated location.
84 static UnallocatedLocation SameAsFirstInput() {
85 return UnallocatedLocation(kSameAsFirstInput);
86 }
87
88 private:
89 explicit UnallocatedLocation(uword value) : Location(value) { }
90
91 typedef BitField<Policy, 0, 1> PolicyField;
92 };
93
94
95 // RegisterLocation represents a fixed register.
96 class RegisterLocation : public Location {
97 public:
98 explicit RegisterLocation(Register reg)
99 : Location(kRegister, reg) { }
100
101 Register reg() const {
102 return static_cast<Register>(payload());
103 }
104
105 static RegisterLocation Cast(Location loc) {
106 ASSERT(loc.kind() == kRegister);
107 return RegisterLocation(loc.value());
108 }
109
110 private:
111 explicit RegisterLocation(uword value) : Location(value) { }
112 };
113
114
115 // Specification of locations for inputs and output.
116 class LocationSummary : public ZoneAllocated {
117 public:
118 explicit LocationSummary(intptr_t count)
119 : input_locations_(count), output_location_() {
120 for (intptr_t i = 0; i < count; i++) {
121 input_locations_.Add(Location());
122 }
123 }
124
125 intptr_t count() const {
126 return input_locations_.length();
127 }
128
129 Location in(intptr_t index) const {
130 return input_locations_[index];
131 }
132
133 void set_in(intptr_t index, Location loc) {
134 input_locations_[index] = loc;
135 }
136
137 Location out() const {
138 return output_location_;
139 }
140
141 void set_out(Location loc) {
142 output_location_ = loc;
143 }
144
145 // Perform a greedy local register allocation. Consider all register free.
146 void AllocateRegisters();
147
148 private:
149 // TODO(vegorov): replace with ZoneArray.
150 ZoneGrowableArray<Location> input_locations_;
srdjan 2012/05/21 16:05:22 This is a value object -> GrowableArray instead o
Vyacheslav Egorov (Google) 2012/05/21 19:53:46 Done.
151 Location output_location_;
152 };
153
154
155 inline Register Location::AsRegister() const {
156 return RegisterLocation::Cast(*this).reg();
157 }
158
159
160 } // namespace dart
161
162 #endif // VM_LOCATIONS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698