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::GetCallTarget() { | |
41 CHECK_EQ(kBuilding, state_); | |
42 | |
43 // For JS call descriptor, we can assume that the call target / 'this' pointer | |
Michael Starzinger
2015/12/02 19:28:06
We need to use internal nomenclature here, otherwi
vogelheim
2015/12/03 13:10:31
Done.
| |
44 // is parameter 0. If we use other call descriptors, this may or may not hold. | |
45 // So let's check. | |
46 CHECK(assembler_->call_descriptor()->IsJSFunctionCall()); | |
47 return FromRaw(assembler_->Parameter(0)); | |
48 } | |
49 | |
50 | |
51 FastAccessorAssembler::ValueId FastAccessorAssembler::GetInternalField( | |
Michael Starzinger
2015/12/02 19:28:06
nit: How would you feel about s/GetInternalField/L
vogelheim
2015/12/03 13:10:31
Done.
| |
52 ValueId value, int field_no) { | |
53 CHECK_EQ(kBuilding, state_); | |
54 return FromRaw(assembler_->Load( | |
55 kMachPtr, FromId(value), | |
56 assembler_->IntPtrConstant(JSObject::kHeaderSize - kHeapObjectTag + | |
Michael Starzinger
2015/12/02 19:28:06
This calculation is only correct for JSObject, for
vogelheim
2015/12/03 13:10:31
Changed to check for JSObject, and to return Undef
| |
57 kPointerSize * field_no))); | |
58 } | |
59 | |
60 | |
61 FastAccessorAssembler::ValueId FastAccessorAssembler::LoadValue( | |
62 FastAccessorAssembler::ValueId value, int offset) { | |
63 CHECK_EQ(kBuilding, state_); | |
64 return FromRaw(assembler_->Load(kMachIntPtr, FromId(value), | |
65 assembler_->IntPtrConstant(offset))); | |
66 } | |
67 | |
68 | |
69 FastAccessorAssembler::ValueId FastAccessorAssembler::LoadObject( | |
70 FastAccessorAssembler::ValueId value, int offset) { | |
71 CHECK_EQ(kBuilding, state_); | |
72 return FromRaw(assembler_->Load( | |
73 kMachAnyTagged, assembler_->Load(kMachPtr, FromId(value), | |
74 assembler_->IntPtrConstant(offset)))); | |
75 } | |
76 | |
77 | |
78 void FastAccessorAssembler::ReturnValue(ValueId value) { | |
79 CHECK_EQ(kBuilding, state_); | |
80 assembler_->Return(FromId(value)); | |
81 } | |
82 | |
83 | |
84 void FastAccessorAssembler::CheckFlagSetOrReturnNull( | |
85 FastAccessorAssembler::ValueId value, int mask) { | |
86 CHECK_EQ(kBuilding, state_); | |
87 RawMachineLabel pass, fail; | |
88 assembler_->Branch( | |
89 assembler_->Word32Equal( | |
90 assembler_->Word32And(FromId(value), assembler_->Int32Constant(mask)), | |
91 assembler_->Int32Constant(0)), | |
92 &pass, &fail); | |
93 assembler_->Bind(&fail); | |
94 assembler_->Return(assembler_->NullConstant()); | |
95 assembler_->Bind(&pass); | |
96 } | |
97 | |
98 | |
99 void FastAccessorAssembler::CheckNotNullOrReturnNull(ValueId value) { | |
Michael Starzinger
2015/12/02 19:28:06
One "null" is more "null" than the other "null" ..
vogelheim
2015/12/03 13:10:31
Done.
| |
100 CHECK_EQ(kBuilding, state_); | |
101 RawMachineLabel is_null, not_null; | |
102 assembler_->Branch( | |
103 assembler_->IntPtrEqual(FromId(value), assembler_->IntPtrConstant(0)), | |
104 &is_null, ¬_null); | |
105 assembler_->Bind(&is_null); | |
106 assembler_->Return(assembler_->NullConstant()); | |
107 assembler_->Bind(¬_null); | |
108 } | |
109 | |
110 | |
111 FastAccessorAssembler::LabelId FastAccessorAssembler::MakeLabel() { | |
112 CHECK_EQ(kBuilding, state_); | |
113 RawMachineLabel* label = new RawMachineLabel; | |
Michael Starzinger
2015/12/02 19:28:06
Can we allocate the Labels in our Zone please? Oth
vogelheim
2015/12/03 13:10:31
Done.
| |
114 return FromRaw(label); | |
115 } | |
116 | |
117 | |
118 void FastAccessorAssembler::SetLabel(LabelId label_id) { | |
119 CHECK_EQ(kBuilding, state_); | |
120 assembler_->Bind(FromId(label_id)); | |
121 } | |
122 | |
123 | |
124 void FastAccessorAssembler::CheckNotNullOrJump(ValueId value_id, | |
Michael Starzinger
2015/12/02 19:28:06
Likewise s/CheckNotNullOrJump/CheckNotZeroOrJump/
vogelheim
2015/12/03 13:10:31
Done.
| |
125 LabelId label_id) { | |
126 CHECK_EQ(kBuilding, state_); | |
127 RawMachineLabel pass; | |
128 assembler_->Branch( | |
129 assembler_->IntPtrEqual(FromId(value_id), assembler_->IntPtrConstant(0)), | |
130 &pass, FromId(label_id)); | |
131 assembler_->Bind(&pass); | |
132 } | |
133 | |
134 | |
135 MaybeHandle<Code> FastAccessorAssembler::Build() { | |
136 CHECK_EQ(kBuilding, state_); | |
137 | |
138 // Cleanup: We no longer need this. | |
139 nodes_.clear(); | |
140 for (auto label : labels_) { | |
141 delete label; | |
Michael Starzinger
2015/12/02 19:28:06
See comment above, please allocate in Zone and don
vogelheim
2015/12/03 13:10:31
Done.
| |
142 } | |
143 labels_.clear(); | |
144 | |
145 // Export the schedule and call the compiler. | |
146 CompilationInfo info("FastAccessorAssembler", assembler_->isolate(), zone()); | |
147 Schedule* schedule = assembler_->Export(); | |
148 MaybeHandle<Code> code = Pipeline::GenerateCodeForTesting( | |
Michael Starzinger
2015/12/02 19:28:06
This definitely needs a big fat TODO that we shoul
vogelheim
2015/12/03 13:10:31
Done.
| |
149 &info, assembler_->call_descriptor(), assembler_->graph(), schedule); | |
150 | |
151 // Update state & return. | |
152 state_ = !code.is_null() ? kBuilt : kError; | |
153 return code; | |
154 } | |
155 | |
156 | |
157 FastAccessorAssembler::ValueId FastAccessorAssembler::FromRaw(Node* node) { | |
158 nodes_.push_back(node); | |
159 ValueId value = {nodes_.size() - 1}; | |
160 return value; | |
161 } | |
162 | |
163 | |
164 FastAccessorAssembler::LabelId FastAccessorAssembler::FromRaw( | |
165 RawMachineLabel* label) { | |
166 labels_.push_back(label); | |
167 LabelId label_id = {labels_.size() - 1}; | |
168 return label_id; | |
169 } | |
170 | |
171 | |
172 Node* FastAccessorAssembler::FromId( | |
173 FastAccessorAssembler::ValueId value) const { | |
174 CHECK_LT(value.value_id, nodes_.size()); | |
175 CHECK_NOT_NULL(nodes_.at(value.value_id)); | |
176 return nodes_.at(value.value_id); | |
177 } | |
178 | |
179 | |
180 RawMachineLabel* FastAccessorAssembler::FromId( | |
181 FastAccessorAssembler::LabelId label) const { | |
182 CHECK_LT(label.label_id, labels_.size()); | |
183 CHECK_NOT_NULL(labels_.at(label.label_id)); | |
184 return labels_.at(label.label_id); | |
185 } | |
186 | |
187 | |
188 } // namespace compiler | |
189 } // namespace internal | |
190 } // namespace v8 | |
OLD | NEW |