blob: f941696774d105aaf3622715dd9ffba247f78b12 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
5#ifndef V8_CODEGEN_H_
6#define V8_CODEGEN_H_
7
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/code-stubs.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -04009#include "src/runtime/runtime.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000010
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
Steve Block3ce2e202009-11-05 08:53:23 +000015// MakeCodePrologue
16// MakeCodeEpilogue
Steve Blocka7e24c12009-10-30 11:49:00 +000017// masm
18// frame
Steve Blockd0582a62009-12-15 09:54:21 +000019// script
Steve Blocka7e24c12009-10-30 11:49:00 +000020// has_valid_frame
21// SetFrame
22// DeleteFrame
23// allocator
24// AddDeferred
25// in_spilled_code
26// set_in_spilled_code
Steve Block3ce2e202009-11-05 08:53:23 +000027// RecordPositions
Steve Blocka7e24c12009-10-30 11:49:00 +000028//
29// These methods are either used privately by the shared code or implemented as
30// shared code:
31// CodeGenerator
32// ~CodeGenerator
Leon Clarke4515c472010-02-03 11:58:03 +000033// Generate
Steve Block3ce2e202009-11-05 08:53:23 +000034// ComputeLazyCompile
Steve Blocka7e24c12009-10-30 11:49:00 +000035// ProcessDeclarations
36// DeclareGlobals
Steve Blocka7e24c12009-10-30 11:49:00 +000037// CheckForInlineRuntimeCall
Steve Block3ce2e202009-11-05 08:53:23 +000038// AnalyzeCondition
Steve Blocka7e24c12009-10-30 11:49:00 +000039// CodeForFunctionPosition
40// CodeForReturnPosition
41// CodeForStatementPosition
Steve Blockd0582a62009-12-15 09:54:21 +000042// CodeForDoWhileConditionPosition
Steve Blocka7e24c12009-10-30 11:49:00 +000043// CodeForSourcePosition
44
Ben Murdochbb769b22010-08-11 14:56:33 +010045#if V8_TARGET_ARCH_IA32
Ben Murdochb8a8cc12014-11-26 15:28:44 +000046#include "src/ia32/codegen-ia32.h" // NOLINT
Ben Murdochbb769b22010-08-11 14:56:33 +010047#elif V8_TARGET_ARCH_X64
Ben Murdochb8a8cc12014-11-26 15:28:44 +000048#include "src/x64/codegen-x64.h" // NOLINT
49#elif V8_TARGET_ARCH_ARM64
50#include "src/arm64/codegen-arm64.h" // NOLINT
Ben Murdochbb769b22010-08-11 14:56:33 +010051#elif V8_TARGET_ARCH_ARM
Ben Murdochb8a8cc12014-11-26 15:28:44 +000052#include "src/arm/codegen-arm.h" // NOLINT
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000053#elif V8_TARGET_ARCH_PPC
54#include "src/ppc/codegen-ppc.h" // NOLINT
Ben Murdochbb769b22010-08-11 14:56:33 +010055#elif V8_TARGET_ARCH_MIPS
Ben Murdochb8a8cc12014-11-26 15:28:44 +000056#include "src/mips/codegen-mips.h" // NOLINT
57#elif V8_TARGET_ARCH_MIPS64
58#include "src/mips64/codegen-mips64.h" // NOLINT
Ben Murdochda12d292016-06-02 14:46:10 +010059#elif V8_TARGET_ARCH_S390
60#include "src/s390/codegen-s390.h" // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +000061#elif V8_TARGET_ARCH_X87
62#include "src/x87/codegen-x87.h" // NOLINT
Ben Murdochbb769b22010-08-11 14:56:33 +010063#else
64#error Unsupported target architecture.
65#endif
66
Ben Murdoch3ef787d2012-04-12 10:51:47 +010067namespace v8 {
68namespace internal {
69
Ben Murdochb8a8cc12014-11-26 15:28:44 +000070
71class CompilationInfo;
72
73
74class 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,
Ben Murdochb8a8cc12014-11-26 15:28:44 +000081 CompilationInfo* info);
82
83 // Print the code after compiling it.
84 static void PrintCode(Handle<Code> code, CompilationInfo* info);
85
Ben Murdochb8a8cc12014-11-26 15:28:44 +000086 private:
87 DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
88};
89
90
Ben Murdoch3ef787d2012-04-12 10:51:47 +010091// 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.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000094typedef double (*UnaryMathFunctionWithIsolate)(double x, Isolate* isolate);
Ben Murdoch3ef787d2012-04-12 10:51:47 +010095
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000096UnaryMathFunctionWithIsolate CreateExpFunction(Isolate* isolate);
97UnaryMathFunctionWithIsolate CreateSqrtFunction(Isolate* isolate);
Ben Murdoch3ef787d2012-04-12 10:51:47 +010098
99
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000100double modulo(double x, double y);
101
102// Custom implementation of math functions.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000103double fast_exp(double input, Isolate* isolate);
104double fast_sqrt(double input, Isolate* isolate);
105void lazily_initialize_fast_exp(Isolate* isolate);
106void lazily_initialize_fast_sqrt(Isolate* isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000107
108
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100109class ElementsTransitionGenerator : public AllStatic {
110 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000111 // If |mode| is set to DONT_TRACK_ALLOCATION_SITE,
112 // |allocation_memento_found| may be NULL.
113 static void GenerateMapChangeElementsTransition(
114 MacroAssembler* masm,
115 Register receiver,
116 Register key,
117 Register value,
118 Register target_map,
119 AllocationSiteMode mode,
120 Label* allocation_memento_found);
121 static void GenerateSmiToDouble(
122 MacroAssembler* masm,
123 Register receiver,
124 Register key,
125 Register value,
126 Register target_map,
127 AllocationSiteMode mode,
128 Label* fail);
129 static void GenerateDoubleToObject(
130 MacroAssembler* masm,
131 Register receiver,
132 Register key,
133 Register value,
134 Register target_map,
135 AllocationSiteMode mode,
136 Label* fail);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100137
138 private:
139 DISALLOW_COPY_AND_ASSIGN(ElementsTransitionGenerator);
140};
141
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000142static const int kNumberDictionaryProbes = 4;
143
144
145class CodeAgingHelper {
146 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000147 explicit CodeAgingHelper(Isolate* isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000148
149 uint32_t young_sequence_length() const { return young_sequence_.length(); }
150 bool IsYoung(byte* candidate) const {
151 return memcmp(candidate,
152 young_sequence_.start(),
153 young_sequence_.length()) == 0;
154 }
155 void CopyYoungSequenceTo(byte* new_buffer) const {
156 CopyBytes(new_buffer, young_sequence_.start(), young_sequence_.length());
157 }
158
159#ifdef DEBUG
160 bool IsOld(byte* candidate) const;
161#endif
162
163 protected:
164 const EmbeddedVector<byte, kNoCodeAgeSequenceLength> young_sequence_;
165#ifdef DEBUG
166#ifdef V8_TARGET_ARCH_ARM64
167 const EmbeddedVector<byte, kNoCodeAgeSequenceLength> old_sequence_;
168#endif
169#endif
170};
171
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000172} // namespace internal
173} // namespace v8
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100174
Steve Blocka7e24c12009-10-30 11:49:00 +0000175#endif // V8_CODEGEN_H_