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 25 matching lines...) Expand all Loading... |
36 | 36 |
37 // Forward declarations | 37 // Forward declarations |
38 class CompilationInfo; | 38 class CompilationInfo; |
39 class DeferredCode; | 39 class DeferredCode; |
40 class JumpTarget; | 40 class JumpTarget; |
41 class RegisterAllocator; | 41 class RegisterAllocator; |
42 class RegisterFile; | 42 class RegisterFile; |
43 | 43 |
44 enum InitState { CONST_INIT, NOT_CONST_INIT }; | 44 enum InitState { CONST_INIT, NOT_CONST_INIT }; |
45 enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF }; | 45 enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF }; |
| 46 enum GenerateInlineSmi { DONT_GENERATE_INLINE_SMI, GENERATE_INLINE_SMI }; |
46 | 47 |
47 | 48 |
48 // ------------------------------------------------------------------------- | 49 // ------------------------------------------------------------------------- |
49 // Reference support | 50 // Reference support |
50 | 51 |
51 // A reference is a C++ stack-allocated object that puts a | 52 // A reference is a C++ stack-allocated object that puts a |
52 // reference on the virtual frame. The reference may be consumed | 53 // reference on the virtual frame. The reference may be consumed |
53 // by GetValue, TakeValue, SetValue, and Codegen::UnloadReference. | 54 // by GetValue, TakeValue, SetValue, and Codegen::UnloadReference. |
54 // When the lifetime (scope) of a valid reference ends, it must have | 55 // When the lifetime (scope) of a valid reference ends, it must have |
55 // been consumed, and be in state UNLOADED. | 56 // been consumed, and be in state UNLOADED. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // the form of the state of the label pair). It is threaded through the | 123 // the form of the state of the label pair). It is threaded through the |
123 // call stack. Constructing a state implicitly pushes it on the owning code | 124 // call stack. Constructing a state implicitly pushes it on the owning code |
124 // generator's stack of states, and destroying one implicitly pops it. | 125 // generator's stack of states, and destroying one implicitly pops it. |
125 | 126 |
126 class CodeGenState BASE_EMBEDDED { | 127 class CodeGenState BASE_EMBEDDED { |
127 public: | 128 public: |
128 // Create an initial code generator state. Destroying the initial state | 129 // Create an initial code generator state. Destroying the initial state |
129 // leaves the code generator with a NULL state. | 130 // leaves the code generator with a NULL state. |
130 explicit CodeGenState(CodeGenerator* owner); | 131 explicit CodeGenState(CodeGenerator* owner); |
131 | 132 |
132 // Create a code generator state based on a code generator's current | |
133 // state. The new state has its own pair of branch labels. | |
134 CodeGenState(CodeGenerator* owner, | |
135 JumpTarget* true_target, | |
136 JumpTarget* false_target); | |
137 | |
138 // Destroy a code generator state and restore the owning code generator's | 133 // Destroy a code generator state and restore the owning code generator's |
139 // previous state. | 134 // previous state. |
140 ~CodeGenState(); | 135 virtual ~CodeGenState(); |
141 | 136 |
142 JumpTarget* true_target() const { return true_target_; } | 137 virtual JumpTarget* true_target() const { return NULL; } |
143 JumpTarget* false_target() const { return false_target_; } | 138 virtual JumpTarget* false_target() const { return NULL; } |
| 139 |
| 140 protected: |
| 141 inline CodeGenerator* owner() { return owner_; } |
| 142 inline CodeGenState* previous() const { return previous_; } |
144 | 143 |
145 private: | 144 private: |
146 CodeGenerator* owner_; | 145 CodeGenerator* owner_; |
| 146 CodeGenState* previous_; |
| 147 }; |
| 148 |
| 149 |
| 150 class ConditionCodeGenState : public CodeGenState { |
| 151 public: |
| 152 // Create a code generator state based on a code generator's current |
| 153 // state. The new state has its own pair of branch labels. |
| 154 ConditionCodeGenState(CodeGenerator* owner, |
| 155 JumpTarget* true_target, |
| 156 JumpTarget* false_target); |
| 157 |
| 158 virtual JumpTarget* true_target() const { return true_target_; } |
| 159 virtual JumpTarget* false_target() const { return false_target_; } |
| 160 |
| 161 private: |
147 JumpTarget* true_target_; | 162 JumpTarget* true_target_; |
148 JumpTarget* false_target_; | 163 JumpTarget* false_target_; |
149 CodeGenState* previous_; | 164 }; |
| 165 |
| 166 |
| 167 class TypeInfoCodeGenState : public CodeGenState { |
| 168 public: |
| 169 TypeInfoCodeGenState(CodeGenerator* owner, |
| 170 Slot* slot_number, |
| 171 TypeInfo info); |
| 172 ~TypeInfoCodeGenState(); |
| 173 |
| 174 virtual JumpTarget* true_target() const { return previous()->true_target(); } |
| 175 virtual JumpTarget* false_target() const { |
| 176 return previous()->false_target(); |
| 177 } |
| 178 |
| 179 private: |
| 180 Slot* slot_; |
| 181 TypeInfo old_type_info_; |
150 }; | 182 }; |
151 | 183 |
152 | 184 |
153 // ------------------------------------------------------------------------- | 185 // ------------------------------------------------------------------------- |
154 // Arguments allocation mode | 186 // Arguments allocation mode |
155 | 187 |
156 enum ArgumentsAllocationMode { | 188 enum ArgumentsAllocationMode { |
157 NO_ARGUMENTS_ALLOCATION, | 189 NO_ARGUMENTS_ALLOCATION, |
158 EAGER_ARGUMENTS_ALLOCATION, | 190 EAGER_ARGUMENTS_ALLOCATION, |
159 LAZY_ARGUMENTS_ALLOCATION | 191 LAZY_ARGUMENTS_ALLOCATION |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 // non_frame_registers. | 241 // non_frame_registers. |
210 void SetFrame(VirtualFrame* new_frame, RegisterFile* non_frame_registers); | 242 void SetFrame(VirtualFrame* new_frame, RegisterFile* non_frame_registers); |
211 | 243 |
212 void DeleteFrame(); | 244 void DeleteFrame(); |
213 | 245 |
214 RegisterAllocator* allocator() const { return allocator_; } | 246 RegisterAllocator* allocator() const { return allocator_; } |
215 | 247 |
216 CodeGenState* state() { return state_; } | 248 CodeGenState* state() { return state_; } |
217 void set_state(CodeGenState* state) { state_ = state; } | 249 void set_state(CodeGenState* state) { state_ = state; } |
218 | 250 |
| 251 TypeInfo type_info(Slot* slot) { |
| 252 int index = NumberOfSlot(slot); |
| 253 if (index == kInvalidSlotNumber) return TypeInfo::Unknown(); |
| 254 return (*type_info_)[index]; |
| 255 } |
| 256 |
| 257 TypeInfo set_type_info(Slot* slot, TypeInfo info) { |
| 258 int index = NumberOfSlot(slot); |
| 259 ASSERT(index >= kInvalidSlotNumber); |
| 260 if (index != kInvalidSlotNumber) { |
| 261 TypeInfo previous_value = (*type_info_)[index]; |
| 262 (*type_info_)[index] = info; |
| 263 return previous_value; |
| 264 } |
| 265 return TypeInfo::Unknown(); |
| 266 } |
| 267 |
219 void AddDeferred(DeferredCode* code) { deferred_.Add(code); } | 268 void AddDeferred(DeferredCode* code) { deferred_.Add(code); } |
220 | 269 |
221 static const int kUnknownIntValue = -1; | 270 static const int kUnknownIntValue = -1; |
222 | 271 |
223 // If the name is an inline runtime function call return the number of | 272 // If the name is an inline runtime function call return the number of |
224 // expected arguments. Otherwise return -1. | 273 // expected arguments. Otherwise return -1. |
225 static int InlineRuntimeCallArgumentsCount(Handle<String> name); | 274 static int InlineRuntimeCallArgumentsCount(Handle<String> name); |
226 | 275 |
227 // Constants related to patching of inlined load/store. | 276 // Constants related to patching of inlined load/store. |
228 static const int kInlinedKeyedLoadInstructionsAfterPatch = 19; | 277 static const int kInlinedKeyedLoadInstructionsAfterPatch = 17; |
229 static const int kInlinedKeyedStoreInstructionsAfterPatch = 5; | 278 static const int kInlinedKeyedStoreInstructionsAfterPatch = 5; |
230 | 279 |
231 private: | 280 private: |
232 // Construction/Destruction | 281 // Construction/Destruction |
233 explicit CodeGenerator(MacroAssembler* masm); | 282 explicit CodeGenerator(MacroAssembler* masm); |
234 | 283 |
235 // Accessors | 284 // Accessors |
236 inline bool is_eval(); | 285 inline bool is_eval(); |
237 inline Scope* scope(); | 286 inline Scope* scope(); |
238 | 287 |
239 // Generating deferred code. | 288 // Generating deferred code. |
240 void ProcessDeferred(); | 289 void ProcessDeferred(); |
241 | 290 |
| 291 static const int kInvalidSlotNumber = -1; |
| 292 |
| 293 int NumberOfSlot(Slot* slot); |
| 294 |
242 // State | 295 // State |
243 bool has_cc() const { return cc_reg_ != al; } | 296 bool has_cc() const { return cc_reg_ != al; } |
244 JumpTarget* true_target() const { return state_->true_target(); } | 297 JumpTarget* true_target() const { return state_->true_target(); } |
245 JumpTarget* false_target() const { return state_->false_target(); } | 298 JumpTarget* false_target() const { return state_->false_target(); } |
246 | 299 |
247 // Track loop nesting level. | 300 // Track loop nesting level. |
248 int loop_nesting() const { return loop_nesting_; } | 301 int loop_nesting() const { return loop_nesting_; } |
249 void IncrementLoopNesting() { loop_nesting_++; } | 302 void IncrementLoopNesting() { loop_nesting_++; } |
250 void DecrementLoopNesting() { loop_nesting_--; } | 303 void DecrementLoopNesting() { loop_nesting_--; } |
251 | 304 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 // non-existing properties of the global object, so we must make it | 395 // non-existing properties of the global object, so we must make it |
343 // look like an explicit property access, instead of an access | 396 // look like an explicit property access, instead of an access |
344 // through the context chain. | 397 // through the context chain. |
345 void LoadTypeofExpression(Expression* x); | 398 void LoadTypeofExpression(Expression* x); |
346 | 399 |
347 void ToBoolean(JumpTarget* true_target, JumpTarget* false_target); | 400 void ToBoolean(JumpTarget* true_target, JumpTarget* false_target); |
348 | 401 |
349 // Generate code that computes a shortcutting logical operation. | 402 // Generate code that computes a shortcutting logical operation. |
350 void GenerateLogicalBooleanOperation(BinaryOperation* node); | 403 void GenerateLogicalBooleanOperation(BinaryOperation* node); |
351 | 404 |
352 void GenericBinaryOperation(Token::Value op, | |
353 OverwriteMode overwrite_mode, | |
354 int known_rhs = kUnknownIntValue); | |
355 void VirtualFrameBinaryOperation(Token::Value op, | 405 void VirtualFrameBinaryOperation(Token::Value op, |
356 OverwriteMode overwrite_mode, | 406 OverwriteMode overwrite_mode, |
| 407 GenerateInlineSmi inline_smi, |
357 int known_rhs = kUnknownIntValue); | 408 int known_rhs = kUnknownIntValue); |
358 void Comparison(Condition cc, | 409 void Comparison(Condition cc, |
359 Expression* left, | 410 Expression* left, |
360 Expression* right, | 411 Expression* right, |
361 bool strict = false); | 412 bool strict = false); |
362 | 413 |
363 void SmiOperation(Token::Value op, | 414 void SmiOperation(Token::Value op, |
364 Handle<Object> value, | 415 Handle<Object> value, |
365 bool reversed, | 416 bool reversed, |
366 OverwriteMode mode); | 417 OverwriteMode mode); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 | 555 |
505 CompilationInfo* info_; | 556 CompilationInfo* info_; |
506 | 557 |
507 // Code generation state | 558 // Code generation state |
508 VirtualFrame* frame_; | 559 VirtualFrame* frame_; |
509 RegisterAllocator* allocator_; | 560 RegisterAllocator* allocator_; |
510 Condition cc_reg_; | 561 Condition cc_reg_; |
511 CodeGenState* state_; | 562 CodeGenState* state_; |
512 int loop_nesting_; | 563 int loop_nesting_; |
513 | 564 |
| 565 Vector<TypeInfo>* type_info_; |
| 566 |
514 // Jump targets | 567 // Jump targets |
515 BreakTarget function_return_; | 568 BreakTarget function_return_; |
516 | 569 |
517 // True if the function return is shadowed (ie, jumping to the target | 570 // True if the function return is shadowed (ie, jumping to the target |
518 // function_return_ does not jump to the true function return, but rather | 571 // function_return_ does not jump to the true function return, but rather |
519 // to some unlinking code). | 572 // to some unlinking code). |
520 bool function_return_is_shadowed_; | 573 bool function_return_is_shadowed_; |
521 | 574 |
522 static InlineRuntimeLUT kInlineRuntimeLUT[]; | 575 static InlineRuntimeLUT kInlineRuntimeLUT[]; |
523 | 576 |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 return ObjectBits::encode(object_.code()) | | 959 return ObjectBits::encode(object_.code()) | |
907 OffsetBits::encode(offset_.code()) | | 960 OffsetBits::encode(offset_.code()) | |
908 ScratchBits::encode(scratch_.code()); | 961 ScratchBits::encode(scratch_.code()); |
909 } | 962 } |
910 }; | 963 }; |
911 | 964 |
912 | 965 |
913 } } // namespace v8::internal | 966 } } // namespace v8::internal |
914 | 967 |
915 #endif // V8_ARM_CODEGEN_ARM_H_ | 968 #endif // V8_ARM_CODEGEN_ARM_H_ |
OLD | NEW |