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
22namespace llvm {
23
24namespace WebAssembly {
25// Exception handling / setjmp-longjmp handling command-line options
26extern cl::opt<bool> WasmDisableExplicitLocals;
27extern cl::opt<bool> WasmEnableEmEH; // asm.js-style EH
28extern cl::opt<bool> WasmEnableEmSjLj; // asm.js-style SjLJ
29extern cl::opt<bool> WasmEnableEH; // EH using Wasm EH instructions
30extern cl::opt<bool> WasmEnableSjLj; // SjLj using Wasm EH instructions
31extern cl::opt<bool> WasmUseLegacyEH; // Legacy Wasm EH
32} // namespace WebAssembly
33
34class WebAssemblyTargetMachine final : public CodeGenTargetMachineImpl {
35 std::unique_ptr<TargetLoweringObjectFile> TLOF;
36 mutable StringMap<std::unique_ptr<WebAssemblySubtarget>> SubtargetMap;
37 bool UsesMultivalueABI = false;
38
39public:
40 WebAssemblyTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
41 StringRef FS, const TargetOptions &Options,
42 std::optional<Reloc::Model> RM,
43 std::optional<CodeModel::Model> CM,
44 CodeGenOptLevel OL, bool JIT);
45
46 ~WebAssemblyTargetMachine() override;
47
48 const WebAssemblySubtarget *getSubtargetImpl() const;
49 const WebAssemblySubtarget *getSubtargetImpl(std::string CPU,
50 std::string FS) const;
51 const WebAssemblySubtarget *
52 getSubtargetImpl(const Function &F) const override;
53
54 // Pass Pipeline Configuration
55 TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
56
57 TargetLoweringObjectFile *getObjFileLowering() const override {
58 return TLOF.get();
59 }
60
61 MachineFunctionInfo *
62 createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F,
63 const TargetSubtargetInfo *STI) const override;
64
65 TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
66
67 bool usesPhysRegsForValues() const override { return false; }
68
69 yaml::MachineFunctionInfo *createDefaultFuncInfoYAML() const override;
70 yaml::MachineFunctionInfo *
71 convertFuncInfoToYAML(const MachineFunction &MF) const override;
72 bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &,
73 PerFunctionMIParsingState &PFS,
74 SMDiagnostic &Error,
75 SMRange &SourceRange) const override;
76
77 bool usesMultivalueABI() const { return UsesMultivalueABI; }
78
79 void registerPassBuilderCallbacks(PassBuilder &PbB) override;
80
81 Error buildCodeGenPipeline(ModulePassManager &MPM, ModuleAnalysisManager &MAM,
82 raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
83 CodeGenFileType FileType,
84 const CGPassBuilderOption &Opt, MCContext &Ctx,
85 PassInstrumentationCallbacks *PIC) override;
86};
87
88} // end namespace llvm
89
90#endif
91