Gleb Popov via llvm-dev
2019-Jul-22 14:34 UTC
[llvm-dev] GlobalVariable I inserted gets removed by LTO
Hello llvm-dev@ I have a pass that puts a global constant data array into the module. And another pass that gets runned by lld during LTO stage. When I look at bytecode files corresponding to source TUs produced by `clang -flto`, I can see GVs inserted by my pass #1. However, when pass #2 gets to run, these GV's are gone. I figured out that passing -mllvm -compute-dead=0 to the linker fixes the problem, but I'm not sure if it is right thing to do. Ideally, I'd like to trick LTO to ignore only mine GVs during compute-dead analysis. I even tried creating another function that "uses" created GV, but it also got deleted. Any hints? Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190722/ff3f9950/attachment.html>
Teresa Johnson via llvm-dev
2019-Jul-22 14:39 UTC
[llvm-dev] GlobalVariable I inserted gets removed by LTO
You should add your GVs to the llvm.used variable or the llvm.compiler.used variable (see https://llvm.org/docs/LangRef.html#the-llvm-used-global-variable). Otherwise it looks globally dead to the linker and LTO. Look at existingcalls to llvm::appendToUsed for examples. Teresa On Mon, Jul 22, 2019 at 7:34 AM Gleb Popov via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hello llvm-dev@ > > I have a pass that puts a global constant data array into the module. And > another pass that gets runned by lld during LTO stage. > > When I look at bytecode files corresponding to source TUs produced by > `clang -flto`, I can see GVs inserted by my pass #1. However, when pass #2 > gets to run, these GV's are gone. > > I figured out that passing -mllvm -compute-dead=0 to the linker fixes the > problem, but I'm not sure if it is right thing to do. Ideally, I'd like to > trick LTO to ignore only mine GVs during compute-dead analysis. > > I even tried creating another function that "uses" created GV, but it also > got deleted. > > Any hints? > > Thanks in advance. > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-- Teresa Johnson | Software Engineer | tejohnson at google.com | -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190722/d541b0ee/attachment.html>
Gleb Popov via llvm-dev
2019-Jul-24 11:57 UTC
[llvm-dev] GlobalVariable I inserted gets removed by LTO
On Mon, Jul 22, 2019 at 6:39 PM Teresa Johnson <tejohnson at google.com> wrote:> You should add your GVs to the llvm.used variable or the > llvm.compiler.used variable (see > https://llvm.org/docs/LangRef.html#the-llvm-used-global-variable). > Otherwise it looks globally dead to the linker and LTO. Look at > existingcalls to llvm::appendToUsed for examples. > > Teresa >Thank you, that worked!> On Mon, Jul 22, 2019 at 7:34 AM Gleb Popov via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> Hello llvm-dev@ >> >> I have a pass that puts a global constant data array into the module. And >> another pass that gets runned by lld during LTO stage. >> >> When I look at bytecode files corresponding to source TUs produced by >> `clang -flto`, I can see GVs inserted by my pass #1. However, when pass #2 >> gets to run, these GV's are gone. >> >> I figured out that passing -mllvm -compute-dead=0 to the linker fixes the >> problem, but I'm not sure if it is right thing to do. Ideally, I'd like to >> trick LTO to ignore only mine GVs during compute-dead analysis. >> >> I even tried creating another function that "uses" created GV, but it >> also got deleted. >> >> Any hints? >> >> Thanks in advance. >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> > > > -- > Teresa Johnson | Software Engineer | tejohnson at google.com | >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190724/ab7bd560/attachment.html>