comparison lib/Target/NVPTX/NVVMReflect.cpp @ 147:c2174574ed3a

LLVM 10
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 14 Aug 2019 16:55:33 +0900
parents 803732b1fca8
children
comparison
equal deleted inserted replaced
134:3a76565eade5 147:c2174574ed3a
1 //===- NVVMReflect.cpp - NVVM Emulate conditional compilation -------------===// 1 //===- NVVMReflect.cpp - NVVM Emulate conditional compilation -------------===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // 4 // See https://llvm.org/LICENSE.txt for license information.
5 // This file is distributed under the University of Illinois Open Source 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 // License. See LICENSE.TXT for details.
7 // 6 //
8 //===----------------------------------------------------------------------===// 7 //===----------------------------------------------------------------------===//
9 // 8 //
10 // This pass replaces occurrences of __nvvm_reflect("foo") and llvm.nvvm.reflect 9 // This pass replaces occurrences of __nvvm_reflect("foo") and llvm.nvvm.reflect
11 // with an integer. 10 // with an integer.
48 47
49 namespace { 48 namespace {
50 class NVVMReflect : public FunctionPass { 49 class NVVMReflect : public FunctionPass {
51 public: 50 public:
52 static char ID; 51 static char ID;
53 NVVMReflect() : FunctionPass(ID) { 52 unsigned int SmVersion;
53 NVVMReflect() : NVVMReflect(0) {}
54 explicit NVVMReflect(unsigned int Sm) : FunctionPass(ID), SmVersion(Sm) {
54 initializeNVVMReflectPass(*PassRegistry::getPassRegistry()); 55 initializeNVVMReflectPass(*PassRegistry::getPassRegistry());
55 } 56 }
56 57
57 bool runOnFunction(Function &) override; 58 bool runOnFunction(Function &) override;
58 }; 59 };
59 } 60 }
60 61
61 FunctionPass *llvm::createNVVMReflectPass() { return new NVVMReflect(); } 62 FunctionPass *llvm::createNVVMReflectPass(unsigned int SmVersion) {
63 return new NVVMReflect(SmVersion);
64 }
62 65
63 static cl::opt<bool> 66 static cl::opt<bool>
64 NVVMReflectEnabled("nvvm-reflect-enable", cl::init(true), cl::Hidden, 67 NVVMReflectEnabled("nvvm-reflect-enable", cl::init(true), cl::Hidden,
65 cl::desc("NVVM reflection, enabled by default")); 68 cl::desc("NVVM reflection, enabled by default"));
66 69
151 assert(cast<ConstantDataSequential>(Operand)->isCString() && 154 assert(cast<ConstantDataSequential>(Operand)->isCString() &&
152 "Format of _reflect function not recognized"); 155 "Format of _reflect function not recognized");
153 156
154 StringRef ReflectArg = cast<ConstantDataSequential>(Operand)->getAsString(); 157 StringRef ReflectArg = cast<ConstantDataSequential>(Operand)->getAsString();
155 ReflectArg = ReflectArg.substr(0, ReflectArg.size() - 1); 158 ReflectArg = ReflectArg.substr(0, ReflectArg.size() - 1);
156 DEBUG(dbgs() << "Arg of _reflect : " << ReflectArg << "\n"); 159 LLVM_DEBUG(dbgs() << "Arg of _reflect : " << ReflectArg << "\n");
157 160
158 int ReflectVal = 0; // The default value is 0 161 int ReflectVal = 0; // The default value is 0
159 if (ReflectArg == "__CUDA_FTZ") { 162 if (ReflectArg == "__CUDA_FTZ") {
160 // Try to pull __CUDA_FTZ from the nvvm-reflect-ftz module flag. Our 163 // Try to pull __CUDA_FTZ from the nvvm-reflect-ftz module flag. Our
161 // choice here must be kept in sync with AutoUpgrade, which uses the same 164 // choice here must be kept in sync with AutoUpgrade, which uses the same
162 // technique to detect whether ftz is enabled. 165 // technique to detect whether ftz is enabled.
163 if (auto *Flag = mdconst::extract_or_null<ConstantInt>( 166 if (auto *Flag = mdconst::extract_or_null<ConstantInt>(
164 F.getParent()->getModuleFlag("nvvm-reflect-ftz"))) 167 F.getParent()->getModuleFlag("nvvm-reflect-ftz")))
165 ReflectVal = Flag->getSExtValue(); 168 ReflectVal = Flag->getSExtValue();
169 } else if (ReflectArg == "__CUDA_ARCH") {
170 ReflectVal = SmVersion * 10;
166 } 171 }
167 Call->replaceAllUsesWith(ConstantInt::get(Call->getType(), ReflectVal)); 172 Call->replaceAllUsesWith(ConstantInt::get(Call->getType(), ReflectVal));
168 ToRemove.push_back(Call); 173 ToRemove.push_back(Call);
169 } 174 }
170 175