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

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

Issue 586002: Added helper functions for fixed register allocation. (Closed)
Patch Set: 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/fast-codegen.h ('k') | src/x64/fast-codegen-x64.cc » ('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 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
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 Register FastCodeGenerator::accumulator0() { return eax; }
39 Register FastCodeGenerator::accumulator1() { return edx; }
40 Register FastCodeGenerator::scratch0() { return ecx; }
41 Register FastCodeGenerator::scratch1() { return edi; }
42 Register FastCodeGenerator::receiver_reg() { return ebx; }
43 Register FastCodeGenerator::context_reg() { return esi; }
44
45
46 void FastCodeGenerator::EmitLoadReceiver() {
39 // Offset 2 is due to return address and saved frame pointer. 47 // Offset 2 is due to return address and saved frame pointer.
40 int index = 2 + function()->scope()->num_parameters(); 48 int index = 2 + function()->scope()->num_parameters();
41 __ mov(reg, Operand(ebp, index * kPointerSize)); 49 __ mov(receiver_reg(), Operand(ebp, 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(edx);
56 __ CheckMap(edx, 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 __ mov(ebx, CodeGenerator::GlobalObject());
70 __ CheckMap(ebx, map, bailout(), true);
71 } 50 }
72 51
73 52
74 void FastCodeGenerator::EmitGlobalVariableLoad(Handle<Object> cell) { 53 void FastCodeGenerator::EmitGlobalVariableLoad(Handle<Object> cell) {
75 ASSERT(cell->IsJSGlobalPropertyCell()); 54 ASSERT(cell->IsJSGlobalPropertyCell());
76 __ mov(eax, Immediate(cell)); 55 __ mov(accumulator0(), Immediate(cell));
77 __ mov(eax, FieldOperand(eax, JSGlobalPropertyCell::kValueOffset)); 56 __ mov(accumulator0(),
57 FieldOperand(accumulator0(), JSGlobalPropertyCell::kValueOffset));
78 if (FLAG_debug_code) { 58 if (FLAG_debug_code) {
79 __ cmp(eax, Factory::the_hole_value()); 59 __ cmp(accumulator0(), Factory::the_hole_value());
80 __ Check(not_equal, "DontDelete cells can't contain the hole"); 60 __ Check(not_equal, "DontDelete cells can't contain the hole");
81 } 61 }
82 } 62 }
83 63
84 64
85 void FastCodeGenerator::EmitThisPropertyStore(Handle<String> name) { 65 void FastCodeGenerator::EmitThisPropertyStore(Handle<String> name) {
86 LookupResult lookup; 66 LookupResult lookup;
87 info()->receiver()->Lookup(*name, &lookup); 67 info()->receiver()->Lookup(*name, &lookup);
88 68
89 ASSERT(lookup.holder() == *info()->receiver()); 69 ASSERT(lookup.holder() == *info()->receiver());
90 ASSERT(lookup.type() == FIELD); 70 ASSERT(lookup.type() == FIELD);
91 Handle<Map> map(Handle<HeapObject>::cast(info()->receiver())->map()); 71 Handle<Map> map(Handle<HeapObject>::cast(info()->receiver())->map());
92 int index = lookup.GetFieldIndex() - map->inobject_properties(); 72 int index = lookup.GetFieldIndex() - map->inobject_properties();
93 int offset = index * kPointerSize; 73 int offset = index * kPointerSize;
94 74
95 // Negative offsets are inobject properties. 75 // Negative offsets are inobject properties.
96 if (offset < 0) { 76 if (offset < 0) {
97 offset += map->instance_size(); 77 offset += map->instance_size();
98 __ mov(ecx, edx); // Copy receiver for write barrier. 78 __ mov(scratch0(), receiver_reg()); // Copy receiver for write barrier.
99 } else { 79 } else {
100 offset += FixedArray::kHeaderSize; 80 offset += FixedArray::kHeaderSize;
101 __ mov(ecx, FieldOperand(edx, JSObject::kPropertiesOffset)); 81 __ mov(scratch0(),
82 FieldOperand(receiver_reg(), JSObject::kPropertiesOffset));
102 } 83 }
103 // Perform the store. 84 // Perform the store.
104 __ mov(FieldOperand(ecx, offset), eax); 85 __ mov(FieldOperand(scratch0(), offset), accumulator0());
105 // Preserve value from write barrier in case it's needed. 86 // Preserve value from write barrier in case it's needed.
106 __ mov(ebx, eax); 87 __ mov(accumulator1(), accumulator0());
fschneider 2010/02/09 09:38:32 As a separate change: Would it make sense to have
107 __ RecordWrite(ecx, offset, ebx, edi); 88 // The other accumulator register is available as a scratch register
89 // because this is not an AST leaf node.
90 __ RecordWrite(scratch0(), offset, accumulator1(), scratch1());
108 } 91 }
109 92
110 93
111 void FastCodeGenerator::Generate(CompilationInfo* compilation_info) { 94 void FastCodeGenerator::Generate(CompilationInfo* compilation_info) {
112 ASSERT(info_ == NULL); 95 ASSERT(info_ == NULL);
113 info_ = compilation_info; 96 info_ = compilation_info;
114 97
115 // Save the caller's frame pointer and set up our own. 98 // Save the caller's frame pointer and set up our own.
116 Comment prologue_cmnt(masm(), ";; Prologue"); 99 Comment prologue_cmnt(masm(), ";; Prologue");
117 __ push(ebp); 100 __ push(ebp);
118 __ mov(ebp, esp); 101 __ mov(ebp, esp);
119 __ push(esi); // Context. 102 __ push(esi); // Context.
120 __ push(edi); // Closure. 103 __ push(edi); // Closure.
121 // Note that we keep a live register reference to esi (context) at this 104 // Note that we keep a live register reference to esi (context) at this
122 // point. 105 // point.
123 106
124 // Receiver (this) is allocated to edx if there are this properties. 107 // Receiver (this) is allocated to a fixed register.
125 if (info()->has_this_properties()) EmitReceiverMapCheck(); 108 if (info()->has_this_properties()) {
109 Comment cmnt(masm(), ";; MapCheck(this)");
110 if (FLAG_print_ir) {
111 PrintF("MapCheck(this)\n");
112 }
113 ASSERT(info()->has_receiver() && info()->receiver()->IsHeapObject());
114 Handle<HeapObject> object = Handle<HeapObject>::cast(info()->receiver());
115 Handle<Map> map(object->map());
116 EmitLoadReceiver();
117 __ CheckMap(receiver_reg(), map, bailout(), false);
118 }
126 119
127 // If there is a global variable access check if the global object 120 // If there is a global variable access check if the global object is the
128 // is the same as at lazy-compilation time. 121 // same as at lazy-compilation time.
129 if (info()->has_globals()) EmitGlobalMapCheck(); 122 if (info()->has_globals()) {
123 Comment cmnt(masm(), ";; MapCheck(GLOBAL)");
124 if (FLAG_print_ir) {
125 PrintF("MapCheck(GLOBAL)\n");
126 }
127 ASSERT(info()->has_global_object());
128 Handle<Map> map(info()->global_object()->map());
129 __ mov(scratch0(), CodeGenerator::GlobalObject());
130 __ CheckMap(scratch0(), map, bailout(), true);
131 }
130 132
131 VisitStatements(function()->body()); 133 VisitStatements(function()->body());
132 134
133 Comment return_cmnt(masm(), ";; Return(<undefined>)"); 135 Comment return_cmnt(masm(), ";; Return(<undefined>)");
136 if (FLAG_print_ir) {
137 PrintF("Return(<undefined>)\n");
138 }
134 __ mov(eax, Factory::undefined_value()); 139 __ mov(eax, Factory::undefined_value());
135
136 Comment epilogue_cmnt(masm(), ";; Epilogue");
137 __ mov(esp, ebp); 140 __ mov(esp, ebp);
138 __ pop(ebp); 141 __ pop(ebp);
139 __ ret((scope()->num_parameters() + 1) * kPointerSize); 142 __ ret((scope()->num_parameters() + 1) * kPointerSize);
140 143
141 __ bind(&bailout_); 144 __ bind(&bailout_);
142 } 145 }
143 146
144 147
145 #undef __ 148 #undef __
146 149
147 150
148 } } // namespace v8::internal 151 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/fast-codegen.h ('k') | src/x64/fast-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698