OLD | NEW |
| (Empty) |
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 | |
38 Handle<Code> HydrogenCodeStub::CodeFromGraph(HGraph* graph) { | |
39 graph->OrderBlocks(); | |
40 graph->AssignDominators(); | |
41 graph->CollectPhis(); | |
42 graph->InsertRepresentationChanges(); | |
43 graph->EliminateRedundantBoundsChecks(); | |
44 LChunk* chunk = LChunk::NewChunk(graph); | |
45 ASSERT(chunk != NULL); | |
46 Handle<Code> stub = chunk->Codegen(Code::COMPILED_STUB); | |
47 return stub; | |
48 } | |
49 | |
50 | |
51 class CodeStubGraphBuilderBase : public HGraphBuilder { | |
52 public: | |
53 CodeStubGraphBuilderBase(Isolate* isolate, HydrogenCodeStub* stub) | |
54 : HGraphBuilder(&info_), info_(stub, isolate) {} | |
55 virtual bool BuildGraph(); | |
56 | |
57 protected: | |
58 virtual void BuildCodeStub() = 0; | |
59 HParameter* GetParameter(int parameter) { return parameters_[parameter]; } | |
60 HydrogenCodeStub* stub() { return info_.code_stub(); } | |
61 | |
62 private: | |
63 SmartArrayPointer<HParameter*> parameters_; | |
64 CompilationInfoWithZone info_; | |
65 }; | |
66 | |
67 | |
68 bool CodeStubGraphBuilderBase::BuildGraph() { | |
69 if (FLAG_trace_hydrogen) { | |
70 PrintF("-----------------------------------------------------------\n"); | |
71 PrintF("Compiling stub using hydrogen\n"); | |
72 HTracer::Instance()->TraceCompilation(&info_); | |
73 } | |
74 HBasicBlock* next_block = graph()->CreateBasicBlock(); | |
75 next_block->SetInitialEnvironment(graph()->start_environment()); | |
76 HGoto* jump = new(zone()) HGoto(next_block); | |
77 graph()->entry_block()->Finish(jump); | |
78 set_current_block(next_block); | |
79 | |
80 int major_key = stub()->MajorKey(); | |
81 CodeStubInterfaceDescriptor* descriptor = | |
82 info_.isolate()->code_stub_interface_descriptor(major_key); | |
83 if (descriptor->register_param_count_ < 0) { | |
84 stub()->InitializeInterfaceDescriptor(info_.isolate(), descriptor); | |
85 } | |
86 parameters_.Reset(new HParameter*[descriptor->register_param_count_]); | |
87 | |
88 HGraph* graph = this->graph(); | |
89 Zone* zone = this->zone(); | |
90 for (int i = 0; i < descriptor->register_param_count_; ++i) { | |
91 HParameter* param = new(zone) HParameter(i); | |
92 AddInstruction(param); | |
93 graph->start_environment()->Push(param); | |
94 parameters_[i] = param; | |
95 } | |
96 AddSimulate(BailoutId::StubEntry()); | |
97 | |
98 BuildCodeStub(); | |
99 | |
100 return true; | |
101 } | |
102 | |
103 template <class Stub> | |
104 class CodeStubGraphBuilder: public CodeStubGraphBuilderBase { | |
105 public: | |
106 explicit CodeStubGraphBuilder(Stub* stub) | |
107 : CodeStubGraphBuilderBase(Isolate::Current(), stub) {} | |
108 | |
109 protected: | |
110 virtual void BuildCodeStub(); | |
111 Stub* casted_stub() { return static_cast<Stub*>(stub()); } | |
112 }; | |
113 | |
114 | |
115 template <> | |
116 void CodeStubGraphBuilder<KeyedLoadFastElementStub>::BuildCodeStub() { | |
117 Zone* zone = this->zone(); | |
118 | |
119 HInstruction* load = BuildUncheckedMonomorphicElementAccess( | |
120 GetParameter(0), GetParameter(1), NULL, NULL, | |
121 casted_stub()->is_js_array(), casted_stub()->elements_kind(), false); | |
122 AddInstruction(load); | |
123 | |
124 HReturn* ret = new(zone) HReturn(load); | |
125 current_block()->Finish(ret); | |
126 } | |
127 | |
128 | |
129 Handle<Code> KeyedLoadFastElementStub::GenerateCode() { | |
130 CodeStubGraphBuilder<KeyedLoadFastElementStub> builder(this); | |
131 return CodeFromGraph(builder.CreateGraph()); | |
132 } | |
133 | |
134 | |
135 } } // namespace v8::internal | |
OLD | NEW |