[PATCH] D12393: WebAssembly: generate global loads

JF Bastien via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 18:13:17 PDT 2015


jfb created this revision.
jfb added a reviewer: sunfish.
jfb added a subscriber: llvm-commits.
Herald added subscribers: dschuff, jfb.

I'll add global store as a follow-up.

Note that WebAssembly globals *must* be address not-taken, which allows for some magical optimizations by the in-browser JIT. The LLVM backend will need to linearize all address-taken globals into a heap, and GEP into that special global (and that'll need appending linkage when mashing object files together). This will be done later.

http://reviews.llvm.org/D12393

Files:
  lib/Target/WebAssembly/WebAssemblyISD.def
  lib/Target/WebAssembly/WebAssemblyInstrMemory.td
  test/CodeGen/WebAssembly/global-load.ll

Index: test/CodeGen/WebAssembly/global-load.ll
===================================================================
--- /dev/null
+++ test/CodeGen/WebAssembly/global-load.ll
@@ -0,0 +1,19 @@
+; RUN: llc < %s -asm-verbose=false | FileCheck %s
+
+; Test that global loads assemble as expected.
+
+target datalayout = "e-p:32:32-i64:64-v128:8:128-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+ at life = private global i32 42;
+
+define i32 @answer() {
+; CHECK-LABEL: (func $answer
+; CHECK-NEXT: (result i32)
+; CHECK-NEXT: (setlocal @0 (loadglobal $life))
+; CHECK-NEXT: (return @0)
+  %universe = load i32, i32* @life
+  ret i32 %universe
+}
+
+; CHECK: (global $life i32 42)
Index: lib/Target/WebAssembly/WebAssemblyInstrMemory.td
===================================================================
--- lib/Target/WebAssembly/WebAssemblyInstrMemory.td
+++ lib/Target/WebAssembly/WebAssemblyInstrMemory.td
@@ -45,6 +45,14 @@
  * store_global: store a given value to a given global variable
  */
 
+def WebAssemblyLOADGLOBAL : SDNode<"WebAssemblyISD::LOADGLOBAL", SDTIntUnaryOp>;
+let mayLoad = 1 in
+def LOADGLOBAL : I<(outs Int32:$dst), (ins global:$addr),
+                   [(set Int32:$dst,
+                    (WebAssemblyLOADGLOBAL tglobaladdr:$addr))]>;
+def : Pat<(load (WebAssemblywrapper tglobaladdr:$addr)),
+          (LOADGLOBAL tglobaladdr:$addr)>;
+
 def page_size_I32 : I<(outs Int32:$dst), (ins),
                       [(set Int32:$dst, (int_wasm_page_size))]>,
                     Requires<[HasAddr32]>;
Index: lib/Target/WebAssembly/WebAssemblyISD.def
===================================================================
--- lib/Target/WebAssembly/WebAssemblyISD.def
+++ lib/Target/WebAssembly/WebAssemblyISD.def
@@ -17,6 +17,7 @@
 HANDLE_NODETYPE(CALL)
 HANDLE_NODETYPE(RETURN)
 HANDLE_NODETYPE(ARGUMENT)
+HANDLE_NODETYPE(LOADGLOBAL)
 HANDLE_NODETYPE(Wrapper)
 
 // add memory opcodes starting at ISD::FIRST_TARGET_MEMORY_OPCODE here...


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12393.33292.patch
Type: text/x-patch
Size: 1969 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150827/849228ec/attachment.bin>


More information about the llvm-commits mailing list