| 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 17 matching lines...) Expand all Loading... |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "codegen-inl.h" | 30 #include "codegen-inl.h" |
| 31 #include "fast-codegen.h" | 31 #include "fast-codegen.h" |
| 32 | 32 |
| 33 namespace v8 { | 33 namespace v8 { |
| 34 namespace internal { | 34 namespace internal { |
| 35 | 35 |
| 36 #define __ ACCESS_MASM(masm()) | 36 #define __ ACCESS_MASM(masm()) |
| 37 | 37 |
| 38 void FastCodeGenerator::EmitLoadReceiver(Register reg) { | 38 // Registers rcx, rdi, and r8-r15 are free to use as scratch registers |
| 39 // without saving and restoring any other registers. |
| 40 Register FastCodeGenerator::accumulator0() { return rax; } |
| 41 Register FastCodeGenerator::accumulator1() { return rdx; } |
| 42 Register FastCodeGenerator::scratch0() { return rcx; } |
| 43 Register FastCodeGenerator::scratch1() { return rdi; } |
| 44 Register FastCodeGenerator::receiver_reg() { return rbx; } |
| 45 Register FastCodeGenerator::context_reg() { return rsi; } |
| 46 |
| 47 |
| 48 void FastCodeGenerator::EmitLoadReceiver() { |
| 39 // Offset 2 is due to return address and saved frame pointer. | 49 // Offset 2 is due to return address and saved frame pointer. |
| 40 int index = 2 + scope()->num_parameters(); | 50 int index = 2 + scope()->num_parameters(); |
| 41 __ movq(reg, Operand(rbp, index * kPointerSize)); | 51 __ movq(receiver_reg(), Operand(rbp, 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 ASSERT(info()->has_receiver() && info()->receiver()->IsHeapObject()); | |
| 52 Handle<HeapObject> object = Handle<HeapObject>::cast(info()->receiver()); | |
| 53 Handle<Map> map(object->map()); | |
| 54 | |
| 55 EmitLoadReceiver(rdx); | |
| 56 __ CheckMap(rdx, map, bailout(), false); | |
| 57 } | |
| 58 | |
| 59 | |
| 60 void FastCodeGenerator::EmitGlobalMapCheck() { | |
| 61 Comment cmnt(masm(), ";; GlobalMapCheck"); | |
| 62 if (FLAG_print_ir) { | |
| 63 PrintF(";; GlobalMapCheck()"); | |
| 64 } | |
| 65 | |
| 66 ASSERT(info()->has_global_object()); | |
| 67 Handle<Map> map(info()->global_object()->map()); | |
| 68 | |
| 69 __ movq(rbx, CodeGenerator::GlobalObject()); | |
| 70 __ CheckMap(rbx, map, bailout(), true); | |
| 71 } | 52 } |
| 72 | 53 |
| 73 | 54 |
| 74 void FastCodeGenerator::EmitGlobalVariableLoad(Handle<Object> cell) { | 55 void FastCodeGenerator::EmitGlobalVariableLoad(Handle<Object> cell) { |
| 75 ASSERT(cell->IsJSGlobalPropertyCell()); | 56 ASSERT(cell->IsJSGlobalPropertyCell()); |
| 76 __ Move(rax, cell); | 57 __ Move(accumulator0(), cell); |
| 77 __ movq(rax, FieldOperand(rax, JSGlobalPropertyCell::kValueOffset)); | 58 __ movq(accumulator0(), |
| 59 FieldOperand(accumulator0(), JSGlobalPropertyCell::kValueOffset)); |
| 78 if (FLAG_debug_code) { | 60 if (FLAG_debug_code) { |
| 79 __ Cmp(rax, Factory::the_hole_value()); | 61 __ Cmp(accumulator0(), Factory::the_hole_value()); |
| 80 __ Check(not_equal, "DontDelete cells can't contain the hole"); | 62 __ Check(not_equal, "DontDelete cells can't contain the hole"); |
| 81 } | 63 } |
| 82 } | 64 } |
| 83 | 65 |
| 84 | 66 |
| 85 void FastCodeGenerator::EmitThisPropertyStore(Handle<String> name) { | 67 void FastCodeGenerator::EmitThisPropertyStore(Handle<String> name) { |
| 86 LookupResult lookup; | 68 LookupResult lookup; |
| 87 info()->receiver()->Lookup(*name, &lookup); | 69 info()->receiver()->Lookup(*name, &lookup); |
| 88 | 70 |
| 89 ASSERT(lookup.holder() == *info()->receiver()); | 71 ASSERT(lookup.holder() == *info()->receiver()); |
| 90 ASSERT(lookup.type() == FIELD); | 72 ASSERT(lookup.type() == FIELD); |
| 91 Handle<Map> map(Handle<HeapObject>::cast(info()->receiver())->map()); | 73 Handle<Map> map(Handle<HeapObject>::cast(info()->receiver())->map()); |
| 92 int index = lookup.GetFieldIndex() - map->inobject_properties(); | 74 int index = lookup.GetFieldIndex() - map->inobject_properties(); |
| 93 int offset = index * kPointerSize; | 75 int offset = index * kPointerSize; |
| 94 | 76 |
| 95 // Negative offsets are inobject properties. | 77 // Negative offsets are inobject properties. |
| 96 if (offset < 0) { | 78 if (offset < 0) { |
| 97 offset += map->instance_size(); | 79 offset += map->instance_size(); |
| 98 __ movq(rcx, rdx); // Copy receiver for write barrier. | 80 __ movq(scratch0(), receiver_reg()); // Copy receiver for write barrier. |
| 99 } else { | 81 } else { |
| 100 offset += FixedArray::kHeaderSize; | 82 offset += FixedArray::kHeaderSize; |
| 101 __ movq(rcx, FieldOperand(rdx, JSObject::kPropertiesOffset)); | 83 __ movq(scratch0(), |
| 84 FieldOperand(receiver_reg(), JSObject::kPropertiesOffset)); |
| 102 } | 85 } |
| 103 // Perform the store. | 86 // Perform the store. |
| 104 __ movq(FieldOperand(rcx, offset), rax); | 87 __ movq(FieldOperand(scratch0(), offset), accumulator0()); |
| 105 // Preserve value from write barrier in case it's needed. | 88 // Preserve value from write barrier in case it's needed. |
| 106 __ movq(rbx, rax); | 89 __ movq(accumulator1(), accumulator0()); |
| 107 __ RecordWrite(rcx, offset, rbx, rdi); | 90 // The other accumulator register is available as a scratch register |
| 91 // because this is not an AST leaf node. |
| 92 __ RecordWrite(scratch0(), offset, accumulator1(), scratch1()); |
| 108 } | 93 } |
| 109 | 94 |
| 110 | 95 |
| 111 void FastCodeGenerator::Generate(CompilationInfo* compilation_info) { | 96 void FastCodeGenerator::Generate(CompilationInfo* compilation_info) { |
| 112 ASSERT(info_ == NULL); | 97 ASSERT(info_ == NULL); |
| 113 info_ = compilation_info; | 98 info_ = compilation_info; |
| 114 | 99 |
| 115 // Save the caller's frame pointer and set up our own. | 100 // Save the caller's frame pointer and set up our own. |
| 116 Comment prologue_cmnt(masm(), ";; Prologue"); | 101 Comment prologue_cmnt(masm(), ";; Prologue"); |
| 117 __ push(rbp); | 102 __ push(rbp); |
| 118 __ movq(rbp, rsp); | 103 __ movq(rbp, rsp); |
| 119 __ push(rsi); // Context. | 104 __ push(rsi); // Context. |
| 120 __ push(rdi); // Closure. | 105 __ push(rdi); // Closure. |
| 121 // Note that we keep a live register reference to esi (context) at this | 106 // Note that we keep a live register reference to esi (context) at this |
| 122 // point. | 107 // point. |
| 123 | 108 |
| 124 // Receiver (this) is allocated to rdx if there are this properties. | 109 // Receiver (this) is allocated to a fixed register. |
| 125 if (info()->has_this_properties()) EmitReceiverMapCheck(); | 110 if (info()->has_this_properties()) { |
| 111 Comment cmnt(masm(), ";; MapCheck(this)"); |
| 112 if (FLAG_print_ir) { |
| 113 PrintF("MapCheck(this)\n"); |
| 114 } |
| 115 ASSERT(info()->has_receiver() && info()->receiver()->IsHeapObject()); |
| 116 Handle<HeapObject> object = Handle<HeapObject>::cast(info()->receiver()); |
| 117 Handle<Map> map(object->map()); |
| 118 EmitLoadReceiver(); |
| 119 __ CheckMap(receiver_reg(), map, bailout(), false); |
| 120 } |
| 126 | 121 |
| 127 // If there is a global variable access check if the global object | 122 // If there is a global variable access check if the global object is the |
| 128 // is the same as at lazy-compilation time. | 123 // same as at lazy-compilation time. |
| 129 if (info()->has_globals()) EmitGlobalMapCheck(); | 124 if (info()->has_globals()) { |
| 125 Comment cmnt(masm(), ";; MapCheck(GLOBAL)"); |
| 126 if (FLAG_print_ir) { |
| 127 PrintF("MapCheck(GLOBAL)\n"); |
| 128 } |
| 129 ASSERT(info()->has_global_object()); |
| 130 Handle<Map> map(info()->global_object()->map()); |
| 131 __ movq(scratch0(), CodeGenerator::GlobalObject()); |
| 132 __ CheckMap(scratch0(), map, bailout(), true); |
| 133 } |
| 130 | 134 |
| 131 VisitStatements(info()->function()->body()); | 135 VisitStatements(info()->function()->body()); |
| 132 | 136 |
| 133 Comment return_cmnt(masm(), ";; Return(<undefined>)"); | 137 Comment return_cmnt(masm(), ";; Return(<undefined>)"); |
| 138 if (FLAG_print_ir) { |
| 139 PrintF("Return(<undefined>)\n"); |
| 140 } |
| 134 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); | 141 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
| 135 | |
| 136 Comment epilogue_cmnt(masm(), ";; Epilogue"); | |
| 137 __ movq(rsp, rbp); | 142 __ movq(rsp, rbp); |
| 138 __ pop(rbp); | 143 __ pop(rbp); |
| 139 __ ret((scope()->num_parameters() + 1) * kPointerSize); | 144 __ ret((scope()->num_parameters() + 1) * kPointerSize); |
| 140 | 145 |
| 141 __ bind(&bailout_); | 146 __ bind(&bailout_); |
| 142 } | 147 } |
| 143 | 148 |
| 144 | 149 |
| 145 #undef __ | 150 #undef __ |
| 146 | 151 |
| 147 | 152 |
| 148 } } // namespace v8::internal | 153 } } // namespace v8::internal |
| OLD | NEW |