From 04310f4dd7b5356688353a5bfeac559acf6ce47c Mon Sep 17 00:00:00 2001 From: Philip Pfaffe Date: Thu, 14 Jun 2018 08:54:55 +0000 Subject: [PATCH] Simplify the implementation of getCUDALibDeviceFunction. NFC. Summary: The function is currently awfully complicated. Drop the IILE and use StringRef over std::string. Reviewers: Meinersbur, grosser, bollu Reviewed By: Meinersbur Subscribers: nemanjai, kbarton, bollu, llvm-commits, pollydev Differential Revision: https://reviews.llvm.org/D48070 git-svn-id: https://llvm.org/svn/llvm-project/polly/trunk@334695 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/PPCGCodeGeneration.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/CodeGen/PPCGCodeGeneration.cpp b/lib/CodeGen/PPCGCodeGeneration.cpp index 1b8d857c..3a7a832f 100644 --- a/lib/CodeGen/PPCGCodeGeneration.cpp +++ b/lib/CodeGen/PPCGCodeGeneration.cpp @@ -1398,7 +1398,7 @@ const std::map IntrinsicToLibdeviceFunc = { {"llvm.powi.f64", "powi"}, {"llvm.powi.f32", "powif"}}; -/// Return the corresponding CUDA libdevice function name for @p F. +/// Return the corresponding CUDA libdevice function name @p Name. /// Note that this function will try to convert instrinsics in the list /// IntrinsicToLibdeviceFunc into libdevice functions. /// This is because some intrinsics such as `exp` @@ -1407,17 +1407,13 @@ const std::map IntrinsicToLibdeviceFunc = { /// so that we use intrinsics whenever possible. /// /// Return "" if we are not compiling for CUDA. -std::string getCUDALibDeviceFuntion(Function *F) { - auto FnName = [&]() -> const std::string { - auto It = IntrinsicToLibdeviceFunc.find(F->getName()); - if (It != IntrinsicToLibdeviceFunc.end()) - return It->second; +std::string getCUDALibDeviceFuntion(StringRef Name) { + auto It = IntrinsicToLibdeviceFunc.find(Name); + if (It != IntrinsicToLibdeviceFunc.end()) + return getCUDALibDeviceFuntion(It->second); - return std::string(F->getName()); - }(); - - if (CUDALibDeviceFunctions.count(FnName)) - return "__nv_" + FnName; + if (CUDALibDeviceFunctions.count(Name)) + return ("__nv_" + Name).str(); return ""; } @@ -1430,7 +1426,7 @@ static bool isValidFunctionInKernel(llvm::Function *F, bool AllowLibDevice) { // "llvm.copysign". const StringRef Name = F->getName(); - if (AllowLibDevice && getCUDALibDeviceFuntion(F).length() > 0) + if (AllowLibDevice && getCUDALibDeviceFuntion(Name).length() > 0) return true; return F->isIntrinsic() && @@ -2389,7 +2385,7 @@ bool GPUNodeBuilder::requiresCUDALibDevice() { if (!F.isDeclaration()) continue; - const std::string CUDALibDeviceFunc = getCUDALibDeviceFuntion(&F); + const std::string CUDALibDeviceFunc = getCUDALibDeviceFuntion(F.getName()); if (CUDALibDeviceFunc.length() != 0) { // We need to handle the case where a module looks like this: // @expf(..) -- 2.11.4.GIT