xref: /freebsd/contrib/llvm-project/llvm/lib/Target/NVPTX/NVPTXTargetMachine.h (revision dd41de95a84d979615a2ef11df6850622bf6184e)
1 //===-- NVPTXTargetMachine.h - Define TargetMachine for NVPTX ---*- 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 NVPTX specific subclass of TargetMachine.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_TARGET_NVPTX_NVPTXTARGETMACHINE_H
14 #define LLVM_LIB_TARGET_NVPTX_NVPTXTARGETMACHINE_H
15 
16 #include "ManagedStringPool.h"
17 #include "NVPTXSubtarget.h"
18 #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
19 #include "llvm/CodeGen/TargetFrameLowering.h"
20 #include "llvm/Target/TargetMachine.h"
21 
22 namespace llvm {
23 
24 /// NVPTXTargetMachine
25 ///
26 class NVPTXTargetMachine : public LLVMTargetMachine {
27   bool is64bit;
28   // Use 32-bit pointers for accessing const/local/short AS.
29   bool UseShortPointers;
30   std::unique_ptr<TargetLoweringObjectFile> TLOF;
31   NVPTX::DrvInterface drvInterface;
32   NVPTXSubtarget Subtarget;
33 
34   // Hold Strings that can be free'd all together with NVPTXTargetMachine
35   ManagedStringPool ManagedStrPool;
36 
37 public:
38   NVPTXTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
39                      StringRef FS, const TargetOptions &Options,
40                      Optional<Reloc::Model> RM, Optional<CodeModel::Model> CM,
41                      CodeGenOpt::Level OP, bool is64bit);
42 
43   ~NVPTXTargetMachine() override;
44   const NVPTXSubtarget *getSubtargetImpl(const Function &) const override {
45     return &Subtarget;
46   }
47   const NVPTXSubtarget *getSubtargetImpl() const { return &Subtarget; }
48   bool is64Bit() const { return is64bit; }
49   bool useShortPointers() const { return UseShortPointers; }
50   NVPTX::DrvInterface getDrvInterface() const { return drvInterface; }
51   ManagedStringPool *getManagedStrPool() const {
52     return const_cast<ManagedStringPool *>(&ManagedStrPool);
53   }
54 
55   TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
56 
57   // Emission of machine code through MCJIT is not supported.
58   bool addPassesToEmitMC(PassManagerBase &, MCContext *&, raw_pwrite_stream &,
59                          bool = true) override {
60     return true;
61   }
62   TargetLoweringObjectFile *getObjFileLowering() const override {
63     return TLOF.get();
64   }
65 
66   void adjustPassManager(PassManagerBuilder &) override;
67 
68   TargetTransformInfo getTargetTransformInfo(const Function &F) override;
69 
70   bool isMachineVerifierClean() const override {
71     return false;
72   }
73 }; // NVPTXTargetMachine.
74 
75 class NVPTXTargetMachine32 : public NVPTXTargetMachine {
76   virtual void anchor();
77 public:
78   NVPTXTargetMachine32(const Target &T, const Triple &TT, StringRef CPU,
79                        StringRef FS, const TargetOptions &Options,
80                        Optional<Reloc::Model> RM, Optional<CodeModel::Model> CM,
81                        CodeGenOpt::Level OL, bool JIT);
82 };
83 
84 class NVPTXTargetMachine64 : public NVPTXTargetMachine {
85   virtual void anchor();
86 public:
87   NVPTXTargetMachine64(const Target &T, const Triple &TT, StringRef CPU,
88                        StringRef FS, const TargetOptions &Options,
89                        Optional<Reloc::Model> RM, Optional<CodeModel::Model> CM,
90                        CodeGenOpt::Level OL, bool JIT);
91 };
92 
93 } // end namespace llvm
94 
95 #endif
96