diff options
author | Justin Lebar <jlebar@google.com> | 2017-01-15 16:54:35 +0000 |
---|---|---|
committer | Justin Lebar <jlebar@google.com> | 2017-01-15 16:54:35 +0000 |
commit | 38746d9718b2623c09e90c8790adfbf00e1b78e9 (patch) | |
tree | db80ddf6c2b15bc18ab2a7890f3d24c35230ddf8 /llvm/lib/Target/NVPTX/NVVMReflect.cpp | |
parent | 6aded2a0e4f7211502a0696ef4044570ccebf95b (diff) | |
download | bcm5719-llvm-38746d9718b2623c09e90c8790adfbf00e1b78e9.tar.gz bcm5719-llvm-38746d9718b2623c09e90c8790adfbf00e1b78e9.zip |
[NVPTX] Let there be One True Way to set NVVMReflect params.
Summary:
Previously there were three ways to inform the NVVMReflect pass whether
you wanted to flush denormals to zero:
* An LLVM command-line option
* Parameters to the NVVMReflect constructor
* Metadata on the module itself.
This change removes the first two, leaving only the third.
The motivation for this change, aside from simplifying things, is that
we want LLVM to be aware of whether it's operating in FTZ mode, so other
passes can use this information. Ideally we'd have a target-generic
piece of metadata on the module. This change moves us in that
direction.
Reviewers: tra
Subscribers: jholewinski, llvm-commits
Differential Revision: https://reviews.llvm.org/D28700
llvm-svn: 292068
Diffstat (limited to 'llvm/lib/Target/NVPTX/NVVMReflect.cpp')
-rw-r--r-- | llvm/lib/Target/NVPTX/NVVMReflect.cpp | 62 |
1 files changed, 9 insertions, 53 deletions
diff --git a/llvm/lib/Target/NVPTX/NVVMReflect.cpp b/llvm/lib/Target/NVPTX/NVVMReflect.cpp index c639c4dc068..152b665d0fd 100644 --- a/llvm/lib/Target/NVPTX/NVVMReflect.cpp +++ b/llvm/lib/Target/NVPTX/NVVMReflect.cpp @@ -10,11 +10,10 @@ // This pass replaces occurrences of __nvvm_reflect("foo") and llvm.nvvm.reflect // with an integer. // -// 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. +// We choose the value we use by looking at metadata in the module itself. Note +// that we intentionally only have one way to choose these values, because other +// parts of LLVM (particularly, InstCombineCall) rely on being able to predict +// the values chosen by this pass. // // If we see an unknown string, we replace its call with 0. // @@ -49,30 +48,17 @@ namespace llvm { void initializeNVVMReflectPass(PassRegistry &); } namespace { class NVVMReflect : public FunctionPass { -private: - StringMap<int> VarMap; - public: static char ID; - NVVMReflect() : NVVMReflect(StringMap<int>()) {} - - NVVMReflect(const StringMap<int> &Mapping) - : FunctionPass(ID), VarMap(Mapping) { + NVVMReflect() : FunctionPass(ID) { initializeNVVMReflectPass(*PassRegistry::getPassRegistry()); - setVarMap(); } bool runOnFunction(Function &) override; - -private: - void setVarMap(); }; } FunctionPass *llvm::createNVVMReflectPass() { return new NVVMReflect(); } -FunctionPass *llvm::createNVVMReflectPass(const StringMap<int> &Mapping) { - return new NVVMReflect(Mapping); -} static cl::opt<bool> NVVMReflectEnabled("nvvm-reflect-enable", cl::init(true), cl::Hidden, @@ -83,35 +69,6 @@ INITIALIZE_PASS(NVVMReflect, "nvvm-reflect", "Replace occurrences of __nvvm_reflect() calls with 0/1", false, false) -static cl::list<std::string> -ReflectList("nvvm-reflect-list", cl::value_desc("name=<int>"), cl::Hidden, - cl::desc("A list of string=num assignments"), - cl::ValueRequired); - -/// The command line can look as follows : -/// -nvvm-reflect-list a=1,b=2 -nvvm-reflect-list c=3,d=0 -R e=2 -/// The strings "a=1,b=2", "c=3,d=0", "e=2" are available in the -/// ReflectList vector. First, each of ReflectList[i] is 'split' -/// using "," as the delimiter. Then each of this part is split -/// using "=" as the delimiter. -void NVVMReflect::setVarMap() { - for (unsigned i = 0, e = ReflectList.size(); i != e; ++i) { - DEBUG(dbgs() << "Option : " << ReflectList[i] << "\n"); - SmallVector<StringRef, 4> NameValList; - StringRef(ReflectList[i]).split(NameValList, ','); - for (unsigned j = 0, ej = NameValList.size(); j != ej; ++j) { - SmallVector<StringRef, 2> NameValPair; - NameValList[j].split(NameValPair, '='); - assert(NameValPair.size() == 2 && "name=val expected"); - std::stringstream ValStream(NameValPair[1]); - int Val; - ValStream >> Val; - assert((!(ValStream.fail())) && "integer value expected"); - VarMap[NameValPair[0]] = Val; - } - } -} - bool NVVMReflect::runOnFunction(Function &F) { if (!NVVMReflectEnabled) return false; @@ -199,11 +156,10 @@ bool NVVMReflect::runOnFunction(Function &F) { DEBUG(dbgs() << "Arg of _reflect : " << ReflectArg << "\n"); int ReflectVal = 0; // The default value is 0 - 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 (ReflectArg == "__CUDA_FTZ") { + // Try to pull __CUDA_FTZ from the nvvm-reflect-ftz module flag. Our + // choice here must be kept in sync with AutoUpgrade, which uses the same + // technique to detect whether ftz is enabled. if (auto *Flag = mdconst::extract_or_null<ConstantInt>( F.getParent()->getModuleFlag("nvvm-reflect-ftz"))) ReflectVal = Flag->getSExtValue(); |