1 //===-- AMDGPUTargetMachine.h - AMDGPU TargetMachine Interface --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// \file
11 /// The AMDGPU TargetMachine interface definition for hw codgen targets.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUTARGETMACHINE_H
16 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUTARGETMACHINE_H
17 
18 #include "AMDGPUIntrinsicInfo.h"
19 #include "AMDGPUSubtarget.h"
20 #include "llvm/ADT/Optional.h"
21 #include "llvm/ADT/StringMap.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/Analysis/TargetTransformInfo.h"
24 #include "llvm/Support/CodeGen.h"
25 #include "llvm/Target/TargetMachine.h"
26 #include <memory>
27 
28 namespace llvm {
29 
30 //===----------------------------------------------------------------------===//
31 // AMDGPU Target Machine (R600+)
32 //===----------------------------------------------------------------------===//
33 
34 class AMDGPUTargetMachine : public LLVMTargetMachine {
35 protected:
36   std::unique_ptr<TargetLoweringObjectFile> TLOF;
37 
38   StringRef getGPUName(const Function &F) const;
39   StringRef getFeatureString(const Function &F) const;
40 
41 public:
42   static bool EnableLateStructurizeCFG;
43   static bool EnableFunctionCalls;
44 
45   AMDGPUTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
46                       StringRef FS, TargetOptions Options,
47                       Optional<Reloc::Model> RM, Optional<CodeModel::Model> CM,
48                       CodeGenOpt::Level OL);
49   ~AMDGPUTargetMachine() override;
50 
51   const TargetSubtargetInfo *getSubtargetImpl() const;
52   const TargetSubtargetInfo *getSubtargetImpl(const Function &) const override = 0;
53 
getObjFileLowering()54   TargetLoweringObjectFile *getObjFileLowering() const override {
55     return TLOF.get();
56   }
57 
58   void adjustPassManager(PassManagerBuilder &) override;
59 
60   /// Get the integer value of a null pointer in the given address space.
getNullPointerValue(unsigned AddrSpace)61   uint64_t getNullPointerValue(unsigned AddrSpace) const {
62     return (AddrSpace == AMDGPUAS::LOCAL_ADDRESS ||
63             AddrSpace == AMDGPUAS::REGION_ADDRESS) ? -1 : 0;
64   }
65 };
66 
67 //===----------------------------------------------------------------------===//
68 // R600 Target Machine (R600 -> Cayman)
69 //===----------------------------------------------------------------------===//
70 
71 class R600TargetMachine final : public AMDGPUTargetMachine {
72 private:
73   mutable StringMap<std::unique_ptr<R600Subtarget>> SubtargetMap;
74 
75 public:
76   R600TargetMachine(const Target &T, const Triple &TT, StringRef CPU,
77                     StringRef FS, TargetOptions Options,
78                     Optional<Reloc::Model> RM, Optional<CodeModel::Model> CM,
79                     CodeGenOpt::Level OL, bool JIT);
80 
81   TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
82 
83   const R600Subtarget *getSubtargetImpl(const Function &) const override;
84 
85   TargetTransformInfo getTargetTransformInfo(const Function &F) override;
86 
isMachineVerifierClean()87   bool isMachineVerifierClean() const override {
88     return false;
89   }
90 };
91 
92 //===----------------------------------------------------------------------===//
93 // GCN Target Machine (SI+)
94 //===----------------------------------------------------------------------===//
95 
96 class GCNTargetMachine final : public AMDGPUTargetMachine {
97 private:
98   AMDGPUIntrinsicInfo IntrinsicInfo;
99   mutable StringMap<std::unique_ptr<GCNSubtarget>> SubtargetMap;
100 
101 public:
102   GCNTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
103                    StringRef FS, TargetOptions Options,
104                    Optional<Reloc::Model> RM, Optional<CodeModel::Model> CM,
105                    CodeGenOpt::Level OL, bool JIT);
106 
107   TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
108 
109   const GCNSubtarget *getSubtargetImpl(const Function &) const override;
110 
111   TargetTransformInfo getTargetTransformInfo(const Function &F) override;
112 
getIntrinsicInfo()113   const AMDGPUIntrinsicInfo *getIntrinsicInfo() const override {
114     return &IntrinsicInfo;
115   }
116 
useIPRA()117   bool useIPRA() const override {
118     return true;
119   }
120 };
121 
122 } // end namespace llvm
123 
124 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUTARGETMACHINE_H
125