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_CODE_FACTORY_H_
6#define V8_CODEGEN_CODE_FACTORY_H_
7
8#include "src/codegen/callable.h"
9#include "src/codegen/interface-descriptors.h"
10#include "src/common/globals.h"
11#include "src/objects/type-hints.h"
12#include "src/utils/allocation.h"
13
14namespace v8 {
15namespace internal {
16
17// For ArrayNoArgumentConstructor and ArraySingleArgumentConstructor.
18enum AllocationSiteOverrideMode {
19  DONT_OVERRIDE,
20  DISABLE_ALLOCATION_SITES,
21};
22
23class V8_EXPORT_PRIVATE CodeFactory final {
24 public:
25  // CEntry has var-args semantics (all the arguments are passed on the
26  // stack and the arguments count is passed via register) which currently
27  // can't be expressed in CallInterfaceDescriptor. Therefore only the code
28  // is exported here.
29  static Handle<CodeT> RuntimeCEntry(Isolate* isolate, int result_size = 1);
30
31  static Handle<CodeT> CEntry(
32      Isolate* isolate, int result_size = 1,
33      SaveFPRegsMode save_doubles = SaveFPRegsMode::kIgnore,
34      ArgvMode argv_mode = ArgvMode::kStack, bool builtin_exit_frame = false);
35
36  // Initial states for ICs.
37  static Callable LoadGlobalIC(Isolate* isolate, TypeofMode typeof_mode);
38  static Callable LoadGlobalICInOptimizedCode(Isolate* isolate,
39                                              TypeofMode typeof_mode);
40  static Callable DefineNamedOwnIC(Isolate* isolate);
41  static Callable DefineNamedOwnICInOptimizedCode(Isolate* isolate);
42
43  static Callable ResumeGenerator(Isolate* isolate);
44
45  static Callable ApiGetter(Isolate* isolate);
46  static Callable CallApiCallback(Isolate* isolate);
47
48  static Callable NonPrimitiveToPrimitive(
49      Isolate* isolate, ToPrimitiveHint hint = ToPrimitiveHint::kDefault);
50  static Callable OrdinaryToPrimitive(Isolate* isolate,
51                                      OrdinaryToPrimitiveHint hint);
52
53  static Callable StringAdd(Isolate* isolate,
54                            StringAddFlags flags = STRING_ADD_CHECK_NONE);
55
56  static Callable FastNewFunctionContext(Isolate* isolate,
57                                         ScopeType scope_type);
58
59  static Callable Call(Isolate* isolate,
60                       ConvertReceiverMode mode = ConvertReceiverMode::kAny);
61  static Callable Call_WithFeedback(Isolate* isolate, ConvertReceiverMode mode);
62  static Callable CallWithArrayLike(Isolate* isolate);
63  static Callable CallWithSpread(Isolate* isolate);
64  static Callable CallFunction(
65      Isolate* isolate, ConvertReceiverMode mode = ConvertReceiverMode::kAny);
66  static Callable CallVarargs(Isolate* isolate);
67  static Callable CallForwardVarargs(Isolate* isolate);
68  static Callable CallFunctionForwardVarargs(Isolate* isolate);
69  static Callable Construct(Isolate* isolate);
70  static Callable ConstructWithSpread(Isolate* isolate);
71  static Callable ConstructFunction(Isolate* isolate);
72  static Callable ConstructVarargs(Isolate* isolate);
73  static Callable ConstructForwardVarargs(Isolate* isolate);
74  static Callable ConstructFunctionForwardVarargs(Isolate* isolate);
75
76  static Callable InterpreterPushArgsThenCall(Isolate* isolate,
77                                              ConvertReceiverMode receiver_mode,
78                                              InterpreterPushArgsMode mode);
79  static Callable InterpreterPushArgsThenConstruct(
80      Isolate* isolate, InterpreterPushArgsMode mode);
81  static Callable InterpreterCEntry(Isolate* isolate, int result_size = 1);
82  static Callable InterpreterOnStackReplacement(Isolate* isolate);
83  static Callable InterpreterOnStackReplacement_ToBaseline(Isolate* isolate);
84
85  static Callable ArrayNoArgumentConstructor(
86      Isolate* isolate, ElementsKind kind,
87      AllocationSiteOverrideMode override_mode);
88  static Callable ArraySingleArgumentConstructor(
89      Isolate* isolate, ElementsKind kind,
90      AllocationSiteOverrideMode override_mode);
91
92#ifdef V8_IS_TSAN
93  static Builtin GetTSANStoreStub(SaveFPRegsMode fp_mode, int size,
94                                  std::memory_order order);
95  static Builtin GetTSANRelaxedLoadStub(SaveFPRegsMode fp_mode, int size);
96#endif  // V8_IS_TSAN
97};
98
99}  // namespace internal
100}  // namespace v8
101
102#endif  // V8_CODEGEN_CODE_FACTORY_H_
103