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
35 // ProcessDeclarations
37 // CheckForInlineRuntimeCall
39 // CodeForFunctionPosition
40 // CodeForReturnPosition
41 // CodeForStatementPosition
42 // CodeForDoWhileConditionPosition
43 // CodeForSourcePosition
45 #if V8_TARGET_ARCH_IA32
46 #include "src/ia32/codegen-ia32.h" // NOLINT
47 #elif V8_TARGET_ARCH_X64
48 #include "src/x64/codegen-x64.h" // NOLINT
49 #elif V8_TARGET_ARCH_ARM64
50 #include "src/arm64/codegen-arm64.h" // NOLINT
51 #elif V8_TARGET_ARCH_ARM
52 #include "src/arm/codegen-arm.h" // NOLINT
53 #elif V8_TARGET_ARCH_PPC
54 #include "src/ppc/codegen-ppc.h" // NOLINT
55 #elif V8_TARGET_ARCH_MIPS
56 #include "src/mips/codegen-mips.h" // NOLINT
57 #elif V8_TARGET_ARCH_MIPS64
58 #include "src/mips64/codegen-mips64.h" // NOLINT
59 #elif V8_TARGET_ARCH_X87
60 #include "src/x87/codegen-x87.h" // NOLINT
62 #error Unsupported target architecture.
69 class CompilationInfo;
74 // Printing of AST, etc. as requested by flags.
75 static void MakeCodePrologue(CompilationInfo* info, const char* kind);
77 // Allocate and install the code.
78 static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm,
79 CompilationInfo* info);
81 // Print the code after compiling it.
82 static void PrintCode(Handle<Code> code, CompilationInfo* info);
85 DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
89 // Results of the library implementation of transcendental functions may differ
90 // from the one we use in our generated code. Therefore we use the same
91 // generated code both in runtime and compiled code.
92 typedef double (*UnaryMathFunction)(double x);
94 UnaryMathFunction CreateExpFunction();
95 UnaryMathFunction CreateSqrtFunction();
98 double modulo(double x, double y);
100 // Custom implementation of math functions.
101 double fast_exp(double input);
102 double fast_sqrt(double input);
104 void init_modulo_function();
106 void lazily_initialize_fast_exp();
107 void init_fast_sqrt_function();
110 class ElementsTransitionGenerator : public AllStatic {
112 // If |mode| is set to DONT_TRACK_ALLOCATION_SITE,
113 // |allocation_memento_found| may be NULL.
114 static void GenerateMapChangeElementsTransition(
115 MacroAssembler* masm,
120 AllocationSiteMode mode,
121 Label* allocation_memento_found);
122 static void GenerateSmiToDouble(
123 MacroAssembler* masm,
128 AllocationSiteMode mode,
130 static void GenerateDoubleToObject(
131 MacroAssembler* masm,
136 AllocationSiteMode mode,
140 DISALLOW_COPY_AND_ASSIGN(ElementsTransitionGenerator);
143 static const int kNumberDictionaryProbes = 4;
146 class CodeAgingHelper {
150 uint32_t young_sequence_length() const { return young_sequence_.length(); }
151 bool IsYoung(byte* candidate) const {
152 return memcmp(candidate,
153 young_sequence_.start(),
154 young_sequence_.length()) == 0;
156 void CopyYoungSequenceTo(byte* new_buffer) const {
157 CopyBytes(new_buffer, young_sequence_.start(), young_sequence_.length());
161 bool IsOld(byte* candidate) const;
165 const EmbeddedVector<byte, kNoCodeAgeSequenceLength> young_sequence_;
167 #ifdef V8_TARGET_ARCH_ARM64
168 const EmbeddedVector<byte, kNoCodeAgeSequenceLength> old_sequence_;
173 } } // namespace v8::internal
175 #endif // V8_CODEGEN_H_