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

Side by Side Diff: src/code-stubs-hydrogen.cc

Issue 11659022: Generate the TransitionElementsStub using Crankshaft (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review feedback Created 7 years, 10 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
« no previous file with comments | « src/code-stubs.h ('k') | src/compiler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 class CodeStubGraphBuilderBase : public HGraphBuilder { 56 class CodeStubGraphBuilderBase : public HGraphBuilder {
57 public: 57 public:
58 CodeStubGraphBuilderBase(Isolate* isolate, HydrogenCodeStub* stub) 58 CodeStubGraphBuilderBase(Isolate* isolate, HydrogenCodeStub* stub)
59 : HGraphBuilder(&info_), info_(stub, isolate), context_(NULL) {} 59 : HGraphBuilder(&info_), info_(stub, isolate), context_(NULL) {}
60 virtual bool BuildGraph(); 60 virtual bool BuildGraph();
61 61
62 protected: 62 protected:
63 virtual void BuildCodeStub() = 0; 63 virtual void BuildCodeStub() = 0;
64 HParameter* GetParameter(int parameter) { return parameters_[parameter]; } 64 HParameter* GetParameter(int parameter) { return parameters_[parameter]; }
65 CompilationInfo* info() { return &info_; }
65 HydrogenCodeStub* stub() { return info_.code_stub(); } 66 HydrogenCodeStub* stub() { return info_.code_stub(); }
66 HContext* context() { return context_; } 67 HContext* context() { return context_; }
68 Isolate* isolate() { return info_.isolate(); }
67 69
68 private: 70 private:
69 SmartArrayPointer<HParameter*> parameters_; 71 SmartArrayPointer<HParameter*> parameters_;
70 CompilationInfoWithZone info_; 72 CompilationInfoWithZone info_;
71 HContext* context_; 73 HContext* context_;
72 }; 74 };
73 75
74 76
75 bool CodeStubGraphBuilderBase::BuildGraph() { 77 bool CodeStubGraphBuilderBase::BuildGraph() {
76 if (FLAG_trace_hydrogen) { 78 if (FLAG_trace_hydrogen) {
77 PrintF("-----------------------------------------------------------\n"); 79 PrintF("-----------------------------------------------------------\n");
78 PrintF("Compiling stub using hydrogen\n"); 80 PrintF("Compiling stub using hydrogen\n");
79 HTracer::Instance()->TraceCompilation(&info_); 81 HTracer::Instance()->TraceCompilation(&info_);
80 } 82 }
81 HBasicBlock* next_block = graph()->CreateBasicBlock(); 83 HBasicBlock* next_block = graph()->CreateBasicBlock();
82 next_block->SetInitialEnvironment(graph()->start_environment()); 84 next_block->SetInitialEnvironment(graph()->start_environment());
83 HGoto* jump = new(zone()) HGoto(next_block); 85 HGoto* jump = new(zone()) HGoto(next_block);
84 graph()->entry_block()->Finish(jump); 86 graph()->entry_block()->Finish(jump);
85 set_current_block(next_block); 87 set_current_block(next_block);
86 88
87 context_ = new(zone()) HContext();
88 AddInstruction(context_);
89
90 int major_key = stub()->MajorKey(); 89 int major_key = stub()->MajorKey();
91 CodeStubInterfaceDescriptor* descriptor = 90 CodeStubInterfaceDescriptor* descriptor =
92 info_.isolate()->code_stub_interface_descriptor(major_key); 91 info_.isolate()->code_stub_interface_descriptor(major_key);
93 if (descriptor->register_param_count_ < 0) { 92 if (descriptor->register_param_count_ < 0) {
94 stub()->InitializeInterfaceDescriptor(info_.isolate(), descriptor); 93 stub()->InitializeInterfaceDescriptor(info_.isolate(), descriptor);
95 } 94 }
96 parameters_.Reset(new HParameter*[descriptor->register_param_count_]); 95 parameters_.Reset(new HParameter*[descriptor->register_param_count_]);
97 96
97 HConstant* undefined_constant = new(zone()) HConstant(
98 isolate()->factory()->undefined_value(), Representation::Tagged());
99 AddInstruction(undefined_constant);
100 graph()->set_undefined_constant(undefined_constant);
101
98 HGraph* graph = this->graph(); 102 HGraph* graph = this->graph();
99 Zone* zone = this->zone(); 103 Zone* zone = this->zone();
100 for (int i = 0; i < descriptor->register_param_count_; ++i) { 104 for (int i = 0; i < descriptor->register_param_count_; ++i) {
101 HParameter* param = new(zone) HParameter(i); 105 HParameter* param = new(zone) HParameter(i);
102 AddInstruction(param); 106 AddInstruction(param);
103 graph->start_environment()->Push(param); 107 graph->start_environment()->Push(param);
104 parameters_[i] = param; 108 parameters_[i] = param;
105 } 109 }
110
111 context_ = new(zone) HContext();
112 AddInstruction(context_);
113
106 AddSimulate(BailoutId::StubEntry()); 114 AddSimulate(BailoutId::StubEntry());
107 115
108 BuildCodeStub(); 116 BuildCodeStub();
109 117
110 return true; 118 return true;
111 } 119 }
112 120
113 template <class Stub> 121 template <class Stub>
114 class CodeStubGraphBuilder: public CodeStubGraphBuilderBase { 122 class CodeStubGraphBuilder: public CodeStubGraphBuilderBase {
115 public: 123 public:
(...skipping 21 matching lines...) Expand all
137 } 145 }
138 146
139 147
140 Handle<Code> KeyedLoadFastElementStub::GenerateCode() { 148 Handle<Code> KeyedLoadFastElementStub::GenerateCode() {
141 CodeStubGraphBuilder<KeyedLoadFastElementStub> builder(this); 149 CodeStubGraphBuilder<KeyedLoadFastElementStub> builder(this);
142 LChunk* chunk = OptimizeGraph(builder.CreateGraph()); 150 LChunk* chunk = OptimizeGraph(builder.CreateGraph());
143 return chunk->Codegen(Code::COMPILED_STUB); 151 return chunk->Codegen(Code::COMPILED_STUB);
144 } 152 }
145 153
146 154
155 template <>
156 void CodeStubGraphBuilder<TransitionElementsKindStub>::BuildCodeStub() {
157 Zone* zone = this->zone();
158
159 HValue* js_array = GetParameter(0);
160 HValue* map = GetParameter(1);
161
162 info()->MarkAsSavesCallerDoubles();
163
164 AddInstruction(new(zone) HTrapAllocationMemento(js_array));
165
166 HInstruction* array_length =
167 AddInstruction(new(zone) HJSArrayLength(js_array,
168 js_array,
169 HType::Smi()));
170
171 Heap* heap = isolate()->heap();
172 const int kMinFreeNewSpaceAfterGC =
173 ((heap->InitialSemiSpaceSize() - sizeof(FixedArrayBase)) / 2) /
174 kDoubleSize;
175
176 HConstant* max_alloc_size =
177 new(zone) HConstant(kMinFreeNewSpaceAfterGC, Representation::Integer32());
178 AddInstruction(max_alloc_size);
179 AddInstruction(new(zone) HBoundsCheck(array_length, max_alloc_size));
180
181 current_block()->UpdateEnvironment(new(zone) HEnvironment(zone));
182
183 IfBuilder if_builder(this);
184
185 if_builder.BeginTrue(array_length, graph()->GetConstant0(), Token::EQ);
186
187 // Nothing to do, just change the map.
188
189 if_builder.BeginFalse();
190
191 HInstruction* elements =
192 AddInstruction(new(zone) HLoadElements(js_array, js_array));
193
194 HInstruction* elements_length =
195 AddInstruction(new(zone) HFixedArrayBaseLength(elements));
196
197 ElementsKind to_kind = casted_stub()->to_kind();
198 HValue* new_elements =
199 BuildAllocateElements(context(), to_kind, elements_length);
200
201 // Fast elements kinds need to be initialized in case statements below cause a
202 // garbage collection.
203 Factory* factory = isolate()->factory();
204
205 ASSERT(!IsFastSmiElementsKind(to_kind));
206 double nan_double = FixedDoubleArray::hole_nan_as_double();
207 HValue* hole = IsFastObjectElementsKind(to_kind)
208 ? AddInstruction(new(zone) HConstant(factory->the_hole_value(),
209 Representation::Tagged()))
210 : AddInstruction(new(zone) HConstant(nan_double,
211 Representation::Double()));
212
213 LoopBuilder builder(this, context(), LoopBuilder::kPostIncrement);
214
215 HValue* zero = graph()->GetConstant0();
216 HValue* start = IsFastElementsKind(to_kind) ? zero : array_length;
217 HValue* key = builder.BeginBody(start, elements_length, Token::LT);
218
219 AddInstruction(new(zone) HStoreKeyed(new_elements, key, hole, to_kind));
220 AddSimulate(BailoutId::StubEntry(), REMOVABLE_SIMULATE);
221
222 builder.EndBody();
223
224 BuildCopyElements(context(), elements,
225 casted_stub()->from_kind(), new_elements,
226 to_kind, array_length);
227
228 AddInstruction(new(zone) HStoreNamedField(js_array,
229 factory->elements_field_symbol(),
230 new_elements, true,
231 JSArray::kElementsOffset));
232 AddSimulate(BailoutId::StubEntry());
233
234 if_builder.End();
235
236 AddInstruction(new(zone) HStoreNamedField(js_array, factory->length_symbol(),
237 map, true, JSArray::kMapOffset));
238 AddSimulate(BailoutId::StubEntry());
239
240 HReturn* ret = new(zone) HReturn(js_array, context());
241 current_block()->Finish(ret);
242 }
243
244
245 Handle<Code> TransitionElementsKindStub::GenerateCode() {
246 CodeStubGraphBuilder<TransitionElementsKindStub> builder(this);
247 LChunk* chunk = OptimizeGraph(builder.CreateGraph());
248 return chunk->Codegen(Code::COMPILED_STUB);
249 }
250
251
147 } } // namespace v8::internal 252 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/code-stubs.h ('k') | src/compiler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698