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 };
46 enum GenerateInlineSmi { DONT_GENERATE_INLINE_SMI, GENERATE_INLINE_SMI };
49 // -------------------------------------------------------------------------
52 // A reference is a C++ stack-allocated object that puts a
53 // reference on the virtual frame. The reference may be consumed
54 // by GetValue, TakeValue, SetValue, and Codegen::UnloadReference.
55 // When the lifetime (scope) of a valid reference ends, it must have
56 // been consumed, and be in state UNLOADED.
57 class Reference BASE_EMBEDDED {
59 // The values of the types is important, see size().
60 enum Type { UNLOADED = -2, ILLEGAL = -1, SLOT = 0, NAMED = 1, KEYED = 2 };
61 Reference(CodeGenerator* cgen,
62 Expression* expression,
63 bool persist_after_get = false);
66 Expression* expression() const { return expression_; }
67 Type type() const { return type_; }
68 void set_type(Type value) {
69 ASSERT_EQ(ILLEGAL, type_);
74 ASSERT_NE(ILLEGAL, type_);
75 ASSERT_NE(UNLOADED, type_);
78 // The size the reference takes up on the stack.
80 return (type_ < SLOT) ? 0 : type_;
83 bool is_illegal() const { return type_ == ILLEGAL; }
84 bool is_slot() const { return type_ == SLOT; }
85 bool is_property() const { return type_ == NAMED || type_ == KEYED; }
86 bool is_unloaded() const { return type_ == UNLOADED; }
88 // Return the name. Only valid for named property references.
89 Handle<String> GetName();
91 // Generate code to push the value of the reference on top of the
92 // expression stack. The reference is expected to be already on top of
93 // the expression stack, and it is consumed by the call unless the
94 // reference is for a compound assignment.
95 // If the reference is not consumed, it is left in place under its value.
98 // Generate code to store the value on top of the expression stack in the
99 // reference. The reference is expected to be immediately below the value
100 // on the expression stack. The value is stored in the location specified
101 // by the reference, and is left on top of the stack, after the reference
102 // is popped from beneath it (unloaded).
103 void SetValue(InitState init_state);
105 // This is in preparation for something that uses the reference on the stack.
106 // If we need this reference afterwards get then dup it now. Otherwise mark
108 inline void DupIfPersist();
111 CodeGenerator* cgen_;
112 Expression* expression_;
114 // Keep the reference on the stack after get, so it can be used by set later.
115 bool persist_after_get_;
119 // -------------------------------------------------------------------------
120 // Code generation state
122 // The state is passed down the AST by the code generator (and back up, in
123 // the form of the state of the label pair). It is threaded through the
124 // call stack. Constructing a state implicitly pushes it on the owning code
125 // generator's stack of states, and destroying one implicitly pops it.
127 class CodeGenState BASE_EMBEDDED {
129 // Create an initial code generator state. Destroying the initial state
130 // leaves the code generator with a NULL state.
131 explicit CodeGenState(CodeGenerator* owner);
133 // Destroy a code generator state and restore the owning code generator's
135 virtual ~CodeGenState();
137 virtual JumpTarget* true_target() const { return NULL; }
138 virtual JumpTarget* false_target() const { return NULL; }
141 inline CodeGenerator* owner() { return owner_; }
142 inline CodeGenState* previous() const { return previous_; }
145 CodeGenerator* owner_;
146 CodeGenState* previous_;
150 class ConditionCodeGenState : public CodeGenState {
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);
158 virtual JumpTarget* true_target() const { return true_target_; }
159 virtual JumpTarget* false_target() const { return false_target_; }
162 JumpTarget* true_target_;
163 JumpTarget* false_target_;
167 class TypeInfoCodeGenState : public CodeGenState {
169 TypeInfoCodeGenState(CodeGenerator* owner,
172 ~TypeInfoCodeGenState();
174 virtual JumpTarget* true_target() const { return previous()->true_target(); }
175 virtual JumpTarget* false_target() const {
176 return previous()->false_target();
181 TypeInfo old_type_info_;
185 // -------------------------------------------------------------------------
186 // Arguments allocation mode
188 enum ArgumentsAllocationMode {
189 NO_ARGUMENTS_ALLOCATION,
190 EAGER_ARGUMENTS_ALLOCATION,
191 LAZY_ARGUMENTS_ALLOCATION
195 // Different nop operations are used by the code generator to detect certain
196 // states of the generated code.
197 enum NopMarkerTypes {
199 PROPERTY_ACCESS_INLINED
203 // -------------------------------------------------------------------------
206 class CodeGenerator: public AstVisitor {
208 // Takes a function literal, generates code for it. This function should only
209 // be called by compiler.cc.
210 static Handle<Code> MakeCode(CompilationInfo* info);
212 // Printing of AST, etc. as requested by flags.
213 static void MakeCodePrologue(CompilationInfo* info);
215 // Allocate and install the code.
216 static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm,
218 CompilationInfo* info);
220 #ifdef ENABLE_LOGGING_AND_PROFILING
221 static bool ShouldGenerateLog(Expression* type);
224 static void SetFunctionInfo(Handle<JSFunction> fun,
225 FunctionLiteral* lit,
227 Handle<Script> script);
229 static bool RecordPositions(MacroAssembler* masm,
231 bool right_here = false);
234 MacroAssembler* masm() { return masm_; }
235 VirtualFrame* frame() const { return frame_; }
236 inline Handle<Script> script();
238 bool has_valid_frame() const { return frame_ != NULL; }
240 // Set the virtual frame to be new_frame, with non-frame register
241 // reference counts given by non_frame_registers. The non-frame
242 // register reference counts of the old frame are returned in
243 // non_frame_registers.
244 void SetFrame(VirtualFrame* new_frame, RegisterFile* non_frame_registers);
248 RegisterAllocator* allocator() const { return allocator_; }
250 CodeGenState* state() { return state_; }
251 void set_state(CodeGenState* state) { state_ = state; }
253 TypeInfo type_info(Slot* slot) {
254 int index = NumberOfSlot(slot);
255 if (index == kInvalidSlotNumber) return TypeInfo::Unknown();
256 return (*type_info_)[index];
259 TypeInfo set_type_info(Slot* slot, TypeInfo info) {
260 int index = NumberOfSlot(slot);
261 ASSERT(index >= kInvalidSlotNumber);
262 if (index != kInvalidSlotNumber) {
263 TypeInfo previous_value = (*type_info_)[index];
264 (*type_info_)[index] = info;
265 return previous_value;
267 return TypeInfo::Unknown();
270 void AddDeferred(DeferredCode* code) { deferred_.Add(code); }
272 static const int kUnknownIntValue = -1;
274 // If the name is an inline runtime function call return the number of
275 // expected arguments. Otherwise return -1.
276 static int InlineRuntimeCallArgumentsCount(Handle<String> name);
278 // Constants related to patching of inlined load/store.
279 static int GetInlinedKeyedLoadInstructionsAfterPatch() {
280 return FLAG_debug_code ? 27 : 13;
282 static const int kInlinedKeyedStoreInstructionsAfterPatch = 5;
285 // Construction/Destruction
286 explicit CodeGenerator(MacroAssembler* masm);
289 inline bool is_eval();
290 inline Scope* scope();
292 // Generating deferred code.
293 void ProcessDeferred();
295 static const int kInvalidSlotNumber = -1;
297 int NumberOfSlot(Slot* slot);
300 bool has_cc() const { return cc_reg_ != al; }
301 JumpTarget* true_target() const { return state_->true_target(); }
302 JumpTarget* false_target() const { return state_->false_target(); }
304 // Track loop nesting level.
305 int loop_nesting() const { return loop_nesting_; }
306 void IncrementLoopNesting() { loop_nesting_++; }
307 void DecrementLoopNesting() { loop_nesting_--; }
310 void VisitStatements(ZoneList<Statement*>* statements);
312 #define DEF_VISIT(type) \
313 void Visit##type(type* node);
314 AST_NODE_LIST(DEF_VISIT)
317 // Main code generation function
318 void Generate(CompilationInfo* info);
320 // Generate the return sequence code. Should be called no more than
321 // once per compiled function, immediately after binding the return
322 // target (which can not be done more than once). The return value should
324 void GenerateReturnSequence();
326 // Returns the arguments allocation mode.
327 ArgumentsAllocationMode ArgumentsMode();
329 // Store the arguments object and allocate it if necessary.
330 void StoreArgumentsObject(bool initial);
332 // The following are used by class Reference.
333 void LoadReference(Reference* ref);
334 void UnloadReference(Reference* ref);
336 static MemOperand ContextOperand(Register context, int index) {
337 return MemOperand(context, Context::SlotOffset(index));
340 MemOperand SlotOperand(Slot* slot, Register tmp);
342 MemOperand ContextSlotOperandCheckExtensions(Slot* slot,
348 static MemOperand GlobalObject() {
349 return ContextOperand(cp, Context::GLOBAL_INDEX);
352 void LoadCondition(Expression* x,
353 JumpTarget* true_target,
354 JumpTarget* false_target,
356 void Load(Expression* expr);
358 void LoadGlobalReceiver(Register scratch);
360 // Read a value from a slot and leave it on top of the expression stack.
361 void LoadFromSlot(Slot* slot, TypeofState typeof_state);
362 void LoadFromSlotCheckForArguments(Slot* slot, TypeofState state);
364 // Store the value on top of the stack to a slot.
365 void StoreToSlot(Slot* slot, InitState init_state);
367 // Support for compiling assignment expressions.
368 void EmitSlotAssignment(Assignment* node);
369 void EmitNamedPropertyAssignment(Assignment* node);
370 void EmitKeyedPropertyAssignment(Assignment* node);
372 // Load a named property, returning it in r0. The receiver is passed on the
373 // stack, and remains there.
374 void EmitNamedLoad(Handle<String> name, bool is_contextual);
376 // Store to a named property. If the store is contextual, value is passed on
377 // the frame and consumed. Otherwise, receiver and value are passed on the
378 // frame and consumed. The result is returned in r0.
379 void EmitNamedStore(Handle<String> name, bool is_contextual);
381 // Load a keyed property, leaving it in r0. The receiver and key are
382 // passed on the stack, and remain there.
383 void EmitKeyedLoad();
385 // Store a keyed property. Key and receiver are on the stack and the value is
386 // in r0. Result is returned in r0.
387 void EmitKeyedStore(StaticType* key_type);
389 void LoadFromGlobalSlotCheckExtensions(Slot* slot,
390 TypeofState typeof_state,
393 // Support for loading from local/global variables and arguments
394 // whose location is known unless they are shadowed by
395 // eval-introduced bindings. Generates no code for unsupported slot
396 // types and therefore expects to fall through to the slow jump target.
397 void EmitDynamicLoadFromSlotFastCase(Slot* slot,
398 TypeofState typeof_state,
402 // Special code for typeof expressions: Unfortunately, we must
403 // be careful when loading the expression in 'typeof'
404 // expressions. We are not allowed to throw reference errors for
405 // non-existing properties of the global object, so we must make it
406 // look like an explicit property access, instead of an access
407 // through the context chain.
408 void LoadTypeofExpression(Expression* x);
410 void ToBoolean(JumpTarget* true_target, JumpTarget* false_target);
412 // Generate code that computes a shortcutting logical operation.
413 void GenerateLogicalBooleanOperation(BinaryOperation* node);
415 void GenericBinaryOperation(Token::Value op,
416 OverwriteMode overwrite_mode,
417 GenerateInlineSmi inline_smi,
418 int known_rhs = kUnknownIntValue);
419 void Comparison(Condition cc,
422 bool strict = false);
424 void SmiOperation(Token::Value op,
425 Handle<Object> value,
429 void CallWithArguments(ZoneList<Expression*>* arguments,
430 CallFunctionFlags flags,
433 // An optimized implementation of expressions of the form
434 // x.apply(y, arguments). We call x the applicand and y the receiver.
435 // The optimization avoids allocating an arguments object if possible.
436 void CallApplyLazy(Expression* applicand,
437 Expression* receiver,
438 VariableProxy* arguments,
442 void Branch(bool if_true, JumpTarget* target);
445 struct InlineRuntimeLUT {
446 void (CodeGenerator::*method)(ZoneList<Expression*>*);
451 static InlineRuntimeLUT* FindInlineRuntimeLUT(Handle<String> name);
452 bool CheckForInlineRuntimeCall(CallRuntime* node);
453 static bool PatchInlineRuntimeEntry(Handle<String> name,
454 const InlineRuntimeLUT& new_entry,
455 InlineRuntimeLUT* old_entry);
457 static Handle<Code> ComputeLazyCompile(int argc);
458 void ProcessDeclarations(ZoneList<Declaration*>* declarations);
460 static Handle<Code> ComputeCallInitialize(int argc, InLoopFlag in_loop);
462 static Handle<Code> ComputeKeyedCallInitialize(int argc, InLoopFlag in_loop);
464 // Declare global variables and functions in the given array of
466 void DeclareGlobals(Handle<FixedArray> pairs);
468 // Instantiate the function based on the shared function info.
469 void InstantiateFunction(Handle<SharedFunctionInfo> function_info);
471 // Support for type checks.
472 void GenerateIsSmi(ZoneList<Expression*>* args);
473 void GenerateIsNonNegativeSmi(ZoneList<Expression*>* args);
474 void GenerateIsArray(ZoneList<Expression*>* args);
475 void GenerateIsRegExp(ZoneList<Expression*>* args);
476 void GenerateIsObject(ZoneList<Expression*>* args);
477 void GenerateIsFunction(ZoneList<Expression*>* args);
478 void GenerateIsUndetectableObject(ZoneList<Expression*>* args);
480 // Support for construct call checks.
481 void GenerateIsConstructCall(ZoneList<Expression*>* args);
483 // Support for arguments.length and arguments[?].
484 void GenerateArgumentsLength(ZoneList<Expression*>* args);
485 void GenerateArguments(ZoneList<Expression*>* args);
487 // Support for accessing the class and value fields of an object.
488 void GenerateClassOf(ZoneList<Expression*>* args);
489 void GenerateValueOf(ZoneList<Expression*>* args);
490 void GenerateSetValueOf(ZoneList<Expression*>* args);
492 // Fast support for charCodeAt(n).
493 void GenerateStringCharCodeAt(ZoneList<Expression*>* args);
495 // Fast support for string.charAt(n) and string[n].
496 void GenerateStringCharFromCode(ZoneList<Expression*>* args);
498 // Fast support for string.charAt(n) and string[n].
499 void GenerateStringCharAt(ZoneList<Expression*>* args);
501 // Fast support for object equality testing.
502 void GenerateObjectEquals(ZoneList<Expression*>* args);
504 void GenerateLog(ZoneList<Expression*>* args);
506 // Fast support for Math.random().
507 void GenerateRandomHeapNumber(ZoneList<Expression*>* args);
509 // Fast support for StringAdd.
510 void GenerateStringAdd(ZoneList<Expression*>* args);
512 // Fast support for SubString.
513 void GenerateSubString(ZoneList<Expression*>* args);
515 // Fast support for StringCompare.
516 void GenerateStringCompare(ZoneList<Expression*>* args);
518 // Support for direct calls from JavaScript to native RegExp code.
519 void GenerateRegExpExec(ZoneList<Expression*>* args);
521 void GenerateRegExpConstructResult(ZoneList<Expression*>* args);
523 // Support for fast native caches.
524 void GenerateGetFromCache(ZoneList<Expression*>* args);
526 // Fast support for number to string.
527 void GenerateNumberToString(ZoneList<Expression*>* args);
529 // Fast swapping of elements.
530 void GenerateSwapElements(ZoneList<Expression*>* args);
532 // Fast call for custom callbacks.
533 void GenerateCallFunction(ZoneList<Expression*>* args);
535 // Fast call to math functions.
536 void GenerateMathPow(ZoneList<Expression*>* args);
537 void GenerateMathSin(ZoneList<Expression*>* args);
538 void GenerateMathCos(ZoneList<Expression*>* args);
539 void GenerateMathSqrt(ZoneList<Expression*>* args);
541 // Simple condition analysis.
542 enum ConditionAnalysis {
547 ConditionAnalysis AnalyzeCondition(Expression* cond);
549 // Methods used to indicate which source code is generated for. Source
550 // positions are collected by the assembler and emitted with the relocation
552 void CodeForFunctionPosition(FunctionLiteral* fun);
553 void CodeForReturnPosition(FunctionLiteral* fun);
554 void CodeForStatementPosition(Statement* node);
555 void CodeForDoWhileConditionPosition(DoWhileStatement* stmt);
556 void CodeForSourcePosition(int pos);
559 // True if the registers are valid for entry to a block.
560 bool HasValidEntryRegisters();
563 List<DeferredCode*> deferred_;
566 MacroAssembler* masm_; // to generate code
568 CompilationInfo* info_;
570 // Code generation state
571 VirtualFrame* frame_;
572 RegisterAllocator* allocator_;
574 CodeGenState* state_;
577 Vector<TypeInfo>* type_info_;
580 BreakTarget function_return_;
582 // True if the function return is shadowed (ie, jumping to the target
583 // function_return_ does not jump to the true function return, but rather
584 // to some unlinking code).
585 bool function_return_is_shadowed_;
587 static InlineRuntimeLUT kInlineRuntimeLUT[];
589 friend class VirtualFrame;
590 friend class JumpTarget;
591 friend class Reference;
592 friend class FastCodeGenerator;
593 friend class FullCodeGenerator;
594 friend class FullCodeGenSyntaxChecker;
596 DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
600 // Compute a transcendental math function natively, or call the
601 // TranscendentalCache runtime function.
602 class TranscendentalCacheStub: public CodeStub {
604 explicit TranscendentalCacheStub(TranscendentalCache::Type type)
606 void Generate(MacroAssembler* masm);
608 TranscendentalCache::Type type_;
609 Major MajorKey() { return TranscendentalCache; }
610 int MinorKey() { return type_; }
611 Runtime::FunctionId RuntimeFunction();
615 class GenericBinaryOpStub : public CodeStub {
617 GenericBinaryOpStub(Token::Value op,
621 int constant_rhs = CodeGenerator::kUnknownIntValue)
626 constant_rhs_(constant_rhs),
627 specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op, constant_rhs)),
628 runtime_operands_type_(BinaryOpIC::DEFAULT),
631 GenericBinaryOpStub(int key, BinaryOpIC::TypeInfo type_info)
632 : op_(OpBits::decode(key)),
633 mode_(ModeBits::decode(key)),
634 lhs_(LhsRegister(RegisterBits::decode(key))),
635 rhs_(RhsRegister(RegisterBits::decode(key))),
636 constant_rhs_(KnownBitsForMinorKey(KnownIntBits::decode(key))),
637 specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op_, constant_rhs_)),
638 runtime_operands_type_(type_info),
647 bool specialized_on_rhs_;
648 BinaryOpIC::TypeInfo runtime_operands_type_;
651 static const int kMaxKnownRhs = 0x40000000;
652 static const int kKnownRhsKeyBits = 6;
654 // Minor key encoding in 17 bits.
655 class ModeBits: public BitField<OverwriteMode, 0, 2> {};
656 class OpBits: public BitField<Token::Value, 2, 6> {};
657 class TypeInfoBits: public BitField<int, 8, 2> {};
658 class RegisterBits: public BitField<bool, 10, 1> {};
659 class KnownIntBits: public BitField<int, 11, kKnownRhsKeyBits> {};
661 Major MajorKey() { return GenericBinaryOp; }
663 ASSERT((lhs_.is(r0) && rhs_.is(r1)) ||
664 (lhs_.is(r1) && rhs_.is(r0)));
665 // Encode the parameters in a unique 18 bit value.
666 return OpBits::encode(op_)
667 | ModeBits::encode(mode_)
668 | KnownIntBits::encode(MinorKeyForKnownInt())
669 | TypeInfoBits::encode(runtime_operands_type_)
670 | RegisterBits::encode(lhs_.is(r0));
673 void Generate(MacroAssembler* masm);
674 void HandleNonSmiBitwiseOp(MacroAssembler* masm,
677 void HandleBinaryOpSlowCases(MacroAssembler* masm,
681 const Builtins::JavaScript& builtin);
682 void GenerateTypeTransition(MacroAssembler* masm);
684 static bool RhsIsOneWeWantToOptimizeFor(Token::Value op, int constant_rhs) {
685 if (constant_rhs == CodeGenerator::kUnknownIntValue) return false;
686 if (op == Token::DIV) return constant_rhs >= 2 && constant_rhs <= 3;
687 if (op == Token::MOD) {
688 if (constant_rhs <= 1) return false;
689 if (constant_rhs <= 10) return true;
690 if (constant_rhs <= kMaxKnownRhs && IsPowerOf2(constant_rhs)) return true;
696 int MinorKeyForKnownInt() {
697 if (!specialized_on_rhs_) return 0;
698 if (constant_rhs_ <= 10) return constant_rhs_ + 1;
699 ASSERT(IsPowerOf2(constant_rhs_));
701 int d = constant_rhs_;
702 while ((d & 1) == 0) {
706 ASSERT(key >= 0 && key < (1 << kKnownRhsKeyBits));
710 int KnownBitsForMinorKey(int key) {
712 if (key <= 11) return key - 1;
721 Register LhsRegister(bool lhs_is_r0) {
722 return lhs_is_r0 ? r0 : r1;
725 Register RhsRegister(bool lhs_is_r0) {
726 return lhs_is_r0 ? r1 : r0;
729 bool ShouldGenerateSmiCode() {
730 return ((op_ != Token::DIV && op_ != Token::MOD) || specialized_on_rhs_) &&
731 runtime_operands_type_ != BinaryOpIC::HEAP_NUMBERS &&
732 runtime_operands_type_ != BinaryOpIC::STRINGS;
735 bool ShouldGenerateFPCode() {
736 return runtime_operands_type_ != BinaryOpIC::STRINGS;
739 virtual int GetCodeKind() { return Code::BINARY_OP_IC; }
741 virtual InlineCacheState GetICState() {
742 return BinaryOpIC::ToState(runtime_operands_type_);
745 const char* GetName();
749 if (!specialized_on_rhs_) {
750 PrintF("GenericBinaryOpStub (%s)\n", Token::String(op_));
752 PrintF("GenericBinaryOpStub (%s by %d)\n",
761 class StringHelper : public AllStatic {
763 // Generate code for copying characters using a simple loop. This should only
764 // be used in places where the number of characters is small and the
765 // additional setup and checking in GenerateCopyCharactersLong adds too much
766 // overhead. Copying of overlapping regions is not supported.
767 // Dest register ends at the position after the last character written.
768 static void GenerateCopyCharacters(MacroAssembler* masm,
775 // Generate code for copying a large number of characters. This function
776 // is allowed to spend extra time setting up conditions to make copying
777 // faster. Copying of overlapping regions is not supported.
778 // Dest register ends at the position after the last character written.
779 static void GenerateCopyCharactersLong(MacroAssembler* masm,
791 // Probe the symbol table for a two character string. If the string is
792 // not found by probing a jump to the label not_found is performed. This jump
793 // does not guarantee that the string is not in the symbol table. If the
794 // string is found the code falls through with the string in register r0.
795 // Contents of both c1 and c2 registers are modified. At the exit c1 is
796 // guaranteed to contain halfword with low and high bytes equal to
797 // initial contents of c1 and c2 respectively.
798 static void GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm,
808 // Generate string hash.
809 static void GenerateHashInit(MacroAssembler* masm,
813 static void GenerateHashAddCharacter(MacroAssembler* masm,
817 static void GenerateHashGetHash(MacroAssembler* masm,
821 DISALLOW_IMPLICIT_CONSTRUCTORS(StringHelper);
825 // Flag that indicates how to generate code for the stub StringAddStub.
826 enum StringAddFlags {
827 NO_STRING_ADD_FLAGS = 0,
828 NO_STRING_CHECK_IN_STUB = 1 << 0 // Omit string check in stub.
832 class StringAddStub: public CodeStub {
834 explicit StringAddStub(StringAddFlags flags) {
835 string_check_ = ((flags & NO_STRING_CHECK_IN_STUB) == 0);
839 Major MajorKey() { return StringAdd; }
840 int MinorKey() { return string_check_ ? 0 : 1; }
842 void Generate(MacroAssembler* masm);
844 // Should the stub check whether arguments are strings?
849 class SubStringStub: public CodeStub {
854 Major MajorKey() { return SubString; }
855 int MinorKey() { return 0; }
857 void Generate(MacroAssembler* masm);
862 class StringCompareStub: public CodeStub {
864 StringCompareStub() { }
866 // Compare two flat ASCII strings and returns result in r0.
867 // Does not use the stack.
868 static void GenerateCompareFlatAsciiStrings(MacroAssembler* masm,
877 Major MajorKey() { return StringCompare; }
878 int MinorKey() { return 0; }
880 void Generate(MacroAssembler* masm);
884 // This stub can convert a signed int32 to a heap number (double). It does
885 // not work for int32s that are in Smi range! No GC occurs during this stub
886 // so you don't have to set up the frame.
887 class WriteInt32ToHeapNumberStub : public CodeStub {
889 WriteInt32ToHeapNumberStub(Register the_int,
890 Register the_heap_number,
893 the_heap_number_(the_heap_number),
894 scratch_(scratch) { }
898 Register the_heap_number_;
901 // Minor key encoding in 16 bits.
902 class IntRegisterBits: public BitField<int, 0, 4> {};
903 class HeapNumberRegisterBits: public BitField<int, 4, 4> {};
904 class ScratchRegisterBits: public BitField<int, 8, 4> {};
906 Major MajorKey() { return WriteInt32ToHeapNumber; }
908 // Encode the parameters in a unique 16 bit value.
909 return IntRegisterBits::encode(the_int_.code())
910 | HeapNumberRegisterBits::encode(the_heap_number_.code())
911 | ScratchRegisterBits::encode(scratch_.code());
914 void Generate(MacroAssembler* masm);
916 const char* GetName() { return "WriteInt32ToHeapNumberStub"; }
919 void Print() { PrintF("WriteInt32ToHeapNumberStub\n"); }
924 class NumberToStringStub: public CodeStub {
926 NumberToStringStub() { }
928 // Generate code to do a lookup in the number string cache. If the number in
929 // the register object is found in the cache the generated code falls through
930 // with the result in the result register. The object and the result register
931 // can be the same. If the number is not found in the cache the code jumps to
932 // the label not_found with only the content of register object unchanged.
933 static void GenerateLookupNumberStringCache(MacroAssembler* masm,
943 Major MajorKey() { return NumberToString; }
944 int MinorKey() { return 0; }
946 void Generate(MacroAssembler* masm);
948 const char* GetName() { return "NumberToStringStub"; }
952 PrintF("NumberToStringStub\n");
958 class RecordWriteStub : public CodeStub {
960 RecordWriteStub(Register object, Register offset, Register scratch)
961 : object_(object), offset_(offset), scratch_(scratch) { }
963 void Generate(MacroAssembler* masm);
972 PrintF("RecordWriteStub (object reg %d), (offset reg %d),"
973 " (scratch reg %d)\n",
974 object_.code(), offset_.code(), scratch_.code());
978 // Minor key encoding in 12 bits. 4 bits for each of the three
979 // registers (object, offset and scratch) OOOOAAAASSSS.
980 class ScratchBits: public BitField<uint32_t, 0, 4> {};
981 class OffsetBits: public BitField<uint32_t, 4, 4> {};
982 class ObjectBits: public BitField<uint32_t, 8, 4> {};
984 Major MajorKey() { return RecordWrite; }
987 // Encode the registers.
988 return ObjectBits::encode(object_.code()) |
989 OffsetBits::encode(offset_.code()) |
990 ScratchBits::encode(scratch_.code());
995 } } // namespace v8::internal
997 #endif // V8_ARM_CODEGEN_ARM_H_