[PATCH] D139213: [llvm][CUDA] Make NVVM Reflect pass look inside ptr casting

Hugh Delaney via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 14 03:12:11 PST 2022


hdelan updated this revision to Diff 482780.
hdelan added a comment.

Changing the approach to define __nvvm_reflect_ocl which can take a const char * in
AS(4) so it can be used in openCL.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139213/new/

https://reviews.llvm.org/D139213

Files:
  llvm/include/llvm/IR/InstrTypes.h
  llvm/lib/Target/NVPTX/NVVMReflect.cpp
  llvm/test/CodeGen/NVPTX/nvvm-reflect-cast.ll
  llvm/test/CodeGen/NVPTX/nvvm-reflect-ocl.ll


Index: llvm/test/CodeGen/NVPTX/nvvm-reflect-ocl.ll
===================================================================
--- llvm/test/CodeGen/NVPTX/nvvm-reflect-ocl.ll
+++ llvm/test/CodeGen/NVPTX/nvvm-reflect-ocl.ll
@@ -8,12 +8,12 @@
 
 @"$str" = private addrspace(4) constant [12 x i8] c"__CUDA_ARCH\00"
 
-declare i32 @__nvvm_reflect(i8*)
+declare i32 @__nvvm_reflect_ocl(i8 addrspace(4)* noundef) 
 
 ; COMMON-LABEL: @foo
 define i32 @foo(float %a, float %b) {
-; COMMON-NOT: call i32 @__nvvm_reflect
-  %reflect = tail call i32 bitcast (i32 (i8*)* @__nvvm_reflect to i32 (i8 addrspace(4)*)*)(i8 addrspace(4)* noundef getelementptr inbounds ([12 x i8], [12 x i8] addrspace(4)* @"$str", i64 0, i64 0))
+; COMMON-NOT: call i32 @__nvvm_reflect_ocl
+  %reflect = tail call i32 @__nvvm_reflect_ocl(i8 addrspace(4)* noundef getelementptr inbounds ([12 x i8], [12 x i8] addrspace(4)* @"$str", i64 0, i64 0))
 ; SM20: ret i32 200  
 ; SM35: ret i32 350  
   ret i32 %reflect
Index: llvm/lib/Target/NVPTX/NVVMReflect.cpp
===================================================================
--- llvm/lib/Target/NVPTX/NVVMReflect.cpp
+++ llvm/lib/Target/NVPTX/NVVMReflect.cpp
@@ -40,6 +40,7 @@
 #include <sstream>
 #include <string>
 #define NVVM_REFLECT_FUNCTION "__nvvm_reflect"
+#define NVVM_REFLECT_OCL_FUNCTION "__nvvm_reflect_ocl"
 
 using namespace llvm;
 
@@ -78,7 +79,8 @@
   if (!NVVMReflectEnabled)
     return false;
 
-  if (F.getName() == NVVM_REFLECT_FUNCTION) {
+  if (F.getName() == NVVM_REFLECT_FUNCTION ||
+      F.getName() == NVVM_REFLECT_OCL_FUNCTION) {
     assert(F.isDeclaration() && "_reflect function should not have a body");
     assert(F.getReturnType()->isIntegerTy() &&
            "_reflect's return type should be integer");
@@ -118,9 +120,8 @@
     if (!Call)
       continue;
     Function *Callee = Call->getCalledFunction();
-    if (!Callee)
-      Callee = Call->getCalledFunctionRemovingPtrCasts();
     if (!Callee || (Callee->getName() != NVVM_REFLECT_FUNCTION &&
+                    Callee->getName() != NVVM_REFLECT_OCL_FUNCTION &&
                     Callee->getIntrinsicID() != Intrinsic::nvvm_reflect))
       continue;
 
Index: llvm/include/llvm/IR/InstrTypes.h
===================================================================
--- llvm/include/llvm/IR/InstrTypes.h
+++ llvm/include/llvm/IR/InstrTypes.h
@@ -1401,13 +1401,6 @@
     return nullptr;
   }
 
-  /// Returns the function called and removes the pointer casting around it
-  Function *getCalledFunctionRemovingPtrCasts() const {
-    if (auto *Operand = getCalledOperand())
-      return dyn_cast_or_null<Function>(Operand->stripPointerCasts());
-    return nullptr;
-  }
-
   /// Return true if the callsite is an indirect call.
   bool isIndirectCall() const;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139213.482780.patch
Type: text/x-patch
Size: 2767 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221214/0c46c2fd/attachment.bin>


More information about the llvm-commits mailing list