10b57cec5SDimitry Andric //===- NVPTXSubtarget.cpp - NVPTX Subtarget Information -------------------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // This file implements the NVPTX specific subclass of TargetSubtarget. 100b57cec5SDimitry Andric // 110b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric #include "NVPTXSubtarget.h" 140b57cec5SDimitry Andric #include "NVPTXTargetMachine.h" 150b57cec5SDimitry Andric 160b57cec5SDimitry Andric using namespace llvm; 170b57cec5SDimitry Andric 180b57cec5SDimitry Andric #define DEBUG_TYPE "nvptx-subtarget" 190b57cec5SDimitry Andric 200b57cec5SDimitry Andric #define GET_SUBTARGETINFO_ENUM 210b57cec5SDimitry Andric #define GET_SUBTARGETINFO_TARGET_DESC 220b57cec5SDimitry Andric #define GET_SUBTARGETINFO_CTOR 230b57cec5SDimitry Andric #include "NVPTXGenSubtargetInfo.inc" 240b57cec5SDimitry Andric 250b57cec5SDimitry Andric static cl::opt<bool> 260b57cec5SDimitry Andric NoF16Math("nvptx-no-f16-math", cl::ZeroOrMore, cl::Hidden, 270b57cec5SDimitry Andric cl::desc("NVPTX Specific: Disable generation of f16 math ops."), 280b57cec5SDimitry Andric cl::init(false)); 290b57cec5SDimitry Andric 300b57cec5SDimitry Andric // Pin the vtable to this file. 310b57cec5SDimitry Andric void NVPTXSubtarget::anchor() {} 320b57cec5SDimitry Andric 330b57cec5SDimitry Andric NVPTXSubtarget &NVPTXSubtarget::initializeSubtargetDependencies(StringRef CPU, 340b57cec5SDimitry Andric StringRef FS) { 350b57cec5SDimitry Andric // Provide the default CPU if we don't have one. 365ffd83dbSDimitry Andric TargetName = std::string(CPU.empty() ? "sm_20" : CPU); 370b57cec5SDimitry Andric 38*e8d8bef9SDimitry Andric ParseSubtargetFeatures(TargetName, /*TuneCPU*/ TargetName, FS); 390b57cec5SDimitry Andric 400b57cec5SDimitry Andric // Set default to PTX 3.2 (CUDA 5.5) 410b57cec5SDimitry Andric if (PTXVersion == 0) { 420b57cec5SDimitry Andric PTXVersion = 32; 430b57cec5SDimitry Andric } 440b57cec5SDimitry Andric 450b57cec5SDimitry Andric return *this; 460b57cec5SDimitry Andric } 470b57cec5SDimitry Andric 480b57cec5SDimitry Andric NVPTXSubtarget::NVPTXSubtarget(const Triple &TT, const std::string &CPU, 490b57cec5SDimitry Andric const std::string &FS, 500b57cec5SDimitry Andric const NVPTXTargetMachine &TM) 51*e8d8bef9SDimitry Andric : NVPTXGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), PTXVersion(0), 52*e8d8bef9SDimitry Andric SmVersion(20), TM(TM), InstrInfo(), 53*e8d8bef9SDimitry Andric TLInfo(TM, initializeSubtargetDependencies(CPU, FS)), FrameLowering() {} 540b57cec5SDimitry Andric 550b57cec5SDimitry Andric bool NVPTXSubtarget::hasImageHandles() const { 560b57cec5SDimitry Andric // Enable handles for Kepler+, where CUDA supports indirect surfaces and 570b57cec5SDimitry Andric // textures 580b57cec5SDimitry Andric if (TM.getDrvInterface() == NVPTX::CUDA) 590b57cec5SDimitry Andric return (SmVersion >= 30); 600b57cec5SDimitry Andric 610b57cec5SDimitry Andric // Disabled, otherwise 620b57cec5SDimitry Andric return false; 630b57cec5SDimitry Andric } 640b57cec5SDimitry Andric 650b57cec5SDimitry Andric bool NVPTXSubtarget::allowFP16Math() const { 660b57cec5SDimitry Andric return hasFP16Math() && NoF16Math == false; 670b57cec5SDimitry Andric } 68