Commit 4b397e6c authored by Mircea Trofin's avatar Mircea Trofin Committed by Commit Bot

[wasm] Reuse reloc info size and address accessors.

The way we access wasm addresses or sizes is the same, on
a platform. We have 2 size parameters - memory and table - and
2 addresses - globals and memory.

The CL also renames for generality the address setting API.

Bug: 
Change-Id: Ib66c3aff6a0ab4313391528cd2692749bb389559
Reviewed-on: https://chromium-review.googlesource.com/612597
Commit-Queue: Brad Nelson <bradnelson@chromium.org>
Reviewed-by: 's avatarBrad Nelson <bradnelson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47350}
parent 832d5f97
......@@ -338,33 +338,21 @@ bool RelocInfo::IsInConstantPool() {
return Assembler::is_constant_pool_load(pc_);
}
Address RelocInfo::wasm_memory_reference() {
DCHECK(IsWasmMemoryReference(rmode_));
Address RelocInfo::embedded_address() const {
return Assembler::target_address_at(pc_, host_);
}
uint32_t RelocInfo::wasm_memory_size_reference() {
DCHECK(IsWasmMemorySizeReference(rmode_));
uint32_t RelocInfo::embedded_size() const {
return reinterpret_cast<uint32_t>(Assembler::target_address_at(pc_, host_));
}
Address RelocInfo::wasm_global_reference() {
DCHECK(IsWasmGlobalReference(rmode_));
return Assembler::target_address_at(pc_, host_);
}
uint32_t RelocInfo::wasm_function_table_size_reference() {
DCHECK(IsWasmFunctionTableSizeReference(rmode_));
return reinterpret_cast<uint32_t>(Assembler::target_address_at(pc_, host_));
}
void RelocInfo::unchecked_update_wasm_memory_reference(
Isolate* isolate, Address address, ICacheFlushMode flush_mode) {
void RelocInfo::set_embedded_address(Isolate* isolate, Address address,
ICacheFlushMode flush_mode) {
Assembler::set_target_address_at(isolate, pc_, host_, address, flush_mode);
}
void RelocInfo::unchecked_update_wasm_size(Isolate* isolate, uint32_t size,
ICacheFlushMode flush_mode) {
void RelocInfo::set_embedded_size(Isolate* isolate, uint32_t size,
ICacheFlushMode flush_mode) {
Assembler::set_target_address_at(isolate, pc_, host_,
reinterpret_cast<Address>(size), flush_mode);
}
......
......@@ -176,33 +176,21 @@ bool RelocInfo::IsInConstantPool() {
return instr->IsLdrLiteralX();
}
Address RelocInfo::wasm_memory_reference() {
DCHECK(IsWasmMemoryReference(rmode_));
Address RelocInfo::embedded_address() const {
return Memory::Address_at(Assembler::target_pointer_address_at(pc_));
}
uint32_t RelocInfo::wasm_memory_size_reference() {
DCHECK(IsWasmMemorySizeReference(rmode_));
uint32_t RelocInfo::embedded_size() const {
return Memory::uint32_at(Assembler::target_pointer_address_at(pc_));
}
Address RelocInfo::wasm_global_reference() {
DCHECK(IsWasmGlobalReference(rmode_));
return Memory::Address_at(Assembler::target_pointer_address_at(pc_));
}
uint32_t RelocInfo::wasm_function_table_size_reference() {
DCHECK(IsWasmFunctionTableSizeReference(rmode_));
return Memory::uint32_at(Assembler::target_pointer_address_at(pc_));
}
void RelocInfo::unchecked_update_wasm_memory_reference(
Isolate* isolate, Address address, ICacheFlushMode flush_mode) {
void RelocInfo::set_embedded_address(Isolate* isolate, Address address,
ICacheFlushMode flush_mode) {
Assembler::set_target_address_at(isolate, pc_, host_, address, flush_mode);
}
void RelocInfo::unchecked_update_wasm_size(Isolate* isolate, uint32_t size,
ICacheFlushMode flush_mode) {
void RelocInfo::set_embedded_size(Isolate* isolate, uint32_t size,
ICacheFlushMode flush_mode) {
Memory::uint32_at(Assembler::target_pointer_address_at(pc_)) = size;
// No icache flushing needed, see comment in set_target_address_at.
}
......
......@@ -310,8 +310,7 @@ void RelocInfo::update_wasm_memory_reference(
Address updated_reference = new_base + (wasm_memory_reference() - old_base);
// The reference is not checked here but at runtime. Validity of references
// may change over time.
unchecked_update_wasm_memory_reference(isolate, updated_reference,
icache_flush_mode);
set_embedded_address(isolate, updated_reference, icache_flush_mode);
}
void RelocInfo::update_wasm_memory_size(Isolate* isolate, uint32_t old_size,
......@@ -321,8 +320,7 @@ void RelocInfo::update_wasm_memory_size(Isolate* isolate, uint32_t old_size,
uint32_t current_size_reference = wasm_memory_size_reference();
uint32_t updated_size_reference =
new_size + (current_size_reference - old_size);
unchecked_update_wasm_size(isolate, updated_size_reference,
icache_flush_mode);
set_embedded_size(isolate, updated_size_reference, icache_flush_mode);
}
void RelocInfo::update_wasm_global_reference(
......@@ -333,15 +331,34 @@ void RelocInfo::update_wasm_global_reference(
DCHECK_LE(old_base, wasm_global_reference());
updated_reference = new_base + (wasm_global_reference() - old_base);
DCHECK_LE(new_base, updated_reference);
unchecked_update_wasm_memory_reference(isolate, updated_reference,
icache_flush_mode);
set_embedded_address(isolate, updated_reference, icache_flush_mode);
}
Address RelocInfo::wasm_global_reference() const {
DCHECK(IsWasmGlobalReference(rmode_));
return embedded_address();
}
uint32_t RelocInfo::wasm_function_table_size_reference() const {
DCHECK(IsWasmFunctionTableSizeReference(rmode_));
return embedded_size();
}
uint32_t RelocInfo::wasm_memory_size_reference() const {
DCHECK(IsWasmMemorySizeReference(rmode_));
return embedded_size();
}
Address RelocInfo::wasm_memory_reference() const {
DCHECK(IsWasmMemoryReference(rmode_));
return embedded_address();
}
void RelocInfo::update_wasm_function_table_size_reference(
Isolate* isolate, uint32_t old_size, uint32_t new_size,
ICacheFlushMode icache_flush_mode) {
DCHECK(IsWasmFunctionTableSizeReference(rmode_));
unchecked_update_wasm_size(isolate, new_size, icache_flush_mode);
set_embedded_size(isolate, new_size, icache_flush_mode);
}
void RelocInfo::set_target_address(Isolate* isolate, Address target,
......
......@@ -505,10 +505,10 @@ class RelocInfo {
// constant pool, otherwise the pointer is embedded in the instruction stream.
bool IsInConstantPool();
Address wasm_memory_reference();
Address wasm_global_reference();
uint32_t wasm_function_table_size_reference();
uint32_t wasm_memory_size_reference();
Address wasm_memory_reference() const;
Address wasm_global_reference() const;
uint32_t wasm_function_table_size_reference() const;
uint32_t wasm_memory_size_reference() const;
void update_wasm_memory_reference(
Isolate* isolate, Address old_base, Address new_base,
ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED);
......@@ -626,10 +626,13 @@ class RelocInfo {
static const int kApplyMask; // Modes affected by apply. Depends on arch.
private:
void unchecked_update_wasm_memory_reference(Isolate* isolate, Address address,
ICacheFlushMode flush_mode);
void unchecked_update_wasm_size(Isolate* isolate, uint32_t size,
ICacheFlushMode flush_mode);
void set_embedded_address(Isolate* isolate, Address address,
ICacheFlushMode flush_mode);
void set_embedded_size(Isolate* isolate, uint32_t size,
ICacheFlushMode flush_mode);
uint32_t embedded_size() const;
Address embedded_address() const;
// On ARM, note that pc_ is the address of the constant pool entry
// to be relocated and not the address of the instruction
......
......@@ -204,36 +204,20 @@ bool RelocInfo::IsInConstantPool() {
return false;
}
Address RelocInfo::wasm_memory_reference() {
DCHECK(IsWasmMemoryReference(rmode_));
return Memory::Address_at(pc_);
}
Address RelocInfo::wasm_global_reference() {
DCHECK(IsWasmGlobalReference(rmode_));
return Memory::Address_at(pc_);
}
Address RelocInfo::embedded_address() const { return Memory::Address_at(pc_); }
uint32_t RelocInfo::wasm_memory_size_reference() {
DCHECK(IsWasmMemorySizeReference(rmode_));
return Memory::uint32_at(pc_);
}
uint32_t RelocInfo::wasm_function_table_size_reference() {
DCHECK(IsWasmFunctionTableSizeReference(rmode_));
return Memory::uint32_at(pc_);
}
uint32_t RelocInfo::embedded_size() const { return Memory::uint32_at(pc_); }
void RelocInfo::unchecked_update_wasm_memory_reference(
Isolate* isolate, Address address, ICacheFlushMode icache_flush_mode) {
void RelocInfo::set_embedded_address(Isolate* isolate, Address address,
ICacheFlushMode icache_flush_mode) {
Memory::Address_at(pc_) = address;
if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
Assembler::FlushICache(isolate, pc_, sizeof(Address));
}
}
void RelocInfo::unchecked_update_wasm_size(Isolate* isolate, uint32_t size,
ICacheFlushMode icache_flush_mode) {
void RelocInfo::set_embedded_size(Isolate* isolate, uint32_t size,
ICacheFlushMode icache_flush_mode) {
Memory::uint32_at(pc_) = size;
if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
Assembler::FlushICache(isolate, pc_, sizeof(uint32_t));
......
......@@ -191,33 +191,21 @@ bool RelocInfo::IsInConstantPool() {
return false;
}
Address RelocInfo::wasm_memory_reference() {
DCHECK(IsWasmMemoryReference(rmode_));
Address RelocInfo::embedded_address() const {
return Assembler::target_address_at(pc_, host_);
}
Address RelocInfo::wasm_global_reference() {
DCHECK(IsWasmGlobalReference(rmode_));
return Assembler::target_address_at(pc_, host_);
}
uint32_t RelocInfo::wasm_memory_size_reference() {
DCHECK(IsWasmMemorySizeReference(rmode_));
return reinterpret_cast<uint32_t>(Assembler::target_address_at(pc_, host_));
}
uint32_t RelocInfo::wasm_function_table_size_reference() {
DCHECK(IsWasmFunctionTableSizeReference(rmode_));
uint32_t RelocInfo::embedded_size() const {
return reinterpret_cast<uint32_t>(Assembler::target_address_at(pc_, host_));
}
void RelocInfo::unchecked_update_wasm_memory_reference(
Isolate* isolate, Address address, ICacheFlushMode flush_mode) {
void RelocInfo::set_embedded_address(Isolate* isolate, Address address,
ICacheFlushMode flush_mode) {
Assembler::set_target_address_at(isolate, pc_, host_, address, flush_mode);
}
void RelocInfo::unchecked_update_wasm_size(Isolate* isolate, uint32_t size,
ICacheFlushMode flush_mode) {
void RelocInfo::set_embedded_size(Isolate* isolate, uint32_t size,
ICacheFlushMode flush_mode) {
Assembler::set_target_address_at(isolate, pc_, host_,
reinterpret_cast<Address>(size), flush_mode);
}
......
......@@ -169,35 +169,22 @@ bool RelocInfo::IsInConstantPool() {
return false;
}
Address RelocInfo::wasm_memory_reference() {
DCHECK(IsWasmMemoryReference(rmode_));
Address RelocInfo::embedded_address() const {
return Assembler::target_address_at(pc_, host_);
}
Address RelocInfo::wasm_global_reference() {
DCHECK(IsWasmGlobalReference(rmode_));
return Assembler::target_address_at(pc_, host_);
}
uint32_t RelocInfo::wasm_memory_size_reference() {
DCHECK(IsWasmMemorySizeReference(rmode_));
return static_cast<uint32_t>(
reinterpret_cast<intptr_t>((Assembler::target_address_at(pc_, host_))));
}
uint32_t RelocInfo::wasm_function_table_size_reference() {
DCHECK(IsWasmFunctionTableSizeReference(rmode_));
uint32_t RelocInfo::embedded_size() const {
return static_cast<uint32_t>(
reinterpret_cast<intptr_t>((Assembler::target_address_at(pc_, host_))));
}
void RelocInfo::unchecked_update_wasm_memory_reference(
Isolate* isolate, Address address, ICacheFlushMode flush_mode) {
void RelocInfo::set_embedded_address(Isolate* isolate, Address address,
ICacheFlushMode flush_mode) {
Assembler::set_target_address_at(isolate, pc_, host_, address, flush_mode);
}
void RelocInfo::unchecked_update_wasm_size(Isolate* isolate, uint32_t size,
ICacheFlushMode flush_mode) {
void RelocInfo::set_embedded_size(Isolate* isolate, uint32_t size,
ICacheFlushMode flush_mode) {
Assembler::set_target_address_at(isolate, pc_, host_,
reinterpret_cast<Address>(size), flush_mode);
}
......
......@@ -123,36 +123,20 @@ void CpuFeatures::PrintFeatures() {
// -----------------------------------------------------------------------------
// Implementation of RelocInfo
Address RelocInfo::wasm_memory_reference() {
DCHECK(IsWasmMemoryReference(rmode_));
return Memory::Address_at(pc_);
}
Address RelocInfo::wasm_global_reference() {
DCHECK(IsWasmGlobalReference(rmode_));
return Memory::Address_at(pc_);
}
Address RelocInfo::embedded_address() const { return Memory::Address_at(pc_); }
uint32_t RelocInfo::wasm_memory_size_reference() {
DCHECK(IsWasmMemorySizeReference(rmode_));
return Memory::uint32_at(pc_);
}
uint32_t RelocInfo::wasm_function_table_size_reference() {
DCHECK(IsWasmFunctionTableSizeReference(rmode_));
return Memory::uint32_at(pc_);
}
uint32_t RelocInfo::embedded_size() const { return Memory::uint32_at(pc_); }
void RelocInfo::unchecked_update_wasm_memory_reference(
Isolate* isolate, Address address, ICacheFlushMode icache_flush_mode) {
void RelocInfo::set_embedded_address(Isolate* isolate, Address address,
ICacheFlushMode icache_flush_mode) {
Memory::Address_at(pc_) = address;
if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
Assembler::FlushICache(isolate, pc_, sizeof(Address));
}
}
void RelocInfo::unchecked_update_wasm_size(Isolate* isolate, uint32_t size,
ICacheFlushMode icache_flush_mode) {
void RelocInfo::set_embedded_size(Isolate* isolate, uint32_t size,
ICacheFlushMode icache_flush_mode) {
Memory::uint32_at(pc_) = size;
if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
Assembler::FlushICache(isolate, pc_, sizeof(uint32_t));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment