1 //===- 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
16 using namespace llvm;
17
18 #define DEBUG_TYPE "nvptx-subtarget"
19
20 #define GET_SUBTARGETINFO_ENUM
21 #define GET_SUBTARGETINFO_TARGET_DESC
22 #define GET_SUBTARGETINFO_CTOR
23 #include "NVPTXGenSubtargetInfo.inc"
24
25 // Pin the vtable to this file.
anchor()26 void NVPTXSubtarget::anchor() {}
27
computeDataLayout(bool is64Bit)28 static std::string computeDataLayout(bool is64Bit) {
29 std::string Ret = "e";
30
31 if (!is64Bit)
32 Ret += "-p:32:32";
33
34 Ret += "-i64:64-v16:16-v32:32-n16:32:64";
35
36 return Ret;
37 }
38
initializeSubtargetDependencies(StringRef CPU,StringRef FS)39 NVPTXSubtarget &NVPTXSubtarget::initializeSubtargetDependencies(StringRef CPU,
40 StringRef FS) {
41 // Provide the default CPU if we don't have one.
42 if (CPU.empty() && FS.size())
43 llvm_unreachable("we are not using FeatureStr");
44 TargetName = CPU.empty() ? "sm_20" : CPU;
45
46 ParseSubtargetFeatures(TargetName, FS);
47
48 // Set default to PTX 3.2 (CUDA 5.5)
49 if (PTXVersion == 0) {
50 PTXVersion = 32;
51 }
52
53 return *this;
54 }
55
NVPTXSubtarget(const std::string & TT,const std::string & CPU,const std::string & FS,const TargetMachine & TM,bool is64Bit)56 NVPTXSubtarget::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)),
62 TLInfo((const NVPTXTargetMachine &)TM), TSInfo(&DL),
63 FrameLowering(*this) {
64
65 Triple T(TT);
66
67 if (T.getOS() == Triple::NVCL)
68 drvInterface = NVPTX::NVCL;
69 else
70 drvInterface = NVPTX::CUDA;
71 }
72