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