Dávid Bolvanský via llvm-dev
2018-Mar-23 23:07 UTC
[llvm-dev] Change function call name in a CallInst only in certain functions
Hello, In my module I have functions: a b c f3 calls "a" f2 calls "a" f1 calls "b" I would like to modify a CallInst in the f2. Now it calls "a", but I want changed it to "c". When loop over the instructions of the f2, I can get a CallInst to be modified, then I use "setName" to changed it to "c". Problem is, since references are updated, "a" is changed to "c" even in f1. Any solution? Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180324/5722a3dd/attachment.html>
mayuyu.io via llvm-dev
2018-Mar-24 00:05 UTC
[llvm-dev] Change function call name in a CallInst only in certain functions
Not sure why you are using setName here. I personally use CallSite() to wrap InvokeInst and CallInst, then use CallSite::setCalledFunction for this kind of stuff. Zhang> On 23 Mar 2018, at 23:07, Dávid Bolvanský via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > Hello, > > In my module I have functions: > > a > b > c > f3 calls "a" > f2 calls "a" > f1 calls "b" > > I would like to modify a CallInst in the f2. Now it calls "a", but I want changed it to "c". > > When loop over the instructions of the f2, I can get a CallInst to be modified, then I use "setName" to changed it to "c". > > > Problem is, since references are updated, "a" is changed to "c" even in f1. > > Any solution? > > Thanks > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
mayuyu.io via llvm-dev
2018-Mar-24 00:19 UTC
[llvm-dev] Change function call name in a CallInst only in certain functions
You are probably calling setName() on the called Function, which in-turned renamed the called Function instead of replacing the called function. Depending on your use-case, if you are certain that you only need to modify CallInsts, then you could simply call CallInst::setCalledFunction , otherwise it’s probably wiser to use CallSite as a wrapper for both CallInst and InvokeInst. Do note, however, that no matter which solution you end up using, you’ll need to update the FunctionType as well Zhang> On 23 Mar 2018, at 23:07, Dávid Bolvanský via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > Hello, > > In my module I have functions: > > a > b > c > f3 calls "a" > f2 calls "a" > f1 calls "b" > > I would like to modify a CallInst in the f2. Now it calls "a", but I want changed it to "c". > > When loop over the instructions of the f2, I can get a CallInst to be modified, then I use "setName" to changed it to "c". > > > Problem is, since references are updated, "a" is changed to "c" even in f1. > > Any solution? > > Thanks > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Dávid Bolvanský via llvm-dev
2018-Mar-24 12:31 UTC
[llvm-dev] Change function call name in a CallInst only in certain functions
Okey, setCalledFunction is useful. But I have a problem since my "a", "b", "c" are functions from libc, not my defined ones in the module. if (CallInst *call_inst = dyn_cast<CallInst>(&I)) { Function *fn = call_inst->getCalledFunction(); if (fn->getName() == "a") { ValueToValueMapTy map; FN = CloneFunction(fn, map, nullptr); FN->setName("c"); call_inst->setCalledFunction(FN); } ... } I get "Assertion `!NodePtr->isKnownSentinel()' failed." 2018-03-24 1:19 GMT+01:00 mayuyu.io <admin at mayuyu.io>:> > You are probably calling setName() on the called Function, which in-turned > renamed the called Function instead of replacing the called function. > Depending on your use-case, if you are certain that you only need to > modify CallInsts, then you could simply call CallInst::setCalledFunction , > otherwise it’s probably wiser to use CallSite as a wrapper for both > CallInst and InvokeInst. Do note, however, that no matter which solution > you end up using, you’ll need to update the FunctionType as well > Zhang > > > On 23 Mar 2018, at 23:07, Dávid Bolvanský via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > > > > Hello, > > > > In my module I have functions: > > > > a > > b > > c > > f3 calls "a" > > f2 calls "a" > > f1 calls "b" > > > > I would like to modify a CallInst in the f2. Now it calls "a", but I > want changed it to "c". > > > > When loop over the instructions of the f2, I can get a CallInst to be > modified, then I use "setName" to changed it to "c". > > > > > > Problem is, since references are updated, "a" is changed to "c" even in > f1. > > > > Any solution? > > > > Thanks > > _______________________________________________ > > 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/20180324/98e608cb/attachment.html>
Seemingly Similar Threads
- Change function call name in a CallInst only in certain functions
- DSE: Remove useless stores between malloc & memset
- DSE: Remove useless stores between malloc & memset
- DSE: Remove useless stores between malloc & memset
- DSE: Remove useless stores between malloc & memset