yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
| 30 | #include "code-stubs.h" |
| 31 | #include "hydrogen.h" |
| 32 | #include "lithium.h" |
| 33 | |
| 34 | namespace v8 { |
| 35 | namespace internal { |
| 36 | |
| 37 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 38 | static LChunk* OptimizeGraph(HGraph* graph) { |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 39 | DisallowHeapAllocation no_allocation; |
| 40 | DisallowHandleAllocation no_handles; |
| 41 | DisallowHandleDereference no_deref; |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 42 | |
| 43 | ASSERT(graph != NULL); |
| 44 | SmartArrayPointer<char> bailout_reason; |
| 45 | if (!graph->Optimize(&bailout_reason)) { |
| 46 | FATAL(bailout_reason.is_empty() ? "unknown" : *bailout_reason); |
| 47 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 48 | LChunk* chunk = LChunk::NewChunk(graph); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 49 | if (chunk == NULL) { |
| 50 | FATAL(graph->info()->bailout_reason()); |
| 51 | } |
| 52 | return chunk; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | |
| 56 | class CodeStubGraphBuilderBase : public HGraphBuilder { |
| 57 | public: |
| 58 | CodeStubGraphBuilderBase(Isolate* isolate, HydrogenCodeStub* stub) |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 59 | : HGraphBuilder(&info_), |
| 60 | arguments_length_(NULL), |
| 61 | info_(stub, isolate), |
| 62 | context_(NULL) { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 63 | descriptor_ = stub->GetInterfaceDescriptor(isolate); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 64 | parameters_.Reset(new HParameter*[descriptor_->register_param_count_]); |
| 65 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 66 | virtual bool BuildGraph(); |
| 67 | |
| 68 | protected: |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 69 | virtual HValue* BuildCodeStub() = 0; |
| 70 | HParameter* GetParameter(int parameter) { |
| 71 | ASSERT(parameter < descriptor_->register_param_count_); |
| 72 | return parameters_[parameter]; |
| 73 | } |
| 74 | HValue* GetArgumentsLength() { |
| 75 | // This is initialized in BuildGraph() |
| 76 | ASSERT(arguments_length_ != NULL); |
| 77 | return arguments_length_; |
| 78 | } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 79 | CompilationInfo* info() { return &info_; } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 80 | HydrogenCodeStub* stub() { return info_.code_stub(); } |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 81 | HContext* context() { return context_; } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 82 | Isolate* isolate() { return info_.isolate(); } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 83 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 84 | class ArrayContextChecker { |
| 85 | public: |
| 86 | ArrayContextChecker(HGraphBuilder* builder, HValue* constructor, |
| 87 | HValue* array_function) |
| 88 | : checker_(builder) { |
| 89 | checker_.If<HCompareObjectEqAndBranch, HValue*>(constructor, |
| 90 | array_function); |
| 91 | checker_.Then(); |
| 92 | } |
| 93 | |
| 94 | ~ArrayContextChecker() { |
| 95 | checker_.ElseDeopt(); |
| 96 | checker_.End(); |
| 97 | } |
| 98 | private: |
| 99 | IfBuilder checker_; |
| 100 | }; |
| 101 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 102 | private: |
| 103 | SmartArrayPointer<HParameter*> parameters_; |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 104 | HValue* arguments_length_; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 105 | CompilationInfoWithZone info_; |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 106 | CodeStubInterfaceDescriptor* descriptor_; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 107 | HContext* context_; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | |
| 111 | bool CodeStubGraphBuilderBase::BuildGraph() { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 112 | // Update the static counter each time a new code stub is generated. |
| 113 | isolate()->counters()->code_stubs()->Increment(); |
| 114 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 115 | if (FLAG_trace_hydrogen) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 116 | const char* name = CodeStub::MajorName(stub()->MajorKey(), false); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 117 | PrintF("-----------------------------------------------------------\n"); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 118 | PrintF("Compiling stub %s using hydrogen\n", name); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 119 | isolate()->GetHTracer()->TraceCompilation(&info_); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 120 | } |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 121 | |
| 122 | Zone* zone = this->zone(); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 123 | int param_count = descriptor_->register_param_count_; |
| 124 | HEnvironment* start_environment = graph()->start_environment(); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 125 | HBasicBlock* next_block = CreateBasicBlock(start_environment); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 126 | current_block()->Goto(next_block); |
| 127 | next_block->SetJoinId(BailoutId::StubEntry()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 128 | set_current_block(next_block); |
| 129 | |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 130 | HConstant* undefined_constant = new(zone) HConstant( |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 131 | isolate()->factory()->undefined_value(), Representation::Tagged()); |
| 132 | AddInstruction(undefined_constant); |
| 133 | graph()->set_undefined_constant(undefined_constant); |
| 134 | |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 135 | for (int i = 0; i < param_count; ++i) { |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 136 | HParameter* param = |
| 137 | new(zone) HParameter(i, HParameter::REGISTER_PARAMETER); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 138 | AddInstruction(param); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 139 | start_environment->Bind(i, param); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 140 | parameters_[i] = param; |
| 141 | } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 142 | |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 143 | HInstruction* stack_parameter_count; |
| 144 | if (descriptor_->stack_parameter_count_ != NULL) { |
| 145 | ASSERT(descriptor_->environment_length() == (param_count + 1)); |
| 146 | stack_parameter_count = new(zone) HParameter(param_count, |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 147 | HParameter::REGISTER_PARAMETER, |
| 148 | Representation::Integer32()); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 149 | stack_parameter_count->set_type(HType::Smi()); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 150 | // It's essential to bind this value to the environment in case of deopt. |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 151 | AddInstruction(stack_parameter_count); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 152 | start_environment->Bind(param_count, stack_parameter_count); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 153 | arguments_length_ = stack_parameter_count; |
| 154 | } else { |
| 155 | ASSERT(descriptor_->environment_length() == param_count); |
| 156 | stack_parameter_count = graph()->GetConstantMinus1(); |
| 157 | arguments_length_ = graph()->GetConstant0(); |
| 158 | } |
| 159 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 160 | context_ = new(zone) HContext(); |
| 161 | AddInstruction(context_); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 162 | start_environment->BindContext(context_); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 163 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 164 | AddSimulate(BailoutId::StubEntry()); |
| 165 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 166 | NoObservableSideEffectsScope no_effects(this); |
| 167 | |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 168 | HValue* return_value = BuildCodeStub(); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 169 | |
| 170 | // We might have extra expressions to pop from the stack in addition to the |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 171 | // arguments above. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 172 | HInstruction* stack_pop_count = stack_parameter_count; |
| 173 | if (descriptor_->function_mode_ == JS_FUNCTION_STUB_MODE) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 174 | if (!stack_parameter_count->IsConstant() && |
| 175 | descriptor_->hint_stack_parameter_count_ < 0) { |
| 176 | HInstruction* amount = graph()->GetConstant1(); |
| 177 | stack_pop_count = AddInstruction( |
| 178 | HAdd::New(zone, context_, stack_parameter_count, amount)); |
| 179 | stack_pop_count->ChangeRepresentation(Representation::Integer32()); |
| 180 | stack_pop_count->ClearFlag(HValue::kCanOverflow); |
| 181 | } else { |
| 182 | int count = descriptor_->hint_stack_parameter_count_; |
| 183 | stack_pop_count = AddInstruction(new(zone) |
| 184 | HConstant(count, Representation::Integer32())); |
| 185 | } |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 186 | } |
| 187 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 188 | if (current_block() != NULL) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 189 | HReturn* hreturn_instruction = new(zone) HReturn(return_value, |
| 190 | context_, |
| 191 | stack_pop_count); |
| 192 | current_block()->Finish(hreturn_instruction); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 193 | set_current_block(NULL); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 194 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 195 | return true; |
| 196 | } |
| 197 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 198 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 199 | template <class Stub> |
| 200 | class CodeStubGraphBuilder: public CodeStubGraphBuilderBase { |
| 201 | public: |
| 202 | explicit CodeStubGraphBuilder(Stub* stub) |
| 203 | : CodeStubGraphBuilderBase(Isolate::Current(), stub) {} |
| 204 | |
| 205 | protected: |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 206 | virtual HValue* BuildCodeStub() { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 207 | if (casted_stub()->IsUninitialized()) { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 208 | return BuildCodeUninitializedStub(); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 209 | } else { |
| 210 | return BuildCodeInitializedStub(); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | |
| 214 | virtual HValue* BuildCodeInitializedStub() { |
| 215 | UNIMPLEMENTED(); |
| 216 | return NULL; |
| 217 | } |
| 218 | |
| 219 | virtual HValue* BuildCodeUninitializedStub() { |
| 220 | // Force a deopt that falls back to the runtime. |
| 221 | HValue* undefined = graph()->GetConstantUndefined(); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 222 | IfBuilder builder(this); |
| 223 | builder.IfNot<HCompareObjectEqAndBranch, HValue*>(undefined, undefined); |
| 224 | builder.Then(); |
| 225 | builder.ElseDeopt(); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 226 | return undefined; |
| 227 | } |
| 228 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 229 | Stub* casted_stub() { return static_cast<Stub*>(stub()); } |
| 230 | }; |
| 231 | |
| 232 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 233 | Handle<Code> HydrogenCodeStub::GenerateLightweightMissCode(Isolate* isolate) { |
| 234 | Factory* factory = isolate->factory(); |
| 235 | |
| 236 | // Generate the new code. |
| 237 | MacroAssembler masm(isolate, NULL, 256); |
| 238 | |
| 239 | { |
| 240 | // Update the static counter each time a new code stub is generated. |
| 241 | isolate->counters()->code_stubs()->Increment(); |
| 242 | |
| 243 | // Nested stubs are not allowed for leaves. |
| 244 | AllowStubCallsScope allow_scope(&masm, false); |
| 245 | |
| 246 | // Generate the code for the stub. |
| 247 | masm.set_generating_stub(true); |
| 248 | NoCurrentFrameScope scope(&masm); |
| 249 | GenerateLightweightMiss(&masm); |
| 250 | } |
| 251 | |
| 252 | // Create the code object. |
| 253 | CodeDesc desc; |
| 254 | masm.GetCode(&desc); |
| 255 | |
| 256 | // Copy the generated code into a heap object. |
| 257 | Code::Flags flags = Code::ComputeFlags( |
| 258 | GetCodeKind(), |
| 259 | GetICState(), |
| 260 | GetExtraICState(), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 261 | GetStubType(), |
| 262 | GetStubFlags()); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 263 | Handle<Code> new_object = factory->NewCode( |
| 264 | desc, flags, masm.CodeObject(), NeedsImmovableCode()); |
| 265 | return new_object; |
| 266 | } |
| 267 | |
| 268 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 269 | template <class Stub> |
| 270 | static Handle<Code> DoGenerateCode(Stub* stub) { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 271 | Isolate* isolate = Isolate::Current(); |
| 272 | CodeStub::Major major_key = |
| 273 | static_cast<HydrogenCodeStub*>(stub)->MajorKey(); |
| 274 | CodeStubInterfaceDescriptor* descriptor = |
| 275 | isolate->code_stub_interface_descriptor(major_key); |
| 276 | if (descriptor->register_param_count_ < 0) { |
| 277 | stub->InitializeInterfaceDescriptor(isolate, descriptor); |
| 278 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 279 | |
| 280 | // If we are uninitialized we can use a light-weight stub to enter |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 281 | // the runtime that is significantly faster than using the standard |
| 282 | // stub-failure deopt mechanism. |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 283 | if (stub->IsUninitialized() && descriptor->has_miss_handler()) { |
| 284 | ASSERT(descriptor->stack_parameter_count_ == NULL); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 285 | return stub->GenerateLightweightMissCode(isolate); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 286 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 287 | CodeStubGraphBuilder<Stub> builder(stub); |
| 288 | LChunk* chunk = OptimizeGraph(builder.CreateGraph()); |
| 289 | return chunk->Codegen(); |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 293 | template <> |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 294 | HValue* CodeStubGraphBuilder<FastCloneShallowArrayStub>::BuildCodeStub() { |
| 295 | Zone* zone = this->zone(); |
| 296 | Factory* factory = isolate()->factory(); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 297 | HValue* undefined = graph()->GetConstantUndefined(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 298 | AllocationSiteMode alloc_site_mode = casted_stub()->allocation_site_mode(); |
| 299 | FastCloneShallowArrayStub::Mode mode = casted_stub()->mode(); |
| 300 | int length = casted_stub()->length(); |
| 301 | |
| 302 | HInstruction* boilerplate = |
| 303 | AddInstruction(new(zone) HLoadKeyed(GetParameter(0), |
| 304 | GetParameter(1), |
| 305 | NULL, |
| 306 | FAST_ELEMENTS)); |
| 307 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 308 | IfBuilder checker(this); |
| 309 | checker.IfNot<HCompareObjectEqAndBranch, HValue*>(boilerplate, undefined); |
| 310 | checker.Then(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 311 | |
| 312 | if (mode == FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 313 | HValue* elements = AddLoadElements(boilerplate); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 314 | |
| 315 | IfBuilder if_fixed_cow(this); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 316 | if_fixed_cow.IfCompareMap(elements, factory->fixed_cow_array_map()); |
| 317 | if_fixed_cow.Then(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 318 | environment()->Push(BuildCloneShallowArray(context(), |
| 319 | boilerplate, |
| 320 | alloc_site_mode, |
| 321 | FAST_ELEMENTS, |
| 322 | 0/*copy-on-write*/)); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 323 | if_fixed_cow.Else(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 324 | |
| 325 | IfBuilder if_fixed(this); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 326 | if_fixed.IfCompareMap(elements, factory->fixed_array_map()); |
| 327 | if_fixed.Then(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 328 | environment()->Push(BuildCloneShallowArray(context(), |
| 329 | boilerplate, |
| 330 | alloc_site_mode, |
| 331 | FAST_ELEMENTS, |
| 332 | length)); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 333 | if_fixed.Else(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 334 | environment()->Push(BuildCloneShallowArray(context(), |
| 335 | boilerplate, |
| 336 | alloc_site_mode, |
| 337 | FAST_DOUBLE_ELEMENTS, |
| 338 | length)); |
| 339 | } else { |
| 340 | ElementsKind elements_kind = casted_stub()->ComputeElementsKind(); |
| 341 | environment()->Push(BuildCloneShallowArray(context(), |
| 342 | boilerplate, |
| 343 | alloc_site_mode, |
| 344 | elements_kind, |
| 345 | length)); |
| 346 | } |
| 347 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 348 | HValue* result = environment()->Pop(); |
| 349 | checker.ElseDeopt(); |
| 350 | return result; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | |
| 354 | Handle<Code> FastCloneShallowArrayStub::GenerateCode() { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 355 | return DoGenerateCode(this); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | |
| 359 | template <> |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 360 | HValue* CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() { |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 361 | Zone* zone = this->zone(); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 362 | HValue* undefined = graph()->GetConstantUndefined(); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 363 | |
| 364 | HInstruction* boilerplate = |
| 365 | AddInstruction(new(zone) HLoadKeyed(GetParameter(0), |
| 366 | GetParameter(1), |
| 367 | NULL, |
| 368 | FAST_ELEMENTS)); |
| 369 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 370 | IfBuilder checker(this); |
| 371 | checker.IfNot<HCompareObjectEqAndBranch, HValue*>(boilerplate, undefined); |
| 372 | checker.And(); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 373 | |
| 374 | int size = JSObject::kHeaderSize + casted_stub()->length() * kPointerSize; |
| 375 | HValue* boilerplate_size = |
| 376 | AddInstruction(new(zone) HInstanceSize(boilerplate)); |
| 377 | HValue* size_in_words = |
| 378 | AddInstruction(new(zone) HConstant(size >> kPointerSizeLog2, |
| 379 | Representation::Integer32())); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 380 | checker.IfCompare(boilerplate_size, size_in_words, Token::EQ); |
| 381 | checker.Then(); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 382 | |
| 383 | HValue* size_in_bytes = |
| 384 | AddInstruction(new(zone) HConstant(size, Representation::Integer32())); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 385 | HAllocate::Flags flags = HAllocate::CAN_ALLOCATE_IN_NEW_SPACE; |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 386 | if (isolate()->heap()->ShouldGloballyPretenure()) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 387 | flags = static_cast<HAllocate::Flags>( |
| 388 | flags | HAllocate::CAN_ALLOCATE_IN_OLD_POINTER_SPACE); |
| 389 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 390 | |
| 391 | HInstruction* object = AddInstruction(new(zone) |
| 392 | HAllocate(context(), size_in_bytes, HType::JSObject(), flags)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 393 | |
| 394 | for (int i = 0; i < size; i += kPointerSize) { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 395 | HObjectAccess access = HObjectAccess::ForJSObjectOffset(i); |
| 396 | AddStore(object, access, AddLoad(boilerplate, access)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 397 | } |
| 398 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 399 | checker.ElseDeopt(); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 400 | return object; |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | |
| 404 | Handle<Code> FastCloneShallowObjectStub::GenerateCode() { |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 405 | return DoGenerateCode(this); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | |
| 409 | template <> |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 410 | HValue* CodeStubGraphBuilder<KeyedLoadFastElementStub>::BuildCodeStub() { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 411 | HInstruction* load = BuildUncheckedMonomorphicElementAccess( |
| 412 | GetParameter(0), GetParameter(1), NULL, NULL, |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 413 | casted_stub()->is_js_array(), casted_stub()->elements_kind(), |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 414 | false, NEVER_RETURN_HOLE, STANDARD_STORE); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 415 | return load; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | |
| 419 | Handle<Code> KeyedLoadFastElementStub::GenerateCode() { |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 420 | return DoGenerateCode(this); |
| 421 | } |
| 422 | |
| 423 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 424 | template<> |
| 425 | HValue* CodeStubGraphBuilder<LoadFieldStub>::BuildCodeStub() { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 426 | HObjectAccess access = casted_stub()->is_inobject() ? |
| 427 | HObjectAccess::ForJSObjectOffset(casted_stub()->offset()) : |
| 428 | HObjectAccess::ForBackingStoreOffset(casted_stub()->offset()); |
| 429 | return AddInstruction(BuildLoadNamedField(GetParameter(0), access, |
| 430 | casted_stub()->representation())); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | |
| 434 | Handle<Code> LoadFieldStub::GenerateCode() { |
| 435 | return DoGenerateCode(this); |
| 436 | } |
| 437 | |
| 438 | |
| 439 | template<> |
| 440 | HValue* CodeStubGraphBuilder<KeyedLoadFieldStub>::BuildCodeStub() { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 441 | HObjectAccess access = casted_stub()->is_inobject() ? |
| 442 | HObjectAccess::ForJSObjectOffset(casted_stub()->offset()) : |
| 443 | HObjectAccess::ForBackingStoreOffset(casted_stub()->offset()); |
| 444 | return AddInstruction(BuildLoadNamedField(GetParameter(0), access, |
| 445 | casted_stub()->representation())); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | |
| 449 | Handle<Code> KeyedLoadFieldStub::GenerateCode() { |
| 450 | return DoGenerateCode(this); |
| 451 | } |
| 452 | |
| 453 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 454 | template <> |
| 455 | HValue* CodeStubGraphBuilder<KeyedStoreFastElementStub>::BuildCodeStub() { |
| 456 | BuildUncheckedMonomorphicElementAccess( |
| 457 | GetParameter(0), GetParameter(1), GetParameter(2), NULL, |
| 458 | casted_stub()->is_js_array(), casted_stub()->elements_kind(), |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 459 | true, NEVER_RETURN_HOLE, casted_stub()->store_mode()); |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 460 | |
| 461 | return GetParameter(2); |
| 462 | } |
| 463 | |
| 464 | |
| 465 | Handle<Code> KeyedStoreFastElementStub::GenerateCode() { |
| 466 | return DoGenerateCode(this); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 470 | template <> |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 471 | HValue* CodeStubGraphBuilder<TransitionElementsKindStub>::BuildCodeStub() { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 472 | Zone* zone = this->zone(); |
| 473 | |
| 474 | HValue* js_array = GetParameter(0); |
| 475 | HValue* map = GetParameter(1); |
| 476 | |
| 477 | info()->MarkAsSavesCallerDoubles(); |
| 478 | |
| 479 | AddInstruction(new(zone) HTrapAllocationMemento(js_array)); |
| 480 | |
| 481 | HInstruction* array_length = |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 482 | AddLoad(js_array, HObjectAccess::ForArrayLength()); |
| 483 | array_length->set_type(HType::Smi()); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 484 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 485 | ElementsKind to_kind = casted_stub()->to_kind(); |
| 486 | BuildNewSpaceArrayCheck(array_length, to_kind); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 487 | |
danno@chromium.org | 2d18b36 | 2013-03-22 17:19:26 +0000 | [diff] [blame] | 488 | IfBuilder if_builder(this); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 489 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 490 | if_builder.IfCompare(array_length, graph()->GetConstant0(), Token::EQ); |
| 491 | if_builder.Then(); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 492 | |
| 493 | // Nothing to do, just change the map. |
| 494 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 495 | if_builder.Else(); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 496 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 497 | HInstruction* elements = AddLoadElements(js_array); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 498 | |
| 499 | HInstruction* elements_length = |
| 500 | AddInstruction(new(zone) HFixedArrayBaseLength(elements)); |
| 501 | |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 502 | HValue* new_elements = BuildAllocateElementsAndInitializeElementsHeader( |
| 503 | context(), to_kind, elements_length); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 504 | |
| 505 | BuildCopyElements(context(), elements, |
| 506 | casted_stub()->from_kind(), new_elements, |
danno@chromium.org | 2d18b36 | 2013-03-22 17:19:26 +0000 | [diff] [blame] | 507 | to_kind, array_length, elements_length); |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 508 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 509 | AddStore(js_array, HObjectAccess::ForElementsPointer(), new_elements); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 510 | |
| 511 | if_builder.End(); |
| 512 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 513 | AddStore(js_array, HObjectAccess::ForMap(), map); |
| 514 | |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 515 | return js_array; |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 519 | Handle<Code> TransitionElementsKindStub::GenerateCode() { |
| 520 | return DoGenerateCode(this); |
| 521 | } |
| 522 | |
| 523 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 524 | template <> |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 525 | HValue* CodeStubGraphBuilder<ArrayNoArgumentConstructorStub>::BuildCodeStub() { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 526 | // ----------- S t a t e ------------- |
| 527 | // -- Parameter 1 : type info cell |
| 528 | // -- Parameter 0 : constructor |
| 529 | // ----------------------------------- |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 530 | HInstruction* array_function = BuildGetArrayFunction(context()); |
| 531 | ArrayContextChecker(this, |
| 532 | GetParameter(ArrayConstructorStubBase::kConstructor), |
| 533 | array_function); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 534 | // Get the right map |
| 535 | // Should be a constant |
| 536 | JSArrayBuilder array_builder( |
| 537 | this, |
| 538 | casted_stub()->elements_kind(), |
| 539 | GetParameter(ArrayConstructorStubBase::kPropertyCell), |
| 540 | casted_stub()->mode()); |
| 541 | return array_builder.AllocateEmptyArray(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | |
| 545 | Handle<Code> ArrayNoArgumentConstructorStub::GenerateCode() { |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 546 | return DoGenerateCode(this); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | |
| 550 | template <> |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 551 | HValue* CodeStubGraphBuilder<ArraySingleArgumentConstructorStub>:: |
| 552 | BuildCodeStub() { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 553 | HInstruction* array_function = BuildGetArrayFunction(context()); |
| 554 | ArrayContextChecker(this, |
| 555 | GetParameter(ArrayConstructorStubBase::kConstructor), |
| 556 | array_function); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 557 | // Smi check and range check on the input arg. |
| 558 | HValue* constant_one = graph()->GetConstant1(); |
| 559 | HValue* constant_zero = graph()->GetConstant0(); |
| 560 | |
| 561 | HInstruction* elements = AddInstruction( |
| 562 | new(zone()) HArgumentsElements(false)); |
| 563 | HInstruction* argument = AddInstruction( |
| 564 | new(zone()) HAccessArgumentsAt(elements, constant_one, constant_zero)); |
| 565 | |
| 566 | HConstant* max_alloc_length = |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 567 | new(zone()) HConstant(JSObject::kInitialMaxFastElementArray); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 568 | AddInstruction(max_alloc_length); |
| 569 | const int initial_capacity = JSArray::kPreallocatedArrayElements; |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 570 | HConstant* initial_capacity_node = new(zone()) HConstant(initial_capacity); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 571 | AddInstruction(initial_capacity_node); |
| 572 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 573 | HBoundsCheck* checked_arg = AddBoundsCheck(argument, max_alloc_length); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 574 | IfBuilder if_builder(this); |
| 575 | if_builder.IfCompare(checked_arg, constant_zero, Token::EQ); |
| 576 | if_builder.Then(); |
| 577 | Push(initial_capacity_node); // capacity |
| 578 | Push(constant_zero); // length |
| 579 | if_builder.Else(); |
| 580 | Push(checked_arg); // capacity |
| 581 | Push(checked_arg); // length |
| 582 | if_builder.End(); |
| 583 | |
| 584 | // Figure out total size |
| 585 | HValue* length = Pop(); |
| 586 | HValue* capacity = Pop(); |
| 587 | |
| 588 | JSArrayBuilder array_builder( |
| 589 | this, |
| 590 | casted_stub()->elements_kind(), |
| 591 | GetParameter(ArrayConstructorStubBase::kPropertyCell), |
| 592 | casted_stub()->mode()); |
| 593 | return array_builder.AllocateArray(capacity, length, true); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 597 | Handle<Code> ArraySingleArgumentConstructorStub::GenerateCode() { |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 598 | return DoGenerateCode(this); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | |
| 602 | template <> |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 603 | HValue* CodeStubGraphBuilder<ArrayNArgumentsConstructorStub>::BuildCodeStub() { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 604 | HInstruction* array_function = BuildGetArrayFunction(context()); |
| 605 | ArrayContextChecker(this, |
| 606 | GetParameter(ArrayConstructorStubBase::kConstructor), |
| 607 | array_function); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 608 | ElementsKind kind = casted_stub()->elements_kind(); |
| 609 | HValue* length = GetArgumentsLength(); |
| 610 | |
| 611 | JSArrayBuilder array_builder( |
| 612 | this, |
| 613 | kind, |
| 614 | GetParameter(ArrayConstructorStubBase::kPropertyCell), |
| 615 | casted_stub()->mode()); |
| 616 | |
| 617 | // We need to fill with the hole if it's a smi array in the multi-argument |
| 618 | // case because we might have to bail out while copying arguments into |
| 619 | // the array because they aren't compatible with a smi array. |
| 620 | // If it's a double array, no problem, and if it's fast then no |
| 621 | // problem either because doubles are boxed. |
| 622 | bool fill_with_hole = IsFastSmiElementsKind(kind); |
| 623 | HValue* new_object = array_builder.AllocateArray(length, |
| 624 | length, |
| 625 | fill_with_hole); |
| 626 | HValue* elements = array_builder.GetElementsLocation(); |
| 627 | ASSERT(elements != NULL); |
| 628 | |
| 629 | // Now populate the elements correctly. |
| 630 | LoopBuilder builder(this, |
| 631 | context(), |
| 632 | LoopBuilder::kPostIncrement); |
| 633 | HValue* start = graph()->GetConstant0(); |
| 634 | HValue* key = builder.BeginBody(start, length, Token::LT); |
| 635 | HInstruction* argument_elements = AddInstruction( |
| 636 | new(zone()) HArgumentsElements(false)); |
| 637 | HInstruction* argument = AddInstruction(new(zone()) HAccessArgumentsAt( |
| 638 | argument_elements, length, key)); |
| 639 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 640 | AddInstruction(new(zone()) HStoreKeyed(elements, key, argument, kind)); |
| 641 | builder.EndBody(); |
| 642 | return new_object; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | |
| 646 | Handle<Code> ArrayNArgumentsConstructorStub::GenerateCode() { |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 647 | return DoGenerateCode(this); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 648 | } |
| 649 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 650 | |
| 651 | template <> |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 652 | HValue* CodeStubGraphBuilder<CompareNilICStub>::BuildCodeInitializedStub() { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 653 | CompareNilICStub* stub = casted_stub(); |
| 654 | HIfContinuation continuation; |
| 655 | Handle<Map> sentinel_map(graph()->isolate()->heap()->meta_map()); |
| 656 | BuildCompareNil(GetParameter(0), stub->GetKind(), |
| 657 | stub->GetTypes(), sentinel_map, |
| 658 | RelocInfo::kNoPosition, &continuation); |
| 659 | IfBuilder if_nil(this, &continuation); |
| 660 | if_nil.Then(); |
| 661 | if (continuation.IsFalseReachable()) { |
| 662 | if_nil.Else(); |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 663 | if_nil.Return(graph()->GetConstant0()); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 664 | } |
| 665 | if_nil.End(); |
| 666 | return continuation.IsTrueReachable() |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 667 | ? graph()->GetConstant1() |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 668 | : graph()->GetConstantUndefined(); |
| 669 | } |
| 670 | |
| 671 | |
| 672 | Handle<Code> CompareNilICStub::GenerateCode() { |
| 673 | return DoGenerateCode(this); |
| 674 | } |
| 675 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 676 | |
| 677 | template <> |
| 678 | HValue* CodeStubGraphBuilder<ToBooleanStub>::BuildCodeInitializedStub() { |
| 679 | ToBooleanStub* stub = casted_stub(); |
| 680 | |
| 681 | IfBuilder if_true(this); |
| 682 | if_true.If<HBranch>(GetParameter(0), stub->GetTypes()); |
| 683 | if_true.Then(); |
| 684 | if_true.Return(graph()->GetConstant1()); |
| 685 | if_true.Else(); |
| 686 | if_true.End(); |
| 687 | return graph()->GetConstant0(); |
| 688 | } |
| 689 | |
| 690 | |
| 691 | Handle<Code> ToBooleanStub::GenerateCode() { |
| 692 | return DoGenerateCode(this); |
| 693 | } |
| 694 | |
| 695 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 696 | } } // namespace v8::internal |