| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 explicit CodeStubGraphBuilder(Stub* stub) | 131 explicit CodeStubGraphBuilder(Stub* stub) |
| 132 : CodeStubGraphBuilderBase(Isolate::Current(), stub) {} | 132 : CodeStubGraphBuilderBase(Isolate::Current(), stub) {} |
| 133 | 133 |
| 134 protected: | 134 protected: |
| 135 virtual void BuildCodeStub(); | 135 virtual void BuildCodeStub(); |
| 136 Stub* casted_stub() { return static_cast<Stub*>(stub()); } | 136 Stub* casted_stub() { return static_cast<Stub*>(stub()); } |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 | 139 |
| 140 template <> | 140 template <> |
| 141 void CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() { |
| 142 Zone* zone = this->zone(); |
| 143 Factory* factory = isolate()->factory(); |
| 144 |
| 145 HInstruction* boilerplate = |
| 146 AddInstruction(new(zone) HLoadKeyed(GetParameter(0), |
| 147 GetParameter(1), |
| 148 NULL, |
| 149 FAST_ELEMENTS)); |
| 150 |
| 151 CheckBuilder builder(this, BailoutId::StubEntry()); |
| 152 builder.CheckNotUndefined(boilerplate); |
| 153 |
| 154 int size = JSObject::kHeaderSize + casted_stub()->length() * kPointerSize; |
| 155 HValue* boilerplate_size = |
| 156 AddInstruction(new(zone) HInstanceSize(boilerplate)); |
| 157 HValue* size_in_words = |
| 158 AddInstruction(new(zone) HConstant(size >> kPointerSizeLog2, |
| 159 Representation::Integer32())); |
| 160 builder.CheckIntegerEq(boilerplate_size, size_in_words); |
| 161 |
| 162 HValue* size_in_bytes = |
| 163 AddInstruction(new(zone) HConstant(size, Representation::Integer32())); |
| 164 HInstruction* object = |
| 165 AddInstruction(new(zone) HAllocate(context(), |
| 166 size_in_bytes, |
| 167 HType::JSObject(), |
| 168 HAllocate::CAN_ALLOCATE_IN_NEW_SPACE)); |
| 169 |
| 170 for (int i = 0; i < size; i += kPointerSize) { |
| 171 HInstruction* value = |
| 172 AddInstruction(new(zone) HLoadNamedField(boilerplate, true, i)); |
| 173 AddInstruction(new(zone) HStoreNamedField(object, |
| 174 factory->empty_symbol(), |
| 175 value, |
| 176 true, i)); |
| 177 AddSimulate(BailoutId::StubEntry()); |
| 178 } |
| 179 |
| 180 builder.End(); |
| 181 |
| 182 HReturn* ret = new(zone) HReturn(object, context()); |
| 183 current_block()->Finish(ret); |
| 184 } |
| 185 |
| 186 |
| 187 Handle<Code> FastCloneShallowObjectStub::GenerateCode() { |
| 188 CodeStubGraphBuilder<FastCloneShallowObjectStub> builder(this); |
| 189 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); |
| 190 return chunk->Codegen(Code::COMPILED_STUB); |
| 191 } |
| 192 |
| 193 |
| 194 template <> |
| 141 void CodeStubGraphBuilder<KeyedLoadFastElementStub>::BuildCodeStub() { | 195 void CodeStubGraphBuilder<KeyedLoadFastElementStub>::BuildCodeStub() { |
| 142 Zone* zone = this->zone(); | 196 Zone* zone = this->zone(); |
| 143 | 197 |
| 144 HInstruction* load = BuildUncheckedMonomorphicElementAccess( | 198 HInstruction* load = BuildUncheckedMonomorphicElementAccess( |
| 145 GetParameter(0), GetParameter(1), NULL, NULL, | 199 GetParameter(0), GetParameter(1), NULL, NULL, |
| 146 casted_stub()->is_js_array(), casted_stub()->elements_kind(), | 200 casted_stub()->is_js_array(), casted_stub()->elements_kind(), |
| 147 false, Representation::Tagged()); | 201 false, Representation::Tagged()); |
| 148 AddInstruction(load); | 202 AddInstruction(load); |
| 149 | 203 |
| 150 HReturn* ret = new(zone) HReturn(load, context()); | 204 HReturn* ret = new(zone) HReturn(load, context()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 236 |
| 183 HConstant* max_alloc_size = | 237 HConstant* max_alloc_size = |
| 184 new(zone) HConstant(kMinFreeNewSpaceAfterGC, Representation::Integer32()); | 238 new(zone) HConstant(kMinFreeNewSpaceAfterGC, Representation::Integer32()); |
| 185 AddInstruction(max_alloc_size); | 239 AddInstruction(max_alloc_size); |
| 186 // Since we're forcing Integer32 representation for this HBoundsCheck, | 240 // Since we're forcing Integer32 representation for this HBoundsCheck, |
| 187 // there's no need to Smi-check the index. | 241 // there's no need to Smi-check the index. |
| 188 AddInstruction( | 242 AddInstruction( |
| 189 new(zone) HBoundsCheck(array_length, max_alloc_size, | 243 new(zone) HBoundsCheck(array_length, max_alloc_size, |
| 190 DONT_ALLOW_SMI_KEY, Representation::Integer32())); | 244 DONT_ALLOW_SMI_KEY, Representation::Integer32())); |
| 191 | 245 |
| 192 IfBuilder if_builder(this); | 246 IfBuilder if_builder(this, BailoutId::StubEntry()); |
| 193 | 247 |
| 194 if_builder.BeginTrue(array_length, graph()->GetConstant0(), Token::EQ); | 248 if_builder.BeginTrue(array_length, graph()->GetConstant0(), Token::EQ); |
| 195 | 249 |
| 196 // Nothing to do, just change the map. | 250 // Nothing to do, just change the map. |
| 197 | 251 |
| 198 if_builder.BeginFalse(); | 252 if_builder.BeginFalse(); |
| 199 | 253 |
| 200 HInstruction* elements = | 254 HInstruction* elements = |
| 201 AddInstruction(new(zone) HLoadElements(js_array, js_array)); | 255 AddInstruction(new(zone) HLoadElements(js_array, js_array)); |
| 202 | 256 |
| 203 HInstruction* elements_length = | 257 HInstruction* elements_length = |
| 204 AddInstruction(new(zone) HFixedArrayBaseLength(elements)); | 258 AddInstruction(new(zone) HFixedArrayBaseLength(elements)); |
| 205 | 259 |
| 206 ElementsKind to_kind = casted_stub()->to_kind(); | 260 ElementsKind to_kind = casted_stub()->to_kind(); |
| 207 HValue* new_elements = | 261 HValue* new_elements = |
| 208 BuildAllocateElements(context(), to_kind, elements_length); | 262 BuildAllocateElements(context(), to_kind, elements_length); |
| 209 | 263 |
| 210 // Fast elements kinds need to be initialized in case statements below cause a | 264 // Fast elements kinds need to be initialized in case statements below cause a |
| 211 // garbage collection. | 265 // garbage collection. |
| 212 Factory* factory = isolate()->factory(); | 266 Factory* factory = isolate()->factory(); |
| 213 | 267 |
| 214 ASSERT(!IsFastSmiElementsKind(to_kind)); | 268 ASSERT(!IsFastSmiElementsKind(to_kind)); |
| 215 double nan_double = FixedDoubleArray::hole_nan_as_double(); | 269 double nan_double = FixedDoubleArray::hole_nan_as_double(); |
| 216 HValue* hole = IsFastObjectElementsKind(to_kind) | 270 HValue* hole = IsFastObjectElementsKind(to_kind) |
| 217 ? AddInstruction(new(zone) HConstant(factory->the_hole_value(), | 271 ? AddInstruction(new(zone) HConstant(factory->the_hole_value(), |
| 218 Representation::Tagged())) | 272 Representation::Tagged())) |
| 219 : AddInstruction(new(zone) HConstant(nan_double, | 273 : AddInstruction(new(zone) HConstant(nan_double, |
| 220 Representation::Double())); | 274 Representation::Double())); |
| 221 | 275 |
| 222 LoopBuilder builder(this, context(), LoopBuilder::kPostIncrement); | 276 LoopBuilder builder(this, context(), LoopBuilder::kPostIncrement, |
| 277 BailoutId::StubEntry()); |
| 223 | 278 |
| 224 HValue* zero = graph()->GetConstant0(); | 279 HValue* zero = graph()->GetConstant0(); |
| 225 HValue* start = IsFastElementsKind(to_kind) ? zero : array_length; | 280 HValue* start = IsFastElementsKind(to_kind) ? zero : array_length; |
| 226 HValue* key = builder.BeginBody(start, elements_length, Token::LT); | 281 HValue* key = builder.BeginBody(start, elements_length, Token::LT); |
| 227 | 282 |
| 228 AddInstruction(new(zone) HStoreKeyed(new_elements, key, hole, to_kind)); | 283 AddInstruction(new(zone) HStoreKeyed(new_elements, key, hole, to_kind)); |
| 229 AddSimulate(BailoutId::StubEntry(), REMOVABLE_SIMULATE); | 284 AddSimulate(BailoutId::StubEntry(), REMOVABLE_SIMULATE); |
| 230 | 285 |
| 231 builder.EndBody(); | 286 builder.EndBody(); |
| 232 | 287 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 252 | 307 |
| 253 | 308 |
| 254 Handle<Code> TransitionElementsKindStub::GenerateCode() { | 309 Handle<Code> TransitionElementsKindStub::GenerateCode() { |
| 255 CodeStubGraphBuilder<TransitionElementsKindStub> builder(this); | 310 CodeStubGraphBuilder<TransitionElementsKindStub> builder(this); |
| 256 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); | 311 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); |
| 257 return chunk->Codegen(Code::COMPILED_STUB); | 312 return chunk->Codegen(Code::COMPILED_STUB); |
| 258 } | 313 } |
| 259 | 314 |
| 260 | 315 |
| 261 } } // namespace v8::internal | 316 } } // namespace v8::internal |
| OLD | NEW |