xref: /freebsd/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVTargetMachine.h (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1 //===-- RISCVTargetMachine.h - Define TargetMachine for RISC-V --*- 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 // This file declares the RISC-V specific subclass of TargetMachine.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_TARGET_RISCV_RISCVTARGETMACHINE_H
14 #define LLVM_LIB_TARGET_RISCV_RISCVTARGETMACHINE_H
15 
16 #include "MCTargetDesc/RISCVMCTargetDesc.h"
17 #include "RISCVSubtarget.h"
18 #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
19 #include "llvm/IR/DataLayout.h"
20 #include "llvm/Target/TargetMachine.h"
21 #include <optional>
22 
23 namespace llvm {
24 class RISCVTargetMachine : public LLVMTargetMachine {
25   std::unique_ptr<TargetLoweringObjectFile> TLOF;
26   mutable StringMap<std::unique_ptr<RISCVSubtarget>> SubtargetMap;
27 
28 public:
29   RISCVTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
30                      StringRef FS, const TargetOptions &Options,
31                      std::optional<Reloc::Model> RM,
32                      std::optional<CodeModel::Model> CM, CodeGenOpt::Level OL,
33                      bool JIT);
34 
35   const RISCVSubtarget *getSubtargetImpl(const Function &F) const override;
36   // DO NOT IMPLEMENT: There is no such thing as a valid default subtarget,
37   // subtargets are per-function entities based on the target-specific
38   // attributes of each function.
39   const RISCVSubtarget *getSubtargetImpl() const = delete;
40 
41   TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
42 
43   TargetLoweringObjectFile *getObjFileLowering() const override {
44     return TLOF.get();
45   }
46 
47   MachineFunctionInfo *
48   createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F,
49                             const TargetSubtargetInfo *STI) const override;
50 
51   TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
52 
53   bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DstAS) const override;
54 
55   yaml::MachineFunctionInfo *createDefaultFuncInfoYAML() const override;
56   yaml::MachineFunctionInfo *
57   convertFuncInfoToYAML(const MachineFunction &MF) const override;
58   bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &,
59                                 PerFunctionMIParsingState &PFS,
60                                 SMDiagnostic &Error,
61                                 SMRange &SourceRange) const override;
62 };
63 } // namespace llvm
64 
65 #endif
66