diff options
author | dim <dim@FreeBSD.org> | 2016-12-26 20:36:37 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2016-12-26 20:36:37 +0000 |
commit | 06210ae42d418d50d8d9365d5c9419308ae9e7ee (patch) | |
tree | ab60b4cdd6e430dda1f292a46a77ddb744723f31 /contrib/llvm/lib/Target/NVPTX/NVVMReflect.cpp | |
parent | 2dd166267f53df1c3748b4325d294b9b839de74b (diff) | |
download | FreeBSD-src-06210ae42d418d50d8d9365d5c9419308ae9e7ee.zip FreeBSD-src-06210ae42d418d50d8d9365d5c9419308ae9e7ee.tar.gz |
MFC r309124:
Upgrade our copies of clang, llvm, lldb, compiler-rt and libc++ to 3.9.0
release, and add lld 3.9.0. Also completely revamp the build system for
clang, llvm, lldb and their related tools.
Please note that from 3.5.0 onwards, clang, llvm and lldb require C++11
support to build; see UPDATING for more information.
Release notes for llvm, clang and lld are available here:
<http://llvm.org/releases/3.9.0/docs/ReleaseNotes.html>
<http://llvm.org/releases/3.9.0/tools/clang/docs/ReleaseNotes.html>
<http://llvm.org/releases/3.9.0/tools/lld/docs/ReleaseNotes.html>
Thanks to Ed Maste, Bryan Drewery, Andrew Turner, Antoine Brodin and Jan
Beich for their help.
Relnotes: yes
MFC r309147:
Pull in r282174 from upstream llvm trunk (by Krzysztof Parzyszek):
[PPC] Set SP after loading data from stack frame, if no red zone is
present
Follow-up to r280705: Make sure that the SP is only restored after
all data is loaded from the stack frame, if there is no red zone.
This completes the fix for
https://llvm.org/bugs/show_bug.cgi?id=26519.
Differential Revision: https://reviews.llvm.org/D24466
Reported by: Mark Millard
PR: 214433
MFC r309149:
Pull in r283060 from upstream llvm trunk (by Hal Finkel):
[PowerPC] Refactor soft-float support, and enable PPC64 soft float
This change enables soft-float for PowerPC64, and also makes
soft-float disable all vector instruction sets for both 32-bit and
64-bit modes. This latter part is necessary because the PPC backend
canonicalizes many Altivec vector types to floating-point types, and
so soft-float breaks scalarization support for many operations. Both
for embedded targets and for operating-system kernels desiring
soft-float support, it seems reasonable that disabling hardware
floating-point also disables vector instructions (embedded targets
without hardware floating point support are unlikely to have Altivec,
etc. and operating system kernels desiring not to use floating-point
registers to lower syscall cost are unlikely to want to use vector
registers either). If someone needs this to work, we'll need to
change the fact that we promote many Altivec operations to act on
v4f32. To make it possible to disable Altivec when soft-float is
enabled, hardware floating-point support needs to be expressed as a
positive feature, like the others, and not a negative feature,
because target features cannot have dependencies on the disabling of
some other feature. So +soft-float has now become -hard-float.
Fixes PR26970.
Pull in r283061 from upstream clang trunk (by Hal Finkel):
[PowerPC] Enable soft-float for PPC64, and +soft-float -> -hard-float
Enable soft-float support on PPC64, as the backend now supports it.
Also, the backend now uses -hard-float instead of +soft-float, so set
the target features accordingly.
Fixes PR26970.
Reported by: Mark Millard
PR: 214433
MFC r309212:
Add a few missed clang 3.9.0 files to OptionalObsoleteFiles.
MFC r309262:
Fix packaging for clang, lldb and lld 3.9.0
During the upgrade of clang/llvm etc to 3.9.0 in r309124, the PACKAGE
directive in the usr.bin/clang/*.mk files got dropped accidentally.
Restore it, with a few minor changes and additions:
* Correct license in clang.ucl to NCSA
* Add PACKAGE=clang for clang and most of the "ll" tools
* Put lldb in its own package
* Put lld in its own package
Reviewed by: gjb, jmallett
Differential Revision: https://reviews.freebsd.org/D8666
MFC r309656:
During the bootstrap phase, when building the minimal llvm library on
PowerPC, add lib/Support/Atomic.cpp. This is needed because upstream
llvm revision r271821 disabled the use of std::call_once, which causes
some fallback functions from Atomic.cpp to be used instead.
Reported by: Mark Millard
PR: 214902
MFC r309835:
Tentatively apply https://reviews.llvm.org/D18730 to work around gcc PR
70528 (bogus error: constructor required before non-static data member).
This should fix buildworld with the external gcc package.
Reported by: https://jenkins.freebsd.org/job/FreeBSD_HEAD_amd64_gcc/
MFC r310194:
Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to
3.9.1 release.
Please note that from 3.5.0 onwards, clang, llvm and lldb require C++11
support to build; see UPDATING for more information.
Release notes for llvm, clang and lld will be available here:
<http://releases.llvm.org/3.9.1/docs/ReleaseNotes.html>
<http://releases.llvm.org/3.9.1/tools/clang/docs/ReleaseNotes.html>
<http://releases.llvm.org/3.9.1/tools/lld/docs/ReleaseNotes.html>
Relnotes: yes
Diffstat (limited to 'contrib/llvm/lib/Target/NVPTX/NVVMReflect.cpp')
-rw-r--r-- | contrib/llvm/lib/Target/NVPTX/NVVMReflect.cpp | 178 |
1 files changed, 74 insertions, 104 deletions
diff --git a/contrib/llvm/lib/Target/NVPTX/NVVMReflect.cpp b/contrib/llvm/lib/Target/NVPTX/NVVMReflect.cpp index 20ab5db..e0c35e7 100644 --- a/contrib/llvm/lib/Target/NVPTX/NVVMReflect.cpp +++ b/contrib/llvm/lib/Target/NVPTX/NVVMReflect.cpp @@ -7,20 +7,26 @@ // //===----------------------------------------------------------------------===// // -// This pass replaces occurrences of __nvvm_reflect("string") with an -// integer based on -nvvm-reflect-list string=<int> option given to this pass. -// If an undefined string value is seen in a call to __nvvm_reflect("string"), -// a default value of 0 will be used. +// 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. +// +// If we see an unknown string, we replace its call with 0. // //===----------------------------------------------------------------------===// #include "NVPTX.h" -#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" +#include "llvm/IR/InstIterator.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/Module.h" @@ -31,11 +37,8 @@ #include "llvm/Support/raw_os_ostream.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Scalar.h" -#include <map> #include <sstream> #include <string> -#include <vector> - #define NVVM_REFLECT_FUNCTION "__nvvm_reflect" using namespace llvm; @@ -45,31 +48,21 @@ using namespace llvm; namespace llvm { void initializeNVVMReflectPass(PassRegistry &); } namespace { -class NVVMReflect : public ModulePass { +class NVVMReflect : public FunctionPass { private: StringMap<int> VarMap; - typedef DenseMap<std::string, int>::iterator VarMapIter; public: static char ID; - NVVMReflect() : ModulePass(ID) { - initializeNVVMReflectPass(*PassRegistry::getPassRegistry()); - VarMap.clear(); - } + NVVMReflect() : NVVMReflect(StringMap<int>()) {} NVVMReflect(const StringMap<int> &Mapping) - : ModulePass(ID) { + : FunctionPass(ID), VarMap(Mapping) { initializeNVVMReflectPass(*PassRegistry::getPassRegistry()); - for (StringMap<int>::const_iterator I = Mapping.begin(), E = Mapping.end(); - I != E; ++I) { - VarMap[(*I).getKey()] = (*I).getValue(); - } + setVarMap(); } - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.setPreservesAll(); - } - bool runOnModule(Module &) override; + bool runOnFunction(Function &) override; private: bool handleFunction(Function *ReflectFunction); @@ -77,11 +70,8 @@ private: }; } -ModulePass *llvm::createNVVMReflectPass() { - return new NVVMReflect(); -} - -ModulePass *llvm::createNVVMReflectPass(const StringMap<int>& Mapping) { +FunctionPass *llvm::createNVVMReflectPass() { return new NVVMReflect(); } +FunctionPass *llvm::createNVVMReflectPass(const StringMap<int> &Mapping) { return new NVVMReflect(Mapping); } @@ -123,30 +113,35 @@ void NVVMReflect::setVarMap() { } } -bool NVVMReflect::handleFunction(Function *ReflectFunction) { - // Validate _reflect function - assert(ReflectFunction->isDeclaration() && - "_reflect function should not have a body"); - assert(ReflectFunction->getReturnType()->isIntegerTy() && - "_reflect's return type should be integer"); +bool NVVMReflect::runOnFunction(Function &F) { + if (!NVVMReflectEnabled) + return false; + + if (F.getName() == NVVM_REFLECT_FUNCTION) { + assert(F.isDeclaration() && "_reflect function should not have a body"); + assert(F.getReturnType()->isIntegerTy() && + "_reflect's return type should be integer"); + return false; + } - std::vector<Instruction *> ToRemove; + SmallVector<Instruction *, 4> ToRemove; - // Go through the uses of ReflectFunction in this Function. - // Each of them should a CallInst with a ConstantArray argument. - // First validate that. If the c-string corresponding to the - // ConstantArray can be found successfully, see if it can be - // found in VarMap. If so, replace the uses of CallInst with the - // value found in VarMap. If not, replace the use with value 0. + // Go through the calls in this function. Each call to __nvvm_reflect or + // llvm.nvvm.reflect should be a CallInst with a ConstantArray argument. + // First validate that. If the c-string corresponding to the ConstantArray can + // be found successfully, see if it can be found in VarMap. If so, replace the + // uses of CallInst with the value found in VarMap. If not, replace the use + // with value 0. - // IR for __nvvm_reflect calls differs between CUDA versions: + // The IR for __nvvm_reflect calls differs between CUDA versions. + // // CUDA 6.5 and earlier uses this sequence: // %ptr = tail call i8* @llvm.nvvm.ptr.constant.to.gen.p0i8.p4i8 // (i8 addrspace(4)* getelementptr inbounds // ([8 x i8], [8 x i8] addrspace(4)* @str, i32 0, i32 0)) // %reflect = tail call i32 @__nvvm_reflect(i8* %ptr) // - // Value returned by Sym->getOperand(0) is a Constant with a + // The value returned by Sym->getOperand(0) is a Constant with a // ConstantDataSequential operand which can be converted to string and used // for lookup. // @@ -157,31 +152,37 @@ bool NVVMReflect::handleFunction(Function *ReflectFunction) { // // In this case, we get a Constant with a GlobalVariable operand and we need // to dig deeper to find its initializer with the string we'll use for lookup. - - for (User *U : ReflectFunction->users()) { - assert(isa<CallInst>(U) && "Only a call instruction can use _reflect"); - CallInst *Reflect = cast<CallInst>(U); - - assert((Reflect->getNumOperands() == 2) && - "Only one operand expect for _reflect function"); - // In cuda, we will have an extra constant-to-generic conversion of - // the string. - const Value *Str = Reflect->getArgOperand(0); - if (isa<CallInst>(Str)) { - // CUDA path - const CallInst *ConvCall = cast<CallInst>(Str); + for (Instruction &I : instructions(F)) { + CallInst *Call = dyn_cast<CallInst>(&I); + if (!Call) + continue; + Function *Callee = Call->getCalledFunction(); + if (!Callee || (Callee->getName() != NVVM_REFLECT_FUNCTION && + Callee->getIntrinsicID() != Intrinsic::nvvm_reflect)) + continue; + + // FIXME: Improve error handling here and elsewhere in this pass. + assert(Call->getNumOperands() == 2 && + "Wrong number of operands to __nvvm_reflect function"); + + // In cuda 6.5 and earlier, we will have an extra constant-to-generic + // conversion of the string. + const Value *Str = Call->getArgOperand(0); + if (const CallInst *ConvCall = dyn_cast<CallInst>(Str)) { + // FIXME: Add assertions about ConvCall. Str = ConvCall->getArgOperand(0); } assert(isa<ConstantExpr>(Str) && - "Format of _reflect function not recognized"); + "Format of __nvvm__reflect function not recognized"); const ConstantExpr *GEP = cast<ConstantExpr>(Str); const Value *Sym = GEP->getOperand(0); - assert(isa<Constant>(Sym) && "Format of _reflect function not recognized"); + assert(isa<Constant>(Sym) && + "Format of __nvvm_reflect function not recognized"); const Value *Operand = cast<Constant>(Sym)->getOperand(0); if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Operand)) { - // For CUDA-7.0 style __nvvm_reflect calls we need to find operand's + // For CUDA-7.0 style __nvvm_reflect calls, we need to find the operand's // initializer. assert(GV->hasInitializer() && "Format of _reflect function not recognized"); @@ -194,57 +195,26 @@ bool NVVMReflect::handleFunction(Function *ReflectFunction) { assert(cast<ConstantDataSequential>(Operand)->isCString() && "Format of _reflect function not recognized"); - std::string ReflectArg = - cast<ConstantDataSequential>(Operand)->getAsString(); - + StringRef ReflectArg = cast<ConstantDataSequential>(Operand)->getAsString(); ReflectArg = ReflectArg.substr(0, ReflectArg.size() - 1); DEBUG(dbgs() << "Arg of _reflect : " << ReflectArg << "\n"); int ReflectVal = 0; // The default value is 0 - if (VarMap.find(ReflectArg) != VarMap.end()) { - ReflectVal = VarMap[ReflectArg]; - } - Reflect->replaceAllUsesWith( - ConstantInt::get(Reflect->getType(), ReflectVal)); - ToRemove.push_back(Reflect); - } - if (ToRemove.size() == 0) - return false; - - for (unsigned i = 0, e = ToRemove.size(); i != e; ++i) - ToRemove[i]->eraseFromParent(); - return true; -} - -bool NVVMReflect::runOnModule(Module &M) { - if (!NVVMReflectEnabled) - return false; - - setVarMap(); - - - bool Res = false; - std::string Name; - Type *Tys[1]; - Type *I8Ty = Type::getInt8Ty(M.getContext()); - Function *ReflectFunction; - - // Check for standard overloaded versions of llvm.nvvm.reflect - - for (unsigned i = 0; i != 5; ++i) { - Tys[0] = PointerType::get(I8Ty, i); - Name = Intrinsic::getName(Intrinsic::nvvm_reflect, Tys); - ReflectFunction = M.getFunction(Name); - if(ReflectFunction != 0) { - Res |= handleFunction(ReflectFunction); + 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); } - ReflectFunction = M.getFunction(NVVM_REFLECT_FUNCTION); - // If reflect function is not used, then there will be - // no entry in the module. - if (ReflectFunction != 0) - Res |= handleFunction(ReflectFunction); + for (Instruction *I : ToRemove) + I->eraseFromParent(); - return Res; + return ToRemove.size() > 0; } |