Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 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 | #define GET_SUBTARGETINFO_ENUM |
| 16 | #define GET_SUBTARGETINFO_TARGET_DESC |
| 17 | #define GET_SUBTARGETINFO_CTOR |
| 18 | #include "NVPTXGenSubtargetInfo.inc" |
| 19 | |
| 20 | using namespace llvm; |
| 21 | |
| 22 | // Select Driver Interface |
| 23 | #include "llvm/Support/CommandLine.h" |
| 24 | namespace { |
Justin Holewinski | 3639ce2 | 2013-03-30 14:29:21 +0000 | [diff] [blame] | 25 | cl::opt<NVPTX::DrvInterface> DriverInterface( |
| 26 | cl::desc("Choose driver interface:"), |
| 27 | cl::values(clEnumValN(NVPTX::NVCL, "drvnvcl", "Nvidia OpenCL driver"), |
| 28 | clEnumValN(NVPTX::CUDA, "drvcuda", "Nvidia CUDA driver"), |
| 29 | clEnumValN(NVPTX::TEST, "drvtest", "Plain Test"), clEnumValEnd), |
| 30 | cl::init(NVPTX::NVCL)); |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | NVPTXSubtarget::NVPTXSubtarget(const std::string &TT, const std::string &CPU, |
| 34 | const std::string &FS, bool is64Bit) |
Justin Holewinski | 3639ce2 | 2013-03-30 14:29:21 +0000 | [diff] [blame] | 35 | : NVPTXGenSubtargetInfo(TT, CPU, FS), Is64Bit(is64Bit), PTXVersion(0), |
Justin Holewinski | b24fc1c | 2013-03-30 14:29:30 +0000 | [diff] [blame] | 36 | SmVersion(20) { |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 37 | |
| 38 | drvInterface = DriverInterface; |
| 39 | |
| 40 | // Provide the default CPU if none |
Justin Holewinski | b24fc1c | 2013-03-30 14:29:30 +0000 | [diff] [blame] | 41 | std::string defCPU = "sm_20"; |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 42 | |
Justin Holewinski | 08e9cb4 | 2012-11-12 03:16:43 +0000 | [diff] [blame] | 43 | ParseSubtargetFeatures((CPU.empty() ? defCPU : CPU), FS); |
| 44 | |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 45 | // Get the TargetName from the FS if available |
| 46 | if (FS.empty() && CPU.empty()) |
| 47 | TargetName = defCPU; |
| 48 | else if (!CPU.empty()) |
| 49 | TargetName = CPU; |
| 50 | else |
| 51 | llvm_unreachable("we are not using FeatureStr"); |
| 52 | |
Justin Holewinski | 08e9cb4 | 2012-11-12 03:16:43 +0000 | [diff] [blame] | 53 | // We default to PTX 3.1, but we cannot just default to it in the initializer |
| 54 | // since the attribute parser checks if the given option is >= the default. |
| 55 | // So if we set ptx31 as the default, the ptx30 attribute would never match. |
| 56 | // Instead, we use 0 as the default and manually set 31 if the default is |
| 57 | // used. |
| 58 | if (PTXVersion == 0) { |
| 59 | PTXVersion = 31; |
| 60 | } |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 61 | } |