mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
a2b88794ad
This patch adds TargetStackID::WasmLocal. This stack holds locations of values that are only addressable by name -- not via a pointer to memory. For the WebAssembly target, these objects are lowered to WebAssembly local variables, which are managed by the WebAssembly run-time and are not addressable by linear memory. For the WebAssembly target IR indicates that an AllocaInst should be put on TargetStackID::WasmLocal by putting it in the non-integral address space WASM_ADDRESS_SPACE_WASM_VAR, with value 1. SROA will mostly lift these allocations to SSA locals, but any alloca that reaches instruction selection (usually in non-optimized builds) will be assigned the new TargetStackID there. Loads and stores to those values are transformed to new WebAssemblyISD::LOCAL_GET / WebAssemblyISD::LOCAL_SET nodes, which then lower to the type-specific LOCAL_GET_I32 etc instructions via tablegen patterns. Differential Revision: https://reviews.llvm.org/D101140
88 lines
2.8 KiB
LLVM
88 lines
2.8 KiB
LLVM
; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false | FileCheck %s
|
|
|
|
%i32_cell = type i32 addrspace(1)*
|
|
%i64_cell = type i64 addrspace(1)*
|
|
%f32_cell = type float addrspace(1)*
|
|
%f64_cell = type double addrspace(1)*
|
|
|
|
; We have a set of tests in which we set a local and then reload the
|
|
; local. If the load immediately follows the set, the DAG combiner will
|
|
; infer that the reloaded value is the same value that was set, which
|
|
; isn't what we want to test. To inhibit this optimization, we include
|
|
; an opaque call between the store and the load.
|
|
declare void @inhibit_store_to_load_forwarding()
|
|
|
|
define i32 @ir_local_i32(i32 %arg) {
|
|
; CHECK-LABEL: ir_local_i32:
|
|
; CHECK-NEXT: .functype ir_local_i32 (i32) -> (i32)
|
|
%retval = alloca i32, addrspace(1)
|
|
; CHECK-NEXT: .local i32
|
|
store i32 %arg, %i32_cell %retval
|
|
; CHECK-NEXT: local.get 0
|
|
; CHECK-NEXT: local.set 1
|
|
call void @inhibit_store_to_load_forwarding()
|
|
; CHECK-NEXT: call inhibit_store_to_load_forwarding
|
|
%reloaded = load i32, %i32_cell %retval
|
|
; CHECK-NEXT: local.get 1
|
|
ret i32 %reloaded
|
|
; CHECK-NEXT: end_function
|
|
}
|
|
|
|
define i64 @ir_local_i64(i64 %arg) {
|
|
; CHECK-LABEL: ir_local_i64:
|
|
; CHECK-NEXT: .functype ir_local_i64 (i64) -> (i64)
|
|
%retval = alloca i64, addrspace(1)
|
|
; CHECK-NEXT: .local i64
|
|
store i64 %arg, %i64_cell %retval
|
|
; CHECK-NEXT: local.get 0
|
|
; CHECK-NEXT: local.set 1
|
|
call void @inhibit_store_to_load_forwarding()
|
|
; CHECK-NEXT: call inhibit_store_to_load_forwarding
|
|
%reloaded = load i64, %i64_cell %retval
|
|
; See note in ir_local_i32.
|
|
; CHECK-NEXT: local.get 1
|
|
ret i64 %reloaded
|
|
; CHECK-NEXT: end_function
|
|
}
|
|
|
|
define float @ir_local_f32(float %arg) {
|
|
; CHECK-LABEL: ir_local_f32:
|
|
; CHECK-NEXT: .functype ir_local_f32 (f32) -> (f32)
|
|
%retval = alloca float, addrspace(1)
|
|
; CHECK-NEXT: .local f32
|
|
store float %arg, %f32_cell %retval
|
|
; CHECK-NEXT: local.get 0
|
|
; CHECK-NEXT: local.set 1
|
|
call void @inhibit_store_to_load_forwarding()
|
|
; CHECK-NEXT: call inhibit_store_to_load_forwarding
|
|
%reloaded = load float, %f32_cell %retval
|
|
; CHECK-NEXT: local.get 1
|
|
; CHECK-NEXT: end_function
|
|
ret float %reloaded
|
|
}
|
|
|
|
define double @ir_local_f64(double %arg) {
|
|
; CHECK-LABEL: ir_local_f64:
|
|
; CHECK-NEXT: .functype ir_local_f64 (f64) -> (f64)
|
|
%retval = alloca double, addrspace(1)
|
|
; CHECK-NEXT: .local f64
|
|
store double %arg, %f64_cell %retval
|
|
; CHECK-NEXT: local.get 0
|
|
; CHECK-NEXT: local.set 1
|
|
call void @inhibit_store_to_load_forwarding()
|
|
; CHECK-NEXT: call inhibit_store_to_load_forwarding
|
|
%reloaded = load double, %f64_cell %retval
|
|
; CHECK-NEXT: local.get 1
|
|
; CHECK-NEXT: end_function
|
|
ret double %reloaded
|
|
}
|
|
|
|
define void @ir_unreferenced_local() {
|
|
; CHECK-LABEL: ir_unreferenced_local:
|
|
; CHECK-NEXT: .functype ir_unreferenced_local () -> ()
|
|
%unused = alloca i32, addrspace(1)
|
|
; CHECK-NEXT: .local i32
|
|
ret void
|
|
; CHECK-NEXT: end_function
|
|
}
|