Fix the ridiculous SubtargetFeatures API where it implicitly expects CPU name to
[oota-llvm.git] / lib / Target / PTX / PTXSubtarget.h
1 //====-- PTXSubtarget.h - Define Subtarget for the PTX ---------*- 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 // This file declares the PTX specific subclass of TargetSubtarget.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef PTX_SUBTARGET_H
15 #define PTX_SUBTARGET_H
16
17 #include "llvm/Target/TargetSubtarget.h"
18
19 namespace llvm {
20   class PTXSubtarget : public TargetSubtarget {
21     public:
22
23       /**
24        * Enumeration of Shader Models supported by the back-end.
25        */
26       enum PTXTargetEnum {
27         PTX_COMPUTE_1_0, /*< Compute Compatibility 1.0 */
28         PTX_COMPUTE_1_1, /*< Compute Compatibility 1.1 */
29         PTX_COMPUTE_1_2, /*< Compute Compatibility 1.2 */
30         PTX_COMPUTE_1_3, /*< Compute Compatibility 1.3 */
31         PTX_COMPUTE_2_0, /*< Compute Compatibility 2.0 */
32         PTX_LAST_COMPUTE,
33
34         PTX_SM_1_0, /*< Shader Model 1.0 */
35         PTX_SM_1_1, /*< Shader Model 1.1 */
36         PTX_SM_1_2, /*< Shader Model 1.2 */
37         PTX_SM_1_3, /*< Shader Model 1.3 */
38         PTX_SM_2_0, /*< Shader Model 2.0 */
39         PTX_SM_2_1, /*< Shader Model 2.1 */
40         PTX_SM_2_2, /*< Shader Model 2.2 */
41         PTX_SM_2_3, /*< Shader Model 2.3 */
42         PTX_LAST_SM
43       };
44
45       /**
46        * Enumeration of PTX versions supported by the back-end.
47        *
48        * Currently, PTX 2.0 is the minimum supported version.
49        */
50       enum PTXVersionEnum {
51         PTX_VERSION_2_0,  /*< PTX Version 2.0 */
52         PTX_VERSION_2_1,  /*< PTX Version 2.1 */
53         PTX_VERSION_2_2,  /*< PTX Version 2.2 */
54         PTX_VERSION_2_3   /*< PTX Version 2.3 */
55       };
56
57   private:
58
59       /// Shader Model supported on the target GPU.
60       PTXTargetEnum PTXTarget;
61
62       /// PTX Language Version.
63       PTXVersionEnum PTXVersion;
64
65       // The native .f64 type is supported on the hardware.
66       bool SupportsDouble;
67
68       // Support the fused-multiply add (FMA) and multiply-add (MAD)
69       // instructions
70       bool SupportsFMA;
71
72       // Use .u64 instead of .u32 for addresses.
73       bool Is64Bit;
74
75     public:
76
77       PTXSubtarget(const std::string &TT, const std::string &CPU,
78                    const std::string &FS, bool is64Bit);
79
80       // Target architecture accessors
81       std::string getTargetString() const;
82
83       std::string getPTXVersionString() const;
84
85       bool supportsDouble() const { return SupportsDouble; }
86
87       bool is64Bit() const { return Is64Bit; }
88
89       bool supportsFMA() const { return SupportsFMA; }
90
91       bool supportsPTX21() const { return PTXVersion >= PTX_VERSION_2_1; }
92
93       bool supportsPTX22() const { return PTXVersion >= PTX_VERSION_2_2; }
94
95       bool supportsPTX23() const { return PTXVersion >= PTX_VERSION_2_3; }
96
97       bool fdivNeedsRoundingMode() const {
98         return (PTXTarget >= PTX_SM_1_3 && PTXTarget < PTX_LAST_SM) ||
99                (PTXTarget >= PTX_COMPUTE_1_3 && PTXTarget < PTX_LAST_COMPUTE);
100       }
101
102       bool fmadNeedsRoundingMode() const {
103         return (PTXTarget >= PTX_SM_1_3 && PTXTarget < PTX_LAST_SM) ||
104                (PTXTarget >= PTX_COMPUTE_1_3 && PTXTarget < PTX_LAST_COMPUTE);
105       }
106
107       bool useParamSpaceForDeviceArgs() const {
108         return (PTXTarget >= PTX_SM_2_0 && PTXTarget < PTX_LAST_SM) ||
109                (PTXTarget >= PTX_COMPUTE_2_0 && PTXTarget < PTX_LAST_COMPUTE);
110       }
111
112       void ParseSubtargetFeatures(const std::string &FS,
113                                   const std::string &CPU);
114   }; // class PTXSubtarget
115 } // namespace llvm
116
117 #endif // PTX_SUBTARGET_H