blob: 3d52532310ff23688f159a65fbe2bff4a75b8fd2 [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"
Chandler Carruthe96dd892014-04-21 22:55:11 +000015
Chandler Carruthd174b722014-04-22 02:03:14 +000016using namespace llvm;
17
Chandler Carruthe96dd892014-04-21 22:55:11 +000018#define DEBUG_TYPE "nvptx-subtarget"
19
Justin Holewinskiae556d32012-05-04 20:18:50 +000020#define GET_SUBTARGETINFO_ENUM
21#define GET_SUBTARGETINFO_TARGET_DESC
22#define GET_SUBTARGETINFO_CTOR
23#include "NVPTXGenSubtargetInfo.inc"
24
Juergen Ributzkad12ccbd2013-11-19 00:57:56 +000025// Pin the vtable to this file.
26void NVPTXSubtarget::anchor() {}
27
Eric Christopher493f91b2014-06-27 04:33:14 +000028static std::string computeDataLayout(bool is64Bit) {
29 std::string Ret = "e";
Justin Holewinskiae556d32012-05-04 20:18:50 +000030
Eric Christopher493f91b2014-06-27 04:33:14 +000031 if (!is64Bit)
32 Ret += "-p:32:32";
Justin Holewinskib6e6cd32013-06-21 18:51:49 +000033
Eric Christopher493f91b2014-06-27 04:33:14 +000034 Ret += "-i64:64-v16:16-v32:32-n16:32:64";
Justin Holewinskiae556d32012-05-04 20:18:50 +000035
Eric Christopher493f91b2014-06-27 04:33:14 +000036 return Ret;
37}
38
39NVPTXSubtarget &NVPTXSubtarget::initializeSubtargetDependencies(StringRef CPU,
40 StringRef FS) {
41 // Provide the default CPU if we don't have one.
Eric Christopherd8132862014-06-27 02:05:19 +000042 if (CPU.empty() && FS.size())
Justin Holewinskiae556d32012-05-04 20:18:50 +000043 llvm_unreachable("we are not using FeatureStr");
Eric Christopherd8132862014-06-27 02:05:19 +000044 TargetName = CPU.empty() ? "sm_20" : CPU;
45
46 ParseSubtargetFeatures(TargetName, FS);
Justin Holewinskiae556d32012-05-04 20:18:50 +000047
Justin Holewinski602fa5b2014-06-27 18:35:18 +000048 // Set default to PTX 3.2 (CUDA 5.5)
49 if (PTXVersion == 0) {
50 PTXVersion = 32;
51 }
Eric Christopher493f91b2014-06-27 04:33:14 +000052
53 return *this;
54}
55
56NVPTXSubtarget::NVPTXSubtarget(const std::string &TT, const std::string &CPU,
57 const std::string &FS, const TargetMachine &TM,
58 bool is64Bit)
59 : NVPTXGenSubtargetInfo(TT, CPU, FS), Is64Bit(is64Bit), PTXVersion(0),
60 SmVersion(20), DL(computeDataLayout(is64Bit)),
61 InstrInfo(initializeSubtargetDependencies(CPU, FS)),
Aaron Ballman08c0b5a2014-08-01 12:34:58 +000062 TLInfo((const NVPTXTargetMachine &)TM), TSInfo(&DL),
63 FrameLowering(*this) {
Eric Christopher493f91b2014-06-27 04:33:14 +000064
65 Triple T(TT);
66
67 if (T.getOS() == Triple::NVCL)
68 drvInterface = NVPTX::NVCL;
69 else
70 drvInterface = NVPTX::CUDA;
Justin Holewinskiae556d32012-05-04 20:18:50 +000071}