]> granicus.if.org Git - llvm/commitdiff
[WebAssembly] Emit .import_global assembler directives
authorDerek Schuff <dschuff@google.com>
Thu, 1 Dec 2016 00:11:15 +0000 (00:11 +0000)
committerDerek Schuff <dschuff@google.com>
Thu, 1 Dec 2016 00:11:15 +0000 (00:11 +0000)
Support a new assembler directive, .import_global, to declare imported
global variables (i.e. those with external linkage and no
initializer). The linker turns these into wasm imports.

Patch by Jacob Gravelle

Differential Revision: https://reviews.llvm.org/D26875

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288296 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp
lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.h
lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
test/CodeGen/WebAssembly/globl.ll

index f088688080230683dea6857bbf0625c49dba255b..3cee8b2a184442585ba48432beb142336e6922d0 100644 (file)
@@ -80,6 +80,10 @@ void WebAssemblyTargetAsmStreamer::emitIndirectFunctionType(
   OS << '\n';
 }
 
+void WebAssemblyTargetAsmStreamer::emitGlobalImport(StringRef name) {
+  OS << "\t.import_global\t" << name << '\n';
+}
+
 void WebAssemblyTargetAsmStreamer::emitIndIdx(const MCExpr *Value) {
   OS << "\t.indidx  \t" << *Value << '\n';
 }
@@ -111,3 +115,6 @@ void WebAssemblyTargetELFStreamer::emitIndirectFunctionType(
   // Nothing to emit here. TODO: Re-design how linking works and re-evaluate
   // whether it's necessary for .o files to declare indirect function types.
 }
+
+void WebAssemblyTargetELFStreamer::emitGlobalImport(StringRef name) {
+}
\ No newline at end of file
index cf164ca592411aaeed9bc0b54279adf8f34b8c3a..23ac3190243ad126178f92b1c8c118de845fa954 100644 (file)
@@ -45,6 +45,8 @@ public:
   }
   /// .indidx
   virtual void emitIndIdx(const MCExpr *Value) = 0;
+  /// .import_global
+  virtual void emitGlobalImport(StringRef name) = 0;
 };
 
 /// This part is for ascii assembly output
@@ -62,6 +64,7 @@ public:
                                 SmallVectorImpl<MVT> &Params,
                                 SmallVectorImpl<MVT> &Results) override;
   void emitIndIdx(const MCExpr *Value) override;
+  void emitGlobalImport(StringRef name) override;
 };
 
 /// This part is for ELF object output
@@ -77,6 +80,7 @@ public:
                                 SmallVectorImpl<MVT> &Params,
                                 SmallVectorImpl<MVT> &Results) override;
   void emitIndIdx(const MCExpr *Value) override;
+  void emitGlobalImport(StringRef name) override;
 };
 
 } // end namespace llvm
index f53cfca9db33414db68d1323ae584ac94838fe07..5b4b82eb56037b97aa82ec515235abfb93a50348 100644 (file)
@@ -133,6 +133,11 @@ void WebAssemblyAsmPrinter::EmitEndOfAsmFile(Module &M) {
                                                     Results);
     }
   }
+  for (const auto &G : M.globals()) {
+    if (!G.hasInitializer() && G.hasExternalLinkage()) {
+      getTargetStreamer()->emitGlobalImport(G.getGlobalIdentifier());
+    }
+  }
 }
 
 void WebAssemblyAsmPrinter::EmitConstantPool() {
index 91d3ade4666b4e1c5f83de3a29534aae0137effc..3ebd3d88fb4e717df2f7ab82eca34f12986658d2 100644 (file)
@@ -8,3 +8,7 @@ target triple = "wasm32-unknown-unknown"
 define void @foo() {
   ret void
 }
+
+; Check import directives - must be at the end of the file
+; CHECK: .import_global bar{{$}}
+@bar = external global i32