[vm] Refactor constants to be available in namespaces dart and dart::host

Refactoring motivation: go/dart-simulated-ffi

Change-Id: I219aba2793cfb7d7ea5ecc0a2ab93276c6cbf1e0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97325
Reviewed-by: Samir Jindel <sjindel@google.com>
This commit is contained in:
Daco Harkes 2019-04-08 09:45:27 +00:00 committed by commit-bot@chromium.org
parent 7f5ed18ffc
commit 544371c7f2
28 changed files with 111 additions and 61 deletions

View file

@ -15,7 +15,7 @@
#include "platform/utils.h"
#include "vm/code_entry_kind.h"
#include "vm/compiler/runtime_api.h"
#include "vm/constants_arm.h"
#include "vm/constants.h"
#include "vm/cpu.h"
#include "vm/hash_map.h"
#include "vm/simulator.h"

View file

@ -14,7 +14,7 @@
#include "platform/assert.h"
#include "platform/utils.h"
#include "vm/class_id.h"
#include "vm/constants_arm64.h"
#include "vm/constants.h"
#include "vm/hash_map.h"
#include "vm/simulator.h"

View file

@ -11,7 +11,7 @@
#include "platform/assert.h"
#include "platform/utils.h"
#include "vm/constants_ia32.h"
#include "vm/constants.h"
#include "vm/constants_x86.h"
#include "vm/pointer_tagging.h"
@ -466,7 +466,7 @@ class Assembler : public AssemblerBase {
F(sub, 0x2b, 0x29, 5) \
F(sbb, 0x1b, 0x19, 3) \
F(cmp, 0x3b, 0x39, 7)
// clang-format on
// clang-format on
#define DECLARE_ALU(op, opcode, opcode2, modrm_opcode) \
void op##l(Register dst, Register src) { Alu(4, opcode, dst, src); } \

View file

@ -13,7 +13,7 @@
#include "platform/assert.h"
#include "platform/utils.h"
#include "vm/constants_x64.h"
#include "vm/constants.h"
#include "vm/constants_x86.h"
#include "vm/hash_map.h"
#include "vm/pointer_tagging.h"

View file

@ -14,7 +14,7 @@
#include "vm/code_entry_kind.h"
#include "vm/compiler/assembler/assembler.h"
#include "vm/compiler/backend/locations.h"
#include "vm/constants_arm.h"
#include "vm/constants.h"
#include "vm/instructions.h"
#include "vm/static_type_exactness_state.h"
#include "vm/tags.h"

View file

@ -14,7 +14,7 @@
#include "vm/code_entry_kind.h"
#include "vm/compiler/assembler/assembler.h"
#include "vm/compiler/backend/locations.h"
#include "vm/constants_arm64.h"
#include "vm/constants.h"
#include "vm/instructions.h"
#include "vm/static_type_exactness_state.h"
#include "vm/tags.h"

View file

@ -14,7 +14,7 @@
#include "vm/code_entry_kind.h"
#include "vm/compiler/assembler/assembler.h"
#include "vm/compiler/backend/locations.h"
#include "vm/constants_ia32.h"
#include "vm/constants.h"
#include "vm/instructions.h"
#include "vm/static_type_exactness_state.h"
#include "vm/tags.h"

View file

@ -13,7 +13,7 @@
#include "vm/class_id.h"
#include "vm/code_entry_kind.h"
#include "vm/compiler/assembler/assembler.h"
#include "vm/constants_x64.h"
#include "vm/constants.h"
#include "vm/instructions.h"
#include "vm/static_type_exactness_state.h"
#include "vm/tags.h"

View file

@ -19,4 +19,50 @@
#error Unknown architecture.
#endif
#if defined(HOST_ARCH_IA32)
#include "vm/constants_ia32.h"
#elif defined(HOST_ARCH_X64)
#include "vm/constants_x64.h"
#elif defined(HOST_ARCH_ARM)
#include "vm/constants_arm.h"
#elif defined(HOST_ARCH_ARM64)
#include "vm/constants_arm64.h"
#else
#error Unknown host architecture.
#endif
namespace dart {
#if defined(TARGET_ARCH_IA32)
using namespace arch_ia32; // NOLINT
#elif defined(TARGET_ARCH_X64)
using namespace arch_x64; // NOLINT
#elif defined(TARGET_ARCH_ARM)
using namespace arch_arm; // NOLINT
#elif defined(TARGET_ARCH_ARM64)
using namespace arch_arm64; // NOLINT
#elif defined(TARGET_ARCH_DBC)
// DBC is defined in namespace dart already.
#else
#error Unknown architecture.
#endif
namespace host {
#if defined(HOST_ARCH_IA32)
using namespace arch_ia32; // NOLINT
#elif defined(HOST_ARCH_X64)
using namespace arch_x64; // NOLINT
#elif defined(HOST_ARCH_ARM)
using namespace arch_arm; // NOLINT
#elif defined(HOST_ARCH_ARM64)
using namespace arch_arm64; // NOLINT
#else
#error Unknown host architecture.
#endif
} // namespace host
} // namespace dart
#endif // RUNTIME_VM_CONSTANTS_H_

View file

@ -5,10 +5,14 @@
#ifndef RUNTIME_VM_CONSTANTS_ARM_H_
#define RUNTIME_VM_CONSTANTS_ARM_H_
#ifndef RUNTIME_VM_CONSTANTS_H_
#error Do not include constants_arm.h directly; use constants.h instead.
#endif
#include "platform/assert.h"
#include "platform/globals.h"
namespace dart {
namespace arch_arm {
// We support both VFPv3-D16 and VFPv3-D32 profiles, but currently only one at
// a time.
@ -609,14 +613,14 @@ class Instr {
inline float ImmFloatField() const {
uint32_t imm32 = (Bit(19) << 31) | (((1 << 5) - Bit(18)) << 25) |
(Bits(16, 2) << 23) | (Bits(0, 4) << 19);
return bit_cast<float, uint32_t>(imm32);
return ::dart::bit_cast<float, uint32_t>(imm32);
}
// Field used in VFP double immediate move instruction
inline double ImmDoubleField() const {
uint64_t imm64 = (Bit(19) * (1LL << 63)) | (((1LL << 8) - Bit(18)) << 54) |
(Bits(16, 2) * (1LL << 52)) | (Bits(0, 4) * (1LL << 48));
return bit_cast<double, uint64_t>(imm64);
return ::dart::bit_cast<double, uint64_t>(imm64);
}
inline Register DivRdField() const {
@ -757,13 +761,13 @@ class Instr {
// reference to an instruction is to convert a pointer. There is no way
// to allocate or create instances of class Instr.
// Use the At(pc) function to create references to Instr.
static Instr* At(uword pc) { return reinterpret_cast<Instr*>(pc); }
static Instr* At(::dart::uword pc) { return reinterpret_cast<Instr*>(pc); }
private:
DISALLOW_ALLOCATION();
DISALLOW_IMPLICIT_CONSTRUCTORS(Instr);
};
} // namespace dart
} // namespace arch_arm
#endif // RUNTIME_VM_CONSTANTS_ARM_H_

View file

@ -2,11 +2,10 @@
// 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.
#if defined(TARGET_ARCH_ARM64)
#define RUNTIME_VM_CONSTANTS_H_ // To work around include guard.
#include "vm/constants_arm64.h"
namespace dart {
namespace arch_arm64 {
const Register CallingConventions::ArgumentRegisters[] = {
R0, R1, R2, R3, R4, R5, R6, R7,
@ -16,6 +15,4 @@ const FpuRegister CallingConventions::FpuArgumentRegisters[] = {
V0, V1, V2, V3, V4, V5, V6, V7,
};
} // namespace dart
#endif
} // namespace arch_arm64

View file

@ -5,9 +5,13 @@
#ifndef RUNTIME_VM_CONSTANTS_ARM64_H_
#define RUNTIME_VM_CONSTANTS_ARM64_H_
#ifndef RUNTIME_VM_CONSTANTS_H_
#error Do not include constants_arm64.h directly; use constants.h instead.
#endif
#include "platform/assert.h"
namespace dart {
namespace arch_arm64 {
enum Register {
R0 = 0,
@ -107,7 +111,7 @@ const FpuRegister kNoFpuRegister = kNoVRegister;
// Register aliases.
const Register TMP = R16; // Used as scratch register by assembler.
const Register TMP2 = R17;
const Register PP = R27; // Caches object pool pointer in generated code.
const Register PP = R27; // Caches object pool pointer in generated code.
const Register CODE_REG = R24;
const Register FPREG = FP; // Frame pointer register.
const Register SPREG = R15; // Stack pointer register.
@ -397,10 +401,7 @@ enum SystemOp {
SystemFixed = CompareBranchFixed | B31 | B30 | B24,
HINT = SystemFixed | B17 | B16 | B13 | B4 | B3 | B2 | B1 | B0,
CLREX = SystemFixed | B17 | B16 | B13 | B12 | B11 | B10 | B9 | B8 | B6 | B4 |
B3 |
B2 |
B1 |
B0,
B3 | B2 | B1 | B0,
};
// C3.2.5
@ -1186,13 +1187,13 @@ class Instr {
// reference to an instruction is to convert a pointer. There is no way
// to allocate or create instances of class Instr.
// Use the At(pc) function to create references to Instr.
static Instr* At(uword pc) { return reinterpret_cast<Instr*>(pc); }
static Instr* At(::dart::uword pc) { return reinterpret_cast<Instr*>(pc); }
private:
DISALLOW_ALLOCATION();
DISALLOW_IMPLICIT_CONSTRUCTORS(Instr);
};
} // namespace dart
} // namespace arch_arm64
#endif // RUNTIME_VM_CONSTANTS_ARM64_H_

View file

@ -2,11 +2,10 @@
// 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.
#if defined(TARGET_ARCH_IA32)
#define RUNTIME_VM_CONSTANTS_H_ // To work around include guard.
#include "vm/constants_ia32.h"
namespace dart {
namespace arch_ia32 {
// Although 'kArgumentRegisters' and 'kFpuArgumentRegisters' are both 0, we have
// to give these arrays at least one element to appease MSVC.
@ -16,6 +15,4 @@ const Register CallingConventions::ArgumentRegisters[] = {
const FpuRegister CallingConventions::FpuArgumentRegisters[] = {
static_cast<FpuRegister>(0)};
} // namespace dart
#endif
} // namespace arch_ia32

View file

@ -5,9 +5,13 @@
#ifndef RUNTIME_VM_CONSTANTS_IA32_H_
#define RUNTIME_VM_CONSTANTS_IA32_H_
#ifndef RUNTIME_VM_CONSTANTS_H_
#error Do not include constants_ia32.h directly; use constants.h instead.
#endif
#include "platform/assert.h"
namespace dart {
namespace arch_ia32 {
enum Register {
EAX = 0,
@ -88,7 +92,7 @@ enum ScaleFactor {
TIMES_4 = 2,
TIMES_8 = 3,
TIMES_16 = 4,
TIMES_HALF_WORD_SIZE = kWordSizeLog2 - 1
TIMES_HALF_WORD_SIZE = ::dart::kWordSizeLog2 - 1
};
class Instr {
@ -107,7 +111,7 @@ class Instr {
// reference to an instruction is to convert a pointer. There is no way
// to allocate or create instances of class Instr.
// Use the At(pc) function to create references to Instr.
static Instr* At(uword pc) { return reinterpret_cast<Instr*>(pc); }
static Instr* At(::dart::uword pc) { return reinterpret_cast<Instr*>(pc); }
private:
DISALLOW_ALLOCATION();
@ -142,6 +146,6 @@ class CallingConventions {
static constexpr Register kSecondNonArgumentRegister = ECX;
};
} // namespace dart
} // namespace arch_ia32
#endif // RUNTIME_VM_CONSTANTS_IA32_H_

View file

@ -2,11 +2,10 @@
// 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.
#if defined(TARGET_ARCH_X64)
#define RUNTIME_VM_CONSTANTS_H_ // To work around include guard.
#include "vm/constants_x64.h"
namespace dart {
namespace arch_x64 {
#if defined(_WIN64)
const Register CallingConventions::ArgumentRegisters[] = {
@ -26,6 +25,4 @@ const XmmRegister CallingConventions::FpuArgumentRegisters[] = {
XmmRegister::XMM4, XmmRegister::XMM5, XmmRegister::XMM6, XmmRegister::XMM7};
#endif
} // namespace dart
#endif
} // namespace arch_x64

View file

@ -5,10 +5,14 @@
#ifndef RUNTIME_VM_CONSTANTS_X64_H_
#define RUNTIME_VM_CONSTANTS_X64_H_
#ifndef RUNTIME_VM_CONSTANTS_H_
#error Do not include constants_x64.h directly; use constants.h instead.
#endif
#include "platform/assert.h"
#include "platform/globals.h"
namespace dart {
namespace arch_x64 {
enum Register {
RAX = 0,
@ -140,7 +144,7 @@ enum ScaleFactor {
TIMES_4 = 2,
TIMES_8 = 3,
TIMES_16 = 4,
TIMES_HALF_WORD_SIZE = kWordSizeLog2 - 1
TIMES_HALF_WORD_SIZE = ::dart::kWordSizeLog2 - 1
};
#define R(reg) (1 << (reg))
@ -166,7 +170,7 @@ class CallingConventions {
// same time? (Windows no, rest yes)
static const bool kArgumentIntRegXorFpuReg = true;
static const intptr_t kShadowSpaceBytes = 4 * kWordSize;
static const intptr_t kShadowSpaceBytes = 4 * ::dart::kWordSize;
static const intptr_t kVolatileCpuRegisters =
R(RAX) | R(RCX) | R(RDX) | R(R8) | R(R9) | R(R10) | R(R11);
@ -268,7 +272,7 @@ class Instr {
// reference to an instruction is to convert a pointer. There is no way
// to allocate or create instances of class Instr.
// Use the At(pc) function to create references to Instr.
static Instr* At(uword pc) { return reinterpret_cast<Instr*>(pc); }
static Instr* At(::dart::uword pc) { return reinterpret_cast<Instr*>(pc); }
private:
DISALLOW_ALLOCATION();
@ -280,6 +284,6 @@ class Instr {
// becomes important to us.
const int MAX_NOP_SIZE = 8;
} // namespace dart
} // namespace arch_x64
#endif // RUNTIME_VM_CONSTANTS_X64_H_

View file

@ -9,7 +9,7 @@
#include "vm/cpu_ia32.h"
#include "vm/compiler/assembler/assembler.h"
#include "vm/constants_ia32.h"
#include "vm/constants.h"
#include "vm/cpuinfo.h"
#include "vm/heap/heap.h"
#include "vm/isolate.h"

View file

@ -9,7 +9,7 @@
#include "vm/cpu_x64.h"
#include "vm/compiler/assembler/assembler.h"
#include "vm/constants_x64.h"
#include "vm/constants.h"
#include "vm/cpuinfo.h"
#include "vm/heap/heap.h"
#include "vm/isolate.h"

View file

@ -9,7 +9,7 @@
#include "vm/instructions_arm.h"
#include "vm/compiler/assembler/assembler.h"
#include "vm/constants_arm.h"
#include "vm/constants.h"
#include "vm/cpu.h"
#include "vm/object.h"
#include "vm/reverse_pc_lookup_cache.h"

View file

@ -12,7 +12,7 @@
#include "vm/allocation.h"
#include "vm/compiler/assembler/assembler.h"
#include "vm/constants_arm.h"
#include "vm/constants.h"
#include "vm/native_function.h"
namespace dart {

View file

@ -9,7 +9,7 @@
#include "vm/instructions_arm64.h"
#include "vm/compiler/assembler/assembler.h"
#include "vm/constants_arm64.h"
#include "vm/constants.h"
#include "vm/cpu.h"
#include "vm/object.h"
#include "vm/reverse_pc_lookup_cache.h"

View file

@ -12,7 +12,7 @@
#include "vm/allocation.h"
#include "vm/compiler/assembler/assembler.h"
#include "vm/constants_arm64.h"
#include "vm/constants.h"
#include "vm/native_function.h"
namespace dart {

View file

@ -9,7 +9,7 @@
#include "vm/instructions.h"
#include "vm/instructions_x64.h"
#include "vm/constants_x64.h"
#include "vm/constants.h"
#include "vm/cpu.h"
#include "vm/object.h"

View file

@ -15,7 +15,7 @@
#include "vm/compiler/assembler/assembler.h"
#include "vm/compiler/assembler/disassembler.h"
#include "vm/constants_arm.h"
#include "vm/constants.h"
#include "vm/cpu.h"
#include "vm/native_arguments.h"
#include "vm/os_thread.h"

View file

@ -16,7 +16,7 @@
#error Do not include simulator_arm.h directly; use simulator.h.
#endif
#include "vm/constants_arm.h"
#include "vm/constants.h"
namespace dart {

View file

@ -15,7 +15,7 @@
#include "vm/compiler/assembler/assembler.h"
#include "vm/compiler/assembler/disassembler.h"
#include "vm/constants_arm64.h"
#include "vm/constants.h"
#include "vm/native_arguments.h"
#include "vm/os_thread.h"
#include "vm/stack_frame.h"

View file

@ -16,7 +16,7 @@
#error Do not include simulator_arm64.h directly; use simulator.h.
#endif
#include "vm/constants_arm64.h"
#include "vm/constants.h"
namespace dart {

View file

@ -46,8 +46,8 @@ vm_sources = [
"constants_arm64.cc",
"constants_arm64.h",
"constants_dbc.h",
"constants_ia32.h",
"constants_ia32.cc",
"constants_ia32.h",
"constants_kbc.h",
"constants_x64.cc",
"constants_x64.h",