OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "src/compiler/fast-accessor-assembler.h" | |
6 | |
7 #include "src/base/logging.h" | |
8 #include "src/compiler/graph.h" | |
9 #include "src/compiler/linkage.h" | |
10 #include "src/compiler/pipeline.h" | |
11 #include "src/compiler/raw-machine-assembler.h" | |
12 #include "src/compiler/schedule.h" | |
13 #include "src/compiler/verifier.h" | |
14 #include "src/handles-inl.h" | |
15 #include "src/objects.h" // For FAA::GetInternalField impl. | |
16 | |
17 namespace v8 { | |
18 namespace internal { | |
19 namespace compiler { | |
20 | |
21 FastAccessorAssembler::FastAccessorAssembler(Isolate* isolate) | |
22 : zone_(), | |
23 assembler_(new RawMachineAssembler( | |
24 isolate, new (zone()) Graph(zone()), | |
25 Linkage::GetJSCallDescriptor(&zone_, false, 1, | |
26 CallDescriptor::kNoFlags))), | |
27 state_(kBuilding) {} | |
28 | |
29 | |
30 FastAccessorAssembler::~FastAccessorAssembler() {} | |
31 | |
32 | |
33 FastAccessorAssembler::ValueId FastAccessorAssembler::IntegerConstant( | |
34 int const_value) { | |
35 CHECK_EQ(kBuilding, state_); | |
36 return FromRaw(assembler_->NumberConstant(const_value)); | |
37 } | |
38 | |
39 | |
40 FastAccessorAssembler::ValueId FastAccessorAssembler::GetReceiver() { | |
41 CHECK_EQ(kBuilding, state_); | |
42 | |
43 // For JS call descriptor, the receiver is parameter 0. If we use other | |
44 // call descriptors, this may or may not hold. So let's check. | |
45 CHECK(assembler_->call_descriptor()->IsJSFunctionCall()); | |
46 return FromRaw(assembler_->Parameter(0)); | |
47 } | |
48 | |
49 | |
50 FastAccessorAssembler::ValueId FastAccessorAssembler::LoadInternalField( | |
51 ValueId value, int field_no) { | |
52 CHECK_EQ(kBuilding, state_); | |
53 // Determine the 'value' object's instance type. | |
54 Node* object_map = | |
55 assembler_->Load(kMachPtr, FromId(value), | |
56 assembler_->IntPtrConstant( | |
57 Internals::kHeapObjectMapOffset - kHeapObjectTag)); | |
58 Node* instance_type = assembler_->WordAnd( | |
59 assembler_->Load( | |
60 kMachUint16, object_map, | |
61 assembler_->IntPtrConstant( | |
62 Internals::kMapInstanceTypeAndBitFieldOffset - kHeapObjectTag)), | |
63 assembler_->IntPtrConstant(0xff)); | |
64 | |
65 // Check whether we have a proper JSObject. | |
66 RawMachineLabel is_jsobject, is_not_jsobject, merge; | |
67 assembler_->Branch( | |
68 assembler_->WordEqual( | |
69 instance_type, assembler_->IntPtrConstant(Internals::kJSObjectType)), | |
70 &is_jsobject, &is_not_jsobject); | |
71 | |
72 // JSObject? Then load the internal field field_no. | |
73 assembler_->Bind(&is_jsobject); | |
74 Node* internal_field = assembler_->Load( | |
75 kMachPtr, FromId(value), | |
76 assembler_->IntPtrConstant(JSObject::kHeaderSize - kHeapObjectTag + | |
77 kPointerSize * field_no)); | |
78 assembler_->Goto(&merge); | |
79 | |
80 // No JSObject? Return undefined. | |
81 // TODO(vogelheim): Check whether this is the appropriate action, or whether | |
82 // the method should take a label instead. | |
83 assembler_->Bind(&is_not_jsobject); | |
84 Node* fail_value = assembler_->UndefinedConstant(); | |
85 assembler_->Goto(&merge); | |
86 | |
87 // Return. | |
88 assembler_->Bind(&merge); | |
89 Node* phi = assembler_->Phi(kMachAnyTagged, internal_field, fail_value); | |
90 return FromRaw(phi); | |
91 } | |
92 | |
93 | |
94 FastAccessorAssembler::ValueId FastAccessorAssembler::LoadValue( | |
95 FastAccessorAssembler::ValueId value, int offset) { | |
epertoso
2015/12/04 09:56:32
Qualifying ValueId here and below is not necessary
vogelheim
2015/12/08 12:52:56
Done.
| |
96 CHECK_EQ(kBuilding, state_); | |
97 return FromRaw(assembler_->Load(kMachIntPtr, FromId(value), | |
98 assembler_->IntPtrConstant(offset))); | |
99 } | |
100 | |
101 | |
102 FastAccessorAssembler::ValueId FastAccessorAssembler::LoadObject( | |
103 FastAccessorAssembler::ValueId value, int offset) { | |
104 CHECK_EQ(kBuilding, state_); | |
105 return FromRaw(assembler_->Load( | |
106 kMachAnyTagged, assembler_->Load(kMachPtr, FromId(value), | |
107 assembler_->IntPtrConstant(offset)))); | |
108 } | |
109 | |
110 | |
111 void FastAccessorAssembler::ReturnValue(ValueId value) { | |
112 CHECK_EQ(kBuilding, state_); | |
113 assembler_->Return(FromId(value)); | |
114 } | |
115 | |
116 | |
117 void FastAccessorAssembler::CheckFlagSetOrReturnNull( | |
118 FastAccessorAssembler::ValueId value, int mask) { | |
119 CHECK_EQ(kBuilding, state_); | |
120 RawMachineLabel pass, fail; | |
121 assembler_->Branch( | |
122 assembler_->Word32Equal( | |
123 assembler_->Word32And(FromId(value), assembler_->Int32Constant(mask)), | |
124 assembler_->Int32Constant(0)), | |
125 &pass, &fail); | |
126 assembler_->Bind(&fail); | |
127 assembler_->Return(assembler_->NullConstant()); | |
128 assembler_->Bind(&pass); | |
129 } | |
130 | |
131 | |
132 void FastAccessorAssembler::CheckNotZeroOrReturnNull(ValueId value) { | |
133 CHECK_EQ(kBuilding, state_); | |
134 RawMachineLabel is_null, not_null; | |
135 assembler_->Branch( | |
136 assembler_->IntPtrEqual(FromId(value), assembler_->IntPtrConstant(0)), | |
137 &is_null, ¬_null); | |
138 assembler_->Bind(&is_null); | |
139 assembler_->Return(assembler_->NullConstant()); | |
140 assembler_->Bind(¬_null); | |
141 } | |
142 | |
143 | |
144 FastAccessorAssembler::LabelId FastAccessorAssembler::MakeLabel() { | |
145 CHECK_EQ(kBuilding, state_); | |
146 RawMachineLabel* label = | |
147 new (zone()->New(sizeof(RawMachineLabel))) RawMachineLabel; | |
148 return FromRaw(label); | |
149 } | |
150 | |
151 | |
152 void FastAccessorAssembler::SetLabel(LabelId label_id) { | |
153 CHECK_EQ(kBuilding, state_); | |
154 assembler_->Bind(FromId(label_id)); | |
155 } | |
156 | |
157 | |
158 void FastAccessorAssembler::CheckNotZeroOrJump(ValueId value_id, | |
159 LabelId label_id) { | |
160 CHECK_EQ(kBuilding, state_); | |
161 RawMachineLabel pass; | |
162 assembler_->Branch( | |
163 assembler_->IntPtrEqual(FromId(value_id), assembler_->IntPtrConstant(0)), | |
164 &pass, FromId(label_id)); | |
165 assembler_->Bind(&pass); | |
166 } | |
167 | |
168 | |
169 MaybeHandle<Code> FastAccessorAssembler::Build() { | |
170 CHECK_EQ(kBuilding, state_); | |
171 | |
172 // Cleanup: We no longer need this. | |
173 nodes_.clear(); | |
174 labels_.clear(); | |
175 | |
176 // Export the schedule and call the compiler. | |
177 CompilationInfo info("FastAccessorAssembler", assembler_->isolate(), zone()); | |
178 Schedule* schedule = assembler_->Export(); | |
179 | |
180 // TODO(vogelheim): Pipeline should have a dedicated entry point for this | |
181 // assembler. | |
182 MaybeHandle<Code> code = Pipeline::GenerateCodeForTesting( | |
183 &info, assembler_->call_descriptor(), assembler_->graph(), schedule); | |
184 | |
185 // Update state & return. | |
186 state_ = !code.is_null() ? kBuilt : kError; | |
187 return code; | |
188 } | |
189 | |
190 | |
191 FastAccessorAssembler::ValueId FastAccessorAssembler::FromRaw(Node* node) { | |
192 nodes_.push_back(node); | |
193 ValueId value = {nodes_.size() - 1}; | |
194 return value; | |
195 } | |
196 | |
197 | |
198 FastAccessorAssembler::LabelId FastAccessorAssembler::FromRaw( | |
199 RawMachineLabel* label) { | |
200 labels_.push_back(label); | |
201 LabelId label_id = {labels_.size() - 1}; | |
202 return label_id; | |
203 } | |
204 | |
205 | |
206 Node* FastAccessorAssembler::FromId(ValueId value) const { | |
207 CHECK_LT(value.value_id, nodes_.size()); | |
208 CHECK_NOT_NULL(nodes_.at(value.value_id)); | |
209 return nodes_.at(value.value_id); | |
210 } | |
211 | |
212 | |
213 RawMachineLabel* FastAccessorAssembler::FromId(LabelId label) const { | |
214 CHECK_LT(label.label_id, labels_.size()); | |
215 CHECK_NOT_NULL(labels_.at(label.label_id)); | |
216 return labels_.at(label.label_id); | |
217 } | |
218 | |
219 | |
220 } // namespace compiler | |
221 } // namespace internal | |
222 } // namespace v8 | |
OLD | NEW |