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

Side by Side Diff: src/arm/fast-codegen-arm.cc

Issue 553149: Implement simple fast-path code for functions containing this property stores and global variables. (Closed)
Patch Set: Incorporated codereview comments. Created 10 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
« no previous file with comments | « src/arm/codegen-arm.h ('k') | src/arm/full-codegen-arm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2010 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 "codegen-inl.h"
31 #include "fast-codegen.h"
32
33 namespace v8 {
34 namespace internal {
35
36 #define __ ACCESS_MASM(masm())
37
38 void FastCodeGenerator::EmitLoadReceiver(Register reg) {
39 // Offset 2 is due to return address and saved frame pointer.
40 int index = 2 + function()->scope()->num_parameters();
41 __ ldr(reg, MemOperand(sp, index * kPointerSize));
42 }
43
44
45 void FastCodeGenerator::EmitReceiverMapCheck() {
46 Comment cmnt(masm(), ";; MapCheck(this)");
47 if (FLAG_print_ir) {
48 PrintF("MapCheck(this)\n");
49 }
50
51 EmitLoadReceiver(r1);
52 __ BranchOnSmi(r1, bailout());
53
54 ASSERT(has_receiver() && receiver()->IsHeapObject());
55 Handle<HeapObject> object = Handle<HeapObject>::cast(receiver());
56 Handle<Map> map(object->map());
57 __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset));
58 __ mov(ip, Operand(map));
59 __ cmp(r3, ip);
60 __ b(ne, bailout());
61 }
62
63
64 void FastCodeGenerator::EmitGlobalVariableLoad(Handle<String> name) {
65 // Compile global variable accesses as load IC calls. The only live
66 // registers are cp (context) and possibly r1 (this). Both are also saved
67 // in the stack and cp is preserved by the call.
68 __ ldr(ip, CodeGenerator::GlobalObject());
69 __ push(ip);
70 __ mov(r2, Operand(name));
71 Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize));
72 __ Call(ic, RelocInfo::CODE_TARGET_CONTEXT);
73 if (has_this_properties()) {
74 // Restore this.
75 EmitLoadReceiver(r1);
76 }
77 }
78
79
80 void FastCodeGenerator::EmitThisPropertyStore(Handle<String> name) {
81 LookupResult lookup;
82 receiver()->Lookup(*name, &lookup);
83
84 ASSERT(lookup.holder() == *receiver());
85 ASSERT(lookup.type() == FIELD);
86 Handle<Map> map(Handle<HeapObject>::cast(receiver())->map());
87 int index = lookup.GetFieldIndex() - map->inobject_properties();
88 int offset = index * kPointerSize;
89
90 // Negative offsets are inobject properties.
91 if (offset < 0) {
92 offset += map->instance_size();
93 __ mov(r2, r1); // Copy receiver for write barrier.
94 } else {
95 offset += FixedArray::kHeaderSize;
96 __ ldr(r2, FieldMemOperand(r1, JSObject::kPropertiesOffset));
97 }
98 // Perform the store.
99 __ str(r0, FieldMemOperand(r2, offset));
100 __ mov(r3, Operand(offset));
101 __ RecordWrite(r2, r3, ip);
102 }
103
104
105 void FastCodeGenerator::Generate(FunctionLiteral* fun, CompilationInfo* info) {
106 ASSERT(function_ == NULL);
107 ASSERT(info_ == NULL);
108 function_ = fun;
109 info_ = info;
110
111 // Save the caller's frame pointer and set up our own.
112 Comment prologue_cmnt(masm(), ";; Prologue");
113 __ stm(db_w, sp, r1.bit() | cp.bit() | fp.bit() | lr.bit());
114 // Note that we keep a live register reference to cp (context) at
115 // this point.
116
117 // Receiver (this) is allocated to r1 if there are this properties.
118 if (has_this_properties()) EmitReceiverMapCheck();
119
120 VisitStatements(fun->body());
121
122 Comment return_cmnt(masm(), ";; Return(<undefined>)");
123 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex);
124
125 Comment epilogue_cmnt(masm(), ";; Epilogue");
126 __ mov(sp, fp);
127 __ ldm(ia_w, sp, fp.bit() | lr.bit());
128 int32_t sp_delta = (fun->scope()->num_parameters() + 1) * kPointerSize;
129 __ add(sp, sp, Operand(sp_delta));
130 __ Jump(lr);
131
132 __ bind(&bailout_);
133 }
134
135
136 #undef __
137
138
139 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/arm/codegen-arm.h ('k') | src/arm/full-codegen-arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698