1239310Sdim//===- NVPTXSubtarget.cpp - NVPTX Subtarget Information -------------------===//
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 implements the NVPTX specific subclass of TargetSubtarget.
11239310Sdim//
12239310Sdim//===----------------------------------------------------------------------===//
13239310Sdim
14239310Sdim#include "NVPTXSubtarget.h"
15239310Sdim#define GET_SUBTARGETINFO_ENUM
16239310Sdim#define GET_SUBTARGETINFO_TARGET_DESC
17239310Sdim#define GET_SUBTARGETINFO_CTOR
18239310Sdim#include "NVPTXGenSubtargetInfo.inc"
19239310Sdim
20239310Sdimusing namespace llvm;
21239310Sdim
22239310Sdim
23263508Sdim// Pin the vtable to this file.
24263508Sdimvoid NVPTXSubtarget::anchor() {}
25263508Sdim
26239310SdimNVPTXSubtarget::NVPTXSubtarget(const std::string &TT, const std::string &CPU,
27239310Sdim                               const std::string &FS, bool is64Bit)
28249423Sdim    : NVPTXGenSubtargetInfo(TT, CPU, FS), Is64Bit(is64Bit), PTXVersion(0),
29249423Sdim      SmVersion(20) {
30239310Sdim
31263508Sdim  Triple T(TT);
32239310Sdim
33263508Sdim  if (T.getOS() == Triple::NVCL)
34263508Sdim    drvInterface = NVPTX::NVCL;
35263508Sdim  else
36263508Sdim    drvInterface = NVPTX::CUDA;
37263508Sdim
38239310Sdim  // Provide the default CPU if none
39249423Sdim  std::string defCPU = "sm_20";
40239310Sdim
41243830Sdim  ParseSubtargetFeatures((CPU.empty() ? defCPU : CPU), FS);
42243830Sdim
43239310Sdim  // Get the TargetName from the FS if available
44239310Sdim  if (FS.empty() && CPU.empty())
45239310Sdim    TargetName = defCPU;
46239310Sdim  else if (!CPU.empty())
47239310Sdim    TargetName = CPU;
48239310Sdim  else
49239310Sdim    llvm_unreachable("we are not using FeatureStr");
50239310Sdim
51243830Sdim  // We default to PTX 3.1, but we cannot just default to it in the initializer
52243830Sdim  // since the attribute parser checks if the given option is >= the default.
53243830Sdim  // So if we set ptx31 as the default, the ptx30 attribute would never match.
54243830Sdim  // Instead, we use 0 as the default and manually set 31 if the default is
55243830Sdim  // used.
56243830Sdim  if (PTXVersion == 0) {
57243830Sdim    PTXVersion = 31;
58243830Sdim  }
59239310Sdim}
60