[clang] Correctly link and optimize device libraries with -mlink-builtin-bitcode (PR #69371)

Joseph Huber via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 6 09:21:59 PST 2023


================
@@ -1035,6 +1043,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
     }
   }
 
+  // Re-link against any bitcodes supplied via the -mlink-builtin-bitcode option
+  // Some optimizations may generate new function calls that would not have
+  // been linked pre-optimization (i.e. fused sincos calls generated by
+  // AMDGPULibCalls::fold_sincos.)
+  if (ClRelinkBuiltinBitcodePostop)
----------------
jhuber6 wrote:

So, what I had in mind is that we could make a new `clang` option similar to `-mlink-builtin-bitcode`. This would then be used by the HIP toolchain or similar when constructing the list of files to pass via `-mlink-builtin-bitcode`. We would then simply register those with this secondary pass.

This approach seems much simpler, being a boolean option that just relinks everything, but I somewhat like the idea of `-mlink-builtin-bitcode` being a pre-link operation and having another one for post-linking. That being said, it may not be worth the extra work because this is a huge hack around this ecosystem already.

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


More information about the cfe-commits mailing list