v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
wasm-compiler-definitions.cc
Go to the documentation of this file.
1// Copyright 2023 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
6
7#include <optional>
8
9#include "src/base/strings.h"
14
15namespace v8::internal::compiler {
16
18 const wasm::WasmModule* module,
19 const wasm::WireBytesStorage* wire_bytes,
20 int index) {
21 std::optional<wasm::ModuleWireBytes> module_bytes =
22 wire_bytes->GetModuleBytes();
23 if (module_bytes.has_value() &&
24 (v8_flags.trace_turbo || v8_flags.trace_turbo_scheduled ||
25 v8_flags.trace_turbo_graph || v8_flags.print_wasm_code
26#ifdef V8_ENABLE_WASM_SIMD256_REVEC
27 || v8_flags.trace_wasm_revectorize
28#endif // V8_ENABLE_WASM_SIMD256_REVEC
29 )) {
30 wasm::WireBytesRef name = module->lazily_generated_names.LookupFunctionName(
31 module_bytes.value(), index);
32 if (!name.is_empty()) {
33 int name_len = name.length();
34 char* index_name = zone->AllocateArray<char>(name_len);
35 memcpy(index_name, module_bytes->start() + name.offset(), name_len);
36 return base::Vector<const char>(index_name, name_len);
37 }
38 }
39
40 constexpr int kBufferLength = 24;
41
43 int name_len = SNPrintF(name_vector, "wasm-function#%d", index);
44 DCHECK(name_len > 0 && name_len < name_vector.length());
45
46 char* index_name = zone->AllocateArray<char>(name_len);
47 memcpy(index_name, name_vector.begin(), name_len);
48 return base::Vector<const char>(index_name, name_len);
49}
50
51// General code uses the above configuration data.
52template <typename T>
54 WasmCallKind call_kind,
55 bool need_frame_state) {
56 // The extra here is to accommodate the instance object as first parameter
57 // and, when specified, the additional callable.
58 bool extra_callable_param =
59 call_kind == kWasmImportWrapper || call_kind == kWasmCapiFunction;
60
61 int parameter_slots;
62 int return_slots;
63 LocationSignature* location_sig = BuildLocations(
64 zone, fsig, extra_callable_param, &parameter_slots, &return_slots);
65
66 const RegList kCalleeSaveRegisters;
67 const DoubleRegList kCalleeSaveFPRegisters;
68
69 // The target for wasm calls is always a code object.
70 MachineType target_type = MachineType::Pointer();
71 LinkageLocation target_loc = LinkageLocation::ForAnyRegister(target_type);
72
73 CallDescriptor::Kind descriptor_kind;
74 uint64_t signature_hash = kInvalidWasmSignatureHash;
75
76 switch (call_kind) {
77 case kWasmFunction:
78 descriptor_kind = CallDescriptor::kCallWasmFunction;
79 break;
81 descriptor_kind = CallDescriptor::kCallWasmFunctionIndirect;
82 signature_hash = wasm::SignatureHasher::Hash(fsig);
83 break;
85 descriptor_kind = CallDescriptor::kCallWasmImportWrapper;
86 break;
88 descriptor_kind = CallDescriptor::kCallWasmCapiFunction;
89 break;
90 }
91
92 CallDescriptor::Flags flags = need_frame_state
95 return zone->New<CallDescriptor>( // --
96 descriptor_kind, // kind
97 kWasmEntrypointTag, // tag
98 target_type, // target MachineType
99 target_loc, // target location
100 location_sig, // location_sig
101 parameter_slots, // parameter slot count
103 kCalleeSaveRegisters, // callee-saved registers
104 kCalleeSaveFPRegisters, // callee-saved fp regs
105 flags, // flags
106 "wasm-call", // debug name
107 StackArgumentOrder::kDefault, // order of the arguments in the stack
108 RegList{}, // allocatable registers
109 return_slots, // return slot count
110 signature_hash);
111}
112
119
120std::ostream& operator<<(std::ostream& os, CheckForNull null_check) {
121 return os << (null_check == kWithoutNullCheck ? "no null check"
122 : "null check");
123}
124
125} // namespace v8::internal::compiler
int length() const
Definition vector.h:64
constexpr T * begin() const
Definition vector.h:96
static LinkageLocation ForAnyRegister(MachineType type=MachineType::None())
static constexpr MachineType Pointer()
T * AllocateArray(size_t length)
Definition zone.h:127
T * New(Args &&... args)
Definition zone.h:114
static uint64_t Hash(const SigType *sig)
virtual std::optional< ModuleWireBytes > GetModuleBytes() const =0
#define EXPORT_TEMPLATE_DEFINE(export)
base::Vector< const char > GetDebugName(Zone *zone, const wasm::WasmModule *module, const wasm::WireBytesStorage *wire_bytes, int index)
LocationSignature * BuildLocations(Zone *zone, const Signature< T > *sig, bool extra_callable_param, int *parameter_slots, int *return_slots)
CallDescriptor * GetWasmCallDescriptor(Zone *zone, const Signature< T > *fsig, WasmCallKind call_kind, bool need_frame_state)
std::ostream & operator<<(std::ostream &os, AccessMode access_mode)
Flag flags[]
Definition flags.cc:3797
V8_EXPORT_PRIVATE FlagValues v8_flags
constexpr uint64_t kInvalidWasmSignatureHash
Definition globals.h:2896
#define DCHECK(condition)
Definition logging.h:482
#define V8_EXPORT_PRIVATE
Definition macros.h:460