• 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_MACRO_ASSEMBLER_H_
6 #define V8_CODEGEN_MACRO_ASSEMBLER_H_
7 
8 #include "src/codegen/turbo-assembler.h"
9 #include "src/execution/frames.h"
10 #include "src/heap/heap.h"
11 
12 // Helper types to make boolean flag easier to read at call-site.
13 enum InvokeFlag { CALL_FUNCTION, JUMP_FUNCTION };
14 
15 // Flags used for the AllocateInNewSpace functions.
16 enum AllocationFlags {
17   // No special flags.
18   NO_ALLOCATION_FLAGS = 0,
19   // The content of the result register already contains the allocation top in
20   // new space.
21   RESULT_CONTAINS_TOP = 1 << 0,
22   // Specify that the requested size of the space to allocate is specified in
23   // words instead of bytes.
24   SIZE_IN_WORDS = 1 << 1,
25   // Align the allocation to a multiple of kDoubleSize
26   DOUBLE_ALIGNMENT = 1 << 2,
27   // Directly allocate in old space
28   PRETENURE = 1 << 3,
29 };
30 
31 // This is the only place allowed to include the platform-specific headers.
32 #define INCLUDED_FROM_MACRO_ASSEMBLER_H
33 #if V8_TARGET_ARCH_IA32
34 #include "src/codegen/ia32/macro-assembler-ia32.h"
35 #elif V8_TARGET_ARCH_X64
36 #include "src/codegen/x64/macro-assembler-x64.h"
37 #elif V8_TARGET_ARCH_ARM64
38 #include "src/codegen/arm64/constants-arm64.h"
39 #include "src/codegen/arm64/macro-assembler-arm64.h"
40 #elif V8_TARGET_ARCH_ARM
41 #include "src/codegen/arm/constants-arm.h"
42 #include "src/codegen/arm/macro-assembler-arm.h"
43 #elif V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_PPC64
44 #include "src/codegen/ppc/constants-ppc.h"
45 #include "src/codegen/ppc/macro-assembler-ppc.h"
46 #elif V8_TARGET_ARCH_MIPS
47 #include "src/codegen/mips/constants-mips.h"
48 #include "src/codegen/mips/macro-assembler-mips.h"
49 #elif V8_TARGET_ARCH_MIPS64
50 #include "src/codegen/mips64/constants-mips64.h"
51 #include "src/codegen/mips64/macro-assembler-mips64.h"
52 #elif V8_TARGET_ARCH_S390
53 #include "src/codegen/s390/constants-s390.h"
54 #include "src/codegen/s390/macro-assembler-s390.h"
55 #else
56 #error Unsupported target architecture.
57 #endif
58 #undef INCLUDED_FROM_MACRO_ASSEMBLER_H
59 
60 namespace v8 {
61 namespace internal {
62 
63 // Maximum number of parameters supported in calls to C/C++. The C++ standard
64 // defines a limit of 256 parameters but in simulator builds we provide only
65 // limited support.
66 #ifdef USE_SIMULATOR
67 static constexpr int kMaxCParameters = 10;
68 #else
69 static constexpr int kMaxCParameters = 256;
70 #endif
71 
72 class FrameScope {
73  public:
FrameScope(TurboAssembler * tasm,StackFrame::Type type)74   explicit FrameScope(TurboAssembler* tasm, StackFrame::Type type)
75       : tasm_(tasm), type_(type), old_has_frame_(tasm->has_frame()) {
76     tasm->set_has_frame(true);
77     if (type != StackFrame::MANUAL && type_ != StackFrame::NONE) {
78       tasm->EnterFrame(type);
79     }
80   }
81 
~FrameScope()82   ~FrameScope() {
83     if (type_ != StackFrame::MANUAL && type_ != StackFrame::NONE) {
84       tasm_->LeaveFrame(type_);
85     }
86     tasm_->set_has_frame(old_has_frame_);
87   }
88 
89  private:
90   TurboAssembler* tasm_;
91   StackFrame::Type type_;
92   bool old_has_frame_;
93 };
94 
95 class FrameAndConstantPoolScope {
96  public:
FrameAndConstantPoolScope(MacroAssembler * masm,StackFrame::Type type)97   FrameAndConstantPoolScope(MacroAssembler* masm, StackFrame::Type type)
98       : masm_(masm),
99         type_(type),
100         old_has_frame_(masm->has_frame()),
101         old_constant_pool_available_(FLAG_enable_embedded_constant_pool &&
102                                      masm->is_constant_pool_available()) {
103     masm->set_has_frame(true);
104     if (FLAG_enable_embedded_constant_pool) {
105       masm->set_constant_pool_available(true);
106     }
107     if (type_ != StackFrame::MANUAL && type_ != StackFrame::NONE) {
108       masm->EnterFrame(type, !old_constant_pool_available_);
109     }
110   }
111 
~FrameAndConstantPoolScope()112   ~FrameAndConstantPoolScope() {
113     masm_->LeaveFrame(type_);
114     masm_->set_has_frame(old_has_frame_);
115     if (FLAG_enable_embedded_constant_pool) {
116       masm_->set_constant_pool_available(old_constant_pool_available_);
117     }
118   }
119 
120  private:
121   MacroAssembler* masm_;
122   StackFrame::Type type_;
123   bool old_has_frame_;
124   bool old_constant_pool_available_;
125 
126   DISALLOW_IMPLICIT_CONSTRUCTORS(FrameAndConstantPoolScope);
127 };
128 
129 // Class for scoping the the unavailability of constant pool access.
130 class ConstantPoolUnavailableScope {
131  public:
ConstantPoolUnavailableScope(Assembler * assembler)132   explicit ConstantPoolUnavailableScope(Assembler* assembler)
133       : assembler_(assembler),
134         old_constant_pool_available_(FLAG_enable_embedded_constant_pool &&
135                                      assembler->is_constant_pool_available()) {
136     if (FLAG_enable_embedded_constant_pool) {
137       assembler->set_constant_pool_available(false);
138     }
139   }
~ConstantPoolUnavailableScope()140   ~ConstantPoolUnavailableScope() {
141     if (FLAG_enable_embedded_constant_pool) {
142       assembler_->set_constant_pool_available(old_constant_pool_available_);
143     }
144   }
145 
146  private:
147   Assembler* assembler_;
148   int old_constant_pool_available_;
149 
150   DISALLOW_IMPLICIT_CONSTRUCTORS(ConstantPoolUnavailableScope);
151 };
152 
153 class AllowExternalCallThatCantCauseGC : public FrameScope {
154  public:
AllowExternalCallThatCantCauseGC(MacroAssembler * masm)155   explicit AllowExternalCallThatCantCauseGC(MacroAssembler* masm)
156       : FrameScope(masm, StackFrame::NONE) {}
157 };
158 
159 // Prevent the use of the RootArray during the lifetime of this
160 // scope object.
161 class NoRootArrayScope {
162  public:
NoRootArrayScope(TurboAssembler * masm)163   explicit NoRootArrayScope(TurboAssembler* masm)
164       : masm_(masm), old_value_(masm->root_array_available()) {
165     masm->set_root_array_available(false);
166   }
167 
~NoRootArrayScope()168   ~NoRootArrayScope() { masm_->set_root_array_available(old_value_); }
169 
170  private:
171   TurboAssembler* masm_;
172   bool old_value_;
173 };
174 
175 }  // namespace internal
176 }  // namespace v8
177 
178 #endif  // V8_CODEGEN_MACRO_ASSEMBLER_H_
179