OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 30 matching lines...) Expand all Loading... |
41 __ ldr(reg, MemOperand(sp, index * kPointerSize)); | 41 __ ldr(reg, MemOperand(sp, index * kPointerSize)); |
42 } | 42 } |
43 | 43 |
44 | 44 |
45 void FastCodeGenerator::EmitReceiverMapCheck() { | 45 void FastCodeGenerator::EmitReceiverMapCheck() { |
46 Comment cmnt(masm(), ";; MapCheck(this)"); | 46 Comment cmnt(masm(), ";; MapCheck(this)"); |
47 if (FLAG_print_ir) { | 47 if (FLAG_print_ir) { |
48 PrintF("MapCheck(this)\n"); | 48 PrintF("MapCheck(this)\n"); |
49 } | 49 } |
50 | 50 |
| 51 ASSERT(info()->has_receiver() && info()->receiver()->IsHeapObject()); |
| 52 Handle<HeapObject> object = Handle<HeapObject>::cast(info()->receiver()); |
| 53 Handle<Map> map(object->map()); |
| 54 |
51 EmitLoadReceiver(r1); | 55 EmitLoadReceiver(r1); |
52 __ BranchOnSmi(r1, bailout()); | 56 __ CheckMap(r1, r3, map, bailout(), false); |
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 } | 57 } |
62 | 58 |
63 | 59 |
64 void FastCodeGenerator::EmitGlobalVariableLoad(Handle<String> name) { | 60 void FastCodeGenerator::EmitGlobalMapCheck() { |
65 // Compile global variable accesses as load IC calls. The only live | 61 Comment cmnt(masm(), ";; GlobalMapCheck"); |
66 // registers are cp (context) and possibly r1 (this). Both are also saved | 62 if (FLAG_print_ir) { |
67 // in the stack and cp is preserved by the call. | 63 PrintF(";; GlobalMapCheck()"); |
68 __ ldr(ip, CodeGenerator::GlobalObject()); | 64 } |
69 __ push(ip); | 65 |
70 __ mov(r2, Operand(name)); | 66 ASSERT(info()->has_global_object()); |
71 Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); | 67 Handle<Map> map(info()->global_object()->map()); |
72 __ Call(ic, RelocInfo::CODE_TARGET_CONTEXT); | 68 |
73 if (has_this_properties()) { | 69 __ ldr(r3, CodeGenerator::GlobalObject()); |
74 // Restore this. | 70 __ CheckMap(r3, r3, map, bailout(), true); |
75 EmitLoadReceiver(r1); | 71 } |
| 72 |
| 73 |
| 74 void FastCodeGenerator::EmitGlobalVariableLoad(Handle<Object> cell) { |
| 75 ASSERT(cell->IsJSGlobalPropertyCell()); |
| 76 __ mov(r0, Operand(cell)); |
| 77 __ ldr(r0, FieldMemOperand(r0, JSGlobalPropertyCell::kValueOffset)); |
| 78 if (FLAG_debug_code) { |
| 79 __ mov(ip, Operand(Factory::the_hole_value())); |
| 80 __ cmp(r0, ip); |
| 81 __ Check(ne, "DontDelete cells can't contain the hole"); |
76 } | 82 } |
77 } | 83 } |
78 | 84 |
79 | 85 |
80 void FastCodeGenerator::EmitThisPropertyStore(Handle<String> name) { | 86 void FastCodeGenerator::EmitThisPropertyStore(Handle<String> name) { |
81 LookupResult lookup; | 87 LookupResult lookup; |
82 receiver()->Lookup(*name, &lookup); | 88 info()->receiver()->Lookup(*name, &lookup); |
83 | 89 |
84 ASSERT(lookup.holder() == *receiver()); | 90 ASSERT(lookup.holder() == *info()->receiver()); |
85 ASSERT(lookup.type() == FIELD); | 91 ASSERT(lookup.type() == FIELD); |
86 Handle<Map> map(Handle<HeapObject>::cast(receiver())->map()); | 92 Handle<Map> map(Handle<HeapObject>::cast(info()->receiver())->map()); |
87 int index = lookup.GetFieldIndex() - map->inobject_properties(); | 93 int index = lookup.GetFieldIndex() - map->inobject_properties(); |
88 int offset = index * kPointerSize; | 94 int offset = index * kPointerSize; |
89 | 95 |
90 // Negative offsets are inobject properties. | 96 // Negative offsets are inobject properties. |
91 if (offset < 0) { | 97 if (offset < 0) { |
92 offset += map->instance_size(); | 98 offset += map->instance_size(); |
93 __ mov(r2, r1); // Copy receiver for write barrier. | 99 __ mov(r2, r1); // Copy receiver for write barrier. |
94 } else { | 100 } else { |
95 offset += FixedArray::kHeaderSize; | 101 offset += FixedArray::kHeaderSize; |
96 __ ldr(r2, FieldMemOperand(r1, JSObject::kPropertiesOffset)); | 102 __ ldr(r2, FieldMemOperand(r1, JSObject::kPropertiesOffset)); |
97 } | 103 } |
98 // Perform the store. | 104 // Perform the store. |
99 __ str(r0, FieldMemOperand(r2, offset)); | 105 __ str(r0, FieldMemOperand(r2, offset)); |
100 __ mov(r3, Operand(offset)); | 106 __ mov(r3, Operand(offset)); |
101 __ RecordWrite(r2, r3, ip); | 107 __ RecordWrite(r2, r3, ip); |
102 } | 108 } |
103 | 109 |
104 | 110 |
105 void FastCodeGenerator::Generate(CompilationInfo* info) { | 111 void FastCodeGenerator::Generate(CompilationInfo* compilation_info) { |
106 ASSERT(info_ == NULL); | 112 ASSERT(info_ == NULL); |
107 info_ = info; | 113 info_ = compilation_info; |
108 | 114 |
109 // Save the caller's frame pointer and set up our own. | 115 // Save the caller's frame pointer and set up our own. |
110 Comment prologue_cmnt(masm(), ";; Prologue"); | 116 Comment prologue_cmnt(masm(), ";; Prologue"); |
111 __ stm(db_w, sp, r1.bit() | cp.bit() | fp.bit() | lr.bit()); | 117 __ stm(db_w, sp, r1.bit() | cp.bit() | fp.bit() | lr.bit()); |
112 __ add(fp, sp, Operand(2 * kPointerSize)); | 118 __ add(fp, sp, Operand(2 * kPointerSize)); |
113 // Note that we keep a live register reference to cp (context) at | 119 // Note that we keep a live register reference to cp (context) at |
114 // this point. | 120 // this point. |
115 | 121 |
116 // Receiver (this) is allocated to r1 if there are this properties. | 122 // Receiver (this) is allocated to r1 if there are this properties. |
117 if (has_this_properties()) EmitReceiverMapCheck(); | 123 if (info()->has_this_properties()) EmitReceiverMapCheck(); |
| 124 |
| 125 // If there is a global variable access check if the global object |
| 126 // is the same as at lazy-compilation time. |
| 127 if (info()->has_globals()) EmitGlobalMapCheck(); |
118 | 128 |
119 VisitStatements(function()->body()); | 129 VisitStatements(function()->body()); |
120 | 130 |
121 Comment return_cmnt(masm(), ";; Return(<undefined>)"); | 131 Comment return_cmnt(masm(), ";; Return(<undefined>)"); |
122 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); | 132 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
123 | 133 |
124 Comment epilogue_cmnt(masm(), ";; Epilogue"); | 134 Comment epilogue_cmnt(masm(), ";; Epilogue"); |
125 __ mov(sp, fp); | 135 __ mov(sp, fp); |
126 __ ldm(ia_w, sp, fp.bit() | lr.bit()); | 136 __ ldm(ia_w, sp, fp.bit() | lr.bit()); |
127 int32_t sp_delta = (scope()->num_parameters() + 1) * kPointerSize; | 137 int32_t sp_delta = (scope()->num_parameters() + 1) * kPointerSize; |
128 __ add(sp, sp, Operand(sp_delta)); | 138 __ add(sp, sp, Operand(sp_delta)); |
129 __ Jump(lr); | 139 __ Jump(lr); |
130 | 140 |
131 __ bind(&bailout_); | 141 __ bind(&bailout_); |
132 } | 142 } |
133 | 143 |
134 | 144 |
135 #undef __ | 145 #undef __ |
136 | 146 |
137 | 147 |
138 } } // namespace v8::internal | 148 } } // namespace v8::internal |
OLD | NEW |