blob: bf0b9543b897f73b9c394dc772623b68a369a1a0 [file] [log] [blame]
Tom Stellard75aadc22012-12-11 21:25:42 +00001//===-- 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/// \brief The AMDGPU TargetMachine interface definition for hw codgen targets.
12//
13//===----------------------------------------------------------------------===//
14
Matt Arsenault6b6a2c32016-03-11 08:00:27 +000015#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUTARGETMACHINE_H
16#define LLVM_LIB_TARGET_AMDGPU_AMDGPUTARGETMACHINE_H
Tom Stellard75aadc22012-12-11 21:25:42 +000017
Matt Arsenaultc791f392014-06-23 18:00:31 +000018#include "AMDGPUIntrinsicInfo.h"
Tom Stellard75aadc22012-12-11 21:25:42 +000019#include "AMDGPUSubtarget.h"
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000020#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>
Tom Stellard75aadc22012-12-11 21:25:42 +000027
28namespace llvm {
29
Tom Stellard49f8bfd2015-01-06 18:00:21 +000030//===----------------------------------------------------------------------===//
31// AMDGPU Target Machine (R600+)
32//===----------------------------------------------------------------------===//
33
Tom Stellard75aadc22012-12-11 21:25:42 +000034class AMDGPUTargetMachine : public LLVMTargetMachine {
Tom Stellard49f8bfd2015-01-06 18:00:21 +000035protected:
Tom Stellarde135ffd2015-09-25 21:41:28 +000036 std::unique_ptr<TargetLoweringObjectFile> TLOF;
Eric Christopher34aaf972014-08-04 17:37:43 +000037 AMDGPUIntrinsicInfo IntrinsicInfo;
Tom Stellard75aadc22012-12-11 21:25:42 +000038
Matt Arsenault59c0ffa2016-06-27 20:48:03 +000039 StringRef getGPUName(const Function &F) const;
40 StringRef getFeatureString(const Function &F) const;
41
Tom Stellard75aadc22012-12-11 21:25:42 +000042public:
Tom Stellard5dde1d22016-02-05 18:29:17 +000043 AMDGPUTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
Rafael Espindola8c34dd82016-05-18 22:04:49 +000044 StringRef FS, TargetOptions Options,
45 Optional<Reloc::Model> RM, CodeModel::Model CM,
46 CodeGenOpt::Level OL);
Eugene Zelenko2bc2f332016-12-09 22:06:55 +000047 ~AMDGPUTargetMachine() override;
Mehdi Amini93e1ea12015-03-12 00:07:24 +000048
Matt Arsenault43e92fe2016-06-24 06:30:11 +000049 const AMDGPUSubtarget *getSubtargetImpl() const;
Matt Arsenaultf9245b72016-07-22 17:01:25 +000050 const AMDGPUSubtarget *getSubtargetImpl(const Function &) const override = 0;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000051
Benjamin Kramer8c90fd72014-09-03 11:41:21 +000052 const AMDGPUIntrinsicInfo *getIntrinsicInfo() const override {
53 return &IntrinsicInfo;
54 }
Chandler Carruth8b04c0d2015-02-01 13:20:00 +000055 TargetIRAnalysis getTargetIRAnalysis() override;
Chandler Carruth93dcdc42015-01-31 11:17:59 +000056
Aditya Nandakumara2719322014-11-13 09:26:31 +000057 TargetLoweringObjectFile *getObjFileLowering() const override {
Tom Stellarde135ffd2015-09-25 21:41:28 +000058 return TLOF.get();
Aditya Nandakumara2719322014-11-13 09:26:31 +000059 }
Stanislav Mekhanoshin81598112017-01-26 16:49:08 +000060
61 void adjustPassManager(PassManagerBuilder &) override;
Yaxun Liu8f844f32017-02-07 00:43:21 +000062 /// Get the integer value of a null pointer in the given address space.
63 uint64_t getNullPointerValue(unsigned AddrSpace) const {
64 switch(AddrSpace) {
65 case AMDGPUAS::PRIVATE_ADDRESS:
66 case AMDGPUAS::LOCAL_ADDRESS:
67 case AMDGPUAS::REGION_ADDRESS:
68 return -1;
69 default:
70 return 0;
71 }
72 }
73
Tom Stellard75aadc22012-12-11 21:25:42 +000074};
75
Tom Stellard49f8bfd2015-01-06 18:00:21 +000076//===----------------------------------------------------------------------===//
Tom Stellardc65b3602015-02-11 17:11:50 +000077// R600 Target Machine (R600 -> Cayman)
78//===----------------------------------------------------------------------===//
79
Matt Arsenault6b6a2c32016-03-11 08:00:27 +000080class R600TargetMachine final : public AMDGPUTargetMachine {
Matt Arsenault43e92fe2016-06-24 06:30:11 +000081private:
Matt Arsenault59c0ffa2016-06-27 20:48:03 +000082 mutable StringMap<std::unique_ptr<R600Subtarget>> SubtargetMap;
Tom Stellardc65b3602015-02-11 17:11:50 +000083
84public:
Tom Stellard5dde1d22016-02-05 18:29:17 +000085 R600TargetMachine(const Target &T, const Triple &TT, StringRef CPU,
Rafael Espindola8c34dd82016-05-18 22:04:49 +000086 StringRef FS, TargetOptions Options,
87 Optional<Reloc::Model> RM, CodeModel::Model CM,
88 CodeGenOpt::Level OL);
Tom Stellardde5b7b12015-02-11 17:11:51 +000089
90 TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000091
Matt Arsenault59c0ffa2016-06-27 20:48:03 +000092 const R600Subtarget *getSubtargetImpl(const Function &) const override;
Tom Stellardc65b3602015-02-11 17:11:50 +000093};
94
95//===----------------------------------------------------------------------===//
Tom Stellard49f8bfd2015-01-06 18:00:21 +000096// GCN Target Machine (SI+)
97//===----------------------------------------------------------------------===//
98
Matt Arsenault6b6a2c32016-03-11 08:00:27 +000099class GCNTargetMachine final : public AMDGPUTargetMachine {
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000100private:
Matt Arsenault59c0ffa2016-06-27 20:48:03 +0000101 mutable StringMap<std::unique_ptr<SISubtarget>> SubtargetMap;
Tom Stellard49f8bfd2015-01-06 18:00:21 +0000102
103public:
Tom Stellard5dde1d22016-02-05 18:29:17 +0000104 GCNTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
Rafael Espindola8c34dd82016-05-18 22:04:49 +0000105 StringRef FS, TargetOptions Options,
106 Optional<Reloc::Model> RM, CodeModel::Model CM,
107 CodeGenOpt::Level OL);
Tom Stellardde5b7b12015-02-11 17:11:51 +0000108
109 TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000110
Matt Arsenault59c0ffa2016-06-27 20:48:03 +0000111 const SISubtarget *getSubtargetImpl(const Function &) const override;
Tom Stellard49f8bfd2015-01-06 18:00:21 +0000112};
113
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000114} // end namespace llvm
Tom Stellard75aadc22012-12-11 21:25:42 +0000115
Eugene Zelenko2bc2f332016-12-09 22:06:55 +0000116#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUTARGETMACHINE_H