llvm.org GIT mirror llvm / a743413
[WebAssembly] Initial WebAssembly backend 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 Dan Gohman 4 years ago
56 changed file(s) with 1914 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
6363 N: Hal Finkel
6464 E: hfinkel@anl.gov
6565 D: BBVectorize, the loop reroller, alias analysis and the PowerPC target
66
67 N: Dan Gohman
68 E: sunfish@mozilla.com
69 D: WebAssembly Backend (lib/Target/WebAssembly/*)
6670
6771 N: Renato Golin
6872 E: renato.golin@linaro.org
151151 D: Author of llvmc2
152152
153153 N: Dan Gohman
154 E: dan433584@gmail.com
155 D: Miscellaneous bug fixes
154 E: sunfish@mozilla.com
155 D: Miscellaneous bug fixes
156 D: WebAssembly Backend
156157
157158 N: David Goodwin
158159 E: david@goodwinz.net
444444 hexagon-*) llvm_cv_target_arch="Hexagon" ;;
445445 nvptx-*) llvm_cv_target_arch="NVPTX" ;;
446446 s390x-*) llvm_cv_target_arch="SystemZ" ;;
447 wasm*-*) llvm_cv_target_arch="WebAssembly" ;;
447448 *) llvm_cv_target_arch="Unknown" ;;
448449 esac])
449450
479480 msp430-*) host_arch="MSP430" ;;
480481 hexagon-*) host_arch="Hexagon" ;;
481482 s390x-*) host_arch="SystemZ" ;;
483 wasm*-*) host_arch="WebAssembly" ;;
482484 *) host_arch="Unknown" ;;
483485 esac
484486
811813 Hexagon) AC_SUBST(TARGET_HAS_JIT,0) ;;
812814 NVPTX) AC_SUBST(TARGET_HAS_JIT,0) ;;
813815 SystemZ) AC_SUBST(TARGET_HAS_JIT,1) ;;
816 WebAssembly) AC_SUBST(TARGET_HAS_JIT,0) ;;
814817 *) AC_SUBST(TARGET_HAS_JIT,0) ;;
815818 esac
816819 fi
11041107 AC_ARG_ENABLE([targets],AS_HELP_STRING([--enable-targets],
11051108 [Build specific host targets: all or target1,target2,... Valid targets are:
11061109 host, x86, x86_64, sparc, powerpc, arm64, arm, aarch64, mips, hexagon,
1107 xcore, msp430, nvptx, systemz, r600, bpf, and cpp (default=all)]),,
1110 xcore, msp430, nvptx, systemz, r600, bpf, wasm, and cpp (default=all)]),,
11081111 enableval=all)
11091112 if test "$enableval" = host-only ; then
11101113 enableval=host
11331136 systemz) TARGETS_TO_BUILD="SystemZ $TARGETS_TO_BUILD" ;;
11341137 amdgpu) TARGETS_TO_BUILD="AMDGPU $TARGETS_TO_BUILD" ;;
11351138 r600) TARGETS_TO_BUILD="AMDGPU $TARGETS_TO_BUILD" ;;
1139 wasm) TARGETS_TO_BUILD="WebAssembly $TARGETS_TO_BUILD" ;;
11361140 host) case "$llvm_cv_target_arch" in
11371141 x86) TARGETS_TO_BUILD="X86 $TARGETS_TO_BUILD" ;;
11381142 x86_64) TARGETS_TO_BUILD="X86 $TARGETS_TO_BUILD" ;;
11461150 Hexagon) TARGETS_TO_BUILD="Hexagon $TARGETS_TO_BUILD" ;;
11471151 NVPTX) TARGETS_TO_BUILD="NVPTX $TARGETS_TO_BUILD" ;;
11481152 SystemZ) TARGETS_TO_BUILD="SystemZ $TARGETS_TO_BUILD" ;;
1153 WebAssembly) TARGETS_TO_BUILD="WebAssembly $TARGETS_TO_BUILD" ;;
11491154 *) AC_MSG_ERROR([Can not set target to build]) ;;
11501155 esac ;;
11511156 *) AC_MSG_ERROR([Unrecognized target $a_target]) ;;
357357 set(LLVM_NATIVE_ARCH Hexagon)
358358 elseif (LLVM_NATIVE_ARCH MATCHES "s390x")
359359 set(LLVM_NATIVE_ARCH SystemZ)
360 elseif (LLVM_NATIVE_ARCH MATCHES "wasm32")
361 set(LLVM_NATIVE_ARCH WebAssembly)
362 elseif (LLVM_NATIVE_ARCH MATCHES "wasm64")
363 set(LLVM_NATIVE_ARCH WebAssembly)
360364 else ()
361365 message(FATAL_ERROR "Unknown architecture ${LLVM_NATIVE_ARCH}")
362366 endif ()
14621462 target1,target2,... Valid targets are: host, x86,
14631463 x86_64, sparc, powerpc, arm64, arm, aarch64, mips,
14641464 hexagon, xcore, msp430, nvptx, systemz, r600, bpf,
1465 and cpp (default=all)
1465 wasm, and cpp (default=all)
14661466 --enable-experimental-targets
14671467 Build experimental host targets: disable or
14681468 target1,target2,... (default=disable)
42064206 hexagon-*) llvm_cv_target_arch="Hexagon" ;;
42074207 nvptx-*) llvm_cv_target_arch="NVPTX" ;;
42084208 s390x-*) llvm_cv_target_arch="SystemZ" ;;
4209 wasm*-*) llvm_cv_target_arch="WebAssembly" ;;
42094210 *) llvm_cv_target_arch="Unknown" ;;
42104211 esac
42114212 fi
42424243 msp430-*) host_arch="MSP430" ;;
42434244 hexagon-*) host_arch="Hexagon" ;;
42444245 s390x-*) host_arch="SystemZ" ;;
4246 wasm*-*) host_arch="WebAssembly" ;;
42454247 *) host_arch="Unknown" ;;
42464248 esac
42474249
51685170 NVPTX) TARGET_HAS_JIT=0
51695171 ;;
51705172 SystemZ) TARGET_HAS_JIT=1
5173 ;;
5174 WebAssembly) TARGET_HAS_JIT=0
51715175 ;;
51725176 *) TARGET_HAS_JIT=0
51735177 ;;
56665670 systemz) TARGETS_TO_BUILD="SystemZ $TARGETS_TO_BUILD" ;;
56675671 amdgpu) TARGETS_TO_BUILD="AMDGPU $TARGETS_TO_BUILD" ;;
56685672 r600) TARGETS_TO_BUILD="AMDGPU $TARGETS_TO_BUILD" ;;
5673 wasm) TARGETS_TO_BUILD="WebAssembly $TARGETS_TO_BUILD" ;;
56695674 host) case "$llvm_cv_target_arch" in
56705675 x86) TARGETS_TO_BUILD="X86 $TARGETS_TO_BUILD" ;;
56715676 x86_64) TARGETS_TO_BUILD="X86 $TARGETS_TO_BUILD" ;;
56795684 Hexagon) TARGETS_TO_BUILD="Hexagon $TARGETS_TO_BUILD" ;;
56805685 NVPTX) TARGETS_TO_BUILD="NVPTX $TARGETS_TO_BUILD" ;;
56815686 SystemZ) TARGETS_TO_BUILD="SystemZ $TARGETS_TO_BUILD" ;;
5687 WebAssembly) TARGETS_TO_BUILD="WebAssembly $TARGETS_TO_BUILD" ;;
56825688 *) { { echo "$as_me:$LINENO: error: Can not set target to build" >&5
56835689 echo "$as_me: error: Can not set target to build" >&2;}
56845690 { (exit 1); exit 1; }; } ;;
8484 spir64, // SPIR: standard portable IR for OpenCL 64-bit version
8585 kalimba, // Kalimba: generic kalimba
8686 shave, // SHAVE: Movidius vector VLIW processors
87 wasm32, // WebAssembly with 32-bit pointers
88 wasm64, // WebAssembly with 64-bit pointers
8789 LastArchType = shave
8890 };
8991 enum SubArchType {
150152 NVCL, // NVIDIA OpenCL
151153 AMDHSA, // AMD HSA Runtime
152154 PS4,
153 LastOSType = PS4
155 WebAssembly,
156 LastOSType = WebAssembly
154157 };
155158 enum EnvironmentType {
156159 UnknownEnvironment,
5959 case spir64: return "spir64";
6060 case kalimba: return "kalimba";
6161 case shave: return "shave";
62 case wasm32: return "wasm32";
63 case wasm64: return "wasm64";
6264 }
6365
6466 llvm_unreachable("Invalid ArchType!");
121123 case spir64: return "spir";
122124 case kalimba: return "kalimba";
123125 case shave: return "shave";
126 case wasm32: return "wasm32";
127 case wasm64: return "wasm64";
124128 }
125129 }
126130
172176 case NVCL: return "nvcl";
173177 case AMDHSA: return "amdhsa";
174178 case PS4: return "ps4";
179 case WebAssembly: return "wasm";
175180 }
176181
177182 llvm_unreachable("Invalid OSType");
254259 .Case("spir64", spir64)
255260 .Case("kalimba", kalimba)
256261 .Case("shave", shave)
262 .Case("wasm32", wasm32)
263 .Case("wasm64", wasm64)
257264 .Default(UnknownArch);
258265 }
259266
359366 .Case("spir64", Triple::spir64)
360367 .StartsWith("kalimba", Triple::kalimba)
361368 .Case("shave", Triple::shave)
369 .Case("wasm32", Triple::wasm32)
370 .Case("wasm64", Triple::wasm64)
362371 .Default(Triple::UnknownArch);
363372 }
364373
405414 .StartsWith("nvcl", Triple::NVCL)
406415 .StartsWith("amdhsa", Triple::AMDHSA)
407416 .StartsWith("ps4", Triple::PS4)
417 .StartsWith("wasm", Triple::WebAssembly)
408418 .Default(Triple::UnknownOS);
409419 }
410420
10081018 case llvm::Triple::spir:
10091019 case llvm::Triple::kalimba:
10101020 case llvm::Triple::shave:
1021 case llvm::Triple::wasm32:
10111022 return 32;
10121023
10131024 case llvm::Triple::aarch64:
10271038 case llvm::Triple::amdil64:
10281039 case llvm::Triple::hsail64:
10291040 case llvm::Triple::spir64:
1041 case llvm::Triple::wasm64:
10301042 return 64;
10311043 }
10321044 llvm_unreachable("Invalid architecture value");
10801092 case Triple::x86:
10811093 case Triple::xcore:
10821094 case Triple::shave:
1095 case Triple::wasm32:
10831096 // Already 32-bit.
10841097 break;
10851098
10931106 case Triple::amdil64: T.setArch(Triple::amdil); break;
10941107 case Triple::hsail64: T.setArch(Triple::hsail); break;
10951108 case Triple::spir64: T.setArch(Triple::spir); break;
1109 case Triple::wasm64: T.setArch(Triple::wasm32); break;
10961110 }
10971111 return T;
10981112 }
11331147 case Triple::sparcv9:
11341148 case Triple::systemz:
11351149 case Triple::x86_64:
1150 case Triple::wasm64:
11361151 // Already 64-bit.
11371152 break;
11381153
11461161 case Triple::amdil: T.setArch(Triple::amdil64); break;
11471162 case Triple::hsail: T.setArch(Triple::hsail64); break;
11481163 case Triple::spir: T.setArch(Triple::spir64); break;
1164 case Triple::wasm32: T.setArch(Triple::wasm64); break;
11491165 }
11501166 return T;
11511167 }
3030 PowerPC
3131 Sparc
3232 SystemZ
33 WebAssembly
3334 X86
3435 XCore
3536
0 set(LLVM_TARGET_DEFINITIONS WebAssembly.td)
1
2 tablegen(LLVM WebAssemblyGenMCCodeEmitter.inc -gen-emitter)
3 tablegen(LLVM WebAssemblyGenSubtargetInfo.inc -gen-subtarget)
4 add_public_tablegen_target(WebAssemblyCommonTableGen)
5
6 add_llvm_target(WebAssemblyCodeGen
7 WebAssemblyFrameLowering.cpp
8 WebAssemblyInstrInfo.cpp
9 WebAssemblyISelDAGToDAG.cpp
10 WebAssemblyISelLowering.cpp
11 WebAssemblyMachineFunctionInfo.cpp
12 WebAssemblyRegisterInfo.cpp
13 WebAssemblySelectionDAGInfo.cpp
14 WebAssemblySubtarget.cpp
15 WebAssemblyTargetMachine.cpp
16 WebAssemblyTargetTransformInfo.cpp
17 )
18
19 add_dependencies(LLVMWebAssemblyCodeGen intrinsics_gen)
20
21 add_subdirectory(InstPrinter)
22 add_subdirectory(TargetInfo)
23 add_subdirectory(MCTargetDesc)
0 add_llvm_library(LLVMWebAssemblyAsmPrinter
1 WebAssemblyInstPrinter.cpp
2 )
0 ;===- ./lib/Target/WebAssembly/InstPrinter/LLVMBuild.txt -------*- Conf -*--===;
1 ;
2 ; The LLVM Compiler Infrastructure
3 ;
4 ; This file is distributed under the University of Illinois Open Source
5 ; License. See LICENSE.TXT for details.
6 ;
7 ;===------------------------------------------------------------------------===;
8 ;
9 ; This is an LLVMBuild description file for the components in this subdirectory.
10 ;
11 ; For more information on the LLVMBuild system, please see:
12 ;
13 ; http://llvm.org/docs/LLVMBuild.html
14 ;
15 ;===------------------------------------------------------------------------===;
16
17 [component_0]
18 type = Library
19 name = WebAssemblyAsmPrinter
20 parent = WebAssembly
21 required_libraries = MC Support
22 add_to_library_groups = WebAssembly
0 ##===- lib/Target/WebAssembly/AsmPrinter/Makefile ----------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../../../..
10 LIBRARYNAME = LLVMWebAssemblyAsmPrinter
11
12 # Hack: we need to include 'main' wasm target directory to grab private headers
13 CPP.Flags += -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/..
14
15 include $(LEVEL)/Makefile.common
0 //=- WebAssemblyInstPrinter.cpp - WebAssembly assembly instruction printing -=//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief Print MCInst instructions to wasm format.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #include "InstPrinter/WebAssemblyInstPrinter.h"
15 #include "WebAssembly.h"
16 #include "llvm/MC/MCExpr.h"
17 #include "llvm/MC/MCInst.h"
18 #include "llvm/MC/MCInstrInfo.h"
19 #include "llvm/MC/MCSubtargetInfo.h"
20 #include "llvm/MC/MCSymbol.h"
21 #include "llvm/Support/ErrorHandling.h"
22 #include "llvm/Support/FormattedStream.h"
23 #include
24 using namespace llvm;
25
26 #define DEBUG_TYPE "asm-printer"
27
28 WebAssemblyInstPrinter::WebAssemblyInstPrinter(const MCAsmInfo &MAI,
29 const MCInstrInfo &MII,
30 const MCRegisterInfo &MRI)
31 : MCInstPrinter(MAI, MII, MRI) {}
32
33 void WebAssemblyInstPrinter::printRegName(raw_ostream &OS,
34 unsigned RegNo) const {
35 llvm_unreachable("TODO: implement printRegName");
36 }
37
38 void WebAssemblyInstPrinter::printInst(const MCInst *MI, raw_ostream &OS,
39 StringRef Annot,
40 const MCSubtargetInfo &STI) {
41 llvm_unreachable("TODO: implement printInst");
42 }
0 // WebAssemblyInstPrinter.h - Print wasm MCInst to assembly syntax -*- C++ -*-//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This class prints an WebAssembly MCInst to wasm file syntax.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_INSTPRINTER_WEBASSEMBLYINSTPRINTER_H
15 #define LLVM_LIB_TARGET_WEBASSEMBLY_INSTPRINTER_WEBASSEMBLYINSTPRINTER_H
16
17 #include "llvm/MC/MCInstPrinter.h"
18 #include "llvm/Support/raw_ostream.h"
19
20 namespace llvm {
21
22 class MCOperand;
23 class MCSubtargetInfo;
24
25 class WebAssemblyInstPrinter : public MCInstPrinter {
26 public:
27 WebAssemblyInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
28 const MCRegisterInfo &MRI);
29
30 void printRegName(raw_ostream &OS, unsigned RegNo) const override;
31 void printInst(const MCInst *MI, raw_ostream &OS, StringRef Annot,
32 const MCSubtargetInfo &STI) override;
33 };
34
35 } // end namespace llvm
36
37 #endif
0 ;===- ./lib/Target/WebAssembly/LLVMBuild.txt -------------------*- Conf -*--===;
1 ;
2 ; The LLVM Compiler Infrastructure
3 ;
4 ; This file is distributed under the University of Illinois Open Source
5 ; License. See LICENSE.TXT for details.
6 ;
7 ;===------------------------------------------------------------------------===;
8 ;
9 ; This is an LLVMBuild description file for the components in this subdirectory.
10 ;
11 ; For more information on the LLVMBuild system, please see:
12 ;
13 ; http://llvm.org/docs/LLVMBuild.html
14 ;
15 ;===------------------------------------------------------------------------===;
16
17 [common]
18 subdirectories = InstPrinter MCTargetDesc TargetInfo
19
20 [component_0]
21 type = TargetGroup
22 name = WebAssembly
23 parent = Target
24 has_asmprinter = 1
25
26 [component_1]
27 type = Library
28 name = WebAssemblyCodeGen
29 parent = WebAssembly
30 required_libraries = Analysis AsmPrinter CodeGen Core MC Scalar SelectionDAG Support Target WebAssemblyDesc WebAssemblyInfo
31 add_to_library_groups = WebAssembly
0 add_llvm_library(LLVMWebAssemblyDesc
1 WebAssemblyMCAsmInfo.cpp
2 WebAssemblyMCTargetDesc.cpp
3 )
0 ;===- ./lib/Target/WebAssembly/MCTargetDesc/LLVMBuild.txt ------*- Conf -*--===;
1 ;
2 ; The LLVM Compiler Infrastructure
3 ;
4 ; This file is distributed under the University of Illinois Open Source
5 ; License. See LICENSE.TXT for details.
6 ;
7 ;===------------------------------------------------------------------------===;
8 ;
9 ; This is an LLVMBuild description file for the components in this subdirectory.
10 ;
11 ; For more information on the LLVMBuild system, please see:
12 ;
13 ; http://llvm.org/docs/LLVMBuild.html
14 ;
15 ;===------------------------------------------------------------------------===;
16
17 [component_0]
18 type = Library
19 name = WebAssemblyDesc
20 parent = WebAssembly
21 required_libraries = MC Support WebAssemblyAsmPrinter WebAssemblyInfo
22 add_to_library_groups = WebAssembly
0 ##===- lib/Target/WebAssembly/TargetDesc/Makefile ----------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../../../..
10 LIBRARYNAME = LLVMWebAssemblyDesc
11
12 # Hack: we need to include 'main' target directory to grab private headers
13 CPP.Flags += -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/..
14
15 include $(LEVEL)/Makefile.common
0 //===-- WebAssemblyMCAsmInfo.cpp - WebAssembly asm properties -------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file contains the declarations of the WebAssemblyMCAsmInfo
11 /// properties.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #include "WebAssemblyMCAsmInfo.h"
16 #include "llvm/ADT/Triple.h"
17 #include "llvm/Support/CommandLine.h"
18 using namespace llvm;
19
20 #define DEBUG_TYPE "wasm-mc-asm-info"
21
22 WebAssemblyMCAsmInfo::~WebAssemblyMCAsmInfo() {}
23
24 WebAssemblyMCAsmInfo::WebAssemblyMCAsmInfo(const Triple &T) {
25 PointerSize = CalleeSaveStackSlotSize = T.isArch64Bit();
26
27 // TODO: What should MaxInstLength be?
28
29 PrivateGlobalPrefix = "";
30 PrivateLabelPrefix = "";
31
32 UseDataRegionDirectives = true;
33
34 Data8bitsDirective = "\t.int8\t";
35 Data16bitsDirective = "\t.int16\t";
36 Data32bitsDirective = "\t.int32\t";
37 Data64bitsDirective = "\t.int64\t";
38
39 AlignmentIsInBytes = false;
40 COMMDirectiveAlignmentIsInBytes = false;
41 LCOMMDirectiveAlignmentType = LCOMM::Log2Alignment;
42
43 HasDotTypeDotSizeDirective = false;
44 HasSingleParameterDotFile = false;
45
46 SupportsDebugInformation = true;
47
48 // For now, WebAssembly does not support exceptions.
49 ExceptionsType = ExceptionHandling::None;
50
51 // TODO: UseIntegratedAssembler?
52 }
0 //===-- WebAssemblyMCAsmInfo.h - WebAssembly asm properties -----*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file contains the declaration of the WebAssemblyMCAsmInfo class.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCASMINFO_H
15 #define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCASMINFO_H
16
17 #include "llvm/MC/MCAsmInfo.h"
18
19 namespace llvm {
20
21 class Triple;
22
23 class WebAssemblyMCAsmInfo final : public MCAsmInfo {
24 public:
25 explicit WebAssemblyMCAsmInfo(const Triple &T);
26 ~WebAssemblyMCAsmInfo() override;
27 };
28
29 } // end namespace llvm
30
31 #endif
0 //===-- WebAssemblyMCTargetDesc.cpp - WebAssembly Target Descriptions -----===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file provides WebAssembly-specific target descriptions.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #include "WebAssemblyMCTargetDesc.h"
15 #include "InstPrinter/WebAssemblyInstPrinter.h"
16 #include "WebAssemblyMCAsmInfo.h"
17 #include "llvm/MC/MCCodeGenInfo.h"
18 #include "llvm/MC/MCInstrInfo.h"
19 #include "llvm/MC/MCRegisterInfo.h"
20 #include "llvm/MC/MCStreamer.h"
21 #include "llvm/MC/MCSubtargetInfo.h"
22 #include "llvm/Support/ErrorHandling.h"
23 #include "llvm/Support/TargetRegistry.h"
24 using namespace llvm;
25
26 #define DEBUG_TYPE "wasm-mc-target-desc"
27
28 #define GET_SUBTARGETINFO_MC_DESC
29 #include "WebAssemblyGenSubtargetInfo.inc"
30
31 static MCAsmInfo *createWebAssemblyMCAsmInfo(const MCRegisterInfo &MRI,
32 const Triple &TT) {
33 MCAsmInfo *MAI = new WebAssemblyMCAsmInfo(TT);
34 return MAI;
35 }
36
37 static MCInstPrinter *
38 createWebAssemblyMCInstPrinter(const Triple &T, unsigned SyntaxVariant,
39 const MCAsmInfo &MAI, const MCInstrInfo &MII,
40 const MCRegisterInfo &MRI) {
41 if (SyntaxVariant == 0 || SyntaxVariant == 1)
42 return new WebAssemblyInstPrinter(MAI, MII, MRI);
43 return nullptr;
44 }
45
46 // Force static initialization.
47 extern "C" void LLVMInitializeWebAssemblyTargetMC() {
48 for (Target *T : {&TheWebAssemblyTarget}) {
49 // Register the MC asm info.
50 RegisterMCAsmInfoFn X(*T, createWebAssemblyMCAsmInfo);
51
52 // Register the MCInstPrinter.
53 TargetRegistry::RegisterMCInstPrinter(*T, createWebAssemblyMCInstPrinter);
54 }
55 }
0 //==- WebAssemblyMCTargetDesc.h - WebAssembly Target Descriptions -*- C++ -*-=//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file provides WebAssembly-specific target descriptions.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTARGETDESC_H
15 #define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTARGETDESC_H
16
17 #include "llvm/Support/DataTypes.h"
18 #include
19
20 namespace llvm {
21
22 class formatted_raw_ostream;
23 class MCAsmBackend;
24 class MCCodeEmitter;
25 class MCContext;
26 class MCInstrInfo;
27 class MCRegisterInfo;
28 class MCObjectWriter;
29 class MCStreamer;
30 class MCSubtargetInfo;
31 class MCTargetStreamer;
32 class StringRef;
33 class Target;
34 class Triple;
35 class raw_ostream;
36
37 extern Target TheWebAssemblyTarget;
38
39 MCAsmBackend *createWebAssemblyAsmBackend(const Target &T,
40 const MCRegisterInfo &MRI,
41 StringRef TT, StringRef CPU);
42
43 } // end namespace llvm
44
45 // Defines symbolic names for WebAssembly registers. This defines a mapping from
46 // register name to register number.
47 //
48 #define GET_SUBTARGETINFO_ENUM
49 #include "WebAssemblyGenSubtargetInfo.inc"
50
51 #endif
0 ##===- lib/Target/WebAssembly/Makefile ---------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../../..
10 LIBRARYNAME = LLVMWebAssemblyCodeGen
11 TARGET = WebAssembly
12
13 # Make sure that tblgen is run, first thing.
14 BUILT_SOURCES = WebAssemblyGenSubtargetInfo.inc WebAssemblyGenMCCodeEmitter.inc
15
16 DIRS = InstPrinter TargetInfo MCTargetDesc
17
18 include $(LEVEL)/Makefile.common
0 //===-- README.txt - Notes for WebAssembly code gen -----------------------===//
1
2 This WebAssembly backend is presently in a very early stage of development.
3 The code should build and not break anything else, but don't expect a lot more
4 at this point.
5
6 For more information on WebAssembly itself, see the design documents:
7 * https://github.com/WebAssembly/design/blob/master/README.md
8
9 The following documents contain some information on the planned semantics and
10 binary encoding of WebAssembly itself:
11 * https://github.com/WebAssembly/design/blob/master/AstSemantics.md
12 * https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md
13
14 //===---------------------------------------------------------------------===//
0 include_directories( ${CMAKE_CURRENT_BINARY_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/.. )
1
2 add_llvm_library(LLVMWebAssemblyInfo
3 WebAssemblyTargetInfo.cpp
4 )
5
6 add_dependencies(LLVMWebAssemblyInfo WebAssemblyCommonTableGen)
0 ;===- ./lib/Target/WebAssembly/TargetInfo/LLVMBuild.txt --------*- Conf -*--===;
1 ;
2 ; The LLVM Compiler Infrastructure
3 ;
4 ; This file is distributed under the University of Illinois Open Source
5 ; License. See LICENSE.TXT for details.
6 ;
7 ;===------------------------------------------------------------------------===;
8 ;
9 ; This is an LLVMBuild description file for the components in this subdirectory.
10 ;
11 ; For more information on the LLVMBuild system, please see:
12 ;
13 ; http://llvm.org/docs/LLVMBuild.html
14 ;
15 ;===------------------------------------------------------------------------===;
16
17 [component_0]
18 type = Library
19 name = WebAssemblyInfo
20 parent = WebAssembly
21 required_libraries = Support
22 add_to_library_groups = WebAssembly
0 ##===- lib/Target/WebAssembly/TargetInfo/Makefile ----------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8 LEVEL = ../../../..
9 LIBRARYNAME = LLVMWebAssemblyInfo
10
11 # Hack: we need to include 'main' target directory to grab private headers
12 CPPFLAGS = -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/..
13
14 include $(LEVEL)/Makefile.common
0 //===-- WebAssemblyTargetInfo.cpp - WebAssembly Target Implementation -----===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file registers the WebAssembly target.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
15 #include "llvm/ADT/Triple.h"
16 #include "llvm/Support/TargetRegistry.h"
17 using namespace llvm;
18
19 #define DEBUG_TYPE "wasm-target-info"
20
21 Target llvm::TheWebAssemblyTarget;
22
23 extern "C" void LLVMInitializeWebAssemblyTargetInfo() {
24 RegisterTarget X(TheWebAssemblyTarget, "wasm32",
25 "WebAssembly 32-bit");
26 RegisterTarget Y(TheWebAssemblyTarget, "wasm64",
27 "WebAssembly 64-bit");
28 }
0 //===-- WebAssembly.h - Top-level interface for WebAssembly ----*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file contains the entry points for global functions defined in
11 /// the LLVM WebAssembly back-end.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLY_H
16 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLY_H
17
18 #include "llvm/Support/CodeGen.h"
19
20 namespace llvm {
21
22 class WebAssemblyTargetMachine;
23 class FunctionPass;
24
25 FunctionPass *createWebAssemblyISelDag(WebAssemblyTargetMachine &TM,
26 CodeGenOpt::Level OptLevel);
27
28 } // end namespace llvm
29
30 #endif
0 //- WebAssembly.td - Describe the WebAssembly Target Machine --*- tablegen -*-//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This is a target description file for the WebAssembly architecture, which is
10 // also known as "wasm".
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 // Target-independent interfaces which we are implementing
16 //===----------------------------------------------------------------------===//
17
18 include "llvm/Target/Target.td"
19
20 //===----------------------------------------------------------------------===//
21 // WebAssembly Subtarget features.
22 //===----------------------------------------------------------------------===//
23
24 def FeatureSIMD : SubtargetFeature<"simd", "HasSIMD", "true",
25 "Enable SIMD">;
26
27 //===----------------------------------------------------------------------===//
28 // Architectures.
29 //===----------------------------------------------------------------------===//
30
31 //===----------------------------------------------------------------------===//
32 // Register File Description
33 //===----------------------------------------------------------------------===//
34
35 include "WebAssemblyRegisterInfo.td"
36
37 //===----------------------------------------------------------------------===//
38 // Instruction Descriptions
39 //===----------------------------------------------------------------------===//
40
41 include "WebAssemblyInstrInfo.td"
42
43 def WebAssemblyInstrInfo : InstrInfo;
44
45 //===----------------------------------------------------------------------===//
46 // WebAssembly Processors supported.
47 //===----------------------------------------------------------------------===//
48
49 def : ProcessorModel<"generic", NoSchedModel, [FeatureSIMD]>;
50
51 //===----------------------------------------------------------------------===//
52 // Target Declaration
53 //===----------------------------------------------------------------------===//
54
55 def WebAssembly : Target {
56 let InstructionSet = WebAssemblyInstrInfo;
57 }
0 //===-- WebAssemblyFrameLowering.cpp - WebAssembly Frame Lowering ----------==//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file contains the WebAssembly implementation of
11 /// TargetFrameLowering class.
12 ///
13 /// On WebAssembly, there aren't a lot of things to do here. There are no
14 /// callee-saved registers to save, and no spill slots.
15 ///
16 /// The stack grows downward.
17 ///
18 //===----------------------------------------------------------------------===//
19
20 #include "WebAssemblyFrameLowering.h"
21 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
22 #include "WebAssemblyInstrInfo.h"
23 #include "WebAssemblyMachineFunctionInfo.h"
24 #include "WebAssemblySubtarget.h"
25 #include "WebAssemblyTargetMachine.h"
26 #include "llvm/CodeGen/MachineFrameInfo.h"
27 #include "llvm/CodeGen/MachineFunction.h"
28 #include "llvm/CodeGen/MachineInstrBuilder.h"
29 #include "llvm/CodeGen/MachineModuleInfo.h"
30 #include "llvm/CodeGen/MachineRegisterInfo.h"
31 #include "llvm/Support/Debug.h"
32 using namespace llvm;
33
34 #define DEBUG_TYPE "frame-info"
35
36 // TODO: Implement a red zone?
37
38 /// Return true if the specified function should have a dedicated frame pointer
39 /// register.
40 bool WebAssemblyFrameLowering::hasFP(const MachineFunction &MF) const {
41 llvm_unreachable("TODO: implement hasFP");
42 }
43
44 /// Under normal circumstances, when a frame pointer is not required, we reserve
45 /// argument space for call sites in the function immediately on entry to the
46 /// current function. This eliminates the need for add/sub sp brackets around
47 /// call sites. Returns true if the call frame is included as part of the stack
48 /// frame.
49 bool WebAssemblyFrameLowering::hasReservedCallFrame(
50 const MachineFunction &MF) const {
51 return !MF.getFrameInfo()->hasVarSizedObjects();
52 }
53
54 void WebAssemblyFrameLowering::eliminateCallFramePseudoInstr(
55 MachineFunction &MF, MachineBasicBlock &MBB,
56 MachineBasicBlock::iterator I) const {
57 llvm_unreachable("TODO: implement eliminateCallFramePseudoInstr");
58 }
59
60 void WebAssemblyFrameLowering::emitPrologue(MachineFunction &MF,
61 MachineBasicBlock &MBB) const {
62 llvm_unreachable("TODO: implement emitPrologue");
63 }
64
65 void WebAssemblyFrameLowering::emitEpilogue(MachineFunction &MF,
66 MachineBasicBlock &MBB) const {
67 llvm_unreachable("TODO: implement emitEpilogue");
68 }
69
70 void WebAssemblyFrameLowering::processFunctionBeforeCalleeSavedScan(
71 MachineFunction &MF, RegScavenger *RS) const {
72 llvm_unreachable("TODO: implement processFunctionBeforeCalleeSavedScan");
73 }
0 // WebAssemblyFrameLowering.h - TargetFrameLowering for WebAssembly -*- C++ -*-/
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This class implements WebAssembly-specific bits of
11 /// TargetFrameLowering class.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H
16 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H
17
18 #include "llvm/Target/TargetFrameLowering.h"
19
20 namespace llvm {
21
22 class WebAssemblyFrameLowering final : public TargetFrameLowering {
23 public:
24 WebAssemblyFrameLowering()
25 : TargetFrameLowering(StackGrowsDown, /*StackAlignment=*/16,
26 /*LocalAreaOffset=*/0,
27 /*TransientStackAlignment=*/16,
28 /*StackRealignable=*/true) {}
29
30 void
31 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
32 MachineBasicBlock::iterator I) const override;
33
34 /// These methods insert prolog and epilog code into the function.
35 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
36 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
37
38 bool hasFP(const MachineFunction &MF) const override;
39 bool hasReservedCallFrame(const MachineFunction &MF) const override;
40
41 void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
42 RegScavenger *RS) const override;
43 };
44
45 } // end namespace llvm
46
47 #endif
0 //- WebAssemblyISelDAGToDAG.cpp - A dag to dag inst selector for WebAssembly -//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file defines an instruction selector for the WebAssembly target.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #include "WebAssembly.h"
15 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
16 #include "WebAssemblyTargetMachine.h"
17 #include "llvm/CodeGen/SelectionDAGISel.h"
18 #include "llvm/IR/Function.h" // To access function attributes.
19 #include "llvm/Support/Debug.h"
20 #include "llvm/Support/MathExtras.h"
21 #include "llvm/Support/raw_ostream.h"
22 using namespace llvm;
23
24 #define DEBUG_TYPE "wasm-isel"
25
26 //===--------------------------------------------------------------------===//
27 /// WebAssembly-specific code to select WebAssembly machine instructions for
28 /// SelectionDAG operations.
29 ///
30 namespace {
31 class WebAssemblyDAGToDAGISel final : public SelectionDAGISel {
32 /// Keep a pointer to the WebAssemblySubtarget around so that we can make the
33 /// right decision when generating code for different targets.
34 const WebAssemblySubtarget *Subtarget;
35
36 bool ForCodeSize;
37
38 public:
39 WebAssemblyDAGToDAGISel(WebAssemblyTargetMachine &tm,
40 CodeGenOpt::Level OptLevel)
41 : SelectionDAGISel(tm, OptLevel), Subtarget(nullptr), ForCodeSize(false) {
42 }
43
44 const char *getPassName() const override {
45 return "WebAssembly Instruction Selection";
46 }
47
48 bool runOnMachineFunction(MachineFunction &MF) override {
49 ForCodeSize =
50 MF.getFunction()->hasFnAttribute(Attribute::OptimizeForSize) ||
51 MF.getFunction()->hasFnAttribute(Attribute::MinSize);
52 Subtarget = &MF.getSubtarget();
53 return SelectionDAGISel::runOnMachineFunction(MF);
54 }
55
56 SDNode *Select(SDNode *Node) override;
57
58 private:
59 // add select functions here...
60 };
61 } // end anonymous namespace
62
63 SDNode *WebAssemblyDAGToDAGISel::Select(SDNode *Node) {
64 llvm_unreachable("TODO: implement Select");
65 }
66
67 /// This pass converts a legalized DAG into a WebAssembly-specific DAG, ready
68 /// for instruction scheduling.
69 FunctionPass *llvm::createWebAssemblyISelDag(WebAssemblyTargetMachine &TM,
70 CodeGenOpt::Level OptLevel) {
71 return new WebAssemblyDAGToDAGISel(TM, OptLevel);
72 }
0 //=- WebAssemblyISelLowering.cpp - WebAssembly DAG Lowering Implementation -==//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file implements the WebAssemblyTargetLowering class.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #include "WebAssemblyISelLowering.h"
15 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
16 #include "WebAssemblyMachineFunctionInfo.h"
17 #include "WebAssemblySubtarget.h"
18 #include "WebAssemblyTargetMachine.h"
19 #include "WebAssemblyTargetObjectFile.h"
20 #include "llvm/CodeGen/Analysis.h"
21 #include "llvm/CodeGen/MachineRegisterInfo.h"
22 #include "llvm/CodeGen/SelectionDAG.h"
23 #include "llvm/IR/Function.h"
24 #include "llvm/IR/Intrinsics.h"
25 #include "llvm/Support/CommandLine.h"
26 #include "llvm/Support/Debug.h"
27 #include "llvm/Support/ErrorHandling.h"
28 #include "llvm/Support/raw_ostream.h"
29 #include "llvm/Target/TargetOptions.h"
30 using namespace llvm;
31
32 #define DEBUG_TYPE "wasm-lower"
33
34 WebAssemblyTargetLowering::WebAssemblyTargetLowering(
35 const TargetMachine &TM, const WebAssemblySubtarget &STI)
36 : TargetLowering(TM), Subtarget(&STI) {}
37
38 //===----------------------------------------------------------------------===//
39 // WebAssembly Lowering private implementation.
40 //===----------------------------------------------------------------------===//
41
42 //===----------------------------------------------------------------------===//
43 // Lowering Code
44 //===----------------------------------------------------------------------===//
45
46 //===----------------------------------------------------------------------===//
47 // Other Lowering Code
48 //===----------------------------------------------------------------------===//
49
50 //===----------------------------------------------------------------------===//
51 // WebAssembly Optimization Hooks
52 //===----------------------------------------------------------------------===//
53
54 MCSection *WebAssemblyTargetObjectFile::SelectSectionForGlobal(
55 const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
56 const TargetMachine &TM) const {
57 return getDataSection();
58 }
0 //- WebAssemblyISelLowering.h - WebAssembly DAG Lowering Interface -*- C++ -*-//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file defines the interfaces that WebAssembly uses to lower LLVM
11 /// code into a selection DAG.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYISELLOWERING_H
16 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYISELLOWERING_H
17
18 #include "llvm/Target/TargetLowering.h"
19
20 namespace llvm {
21
22 namespace WebAssemblyISD {
23
24 enum {
25 FIRST_NUMBER = ISD::BUILTIN_OP_END,
26
27 // add memory opcodes starting at ISD::FIRST_TARGET_MEMORY_OPCODE here...
28 };
29
30 } // end namespace WebAssemblyISD
31
32 class WebAssemblySubtarget;
33 class WebAssemblyTargetMachine;
34
35 class WebAssemblyTargetLowering final : public TargetLowering {
36 public:
37 WebAssemblyTargetLowering(const TargetMachine &TM,
38 const WebAssemblySubtarget &STI);
39
40 private:
41 /// Keep a pointer to the WebAssemblySubtarget around so that we can make the
42 /// right decision when generating code for different targets.
43 const WebAssemblySubtarget *Subtarget;
44 };
45
46 } // end namespace llvm
47
48 #endif
0 // WebAssemblyInstrAtomics.td-WebAssembly Atomic codegen support-*- tablegen -*-
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // WebAssembly Atomic operand code-gen constructs.
10 //
11 //===----------------------------------------------------------------------===//
12
13 //===----------------------------------------------------------------------===//
14 // Atomic fences
15 //===----------------------------------------------------------------------===//
16
17 // TODO: add atomic fences here...
18
19 //===----------------------------------------------------------------------===//
20 // Atomic loads
21 //===----------------------------------------------------------------------===//
22
23 // TODO: add atomic loads here...
24
25 //===----------------------------------------------------------------------===//
26 // Atomic stores
27 //===----------------------------------------------------------------------===//
28
29 // TODO: add atomic stores here...
30
31 //===----------------------------------------------------------------------===//
32 // Low-level exclusive operations
33 //===----------------------------------------------------------------------===//
34
35 // TODO: add exclusive operations here...
36
37 // Load-exclusives.
38
39 // Store-exclusives.
40
41 // Store-release-exclusives.
42
43 // And clear exclusive.
0 // WebAssemblyInstrFormats.td - WebAssembly Instruction Formats -*- tblgen -*-//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // WebAssembly instruction format definitions.
10 //
11 //===----------------------------------------------------------------------===//
12
13 // WebAssembly Instruction Format
14 class WebAssemblyInst : Instruction {
15 field bits<0> Inst; // Instruction encoding.
16 let Namespace = "WebAssembly";
17 let Pattern = [];
18 let Constraints = cstr;
19 }
20
21 // Normal instructions
22 class I pattern, string cstr = "">
23 : WebAssemblyInst {
24 dag OutOperandList = oops;
25 dag InOperandList = iops;
26 let Pattern = pattern;
27 }
0 //===-- WebAssemblyInstrInfo.cpp - WebAssembly Instruction Information ----===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file contains the WebAssembly implementation of the
11 /// TargetInstrInfo class.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #include "WebAssemblyInstrInfo.h"
16 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
17 #include "WebAssemblySubtarget.h"
18 #include "llvm/CodeGen/MachineFrameInfo.h"
19 #include "llvm/CodeGen/MachineInstrBuilder.h"
20 #include "llvm/CodeGen/MachineMemOperand.h"
21 #include "llvm/CodeGen/MachineRegisterInfo.h"
22 using namespace llvm;
23
24 #define DEBUG_TYPE "wasm-instr-info"
25
26 WebAssemblyInstrInfo::WebAssemblyInstrInfo(const WebAssemblySubtarget &STI)
27 : RI(STI.getTargetTriple()) {}
0 //=- WebAssemblyInstrInfo.h - WebAssembly Instruction Information -*- C++ -*-=//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file contains the WebAssembly implementation of the
11 /// TargetInstrInfo class.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYINSTRINFO_H
16 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYINSTRINFO_H
17
18 #include "WebAssemblyRegisterInfo.h"
19 #include "llvm/Target/TargetInstrInfo.h"
20
21 namespace llvm {
22
23 class WebAssemblySubtarget;
24
25 class WebAssemblyInstrInfo final {
26 const WebAssemblyRegisterInfo RI;
27
28 public:
29 explicit WebAssemblyInstrInfo(const WebAssemblySubtarget &STI);
30
31 const WebAssemblyRegisterInfo &getRegisterInfo() const { return RI; }
32 };
33
34 } // end namespace llvm
35
36 #endif
0 // WebAssemblyInstrInfo.td-Describe the WebAssembly Instructions-*- tablegen -*-
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // WebAssembly Instruction definitions.
10 //
11 //===----------------------------------------------------------------------===//
12
13 //===----------------------------------------------------------------------===//
14 // WebAssembly Instruction Predicate Definitions.
15 //===----------------------------------------------------------------------===//
16
17 //===----------------------------------------------------------------------===//
18 // WebAssembly-specific DAG Node Types.
19 //===----------------------------------------------------------------------===//
20
21 //===----------------------------------------------------------------------===//
22 // WebAssembly-specific DAG Nodes.
23 //===----------------------------------------------------------------------===//
24
25 //===----------------------------------------------------------------------===//
26 // WebAssembly-specific Operands.
27 //===----------------------------------------------------------------------===//
28
29 //===----------------------------------------------------------------------===//
30 // WebAssembly Instruction Format Definitions.
31 //===----------------------------------------------------------------------===//
32
33 include "WebAssemblyInstrFormats.td"
34
35 //===----------------------------------------------------------------------===//
36 // Additional sets of instructions.
37 //===----------------------------------------------------------------------===//
38
39 include "WebAssemblyInstrAtomics.td"
40 include "WebAssemblyInstrSIMD.td"
0 // WebAssemblyInstrSIMD.td - WebAssembly SIMD codegen support -*- tablegen -*-//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // WebAssembly SIMD operand code-gen constructs.
10 //
11 //===----------------------------------------------------------------------===//
12
13 // TODO: Implement SIMD instructions.
14 // Note: use Requires<[HasSIMD]>.
0 //=- WebAssemblyMachineFunctionInfo.cpp - WebAssembly Machine Function Info -=//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file implements WebAssembly-specific per-machine-function
11 /// information.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #include "WebAssemblyMachineFunctionInfo.h"
16 using namespace llvm;
17
18 WebAssemblyFunctionInfo::~WebAssemblyFunctionInfo() {}
0 // WebAssemblyMachineFuctionInfo.h-WebAssembly machine function info -*- C++ -*-
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file declares WebAssembly-specific per-machine-function
11 /// information.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYMACHINEFUNCTIONINFO_H
16 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYMACHINEFUNCTIONINFO_H
17
18 #include "WebAssemblyRegisterInfo.h"
19 #include "llvm/CodeGen/MachineFunction.h"
20 #include "llvm/CodeGen/MachineRegisterInfo.h"
21
22 namespace llvm {
23
24 /// This class is derived from MachineFunctionInfo and contains private
25 /// WebAssembly-specific information for each MachineFunction.
26 class WebAssemblyFunctionInfo final : public MachineFunctionInfo {
27 MachineFunction &MF;
28
29 public:
30 explicit WebAssemblyFunctionInfo(MachineFunction &MF) : MF(MF) {}
31 ~WebAssemblyFunctionInfo() override;
32 };
33
34 } // end namespace llvm
35
36 #endif
0 //===-- WebAssemblyRegisterInfo.cpp - WebAssembly Register Information ----===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file contains the WebAssembly implementation of the
11 /// TargetRegisterInfo class.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #include "WebAssemblyRegisterInfo.h"
16 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
17 #include "WebAssemblyFrameLowering.h"
18 #include "WebAssemblyInstrInfo.h"
19 #include "WebAssemblyMachineFunctionInfo.h"
20 #include "WebAssemblySubtarget.h"
21 #include "llvm/CodeGen/MachineFrameInfo.h"
22 #include "llvm/CodeGen/MachineInstrBuilder.h"
23 #include "llvm/CodeGen/MachineRegisterInfo.h"
24 #include "llvm/IR/Function.h"
25 #include "llvm/Support/raw_ostream.h"
26 #include "llvm/Target/TargetFrameLowering.h"
27 #include "llvm/Target/TargetOptions.h"
28 using namespace llvm;
29
30 #define DEBUG_TYPE "wasm-reg-info"
31
32 WebAssemblyRegisterInfo::WebAssemblyRegisterInfo(const Triple &TT) : TT(TT) {}
0 // WebAssemblyRegisterInfo.h - WebAssembly Register Information Impl -*- C++ -*-
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file contains the WebAssembly implementation of the
11 /// WebAssemblyRegisterInfo class.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYREGISTERINFO_H
16 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYREGISTERINFO_H
17
18 namespace llvm {
19
20 class MachineFunction;
21 class RegScavenger;
22 class TargetRegisterClass;
23 class Triple;
24
25 class WebAssemblyRegisterInfo final {
26 const Triple &TT;
27
28 public:
29 explicit WebAssemblyRegisterInfo(const Triple &TT);
30 };
31
32 } // end namespace llvm
33
34 #endif
0 //WebAssemblyRegisterInfo.td-Describe the WebAssembly Registers -*- tablegen -*-
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file describes the WebAssembly register classes and some nominal
10 // physical registers.
11 //
12 //===----------------------------------------------------------------------===//
13
14 class WebAssemblyReg : Register {
15 let Namespace = "WebAssembly";
16 }
17
18 class WebAssemblyRegClass regTypes, int alignment, dag regList>
19 : RegisterClass<"WebAssembly", regTypes, alignment, regList>;
20
21 //===----------------------------------------------------------------------===//
22 // Registers
23 //===----------------------------------------------------------------------===//
24
25 //===----------------------------------------------------------------------===//
26 // Register classes
27 //===----------------------------------------------------------------------===//
0 //===-- WebAssemblySelectionDAGInfo.cpp - WebAssembly SelectionDAG Info ---===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file implements the WebAssemblySelectionDAGInfo class.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #include "WebAssemblyTargetMachine.h"
15 using namespace llvm;
16
17 #define DEBUG_TYPE "wasm-selectiondag-info"
18
19 WebAssemblySelectionDAGInfo::WebAssemblySelectionDAGInfo(const DataLayout *DL)
20 : TargetSelectionDAGInfo(DL) {}
21
22 WebAssemblySelectionDAGInfo::~WebAssemblySelectionDAGInfo() {}
0 //=- WebAssemblySelectionDAGInfo.h - WebAssembly SelectionDAG Info -*- C++ -*-//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file defines the WebAssembly subclass for
11 /// TargetSelectionDAGInfo.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYSELECTIONDAGINFO_H
16 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYSELECTIONDAGINFO_H
17
18 #include "llvm/Target/TargetSelectionDAGInfo.h"
19
20 namespace llvm {
21
22 class WebAssemblySelectionDAGInfo final : public TargetSelectionDAGInfo {
23 public:
24 explicit WebAssemblySelectionDAGInfo(const DataLayout *DL);
25 ~WebAssemblySelectionDAGInfo() override;
26 };
27
28 } // end namespace llvm
29
30 #endif
0 //===-- WebAssemblySubtarget.cpp - WebAssembly Subtarget Information ------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file implements the WebAssembly-specific subclass of
11 /// TargetSubtarget.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #include "WebAssemblyInstrInfo.h"
16 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
17 #include "WebAssemblySubtarget.h"
18 #include "llvm/Support/TargetRegistry.h"
19 using namespace llvm;
20
21 #define DEBUG_TYPE "subtarget"
22
23 #define GET_SUBTARGETINFO_CTOR
24 #define GET_SUBTARGETINFO_TARGET_DESC
25 #include "WebAssemblyGenSubtargetInfo.inc"
26
27 WebAssemblySubtarget &
28 WebAssemblySubtarget::initializeSubtargetDependencies(StringRef FS) {
29 // Determine default and user-specified characteristics
30
31 if (CPUString.empty())
32 CPUString = "generic";
33
34 ParseSubtargetFeatures(CPUString, FS);
35 return *this;
36 }
37
38 WebAssemblySubtarget::WebAssemblySubtarget(const Triple &TT,
39 const std::string &CPU,
40 const std::string &FS,
41 const TargetMachine &TM)
42 : WebAssemblyGenSubtargetInfo(TT, CPU, FS), HasSIMD(true), CPUString(CPU),
43 TargetTriple(TT), FrameLowering(),
44 InstrInfo(initializeSubtargetDependencies(FS)),
45 TSInfo(TM.getDataLayout()), TLInfo(TM, *this) {}
46
47 bool WebAssemblySubtarget::enableMachineScheduler() const { return true; }
0 //=- WebAssemblySubtarget.h - Define Subtarget for the WebAssembly -*- C++ -*-//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file declares the WebAssembly-specific subclass of
11 /// TargetSubtarget.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYSUBTARGET_H
16 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYSUBTARGET_H
17
18 #include "WebAssemblyFrameLowering.h"
19 #include "WebAssemblyISelLowering.h"
20 #include "WebAssemblyInstrInfo.h"
21 #include "WebAssemblySelectionDAGInfo.h"
22 #include "llvm/Target/TargetSubtargetInfo.h"
23 #include
24
25 #define GET_SUBTARGETINFO_HEADER
26 #include "WebAssemblyGenSubtargetInfo.inc"
27
28 namespace llvm {
29
30 class WebAssemblySubtarget final : public WebAssemblyGenSubtargetInfo {
31 bool HasSIMD;
32
33 /// String name of used CPU.
34 std::string CPUString;
35
36 /// What processor and OS we're targeting.
37 Triple TargetTriple;
38
39 WebAssemblyFrameLowering FrameLowering;
40 WebAssemblyInstrInfo InstrInfo;
41 WebAssemblySelectionDAGInfo TSInfo;
42 WebAssemblyTargetLowering TLInfo;
43
44 /// Initializes using CPUString and the passed in feature string so that we
45 /// can use initializer lists for subtarget initialization.
46 WebAssemblySubtarget &initializeSubtargetDependencies(StringRef FS);
47
48 public:
49 /// This constructor initializes the data members to match that
50 /// of the specified triple.
51 WebAssemblySubtarget(const Triple &TT, const std::string &CPU,
52 const std::string &FS, const TargetMachine &TM);
53
54 const WebAssemblySelectionDAGInfo *getSelectionDAGInfo() const override {
55 return &TSInfo;
56 }
57 const WebAssemblyFrameLowering *getFrameLowering() const override {
58 return &FrameLowering;
59 }
60 const WebAssemblyTargetLowering *getTargetLowering() const override {
61 return &TLInfo;
62 }
63 const Triple &getTargetTriple() const { return TargetTriple; }
64 bool enableMachineScheduler() const override;
65 bool useAA() const override { return true; }
66
67 // Predicates used by WebAssemblyInstrInfo.td.
68 bool hasSIMD() const { return HasSIMD; }
69
70 /// Parses features string setting specified subtarget options. Definition of
71 /// function is auto generated by tblgen.
72 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
73 };
74
75 } // end namespace llvm
76
77 #endif
0 //===- WebAssemblyTargetMachine.cpp - Define TargetMachine for WebAssembly -==//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file defines the WebAssembly-specific subclass of TargetMachine.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #include "WebAssembly.h"
15 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
16 #include "WebAssemblyTargetMachine.h"
17 #include "WebAssemblyTargetObjectFile.h"
18 #include "WebAssemblyTargetTransformInfo.h"
19 #include "llvm/CodeGen/MachineFunctionPass.h"
20 #include "llvm/CodeGen/Passes.h"
21 #include "llvm/CodeGen/RegAllocRegistry.h"
22 #include "llvm/IR/Function.h"
23 #include "llvm/Support/CommandLine.h"
24 #include "llvm/Support/TargetRegistry.h"
25 #include "llvm/Target/TargetOptions.h"
26 using namespace llvm;
27
28 #define DEBUG_TYPE "wasm"
29
30 extern "C" void LLVMInitializeWebAssemblyTarget() {
31 // Register the target.
32 RegisterTargetMachine X(TheWebAssemblyTarget);
33 }
34
35 //===----------------------------------------------------------------------===//
36 // WebAssembly Lowering public interface.
37 //===----------------------------------------------------------------------===//
38
39 /// Create an WebAssembly architecture model.
40 ///
41 WebAssemblyTargetMachine::WebAssemblyTargetMachine(
42 const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
43 const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM,
44 CodeGenOpt::Level OL)
45 : LLVMTargetMachine(T, TT.isArch64Bit()
46 ? "e-p:64:64-i64:64-v128:8:128-n32:64-S128"
47 : "e-p:32:32-i64:64-v128:8:128-n32:64-S128",
48 TT, CPU, FS, Options, RM, CM, OL),
49 TLOF(make_unique()) {
50 initAsmInfo();
51
52 // We need a reducible CFG, so disable some optimizations which tend to
53 // introduce irreducibility.
54 setRequiresStructuredCFG(true);
55 }
56
57 WebAssemblyTargetMachine::~WebAssemblyTargetMachine() {}
58
59 const WebAssemblySubtarget *
60 WebAssemblyTargetMachine::getSubtargetImpl(const Function &F) const {
61 Attribute CPUAttr = F.getFnAttribute("target-cpu");
62 Attribute FSAttr = F.getFnAttribute("target-features");
63
64 std::string CPU = !CPUAttr.hasAttribute(Attribute::None)
65 ? CPUAttr.getValueAsString().str()
66 : TargetCPU;
67 std::string FS = !FSAttr.hasAttribute(Attribute::None)
68 ? FSAttr.getValueAsString().str()
69 : TargetFS;
70
71 auto &I = SubtargetMap[CPU + FS];
72 if (!I) {
73 // This needs to be done before we create a new subtarget since any
74 // creation will depend on the TM and the code generation flags on the
75 // function that reside in TargetOptions.
76 resetTargetOptions(F);
77 I = make_unique(TargetTriple, CPU, FS, *this);
78 }
79 return I.get();
80 }
81
82 namespace {
83 /// WebAssembly Code Generator Pass Configuration Options.
84 class WebAssemblyPassConfig final : public TargetPassConfig {
85 public:
86 WebAssemblyPassConfig(WebAssemblyTargetMachine *TM, PassManagerBase &PM)
87 : TargetPassConfig(TM, PM) {}
88
89 WebAssemblyTargetMachine &getWebAssemblyTargetMachine() const {
90 return getTM();
91 }
92
93 FunctionPass *createTargetRegisterAllocator(bool) override;
94 void addFastRegAlloc(FunctionPass *RegAllocPass) override;
95 void addOptimizedRegAlloc(FunctionPass *RegAllocPass) override;
96
97 void addIRPasses() override;
98 bool addPreISel() override;
99 bool addInstSelector() override;
100 bool addILPOpts() override;
101 void addPreRegAlloc() override;
102 void addRegAllocPasses(bool Optimized);
103 void addPostRegAlloc() override;
104 void addPreSched2() override;
105 void addPreEmitPass() override;
106 };
107 } // end anonymous namespace
108
109 TargetIRAnalysis WebAssemblyTargetMachine::getTargetIRAnalysis() {
110 return TargetIRAnalysis([this](Function &F) {
111 return TargetTransformInfo(WebAssemblyTTIImpl(this, F));
112 });
113 }
114
115 TargetPassConfig *
116 WebAssemblyTargetMachine::createPassConfig(PassManagerBase &PM) {
117 return new WebAssemblyPassConfig(this, PM);
118 }
119
120 FunctionPass *WebAssemblyPassConfig::createTargetRegisterAllocator(bool) {
121 return nullptr; // No reg alloc
122 }
123
124 void WebAssemblyPassConfig::addFastRegAlloc(FunctionPass *RegAllocPass) {
125 assert(!RegAllocPass && "WebAssembly uses no regalloc!");
126 addRegAllocPasses(false);
127 }
128
129 void WebAssemblyPassConfig::addOptimizedRegAlloc(FunctionPass *RegAllocPass) {
130 assert(!RegAllocPass && "WebAssembly uses no regalloc!");
131 addRegAllocPasses(true);
132 }
133
134 //===----------------------------------------------------------------------===//
135 // The following functions are called from lib/CodeGen/Passes.cpp to modify
136 // the CodeGen pass sequence.
137 //===----------------------------------------------------------------------===//
138
139 void WebAssemblyPassConfig::addIRPasses() {
140 // Expand some atomic operations. WebAssemblyTargetLowering has hooks which
141 // control specifically what gets lowered.
142 addPass(createAtomicExpandPass(&getTM()));
143
144 TargetPassConfig::addIRPasses();
145 }
146
147 bool WebAssemblyPassConfig::addPreISel() { return false; }
148
149 bool WebAssemblyPassConfig::addInstSelector() {
150 addPass(
151 createWebAssemblyISelDag(getWebAssemblyTargetMachine(), getOptLevel()));
152 return false;
153 }
154
155 bool WebAssemblyPassConfig::addILPOpts() { return true; }
156
157 void WebAssemblyPassConfig::addPreRegAlloc() {}
158
159 void WebAssemblyPassConfig::addRegAllocPasses(bool Optimized) {}
160
161 void WebAssemblyPassConfig::addPostRegAlloc() {}
162
163 void WebAssemblyPassConfig::addPreSched2() {}
164
165 void WebAssemblyPassConfig::addPreEmitPass() {}
0 // WebAssemblyTargetMachine.h - Define TargetMachine for WebAssembly -*- C++ -*-
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file declares the WebAssembly-specific subclass of
11 /// TargetMachine.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYTARGETMACHINE_H
16 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYTARGETMACHINE_H
17
18 #include "WebAssemblySubtarget.h"
19 #include "llvm/Target/TargetMachine.h"
20
21 namespace llvm {
22
23 class WebAssemblyTargetMachine final : public LLVMTargetMachine {
24 std::unique_ptr TLOF;
25 mutable StringMap> SubtargetMap;
26
27 public:
28 WebAssemblyTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
29 StringRef FS, const TargetOptions &Options,
30 Reloc::Model RM, CodeModel::Model CM,
31 CodeGenOpt::Level OL);
32
33 ~WebAssemblyTargetMachine() override;
34 const WebAssemblySubtarget *
35 getSubtargetImpl(const Function &F) const override;
36
37 // Pass Pipeline Configuration
38 TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
39
40 TargetLoweringObjectFile *getObjFileLowering() const override {
41 return TLOF.get();
42 }
43
44 /// \brief Get the TargetIRAnalysis for this target.
45 TargetIRAnalysis getTargetIRAnalysis() override;
46 };
47
48 } // end namespace llvm
49
50 #endif
0 //===-- WebAssemblyTargetObjectFile.h - WebAssembly Object Info -*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file declares the WebAssembly-specific subclass of
11 /// TargetLoweringObjectFile.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYTARGETOBJECTFILE_H
16 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYTARGETOBJECTFILE_H
17
18 #include "llvm/Target/TargetLoweringObjectFile.h"
19
20 namespace llvm {
21
22 class GlobalVariable;
23
24 class WebAssemblyTargetObjectFile final : public TargetLoweringObjectFile {
25 public:
26 WebAssemblyTargetObjectFile() {
27 TextSection = nullptr;
28 DataSection = nullptr;
29 BSSSection = nullptr;
30 ReadOnlySection = nullptr;
31
32 StaticCtorSection = nullptr;
33 StaticDtorSection = nullptr;
34 LSDASection = nullptr;
35 EHFrameSection = nullptr;
36 DwarfAbbrevSection = nullptr;
37 DwarfInfoSection = nullptr;
38 DwarfLineSection = nullptr;
39 DwarfFrameSection = nullptr;
40 DwarfPubTypesSection = nullptr;
41 DwarfDebugInlineSection = nullptr;
42 DwarfStrSection = nullptr;
43 DwarfLocSection = nullptr;
44 DwarfARangesSection = nullptr;
45 DwarfRangesSection = nullptr;
46 }
47
48 MCSection *getSectionForConstant(SectionKind Kind,
49 const Constant *C) const override {
50 return ReadOnlySection;
51 }
52
53 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
54 Mangler &Mang,
55 const TargetMachine &TM) const override {
56 return DataSection;
57 }
58
59 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
60 Mangler &Mang,
61 const TargetMachine &TM) const override;
62 };
63
64 } // end namespace llvm
65
66 #endif
0 //===-- WebAssemblyTargetTransformInfo.cpp - WebAssembly-specific TTI -----===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file defines the WebAssembly-specific TargetTransformInfo
11 /// implementation.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #include "WebAssemblyTargetTransformInfo.h"
16 #include "llvm/Support/Debug.h"
17 #include "llvm/Target/CostTable.h"
18 using namespace llvm;
19
20 #define DEBUG_TYPE "wasmtti"
21
22 TargetTransformInfo::PopcntSupportKind
23 WebAssemblyTTIImpl::getPopcntSupport(unsigned TyWidth) {
24 assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2");
25 // TODO: Make Math.popcount32 happen in WebAssembly.
26 return TTI::PSK_Software;
27 }
0 //==- WebAssemblyTargetTransformInfo.h - WebAssembly-specific TTI -*- C++ -*-=//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file a TargetTransformInfo::Concept conforming object specific
11 /// to the WebAssembly target machine.
12 ///
13 /// It uses the target's detailed information to provide more precise answers to
14 /// certain TTI queries, while letting the target independent and default TTI
15 /// implementations handle the rest.
16 ///
17 //===----------------------------------------------------------------------===//
18
19 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYTARGETTRANSFORMINFO_H
20 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYTARGETTRANSFORMINFO_H
21
22 #include "WebAssemblyTargetMachine.h"
23 #include "llvm/CodeGen/BasicTTIImpl.h"
24 #include
25
26 namespace llvm {
27
28 class WebAssemblyTTIImpl final : public BasicTTIImplBase {
29 typedef BasicTTIImplBase BaseT;
30 typedef TargetTransformInfo TTI;
31 friend BaseT;
32
33 const WebAssemblyTargetMachine *TM;
34 const WebAssemblySubtarget *ST;
35 const WebAssemblyTargetLowering *TLI;
36
37 const WebAssemblySubtarget *getST() const { return ST; }
38 const WebAssemblyTargetLowering *getTLI() const { return TLI; }
39
40 public:
41 WebAssemblyTTIImpl(const WebAssemblyTargetMachine *TM, Function &F)
42 : BaseT(TM), TM(TM), ST(TM->getSubtargetImpl(F)),
43 TLI(ST->getTargetLowering()) {}
44
45 // Provide value semantics. MSVC requires that we spell all of these out.
46 WebAssemblyTTIImpl(const WebAssemblyTTIImpl &Arg)
47 : BaseT(static_cast(Arg)), TM(Arg.TM), ST(Arg.ST),
48 TLI(Arg.TLI) {}
49 WebAssemblyTTIImpl(WebAssemblyTTIImpl &&Arg)
50 : BaseT(std::move(static_cast(Arg))), TM(std::move(Arg.TM)),
51 ST(std::move(Arg.ST)), TLI(std::move(Arg.TLI)) {}
52 WebAssemblyTTIImpl &operator=(const WebAssemblyTTIImpl &RHS) {
53 BaseT::operator=(static_cast(RHS));
54 TM = RHS.TM;
55 ST = RHS.ST;
56 TLI = RHS.TLI;
57 return *this;
58 }
59 WebAssemblyTTIImpl &operator=(WebAssemblyTTIImpl &&RHS) {
60 BaseT::operator=(std::move(static_cast(RHS)));
61 TM = std::move(RHS.TM);
62 ST = std::move(RHS.ST);
63 TLI = std::move(RHS.TLI);
64 return *this;
65 }
66
67 /// \name Scalar TTI Implementations
68 /// @{
69
70 // TODO: Implement more Scalar TTI for WebAssembly
71
72 TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth);
73
74 /// @}
75
76 /// \name Vector TTI Implementations
77 /// @{
78
79 // TODO: Implement Vector TTI for WebAssembly
80
81 /// @}
82 };
83
84 } // end namespace llvm
85
86 #endif
179179 EXPECT_EQ(Triple::x86_64, T.getArch());
180180 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
181181 EXPECT_EQ(Triple::CloudABI, T.getOS());
182 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
183
184 T = Triple("wasm32-unknown-wasm");
185 EXPECT_EQ(Triple::wasm32, T.getArch());
186 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
187 EXPECT_EQ(Triple::WebAssembly, T.getOS());
188 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
189
190 T = Triple("wasm64-unknown-wasm");
191 EXPECT_EQ(Triple::wasm64, T.getArch());
192 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
193 EXPECT_EQ(Triple::WebAssembly, T.getOS());
182194 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
183195
184196 T = Triple("huh");
438450 EXPECT_FALSE(T.isArch16Bit());
439451 EXPECT_FALSE(T.isArch32Bit());
440452 EXPECT_TRUE(T.isArch64Bit());
453
454 T.setArch(Triple::wasm32);
455 EXPECT_FALSE(T.isArch16Bit());
456 EXPECT_TRUE(T.isArch32Bit());
457 EXPECT_FALSE(T.isArch64Bit());
458
459 T.setArch(Triple::wasm64);
460 EXPECT_FALSE(T.isArch16Bit());
461 EXPECT_FALSE(T.isArch32Bit());
462 EXPECT_TRUE(T.isArch64Bit());
441463 }
442464
443465 TEST(TripleTest, BitWidthArchVariants) {
520542 T.setArch(Triple::spir64);
521543 EXPECT_EQ(Triple::spir, T.get32BitArchVariant().getArch());
522544 EXPECT_EQ(Triple::spir64, T.get64BitArchVariant().getArch());
545
546 T.setArch(Triple::wasm32);
547 EXPECT_EQ(Triple::wasm32, T.get32BitArchVariant().getArch());
548 EXPECT_EQ(Triple::wasm64, T.get64BitArchVariant().getArch());
549
550 T.setArch(Triple::wasm64);
551 EXPECT_EQ(Triple::wasm32, T.get32BitArchVariant().getArch());
552 EXPECT_EQ(Triple::wasm64, T.get64BitArchVariant().getArch());
523553 }
524554
525555 TEST(TripleTest, getOSVersion) {