From 4f7bb16cc5cafbb4744e9b4e9cebf527bf30edcd Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Fri, 29 Jul 2022 18:11:01 +0000 Subject: [PATCH] [vm] Add a stub simx64. This allows building gen_snapshot with host=arm64, target=x64. TEST=ci Bug: https://github.com/flutter/flutter/issues/103386 Change-Id: I478cc0917462896de9b598455d2ed68401323b50 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/252962 Reviewed-by: Alexander Aprelev Reviewed-by: Siva Annamalai Commit-Queue: Ryan Macnak --- pkg/smith/lib/configuration.dart | 4 + .../lib/src/compiler_configuration.dart | 2 + runtime/vm/cpu_x64.cc | 26 +++++++ runtime/vm/simulator.h | 4 +- runtime/vm/simulator_x64.cc | 72 ++++++++++++++++++ runtime/vm/simulator_x64.h | 76 +++++++++++++++++++ runtime/vm/vm_sources.gni | 2 + tools/bots/test_matrix.json | 8 ++ tools/gn.py | 8 +- tools/utils.py | 2 + 10 files changed, 199 insertions(+), 5 deletions(-) create mode 100644 runtime/vm/simulator_x64.cc create mode 100644 runtime/vm/simulator_x64.h diff --git a/pkg/smith/lib/configuration.dart b/pkg/smith/lib/configuration.dart index f5a7d94a856..07a761898a5 100644 --- a/pkg/smith/lib/configuration.dart +++ b/pkg/smith/lib/configuration.dart @@ -578,6 +578,8 @@ class Architecture extends NamedEnum { static const ia32 = Architecture._('ia32'); static const x64 = Architecture._('x64'); static const x64c = Architecture._('x64c'); + static const simx64 = Architecture._('simx64'); + static const simx64c = Architecture._('simx64c'); static const arm = Architecture._('arm'); // ignore: constant_identifier_names static const arm_x64 = Architecture._('arm_x64'); @@ -597,6 +599,8 @@ class Architecture extends NamedEnum { ia32, x64, x64c, + simx64, + simx64c, arm, arm_x64, arm64, diff --git a/pkg/test_runner/lib/src/compiler_configuration.dart b/pkg/test_runner/lib/src/compiler_configuration.dart index 190e81d37b8..1b6e70b4292 100644 --- a/pkg/test_runner/lib/src/compiler_configuration.dart +++ b/pkg/test_runner/lib/src/compiler_configuration.dart @@ -1005,6 +1005,8 @@ class PrecompilerCompilerConfiguration extends CompilerConfiguration switch (_configuration.architecture) { case Architecture.x64: case Architecture.x64c: + case Architecture.simx64: + case Architecture.simx64c: ccFlags = "-m64"; break; case Architecture.simarm64: diff --git a/runtime/vm/cpu_x64.cc b/runtime/vm/cpu_x64.cc index cf0acf3798c..bd78c504d03 100644 --- a/runtime/vm/cpu_x64.cc +++ b/runtime/vm/cpu_x64.cc @@ -40,6 +40,7 @@ bool HostCPUFeatures::abm_supported_ = false; bool HostCPUFeatures::initialized_ = false; #endif +#if !defined(USING_SIMULATOR) void HostCPUFeatures::Init() { CpuInfo::Init(); hardware_ = CpuInfo::GetCpuModel(); @@ -63,6 +64,31 @@ void HostCPUFeatures::Cleanup() { CpuInfo::Cleanup(); } +#else // !defined(USING_SIMULATOR) + +void HostCPUFeatures::Init() { + CpuInfo::Init(); + hardware_ = CpuInfo::GetCpuModel(); + sse4_1_supported_ = false; + popcnt_supported_ = false; + abm_supported_ = false; +#if defined(DEBUG) + initialized_ = true; +#endif +} + +void HostCPUFeatures::Cleanup() { + DEBUG_ASSERT(initialized_); +#if defined(DEBUG) + initialized_ = false; +#endif + ASSERT(hardware_ != NULL); + free(const_cast(hardware_)); + hardware_ = NULL; + CpuInfo::Cleanup(); +} +#endif // !defined(USING_SIMULATOR) + } // namespace dart #endif // defined TARGET_ARCH_X64 diff --git a/runtime/vm/simulator.h b/runtime/vm/simulator.h index 7738d0c9af6..659bc8b2482 100644 --- a/runtime/vm/simulator.h +++ b/runtime/vm/simulator.h @@ -8,8 +8,10 @@ #include "vm/globals.h" #if defined(USING_SIMULATOR) -#if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) +#if defined(TARGET_ARCH_IA32) #error Simulator not implemented. +#elif defined(TARGET_ARCH_X64) +#include "vm/simulator_x64.h" #elif defined(TARGET_ARCH_ARM) #include "vm/simulator_arm.h" #elif defined(TARGET_ARCH_ARM64) diff --git a/runtime/vm/simulator_x64.cc b/runtime/vm/simulator_x64.cc new file mode 100644 index 00000000000..936427170a8 --- /dev/null +++ b/runtime/vm/simulator_x64.cc @@ -0,0 +1,72 @@ +// Copyright (c) 2022, 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. + +#include // NOLINT +#include + +#include "vm/globals.h" +#if defined(TARGET_ARCH_X64) + +// Only build the simulator if not compiling for real X64 hardware. +#if defined(USING_SIMULATOR) + +#include "vm/simulator.h" + +#include "vm/heap/safepoint.h" +#include "vm/isolate.h" + +namespace dart { + +// Get the active Simulator for the current isolate. +Simulator* Simulator::Current() { + Isolate* isolate = Isolate::Current(); + Simulator* simulator = isolate->simulator(); + if (simulator == NULL) { + NoSafepointScope no_safepoint; + simulator = new Simulator(); + isolate->set_simulator(simulator); + } + return simulator; +} + +void Simulator::Init() {} + +Simulator::Simulator() {} + +Simulator::~Simulator() { + Isolate* isolate = Isolate::Current(); + if (isolate != NULL) { + isolate->set_simulator(NULL); + } +} + +int64_t Simulator::Call(int64_t entry, + int64_t parameter0, + int64_t parameter1, + int64_t parameter2, + int64_t parameter3, + bool fp_return, + bool fp_args) { + UNIMPLEMENTED(); +} + +void Simulator::JumpToFrame(uword pc, uword sp, uword fp, Thread* thread) { + UNIMPLEMENTED(); +} + +uword Simulator::RedirectExternalReference(uword function, + CallKind call_kind, + int argument_count) { + return 0; +} + +uword Simulator::FunctionForRedirect(uword redirect) { + return 0; +} + +} // namespace dart + +#endif // !defined(USING_SIMULATOR) + +#endif // defined TARGET_ARCH_RISCV diff --git a/runtime/vm/simulator_x64.h b/runtime/vm/simulator_x64.h new file mode 100644 index 00000000000..dad98f22347 --- /dev/null +++ b/runtime/vm/simulator_x64.h @@ -0,0 +1,76 @@ +// Copyright (c) 2022, 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_SIMULATOR_X64_H_ +#define RUNTIME_VM_SIMULATOR_X64_H_ + +#ifndef RUNTIME_VM_SIMULATOR_H_ +#error Do not include simulator_x64.h directly; use simulator.h. +#endif + +#include "vm/constants.h" +#include "vm/random.h" + +namespace dart { + +class Thread; + +class Simulator { + public: + static const uword kSimulatorStackUnderflowSize = 64; + + Simulator(); + ~Simulator(); + + static Simulator* Current(); + + int64_t Call(int64_t entry, + int64_t parameter0, + int64_t parameter1, + int64_t parameter2, + int64_t parameter3, + bool fp_return = false, + bool fp_args = false); + + // Runtime and native call support. + enum CallKind { + kRuntimeCall, + kLeafRuntimeCall, + kLeafFloatRuntimeCall, + kNativeCallWrapper + }; + static uword RedirectExternalReference(uword function, + CallKind call_kind, + int argument_count); + + static uword FunctionForRedirect(uword redirect); + + void JumpToFrame(uword pc, uword sp, uword fp, Thread* thread); + + uint64_t get_register(Register rs) const { return 0; } + uint64_t get_pc() const { return 0; } + uint64_t get_sp() const { return 0; } + uint64_t get_fp() const { return 0; } + uint64_t get_lr() const { return 0; } + + // High address. + uword stack_base() const { return 0; } + // Limit for StackOverflowError. + uword overflow_stack_limit() const { return 0; } + // Low address. + uword stack_limit() const { return 0; } + + // Accessor to the instruction counter. + uint64_t get_icount() const { return 0; } + + // Call on program start. + static void Init(); + + private: + DISALLOW_COPY_AND_ASSIGN(Simulator); +}; + +} // namespace dart + +#endif // RUNTIME_VM_SIMULATOR_X64_H_ diff --git a/runtime/vm/vm_sources.gni b/runtime/vm/vm_sources.gni index 5efb5042f5c..4af1fd18c72 100644 --- a/runtime/vm/vm_sources.gni +++ b/runtime/vm/vm_sources.gni @@ -301,6 +301,8 @@ vm_sources = [ "simulator_arm64.h", "simulator_riscv.cc", "simulator_riscv.h", + "simulator_x64.cc", + "simulator_x64.h", "snapshot.cc", "snapshot.h", "source_report.cc", diff --git a/tools/bots/test_matrix.json b/tools/bots/test_matrix.json index 87cb2548963..15995b85c2b 100644 --- a/tools/bots/test_matrix.json +++ b/tools/bots/test_matrix.json @@ -1337,6 +1337,14 @@ "gen_snapshot" ] }, + { + "name": "build dart (cross x64)", + "script": "tools/build.py", + "arguments": [ + "--arch=simx64", + "gen_snapshot" + ] + }, { "name": "vm nnbd tests in weak mode with asserts", "arguments": [ diff --git a/tools/gn.py b/tools/gn.py index c93daea550b..b532f0bae4f 100755 --- a/tools/gn.py +++ b/tools/gn.py @@ -82,8 +82,8 @@ def HostCpuForArch(arch): # - using a host architecture with a different word size (supports only AOT and only 32-bit target on 64-bit host) if arch in ['ia32']: candidates = ['x86'] - elif arch in ['x64', 'x64c']: - candidates = ['x64'] + elif arch in ['x64', 'x64c', 'simx64', 'simx64c']: + candidates = ['x64', 'arm64'] elif arch in ['arm', 'simarm']: candidates = ['arm', 'x86', 'riscv32', 'arm64', 'x64', 'riscv64'] elif arch in ['arm64', 'arm64c', 'simarm64', 'simarm64c']: @@ -124,7 +124,7 @@ def TargetCpuForArch(arch, target_os): # Simulators if arch in ['simarm_x64', 'simriscv32_x64']: return 'x64' - elif arch in ['simarm_arm64', 'simriscv32_arm64']: + elif arch in ['simarm_arm64', 'simriscv32_arm64', 'simx64', 'simx64c']: return 'arm64' elif arch in ['simarm_riscv64', 'simriscv32_riscv64']: return 'riscv64' @@ -149,7 +149,7 @@ def TargetCpuForArch(arch, target_os): def DartTargetCpuForArch(arch): if arch in ['ia32']: return 'ia32' - if arch in ['x64', 'x64c']: + if arch in ['x64', 'x64c', 'simx64', 'simx64c']: return 'x64' if arch in [ 'arm', 'simarm', 'simarm_x64', 'arm_x64', 'simarm_arm64', diff --git a/tools/utils.py b/tools/utils.py index 9141d937709..9186fddd38f 100644 --- a/tools/utils.py +++ b/tools/utils.py @@ -77,6 +77,8 @@ ARCH_FAMILY = { 'simarm64c': 'ia32', 'simriscv32': 'ia32', 'simriscv64': 'ia32', + 'simx64': 'arm', + 'simx64c': 'arm', 'riscv32': 'riscv', 'riscv64': 'riscv', }