[cfe-dev] allow function declarations in @llvm.compiler.used

Sameer Sahasrabuddhe via cfe-dev cfe-dev at lists.llvm.org
Fri Aug 9 01:28:16 PDT 2019


Hi all,

CodeGenModule::addCompilerUsedGlobal() currently asserts if the global being added is a function
declaration.
https://github.com/llvm/llvm-project/blob/474d70b2204ee082854049ad691ccf435863709a/clang/lib/CodeGen/CodeGenModule.cpp#L1883

Is there is any specific requirement that a global being added here must have a definition? Or in other words, what could go wrong if a function declaration was added to @llvm.compiler.used?

The Clang toolchain for HIP language provides a set of device libraries in bitcode format that are linked into the current module being compiled. But Linker::LinkOnlyNeeded causes unused functions to be dropped while linking in the device libraries. I am working on an implementation that requires specific functions to be retained until calls for them are later generated by an LLVM pass in the AMDGPU target. As far as I can see, the simplest way is to add their declarations to @llvm.compiler.used. This has to be done before LinkInModules() is invoked in CodeGenAction. 

Sameer.



More information about the cfe-dev mailing list