Revert r354244 "[DAGCombiner] Eliminate dead stores to stack."
[llvm-complete.git] / lib / Target / WebAssembly / MCTargetDesc / WebAssemblyMCTargetDesc.cpp
blob0667816c0265307246501731cc5067ee58ffeb0d
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 "WebAssemblyMCTargetDesc.h"
15 #include "InstPrinter/WebAssemblyInstPrinter.h"
16 #include "WebAssemblyMCAsmInfo.h"
17 #include "WebAssemblyTargetStreamer.h"
18 #include "llvm/MC/MCInstrInfo.h"
19 #include "llvm/MC/MCRegisterInfo.h"
20 #include "llvm/MC/MCSubtargetInfo.h"
21 #include "llvm/Support/ErrorHandling.h"
22 #include "llvm/Support/TargetRegistry.h"
23 using namespace llvm;
25 #define DEBUG_TYPE "wasm-mc-target-desc"
27 #define GET_INSTRINFO_MC_DESC
28 #include "WebAssemblyGenInstrInfo.inc"
30 #define GET_SUBTARGETINFO_MC_DESC
31 #include "WebAssemblyGenSubtargetInfo.inc"
33 #define GET_REGINFO_MC_DESC
34 #include "WebAssemblyGenRegisterInfo.inc"
36 static MCAsmInfo *createMCAsmInfo(const MCRegisterInfo & /*MRI*/,
37 const Triple &TT) {
38 return new WebAssemblyMCAsmInfo(TT);
41 static MCInstrInfo *createMCInstrInfo() {
42 auto *X = new MCInstrInfo();
43 InitWebAssemblyMCInstrInfo(X);
44 return X;
47 static MCRegisterInfo *createMCRegisterInfo(const Triple & /*T*/) {
48 auto *X = new MCRegisterInfo();
49 InitWebAssemblyMCRegisterInfo(X, 0);
50 return X;
53 static MCInstPrinter *createMCInstPrinter(const Triple & /*T*/,
54 unsigned SyntaxVariant,
55 const MCAsmInfo &MAI,
56 const MCInstrInfo &MII,
57 const MCRegisterInfo &MRI) {
58 assert(SyntaxVariant == 0 && "WebAssembly only has one syntax variant");
59 return new WebAssemblyInstPrinter(MAI, MII, MRI);
62 static MCCodeEmitter *createCodeEmitter(const MCInstrInfo &MCII,
63 const MCRegisterInfo & /*MRI*/,
64 MCContext &Ctx) {
65 return createWebAssemblyMCCodeEmitter(MCII);
68 static MCAsmBackend *createAsmBackend(const Target & /*T*/,
69 const MCSubtargetInfo &STI,
70 const MCRegisterInfo & /*MRI*/,
71 const MCTargetOptions & /*Options*/) {
72 return createWebAssemblyAsmBackend(STI.getTargetTriple());
75 static MCSubtargetInfo *createMCSubtargetInfo(const Triple &TT, StringRef CPU,
76 StringRef FS) {
77 return createWebAssemblyMCSubtargetInfoImpl(TT, CPU, FS);
80 static MCTargetStreamer *
81 createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
82 return new WebAssemblyTargetWasmStreamer(S);
85 static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
86 formatted_raw_ostream &OS,
87 MCInstPrinter * /*InstPrint*/,
88 bool /*isVerboseAsm*/) {
89 return new WebAssemblyTargetAsmStreamer(S, OS);
92 static MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) {
93 return new WebAssemblyTargetNullStreamer(S);
96 // Force static initialization.
97 extern "C" void LLVMInitializeWebAssemblyTargetMC() {
98 for (Target *T :
99 {&getTheWebAssemblyTarget32(), &getTheWebAssemblyTarget64()}) {
100 // Register the MC asm info.
101 RegisterMCAsmInfoFn X(*T, createMCAsmInfo);
103 // Register the MC instruction info.
104 TargetRegistry::RegisterMCInstrInfo(*T, createMCInstrInfo);
106 // Register the MC register info.
107 TargetRegistry::RegisterMCRegInfo(*T, createMCRegisterInfo);
109 // Register the MCInstPrinter.
110 TargetRegistry::RegisterMCInstPrinter(*T, createMCInstPrinter);
112 // Register the MC code emitter.
113 TargetRegistry::RegisterMCCodeEmitter(*T, createCodeEmitter);
115 // Register the ASM Backend.
116 TargetRegistry::RegisterMCAsmBackend(*T, createAsmBackend);
118 // Register the MC subtarget info.
119 TargetRegistry::RegisterMCSubtargetInfo(*T, createMCSubtargetInfo);
121 // Register the object target streamer.
122 TargetRegistry::RegisterObjectTargetStreamer(*T,
123 createObjectTargetStreamer);
124 // Register the asm target streamer.
125 TargetRegistry::RegisterAsmTargetStreamer(*T, createAsmTargetStreamer);
126 // Register the null target streamer.
127 TargetRegistry::RegisterNullTargetStreamer(*T, createNullTargetStreamer);
131 wasm::ValType WebAssembly::toValType(const MVT &Ty) {
132 switch (Ty.SimpleTy) {
133 case MVT::i32:
134 return wasm::ValType::I32;
135 case MVT::i64:
136 return wasm::ValType::I64;
137 case MVT::f32:
138 return wasm::ValType::F32;
139 case MVT::f64:
140 return wasm::ValType::F64;
141 case MVT::v16i8:
142 case MVT::v8i16:
143 case MVT::v4i32:
144 case MVT::v2i64:
145 case MVT::v4f32:
146 case MVT::v2f64:
147 return wasm::ValType::V128;
148 case MVT::ExceptRef:
149 return wasm::ValType::EXCEPT_REF;
150 default:
151 llvm_unreachable("unexpected type");