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 "NVPTXSubtarget.h"
17#include "llvm/CodeGen/CodeGenTargetMachineImpl.h"
18#include <optional>
19#include <utility>
20
21namespace llvm {
22
23/// NVPTXTargetMachine
24///
25class NVPTXTargetMachine : public CodeGenTargetMachineImpl {
26 std::unique_ptr<TargetLoweringObjectFile> TLOF;
27 NVPTXSubtarget Subtarget;
28
29 // Hold Strings that can be free'd all together with NVPTXTargetMachine
30 mutable BumpPtrAllocator StrAlloc;
31 mutable UniqueStringSaver StrPool;
32
33public:
34 NVPTXTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
35 StringRef FS, const TargetOptions &Options,
36 std::optional<Reloc::Model> RM,
37 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
38 bool JIT);
39 ~NVPTXTargetMachine() override;
40 const NVPTXSubtarget *getSubtargetImpl(const Function &) const override {
41 return &Subtarget;
42 }
43 const NVPTXSubtarget *getSubtargetImpl() const { return &Subtarget; }
44 NVPTX::DrvInterface getDrvInterface() const {
45 return getTargetTriple().getOS() == Triple::NVCL ? NVPTX::NVCL
46 : NVPTX::CUDA;
47 }
48 UniqueStringSaver &getStrPool() const { return StrPool; }
49
50 TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
51
52 // Emission of machine code through MCJIT is not supported.
53 bool addPassesToEmitMC(PassManagerBase &, MCContext *&, raw_pwrite_stream &,
54 bool = true) override {
55 return true;
56 }
57 TargetLoweringObjectFile *getObjFileLowering() const override {
58 return TLOF.get();
59 }
60
61 MachineFunctionInfo *
62 createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F,
63 const TargetSubtargetInfo *STI) const override;
64
65 void registerEarlyDefaultAliasAnalyses(AAManager &AAM) override;
66
67 void registerPassBuilderCallbacks(PassBuilder &PB) override;
68
69 Error buildCodeGenPipeline(ModulePassManager &MPM, ModuleAnalysisManager &MAM,
70 raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
71 CodeGenFileType FileType,
72 const CGPassBuilderOption &Opt, MCContext &Ctx,
73 PassInstrumentationCallbacks *PIC) override;
74
75 TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
76
77 bool isMachineVerifierClean() const override { return false; }
78
79 std::pair<const Value *, unsigned>
80 getPredicatedAddrSpace(const Value *V) const override;
81}; // NVPTXTargetMachine.
82
83} // end namespace llvm
84
85#endif
86