Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
| 5 | #ifndef V8_CODEGEN_H_ |
| 6 | #define V8_CODEGEN_H_ |
| 7 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8 | #include "src/code-stubs.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9 | #include "src/runtime/runtime.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 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 |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 15 | // MakeCodePrologue |
| 16 | // MakeCodeEpilogue |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 17 | // masm |
| 18 | // frame |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 19 | // script |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 20 | // has_valid_frame |
| 21 | // SetFrame |
| 22 | // DeleteFrame |
| 23 | // allocator |
| 24 | // AddDeferred |
| 25 | // in_spilled_code |
| 26 | // set_in_spilled_code |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 27 | // RecordPositions |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 28 | // |
| 29 | // These methods are either used privately by the shared code or implemented as |
| 30 | // shared code: |
| 31 | // CodeGenerator |
| 32 | // ~CodeGenerator |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 33 | // Generate |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 34 | // ComputeLazyCompile |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 35 | // ProcessDeclarations |
| 36 | // DeclareGlobals |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 37 | // CheckForInlineRuntimeCall |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 38 | // AnalyzeCondition |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 39 | // CodeForFunctionPosition |
| 40 | // CodeForReturnPosition |
| 41 | // CodeForStatementPosition |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 42 | // CodeForDoWhileConditionPosition |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 43 | // CodeForSourcePosition |
| 44 | |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 45 | #if V8_TARGET_ARCH_IA32 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 46 | #include "src/ia32/codegen-ia32.h" // NOLINT |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 47 | #elif V8_TARGET_ARCH_X64 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 48 | #include "src/x64/codegen-x64.h" // NOLINT |
| 49 | #elif V8_TARGET_ARCH_ARM64 |
| 50 | #include "src/arm64/codegen-arm64.h" // NOLINT |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 51 | #elif V8_TARGET_ARCH_ARM |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 52 | #include "src/arm/codegen-arm.h" // NOLINT |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 53 | #elif V8_TARGET_ARCH_PPC |
| 54 | #include "src/ppc/codegen-ppc.h" // NOLINT |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 55 | #elif V8_TARGET_ARCH_MIPS |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 61 | #else |
| 62 | #error Unsupported target architecture. |
| 63 | #endif |
| 64 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 65 | namespace v8 { |
| 66 | namespace internal { |
| 67 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 68 | |
| 69 | class CompilationInfo; |
| 70 | |
| 71 | |
| 72 | class CodeGenerator { |
| 73 | public: |
| 74 | // Printing of AST, etc. as requested by flags. |
| 75 | static void MakeCodePrologue(CompilationInfo* info, const char* kind); |
| 76 | |
| 77 | // Allocate and install the code. |
| 78 | static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 79 | CompilationInfo* info); |
| 80 | |
| 81 | // Print the code after compiling it. |
| 82 | static void PrintCode(Handle<Code> code, CompilationInfo* info); |
| 83 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 84 | private: |
| 85 | DISALLOW_COPY_AND_ASSIGN(CodeGenerator); |
| 86 | }; |
| 87 | |
| 88 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 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. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 92 | typedef double (*UnaryMathFunctionWithIsolate)(double x, Isolate* isolate); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 93 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 94 | UnaryMathFunctionWithIsolate CreateExpFunction(Isolate* isolate); |
| 95 | UnaryMathFunctionWithIsolate CreateSqrtFunction(Isolate* isolate); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 96 | |
| 97 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 98 | double modulo(double x, double y); |
| 99 | |
| 100 | // Custom implementation of math functions. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 101 | double fast_exp(double input, Isolate* isolate); |
| 102 | double fast_sqrt(double input, Isolate* isolate); |
| 103 | void lazily_initialize_fast_exp(Isolate* isolate); |
| 104 | void lazily_initialize_fast_sqrt(Isolate* isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 105 | |
| 106 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 107 | class ElementsTransitionGenerator : public AllStatic { |
| 108 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 109 | // If |mode| is set to DONT_TRACK_ALLOCATION_SITE, |
| 110 | // |allocation_memento_found| may be NULL. |
| 111 | static void GenerateMapChangeElementsTransition( |
| 112 | MacroAssembler* masm, |
| 113 | Register receiver, |
| 114 | Register key, |
| 115 | Register value, |
| 116 | Register target_map, |
| 117 | AllocationSiteMode mode, |
| 118 | Label* allocation_memento_found); |
| 119 | static void GenerateSmiToDouble( |
| 120 | MacroAssembler* masm, |
| 121 | Register receiver, |
| 122 | Register key, |
| 123 | Register value, |
| 124 | Register target_map, |
| 125 | AllocationSiteMode mode, |
| 126 | Label* fail); |
| 127 | static void GenerateDoubleToObject( |
| 128 | MacroAssembler* masm, |
| 129 | Register receiver, |
| 130 | Register key, |
| 131 | Register value, |
| 132 | Register target_map, |
| 133 | AllocationSiteMode mode, |
| 134 | Label* fail); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 135 | |
| 136 | private: |
| 137 | DISALLOW_COPY_AND_ASSIGN(ElementsTransitionGenerator); |
| 138 | }; |
| 139 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 140 | static const int kNumberDictionaryProbes = 4; |
| 141 | |
| 142 | |
| 143 | class CodeAgingHelper { |
| 144 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 145 | explicit CodeAgingHelper(Isolate* isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 146 | |
| 147 | uint32_t young_sequence_length() const { return young_sequence_.length(); } |
| 148 | bool IsYoung(byte* candidate) const { |
| 149 | return memcmp(candidate, |
| 150 | young_sequence_.start(), |
| 151 | young_sequence_.length()) == 0; |
| 152 | } |
| 153 | void CopyYoungSequenceTo(byte* new_buffer) const { |
| 154 | CopyBytes(new_buffer, young_sequence_.start(), young_sequence_.length()); |
| 155 | } |
| 156 | |
| 157 | #ifdef DEBUG |
| 158 | bool IsOld(byte* candidate) const; |
| 159 | #endif |
| 160 | |
| 161 | protected: |
| 162 | const EmbeddedVector<byte, kNoCodeAgeSequenceLength> young_sequence_; |
| 163 | #ifdef DEBUG |
| 164 | #ifdef V8_TARGET_ARCH_ARM64 |
| 165 | const EmbeddedVector<byte, kNoCodeAgeSequenceLength> old_sequence_; |
| 166 | #endif |
| 167 | #endif |
| 168 | }; |
| 169 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 170 | } // namespace internal |
| 171 | } // namespace v8 |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 172 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 173 | #endif // V8_CODEGEN_H_ |