diff options
-rw-r--r-- | llvm/include/llvm/Analysis/TargetLibraryInfo.def | 5 | ||||
-rw-r--r-- | llvm/lib/Analysis/TargetLibraryInfo.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/Transforms/IPO/InferFunctionAttrs.cpp | 9 | ||||
-rw-r--r-- | llvm/test/Transforms/InferFunctionAttrs/annotate.ll | 5 |
4 files changed, 24 insertions, 1 deletions
diff --git a/llvm/include/llvm/Analysis/TargetLibraryInfo.def b/llvm/include/llvm/Analysis/TargetLibraryInfo.def index 7798e3c8824..b2a593d67dc 100644 --- a/llvm/include/llvm/Analysis/TargetLibraryInfo.def +++ b/llvm/include/llvm/Analysis/TargetLibraryInfo.def @@ -195,6 +195,11 @@ TLI_DEFINE_STRING_INTERNAL("__memmove_chk") /// void *__memset_chk(void *s, char v, size_t n, size_t s1size); TLI_DEFINE_ENUM_INTERNAL(memset_chk) TLI_DEFINE_STRING_INTERNAL("__memset_chk") + +// int __nvvm_reflect(const char *) +TLI_DEFINE_ENUM_INTERNAL(nvvm_reflect) +TLI_DEFINE_STRING_INTERNAL("__nvvm_reflect") + /// double __sincospi_stret(double x); TLI_DEFINE_ENUM_INTERNAL(sincospi_stret) TLI_DEFINE_STRING_INTERNAL("__sincospi_stret") diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp index 3bd54c47e60..ab667ab7b6a 100644 --- a/llvm/lib/Analysis/TargetLibraryInfo.cpp +++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp @@ -396,8 +396,12 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, // // FIXME: Having no standard library prevents e.g. many fastmath // optimizations, so this situation should be fixed. - if (T.isNVPTX()) + if (T.isNVPTX()) { TLI.disableAllFunctions(); + TLI.setAvailable(LibFunc::nvvm_reflect); + } else { + TLI.setUnavailable(LibFunc::nvvm_reflect); + } TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary); } diff --git a/llvm/lib/Transforms/IPO/InferFunctionAttrs.cpp b/llvm/lib/Transforms/IPO/InferFunctionAttrs.cpp index 16922ab9256..030a6464522 100644 --- a/llvm/lib/Transforms/IPO/InferFunctionAttrs.cpp +++ b/llvm/lib/Transforms/IPO/InferFunctionAttrs.cpp @@ -924,6 +924,15 @@ static bool inferPrototypeAttributes(Function &F, Changed |= setOnlyReadsMemory(F, 2); return Changed; + // int __nvvm_reflect(const char *) + case LibFunc::nvvm_reflect: + if (FTy->getNumParams() != 1 || !isa<PointerType>(FTy->getParamType(0))) + return false; + + Changed |= setDoesNotAccessMemory(F); + Changed |= setDoesNotThrow(F); + return Changed; + default: // FIXME: It'd be really nice to cover all the library functions we're // aware of here. diff --git a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll index 1cb7ab137c0..8ac45df6e7e 100644 --- a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll +++ b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll @@ -1,6 +1,7 @@ ; RUN: opt < %s -inferattrs -S | FileCheck %s ; RUN: opt < %s -passes=inferattrs -S | FileCheck %s ; RUN: opt < %s -mtriple=x86_64-apple-macosx10.8.0 -inferattrs -S | FileCheck -check-prefix=CHECK-POSIX %s +; RUN: opt < %s -mtriple=nvptx -inferattrs -S | FileCheck -check-prefix=CHECK-NVPTX %s declare i8* @fopen(i8*, i8*) ; CHECK: declare noalias i8* @fopen(i8* nocapture readonly, i8* nocapture readonly) [[G0:#[0-9]]] @@ -33,3 +34,7 @@ declare i32 @gettimeofday(i8*, i8*) ; CHECK: attributes [[G1]] = { nounwind readonly } ; CHECK-POSIX: attributes [[G0]] = { nounwind } ; CHECK-POSIX: attributes [[G2]] = { argmemonly } + +declare i32 @__nvvm_reflect(i8*) +; CHECK-NVPTX: declare i32 @__nvvm_reflect(i8*) [[G0:#[0-9]+]] +; CHECK-NVPTX: attributes [[G0]] = { nounwind readnone } |