NVPTXSubtarget.h revision 276479
1239310Sdim//=====-- NVPTXSubtarget.h - Define Subtarget for the NVPTX ---*- C++ -*--====//
2239310Sdim//
3239310Sdim//                     The LLVM Compiler Infrastructure
4239310Sdim//
5239310Sdim// This file is distributed under the University of Illinois Open Source
6239310Sdim// License. See LICENSE.TXT for details.
7239310Sdim//
8239310Sdim//===----------------------------------------------------------------------===//
9239310Sdim//
10239310Sdim// This file declares the NVPTX specific subclass of TargetSubtarget.
11239310Sdim//
12239310Sdim//===----------------------------------------------------------------------===//
13239310Sdim
14239310Sdim#ifndef NVPTXSUBTARGET_H
15239310Sdim#define NVPTXSUBTARGET_H
16239310Sdim
17249423Sdim#include "NVPTX.h"
18276479Sdim#include "NVPTXFrameLowering.h"
19276479Sdim#include "NVPTXISelLowering.h"
20276479Sdim#include "NVPTXInstrInfo.h"
21276479Sdim#include "NVPTXRegisterInfo.h"
22276479Sdim#include "llvm/IR/DataLayout.h"
23276479Sdim#include "llvm/Target/TargetSelectionDAGInfo.h"
24239310Sdim#include "llvm/Target/TargetSubtargetInfo.h"
25276479Sdim#include <string>
26239310Sdim
27239310Sdim#define GET_SUBTARGETINFO_HEADER
28239310Sdim#include "NVPTXGenSubtargetInfo.inc"
29239310Sdim
30239310Sdimnamespace llvm {
31239310Sdim
32239310Sdimclass NVPTXSubtarget : public NVPTXGenSubtargetInfo {
33261991Sdim  virtual void anchor();
34239310Sdim  std::string TargetName;
35239310Sdim  NVPTX::DrvInterface drvInterface;
36239310Sdim  bool Is64Bit;
37239310Sdim
38243830Sdim  // PTX version x.y is represented as 10*x+y, e.g. 3.1 == 31
39243830Sdim  unsigned PTXVersion;
40243830Sdim
41243830Sdim  // SM version x.y is represented as 10*x+y, e.g. 3.1 == 31
42243830Sdim  unsigned int SmVersion;
43243830Sdim
44276479Sdim  const DataLayout DL; // Calculates type size & alignment
45276479Sdim  NVPTXInstrInfo InstrInfo;
46276479Sdim  NVPTXTargetLowering TLInfo;
47276479Sdim  TargetSelectionDAGInfo TSInfo;
48276479Sdim
49276479Sdim  // NVPTX does not have any call stack frame, but need a NVPTX specific
50276479Sdim  // FrameLowering class because TargetFrameLowering is abstract.
51276479Sdim  NVPTXFrameLowering FrameLowering;
52276479Sdim
53239310Sdimpublic:
54239310Sdim  /// This constructor initializes the data members to match that
55239310Sdim  /// of the specified module.
56239310Sdim  ///
57239310Sdim  NVPTXSubtarget(const std::string &TT, const std::string &CPU,
58276479Sdim                 const std::string &FS, const TargetMachine &TM, bool is64Bit);
59239310Sdim
60276479Sdim  const TargetFrameLowering *getFrameLowering() const { return &FrameLowering; }
61276479Sdim  const NVPTXInstrInfo *getInstrInfo() const { return &InstrInfo; }
62276479Sdim  const DataLayout *getDataLayout() const { return &DL; }
63276479Sdim  const NVPTXRegisterInfo *getRegisterInfo() const {
64276479Sdim    return &InstrInfo.getRegisterInfo();
65276479Sdim  }
66276479Sdim  const NVPTXTargetLowering *getTargetLowering() const { return &TLInfo; }
67276479Sdim  const TargetSelectionDAGInfo *getSelectionDAGInfo() const { return &TSInfo; }
68276479Sdim
69239310Sdim  bool hasBrkPt() const { return SmVersion >= 11; }
70239310Sdim  bool hasAtomRedG32() const { return SmVersion >= 11; }
71239310Sdim  bool hasAtomRedS32() const { return SmVersion >= 12; }
72239310Sdim  bool hasAtomRedG64() const { return SmVersion >= 12; }
73239310Sdim  bool hasAtomRedS64() const { return SmVersion >= 20; }
74239310Sdim  bool hasAtomRedGen32() const { return SmVersion >= 20; }
75239310Sdim  bool hasAtomRedGen64() const { return SmVersion >= 20; }
76239310Sdim  bool hasAtomAddF32() const { return SmVersion >= 20; }
77239310Sdim  bool hasVote() const { return SmVersion >= 12; }
78239310Sdim  bool hasDouble() const { return SmVersion >= 13; }
79239310Sdim  bool reqPTX20() const { return SmVersion >= 20; }
80239310Sdim  bool hasF32FTZ() const { return SmVersion >= 20; }
81239310Sdim  bool hasFMAF32() const { return SmVersion >= 20; }
82239310Sdim  bool hasFMAF64() const { return SmVersion >= 13; }
83249423Sdim  bool hasLDG() const { return SmVersion >= 32; }
84276479Sdim  bool hasLDU() const { return ((SmVersion >= 20) && (SmVersion < 30)); }
85239310Sdim  bool hasGenericLdSt() const { return SmVersion >= 20; }
86276479Sdim  inline bool hasHWROT32() const { return SmVersion >= 32; }
87276479Sdim  inline bool hasSWROT32() const {
88276479Sdim    return ((SmVersion >= 20) && (SmVersion < 32));
89276479Sdim  }
90249423Sdim  inline bool hasROT32() const { return hasHWROT32() || hasSWROT32(); }
91239310Sdim  inline bool hasROT64() const { return SmVersion >= 20; }
92239310Sdim
93276479Sdim  bool hasImageHandles() const {
94276479Sdim    // Enable handles for Kepler+, where CUDA supports indirect surfaces and
95276479Sdim    // textures
96276479Sdim    if (getDrvInterface() == NVPTX::CUDA)
97276479Sdim      return (SmVersion >= 30);
98276479Sdim
99276479Sdim    // Disabled, otherwise
100276479Sdim    return false;
101276479Sdim  }
102239310Sdim  bool is64Bit() const { return Is64Bit; }
103239310Sdim
104239310Sdim  unsigned int getSmVersion() const { return SmVersion; }
105239310Sdim  NVPTX::DrvInterface getDrvInterface() const { return drvInterface; }
106239310Sdim  std::string getTargetName() const { return TargetName; }
107239310Sdim
108243830Sdim  unsigned getPTXVersion() const { return PTXVersion; }
109243830Sdim
110276479Sdim  NVPTXSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
111239310Sdim  void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
112239310Sdim};
113239310Sdim
114239310Sdim} // End llvm namespace
115239310Sdim
116249423Sdim#endif // NVPTXSUBTARGET_H
117