[llvm-dev] Moving instructions from source Basic Block to dest Basic Block

Nemanja Ivanovic via llvm-dev llvm-dev at lists.llvm.org
Fri May 26 05:53:52 PDT 2017


It's a bit unclear what exactly you're looking to do. The subject talks
about moving instructions and the subsequent question mentions copying them.

I imagine you can get a pretty good example of how moving is done by
looking at `splitBasicBlock()` for the moving case (it may in fact turn out
that you actually want `llvm::splitBlock()` from lib/Transforms/Utils). You
might want to look at the numerous uses of `IRBuilder` if you're looking to
create new instructions that replicate the existing ones.


If none of this leads you to the answer, feel free to clarify the question
a bit and re-post. If you specify exactly why you want this, you may get
very good input in terms of how best to achieve the actual goal.

On Fri, May 26, 2017 at 8:39 AM, Jajoo, Malhar via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hi,
>
>
> I have been trying to move some instructions between basic blocks ,
>
>
> After looking at the API , I found* llvm::Instruction::clone() * but
> there
>
> is no result value for this.
>
>
>
> For example-
>
>
> *source Basic block :*
>
>
> continuation:                                     ; preds = %else, %then
>   %iftmp = phi i32 [ 5, %then ], [ 9, %else ]
>   store i32 %iftmp, i32* %datasize
>
> * ; 3 instructions below being copied*
>  * store i8000000 0, i8000000* %res *
> *  %res4 = load i8000000, i8000000* %res*
> *  ret i8000000 %res4*
>
>
> After copying the 3 instructions above to destination basic block.
>
> *destination basic block :*
>
>
> else:                                             ; preds = %entry
>   store i8000000 0, i8000000* %res
> *  %1---->issue* = load i8000000, i8000000* %res
>   ret i8000000 *%res4 -----> issue , need to get result of instruction
> above. *
>   br label %continuation
>
>
>
>
> I had tried using a simple Instruction::insert() earlier but ran
>
> into an assertion error complaining that the Function contained duplicated
> instruction.
>
>
> *My Question* : How to copy an instruction ( along with it's name , or
> the LHS of the instruction )
>
> Is it possible to do name the LHS of the instruction using clone()  ?
>
>
> Thanks,
>
> Malhar
>
>
>
> _______________________________________________
> 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/20170526/1dcf90b6/attachment.html>


More information about the llvm-dev mailing list