1 // WebAssemblyTargetMachine.h - Define TargetMachine for WebAssembly -*- C++ -*- 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 declares the WebAssembly-specific subclass of 11 /// TargetMachine. 12 /// 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYTARGETMACHINE_H 16 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYTARGETMACHINE_H 17 18 #include "WebAssemblySubtarget.h" 19 #include "llvm/CodeGen/CodeGenTargetMachineImpl.h" 20 #include <optional> 21 22 namespace llvm { 23 24 namespace WebAssembly { 25 // Exception handling / setjmp-longjmp handling command-line options 26 extern cl::opt<bool> WasmEnableEmEH; // asm.js-style EH 27 extern cl::opt<bool> WasmEnableEmSjLj; // asm.js-style SjLJ 28 extern cl::opt<bool> WasmEnableEH; // EH using Wasm EH instructions 29 extern cl::opt<bool> WasmEnableSjLj; // SjLj using Wasm EH instructions 30 extern cl::opt<bool> WasmUseLegacyEH; // Legacy Wasm EH 31 } // namespace WebAssembly 32 33 class WebAssemblyTargetMachine final : public CodeGenTargetMachineImpl { 34 std::unique_ptr<TargetLoweringObjectFile> TLOF; 35 mutable StringMap<std::unique_ptr<WebAssemblySubtarget>> SubtargetMap; 36 bool UsesMultivalueABI = false; 37 38 public: 39 WebAssemblyTargetMachine(const Target &T, const Triple &TT, StringRef CPU, 40 StringRef FS, const TargetOptions &Options, 41 std::optional<Reloc::Model> RM, 42 std::optional<CodeModel::Model> CM, 43 CodeGenOptLevel OL, bool JIT); 44 45 ~WebAssemblyTargetMachine() override; 46 47 const WebAssemblySubtarget *getSubtargetImpl() const; 48 const WebAssemblySubtarget *getSubtargetImpl(std::string CPU, 49 std::string FS) const; 50 const WebAssemblySubtarget * 51 getSubtargetImpl(const Function &F) const override; 52 53 // Pass Pipeline Configuration 54 TargetPassConfig *createPassConfig(PassManagerBase &PM) override; 55 56 TargetLoweringObjectFile *getObjFileLowering() const override { 57 return TLOF.get(); 58 } 59 60 MachineFunctionInfo * 61 createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F, 62 const TargetSubtargetInfo *STI) const override; 63 64 TargetTransformInfo getTargetTransformInfo(const Function &F) const override; 65 66 bool usesPhysRegsForValues() const override { return false; } 67 68 yaml::MachineFunctionInfo *createDefaultFuncInfoYAML() const override; 69 yaml::MachineFunctionInfo * 70 convertFuncInfoToYAML(const MachineFunction &MF) const override; 71 bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &, 72 PerFunctionMIParsingState &PFS, 73 SMDiagnostic &Error, 74 SMRange &SourceRange) const override; 75 76 bool usesMultivalueABI() const { return UsesMultivalueABI; } 77 }; 78 79 } // end namespace llvm 80 81 #endif 82