n3v3rm03 via llvm-dev
2019-Jan-19 06:52 UTC
[llvm-dev] Can't find symbol from llvm backend
No, I don't. But I’m sure it is not optimized because I can see this variable in the final binary file emitted. Do you mean if I don’t refer to this variable in the front end, then I can’t see it in the backend? (although it’s in the final binary file) Thank you! 2019年1月19日(土) 2:00 <paul.robinson at sony.com>:> Do you have a use of the new variable as well? If not, it might be > optimized out between the point where you create it and your > MachineFunction pass. > > --paulr > > > > *From:* llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] *On Behalf Of *n3v3rm03 > via llvm-dev > *Sent:* Friday, January 18, 2019 5:57 AM > *To:* llvm-dev at lists.llvm.org > *Subject:* [llvm-dev] Can't find symbol from llvm backend > > > > Hi, I am new to llvm. > > I create a global variable called "test_llvm_var" in the front end > function pass like this: > > > > new GlobalVariable(*m, tmp->getType(), true, > llvm::GlobalValue::ExternalLinkage, tmp, "test_llvm_var"); > > > > where tmp is a function. > > > > Then I tried to access this global variable in the back end > MachineFunctionPass like this: > > > > MCContext& MCC = MF.getContext(); > MCSymbol* MCS = MCC.lookupSymbol("test_llvm_var"); > if (MCS == NULL) { > errs() << ">>> MCSymbol is null\n"; > } > else { > MCS->dump(); > } > > > > (MF is a MachineFunction). > > > > However I always get MCS==NULL, there is no symbol called test_llvm_var in > the backend. > > > > Am I doing something wrong? What I would like to do is to modify the > global variable's value from the backend pass. > > > > Any help would be appreciated. > > Thank you! >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190119/9b0ae764/attachment.html>
n3v3rm03 via llvm-dev
2019-Jan-19 07:02 UTC
[llvm-dev] Can't find symbol from llvm backend
No, I don't. But I’m sure it is not optimized because I can see this variable in the final binary file emitted. Do you mean if I don’t refer to this variable in the front end, then I can’t see it in the backend? (although it’s in the final binary file) Thank you! On Sat, Jan 19, 2019 at 3:52 PM n3v3rm03 <n3v3rm03 at gmail.com> wrote:> No, I don't. But I’m sure it is not optimized because I can see this > variable in the final binary file emitted. > > Do you mean if I don’t refer to this variable in the front end, then I > can’t see it in the backend? (although it’s in the final binary file) > > Thank you! > 2019年1月19日(土) 2:00 <paul.robinson at sony.com>: > >> Do you have a use of the new variable as well? If not, it might be >> optimized out between the point where you create it and your >> MachineFunction pass. >> >> --paulr >> >> >> >> *From:* llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] *On Behalf Of *n3v3rm03 >> via llvm-dev >> *Sent:* Friday, January 18, 2019 5:57 AM >> *To:* llvm-dev at lists.llvm.org >> *Subject:* [llvm-dev] Can't find symbol from llvm backend >> >> >> >> Hi, I am new to llvm. >> >> I create a global variable called "test_llvm_var" in the front end >> function pass like this: >> >> >> >> new GlobalVariable(*m, tmp->getType(), true, >> llvm::GlobalValue::ExternalLinkage, tmp, "test_llvm_var"); >> >> >> >> where tmp is a function. >> >> >> >> Then I tried to access this global variable in the back end >> MachineFunctionPass like this: >> >> >> >> MCContext& MCC = MF.getContext(); >> MCSymbol* MCS = MCC.lookupSymbol("test_llvm_var"); >> if (MCS == NULL) { >> errs() << ">>> MCSymbol is null\n"; >> } >> else { >> MCS->dump(); >> } >> >> >> >> (MF is a MachineFunction). >> >> >> >> However I always get MCS==NULL, there is no symbol called test_llvm_var >> in the backend. >> >> >> >> Am I doing something wrong? What I would like to do is to modify the >> global variable's value from the backend pass. >> >> >> >> Any help would be appreciated. >> >> Thank you! >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190119/fd29b51a/attachment.html>
Craig Topper via llvm-dev
2019-Jan-19 07:11 UTC
[llvm-dev] Can't find symbol from llvm backend
I'm not sure, but I think the MCSymbol won't exist until the AsmPrinter pass runs at the end of the codegen pipeline. ~Craig On Fri, Jan 18, 2019 at 11:02 PM n3v3rm03 via llvm-dev < llvm-dev at lists.llvm.org> wrote:> No, I don't. But I’m sure it is not optimized because I can see this > variable in the final binary file emitted. > > Do you mean if I don’t refer to this variable in the front end, then I > can’t see it in the backend? (although it’s in the final binary file) > > Thank you! > > On Sat, Jan 19, 2019 at 3:52 PM n3v3rm03 <n3v3rm03 at gmail.com> wrote: > >> No, I don't. But I’m sure it is not optimized because I can see this >> variable in the final binary file emitted. >> >> Do you mean if I don’t refer to this variable in the front end, then I >> can’t see it in the backend? (although it’s in the final binary file) >> >> Thank you! >> 2019年1月19日(土) 2:00 <paul.robinson at sony.com>: >> >>> Do you have a use of the new variable as well? If not, it might be >>> optimized out between the point where you create it and your >>> MachineFunction pass. >>> >>> --paulr >>> >>> >>> >>> *From:* llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] *On Behalf Of >>> *n3v3rm03 via llvm-dev >>> *Sent:* Friday, January 18, 2019 5:57 AM >>> *To:* llvm-dev at lists.llvm.org >>> *Subject:* [llvm-dev] Can't find symbol from llvm backend >>> >>> >>> >>> Hi, I am new to llvm. >>> >>> I create a global variable called "test_llvm_var" in the front end >>> function pass like this: >>> >>> >>> >>> new GlobalVariable(*m, tmp->getType(), true, >>> llvm::GlobalValue::ExternalLinkage, tmp, "test_llvm_var"); >>> >>> >>> >>> where tmp is a function. >>> >>> >>> >>> Then I tried to access this global variable in the back end >>> MachineFunctionPass like this: >>> >>> >>> >>> MCContext& MCC = MF.getContext(); >>> MCSymbol* MCS = MCC.lookupSymbol("test_llvm_var"); >>> if (MCS == NULL) { >>> errs() << ">>> MCSymbol is null\n"; >>> } >>> else { >>> MCS->dump(); >>> } >>> >>> >>> >>> (MF is a MachineFunction). >>> >>> >>> >>> However I always get MCS==NULL, there is no symbol called test_llvm_var >>> in the backend. >>> >>> >>> >>> Am I doing something wrong? What I would like to do is to modify the >>> global variable's value from the backend pass. >>> >>> >>> >>> Any help would be appreciated. >>> >>> Thank you! >>> >> _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190118/3906befa/attachment-0001.html>
张雨姗(ZHANG Yushan)-11310380 via llvm-dev
2019-Jan-20 09:47 UTC
[llvm-dev] Can't find symbol from llvm backend
Hi, Did you check your variable is inserted successfully? As far as I know, to insert functions you need to instrument the bitcode as the following: Constant *c = module->getOrInsertFunction("cmpr", FunctionType::getVoidTy(*context), Type::getInt64Ty(*context), Type::getInt64Ty(*context), NULL); f = &cast<Function>(*c); The upper code inserts a new function "cmpr" (declaration) to the function table, but later you need to add definitions. Or if you want to insert a variable (e.g. int), the following is code from StackOverflow I found work for my case: GlobalVariable* gvar_int = new GlobalVariable( /*Type=*/i64_type, /*isConstant=*/false, /*Linkage=*/GlobalValue::CommonLinkage, /*Initializer=*/0, // has initializer, specified below /*Name=*/name); And you could retrieve this variable with: module->getGlobalVariable("var_name") If you have further questions, I'm happy to discuss. Regards, Yushan ------------------ Original ------------------ From: "n3v3rm03 via llvm-dev"<llvm-dev at lists.llvm.org>; Date: Sat, Jan 19, 2019 02:52 PM To: "paul.robinson"<paul.robinson at sony.com>; Cc: "llvm-dev"<llvm-dev at lists.llvm.org>; Subject: Re: [llvm-dev] Can't find symbol from llvm backend No, I don't. But I’m sure it is not optimized because I can see this variable in the final binary file emitted. Do you mean if I don’t refer to this variable in the front end, then I can’t see it in the backend? (although it’s in the final binary file) Thank you! 2019年1月19日(土) 2:00 <paul.robinson at sony.com>: Do you have a use of the new variable as well? If not, it might be optimized out between the point where you create it and your MachineFunction pass. --paulr From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of n3v3rm03 via llvm-dev Sent: Friday, January 18, 2019 5:57 AM To: llvm-dev at lists.llvm.org Subject: [llvm-dev] Can't find symbol from llvm backend Hi, I am new to llvm. I create a global variable called "test_llvm_var" in the front end function pass like this: new GlobalVariable(*m, tmp->getType(), true, llvm::GlobalValue::ExternalLinkage, tmp, "test_llvm_var"); where tmp is a function. Then I tried to access this global variable in the back end MachineFunctionPass like this: MCContext& MCC = MF.getContext(); MCSymbol* MCS = MCC.lookupSymbol("test_llvm_var"); if (MCS == NULL) { errs() << ">>> MCSymbol is null\n"; } else { MCS->dump(); } (MF is a MachineFunction). However I always get MCS==NULL, there is no symbol called test_llvm_var in the backend. Am I doing something wrong? What I would like to do is to modify the global variable's value from the backend pass. Any help would be appreciated. Thank you! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190120/e02e6769/attachment.html>