LLVM 20.0.0git
WebAssemblyMCTargetDesc.cpp
Go to the documentation of this file.
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//===----------------------------------------------------------------------===//
13
19#include "llvm/MC/MCInstrInfo.h"
24using namespace llvm;
25
26#define DEBUG_TYPE "wasm-mc-target-desc"
27
28#define GET_INSTRINFO_MC_DESC
29#define ENABLE_INSTR_PREDICATE_VERIFIER
30#include "WebAssemblyGenInstrInfo.inc"
31
32#define GET_SUBTARGETINFO_MC_DESC
33#include "WebAssemblyGenSubtargetInfo.inc"
34
35#define GET_REGINFO_MC_DESC
36#include "WebAssemblyGenRegisterInfo.inc"
37
38// Exception handling & setjmp-longjmp handling related options.
39
40// Emscripten's asm.js-style exception handling
42 "enable-emscripten-cxx-exceptions",
43 cl::desc("WebAssembly Emscripten-style exception handling"),
44 cl::init(false));
45// Emscripten's asm.js-style setjmp/longjmp handling
47 "enable-emscripten-sjlj",
48 cl::desc("WebAssembly Emscripten-style setjmp/longjmp handling"),
49 cl::init(false));
50// Exception handling using wasm EH instructions
52 WebAssembly::WasmEnableEH("wasm-enable-eh",
53 cl::desc("WebAssembly exception handling"));
54// setjmp/longjmp handling using wasm EH instrutions
56 "wasm-enable-sjlj", cl::desc("WebAssembly setjmp/longjmp handling"));
57// Whether we use the new exnref Wasm EH proposal adopted on Oct 2023.
58// Should be used with -wasm-enable-eh.
59// Currently set to false by default, but will later change to true and then
60// later can be removed after the legacy WAsm EH instructions are removed.
62 "wasm-enable-exnref", cl::desc("WebAssembly exception handling (exnref)"),
63 cl::init(false));
64
66 const Triple &TT,
67 const MCTargetOptions &Options) {
68 return new WebAssemblyMCAsmInfo(TT, Options);
69}
70
72 auto *X = new MCInstrInfo();
73 InitWebAssemblyMCInstrInfo(X);
74 return X;
75}
76
78 auto *X = new MCRegisterInfo();
79 InitWebAssemblyMCRegisterInfo(X, 0);
80 return X;
81}
82
84 unsigned SyntaxVariant,
85 const MCAsmInfo &MAI,
86 const MCInstrInfo &MII,
87 const MCRegisterInfo &MRI) {
88 assert(SyntaxVariant == 0 && "WebAssembly only has one syntax variant");
89 return new WebAssemblyInstPrinter(MAI, MII, MRI);
90}
91
93 MCContext &Ctx) {
94 return createWebAssemblyMCCodeEmitter(MCII, Ctx);
95}
96
97static MCAsmBackend *createAsmBackend(const Target & /*T*/,
98 const MCSubtargetInfo &STI,
99 const MCRegisterInfo & /*MRI*/,
100 const MCTargetOptions & /*Options*/) {
102}
103
105 StringRef FS) {
106 return createWebAssemblyMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
107}
108
109static MCTargetStreamer *
111 return new WebAssemblyTargetWasmStreamer(S);
112}
113
114static MCTargetStreamer *
116 MCInstPrinter * /*InstPrint*/) {
117 return new WebAssemblyTargetAsmStreamer(S, OS);
118}
119
121 return new WebAssemblyTargetNullStreamer(S);
122}
123
124// Force static initialization.
126 for (Target *T :
128 // Register the MC asm info.
130
131 // Register the MC instruction info.
133
134 // Register the MC register info.
136
137 // Register the MCInstPrinter.
139
140 // Register the MC code emitter.
142
143 // Register the ASM Backend.
145
146 // Register the MC subtarget info.
148
149 // Register the object target streamer.
152 // Register the asm target streamer.
154 // Register the null target streamer.
156 }
157}
unsigned const MachineRegisterInfo * MRI
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:128
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static LVOptions Options
Definition: LVOptions.cpp:25
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
This class prints an WebAssembly MCInst to wasm file syntax.
This file contains the declaration of the WebAssemblyMCAsmInfo class.
static MCAsmInfo * createMCAsmInfo(const MCRegisterInfo &, const Triple &TT, const MCTargetOptions &Options)
static MCRegisterInfo * createMCRegisterInfo(const Triple &)
static MCInstPrinter * createMCInstPrinter(const Triple &, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeWebAssemblyTargetMC()
static MCInstrInfo * createMCInstrInfo()
static MCTargetStreamer * createNullTargetStreamer(MCStreamer &S)
static MCAsmBackend * createAsmBackend(const Target &, const MCSubtargetInfo &STI, const MCRegisterInfo &, const MCTargetOptions &)
static MCTargetStreamer * createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
static MCTargetStreamer * createAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *)
static MCCodeEmitter * createCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
static MCSubtargetInfo * createMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
This file provides WebAssembly-specific target descriptions.
This file registers the WebAssembly target.
This file declares WebAssembly-specific target streamer classes.
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:42
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:21
Context object for machine code objects.
Definition: MCContext.h:83
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:46
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:26
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Streaming machine code generation interface.
Definition: MCStreamer.h:213
Generic base class for all target subtargets.
const Triple & getTargetTriple() const
Target specific streamer interface.
Definition: MCStreamer.h:94
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
This part is for ascii assembly output.
This part is for Wasm object output.
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
cl::opt< bool > WasmEnableEH
cl::opt< bool > WasmEnableSjLj
cl::opt< bool > WasmEnableExnref
cl::opt< bool > WasmEnableEmEH
cl::opt< bool > WasmEnableEmSjLj
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
MCCodeEmitter * createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
MCAsmBackend * createWebAssemblyAsmBackend(const Triple &TT)
Target & getTheWebAssemblyTarget32()
Target & getTheWebAssemblyTarget64()
RegisterMCAsmInfoFn - Helper template for registering a target assembly info implementation.
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
static void RegisterMCSubtargetInfo(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for the given target.
static void RegisterObjectTargetStreamer(Target &T, Target::ObjectTargetStreamerCtorTy Fn)
static void RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn)
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
RegisterMCInstPrinter - Register a MCInstPrinter implementation for the given target.
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target.
static void RegisterAsmTargetStreamer(Target &T, Target::AsmTargetStreamerCtorTy Fn)