• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef V8_CODEGEN_H_
6 #define V8_CODEGEN_H_
7 
8 #include "src/code-stubs.h"
9 #include "src/runtime/runtime.h"
10 
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:
14 //   MakeCode
15 //   MakeCodePrologue
16 //   MakeCodeEpilogue
17 //   masm
18 //   frame
19 //   script
20 //   has_valid_frame
21 //   SetFrame
22 //   DeleteFrame
23 //   allocator
24 //   AddDeferred
25 //   in_spilled_code
26 //   set_in_spilled_code
27 //   RecordPositions
28 //
29 // These methods are either used privately by the shared code or implemented as
30 // shared code:
31 //   CodeGenerator
32 //   ~CodeGenerator
33 //   Generate
34 //   ComputeLazyCompile
35 //   ProcessDeclarations
36 //   DeclareGlobals
37 //   CheckForInlineRuntimeCall
38 //   AnalyzeCondition
39 //   CodeForFunctionPosition
40 //   CodeForReturnPosition
41 //   CodeForStatementPosition
42 //   CodeForDoWhileConditionPosition
43 //   CodeForSourcePosition
44 
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_S390
60 #include "src/s390/codegen-s390.h"  // NOLINT
61 #elif V8_TARGET_ARCH_X87
62 #include "src/x87/codegen-x87.h"  // NOLINT
63 #else
64 #error Unsupported target architecture.
65 #endif
66 
67 namespace v8 {
68 namespace internal {
69 
70 
71 class CompilationInfo;
72 
73 
74 class CodeGenerator {
75  public:
76   // Printing of AST, etc. as requested by flags.
77   static void MakeCodePrologue(CompilationInfo* info, const char* kind);
78 
79   // Allocate and install the code.
80   static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm,
81                                        CompilationInfo* info);
82 
83   // Print the code after compiling it.
84   static void PrintCode(Handle<Code> code, CompilationInfo* info);
85 
86  private:
87   DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
88 };
89 
90 
91 // Results of the library implementation of transcendental functions may differ
92 // from the one we use in our generated code.  Therefore we use the same
93 // generated code both in runtime and compiled code.
94 typedef double (*UnaryMathFunctionWithIsolate)(double x, Isolate* isolate);
95 
96 UnaryMathFunctionWithIsolate CreateSqrtFunction(Isolate* isolate);
97 
98 
99 double modulo(double x, double y);
100 
101 // Custom implementation of math functions.
102 double fast_sqrt(double input, Isolate* isolate);
103 void lazily_initialize_fast_sqrt(Isolate* isolate);
104 
105 
106 class ElementsTransitionGenerator : public AllStatic {
107  public:
108   // If |mode| is set to DONT_TRACK_ALLOCATION_SITE,
109   // |allocation_memento_found| may be NULL.
110   static void GenerateMapChangeElementsTransition(
111       MacroAssembler* masm,
112       Register receiver,
113       Register key,
114       Register value,
115       Register target_map,
116       AllocationSiteMode mode,
117       Label* allocation_memento_found);
118   static void GenerateSmiToDouble(
119       MacroAssembler* masm,
120       Register receiver,
121       Register key,
122       Register value,
123       Register target_map,
124       AllocationSiteMode mode,
125       Label* fail);
126   static void GenerateDoubleToObject(
127       MacroAssembler* masm,
128       Register receiver,
129       Register key,
130       Register value,
131       Register target_map,
132       AllocationSiteMode mode,
133       Label* fail);
134 
135  private:
136   DISALLOW_COPY_AND_ASSIGN(ElementsTransitionGenerator);
137 };
138 
139 static const int kNumberDictionaryProbes = 4;
140 
141 
142 class CodeAgingHelper {
143  public:
144   explicit CodeAgingHelper(Isolate* isolate);
145 
young_sequence_length()146   uint32_t young_sequence_length() const { return young_sequence_.length(); }
IsYoung(byte * candidate)147   bool IsYoung(byte* candidate) const {
148     return memcmp(candidate,
149                   young_sequence_.start(),
150                   young_sequence_.length()) == 0;
151   }
CopyYoungSequenceTo(byte * new_buffer)152   void CopyYoungSequenceTo(byte* new_buffer) const {
153     CopyBytes(new_buffer, young_sequence_.start(), young_sequence_.length());
154   }
155 
156 #ifdef DEBUG
157   bool IsOld(byte* candidate) const;
158 #endif
159 
160  protected:
161   const EmbeddedVector<byte, kNoCodeAgeSequenceLength> young_sequence_;
162 #ifdef DEBUG
163 #ifdef V8_TARGET_ARCH_ARM64
164   const EmbeddedVector<byte, kNoCodeAgeSequenceLength> old_sequence_;
165 #endif
166 #endif
167 };
168 
169 }  // namespace internal
170 }  // namespace v8
171 
172 #endif  // V8_CODEGEN_H_
173