Consolidate address calculations for atomics (#3143)

* Consolidate address calculations for atomics

This commit consolidates all calcuations of guest addresses into one
`prepare_addr` function. This notably remove the atomics-specifics paths
as well as the `prepare_load` function (now renamed to `prepare_addr`
and folded into `get_heap_addr`).

The goal of this commit is to simplify how addresses are managed in the
code generator for atomics to use all the shared infrastrucutre of other
loads/stores as well. This additionally fixes #3132 via the use of
`heap_addr` in clif for all operations.

I also added a number of tests for loads/stores with varying alignments.
Originally I was going to allow loads/stores to not be aligned since
that's what the current formal specification says, but the overview of
the threads proposal disagrees with the formal specification, so I
figured I'd leave it as-is but adding tests probably doesn't hurt.

Closes #3132

* Fix old backend

* Guarantee misalignment checks happen before out-of-bounds
This commit is contained in:
Alex Crichton
2021-08-04 15:57:56 -05:00
committed by GitHub
parent 91d24b8448
commit 85f16f488d
6 changed files with 328 additions and 208 deletions

View File

@@ -613,6 +613,10 @@ pub trait FuncEnvironment: TargetEnvironment {
/// for the same index. Whether the waited-on value is 32- or 64-bit can be
/// determined by examining the type of `expected`, which must be only I32 or I64.
///
/// Note that the `addr` here is the host linear memory address rather
/// than a relative wasm linear memory address. The type of this value is
/// the same as the host's pointer.
///
/// Returns an i32, which is negative if the helper call failed.
fn translate_atomic_wait(
&mut self,
@@ -629,6 +633,10 @@ pub trait FuncEnvironment: TargetEnvironment {
/// to wait on, and `heap` is the heap reference returned by `make_heap`
/// for the same index.
///
/// Note that the `addr` here is the host linear memory address rather
/// than a relative wasm linear memory address. The type of this value is
/// the same as the host's pointer.
///
/// Returns an i64, which is negative if the helper call failed.
fn translate_atomic_notify(
&mut self,