diff options
author | Justin Lebar <jlebar@google.com> | 2016-04-01 01:09:07 +0000 |
---|---|---|
committer | Justin Lebar <jlebar@google.com> | 2016-04-01 01:09:07 +0000 |
commit | efcc81cbb4852faec3c0deb20e35225244c67fcb (patch) | |
tree | 523f824d063561e4417d931369b2bc7454304300 /llvm/lib/Target/NVPTX/NVVMReflect.cpp | |
parent | 645c3014a12cc24b75556d93db2ecfa4b99f8635 (diff) | |
download | bcm5719-llvm-efcc81cbb4852faec3c0deb20e35225244c67fcb.tar.gz bcm5719-llvm-efcc81cbb4852faec3c0deb20e35225244c67fcb.zip |
[NVPTX] Read __CUDA_FTZ from module flags in NVVMReflect.
Summary:
Previously the NVVMReflect pass would read its configuration from
command-line flags or a static configuration given to the pass at
instantiation time.
This doesn't quite work for clang's use-case. It needs to pass a value
for __CUDA_FTZ down on a per-module basis. We use a module flag for
this, so the NVVMReflect pass needs to be updated to read said flag.
Reviewers: tra, rnk
Subscribers: cfe-commits, jholewinski
Differential Revision: http://reviews.llvm.org/D18672
llvm-svn: 265090
Diffstat (limited to 'llvm/lib/Target/NVPTX/NVVMReflect.cpp')
-rw-r--r-- | llvm/lib/Target/NVPTX/NVVMReflect.cpp | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/llvm/lib/Target/NVPTX/NVVMReflect.cpp b/llvm/lib/Target/NVPTX/NVVMReflect.cpp index 14f60761966..2f80791a433 100644 --- a/llvm/lib/Target/NVPTX/NVVMReflect.cpp +++ b/llvm/lib/Target/NVPTX/NVVMReflect.cpp @@ -7,11 +7,16 @@ // //===----------------------------------------------------------------------===// // -// This pass replaces occurrences of __nvvm_reflect("string") and -// llvm.nvvm.reflect with an integer based on the value of -nvvm-reflect-list -// string=<int>. +// This pass replaces occurrences of __nvvm_reflect("foo") and llvm.nvvm.reflect +// with an integer. // -// If we see a string not specified in our flags, we replace that call with 0. +// We choose the value we use by looking, in this order, at: +// +// * the -nvvm-reflect-list flag, which has the format "foo=1,bar=42", +// * the StringMap passed to the pass's constructor, and +// * metadata in the module itself. +// +// If we see an unknown string, we replace its call with 0. // //===----------------------------------------------------------------------===// @@ -55,10 +60,9 @@ public: static char ID; NVVMReflect() : NVVMReflect(StringMap<int>()) {} - NVVMReflect(const StringMap<int> &Mapping) : FunctionPass(ID) { + NVVMReflect(const StringMap<int> &Mapping) + : FunctionPass(ID), VarMap(Mapping) { initializeNVVMReflectPass(*PassRegistry::getPassRegistry()); - for (const auto &KV : Mapping) - VarMap[KV.getKey()] = KV.getValue(); setVarMap(); } @@ -206,6 +210,12 @@ bool NVVMReflect::runOnFunction(Function &F) { auto Iter = VarMap.find(ReflectArg); if (Iter != VarMap.end()) ReflectVal = Iter->second; + else if (ReflectArg == "__CUDA_FTZ") { + // Try to pull __CUDA_FTZ from the nvvm-reflect-ftz module flag. + if (auto *Flag = mdconst::extract_or_null<ConstantInt>( + F.getParent()->getModuleFlag("nvvm-reflect-ftz"))) + ReflectVal = Flag->getSExtValue(); + } Call->replaceAllUsesWith(ConstantInt::get(Call->getType(), ReflectVal)); ToRemove.push_back(Call); } |