xref: /freebsd/contrib/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
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/Target/TargetMachine.h"
20 #include <optional>
21 
22 namespace llvm {
23 
24 class WebAssemblyTargetMachine final : public LLVMTargetMachine {
25   std::unique_ptr<TargetLoweringObjectFile> TLOF;
26   mutable StringMap<std::unique_ptr<WebAssemblySubtarget>> SubtargetMap;
27   bool UsesMultivalueABI = false;
28 
29 public:
30   WebAssemblyTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
31                            StringRef FS, const TargetOptions &Options,
32                            std::optional<Reloc::Model> RM,
33                            std::optional<CodeModel::Model> CM,
34                            CodeGenOptLevel OL, bool JIT);
35 
36   ~WebAssemblyTargetMachine() override;
37 
38   const WebAssemblySubtarget *getSubtargetImpl() const;
39   const WebAssemblySubtarget *getSubtargetImpl(std::string CPU,
40                                                std::string FS) const;
41   const WebAssemblySubtarget *
42   getSubtargetImpl(const Function &F) const override;
43 
44   // Pass Pipeline Configuration
45   TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
46 
getObjFileLowering()47   TargetLoweringObjectFile *getObjFileLowering() const override {
48     return TLOF.get();
49   }
50 
51   MachineFunctionInfo *
52   createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F,
53                             const TargetSubtargetInfo *STI) const override;
54 
55   TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
56 
usesPhysRegsForValues()57   bool usesPhysRegsForValues() const override { return false; }
58 
59   yaml::MachineFunctionInfo *createDefaultFuncInfoYAML() const override;
60   yaml::MachineFunctionInfo *
61   convertFuncInfoToYAML(const MachineFunction &MF) const override;
62   bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &,
63                                 PerFunctionMIParsingState &PFS,
64                                 SMDiagnostic &Error,
65                                 SMRange &SourceRange) const override;
66 
usesMultivalueABI()67   bool usesMultivalueABI() const { return UsesMultivalueABI; }
68 };
69 
70 } // end namespace llvm
71 
72 #endif
73