[llvm] [NVPTX] Improve NVVMReflect Efficiency (PR #134416)

Alex MacLean via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 9 09:47:31 PDT 2025


================
@@ -39,186 +39,207 @@
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
 #include "llvm/Transforms/Utils/Local.h"
-#include <algorithm>
 #define NVVM_REFLECT_FUNCTION "__nvvm_reflect"
 #define NVVM_REFLECT_OCL_FUNCTION "__nvvm_reflect_ocl"
+// Argument of reflect call to retrive arch number
+#define CUDA_ARCH_NAME "__CUDA_ARCH"
+// Argument of reflect call to retrive ftz mode
+#define CUDA_FTZ_NAME "__CUDA_FTZ"
+// Name of module metadata where ftz mode is stored
+#define CUDA_FTZ_MODULE_NAME "nvvm-reflect-ftz"
 
 using namespace llvm;
 
-#define DEBUG_TYPE "nvptx-reflect"
+#define DEBUG_TYPE "nvvm-reflect"
+
+namespace llvm {
+void initializeNVVMReflectLegacyPassPass(PassRegistry &);
+} // namespace llvm
 
 namespace {
-class NVVMReflect : public FunctionPass {
+class NVVMReflect {
+  // Map from reflect function call arguments to the value to replace the call
+  // with. Should include __CUDA_FTZ and __CUDA_ARCH values.
+  StringMap<unsigned> ReflectMap;
+  bool handleReflectFunction(Module &M, const StringRef ReflectName);
+  void populateReflectMap(Module &M);
+  void foldReflectCall(CallInst *const Call, Constant *const NewValue);
----------------
AlexMaclean wrote:

Even if you were to add `const` on the arguments in the definition of these functions, I don't think it makes sense on the definition. These `const`s are just an implementation detail indicating that in the body you won't be reassigning these variables, they add no information in the declaration.

https://github.com/llvm/llvm-project/pull/134416


More information about the llvm-commits mailing list