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