mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
![Ryan Macnak](/assets/img/avatar_default.png)
Implements a backend targeting RV32GC and RV64GC, based on Linux standardizing around GC. The assembler is written to make it easy to disable usage of C, but because the sizes of some instruction sequences are compile-time constants, an additional build configuration would need to be defined to make use of it. The assembler and disassembler cover every RV32/64GC instruction. The simulator covers all instructions except accessing CSRs and the floating point state accessible through such, include accrued exceptions and dynamic rounding mode. Quirks: - RISC-V is a compare-and-branch architecture, but some existing "architecture-independent" parts of the Dart compiler assume a condition code architecture. To avoid rewriting these parts, we use a peephole in the assembler to map to compare-and-branch. See Assembler::BranchIf. Luckily nothing depended on taking multiple branches on the same condition code set. - There are no hardware overflow checks, so we must use Hacker's Delight style software checks. Often these are very cheap: if the sign of one operand is known, a single branch is needed. - The ranges of RISC-V branches and jumps are such that we use 3 levels of generation for forward branches, instead of the 2 levels of near and far branches used on ARM[64]. Nearly all code is handled by the first two levels with 20-bits of range, with enormous regex matchers triggering the third level that uses aupic+jalr to get 32-bits of range. - For PC-relative calls in AOT, we always generate auipc+jalr pairs with 32-bits of range, so we never generate trampolines. - Only a subset of registers are available in some compressed instructions, so we assign the most popular uses to these registers. In particular, THR, TMP[2], CODE and PP. This has the effect of assigning CODE and PP to volatile registers in the C calling convention, whereas they are assigned preserved registers on the other architectures. As on ARM64, PP is untagged; this is so short indices can be accessed with a compressed instruction. - There are no push or pop instructions, so combining pushes and pops is preferred so we can update SP once. - The C calling convention has a strongly aligned stack, but unlike on ARM64 we don't need to use an alternate stack pointer. The author ensured language was added to the RISC-V psABI making the OS responsible for realigning the stack pointer for signal handlers, allowing Dart to leave the stack pointer misaligned from the C calling convention's point of view until a foreign call. - We don't bother with the link register tracking done on ARM[64]. Instead we make use of an alternate link register to avoid inline spilling in the write barrier. Unimplemented: - non-trivial FFI cases - Compressed pointers - No intention to implement. - Unboxed SIMD - We might make use of the V extension registers when the V extension is ratified. - BigInt intrinsics TEST=existing tests for IL level, new tests for assembler/disassembler/simulator Bug: https://github.com/dart-lang/sdk/issues/38587 Bug: https://github.com/dart-lang/sdk/issues/48164 Change-Id: I991d1df4be5bf55efec5371b767b332d37dfa3e0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217289 Reviewed-by: Alexander Markov <alexmarkov@google.com> Reviewed-by: Daco Harkes <dacoharkes@google.com> Reviewed-by: Slava Egorov <vegorov@google.com> Commit-Queue: Ryan Macnak <rmacnak@google.com>
93 lines
2.1 KiB
C++
93 lines
2.1 KiB
C++
// Copyright (c) 2017, 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 "platform/globals.h"
|
|
|
|
#if !defined(DEBUG) || !defined(DART_USE_TCMALLOC)
|
|
|
|
#include "vm/malloc_hooks.h"
|
|
|
|
#include "vm/json_stream.h"
|
|
|
|
#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID)
|
|
#include <malloc.h>
|
|
#elif defined(DART_HOST_OS_MACOS)
|
|
#include <malloc/malloc.h>
|
|
#endif
|
|
|
|
#if !defined(DART_HOST_OS_WINDOWS) && !defined(DART_HOST_OS_MACOS)
|
|
extern "C" {
|
|
__attribute__((weak)) uintptr_t __sanitizer_get_current_allocated_bytes();
|
|
__attribute__((weak)) uintptr_t __sanitizer_get_heap_size();
|
|
__attribute__((weak)) int __sanitizer_install_malloc_and_free_hooks(
|
|
void (*malloc_hook)(const void*, uintptr_t),
|
|
void (*free_hook)(const void*));
|
|
}
|
|
#endif
|
|
|
|
namespace dart {
|
|
|
|
void MallocHooks::Init() {
|
|
// Do nothing.
|
|
}
|
|
|
|
void MallocHooks::Cleanup() {
|
|
// Do nothing.
|
|
}
|
|
|
|
bool MallocHooks::ProfilingEnabled() {
|
|
return false;
|
|
}
|
|
|
|
bool MallocHooks::stack_trace_collection_enabled() {
|
|
return false;
|
|
}
|
|
|
|
void MallocHooks::set_stack_trace_collection_enabled(bool enabled) {
|
|
// Do nothing.
|
|
}
|
|
|
|
void MallocHooks::ResetStats() {
|
|
// Do nothing.
|
|
}
|
|
|
|
bool MallocHooks::Active() {
|
|
return false;
|
|
}
|
|
|
|
bool MallocHooks::GetStats(intptr_t* used,
|
|
intptr_t* capacity,
|
|
const char** implementation) {
|
|
#if !defined(PRODUCT)
|
|
#if !defined(DART_HOST_OS_WINDOWS) && !defined(DART_HOST_OS_MACOS)
|
|
if (__sanitizer_get_current_allocated_bytes != nullptr &&
|
|
__sanitizer_get_heap_size != nullptr) {
|
|
*used = __sanitizer_get_current_allocated_bytes();
|
|
*capacity = __sanitizer_get_heap_size();
|
|
*implementation = "scudo";
|
|
return true;
|
|
}
|
|
#endif
|
|
return false;
|
|
#else
|
|
return false;
|
|
#endif
|
|
}
|
|
|
|
Sample* MallocHooks::GetSample(const void* ptr) {
|
|
return NULL;
|
|
}
|
|
|
|
intptr_t MallocHooks::allocation_count() {
|
|
return 0;
|
|
}
|
|
|
|
intptr_t MallocHooks::heap_allocated_memory_in_bytes() {
|
|
return 0;
|
|
}
|
|
|
|
} // namespace dart
|
|
|
|
#endif // !defined(DART_USE_TCMALLOC) && ...
|