Home | History | Annotate | Download | only in src
      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/globals.h"
     10 #include "src/runtime/runtime.h"
     11 
     12 // Include the declaration of the architecture defined class CodeGenerator.
     13 // The contract  to the shared code is that the the CodeGenerator is a subclass
     14 // of Visitor and that the following methods are available publicly:
     15 //   MakeCode
     16 //   MakeCodePrologue
     17 //   MakeCodeEpilogue
     18 //   masm
     19 //   frame
     20 //   script
     21 //   has_valid_frame
     22 //   SetFrame
     23 //   DeleteFrame
     24 //   allocator
     25 //   AddDeferred
     26 //   in_spilled_code
     27 //   set_in_spilled_code
     28 //   RecordPositions
     29 //
     30 // These methods are either used privately by the shared code or implemented as
     31 // shared code:
     32 //   CodeGenerator
     33 //   ~CodeGenerator
     34 //   Generate
     35 //   ComputeLazyCompile
     36 //   ProcessDeclarations
     37 //   DeclareGlobals
     38 //   CheckForInlineRuntimeCall
     39 //   AnalyzeCondition
     40 //   CodeForFunctionPosition
     41 //   CodeForReturnPosition
     42 //   CodeForStatementPosition
     43 //   CodeForDoWhileConditionPosition
     44 //   CodeForSourcePosition
     45 
     46 #if V8_TARGET_ARCH_IA32
     47 #include "src/ia32/codegen-ia32.h"  // NOLINT
     48 #elif V8_TARGET_ARCH_X64
     49 #include "src/x64/codegen-x64.h"  // NOLINT
     50 #elif V8_TARGET_ARCH_ARM64
     51 #include "src/arm64/codegen-arm64.h"  // NOLINT
     52 #elif V8_TARGET_ARCH_ARM
     53 #include "src/arm/codegen-arm.h"  // NOLINT
     54 #elif V8_TARGET_ARCH_PPC
     55 #include "src/ppc/codegen-ppc.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_S390
     61 #include "src/s390/codegen-s390.h"  // NOLINT
     62 #elif V8_TARGET_ARCH_X87
     63 #include "src/x87/codegen-x87.h"  // NOLINT
     64 #else
     65 #error Unsupported target architecture.
     66 #endif
     67 
     68 namespace v8 {
     69 namespace internal {
     70 
     71 
     72 class CompilationInfo;
     73 class EhFrameWriter;
     74 
     75 class CodeGenerator {
     76  public:
     77   // Printing of AST, etc. as requested by flags.
     78   static void MakeCodePrologue(CompilationInfo* info, const char* kind);
     79 
     80   // Allocate and install the code.
     81   static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm,
     82                                        EhFrameWriter* unwinding,
     83                                        CompilationInfo* info,
     84                                        Handle<Object> self_reference);
     85 
     86   // Print the code after compiling it.
     87   static void PrintCode(Handle<Code> code, CompilationInfo* info);
     88 
     89  private:
     90   DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
     91 };
     92 
     93 
     94 // Results of the library implementation of transcendental functions may differ
     95 // from the one we use in our generated code.  Therefore we use the same
     96 // generated code both in runtime and compiled code.
     97 typedef double (*UnaryMathFunctionWithIsolate)(double x, Isolate* isolate);
     98 
     99 UnaryMathFunctionWithIsolate CreateSqrtFunction(Isolate* isolate);
    100 
    101 V8_EXPORT_PRIVATE double modulo(double x, double y);
    102 
    103 // Custom implementation of math functions.
    104 double fast_sqrt(double input, Isolate* isolate);
    105 void lazily_initialize_fast_sqrt(Isolate* isolate);
    106 
    107 class CodeAgingHelper {
    108  public:
    109   explicit CodeAgingHelper(Isolate* isolate);
    110 
    111   uint32_t young_sequence_length() const { return young_sequence_.length(); }
    112   bool IsYoung(byte* candidate) const {
    113     return memcmp(candidate,
    114                   young_sequence_.start(),
    115                   young_sequence_.length()) == 0;
    116   }
    117   void CopyYoungSequenceTo(byte* new_buffer) const {
    118     CopyBytes(new_buffer, young_sequence_.start(), young_sequence_.length());
    119   }
    120 
    121 #ifdef DEBUG
    122   bool IsOld(byte* candidate) const;
    123 #endif
    124 
    125  protected:
    126   const EmbeddedVector<byte, kNoCodeAgeSequenceLength> young_sequence_;
    127 #ifdef DEBUG
    128 #ifdef V8_TARGET_ARCH_ARM64
    129   const EmbeddedVector<byte, kNoCodeAgeSequenceLength> old_sequence_;
    130 #endif
    131 #endif
    132 };
    133 
    134 }  // namespace internal
    135 }  // namespace v8
    136 
    137 #endif  // V8_CODEGEN_H_
    138