[PATCH] D95425: Implementation of global.get/set for reftypes in LLVM IR

Paulo Matos via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 26 01:02:03 PST 2021


pmatos added a comment.

This is  very,  very WIP patch implementing LLVM IR support for `global.get/set`.

A `global.get` is represented as a load from a IR global. A `global.set` is represented as a store.

A test case looks like:

  target triple = "wasm32-unknown-unknown"
  
  %extern = type opaque
  %externref = type %extern addrspace(1)* ;; addrspace 1 is nonintegral
  
  ; %func = type void ()
  ; %funcref = type %func addrspace(1)* ;; addrspace 1 is nonintegral
  
  ; ;; Requires "P1" in the data layout string.
  ; define void @call_funcref(%funcref %ref) {
  ;   call addrspace(1) void %ref() 
  ;   ret void
  ; }
  
  ;; =========
  ;;  Globals
  ;; =========
  
  @externref_global = local_unnamed_addr addrspace(1) global %externref undef
  
  define %externref @return_externref_global() {
    ;; this generates a global.get of @externref_global
    %ref = load %externref, %externref addrspace(1)* @externref_global
    ret %externref %ref
  }
  
  define void @set_externref_global(%externref %g) {
    ;; this generates a global.set of @externref.global
    store %externref %g, %externref addrspace(1)* @externref_global
    ret void
  }

There are two new DAG Nodes: `WebAssemblyISD::GLOBAL_SET` and `WebAssemblyISD::GLOBAL_GET`. Lowering creates these nodes and tablegen pattern matches them into the proper Wasm nodes that represent the `global.set` and `global.get` instructions.

The lowering code has gone through several refactorings and `LowerStore` is currently generating the proper nodes but failing during match.

The problem is that the element to store has IR type `opaque addrspace(1) *` while during matching, tablegen expects the type to be `MVT::externref` and I was yet unsuccessful to tell LLVM to lower `opaque addrspace(1) *` to `MVT::externref`. Also, I am currently ignoring funcrefs but it will be part of the final patch, once I get through the current hurdle.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95425/new/

https://reviews.llvm.org/D95425



More information about the llvm-commits mailing list