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