Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Commit

Permalink
[WebAssembly] Initial WebAssembly backend
Browse files Browse the repository at this point in the history
This WebAssembly backend is just a skeleton at this time and is not yet
functional.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241022 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Dan Gohman committed Jun 29, 2015
1 parent 3adaf02 commit 685ec0e
Show file tree
Hide file tree
Showing 56 changed files with 1,913 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CODE_OWNERS.TXT
Expand Up @@ -65,6 +65,10 @@ N: Hal Finkel
E: hfinkel@anl.gov
D: BBVectorize, the loop reroller, alias analysis and the PowerPC target

N: Dan Gohman
E: sunfish@mozilla.com
D: WebAssembly Backend (lib/Target/WebAssembly/*)

N: Renato Golin
E: renato.golin@linaro.org
D: ARM Linux support
Expand Down
3 changes: 2 additions & 1 deletion CREDITS.TXT
Expand Up @@ -152,8 +152,9 @@ E: foldr@codedgers.com
D: Author of llvmc2

N: Dan Gohman
E: dan433584@gmail.com
E: sunfish@mozilla.com
D: Miscellaneous bug fixes
D: WebAssembly Backend

N: David Goodwin
E: david@goodwinz.net
Expand Down
7 changes: 6 additions & 1 deletion autoconf/configure.ac
Expand Up @@ -445,6 +445,7 @@ AC_CACHE_CHECK([target architecture],[llvm_cv_target_arch],
hexagon-*) llvm_cv_target_arch="Hexagon" ;;
nvptx-*) llvm_cv_target_arch="NVPTX" ;;
s390x-*) llvm_cv_target_arch="SystemZ" ;;
wasm*-*) llvm_cv_target_arch="WebAssembly" ;;
*) llvm_cv_target_arch="Unknown" ;;
esac])

Expand Down Expand Up @@ -480,6 +481,7 @@ case $host in
msp430-*) host_arch="MSP430" ;;
hexagon-*) host_arch="Hexagon" ;;
s390x-*) host_arch="SystemZ" ;;
wasm*-*) host_arch="WebAssembly" ;;
*) host_arch="Unknown" ;;
esac

Expand Down Expand Up @@ -812,6 +814,7 @@ else
Hexagon) AC_SUBST(TARGET_HAS_JIT,0) ;;
NVPTX) AC_SUBST(TARGET_HAS_JIT,0) ;;
SystemZ) AC_SUBST(TARGET_HAS_JIT,1) ;;
WebAssembly) AC_SUBST(TARGET_HAS_JIT,0) ;;
*) AC_SUBST(TARGET_HAS_JIT,0) ;;
esac
fi
Expand Down Expand Up @@ -1105,7 +1108,7 @@ TARGETS_TO_BUILD=""
AC_ARG_ENABLE([targets],AS_HELP_STRING([--enable-targets],
[Build specific host targets: all or target1,target2,... Valid targets are:
host, x86, x86_64, sparc, powerpc, arm64, arm, aarch64, mips, hexagon,
xcore, msp430, nvptx, systemz, r600, bpf, and cpp (default=all)]),,
xcore, msp430, nvptx, systemz, r600, bpf, wasm, and cpp (default=all)]),,
enableval=all)
if test "$enableval" = host-only ; then
enableval=host
Expand Down Expand Up @@ -1134,6 +1137,7 @@ case "$enableval" in
systemz) TARGETS_TO_BUILD="SystemZ $TARGETS_TO_BUILD" ;;
amdgpu) TARGETS_TO_BUILD="AMDGPU $TARGETS_TO_BUILD" ;;
r600) TARGETS_TO_BUILD="AMDGPU $TARGETS_TO_BUILD" ;;
wasm) TARGETS_TO_BUILD="WebAssembly $TARGETS_TO_BUILD" ;;
host) case "$llvm_cv_target_arch" in
x86) TARGETS_TO_BUILD="X86 $TARGETS_TO_BUILD" ;;
x86_64) TARGETS_TO_BUILD="X86 $TARGETS_TO_BUILD" ;;
Expand All @@ -1147,6 +1151,7 @@ case "$enableval" in
Hexagon) TARGETS_TO_BUILD="Hexagon $TARGETS_TO_BUILD" ;;
NVPTX) TARGETS_TO_BUILD="NVPTX $TARGETS_TO_BUILD" ;;
SystemZ) TARGETS_TO_BUILD="SystemZ $TARGETS_TO_BUILD" ;;
WebAssembly) TARGETS_TO_BUILD="WebAssembly $TARGETS_TO_BUILD" ;;
*) AC_MSG_ERROR([Can not set target to build]) ;;
esac ;;
*) AC_MSG_ERROR([Unrecognized target $a_target]) ;;
Expand Down
4 changes: 4 additions & 0 deletions cmake/config-ix.cmake
Expand Up @@ -358,6 +358,10 @@ elseif (LLVM_NATIVE_ARCH MATCHES "hexagon")
set(LLVM_NATIVE_ARCH Hexagon)
elseif (LLVM_NATIVE_ARCH MATCHES "s390x")
set(LLVM_NATIVE_ARCH SystemZ)
elseif (LLVM_NATIVE_ARCH MATCHES "wasm32")
set(LLVM_NATIVE_ARCH WebAssembly)
elseif (LLVM_NATIVE_ARCH MATCHES "wasm64")
set(LLVM_NATIVE_ARCH WebAssembly)
else ()
message(FATAL_ERROR "Unknown architecture ${LLVM_NATIVE_ARCH}")
endif ()
Expand Down
8 changes: 7 additions & 1 deletion configure
Expand Up @@ -1463,7 +1463,7 @@ Optional Features:
target1,target2,... Valid targets are: host, x86,
x86_64, sparc, powerpc, arm64, arm, aarch64, mips,
hexagon, xcore, msp430, nvptx, systemz, r600, bpf,
and cpp (default=all)
wasm, and cpp (default=all)
--enable-experimental-targets
Build experimental host targets: disable or
target1,target2,... (default=disable)
Expand Down Expand Up @@ -4207,6 +4207,7 @@ else
hexagon-*) llvm_cv_target_arch="Hexagon" ;;
nvptx-*) llvm_cv_target_arch="NVPTX" ;;
s390x-*) llvm_cv_target_arch="SystemZ" ;;
wasm*-*) llvm_cv_target_arch="WebAssembly" ;;
*) llvm_cv_target_arch="Unknown" ;;
esac
fi
Expand Down Expand Up @@ -4243,6 +4244,7 @@ case $host in
msp430-*) host_arch="MSP430" ;;
hexagon-*) host_arch="Hexagon" ;;
s390x-*) host_arch="SystemZ" ;;
wasm*-*) host_arch="WebAssembly" ;;
*) host_arch="Unknown" ;;
esac

Expand Down Expand Up @@ -5169,6 +5171,8 @@ else
NVPTX) TARGET_HAS_JIT=0
;;
SystemZ) TARGET_HAS_JIT=1
;;
WebAssembly) TARGET_HAS_JIT=0
;;
*) TARGET_HAS_JIT=0
;;
Expand Down Expand Up @@ -5667,6 +5671,7 @@ case "$enableval" in
systemz) TARGETS_TO_BUILD="SystemZ $TARGETS_TO_BUILD" ;;
amdgpu) TARGETS_TO_BUILD="AMDGPU $TARGETS_TO_BUILD" ;;
r600) TARGETS_TO_BUILD="AMDGPU $TARGETS_TO_BUILD" ;;
wasm) TARGETS_TO_BUILD="WebAssembly $TARGETS_TO_BUILD" ;;
host) case "$llvm_cv_target_arch" in
x86) TARGETS_TO_BUILD="X86 $TARGETS_TO_BUILD" ;;
x86_64) TARGETS_TO_BUILD="X86 $TARGETS_TO_BUILD" ;;
Expand All @@ -5680,6 +5685,7 @@ case "$enableval" in
Hexagon) TARGETS_TO_BUILD="Hexagon $TARGETS_TO_BUILD" ;;
NVPTX) TARGETS_TO_BUILD="NVPTX $TARGETS_TO_BUILD" ;;
SystemZ) TARGETS_TO_BUILD="SystemZ $TARGETS_TO_BUILD" ;;
WebAssembly) TARGETS_TO_BUILD="WebAssembly $TARGETS_TO_BUILD" ;;
*) { { echo "$as_me:$LINENO: error: Can not set target to build" >&5
echo "$as_me: error: Can not set target to build" >&2;}
{ (exit 1); exit 1; }; } ;;
Expand Down
5 changes: 4 additions & 1 deletion include/llvm/ADT/Triple.h
Expand Up @@ -85,6 +85,8 @@ class Triple {
spir64, // SPIR: standard portable IR for OpenCL 64-bit version
kalimba, // Kalimba: generic kalimba
shave, // SHAVE: Movidius vector VLIW processors
wasm32, // WebAssembly with 32-bit pointers
wasm64, // WebAssembly with 64-bit pointers
LastArchType = shave
};
enum SubArchType {
Expand Down Expand Up @@ -151,7 +153,8 @@ class Triple {
NVCL, // NVIDIA OpenCL
AMDHSA, // AMD HSA Runtime
PS4,
LastOSType = PS4
WebAssembly,
LastOSType = WebAssembly
};
enum EnvironmentType {
UnknownEnvironment,
Expand Down
16 changes: 16 additions & 0 deletions lib/Support/Triple.cpp
Expand Up @@ -60,6 +60,8 @@ const char *Triple::getArchTypeName(ArchType Kind) {
case spir64: return "spir64";
case kalimba: return "kalimba";
case shave: return "shave";
case wasm32: return "wasm32";
case wasm64: return "wasm64";
}

llvm_unreachable("Invalid ArchType!");
Expand Down Expand Up @@ -122,6 +124,8 @@ const char *Triple::getArchTypePrefix(ArchType Kind) {
case spir64: return "spir";
case kalimba: return "kalimba";
case shave: return "shave";
case wasm32: return "wasm32";
case wasm64: return "wasm64";
}
}

Expand Down Expand Up @@ -173,6 +177,7 @@ const char *Triple::getOSTypeName(OSType Kind) {
case NVCL: return "nvcl";
case AMDHSA: return "amdhsa";
case PS4: return "ps4";
case WebAssembly: return "wasm";
}

llvm_unreachable("Invalid OSType");
Expand Down Expand Up @@ -255,6 +260,8 @@ Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
.Case("spir64", spir64)
.Case("kalimba", kalimba)
.Case("shave", shave)
.Case("wasm32", wasm32)
.Case("wasm64", wasm64)
.Default(UnknownArch);
}

Expand Down Expand Up @@ -360,6 +367,8 @@ static Triple::ArchType parseArch(StringRef ArchName) {
.Case("spir64", Triple::spir64)
.StartsWith("kalimba", Triple::kalimba)
.Case("shave", Triple::shave)
.Case("wasm32", Triple::wasm32)
.Case("wasm64", Triple::wasm64)
.Default(Triple::UnknownArch);
}

Expand Down Expand Up @@ -406,6 +415,7 @@ static Triple::OSType parseOS(StringRef OSName) {
.StartsWith("nvcl", Triple::NVCL)
.StartsWith("amdhsa", Triple::AMDHSA)
.StartsWith("ps4", Triple::PS4)
.StartsWith("wasm", Triple::WebAssembly)
.Default(Triple::UnknownOS);
}

Expand Down Expand Up @@ -1009,6 +1019,7 @@ static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
case llvm::Triple::spir:
case llvm::Triple::kalimba:
case llvm::Triple::shave:
case llvm::Triple::wasm32:
return 32;

case llvm::Triple::aarch64:
Expand All @@ -1028,6 +1039,7 @@ static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
case llvm::Triple::amdil64:
case llvm::Triple::hsail64:
case llvm::Triple::spir64:
case llvm::Triple::wasm64:
return 64;
}
llvm_unreachable("Invalid architecture value");
Expand Down Expand Up @@ -1081,6 +1093,7 @@ Triple Triple::get32BitArchVariant() const {
case Triple::x86:
case Triple::xcore:
case Triple::shave:
case Triple::wasm32:
// Already 32-bit.
break;

Expand All @@ -1094,6 +1107,7 @@ Triple Triple::get32BitArchVariant() const {
case Triple::amdil64: T.setArch(Triple::amdil); break;
case Triple::hsail64: T.setArch(Triple::hsail); break;
case Triple::spir64: T.setArch(Triple::spir); break;
case Triple::wasm64: T.setArch(Triple::wasm32); break;
}
return T;
}
Expand Down Expand Up @@ -1134,6 +1148,7 @@ Triple Triple::get64BitArchVariant() const {
case Triple::sparcv9:
case Triple::systemz:
case Triple::x86_64:
case Triple::wasm64:
// Already 64-bit.
break;

Expand All @@ -1147,6 +1162,7 @@ Triple Triple::get64BitArchVariant() const {
case Triple::amdil: T.setArch(Triple::amdil64); break;
case Triple::hsail: T.setArch(Triple::hsail64); break;
case Triple::spir: T.setArch(Triple::spir64); break;
case Triple::wasm32: T.setArch(Triple::wasm64); break;
}
return T;
}
Expand Down
1 change: 1 addition & 0 deletions lib/Target/LLVMBuild.txt
Expand Up @@ -31,6 +31,7 @@ subdirectories =
PowerPC
Sparc
SystemZ
WebAssembly
X86
XCore

Expand Down
24 changes: 24 additions & 0 deletions lib/Target/WebAssembly/CMakeLists.txt
@@ -0,0 +1,24 @@
set(LLVM_TARGET_DEFINITIONS WebAssembly.td)

tablegen(LLVM WebAssemblyGenMCCodeEmitter.inc -gen-emitter)
tablegen(LLVM WebAssemblyGenSubtargetInfo.inc -gen-subtarget)
add_public_tablegen_target(WebAssemblyCommonTableGen)

add_llvm_target(WebAssemblyCodeGen
WebAssemblyFrameLowering.cpp
WebAssemblyInstrInfo.cpp
WebAssemblyISelDAGToDAG.cpp
WebAssemblyISelLowering.cpp
WebAssemblyMachineFunctionInfo.cpp
WebAssemblyRegisterInfo.cpp
WebAssemblySelectionDAGInfo.cpp
WebAssemblySubtarget.cpp
WebAssemblyTargetMachine.cpp
WebAssemblyTargetTransformInfo.cpp
)

add_dependencies(LLVMWebAssemblyCodeGen intrinsics_gen)

add_subdirectory(InstPrinter)
add_subdirectory(TargetInfo)
add_subdirectory(MCTargetDesc)
3 changes: 3 additions & 0 deletions lib/Target/WebAssembly/InstPrinter/CMakeLists.txt
@@ -0,0 +1,3 @@
add_llvm_library(LLVMWebAssemblyAsmPrinter
WebAssemblyInstPrinter.cpp
)
23 changes: 23 additions & 0 deletions lib/Target/WebAssembly/InstPrinter/LLVMBuild.txt
@@ -0,0 +1,23 @@
;===- ./lib/Target/WebAssembly/InstPrinter/LLVMBuild.txt -------*- Conf -*--===;
;
; The LLVM Compiler Infrastructure
;
; This file is distributed under the University of Illinois Open Source
; License. See LICENSE.TXT for details.
;
;===------------------------------------------------------------------------===;
;
; This is an LLVMBuild description file for the components in this subdirectory.
;
; For more information on the LLVMBuild system, please see:
;
; http://llvm.org/docs/LLVMBuild.html
;
;===------------------------------------------------------------------------===;

[component_0]
type = Library
name = WebAssemblyAsmPrinter
parent = WebAssembly
required_libraries = MC Support
add_to_library_groups = WebAssembly
16 changes: 16 additions & 0 deletions lib/Target/WebAssembly/InstPrinter/Makefile
@@ -0,0 +1,16 @@
##===- lib/Target/WebAssembly/AsmPrinter/Makefile ----------*- Makefile -*-===##
#
# The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#
##===----------------------------------------------------------------------===##

LEVEL = ../../../..
LIBRARYNAME = LLVMWebAssemblyAsmPrinter

# Hack: we need to include 'main' wasm target directory to grab private headers
CPP.Flags += -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/..

include $(LEVEL)/Makefile.common
43 changes: 43 additions & 0 deletions lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp
@@ -0,0 +1,43 @@
//=- WebAssemblyInstPrinter.cpp - WebAssembly assembly instruction printing -=//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief Print MCInst instructions to wasm format.
///
//===----------------------------------------------------------------------===//

#include "InstPrinter/WebAssemblyInstPrinter.h"
#include "WebAssembly.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormattedStream.h"
#include <cctype>
using namespace llvm;

#define DEBUG_TYPE "asm-printer"

WebAssemblyInstPrinter::WebAssemblyInstPrinter(const MCAsmInfo &MAI,
const MCInstrInfo &MII,
const MCRegisterInfo &MRI)
: MCInstPrinter(MAI, MII, MRI) {}

void WebAssemblyInstPrinter::printRegName(raw_ostream &OS,
unsigned RegNo) const {
llvm_unreachable("TODO: implement printRegName");
}

void WebAssemblyInstPrinter::printInst(const MCInst *MI, raw_ostream &OS,
StringRef Annot,
const MCSubtargetInfo &STI) {
llvm_unreachable("TODO: implement printInst");
}

0 comments on commit 685ec0e

Please sign in to comment.