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