[vm, ffi] Extend stack slots to word size for RISC-V.

Clang relies on this, gcc does not.

TEST=ci
Change-Id: Iee14790367f6807abd222f69990640d44e6f1f77
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339081
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Ryan Macnak 2023-11-30 16:42:28 +00:00 committed by Commit Queue
parent ad625dfb5d
commit d229aa0edd
18 changed files with 82 additions and 47 deletions

View file

@ -260,10 +260,8 @@ class ArgumentAllocator : public ValueObject {
// Some calling conventions require the callee to make the lowest 32 bits
// in registers non-garbage.
const auto& container_type =
CallingConventions::kArgumentRegisterExtension == kExtendedTo4
? payload_type_converted.WidenTo4Bytes(zone_)
: payload_type_converted;
const auto& container_type = payload_type_converted.Extend(
zone_, CallingConventions::kArgumentRegisterExtension);
return AllocateInt(payload_type, container_type, is_vararg);
}
@ -619,9 +617,7 @@ class ArgumentAllocator : public ValueObject {
// If the stack arguments are not packed, the 32 lowest bits should not
// contain garbage.
const auto& container_type =
CallingConventions::kArgumentStackExtension == kExtendedTo4
? payload_type.WidenTo4Bytes(zone_)
: payload_type;
payload_type.Extend(zone_, CallingConventions::kArgumentStackExtension);
const auto& result = *new (zone_) NativeStackLocation(
payload_type, container_type, CallingConventions::kStackPointerRegister,
stack_height_in_bytes);
@ -962,10 +958,8 @@ static const NativeLocation& ResultLocation(Zone* zone,
bool has_varargs) {
const auto& payload_type_converted =
ConvertIfSoftFp(zone, payload_type, has_varargs, /*is_result*/ true);
const auto& container_type =
CallingConventions::kReturnRegisterExtension == kExtendedTo4
? payload_type_converted.WidenTo4Bytes(zone)
: payload_type_converted;
const auto& container_type = payload_type_converted.Extend(
zone, CallingConventions::kReturnRegisterExtension);
if (container_type.IsFloat()) {
return *new (zone) NativeFpuRegistersLocation(

View file

@ -191,6 +191,11 @@ NativeLocation& NativeLocation::WidenTo4Bytes(Zone* zone) const {
container_type().WidenTo4Bytes(zone));
}
NativeLocation& NativeLocation::WidenTo8Bytes(Zone* zone) const {
return WithOtherNativeType(zone, payload_type().WidenTo8Bytes(zone),
container_type().WidenTo8Bytes(zone));
}
#if defined(TARGET_ARCH_ARM)
const NativeLocation& NativeLocation::WidenToQFpuRegister(Zone* zone) const {
if (!IsFpuRegisters()) {

View file

@ -94,6 +94,7 @@ class NativeLocation : public ZoneAllocated {
#endif // defined(TARGET_ARCH_ARM)
NativeLocation& WidenTo4Bytes(Zone* zone) const;
NativeLocation& WidenTo8Bytes(Zone* zone) const;
virtual bool IsRegisters() const { return false; }
virtual bool IsFpuRegisters() const { return false; }

View file

@ -1098,6 +1098,17 @@ const NativeType& NativeType::WidenTo4Bytes(Zone* zone) const {
return *this;
}
const NativeType& NativeType::WidenTo8Bytes(Zone* zone) const {
if (IsInt() && SizeInBytes() <= 4) {
if (IsSigned()) {
return *new (zone) NativePrimitiveType(kInt64);
} else {
return *new (zone) NativePrimitiveType(kUint64);
}
}
return *this;
}
} // namespace ffi
} // namespace compiler

View file

@ -8,6 +8,7 @@
#include "platform/assert.h"
#include "platform/globals.h"
#include "vm/allocation.h"
#include "vm/constants_base.h"
#include "vm/growable_array.h"
#if !defined(DART_PRECOMPILED_RUNTIME)
@ -133,6 +134,21 @@ class NativeType : public ZoneAllocated {
// If this is a 8 or 16 bit int, returns a 32 bit container.
// Otherwise, return original representation.
const NativeType& WidenTo4Bytes(Zone* zone) const;
// If this is a 8, 16 or 32 bit int, returns a 64 bit container.
// Otherwise, return original representation.
const NativeType& WidenTo8Bytes(Zone* zone) const;
const NativeType& Extend(Zone* zone, ExtensionStrategy extension) const {
switch (extension) {
case kNotExtended:
return *this;
case kExtendedTo4:
return WidenTo4Bytes(zone);
case kExtendedTo8:
return WidenTo8Bytes(zone);
default:
UNREACHABLE();
}
}
virtual void PrintTo(BaseTextBuffer* f,
bool multi_line = false,

View file

@ -6,7 +6,7 @@ t4 int32[int8]
t5 int32[int8]
a6 int32[int8]
a7 int32[int8]
S+0 int8
S+4 int8
S+0 int32[int8]
S+4 int32[int8]
=>
a0 int32[int8]

View file

@ -1,12 +1,12 @@
a0 int32[int8]
a1 int32[int8]
a2 int32[int8]
t3 int32[int8]
t4 int32[int8]
t5 int32[int8]
a6 int32[int8]
a7 int32[int8]
S+0 int8
S+8 int8
a0 int64[int8]
a1 int64[int8]
a2 int64[int8]
t3 int64[int8]
t4 int64[int8]
t5 int64[int8]
a6 int64[int8]
a7 int64[int8]
S+0 int64[int8]
S+8 int64[int8]
=>
a0 int32[int8]
a0 int64[int8]

View file

@ -1,5 +1,5 @@
a0 int32
a0 int64[int32]
a1 int64
a2 int64
=>
a0 int32
a0 int64[int32]

View file

@ -1,8 +1,8 @@
a0 int64
fa0 double
a1 int32
a1 int64[int32]
fa1 double
a2 int32
a2 int64[int32]
t3 int64
t4 int64
=>

View file

@ -1,4 +1,4 @@
P(a1 int64) Struct(size: 128)
a2 int32
a2 int64[int32]
=>
P(a0 int64) Struct(size: 128)

View file

@ -9,7 +9,7 @@ P(a7 uint32) Struct(size: 16)
P(S+0 uint32) Struct(size: 16)
P(S+4 uint32) Struct(size: 16)
fa1 float
S+8 int8
S+8 int32[int8]
P(S+12 uint32) Struct(size: 16)
=>
P(a0 uint32) Struct(size: 16)

View file

@ -9,7 +9,7 @@ M(S+32 uint64, S+40 uint64) Struct(size: 16)
M(S+48 uint64, S+56 uint64) Struct(size: 16)
M(S+64 uint64, S+72 uint64) Struct(size: 16)
fa1 float
S+80 int8
S+80 int64[int8]
M(S+88 uint64, S+96 uint64) Struct(size: 16)
=>
M(a0 uint64, a1 uint64) Struct(size: 16)

View file

@ -1,15 +1,15 @@
M(a0 int32[int8], fa0 double) Struct(size: 9)
M(a1 int32[int8], fa1 double) Struct(size: 9)
M(a2 int32[int8], fa2 double) Struct(size: 9)
M(t3 int32[int8], fa3 double) Struct(size: 9)
M(t4 int32[int8], fa4 double) Struct(size: 9)
M(t5 int32[int8], fa5 double) Struct(size: 9)
M(a6 int32[int8], fa6 double) Struct(size: 9)
M(a7 int32[int8], fa7 double) Struct(size: 9)
M(a0 int64[int8], fa0 double) Struct(size: 9)
M(a1 int64[int8], fa1 double) Struct(size: 9)
M(a2 int64[int8], fa2 double) Struct(size: 9)
M(t3 int64[int8], fa3 double) Struct(size: 9)
M(t4 int64[int8], fa4 double) Struct(size: 9)
M(t5 int64[int8], fa5 double) Struct(size: 9)
M(a6 int64[int8], fa6 double) Struct(size: 9)
M(a7 int64[int8], fa7 double) Struct(size: 9)
M(S+0 uint64, S+8 uint64[uint8]) Struct(size: 9)
M(S+16 uint64, S+24 uint64[uint8]) Struct(size: 9)
S+32 double
S+40 int32
S+48 int32
S+40 int64[int32]
S+48 int64[int32]
=>
fa0 double

View file

@ -7,7 +7,7 @@ P(a6 uint32) Union(size: 16)
P(a7 uint32) Union(size: 16)
P(S+0 uint32) Union(size: 16)
P(S+4 uint32) Union(size: 16)
S+8 int8
S+8 int32[int8]
P(S+12 uint32) Union(size: 16)
=>
P(a0 uint32) Union(size: 16)

View file

@ -7,7 +7,7 @@ M(S+16 uint64, S+24 uint64) Union(size: 16)
M(S+32 uint64, S+40 uint64) Union(size: 16)
M(S+48 uint64, S+56 uint64) Union(size: 16)
M(S+64 uint64, S+72 uint64) Union(size: 16)
S+80 int8
S+80 int64[int8]
M(S+88 uint64, S+96 uint64) Union(size: 16)
=>
M(a0 uint64, a1 uint64) Union(size: 16)

View file

@ -9,7 +9,7 @@ fa7 double
a0 int32[float]
M(a1 uint64, a2 uint64[uint32]) Struct(size: 12)
t3 int64
t4 int32
t4 int64[int32]
M(t5 uint64, a6 uint64[uint32]) Struct(size: 12)
=>
fa0 double

View file

@ -24,9 +24,12 @@ enum AlignmentStrategy {
enum ExtensionStrategy {
// Values can have arbitrary small size with the upper bits undefined.
kNotExtended,
// Values smaller than 4 bytes are passed around zero- or signextended to
// Values smaller than 4 bytes are passed around zero- or sign-extended to
// 4 bytes.
kExtendedTo4,
// Values smaller than 8 bytes are passed around zero- or sign-extended to
// 8 bytes.
kExtendedTo8,
};
} // namespace dart

View file

@ -562,10 +562,15 @@ class CallingConventions {
// Whether 1 or 2 byte-sized arguments or return values are passed extended
// to 4 bytes.
// TODO(ffi): Need to add kExtendedToWord.
#if XLEN == 32
static constexpr ExtensionStrategy kReturnRegisterExtension = kExtendedTo4;
static constexpr ExtensionStrategy kArgumentRegisterExtension = kExtendedTo4;
static constexpr ExtensionStrategy kArgumentStackExtension = kNotExtended;
static constexpr ExtensionStrategy kArgumentStackExtension = kExtendedTo4;
#else
static constexpr ExtensionStrategy kReturnRegisterExtension = kExtendedTo8;
static constexpr ExtensionStrategy kArgumentRegisterExtension = kExtendedTo8;
static constexpr ExtensionStrategy kArgumentStackExtension = kExtendedTo8;
#endif
static constexpr Register kReturnReg = A0;
static constexpr Register kSecondReturnReg = A1;