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);
105 CodeGenerator* cgen_;
106 Expression* expression_;
108 // Keep the reference on the stack after get, so it can be used by set later.
109 bool persist_after_get_;
113 // -------------------------------------------------------------------------
114 // Code generation state
116 // The state is passed down the AST by the code generator (and back up, in
117 // the form of the state of the label pair). It is threaded through the
118 // call stack. Constructing a state implicitly pushes it on the owning code
119 // generator's stack of states, and destroying one implicitly pops it.
121 class CodeGenState BASE_EMBEDDED {
123 // Create an initial code generator state. Destroying the initial state
124 // leaves the code generator with a NULL state.
125 explicit CodeGenState(CodeGenerator* owner);
127 // Create a code generator state based on a code generator's current
128 // state. The new state has its own pair of branch labels.
129 CodeGenState(CodeGenerator* owner,
130 JumpTarget* true_target,
131 JumpTarget* false_target);
133 // Destroy a code generator state and restore the owning code generator's
137 JumpTarget* true_target() const { return true_target_; }
138 JumpTarget* false_target() const { return false_target_; }
141 CodeGenerator* owner_;
142 JumpTarget* true_target_;
143 JumpTarget* false_target_;
144 CodeGenState* previous_;
148 // -------------------------------------------------------------------------
149 // Arguments allocation mode
151 enum ArgumentsAllocationMode {
152 NO_ARGUMENTS_ALLOCATION,
153 EAGER_ARGUMENTS_ALLOCATION,
154 LAZY_ARGUMENTS_ALLOCATION
158 // Different nop operations are used by the code generator to detect certain
159 // states of the generated code.
160 enum NopMarkerTypes {
162 PROPERTY_ACCESS_INLINED
166 // -------------------------------------------------------------------------
169 class CodeGenerator: public AstVisitor {
171 // Takes a function literal, generates code for it. This function should only
172 // be called by compiler.cc.
173 static Handle<Code> MakeCode(CompilationInfo* info);
175 // Printing of AST, etc. as requested by flags.
176 static void MakeCodePrologue(CompilationInfo* info);
178 // Allocate and install the code.
179 static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm,
181 CompilationInfo* info);
183 #ifdef ENABLE_LOGGING_AND_PROFILING
184 static bool ShouldGenerateLog(Expression* type);
187 static void SetFunctionInfo(Handle<JSFunction> fun,
188 FunctionLiteral* lit,
190 Handle<Script> script);
192 static void RecordPositions(MacroAssembler* masm, int pos);
195 MacroAssembler* masm() { return masm_; }
196 VirtualFrame* frame() const { return frame_; }
197 inline Handle<Script> script();
199 bool has_valid_frame() const { return frame_ != NULL; }
201 // Set the virtual frame to be new_frame, with non-frame register
202 // reference counts given by non_frame_registers. The non-frame
203 // register reference counts of the old frame are returned in
204 // non_frame_registers.
205 void SetFrame(VirtualFrame* new_frame, RegisterFile* non_frame_registers);
209 RegisterAllocator* allocator() const { return allocator_; }
211 CodeGenState* state() { return state_; }
212 void set_state(CodeGenState* state) { state_ = state; }
214 void AddDeferred(DeferredCode* code) { deferred_.Add(code); }
216 static const int kUnknownIntValue = -1;
218 // If the name is an inline runtime function call return the number of
219 // expected arguments. Otherwise return -1.
220 static int InlineRuntimeCallArgumentsCount(Handle<String> name);
222 // Constants related to patching of inlined lokad/store.
223 static const int kInlinedKeyedLoadInstructionsAfterPatchSize = 19;
226 // Construction/Destruction
227 explicit CodeGenerator(MacroAssembler* masm);
230 inline bool is_eval();
231 inline Scope* scope();
233 // Generating deferred code.
234 void ProcessDeferred();
237 bool has_cc() const { return cc_reg_ != al; }
238 JumpTarget* true_target() const { return state_->true_target(); }
239 JumpTarget* false_target() const { return state_->false_target(); }
241 // Track loop nesting level.
242 int loop_nesting() const { return loop_nesting_; }
243 void IncrementLoopNesting() { loop_nesting_++; }
244 void DecrementLoopNesting() { loop_nesting_--; }
247 void VisitStatements(ZoneList<Statement*>* statements);
249 #define DEF_VISIT(type) \
250 void Visit##type(type* node);
251 AST_NODE_LIST(DEF_VISIT)
254 // Visit a statement and then spill the virtual frame if control flow can
255 // reach the end of the statement (ie, it does not exit via break,
256 // continue, return, or throw). This function is used temporarily while
257 // the code generator is being transformed.
258 inline void VisitAndSpill(Statement* statement);
260 // Visit a list of statements and then spill the virtual frame if control
261 // flow can reach the end of the list.
262 inline void VisitStatementsAndSpill(ZoneList<Statement*>* statements);
264 // Main code generation function
265 void Generate(CompilationInfo* info);
267 // Returns the arguments allocation mode.
268 ArgumentsAllocationMode ArgumentsMode();
270 // Store the arguments object and allocate it if necessary.
271 void StoreArgumentsObject(bool initial);
273 // The following are used by class Reference.
274 void LoadReference(Reference* ref);
275 void UnloadReference(Reference* ref);
277 static MemOperand ContextOperand(Register context, int index) {
278 return MemOperand(context, Context::SlotOffset(index));
281 MemOperand SlotOperand(Slot* slot, Register tmp);
283 MemOperand ContextSlotOperandCheckExtensions(Slot* slot,
289 static MemOperand GlobalObject() {
290 return ContextOperand(cp, Context::GLOBAL_INDEX);
293 void LoadCondition(Expression* x,
294 JumpTarget* true_target,
295 JumpTarget* false_target,
297 void Load(Expression* expr);
299 void LoadGlobalReceiver(Register scratch);
301 // Generate code to push the value of an expression on top of the frame
302 // and then spill the frame fully to memory. This function is used
303 // temporarily while the code generator is being transformed.
304 inline void LoadAndSpill(Expression* expression);
306 // Call LoadCondition and then spill the virtual frame unless control flow
307 // cannot reach the end of the expression (ie, by emitting only
308 // unconditional jumps to the control targets).
309 inline void LoadConditionAndSpill(Expression* expression,
310 JumpTarget* true_target,
311 JumpTarget* false_target,
314 // Read a value from a slot and leave it on top of the expression stack.
315 void LoadFromSlot(Slot* slot, TypeofState typeof_state);
316 void LoadFromSlotCheckForArguments(Slot* slot, TypeofState state);
317 // Store the value on top of the stack to a slot.
318 void StoreToSlot(Slot* slot, InitState init_state);
320 // Support for compiling assignment expressions.
321 void EmitSlotAssignment(Assignment* node);
322 void EmitNamedPropertyAssignment(Assignment* node);
323 void EmitKeyedPropertyAssignment(Assignment* node);
325 // Load a named property, returning it in r0. The receiver is passed on the
326 // stack, and remains there.
327 void EmitNamedLoad(Handle<String> name, bool is_contextual);
329 // Store to a named property. If the store is contextual, value is passed on
330 // the frame and consumed. Otherwise, receiver and value are passed on the
331 // frame and consumed. The result is returned in r0.
332 void EmitNamedStore(Handle<String> name, bool is_contextual);
334 // Load a keyed property, leaving it in r0. The receiver and key are
335 // passed on the stack, and remain there.
336 void EmitKeyedLoad();
338 // Store a keyed property. Key and receiver are on the stack and the value is
339 // in r0. Result is returned in r0.
340 void EmitKeyedStore(StaticType* key_type);
342 void LoadFromGlobalSlotCheckExtensions(Slot* slot,
343 TypeofState typeof_state,
346 // Special code for typeof expressions: Unfortunately, we must
347 // be careful when loading the expression in 'typeof'
348 // expressions. We are not allowed to throw reference errors for
349 // non-existing properties of the global object, so we must make it
350 // look like an explicit property access, instead of an access
351 // through the context chain.
352 void LoadTypeofExpression(Expression* x);
354 void ToBoolean(JumpTarget* true_target, JumpTarget* false_target);
356 // Generate code that computes a shortcutting logical operation.
357 void GenerateLogicalBooleanOperation(BinaryOperation* node);
359 void GenericBinaryOperation(Token::Value op,
360 OverwriteMode overwrite_mode,
361 int known_rhs = kUnknownIntValue);
362 void VirtualFrameBinaryOperation(Token::Value op,
363 OverwriteMode overwrite_mode,
364 int known_rhs = kUnknownIntValue);
365 void Comparison(Condition cc,
368 bool strict = false);
370 void SmiOperation(Token::Value op,
371 Handle<Object> value,
375 void CallWithArguments(ZoneList<Expression*>* arguments,
376 CallFunctionFlags flags,
379 // An optimized implementation of expressions of the form
380 // x.apply(y, arguments). We call x the applicand and y the receiver.
381 // The optimization avoids allocating an arguments object if possible.
382 void CallApplyLazy(Expression* applicand,
383 Expression* receiver,
384 VariableProxy* arguments,
388 void Branch(bool if_true, JumpTarget* target);
391 struct InlineRuntimeLUT {
392 void (CodeGenerator::*method)(ZoneList<Expression*>*);
397 static InlineRuntimeLUT* FindInlineRuntimeLUT(Handle<String> name);
398 bool CheckForInlineRuntimeCall(CallRuntime* node);
399 static bool PatchInlineRuntimeEntry(Handle<String> name,
400 const InlineRuntimeLUT& new_entry,
401 InlineRuntimeLUT* old_entry);
403 static Handle<Code> ComputeLazyCompile(int argc);
404 void ProcessDeclarations(ZoneList<Declaration*>* declarations);
406 static Handle<Code> ComputeCallInitialize(int argc, InLoopFlag in_loop);
408 // Declare global variables and functions in the given array of
410 void DeclareGlobals(Handle<FixedArray> pairs);
412 // Instantiate the function based on the shared function info.
413 void InstantiateFunction(Handle<SharedFunctionInfo> function_info);
415 // Support for type checks.
416 void GenerateIsSmi(ZoneList<Expression*>* args);
417 void GenerateIsNonNegativeSmi(ZoneList<Expression*>* args);
418 void GenerateIsArray(ZoneList<Expression*>* args);
419 void GenerateIsRegExp(ZoneList<Expression*>* args);
420 void GenerateIsObject(ZoneList<Expression*>* args);
421 void GenerateIsFunction(ZoneList<Expression*>* args);
422 void GenerateIsUndetectableObject(ZoneList<Expression*>* args);
424 // Support for construct call checks.
425 void GenerateIsConstructCall(ZoneList<Expression*>* args);
427 // Support for arguments.length and arguments[?].
428 void GenerateArgumentsLength(ZoneList<Expression*>* args);
429 void GenerateArguments(ZoneList<Expression*>* args);
431 // Support for accessing the class and value fields of an object.
432 void GenerateClassOf(ZoneList<Expression*>* args);
433 void GenerateValueOf(ZoneList<Expression*>* args);
434 void GenerateSetValueOf(ZoneList<Expression*>* args);
436 // Fast support for charCodeAt(n).
437 void GenerateFastCharCodeAt(ZoneList<Expression*>* args);
439 // Fast support for string.charAt(n) and string[n].
440 void GenerateCharFromCode(ZoneList<Expression*>* args);
442 // Fast support for object equality testing.
443 void GenerateObjectEquals(ZoneList<Expression*>* args);
445 void GenerateLog(ZoneList<Expression*>* args);
447 // Fast support for Math.random().
448 void GenerateRandomHeapNumber(ZoneList<Expression*>* args);
450 // Fast support for StringAdd.
451 void GenerateStringAdd(ZoneList<Expression*>* args);
453 // Fast support for SubString.
454 void GenerateSubString(ZoneList<Expression*>* args);
456 // Fast support for StringCompare.
457 void GenerateStringCompare(ZoneList<Expression*>* args);
459 // Support for direct calls from JavaScript to native RegExp code.
460 void GenerateRegExpExec(ZoneList<Expression*>* args);
462 void GenerateRegExpConstructResult(ZoneList<Expression*>* args);
464 // Support for fast native caches.
465 void GenerateGetFromCache(ZoneList<Expression*>* args);
467 // Fast support for number to string.
468 void GenerateNumberToString(ZoneList<Expression*>* args);
470 // Fast swapping of elements.
471 void GenerateSwapElements(ZoneList<Expression*>* args);
473 // Fast call for custom callbacks.
474 void GenerateCallFunction(ZoneList<Expression*>* args);
476 // Fast call to math functions.
477 void GenerateMathPow(ZoneList<Expression*>* args);
478 void GenerateMathSin(ZoneList<Expression*>* args);
479 void GenerateMathCos(ZoneList<Expression*>* args);
480 void GenerateMathSqrt(ZoneList<Expression*>* args);
482 // Simple condition analysis.
483 enum ConditionAnalysis {
488 ConditionAnalysis AnalyzeCondition(Expression* cond);
490 // Methods used to indicate which source code is generated for. Source
491 // positions are collected by the assembler and emitted with the relocation
493 void CodeForFunctionPosition(FunctionLiteral* fun);
494 void CodeForReturnPosition(FunctionLiteral* fun);
495 void CodeForStatementPosition(Statement* node);
496 void CodeForDoWhileConditionPosition(DoWhileStatement* stmt);
497 void CodeForSourcePosition(int pos);
500 // True if the registers are valid for entry to a block.
501 bool HasValidEntryRegisters();
504 List<DeferredCode*> deferred_;
507 MacroAssembler* masm_; // to generate code
509 CompilationInfo* info_;
511 // Code generation state
512 VirtualFrame* frame_;
513 RegisterAllocator* allocator_;
515 CodeGenState* state_;
519 BreakTarget function_return_;
521 // True if the function return is shadowed (ie, jumping to the target
522 // function_return_ does not jump to the true function return, but rather
523 // to some unlinking code).
524 bool function_return_is_shadowed_;
526 static InlineRuntimeLUT kInlineRuntimeLUT[];
528 friend class VirtualFrame;
529 friend class JumpTarget;
530 friend class Reference;
531 friend class FastCodeGenerator;
532 friend class FullCodeGenerator;
533 friend class FullCodeGenSyntaxChecker;
535 DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
539 class GenericBinaryOpStub : public CodeStub {
541 GenericBinaryOpStub(Token::Value op,
545 int constant_rhs = CodeGenerator::kUnknownIntValue)
550 constant_rhs_(constant_rhs),
551 specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op, constant_rhs)),
552 runtime_operands_type_(BinaryOpIC::DEFAULT),
555 GenericBinaryOpStub(int key, BinaryOpIC::TypeInfo type_info)
556 : op_(OpBits::decode(key)),
557 mode_(ModeBits::decode(key)),
558 lhs_(LhsRegister(RegisterBits::decode(key))),
559 rhs_(RhsRegister(RegisterBits::decode(key))),
560 constant_rhs_(KnownBitsForMinorKey(KnownIntBits::decode(key))),
561 specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op_, constant_rhs_)),
562 runtime_operands_type_(type_info),
571 bool specialized_on_rhs_;
572 BinaryOpIC::TypeInfo runtime_operands_type_;
575 static const int kMaxKnownRhs = 0x40000000;
576 static const int kKnownRhsKeyBits = 6;
578 // Minor key encoding in 17 bits.
579 class ModeBits: public BitField<OverwriteMode, 0, 2> {};
580 class OpBits: public BitField<Token::Value, 2, 6> {};
581 class TypeInfoBits: public BitField<int, 8, 2> {};
582 class RegisterBits: public BitField<bool, 10, 1> {};
583 class KnownIntBits: public BitField<int, 11, kKnownRhsKeyBits> {};
585 Major MajorKey() { return GenericBinaryOp; }
587 ASSERT((lhs_.is(r0) && rhs_.is(r1)) ||
588 (lhs_.is(r1) && rhs_.is(r0)));
589 // Encode the parameters in a unique 18 bit value.
590 return OpBits::encode(op_)
591 | ModeBits::encode(mode_)
592 | KnownIntBits::encode(MinorKeyForKnownInt())
593 | TypeInfoBits::encode(runtime_operands_type_)
594 | RegisterBits::encode(lhs_.is(r0));
597 void Generate(MacroAssembler* masm);
598 void HandleNonSmiBitwiseOp(MacroAssembler* masm, Register lhs, Register rhs);
599 void HandleBinaryOpSlowCases(MacroAssembler* masm,
603 const Builtins::JavaScript& builtin);
604 void GenerateTypeTransition(MacroAssembler* masm);
606 static bool RhsIsOneWeWantToOptimizeFor(Token::Value op, int constant_rhs) {
607 if (constant_rhs == CodeGenerator::kUnknownIntValue) return false;
608 if (op == Token::DIV) return constant_rhs >= 2 && constant_rhs <= 3;
609 if (op == Token::MOD) {
610 if (constant_rhs <= 1) return false;
611 if (constant_rhs <= 10) return true;
612 if (constant_rhs <= kMaxKnownRhs && IsPowerOf2(constant_rhs)) return true;
618 int MinorKeyForKnownInt() {
619 if (!specialized_on_rhs_) return 0;
620 if (constant_rhs_ <= 10) return constant_rhs_ + 1;
621 ASSERT(IsPowerOf2(constant_rhs_));
623 int d = constant_rhs_;
624 while ((d & 1) == 0) {
628 ASSERT(key >= 0 && key < (1 << kKnownRhsKeyBits));
632 int KnownBitsForMinorKey(int key) {
634 if (key <= 11) return key - 1;
643 Register LhsRegister(bool lhs_is_r0) {
644 return lhs_is_r0 ? r0 : r1;
647 Register RhsRegister(bool lhs_is_r0) {
648 return lhs_is_r0 ? r1 : r0;
651 bool ShouldGenerateSmiCode() {
652 return ((op_ != Token::DIV && op_ != Token::MOD) || specialized_on_rhs_) &&
653 runtime_operands_type_ != BinaryOpIC::HEAP_NUMBERS &&
654 runtime_operands_type_ != BinaryOpIC::STRINGS;
657 bool ShouldGenerateFPCode() {
658 return runtime_operands_type_ != BinaryOpIC::STRINGS;
661 virtual int GetCodeKind() { return Code::BINARY_OP_IC; }
663 virtual InlineCacheState GetICState() {
664 return BinaryOpIC::ToState(runtime_operands_type_);
667 const char* GetName();
671 if (!specialized_on_rhs_) {
672 PrintF("GenericBinaryOpStub (%s)\n", Token::String(op_));
674 PrintF("GenericBinaryOpStub (%s by %d)\n",
683 class StringHelper : public AllStatic {
685 // Generates fast code for getting a char code out of a string
686 // object at the given index. May bail out for four reasons (in the
688 // * Receiver is not a string (receiver_not_string label).
689 // * Index is not a smi (index_not_smi label).
690 // * Index is out of range (index_out_of_range).
691 // * Some other reason (slow_case label). In this case it's
692 // guaranteed that the above conditions are not violated,
693 // e.g. it's safe to assume the receiver is a string and the
694 // index is a non-negative smi < length.
695 // When successful, object, index, and scratch are clobbered.
696 // Otherwise, scratch and result are clobbered.
697 static void GenerateFastCharCodeAt(MacroAssembler* masm,
702 Label* receiver_not_string,
703 Label* index_not_smi,
704 Label* index_out_of_range,
707 // Generates code for creating a one-char string from the given char
708 // code. May do a runtime call, so any register can be clobbered
709 // and, if the given invoke flag specifies a call, an internal frame
710 // is required. In tail call mode the result must be r0 register.
711 static void GenerateCharFromCode(MacroAssembler* masm,
717 // Generate code for copying characters using a simple loop. This should only
718 // be used in places where the number of characters is small and the
719 // additional setup and checking in GenerateCopyCharactersLong adds too much
720 // overhead. Copying of overlapping regions is not supported.
721 // Dest register ends at the position after the last character written.
722 static void GenerateCopyCharacters(MacroAssembler* masm,
729 // Generate code for copying a large number of characters. This function
730 // is allowed to spend extra time setting up conditions to make copying
731 // faster. Copying of overlapping regions is not supported.
732 // Dest register ends at the position after the last character written.
733 static void GenerateCopyCharactersLong(MacroAssembler* masm,
745 // Probe the symbol table for a two character string. If the string is
746 // not found by probing a jump to the label not_found is performed. This jump
747 // does not guarantee that the string is not in the symbol table. If the
748 // string is found the code falls through with the string in register r0.
749 // Contents of both c1 and c2 registers are modified. At the exit c1 is
750 // guaranteed to contain halfword with low and high bytes equal to
751 // initial contents of c1 and c2 respectively.
752 static void GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm,
762 // Generate string hash.
763 static void GenerateHashInit(MacroAssembler* masm,
767 static void GenerateHashAddCharacter(MacroAssembler* masm,
771 static void GenerateHashGetHash(MacroAssembler* masm,
775 DISALLOW_IMPLICIT_CONSTRUCTORS(StringHelper);
779 // Flag that indicates how to generate code for the stub StringAddStub.
780 enum StringAddFlags {
781 NO_STRING_ADD_FLAGS = 0,
782 NO_STRING_CHECK_IN_STUB = 1 << 0 // Omit string check in stub.
786 class StringAddStub: public CodeStub {
788 explicit StringAddStub(StringAddFlags flags) {
789 string_check_ = ((flags & NO_STRING_CHECK_IN_STUB) == 0);
793 Major MajorKey() { return StringAdd; }
794 int MinorKey() { return string_check_ ? 0 : 1; }
796 void Generate(MacroAssembler* masm);
798 // Should the stub check whether arguments are strings?
803 class SubStringStub: public CodeStub {
808 Major MajorKey() { return SubString; }
809 int MinorKey() { return 0; }
811 void Generate(MacroAssembler* masm);
816 class StringCompareStub: public CodeStub {
818 StringCompareStub() { }
820 // Compare two flat ASCII strings and returns result in r0.
821 // Does not use the stack.
822 static void GenerateCompareFlatAsciiStrings(MacroAssembler* masm,
831 Major MajorKey() { return StringCompare; }
832 int MinorKey() { return 0; }
834 void Generate(MacroAssembler* masm);
838 // This stub can convert a signed int32 to a heap number (double). It does
839 // not work for int32s that are in Smi range! No GC occurs during this stub
840 // so you don't have to set up the frame.
841 class WriteInt32ToHeapNumberStub : public CodeStub {
843 WriteInt32ToHeapNumberStub(Register the_int,
844 Register the_heap_number,
847 the_heap_number_(the_heap_number),
848 scratch_(scratch) { }
852 Register the_heap_number_;
855 // Minor key encoding in 16 bits.
856 class IntRegisterBits: public BitField<int, 0, 4> {};
857 class HeapNumberRegisterBits: public BitField<int, 4, 4> {};
858 class ScratchRegisterBits: public BitField<int, 8, 4> {};
860 Major MajorKey() { return WriteInt32ToHeapNumber; }
862 // Encode the parameters in a unique 16 bit value.
863 return IntRegisterBits::encode(the_int_.code())
864 | HeapNumberRegisterBits::encode(the_heap_number_.code())
865 | ScratchRegisterBits::encode(scratch_.code());
868 void Generate(MacroAssembler* masm);
870 const char* GetName() { return "WriteInt32ToHeapNumberStub"; }
873 void Print() { PrintF("WriteInt32ToHeapNumberStub\n"); }
878 class NumberToStringStub: public CodeStub {
880 NumberToStringStub() { }
882 // Generate code to do a lookup in the number string cache. If the number in
883 // the register object is found in the cache the generated code falls through
884 // with the result in the result register. The object and the result register
885 // can be the same. If the number is not found in the cache the code jumps to
886 // the label not_found with only the content of register object unchanged.
887 static void GenerateLookupNumberStringCache(MacroAssembler* masm,
897 Major MajorKey() { return NumberToString; }
898 int MinorKey() { return 0; }
900 void Generate(MacroAssembler* masm);
902 const char* GetName() { return "NumberToStringStub"; }
906 PrintF("NumberToStringStub\n");
912 class RecordWriteStub : public CodeStub {
914 RecordWriteStub(Register object, Register offset, Register scratch)
915 : object_(object), offset_(offset), scratch_(scratch) { }
917 void Generate(MacroAssembler* masm);
926 PrintF("RecordWriteStub (object reg %d), (offset reg %d),"
927 " (scratch reg %d)\n",
928 object_.code(), offset_.code(), scratch_.code());
932 // Minor key encoding in 12 bits. 4 bits for each of the three
933 // registers (object, offset and scratch) OOOOAAAASSSS.
934 class ScratchBits: public BitField<uint32_t, 0, 4> {};
935 class OffsetBits: public BitField<uint32_t, 4, 4> {};
936 class ObjectBits: public BitField<uint32_t, 8, 4> {};
938 Major MajorKey() { return RecordWrite; }
941 // Encode the registers.
942 return ObjectBits::encode(object_.code()) |
943 OffsetBits::encode(offset_.code()) |
944 ScratchBits::encode(scratch_.code());
949 } } // namespace v8::internal
951 #endif // V8_ARM_CODEGEN_ARM_H_