v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
builtins-utils-gen.h
Go to the documentation of this file.
1// Copyright 2017 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_BUILTINS_BUILTINS_UTILS_GEN_H_
6#define V8_BUILTINS_BUILTINS_UTILS_GEN_H_
7
10
11namespace v8 {
12namespace internal {
13
14namespace compiler {
16} // namespace compiler
17
18// ----------------------------------------------------------------------------
19// Support macro for defining builtins with Turbofan.
20// ----------------------------------------------------------------------------
21//
22// A builtin function is defined by writing:
23//
24// TF_BUILTIN(name, code_assember_base_class) {
25// ...
26// }
27//
28// In the body of the builtin function the arguments can be accessed
29// as "Parameter(n)".
30#define TF_BUILTIN(Name, AssemblerBase) \
31 class Name##Assembler : public AssemblerBase { \
32 public: \
33 using Descriptor = Builtin_##Name##_InterfaceDescriptor; \
34 \
35 explicit Name##Assembler(compiler::CodeAssemblerState* state) \
36 : AssemblerBase(state) {} \
37 void Generate##Name##Impl(); \
38 \
39 template <class T> \
40 TNode<T> Parameter( \
41 Descriptor::ParameterIndices index, \
42 cppgc::SourceLocation loc = cppgc::SourceLocation::Current()) { \
43 return CodeAssembler::Parameter<T>(static_cast<int>(index), loc); \
44 } \
45 \
46 template <class T> \
47 TNode<T> UncheckedParameter(Descriptor::ParameterIndices index) { \
48 return CodeAssembler::UncheckedParameter<T>(static_cast<int>(index)); \
49 } \
50 }; \
51 void Builtins::Generate_##Name(compiler::CodeAssemblerState* state) { \
52 Name##Assembler assembler(state); \
53 state->SetInitialDebugInformation(#Name, __FILE__, __LINE__); \
54 if (Builtins::KindOf(Builtin::k##Name) == Builtins::TFJ) { \
55 assembler.PerformStackCheck(assembler.GetJSContextParameter()); \
56 } \
57 assembler.Generate##Name##Impl(); \
58 } \
59 void Name##Assembler::Generate##Name##Impl()
60
61#define TS_BUILTIN(Name, BaseAssembler) \
62 class Name##Assembler : public BaseAssembler { \
63 public: \
64 using Descriptor = Builtin_##Name##_InterfaceDescriptor; \
65 Name##Assembler(compiler::turboshaft::PipelineData* data, \
66 Isolate* isolate, compiler::turboshaft::Graph& graph, \
67 Zone* phase_zone) \
68 : BaseAssembler(data, graph, phase_zone) {} \
69 void Generate##Name##Impl(); \
70 }; \
71 void Builtins::Generate_##Name( \
72 compiler::turboshaft::PipelineData* data, Isolate* isolate, \
73 compiler::turboshaft::Graph& graph, Zone* phase_zone) { \
74 Name##Assembler assembler(data, isolate, graph, phase_zone); \
75 assembler.EmitBuiltinProlog(Builtin::k##Name); \
76 Block* catch_block = nullptr; \
77 std::optional<Name##Assembler::CatchScope> catch_scope; \
78 /* If this builtin collects feedback, we need to setup a catch block */ \
79 if (assembler.HasFeedbackCollector()) { \
80 catch_block = assembler.NewBlock(); \
81 catch_scope.emplace(assembler, catch_block); \
82 } \
83 assembler.Generate##Name##Impl(); \
84 /* Builtin definition must generate something! */ \
85 DCHECK_GT(graph.op_id_count(), 0); \
86 assembler.EmitEpilog(catch_block); \
87 } \
88 void Name##Assembler::Generate##Name##Impl()
89
90} // namespace internal
91} // namespace v8
92
93#endif // V8_BUILTINS_BUILTINS_UTILS_GEN_H_