[llvm] r345917 - [WebAssembly] Added a .globaltype directive to .s output.
Wouter van Oortmerssen via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 1 17:45:01 PDT 2018
Author: aardappel
Date: Thu Nov 1 17:45:00 2018
New Revision: 345917
URL: http://llvm.org/viewvc/llvm-project?rev=345917&view=rev
Log:
[WebAssembly] Added a .globaltype directive to .s output.
Summary:
Assembly output can use globals like __stack_pointer implicitly,
but has no way of indicating the type of such a global, which makes
it hard for tools processing it (such as the MC Assembler) to
reconstruct this information.
The improved assembler directives parsing (in progress in
https://reviews.llvm.org/D53842) will make use of this information.
Also deleted code for the .import_global directive which was unused.
New test case in userstack.ll
Reviewers: dschuff, sbc100
Subscribers: jgravelle-google, aheejin, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D54012
Modified:
llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp
llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.h
llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
llvm/trunk/test/CodeGen/WebAssembly/userstack.ll
Modified: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp?rev=345917&r1=345916&r2=345917&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp Thu Nov 1 17:45:00 2018
@@ -99,8 +99,11 @@ void WebAssemblyTargetAsmStreamer::emitI
OS << '\n';
}
-void WebAssemblyTargetAsmStreamer::emitGlobalImport(StringRef name) {
- OS << "\t.import_global\t" << name << '\n';
+void WebAssemblyTargetAsmStreamer::emitGlobalType(MCSymbolWasm *Sym) {
+ OS << "\t.globaltype\t" << Sym->getName() << ", " <<
+ WebAssembly::TypeToString(
+ static_cast<wasm::ValType>(Sym->getGlobalType().Type)) <<
+ '\n';
}
void WebAssemblyTargetAsmStreamer::emitImportModule(MCSymbolWasm *Sym,
@@ -152,8 +155,8 @@ void WebAssemblyTargetWasmStreamer::emit
Symbol->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
}
-void WebAssemblyTargetWasmStreamer::emitGlobalImport(StringRef name) {
- llvm_unreachable(".global_import is not needed for direct wasm output");
+void WebAssemblyTargetWasmStreamer::emitGlobalType(MCSymbolWasm *Sym) {
+ // Not needed.
}
void WebAssemblyTargetWasmStreamer::emitImportModule(MCSymbolWasm *Sym,
Modified: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.h?rev=345917&r1=345916&r2=345917&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.h (original)
+++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.h Thu Nov 1 17:45:00 2018
@@ -43,8 +43,8 @@ public:
virtual void emitIndirectFunctionType(MCSymbolWasm *Symbol) = 0;
/// .indidx
virtual void emitIndIdx(const MCExpr *Value) = 0;
- /// .import_global
- virtual void emitGlobalImport(StringRef name) = 0;
+ /// .globaltype
+ virtual void emitGlobalType(MCSymbolWasm *Sym) = 0;
/// .import_module
virtual void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) = 0;
@@ -65,7 +65,7 @@ public:
void emitEndFunc() override;
void emitIndirectFunctionType(MCSymbolWasm *Symbol) override;
void emitIndIdx(const MCExpr *Value) override;
- void emitGlobalImport(StringRef name) override;
+ void emitGlobalType(MCSymbolWasm *Sym) override;
void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override;
};
@@ -80,7 +80,7 @@ public:
void emitEndFunc() override;
void emitIndirectFunctionType(MCSymbolWasm *Symbol) override;
void emitIndIdx(const MCExpr *Value) override;
- void emitGlobalImport(StringRef name) override;
+ void emitGlobalType(MCSymbolWasm *Sym) override;
void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override;
};
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp?rev=345917&r1=345916&r2=345917&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp Thu Nov 1 17:45:00 2018
@@ -78,6 +78,14 @@ WebAssemblyTargetStreamer *WebAssemblyAs
//===----------------------------------------------------------------------===//
void WebAssemblyAsmPrinter::EmitEndOfAsmFile(Module &M) {
+ for (auto &It : OutContext.getSymbols()) {
+ // Emit a .globaltype declaration.
+ auto Sym = cast<MCSymbolWasm>(It.getValue());
+ if (Sym->getType() == wasm::WASM_SYMBOL_TYPE_GLOBAL) {
+ getTargetStreamer()->emitGlobalType(Sym);
+ }
+ }
+
for (const auto &F : M) {
// Emit function type info for all undefined functions
if (F.isDeclarationForLinker() && !F.isIntrinsic()) {
@@ -105,6 +113,7 @@ void WebAssemblyAsmPrinter::EmitEndOfAsm
}
}
}
+
for (const auto &G : M.globals()) {
if (!G.hasInitializer() && G.hasExternalLinkage()) {
if (G.getValueType()->isSized()) {
Modified: llvm/trunk/test/CodeGen/WebAssembly/userstack.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/userstack.ll?rev=345917&r1=345916&r2=345917&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/userstack.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/userstack.ll Thu Nov 1 17:45:00 2018
@@ -330,4 +330,6 @@ define void @inline_asm() {
ret void
}
+; CHECK: .globaltype __stack_pointer, i32{{$}}
+
; TODO: test over-aligned alloca
More information about the llvm-commits
mailing list