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