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