Files
sdk/runtime/vm/constants.h
T
Vyacheslav Egorov dcac60b672 [vm/aot] Fix BoxInt64 in deferred units
When generating code for deferred units compiler
can't emit PC relative call to the shared Mint allocation
stub. This causes compiler to emit an indirect call
through a Code object. Such calls clobber CODE_REG
which is actually an allocatable register.

Fix this by using non-allocatable register instead of
CODE_REG when generating indirect calls through
Code object in AOT mode. Callees don't expect
anything useful in CODE_REG anyway because AOT
calling convetion does not use it.

TEST=vm/cc/{BranchLinkPreservesRegisters,JumpAndLinkPreservesRegisters,CallCodePreservesRegisters}

Bug: b/242559057
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-release-arm64-try,vm-aot-linux-release-simarm_x64-try,vm-aot-linux-release-x64-try,vm-aot-linux-product-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-linux-debug-simriscv64-try,vm-ffi-qemu-linux-release-riscv64-try
Change-Id: Ib1fdc1c104d0269d41bb1ab9cbe292ad28c7cd49
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338127
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2023-11-28 13:15:56 +00:00

117 lines
3.8 KiB
C++

// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#ifndef RUNTIME_VM_CONSTANTS_H_
#define RUNTIME_VM_CONSTANTS_H_
#if defined(TARGET_ARCH_IA32)
#include "vm/constants_ia32.h"
#elif defined(TARGET_ARCH_X64)
#include "vm/constants_x64.h"
#elif defined(TARGET_ARCH_ARM)
#include "vm/constants_arm.h"
#elif defined(TARGET_ARCH_ARM64)
#include "vm/constants_arm64.h"
#elif defined(TARGET_ARCH_RISCV32) || defined(TARGET_ARCH_RISCV64)
#include "vm/constants_riscv.h"
#else
#error Unknown architecture.
#endif
#include "platform/assert.h"
#include "platform/utils.h"
#include "vm/pointer_tagging.h"
namespace dart {
// An architecture independent ABI for the InstantiateType stub.
//
// We re-use registers from another ABI to avoid duplicating this ABI across 4
// architectures.
struct InstantiateTypeABI {
static constexpr Register kTypeReg =
InstantiationABI::kUninstantiatedTypeArgumentsReg;
static constexpr Register kInstantiatorTypeArgumentsReg =
InstantiationABI::kInstantiatorTypeArgumentsReg;
static constexpr Register kFunctionTypeArgumentsReg =
InstantiationABI::kFunctionTypeArgumentsReg;
static constexpr Register kResultTypeReg = InstantiationABI::kResultTypeReg;
static constexpr Register kScratchReg = InstantiationABI::kScratchReg;
};
class RegisterNames {
public:
static const char* RegisterName(Register reg) {
ASSERT((0 <= reg) && (reg < kNumberOfCpuRegisters));
return cpu_reg_names[reg];
}
static const char* RegisterAbiName(Register reg) {
ASSERT((0 <= reg) && (reg < kNumberOfCpuRegisters));
return cpu_reg_abi_names[reg];
}
static const char* FpuRegisterName(FpuRegister reg) {
ASSERT((0 <= reg) && (reg < kNumberOfFpuRegisters));
return fpu_reg_names[reg];
}
#if defined(TARGET_ARCH_ARM)
static const char* FpuSRegisterName(SRegister reg) {
ASSERT((0 <= reg) && (reg < kNumberOfSRegisters));
return fpu_s_reg_names[reg];
}
static const char* FpuDRegisterName(DRegister reg) {
ASSERT((0 <= reg) && (reg < kNumberOfDRegisters));
return fpu_d_reg_names[reg];
}
#endif // defined(TARGET_ARCH_ARM)
#if defined(TARGET_ARCH_X64) || defined(TARGET_ARCH_IA32)
static const char* RegisterByteName(ByteRegister reg) {
ASSERT((0 <= reg) && (reg < kNumberOfByteRegisters));
return cpu_reg_byte_names[reg];
}
#endif // defined(TARGET_ARCH_X64) || defined(TARGET_ARCH_IA32)
};
static constexpr bool IsArgumentRegister(Register reg) {
return ((1 << reg) & CallingConventions::kArgumentRegisters) != 0;
}
static constexpr bool IsFpuArgumentRegister(FpuRegister reg) {
return ((1 << reg) & CallingConventions::kFpuArgumentRegisters) != 0;
}
static constexpr bool IsCalleeSavedRegister(Register reg) {
return ((1 << reg) & CallingConventions::kCalleeSaveCpuRegisters) != 0;
}
#if !defined(TARGET_ARCH_IA32)
constexpr bool IsAbiPreservedRegister(Register reg) {
return (kAbiPreservedCpuRegs & (1 << reg)) != 0;
}
#endif
static inline ScaleFactor ToScaleFactor(intptr_t index_scale,
bool index_unboxed) {
RELEASE_ASSERT(index_scale >= 0);
const intptr_t shift = Utils::ShiftForPowerOfTwo(index_scale) -
(index_unboxed ? 0 : kSmiTagShift);
// index_scale < kSmiTagShift for boxed indexes must be handled by the caller,
// and ScaleFactor is currently only defined up to TIMES_16 == 4.
RELEASE_ASSERT(shift >= 0 && shift <= 4);
return static_cast<ScaleFactor>(shift);
}
// Helper for using register sets with range loops:
//
// for (auto reg : RegisterRange(kDartAvailableCpuRegs)) { ... }
//
static inline Utils::BitsRange<Register> RegisterRange(uint32_t regs) {
return Utils::BitsRange<Register>(regs);
}
} // namespace dart
#endif // RUNTIME_VM_CONSTANTS_H_