summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@google.com>2016-06-02 21:34:18 +0000
committerDerek Schuff <dschuff@google.com>2016-06-02 21:34:18 +0000
commit23b7d65fe5b93bf7161b3d7ebd54eb9b1f41e291 (patch)
treecf42c2e90fb308a21127e29bd39d19d8430be137 /llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
parentb820edd58ab40a10a3c2f86fd99af97dda2ee63f (diff)
downloadbcm5719-llvm-23b7d65fe5b93bf7161b3d7ebd54eb9b1f41e291.tar.gz
bcm5719-llvm-23b7d65fe5b93bf7161b3d7ebd54eb9b1f41e291.zip
[WebAssembly] Emit type signatures for declared functions
Under emscripten, C code can take the address of a function implemented in Javascript (which is exposed via an import in wasm). Because imports do not have linear memory address in wasm, we need to generate a thunk to be the target of the indirect call; it call the import directly. To make this possible, LLVM needs to emit the type signatures for these functions, because they may not be called directly or referred to other than where the address is taken. This uses s new .s directive (.functype) which specifies the signature. Differential Revision: http://reviews.llvm.org/D20891 llvm-svn: 271599
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp')
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp41
1 files changed, 31 insertions, 10 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
index 64128bf031e..45e43f62811 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
@@ -67,6 +67,7 @@ private:
// AsmPrinter Implementation.
//===------------------------------------------------------------------===//
+ void EmitEndOfAsmFile(Module &M) override;
void EmitJumpTableInfo() override;
void EmitConstantPool() override;
void EmitFunctionBodyStart() override;
@@ -124,16 +125,6 @@ WebAssemblyTargetStreamer *WebAssemblyAsmPrinter::getTargetStreamer() {
//===----------------------------------------------------------------------===//
// WebAssemblyAsmPrinter Implementation.
//===----------------------------------------------------------------------===//
-
-void WebAssemblyAsmPrinter::EmitConstantPool() {
- assert(MF->getConstantPool()->getConstants().empty() &&
- "WebAssembly disables constant pools");
-}
-
-void WebAssemblyAsmPrinter::EmitJumpTableInfo() {
- // Nothing to do; jump tables are incorporated into the instruction stream.
-}
-
static void ComputeLegalValueVTs(const Function &F, const TargetMachine &TM,
Type *Ty, SmallVectorImpl<MVT> &ValueVTs) {
const DataLayout &DL(F.getParent()->getDataLayout());
@@ -150,6 +141,36 @@ static void ComputeLegalValueVTs(const Function &F, const TargetMachine &TM,
}
}
+void WebAssemblyAsmPrinter::EmitEndOfAsmFile(Module &M) {
+ for (const auto &F : M) {
+ // Emit function type info for all undefined functions
+ if (F.isDeclarationForLinker() && !F.isIntrinsic()) {
+ SmallVector<MVT, 4> SignatureVTs;
+ ComputeLegalValueVTs(F, TM, F.getReturnType(), SignatureVTs);
+ if (SignatureVTs.size() > 1) {
+ report_fatal_error(
+ "Import functions with nontrival return types are not supported");
+ }
+ size_t NumResults = SignatureVTs.size();
+ for (auto &Arg : F.args()) {
+ ComputeLegalValueVTs(F, TM, Arg.getType(), SignatureVTs);
+ }
+
+ getTargetStreamer()->emitIndirectFunctionType(F.getName(), SignatureVTs,
+ NumResults);
+ }
+ }
+}
+
+void WebAssemblyAsmPrinter::EmitConstantPool() {
+ assert(MF->getConstantPool()->getConstants().empty() &&
+ "WebAssembly disables constant pools");
+}
+
+void WebAssemblyAsmPrinter::EmitJumpTableInfo() {
+ // Nothing to do; jump tables are incorporated into the instruction stream.
+}
+
void WebAssemblyAsmPrinter::EmitFunctionBodyStart() {
if (!MFI->getParams().empty())
getTargetStreamer()->emitParam(MFI->getParams());
OpenPOWER on IntegriCloud