1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 #include "src/code-stubs.h"
9 #include "src/runtime/runtime.h"
11 // Include the declaration of the architecture defined class CodeGenerator.
12 // The contract to the shared code is that the the CodeGenerator is a subclass
13 // of Visitor and that the following methods are available publicly:
26 // set_in_spilled_code
29 // These methods are either used privately by the shared code or implemented as
36 // ProcessDeclarations
38 // CheckForInlineRuntimeCall
40 // CodeForFunctionPosition
41 // CodeForReturnPosition
42 // CodeForStatementPosition
43 // CodeForDoWhileConditionPosition
44 // CodeForSourcePosition
46 enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF };
48 #if V8_TARGET_ARCH_IA32
49 #include "src/ia32/codegen-ia32.h" // NOLINT
50 #elif V8_TARGET_ARCH_X64
51 #include "src/x64/codegen-x64.h" // NOLINT
52 #elif V8_TARGET_ARCH_ARM64
53 #include "src/arm64/codegen-arm64.h" // NOLINT
54 #elif V8_TARGET_ARCH_ARM
55 #include "src/arm/codegen-arm.h" // NOLINT
56 #elif V8_TARGET_ARCH_MIPS
57 #include "src/mips/codegen-mips.h" // NOLINT
58 #elif V8_TARGET_ARCH_MIPS64
59 #include "src/mips64/codegen-mips64.h" // NOLINT
60 #elif V8_TARGET_ARCH_X87
61 #include "src/x87/codegen-x87.h" // NOLINT
63 #error Unsupported target architecture.
70 class CompilationInfo;
75 // Printing of AST, etc. as requested by flags.
76 static void MakeCodePrologue(CompilationInfo* info, const char* kind);
78 // Allocate and install the code.
79 static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm,
81 CompilationInfo* info);
83 // Print the code after compiling it.
84 static void PrintCode(Handle<Code> code, CompilationInfo* info);
86 static bool RecordPositions(MacroAssembler* masm,
88 bool right_here = false);
91 DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
95 // Results of the library implementation of transcendental functions may differ
96 // from the one we use in our generated code. Therefore we use the same
97 // generated code both in runtime and compiled code.
98 typedef double (*UnaryMathFunction)(double x);
100 UnaryMathFunction CreateExpFunction();
101 UnaryMathFunction CreateSqrtFunction();
104 double modulo(double x, double y);
106 // Custom implementation of math functions.
107 double fast_exp(double input);
108 double fast_sqrt(double input);
110 void init_modulo_function();
112 void lazily_initialize_fast_exp();
113 void init_fast_sqrt_function();
116 class ElementsTransitionGenerator : public AllStatic {
118 // If |mode| is set to DONT_TRACK_ALLOCATION_SITE,
119 // |allocation_memento_found| may be NULL.
120 static void GenerateMapChangeElementsTransition(
121 MacroAssembler* masm,
126 AllocationSiteMode mode,
127 Label* allocation_memento_found);
128 static void GenerateSmiToDouble(
129 MacroAssembler* masm,
134 AllocationSiteMode mode,
136 static void GenerateDoubleToObject(
137 MacroAssembler* masm,
142 AllocationSiteMode mode,
146 DISALLOW_COPY_AND_ASSIGN(ElementsTransitionGenerator);
149 static const int kNumberDictionaryProbes = 4;
152 class CodeAgingHelper {
156 uint32_t young_sequence_length() const { return young_sequence_.length(); }
157 bool IsYoung(byte* candidate) const {
158 return memcmp(candidate,
159 young_sequence_.start(),
160 young_sequence_.length()) == 0;
162 void CopyYoungSequenceTo(byte* new_buffer) const {
163 CopyBytes(new_buffer, young_sequence_.start(), young_sequence_.length());
167 bool IsOld(byte* candidate) const;
171 const EmbeddedVector<byte, kNoCodeAgeSequenceLength> young_sequence_;
173 #ifdef V8_TARGET_ARCH_ARM64
174 const EmbeddedVector<byte, kNoCodeAgeSequenceLength> old_sequence_;
179 } } // namespace v8::internal
181 #endif // V8_CODEGEN_H_