Please keep replies on the list.
Now you've missed "InputIterator must be a random-access iterator
pointing to contiguous storage (e.g. a std::vector<>::iterator).
Checks are made for random-accessness but not for contiguous storage
as that would incur runtime overhead." from CallInst's constructor
(although that comment should be on Create()). Function::arg_iterator
isn't random-access.
You probably also want to pull the arguments out of the old CallInst,
not out of the parameters of the new function. The old CallInst that
you're replacing can't see the arguments of a function you've just
created.
On Thu, Nov 19, 2009 at 10:22 AM, Marc Claesen <claesenm at gmail.com>
wrote:> Thanks for the reply, I've switched from using the constructor to using
> CallInst::Create() but I get another problem which I once again can't
solve
> ...
>
> My function is:
> void replaceByClone(Function *f, CallInst *I){
> Function *clone = CloneFunction(f);
> BasicBlock::iterator ii(I);
> CallInst* call >
CallInst::Create(clone,clone->arg_begin(),clone->arg_end()); // this is
line
> #70
> ReplaceInstWithInst(I->getParent()->getInstList(),ii,call);
> }
>
> This gives me an even more exotic compile error:
> /media/work/cpp-workspace/DivComp/include/llvm/ADT/ilist.h: In static
member
> function ‘static llvm::CallInst* llvm::CallInst::Create(llvm::Value*,
> InputIterator, InputIterator, const llvm::Twine&, llvm::Instruction*)
[with
> InputIterator = llvm::ilist_iterator<llvm::Argument>]’:
>
/media/work/cpp-workspace/DivComp/lib/Transforms/DivComp/FunctionCloning.cpp:70:
> instantiated from here
> /media/work/cpp-workspace/DivComp/include/llvm/ADT/ilist.h:169: error:
‘void
> llvm::ilist_iterator<NodeTy>::operator-(T) const [with T >
llvm::ilist_iterator<llvm::Argument>, NodeTy = llvm::Argument]’ is private
> /media/work/cpp-workspace/DivComp/include/llvm/Instructions.h:993: error:
> within this context
>
/media/work/cpp-workspace/DivComp/lib/Transforms/DivComp/FunctionCloning.cpp:70:
> instantiated from here
> /media/work/cpp-workspace/DivComp/include/llvm/Instructions.h:993: error:
> void value not ignored as it ought to be
>
> What am I doing wrong this time? Thanks in advance for all your help,
it's
> greatly appreciated!
>
> Marc
>
> Jeffrey Yasskin wrote:
>>
>> You're trying to invoke a 5-argument constructor with 3 arguments.
>> Ain't gonna work.
>>
>> CallInst() is private, so even if you found the right overload, it
>> wouldn't compile. To build LLVM IR objects, you generally call
their
>> static Foo::Create() function, which does have an overload taking your
>> parameters.
>>
>> It doesn't really matter that clone is of type Function*&.
It's true,
>> and will let you pass it to a parameter of that type, but it'll
also
>> match a parameter of type Function*.
>>
>> On Wed, Nov 18, 2009 at 8:22 AM, Marc Claesen <claesenm at
gmail.com> wrote:
>>
>>>
>>> Hi,
>>>
>>> This is probably more of a standard C++ question instead of an
actual
>>> LLVM question, but here it goes anyway. I'm trying to invoke
the
>>> following constructor:
>>> CallInst::CallInst(Value *Func, InputIterator ArgBegin,
InputIterator
>>> ArgEnd,
>>> const Twine &NameStr, BasicBlock *InsertAtEnd);
>>>
>>> My code is:
>>>
>>> using namespace llvm;
>>> void replaceByClone(Function *f, CallInst *I){
>>> Function *clone = CloneFunction(f);
>>> BasicBlock::iterator ii(I);
>>>
>>>
ReplaceInstWithInst(I->getParent()->getInstList(),ii,CallInst(clone,clone->arg_begin(),clone->arg_end()));
>>> }
>>>
>>> Compiling generates the following error:
>>> error: no matching function for call to
>>> ‘llvm::CallInst::CallInst(llvm::Function*&,
>>> llvm::ilist_iterator<llvm::Argument>,
>>> llvm::ilist_iterator<llvm::Argument>)’
>>> /media/work/cpp-workspace/DivComp/include/llvm/Instructions.h:985:
note:
>>> candidates are: llvm::CallInst::CallInst(llvm::Value*, const
>>> llvm::Twine&, llvm::BasicBlock*)
>>> /media/work/cpp-workspace/DivComp/include/llvm/Instructions.h:984:
note:
>>> llvm::CallInst::CallInst(llvm::Value*, const llvm::Twine&,
>>> llvm::Instruction*)
>>> /media/work/cpp-workspace/DivComp/include/llvm/Instructions.h:982:
note:
>>> llvm::CallInst::CallInst(llvm::Value*, llvm::Value*, const
llvm::Twine&,
>>> llvm::BasicBlock*)
>>> /media/work/cpp-workspace/DivComp/include/llvm/Instructions.h:980:
note:
>>> llvm::CallInst::CallInst(llvm::Value*, llvm::Value*, const
llvm::Twine&,
>>> llvm::Instruction*)
>>> /media/work/cpp-workspace/DivComp/include/llvm/Instructions.h:940:
note:
>>> llvm::CallInst::CallInst(const llvm::CallInst&)
>>>
>>> Apparantly, clone is not of type Function* but of type
Function*& ... I
>>> have no idea why this is. I've checked the LLVM source for
similar
>>> invocations and they all seem to do what my code does. Any ideas?
>>>
>>> Thanks in advance,
>>> Marc Claesen
>>> _______________________________________________
>>> LLVM Developers mailing list
>>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>>
>>>
>>
>>
>
>