blob: 390f367c29785231867e031f95c1173397026694 [file] [log] [blame]
Dan Gohman10e730a2015-06-29 23:51:55 +00001//===-- WebAssemblyMCTargetDesc.cpp - WebAssembly Target Descriptions -----===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000011/// This file provides WebAssembly-specific target descriptions.
Dan Gohman10e730a2015-06-29 23:51:55 +000012///
13//===----------------------------------------------------------------------===//
14
15#include "WebAssemblyMCTargetDesc.h"
16#include "InstPrinter/WebAssemblyInstPrinter.h"
17#include "WebAssemblyMCAsmInfo.h"
Dan Gohman3469ee12016-01-12 20:30:51 +000018#include "WebAssemblyTargetStreamer.h"
Dan Gohman10e730a2015-06-29 23:51:55 +000019#include "llvm/MC/MCInstrInfo.h"
20#include "llvm/MC/MCRegisterInfo.h"
Dan Gohman10e730a2015-06-29 23:51:55 +000021#include "llvm/MC/MCSubtargetInfo.h"
22#include "llvm/Support/ErrorHandling.h"
23#include "llvm/Support/TargetRegistry.h"
24using namespace llvm;
25
26#define DEBUG_TYPE "wasm-mc-target-desc"
27
JF Bastienb9073fb2015-07-22 21:28:15 +000028#define GET_INSTRINFO_MC_DESC
29#include "WebAssemblyGenInstrInfo.inc"
30
Dan Gohman10e730a2015-06-29 23:51:55 +000031#define GET_SUBTARGETINFO_MC_DESC
32#include "WebAssemblyGenSubtargetInfo.inc"
33
JF Bastien5ca0bac2015-07-10 18:23:10 +000034#define GET_REGINFO_MC_DESC
35#include "WebAssemblyGenRegisterInfo.inc"
36
Dan Gohmancceedf72016-01-08 00:43:54 +000037static MCAsmInfo *createMCAsmInfo(const MCRegisterInfo & /*MRI*/,
38 const Triple &TT) {
JF Bastienae7eebd2015-07-28 17:23:07 +000039 return new WebAssemblyMCAsmInfo(TT);
Dan Gohman10e730a2015-06-29 23:51:55 +000040}
41
Dan Gohmancceedf72016-01-08 00:43:54 +000042static MCInstrInfo *createMCInstrInfo() {
Dan Gohmane9361d52015-11-05 19:28:16 +000043 MCInstrInfo *X = new MCInstrInfo();
44 InitWebAssemblyMCInstrInfo(X);
45 return X;
46}
47
Dan Gohman0656f5f2016-01-12 21:27:55 +000048static MCRegisterInfo *createMCRegisterInfo(const Triple & /*T*/) {
49 MCRegisterInfo *X = new MCRegisterInfo();
50 InitWebAssemblyMCRegisterInfo(X, 0);
51 return X;
52}
53
Dan Gohmancceedf72016-01-08 00:43:54 +000054static MCInstPrinter *createMCInstPrinter(const Triple & /*T*/,
55 unsigned SyntaxVariant,
56 const MCAsmInfo &MAI,
57 const MCInstrInfo &MII,
58 const MCRegisterInfo &MRI) {
Dan Gohman83947562016-01-20 05:54:22 +000059 assert(SyntaxVariant == 0 && "WebAssembly only has one syntax variant");
JF Bastienae7eebd2015-07-28 17:23:07 +000060 return new WebAssemblyInstPrinter(MAI, MII, MRI);
Dan Gohman10e730a2015-06-29 23:51:55 +000061}
62
Dan Gohmancceedf72016-01-08 00:43:54 +000063static MCCodeEmitter *createCodeEmitter(const MCInstrInfo &MCII,
64 const MCRegisterInfo & /*MRI*/,
Dan Gohmandf4f4d42017-02-10 00:14:42 +000065 MCContext &Ctx) {
Sam Clegg9d24fb72017-06-16 23:59:10 +000066 return createWebAssemblyMCCodeEmitter(MCII);
Dan Gohmancceedf72016-01-08 00:43:54 +000067}
68
69static MCAsmBackend *createAsmBackend(const Target & /*T*/,
Alex Bradbury7c093bf2018-01-03 09:30:39 +000070 const MCSubtargetInfo &STI,
Dan Gohmancceedf72016-01-08 00:43:54 +000071 const MCRegisterInfo & /*MRI*/,
David Blaikiebef810f2016-07-25 21:41:42 +000072 const MCTargetOptions & /*Options*/) {
Alex Bradbury7c093bf2018-01-03 09:30:39 +000073 return createWebAssemblyAsmBackend(STI.getTargetTriple());
Dan Gohmancceedf72016-01-08 00:43:54 +000074}
75
Dan Gohmanafd7e3a2016-01-12 03:30:06 +000076static MCSubtargetInfo *createMCSubtargetInfo(const Triple &TT, StringRef CPU,
77 StringRef FS) {
78 return createWebAssemblyMCSubtargetInfoImpl(TT, CPU, FS);
79}
80
Dan Gohman3469ee12016-01-12 20:30:51 +000081static MCTargetStreamer *
Dan Gohman18eafb62017-02-22 01:23:18 +000082createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
Dan Gohman18eafb62017-02-22 01:23:18 +000083 return new WebAssemblyTargetWasmStreamer(S);
Dan Gohman3469ee12016-01-12 20:30:51 +000084}
85
86static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
87 formatted_raw_ostream &OS,
88 MCInstPrinter * /*InstPrint*/,
89 bool /*isVerboseAsm*/) {
90 return new WebAssemblyTargetAsmStreamer(S, OS);
91}
92
Heejin Ahne0f8b9b2018-11-18 11:58:47 +000093static MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) {
94 return new WebAssemblyTargetNullStreamer(S);
95}
96
Dan Gohman10e730a2015-06-29 23:51:55 +000097// Force static initialization.
98extern "C" void LLVMInitializeWebAssemblyTargetMC() {
Mehdi Aminif42454b2016-10-09 23:00:34 +000099 for (Target *T :
100 {&getTheWebAssemblyTarget32(), &getTheWebAssemblyTarget64()}) {
Dan Gohman10e730a2015-06-29 23:51:55 +0000101 // Register the MC asm info.
Dan Gohmancceedf72016-01-08 00:43:54 +0000102 RegisterMCAsmInfoFn X(*T, createMCAsmInfo);
Dan Gohman10e730a2015-06-29 23:51:55 +0000103
Dan Gohmane9361d52015-11-05 19:28:16 +0000104 // Register the MC instruction info.
Dan Gohmancceedf72016-01-08 00:43:54 +0000105 TargetRegistry::RegisterMCInstrInfo(*T, createMCInstrInfo);
Dan Gohmane9361d52015-11-05 19:28:16 +0000106
Dan Gohman0656f5f2016-01-12 21:27:55 +0000107 // Register the MC register info.
108 TargetRegistry::RegisterMCRegInfo(*T, createMCRegisterInfo);
109
Dan Gohman10e730a2015-06-29 23:51:55 +0000110 // Register the MCInstPrinter.
Dan Gohmancceedf72016-01-08 00:43:54 +0000111 TargetRegistry::RegisterMCInstPrinter(*T, createMCInstPrinter);
Dan Gohman05ac43f2015-12-17 01:39:00 +0000112
Dan Gohman4ef99432016-01-08 01:18:00 +0000113 // Register the MC code emitter.
Dan Gohmancceedf72016-01-08 00:43:54 +0000114 TargetRegistry::RegisterMCCodeEmitter(*T, createCodeEmitter);
Dan Gohman05ac43f2015-12-17 01:39:00 +0000115
Dan Gohman4ef99432016-01-08 01:18:00 +0000116 // Register the ASM Backend.
Dan Gohmancceedf72016-01-08 00:43:54 +0000117 TargetRegistry::RegisterMCAsmBackend(*T, createAsmBackend);
Dan Gohmanafd7e3a2016-01-12 03:30:06 +0000118
119 // Register the MC subtarget info.
120 TargetRegistry::RegisterMCSubtargetInfo(*T, createMCSubtargetInfo);
Dan Gohman3469ee12016-01-12 20:30:51 +0000121
122 // Register the object target streamer.
123 TargetRegistry::RegisterObjectTargetStreamer(*T,
124 createObjectTargetStreamer);
125 // Register the asm target streamer.
126 TargetRegistry::RegisterAsmTargetStreamer(*T, createAsmTargetStreamer);
Heejin Ahne0f8b9b2018-11-18 11:58:47 +0000127 // Register the null target streamer.
128 TargetRegistry::RegisterNullTargetStreamer(*T, createNullTargetStreamer);
Dan Gohman10e730a2015-06-29 23:51:55 +0000129 }
130}
Dan Gohman3acb1872016-10-24 23:27:49 +0000131
Derek Schuffe2688c42017-03-14 20:23:22 +0000132wasm::ValType WebAssembly::toValType(const MVT &Ty) {
Dan Gohman3acb1872016-10-24 23:27:49 +0000133 switch (Ty.SimpleTy) {
Heejin Ahnf208f632018-09-05 01:27:38 +0000134 case MVT::i32:
135 return wasm::ValType::I32;
136 case MVT::i64:
137 return wasm::ValType::I64;
138 case MVT::f32:
139 return wasm::ValType::F32;
140 case MVT::f64:
141 return wasm::ValType::F64;
Thomas Lively6f21a132018-09-20 22:04:44 +0000142 case MVT::v16i8:
143 case MVT::v8i16:
144 case MVT::v4i32:
145 case MVT::v2i64:
146 case MVT::v4f32:
147 case MVT::v2f64:
148 return wasm::ValType::V128;
Heejin Ahnf208f632018-09-05 01:27:38 +0000149 case MVT::ExceptRef:
150 return wasm::ValType::EXCEPT_REF;
151 default:
152 llvm_unreachable("unexpected type");
Dan Gohman3acb1872016-10-24 23:27:49 +0000153 }
154}