v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
linkage-location.h
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
5#ifndef V8_CODEGEN_LINKAGE_LOCATION_H_
6#define V8_CODEGEN_LINKAGE_LOCATION_H_
7
11
12#if !defined(__clang__) && defined(_M_ARM64)
13// _M_ARM64 is an MSVC-specific macro that clang-cl emulates.
14#define NO_INLINE_FOR_ARM64_MSVC __declspec(noinline)
15#else
16#define NO_INLINE_FOR_ARM64_MSVC
17#endif
18
19namespace v8 {
20namespace internal {
21template <typename T>
22class Signature;
23
24// Describes the location for a parameter or a return value to a call.
26 public:
27 bool operator==(const LinkageLocation& other) const {
28 return bit_field_ == other.bit_field_ &&
29 machine_type_ == other.machine_type_;
30 }
31
32 bool operator!=(const LinkageLocation& other) const {
33 return !(*this == other);
34 }
35
36 static bool IsSameLocation(const LinkageLocation& a,
37 const LinkageLocation& b) {
38 // Different MachineTypes may end up at the same physical location. With the
39 // sub-type check we make sure that types like {AnyTagged} and
40 // {TaggedPointer} which would end up with the same physical location are
41 // considered equal here.
42 return (a.bit_field_ == b.bit_field_) &&
43 (IsSubtype(a.machine_type_.representation(),
46 a.machine_type_.representation()));
47 }
48
50 int32_t reg, MachineType type = MachineType::None()) {
51 return LinkageLocation(REGISTER, reg, type);
52 }
53
58
61 DCHECK_LE(0, reg);
62 return LinkageLocation(REGISTER, reg, type);
63 }
64
65 static LinkageLocation ForCallerFrameSlot(int32_t slot, MachineType type) {
66 DCHECK_GT(0, slot);
67 return LinkageLocation(STACK_SLOT, slot, type);
68 }
69
70 static LinkageLocation ForCalleeFrameSlot(int32_t slot, MachineType type) {
71 // TODO(titzer): bailout instead of crashing here.
72 DCHECK(slot >= 0 && slot < LinkageLocation::MAX_STACK_SLOT);
73 return LinkageLocation(STACK_SLOT, slot, type);
74 }
75
76 // TODO(ahaas): Extract these TurboFan-specific functions from the
77 // LinkageLocation.
84
91
99
106
108 LinkageLocation caller_location, int stack_param_delta) {
109 if (!caller_location.IsRegister()) {
111 caller_location.GetLocation() + stack_param_delta,
112 caller_location.GetType());
113 }
114 return caller_location;
115 }
116
118
119 int GetSizeInPointers() const {
120 return ElementSizeInPointers(GetType().representation());
121 }
122
123 int32_t GetLocation() const {
124 // We can't use LocationField::decode here because it doesn't work for
125 // negative values!
126 return static_cast<int32_t>(bit_field_ & LocationField::kMask) >>
128 }
129
130 bool IsNullRegister() const {
131 return IsRegister() && GetLocation() < ANY_REGISTER;
132 }
136 bool IsAnyRegister() const {
137 return IsRegister() && GetLocation() == ANY_REGISTER;
138 }
139 bool IsCallerFrameSlot() const { return !IsRegister() && GetLocation() < 0; }
140 bool IsCalleeFrameSlot() const { return !IsRegister() && GetLocation() >= 0; }
141
142 int32_t AsRegister() const {
144 return GetLocation();
145 }
146 int32_t AsCallerFrameSlot() const {
148 return GetLocation();
149 }
150 int32_t AsCalleeFrameSlot() const {
152 return GetLocation();
153 }
154
155 private:
157
160
161 static constexpr int32_t ANY_REGISTER = -1;
162 static constexpr int32_t MAX_STACK_SLOT = 32767;
163
164 LinkageLocation(LocationType type, int32_t location,
165 MachineType machine_type) {
167 // {location} can be -1 (ANY_REGISTER).
168 ((static_cast<uint32_t>(location) << LocationField::kShift) &
170 machine_type_ = machine_type;
171 }
172
173 int32_t bit_field_;
175};
176
178
179} // namespace internal
180} // namespace v8
181#undef NO_INLINE_FOR_ARM64_MSVC
182
183#endif // V8_CODEGEN_LINKAGE_LOCATION_H_
static constexpr T decode(U value)
Definition bit-field.h:66
static constexpr U encode(T value)
Definition bit-field.h:55
static constexpr U kMask
Definition bit-field.h:41
static constexpr int kShift
Definition bit-field.h:39
static constexpr int kConstantPoolOffset
static LinkageLocation ForRegister(int32_t reg, MachineType type=MachineType::None())
static LinkageLocation ForCallerFrameSlot(int32_t slot, MachineType type)
static LinkageLocation ForAnyRegister(MachineType type=MachineType::None())
static LinkageLocation ForNullRegister(int32_t reg, MachineType type=MachineType::None())
static constexpr int32_t MAX_STACK_SLOT
static LinkageLocation ForCalleeFrameSlot(int32_t slot, MachineType type)
static LinkageLocation ForSavedCallerFramePtr()
static constexpr int32_t ANY_REGISTER
bool operator!=(const LinkageLocation &other) const
static LinkageLocation ForSavedCallerConstantPool()
static bool IsSameLocation(const LinkageLocation &a, const LinkageLocation &b)
static LinkageLocation ForSavedCallerFunction()
static LinkageLocation ForSavedCallerReturnAddress()
NO_INLINE_FOR_ARM64_MSVC bool IsRegister() const
bool operator==(const LinkageLocation &other) const
LinkageLocation(LocationType type, int32_t location, MachineType machine_type)
static LinkageLocation ConvertToTailCallerLocation(LinkageLocation caller_location, int stack_param_delta)
static constexpr MachineType Pointer()
constexpr MachineRepresentation representation() const
static constexpr MachineType AnyTagged()
static constexpr MachineType None()
#define V8_EMBEDDED_CONSTANT_POOL_BOOL
Definition globals.h:81
LiftoffRegister reg
#define NO_INLINE_FOR_ARM64_MSVC
V8_EXPORT_PRIVATE constexpr int ElementSizeInPointers(MachineRepresentation rep)
constexpr int kSystemPointerSize
Definition globals.h:410
bool IsSubtype(MachineRepresentation rep1, MachineRepresentation rep2)
#define DCHECK_LE(v1, v2)
Definition logging.h:490
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_GT(v1, v2)
Definition logging.h:487