178 lines · plain
1//- WebAssembly.td - Describe the WebAssembly Target Machine --*- tablegen -*-//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-exception6//7//===----------------------------------------------------------------------===//8///9/// \file10/// This is a target description file for the WebAssembly architecture,11/// which is also known as "wasm".12///13//===----------------------------------------------------------------------===//14 15//===----------------------------------------------------------------------===//16// Target-independent interfaces which we are implementing17//===----------------------------------------------------------------------===//18 19include "llvm/Target/Target.td"20 21//===----------------------------------------------------------------------===//22// WebAssembly Subtarget features.23//===----------------------------------------------------------------------===//24 25def FeatureAtomics : SubtargetFeature<"atomics", "HasAtomics", "true",26 "Enable Atomics">;27 28def FeatureBulkMemory :29 SubtargetFeature<"bulk-memory", "HasBulkMemory", "true",30 "Enable bulk memory operations">;31 32def FeatureBulkMemoryOpt :33 SubtargetFeature<"bulk-memory-opt", "HasBulkMemoryOpt", "true",34 "Enable bulk memory optimization operations">;35 36def FeatureCallIndirectOverlong :37 SubtargetFeature<"call-indirect-overlong", "HasCallIndirectOverlong", "true",38 "Enable overlong encoding for call_indirect immediates">;39 40def FeatureExceptionHandling :41 SubtargetFeature<"exception-handling", "HasExceptionHandling", "true",42 "Enable Wasm exception handling">;43 44def FeatureExtendedConst :45 SubtargetFeature<"extended-const", "HasExtendedConst", "true",46 "Enable extended const expressions">;47 48def FeatureFP16 :49 SubtargetFeature<"fp16", "HasFP16", "true",50 "Enable FP16 instructions">;51 52def FeatureGC : SubtargetFeature<"gc", "HasGC", "true", "Enable wasm gc">;53 54def FeatureMultiMemory :55 SubtargetFeature<"multimemory", "HasMultiMemory", "true",56 "Enable multiple memories">;57 58def FeatureMultivalue :59 SubtargetFeature<"multivalue",60 "HasMultivalue", "true",61 "Enable multivalue blocks, instructions, and functions">;62 63def FeatureMutableGlobals :64 SubtargetFeature<"mutable-globals", "HasMutableGlobals", "true",65 "Enable mutable globals">;66 67def FeatureNontrappingFPToInt :68 SubtargetFeature<"nontrapping-fptoint",69 "HasNontrappingFPToInt", "true",70 "Enable non-trapping float-to-int conversion operators">;71 72def FeatureReferenceTypes :73 SubtargetFeature<"reference-types", "HasReferenceTypes", "true",74 "Enable reference types">;75 76def FeatureRelaxedSIMD :77 SubtargetFeature<"relaxed-simd", "SIMDLevel", "RelaxedSIMD",78 "Enable relaxed-simd instructions">;79 80def FeatureSignExt :81 SubtargetFeature<"sign-ext", "HasSignExt", "true",82 "Enable sign extension operators">;83 84def FeatureSIMD128 : SubtargetFeature<"simd128", "SIMDLevel", "SIMD128",85 "Enable 128-bit SIMD">;86 87def FeatureTailCall :88 SubtargetFeature<"tail-call", "HasTailCall", "true",89 "Enable tail call instructions">;90 91def FeatureWideArithmetic :92 SubtargetFeature<"wide-arithmetic", "HasWideArithmetic", "true",93 "Enable wide-arithmetic instructions">;94 95//===----------------------------------------------------------------------===//96// Architectures.97//===----------------------------------------------------------------------===//98 99//===----------------------------------------------------------------------===//100// Register File Description101//===----------------------------------------------------------------------===//102 103include "WebAssemblyRegisterInfo.td"104 105//===----------------------------------------------------------------------===//106// Instruction Descriptions107//===----------------------------------------------------------------------===//108 109include "WebAssemblyInstrInfo.td"110 111def WASM64 : HwMode<[HasAddr64]>;112 113def wasm_ptr_rc : RegClassByHwMode<114 [DefaultMode, WASM64],115 [I32, I64]>;116 117defm : RemapAllTargetPseudoPointerOperands<wasm_ptr_rc>;118 119def WebAssemblyInstrInfo : InstrInfo;120 121//===----------------------------------------------------------------------===//122// WebAssembly Processors supported.123//===----------------------------------------------------------------------===//124 125// Minimal Viable Product.126def : ProcessorModel<"mvp", NoSchedModel, []>;127 128// Generic processor: latest stable version.129//130// This includes features that have achieved phase 4 of the standards process,131// and that are expected to work for most users in the current time, with132// consideration given to available support in relevant engines and tools, and133// the importance of the features.134def : ProcessorModel<"generic", NoSchedModel,135 [FeatureBulkMemory, FeatureBulkMemoryOpt,136 FeatureCallIndirectOverlong, FeatureMultivalue,137 FeatureMutableGlobals, FeatureNontrappingFPToInt,138 FeatureReferenceTypes, FeatureSignExt]>;139 140// Lime1: <https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#lime1>141def : ProcessorModel<"lime1", NoSchedModel,142 [FeatureBulkMemoryOpt, FeatureCallIndirectOverlong,143 FeatureExtendedConst, FeatureMultivalue,144 FeatureMutableGlobals, FeatureNontrappingFPToInt,145 FeatureSignExt]>;146 147// Latest and greatest experimental version of WebAssembly. Bugs included!148def : ProcessorModel<"bleeding-edge", NoSchedModel,149 [FeatureAtomics, FeatureBulkMemory, FeatureBulkMemoryOpt,150 FeatureCallIndirectOverlong, FeatureExceptionHandling,151 FeatureExtendedConst, FeatureFP16, FeatureGC,152 FeatureMultiMemory, FeatureMultivalue, FeatureMutableGlobals,153 FeatureNontrappingFPToInt, FeatureRelaxedSIMD,154 FeatureReferenceTypes, FeatureSIMD128,155 FeatureSignExt, FeatureTailCall]>;156 157//===----------------------------------------------------------------------===//158// Target Declaration159//===----------------------------------------------------------------------===//160 161def WebAssemblyAsmParser : AsmParser {162 // The physical register names are not in the binary format or asm text163 let ShouldEmitMatchRegisterName = 0;164}165 166def WebAssemblyAsmWriter : AsmWriter {167 string AsmWriterClassName = "InstPrinter";168 int PassSubtarget = 0;169 int Variant = 0;170 bit isMCAsmWriter = 1;171}172 173def WebAssembly : Target {174 let InstructionSet = WebAssemblyInstrInfo;175 let AssemblyParsers = [WebAssemblyAsmParser];176 let AssemblyWriters = [WebAssemblyAsmWriter];177}178