[PATCH] D40573: [NVPTX] Assign valid global names

Jonas Hahnfeld via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 29 14:12:06 PST 2017


Hahnfeld added a comment.

In https://reviews.llvm.org/D40573#939676, @tra wrote:

> There must be some truth in the saying "naming is one of the hardest problems in computer science". :-/


Indeed, and the conflicting requirements listed by Hal makes it even harder to be correct for all cases :-(



================
Comment at: lib/IR/ValueSymbolTable.cpp:54-59
+      // MSVC name mangling but is fine for PTX.
+      if (M && Triple(M->getTargetTriple()).isNVPTX())
+        S << "$";
+      else
+        S << ".";
+    }
----------------
tra wrote:
> This patch addresses "we can't compile generated PTX because LLVM uses illegal characters", but exposes another issue -- having potentially different names on host and device is a problem for CUDA. For some objects host side may need to know what it's called on device side. We need it in order to access it from host (eg cudaMemcpyToSymbol(), or initializing static variables) and we currently assume that the names are the same. If such symbol gets different names on host and device, compilation will succeed, but we'll have problems at runtime.
> 
> Does "." have any special meaning? Can we skip the unique delimiter altogether? 
> 
> If we can't find a suitable way to guarantee identical naming, we'll need a way to have a reliable way to determine the name used on the other side of the compilation.
> 
> 
So the interesting question is: When will this code ever be hit? Most programming languages (including C and C++) obviously don't allow multiple variables of the same name - how would the compiler say which symbol you meant. The use case I've mostly seen is for compiler generated function, `omp_outlined` for example. These can be generated multiple times in the same translation unit and have to get unique names. Do you have another example where this could happen?

I'm not really sure '.' has a special meaning. Maybe @rafael can help because one of his old commits (https://reviews.llvm.org/rL253804) says `For globals it is important to use "foo.1" to help C++ name demangling.`


https://reviews.llvm.org/D40573





More information about the llvm-commits mailing list