blob: c4d0d6e4193dab9513dc2125262d7d98db353d32 [file] [log] [blame]
Justin Holewinskiae556d32012-05-04 20:18:50 +00001//===- NVPTXSubtarget.cpp - NVPTX Subtarget Information -------------------===//
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 implements the NVPTX specific subclass of TargetSubtarget.
11//
12//===----------------------------------------------------------------------===//
13
14#include "NVPTXSubtarget.h"
15#define GET_SUBTARGETINFO_ENUM
16#define GET_SUBTARGETINFO_TARGET_DESC
17#define GET_SUBTARGETINFO_CTOR
18#include "NVPTXGenSubtargetInfo.inc"
19
20using namespace llvm;
21
Justin Holewinskiae556d32012-05-04 20:18:50 +000022
23NVPTXSubtarget::NVPTXSubtarget(const std::string &TT, const std::string &CPU,
24 const std::string &FS, bool is64Bit)
Justin Holewinski0497ab12013-03-30 14:29:21 +000025 : NVPTXGenSubtargetInfo(TT, CPU, FS), Is64Bit(is64Bit), PTXVersion(0),
Justin Holewinski59fd8ba2013-03-30 14:29:30 +000026 SmVersion(20) {
Justin Holewinskiae556d32012-05-04 20:18:50 +000027
Justin Holewinskib6e6cd32013-06-21 18:51:49 +000028 Triple T(TT);
29
30 if (T.getOS() == Triple::NVCL)
31 drvInterface = NVPTX::NVCL;
32 else
33 drvInterface = NVPTX::CUDA;
Justin Holewinskiae556d32012-05-04 20:18:50 +000034
35 // Provide the default CPU if none
Justin Holewinski59fd8ba2013-03-30 14:29:30 +000036 std::string defCPU = "sm_20";
Justin Holewinskiae556d32012-05-04 20:18:50 +000037
Justin Holewinski1812ee92012-11-12 03:16:43 +000038 ParseSubtargetFeatures((CPU.empty() ? defCPU : CPU), FS);
39
Justin Holewinskiae556d32012-05-04 20:18:50 +000040 // Get the TargetName from the FS if available
41 if (FS.empty() && CPU.empty())
42 TargetName = defCPU;
43 else if (!CPU.empty())
44 TargetName = CPU;
45 else
46 llvm_unreachable("we are not using FeatureStr");
47
Justin Holewinski1812ee92012-11-12 03:16:43 +000048 // We default to PTX 3.1, but we cannot just default to it in the initializer
49 // since the attribute parser checks if the given option is >= the default.
50 // So if we set ptx31 as the default, the ptx30 attribute would never match.
51 // Instead, we use 0 as the default and manually set 31 if the default is
52 // used.
53 if (PTXVersion == 0) {
54 PTXVersion = 31;
55 }
Justin Holewinskiae556d32012-05-04 20:18:50 +000056}