[InstCombine] Signed saturation tests. NFC
[llvm-complete.git] / lib / Target / WebAssembly / MCTargetDesc / WebAssemblyMCTargetDesc.cpp
blob9c8ca1f13b18469ec0fca2c6e66cfc58d950b13f
1 //===-- WebAssemblyMCTargetDesc.cpp - WebAssembly Target Descriptions -----===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file provides WebAssembly-specific target descriptions.
11 ///
12 //===----------------------------------------------------------------------===//
14 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
15 #include "MCTargetDesc/WebAssemblyInstPrinter.h"
16 #include "MCTargetDesc/WebAssemblyMCAsmInfo.h"
17 #include "MCTargetDesc/WebAssemblyTargetStreamer.h"
18 #include "TargetInfo/WebAssemblyTargetInfo.h"
19 #include "llvm/MC/MCInstrInfo.h"
20 #include "llvm/MC/MCRegisterInfo.h"
21 #include "llvm/MC/MCSubtargetInfo.h"
22 #include "llvm/Support/ErrorHandling.h"
23 #include "llvm/Support/TargetRegistry.h"
24 using namespace llvm;
26 #define DEBUG_TYPE "wasm-mc-target-desc"
28 #define GET_INSTRINFO_MC_DESC
29 #include "WebAssemblyGenInstrInfo.inc"
31 #define GET_SUBTARGETINFO_MC_DESC
32 #include "WebAssemblyGenSubtargetInfo.inc"
34 #define GET_REGINFO_MC_DESC
35 #include "WebAssemblyGenRegisterInfo.inc"
37 static MCAsmInfo *createMCAsmInfo(const MCRegisterInfo & /*MRI*/,
38 const Triple &TT) {
39 return new WebAssemblyMCAsmInfo(TT);
42 static MCInstrInfo *createMCInstrInfo() {
43 auto *X = new MCInstrInfo();
44 InitWebAssemblyMCInstrInfo(X);
45 return X;
48 static MCRegisterInfo *createMCRegisterInfo(const Triple & /*T*/) {
49 auto *X = new MCRegisterInfo();
50 InitWebAssemblyMCRegisterInfo(X, 0);
51 return X;
54 static MCInstPrinter *createMCInstPrinter(const Triple & /*T*/,
55 unsigned SyntaxVariant,
56 const MCAsmInfo &MAI,
57 const MCInstrInfo &MII,
58 const MCRegisterInfo &MRI) {
59 assert(SyntaxVariant == 0 && "WebAssembly only has one syntax variant");
60 return new WebAssemblyInstPrinter(MAI, MII, MRI);
63 static MCCodeEmitter *createCodeEmitter(const MCInstrInfo &MCII,
64 const MCRegisterInfo & /*MRI*/,
65 MCContext &Ctx) {
66 return createWebAssemblyMCCodeEmitter(MCII);
69 static MCAsmBackend *createAsmBackend(const Target & /*T*/,
70 const MCSubtargetInfo &STI,
71 const MCRegisterInfo & /*MRI*/,
72 const MCTargetOptions & /*Options*/) {
73 return createWebAssemblyAsmBackend(STI.getTargetTriple());
76 static MCSubtargetInfo *createMCSubtargetInfo(const Triple &TT, StringRef CPU,
77 StringRef FS) {
78 return createWebAssemblyMCSubtargetInfoImpl(TT, CPU, FS);
81 static MCTargetStreamer *
82 createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
83 return new WebAssemblyTargetWasmStreamer(S);
86 static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
87 formatted_raw_ostream &OS,
88 MCInstPrinter * /*InstPrint*/,
89 bool /*isVerboseAsm*/) {
90 return new WebAssemblyTargetAsmStreamer(S, OS);
93 static MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) {
94 return new WebAssemblyTargetNullStreamer(S);
97 // Force static initialization.
98 extern "C" void LLVMInitializeWebAssemblyTargetMC() {
99 for (Target *T :
100 {&getTheWebAssemblyTarget32(), &getTheWebAssemblyTarget64()}) {
101 // Register the MC asm info.
102 RegisterMCAsmInfoFn X(*T, createMCAsmInfo);
104 // Register the MC instruction info.
105 TargetRegistry::RegisterMCInstrInfo(*T, createMCInstrInfo);
107 // Register the MC register info.
108 TargetRegistry::RegisterMCRegInfo(*T, createMCRegisterInfo);
110 // Register the MCInstPrinter.
111 TargetRegistry::RegisterMCInstPrinter(*T, createMCInstPrinter);
113 // Register the MC code emitter.
114 TargetRegistry::RegisterMCCodeEmitter(*T, createCodeEmitter);
116 // Register the ASM Backend.
117 TargetRegistry::RegisterMCAsmBackend(*T, createAsmBackend);
119 // Register the MC subtarget info.
120 TargetRegistry::RegisterMCSubtargetInfo(*T, createMCSubtargetInfo);
122 // Register the object target streamer.
123 TargetRegistry::RegisterObjectTargetStreamer(*T,
124 createObjectTargetStreamer);
125 // Register the asm target streamer.
126 TargetRegistry::RegisterAsmTargetStreamer(*T, createAsmTargetStreamer);
127 // Register the null target streamer.
128 TargetRegistry::RegisterNullTargetStreamer(*T, createNullTargetStreamer);
132 wasm::ValType WebAssembly::toValType(const MVT &Ty) {
133 switch (Ty.SimpleTy) {
134 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;
142 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;
149 case MVT::exnref:
150 return wasm::ValType::EXNREF;
151 default:
152 llvm_unreachable("unexpected type");