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
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.
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.
28 #ifndef V8_ARM_CODEGEN_ARM_H_
29 #define V8_ARM_CODEGEN_ARM_H_
37 // Forward declarations
38 class CompilationInfo;
41 class RegisterAllocator;
44 enum InitState { CONST_INIT, NOT_CONST_INIT };
45 enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF };
48 // -------------------------------------------------------------------------
51 // A reference is a C++ stack-allocated object that puts a
52 // reference on the virtual frame. The reference may be consumed
53 // by GetValue, TakeValue, SetValue, and Codegen::UnloadReference.
54 // When the lifetime (scope) of a valid reference ends, it must have
55 // been consumed, and be in state UNLOADED.
56 class Reference BASE_EMBEDDED {
58 // The values of the types is important, see size().
59 enum Type { UNLOADED = -2, ILLEGAL = -1, SLOT = 0, NAMED = 1, KEYED = 2 };
60 Reference(CodeGenerator* cgen,
61 Expression* expression,
62 bool persist_after_get = false);
65 Expression* expression() const { return expression_; }
66 Type type() const { return type_; }
67 void set_type(Type value) {
68 ASSERT_EQ(ILLEGAL, type_);
73 ASSERT_NE(ILLEGAL, type_);
74 ASSERT_NE(UNLOADED, type_);
77 // The size the reference takes up on the stack.
79 return (type_ < SLOT) ? 0 : type_;
82 bool is_illegal() const { return type_ == ILLEGAL; }
83 bool is_slot() const { return type_ == SLOT; }
84 bool is_property() const { return type_ == NAMED || type_ == KEYED; }
85 bool is_unloaded() const { return type_ == UNLOADED; }
87 // Return the name. Only valid for named property references.
88 Handle<String> GetName();
90 // Generate code to push the value of the reference on top of the
91 // expression stack. The reference is expected to be already on top of
92 // the expression stack, and it is consumed by the call unless the
93 // reference is for a compound assignment.
94 // If the reference is not consumed, it is left in place under its value.
97 // Generate code to store the value on top of the expression stack in the
98 // reference. The reference is expected to be immediately below the value
99 // on the expression stack. The value is stored in the location specified
100 // by the reference, and is left on top of the stack, after the reference
101 // is popped from beneath it (unloaded).
102 void SetValue(InitState init_state);
104 // This is in preparation for something that uses the reference on the stack.
105 // If we need this reference afterwards get then dup it now. Otherwise mark
107 inline void DupIfPersist();
110 CodeGenerator* cgen_;
111 Expression* expression_;
113 // Keep the reference on the stack after get, so it can be used by set later.
114 bool persist_after_get_;
118 // -------------------------------------------------------------------------
119 // Code generation state
121 // The state is passed down the AST by the code generator (and back up, in
122 // 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 // generator's stack of states, and destroying one implicitly pops it.
126 class CodeGenState BASE_EMBEDDED {
128 // Create an initial code generator state. Destroying the initial state
129 // leaves the code generator with a NULL state.
130 explicit CodeGenState(CodeGenerator* owner);
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);
138 // Destroy a code generator state and restore the owning code generator's
142 JumpTarget* true_target() const { return true_target_; }
143 JumpTarget* false_target() const { return false_target_; }
146 CodeGenerator* owner_;
147 JumpTarget* true_target_;
148 JumpTarget* false_target_;
149 CodeGenState* previous_;
153 // -------------------------------------------------------------------------
154 // Arguments allocation mode
156 enum ArgumentsAllocationMode {
157 NO_ARGUMENTS_ALLOCATION,
158 EAGER_ARGUMENTS_ALLOCATION,
159 LAZY_ARGUMENTS_ALLOCATION
163 // Different nop operations are used by the code generator to detect certain
164 // states of the generated code.
165 enum NopMarkerTypes {
167 PROPERTY_ACCESS_INLINED
171 // -------------------------------------------------------------------------
174 class CodeGenerator: public AstVisitor {
176 // Takes a function literal, generates code for it. This function should only
177 // be called by compiler.cc.
178 static Handle<Code> MakeCode(CompilationInfo* info);
180 // Printing of AST, etc. as requested by flags.
181 static void MakeCodePrologue(CompilationInfo* info);
183 // Allocate and install the code.
184 static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm,
186 CompilationInfo* info);
188 #ifdef ENABLE_LOGGING_AND_PROFILING
189 static bool ShouldGenerateLog(Expression* type);
192 static void SetFunctionInfo(Handle<JSFunction> fun,
193 FunctionLiteral* lit,
195 Handle<Script> script);
197 static void RecordPositions(MacroAssembler* masm, int pos);
200 MacroAssembler* masm() { return masm_; }
201 VirtualFrame* frame() const { return frame_; }
202 inline Handle<Script> script();
204 bool has_valid_frame() const { return frame_ != NULL; }
206 // Set the virtual frame to be new_frame, with non-frame register
207 // reference counts given by non_frame_registers. The non-frame
208 // register reference counts of the old frame are returned in
209 // non_frame_registers.
210 void SetFrame(VirtualFrame* new_frame, RegisterFile* non_frame_registers);
214 RegisterAllocator* allocator() const { return allocator_; }
216 CodeGenState* state() { return state_; }
217 void set_state(CodeGenState* state) { state_ = state; }
219 void AddDeferred(DeferredCode* code) { deferred_.Add(code); }
221 static const int kUnknownIntValue = -1;
223 // If the name is an inline runtime function call return the number of
224 // expected arguments. Otherwise return -1.
225 static int InlineRuntimeCallArgumentsCount(Handle<String> name);
227 // Constants related to patching of inlined load/store.
228 static const int kInlinedKeyedLoadInstructionsAfterPatch = 19;
229 static const int kInlinedKeyedStoreInstructionsAfterPatch = 5;
232 // Construction/Destruction
233 explicit CodeGenerator(MacroAssembler* masm);
236 inline bool is_eval();
237 inline Scope* scope();
239 // Generating deferred code.
240 void ProcessDeferred();
243 bool has_cc() const { return cc_reg_ != al; }
244 JumpTarget* true_target() const { return state_->true_target(); }
245 JumpTarget* false_target() const { return state_->false_target(); }
247 // Track loop nesting level.
248 int loop_nesting() const { return loop_nesting_; }
249 void IncrementLoopNesting() { loop_nesting_++; }
250 void DecrementLoopNesting() { loop_nesting_--; }
253 void VisitStatements(ZoneList<Statement*>* statements);
255 #define DEF_VISIT(type) \
256 void Visit##type(type* node);
257 AST_NODE_LIST(DEF_VISIT)
260 // Visit a statement and then spill the virtual frame if control flow can
261 // reach the end of the statement (ie, it does not exit via break,
262 // continue, return, or throw). This function is used temporarily while
263 // the code generator is being transformed.
264 inline void VisitAndSpill(Statement* statement);
266 // Visit a list of statements and then spill the virtual frame if control
267 // flow can reach the end of the list.
268 inline void VisitStatementsAndSpill(ZoneList<Statement*>* statements);
270 // Main code generation function
271 void Generate(CompilationInfo* info);
273 // Returns the arguments allocation mode.
274 ArgumentsAllocationMode ArgumentsMode();
276 // Store the arguments object and allocate it if necessary.
277 void StoreArgumentsObject(bool initial);
279 // The following are used by class Reference.
280 void LoadReference(Reference* ref);
281 void UnloadReference(Reference* ref);
283 static MemOperand ContextOperand(Register context, int index) {
284 return MemOperand(context, Context::SlotOffset(index));
287 MemOperand SlotOperand(Slot* slot, Register tmp);
289 MemOperand ContextSlotOperandCheckExtensions(Slot* slot,
295 static MemOperand GlobalObject() {
296 return ContextOperand(cp, Context::GLOBAL_INDEX);
299 void LoadCondition(Expression* x,
300 JumpTarget* true_target,
301 JumpTarget* false_target,
303 void Load(Expression* expr);
305 void LoadGlobalReceiver(Register scratch);
307 // Generate code to push the value of an expression on top of the frame
308 // and then spill the frame fully to memory. This function is used
309 // temporarily while the code generator is being transformed.
310 inline void LoadAndSpill(Expression* expression);
312 // Call LoadCondition and then spill the virtual frame unless control flow
313 // cannot reach the end of the expression (ie, by emitting only
314 // unconditional jumps to the control targets).
315 inline void LoadConditionAndSpill(Expression* expression,
316 JumpTarget* true_target,
317 JumpTarget* false_target,
320 // Read a value from a slot and leave it on top of the expression stack.
321 void LoadFromSlot(Slot* slot, TypeofState typeof_state);
322 void LoadFromSlotCheckForArguments(Slot* slot, TypeofState state);
324 // Store the value on top of the stack to a slot.
325 void StoreToSlot(Slot* slot, InitState init_state);
327 // Support for compiling assignment expressions.
328 void EmitSlotAssignment(Assignment* node);
329 void EmitNamedPropertyAssignment(Assignment* node);
330 void EmitKeyedPropertyAssignment(Assignment* node);
332 // Load a named property, returning it in r0. The receiver is passed on the
333 // stack, and remains there.
334 void EmitNamedLoad(Handle<String> name, bool is_contextual);
336 // Store to a named property. If the store is contextual, value is passed on
337 // the frame and consumed. Otherwise, receiver and value are passed on the
338 // frame and consumed. The result is returned in r0.
339 void EmitNamedStore(Handle<String> name, bool is_contextual);
341 // Load a keyed property, leaving it in r0. The receiver and key are
342 // passed on the stack, and remain there.
343 void EmitKeyedLoad();
345 // Store a keyed property. Key and receiver are on the stack and the value is
346 // in r0. Result is returned in r0.
347 void EmitKeyedStore(StaticType* key_type);
349 void LoadFromGlobalSlotCheckExtensions(Slot* slot,
350 TypeofState typeof_state,
353 // Support for loading from local/global variables and arguments
354 // whose location is known unless they are shadowed by
355 // eval-introduced bindings. Generates no code for unsupported slot
356 // types and therefore expects to fall through to the slow jump target.
357 void EmitDynamicLoadFromSlotFastCase(Slot* slot,
358 TypeofState typeof_state,
362 // Special code for typeof expressions: Unfortunately, we must
363 // be careful when loading the expression in 'typeof'
364 // expressions. We are not allowed to throw reference errors for
365 // non-existing properties of the global object, so we must make it
366 // look like an explicit property access, instead of an access
367 // through the context chain.
368 void LoadTypeofExpression(Expression* x);
370 void ToBoolean(JumpTarget* true_target, JumpTarget* false_target);
372 // Generate code that computes a shortcutting logical operation.
373 void GenerateLogicalBooleanOperation(BinaryOperation* node);
375 void GenericBinaryOperation(Token::Value op,
376 OverwriteMode overwrite_mode,
377 int known_rhs = kUnknownIntValue);
378 void VirtualFrameBinaryOperation(Token::Value op,
379 OverwriteMode overwrite_mode,
380 int known_rhs = kUnknownIntValue);
381 void Comparison(Condition cc,
384 bool strict = false);
386 void SmiOperation(Token::Value op,
387 Handle<Object> value,
391 void CallWithArguments(ZoneList<Expression*>* arguments,
392 CallFunctionFlags flags,
395 // An optimized implementation of expressions of the form
396 // x.apply(y, arguments). We call x the applicand and y the receiver.
397 // The optimization avoids allocating an arguments object if possible.
398 void CallApplyLazy(Expression* applicand,
399 Expression* receiver,
400 VariableProxy* arguments,
404 void Branch(bool if_true, JumpTarget* target);
407 struct InlineRuntimeLUT {
408 void (CodeGenerator::*method)(ZoneList<Expression*>*);
413 static InlineRuntimeLUT* FindInlineRuntimeLUT(Handle<String> name);
414 bool CheckForInlineRuntimeCall(CallRuntime* node);
415 static bool PatchInlineRuntimeEntry(Handle<String> name,
416 const InlineRuntimeLUT& new_entry,
417 InlineRuntimeLUT* old_entry);
419 static Handle<Code> ComputeLazyCompile(int argc);
420 void ProcessDeclarations(ZoneList<Declaration*>* declarations);
422 static Handle<Code> ComputeCallInitialize(int argc, InLoopFlag in_loop);
424 // Declare global variables and functions in the given array of
426 void DeclareGlobals(Handle<FixedArray> pairs);
428 // Instantiate the function based on the shared function info.
429 void InstantiateFunction(Handle<SharedFunctionInfo> function_info);
431 // Support for type checks.
432 void GenerateIsSmi(ZoneList<Expression*>* args);
433 void GenerateIsNonNegativeSmi(ZoneList<Expression*>* args);
434 void GenerateIsArray(ZoneList<Expression*>* args);
435 void GenerateIsRegExp(ZoneList<Expression*>* args);
436 void GenerateIsObject(ZoneList<Expression*>* args);
437 void GenerateIsFunction(ZoneList<Expression*>* args);
438 void GenerateIsUndetectableObject(ZoneList<Expression*>* args);
440 // Support for construct call checks.
441 void GenerateIsConstructCall(ZoneList<Expression*>* args);
443 // Support for arguments.length and arguments[?].
444 void GenerateArgumentsLength(ZoneList<Expression*>* args);
445 void GenerateArguments(ZoneList<Expression*>* args);
447 // Support for accessing the class and value fields of an object.
448 void GenerateClassOf(ZoneList<Expression*>* args);
449 void GenerateValueOf(ZoneList<Expression*>* args);
450 void GenerateSetValueOf(ZoneList<Expression*>* args);
452 // Fast support for charCodeAt(n).
453 void GenerateStringCharCodeAt(ZoneList<Expression*>* args);
455 // Fast support for string.charAt(n) and string[n].
456 void GenerateStringCharFromCode(ZoneList<Expression*>* args);
458 // Fast support for string.charAt(n) and string[n].
459 void GenerateStringCharAt(ZoneList<Expression*>* args);
461 // Fast support for object equality testing.
462 void GenerateObjectEquals(ZoneList<Expression*>* args);
464 void GenerateLog(ZoneList<Expression*>* args);
466 // Fast support for Math.random().
467 void GenerateRandomHeapNumber(ZoneList<Expression*>* args);
469 // Fast support for StringAdd.
470 void GenerateStringAdd(ZoneList<Expression*>* args);
472 // Fast support for SubString.
473 void GenerateSubString(ZoneList<Expression*>* args);
475 // Fast support for StringCompare.
476 void GenerateStringCompare(ZoneList<Expression*>* args);
478 // Support for direct calls from JavaScript to native RegExp code.
479 void GenerateRegExpExec(ZoneList<Expression*>* args);
481 void GenerateRegExpConstructResult(ZoneList<Expression*>* args);
483 // Support for fast native caches.
484 void GenerateGetFromCache(ZoneList<Expression*>* args);
486 // Fast support for number to string.
487 void GenerateNumberToString(ZoneList<Expression*>* args);
489 // Fast swapping of elements.
490 void GenerateSwapElements(ZoneList<Expression*>* args);
492 // Fast call for custom callbacks.
493 void GenerateCallFunction(ZoneList<Expression*>* args);
495 // Fast call to math functions.
496 void GenerateMathPow(ZoneList<Expression*>* args);
497 void GenerateMathSin(ZoneList<Expression*>* args);
498 void GenerateMathCos(ZoneList<Expression*>* args);
499 void GenerateMathSqrt(ZoneList<Expression*>* args);
501 // Simple condition analysis.
502 enum ConditionAnalysis {
507 ConditionAnalysis AnalyzeCondition(Expression* cond);
509 // Methods used to indicate which source code is generated for. Source
510 // positions are collected by the assembler and emitted with the relocation
512 void CodeForFunctionPosition(FunctionLiteral* fun);
513 void CodeForReturnPosition(FunctionLiteral* fun);
514 void CodeForStatementPosition(Statement* node);
515 void CodeForDoWhileConditionPosition(DoWhileStatement* stmt);
516 void CodeForSourcePosition(int pos);
519 // True if the registers are valid for entry to a block.
520 bool HasValidEntryRegisters();
523 List<DeferredCode*> deferred_;
526 MacroAssembler* masm_; // to generate code
528 CompilationInfo* info_;
530 // Code generation state
531 VirtualFrame* frame_;
532 RegisterAllocator* allocator_;
534 CodeGenState* state_;
538 BreakTarget function_return_;
540 // True if the function return is shadowed (ie, jumping to the target
541 // function_return_ does not jump to the true function return, but rather
542 // to some unlinking code).
543 bool function_return_is_shadowed_;
545 static InlineRuntimeLUT kInlineRuntimeLUT[];
547 friend class VirtualFrame;
548 friend class JumpTarget;
549 friend class Reference;
550 friend class FastCodeGenerator;
551 friend class FullCodeGenerator;
552 friend class FullCodeGenSyntaxChecker;
554 DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
558 class GenericBinaryOpStub : public CodeStub {
560 GenericBinaryOpStub(Token::Value op,
564 int constant_rhs = CodeGenerator::kUnknownIntValue)
569 constant_rhs_(constant_rhs),
570 specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op, constant_rhs)),
571 runtime_operands_type_(BinaryOpIC::DEFAULT),
574 GenericBinaryOpStub(int key, BinaryOpIC::TypeInfo type_info)
575 : op_(OpBits::decode(key)),
576 mode_(ModeBits::decode(key)),
577 lhs_(LhsRegister(RegisterBits::decode(key))),
578 rhs_(RhsRegister(RegisterBits::decode(key))),
579 constant_rhs_(KnownBitsForMinorKey(KnownIntBits::decode(key))),
580 specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op_, constant_rhs_)),
581 runtime_operands_type_(type_info),
590 bool specialized_on_rhs_;
591 BinaryOpIC::TypeInfo runtime_operands_type_;
594 static const int kMaxKnownRhs = 0x40000000;
595 static const int kKnownRhsKeyBits = 6;
597 // Minor key encoding in 17 bits.
598 class ModeBits: public BitField<OverwriteMode, 0, 2> {};
599 class OpBits: public BitField<Token::Value, 2, 6> {};
600 class TypeInfoBits: public BitField<int, 8, 2> {};
601 class RegisterBits: public BitField<bool, 10, 1> {};
602 class KnownIntBits: public BitField<int, 11, kKnownRhsKeyBits> {};
604 Major MajorKey() { return GenericBinaryOp; }
606 ASSERT((lhs_.is(r0) && rhs_.is(r1)) ||
607 (lhs_.is(r1) && rhs_.is(r0)));
608 // Encode the parameters in a unique 18 bit value.
609 return OpBits::encode(op_)
610 | ModeBits::encode(mode_)
611 | KnownIntBits::encode(MinorKeyForKnownInt())
612 | TypeInfoBits::encode(runtime_operands_type_)
613 | RegisterBits::encode(lhs_.is(r0));
616 void Generate(MacroAssembler* masm);
617 void HandleNonSmiBitwiseOp(MacroAssembler* masm, Register lhs, Register rhs);
618 void HandleBinaryOpSlowCases(MacroAssembler* masm,
622 const Builtins::JavaScript& builtin);
623 void GenerateTypeTransition(MacroAssembler* masm);
625 static bool RhsIsOneWeWantToOptimizeFor(Token::Value op, int constant_rhs) {
626 if (constant_rhs == CodeGenerator::kUnknownIntValue) return false;
627 if (op == Token::DIV) return constant_rhs >= 2 && constant_rhs <= 3;
628 if (op == Token::MOD) {
629 if (constant_rhs <= 1) return false;
630 if (constant_rhs <= 10) return true;
631 if (constant_rhs <= kMaxKnownRhs && IsPowerOf2(constant_rhs)) return true;
637 int MinorKeyForKnownInt() {
638 if (!specialized_on_rhs_) return 0;
639 if (constant_rhs_ <= 10) return constant_rhs_ + 1;
640 ASSERT(IsPowerOf2(constant_rhs_));
642 int d = constant_rhs_;
643 while ((d & 1) == 0) {
647 ASSERT(key >= 0 && key < (1 << kKnownRhsKeyBits));
651 int KnownBitsForMinorKey(int key) {
653 if (key <= 11) return key - 1;
662 Register LhsRegister(bool lhs_is_r0) {
663 return lhs_is_r0 ? r0 : r1;
666 Register RhsRegister(bool lhs_is_r0) {
667 return lhs_is_r0 ? r1 : r0;
670 bool ShouldGenerateSmiCode() {
671 return ((op_ != Token::DIV && op_ != Token::MOD) || specialized_on_rhs_) &&
672 runtime_operands_type_ != BinaryOpIC::HEAP_NUMBERS &&
673 runtime_operands_type_ != BinaryOpIC::STRINGS;
676 bool ShouldGenerateFPCode() {
677 return runtime_operands_type_ != BinaryOpIC::STRINGS;
680 virtual int GetCodeKind() { return Code::BINARY_OP_IC; }
682 virtual InlineCacheState GetICState() {
683 return BinaryOpIC::ToState(runtime_operands_type_);
686 const char* GetName();
690 if (!specialized_on_rhs_) {
691 PrintF("GenericBinaryOpStub (%s)\n", Token::String(op_));
693 PrintF("GenericBinaryOpStub (%s by %d)\n",
702 class StringHelper : public AllStatic {
704 // Generate code for copying characters using a simple loop. This should only
705 // be used in places where the number of characters is small and the
706 // additional setup and checking in GenerateCopyCharactersLong adds too much
707 // overhead. Copying of overlapping regions is not supported.
708 // Dest register ends at the position after the last character written.
709 static void GenerateCopyCharacters(MacroAssembler* masm,
716 // Generate code for copying a large number of characters. This function
717 // is allowed to spend extra time setting up conditions to make copying
718 // faster. Copying of overlapping regions is not supported.
719 // Dest register ends at the position after the last character written.
720 static void GenerateCopyCharactersLong(MacroAssembler* masm,
732 // Probe the symbol table for a two character string. If the string is
733 // not found by probing a jump to the label not_found is performed. This jump
734 // does not guarantee that the string is not in the symbol table. If the
735 // string is found the code falls through with the string in register r0.
736 // Contents of both c1 and c2 registers are modified. At the exit c1 is
737 // guaranteed to contain halfword with low and high bytes equal to
738 // initial contents of c1 and c2 respectively.
739 static void GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm,
749 // Generate string hash.
750 static void GenerateHashInit(MacroAssembler* masm,
754 static void GenerateHashAddCharacter(MacroAssembler* masm,
758 static void GenerateHashGetHash(MacroAssembler* masm,
762 DISALLOW_IMPLICIT_CONSTRUCTORS(StringHelper);
766 // Flag that indicates how to generate code for the stub StringAddStub.
767 enum StringAddFlags {
768 NO_STRING_ADD_FLAGS = 0,
769 NO_STRING_CHECK_IN_STUB = 1 << 0 // Omit string check in stub.
773 class StringAddStub: public CodeStub {
775 explicit StringAddStub(StringAddFlags flags) {
776 string_check_ = ((flags & NO_STRING_CHECK_IN_STUB) == 0);
780 Major MajorKey() { return StringAdd; }
781 int MinorKey() { return string_check_ ? 0 : 1; }
783 void Generate(MacroAssembler* masm);
785 // Should the stub check whether arguments are strings?
790 class SubStringStub: public CodeStub {
795 Major MajorKey() { return SubString; }
796 int MinorKey() { return 0; }
798 void Generate(MacroAssembler* masm);
803 class StringCompareStub: public CodeStub {
805 StringCompareStub() { }
807 // Compare two flat ASCII strings and returns result in r0.
808 // Does not use the stack.
809 static void GenerateCompareFlatAsciiStrings(MacroAssembler* masm,
818 Major MajorKey() { return StringCompare; }
819 int MinorKey() { return 0; }
821 void Generate(MacroAssembler* masm);
825 // This stub can convert a signed int32 to a heap number (double). It does
826 // not work for int32s that are in Smi range! No GC occurs during this stub
827 // so you don't have to set up the frame.
828 class WriteInt32ToHeapNumberStub : public CodeStub {
830 WriteInt32ToHeapNumberStub(Register the_int,
831 Register the_heap_number,
834 the_heap_number_(the_heap_number),
835 scratch_(scratch) { }
839 Register the_heap_number_;
842 // Minor key encoding in 16 bits.
843 class IntRegisterBits: public BitField<int, 0, 4> {};
844 class HeapNumberRegisterBits: public BitField<int, 4, 4> {};
845 class ScratchRegisterBits: public BitField<int, 8, 4> {};
847 Major MajorKey() { return WriteInt32ToHeapNumber; }
849 // Encode the parameters in a unique 16 bit value.
850 return IntRegisterBits::encode(the_int_.code())
851 | HeapNumberRegisterBits::encode(the_heap_number_.code())
852 | ScratchRegisterBits::encode(scratch_.code());
855 void Generate(MacroAssembler* masm);
857 const char* GetName() { return "WriteInt32ToHeapNumberStub"; }
860 void Print() { PrintF("WriteInt32ToHeapNumberStub\n"); }
865 class NumberToStringStub: public CodeStub {
867 NumberToStringStub() { }
869 // Generate code to do a lookup in the number string cache. If the number in
870 // the register object is found in the cache the generated code falls through
871 // with the result in the result register. The object and the result register
872 // can be the same. If the number is not found in the cache the code jumps to
873 // the label not_found with only the content of register object unchanged.
874 static void GenerateLookupNumberStringCache(MacroAssembler* masm,
884 Major MajorKey() { return NumberToString; }
885 int MinorKey() { return 0; }
887 void Generate(MacroAssembler* masm);
889 const char* GetName() { return "NumberToStringStub"; }
893 PrintF("NumberToStringStub\n");
899 class RecordWriteStub : public CodeStub {
901 RecordWriteStub(Register object, Register offset, Register scratch)
902 : object_(object), offset_(offset), scratch_(scratch) { }
904 void Generate(MacroAssembler* masm);
913 PrintF("RecordWriteStub (object reg %d), (offset reg %d),"
914 " (scratch reg %d)\n",
915 object_.code(), offset_.code(), scratch_.code());
919 // Minor key encoding in 12 bits. 4 bits for each of the three
920 // registers (object, offset and scratch) OOOOAAAASSSS.
921 class ScratchBits: public BitField<uint32_t, 0, 4> {};
922 class OffsetBits: public BitField<uint32_t, 4, 4> {};
923 class ObjectBits: public BitField<uint32_t, 8, 4> {};
925 Major MajorKey() { return RecordWrite; }
928 // Encode the registers.
929 return ObjectBits::encode(object_.code()) |
930 OffsetBits::encode(offset_.code()) |
931 ScratchBits::encode(scratch_.code());
936 } } // namespace v8::internal
938 #endif // V8_ARM_CODEGEN_ARM_H_