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 llvm-svn: 334695
This commit is contained in:
parent
7d1448ea72
commit
66a05ad672
|
@ -1398,7 +1398,7 @@ const std::map<std::string, std::string> IntrinsicToLibdeviceFunc = {
|
||||||
{"llvm.powi.f64", "powi"},
|
{"llvm.powi.f64", "powi"},
|
||||||
{"llvm.powi.f32", "powif"}};
|
{"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
|
/// Note that this function will try to convert instrinsics in the list
|
||||||
/// IntrinsicToLibdeviceFunc into libdevice functions.
|
/// IntrinsicToLibdeviceFunc into libdevice functions.
|
||||||
/// This is because some intrinsics such as `exp`
|
/// This is because some intrinsics such as `exp`
|
||||||
|
@ -1407,17 +1407,13 @@ const std::map<std::string, std::string> IntrinsicToLibdeviceFunc = {
|
||||||
/// so that we use intrinsics whenever possible.
|
/// so that we use intrinsics whenever possible.
|
||||||
///
|
///
|
||||||
/// Return "" if we are not compiling for CUDA.
|
/// Return "" if we are not compiling for CUDA.
|
||||||
std::string getCUDALibDeviceFuntion(Function *F) {
|
std::string getCUDALibDeviceFuntion(StringRef Name) {
|
||||||
auto FnName = [&]() -> const std::string {
|
auto It = IntrinsicToLibdeviceFunc.find(Name);
|
||||||
auto It = IntrinsicToLibdeviceFunc.find(F->getName());
|
if (It != IntrinsicToLibdeviceFunc.end())
|
||||||
if (It != IntrinsicToLibdeviceFunc.end())
|
return getCUDALibDeviceFuntion(It->second);
|
||||||
return It->second;
|
|
||||||
|
|
||||||
return std::string(F->getName());
|
if (CUDALibDeviceFunctions.count(Name))
|
||||||
}();
|
return ("__nv_" + Name).str();
|
||||||
|
|
||||||
if (CUDALibDeviceFunctions.count(FnName))
|
|
||||||
return "__nv_" + FnName;
|
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -1430,7 +1426,7 @@ static bool isValidFunctionInKernel(llvm::Function *F, bool AllowLibDevice) {
|
||||||
// "llvm.copysign".
|
// "llvm.copysign".
|
||||||
const StringRef Name = F->getName();
|
const StringRef Name = F->getName();
|
||||||
|
|
||||||
if (AllowLibDevice && getCUDALibDeviceFuntion(F).length() > 0)
|
if (AllowLibDevice && getCUDALibDeviceFuntion(Name).length() > 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return F->isIntrinsic() &&
|
return F->isIntrinsic() &&
|
||||||
|
@ -2389,7 +2385,7 @@ bool GPUNodeBuilder::requiresCUDALibDevice() {
|
||||||
if (!F.isDeclaration())
|
if (!F.isDeclaration())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const std::string CUDALibDeviceFunc = getCUDALibDeviceFuntion(&F);
|
const std::string CUDALibDeviceFunc = getCUDALibDeviceFuntion(F.getName());
|
||||||
if (CUDALibDeviceFunc.length() != 0) {
|
if (CUDALibDeviceFunc.length() != 0) {
|
||||||
// We need to handle the case where a module looks like this:
|
// We need to handle the case where a module looks like this:
|
||||||
// @expf(..)
|
// @expf(..)
|
||||||
|
|
Loading…
Reference in New Issue