[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 08:45:22 PDT 2017


Ah ok. So you really don't want to clone the instructions. You can build
new ones using IRBuilder.

I suppose you can clone the first one, then use the resulting llvm::Value
to build the next one. And so on.

On Fri, May 26, 2017 at 10:49 AM Jajoo, Malhar <
malhar.jajoo14 at imperial.ac.uk> wrote:

> Hi Nemanja,
>
>
> Thanks for your response.
>
>
> Sorry for the confusion ,
>
>
> I am trying to
>
>
>
>    1. copy a set of instructions from source Basic block to 2 or more
>    destination basic blocks
>    2. After copying I wish to remove the instructions from the
>    source basic block.
>    3. delete source basic block.
>
>
> After struggling a bit with the API I get the following result -
>
>
> //========== destination basic blocks ==========
>
> then:                                             ; preds = %entry
>   store i8000000 0, i8000000* %res
>
> *;after copying*
>  * Issue----->** %res45 = load i8000000, i8000000* %res*
> *  ret i8000000 %res4<----- Issue*
> *  br label %continuation*
>
> else:                                             ; preds = %entry
>   store i8000000 0, i8000000* %res
>
>
> *;after copying *
>  * Issue----->%res46- = load i8000000, i8000000* %res*
> *  ret i8000000 %res4 <----- Issue*
> *  br label %continuation*
>
> //==============  source basic block ===============
>
> continuation:                                     ; preds = %else, %then
>   %iftmp = phi i32 [ 5, %then ], [ 9, %else ]
>   store i32 %iftmp, i32* %datasize
>
> *; 3 lines below to be copied and then this whole basic block needs to be
> deleted.*
> *  store i8000000 0, i8000000* %res*
> *  %res4 = load i8000000, i8000000* %res*
> *  ret i8000000 %res4*
> }
>
>
> *My issue:*
>
> I have been using Instruction::clone() to copy the instructions and then
> set a name for this clone.
>
> As seen marked issue , the "ret" instruction is returning the old "%res"
> value.
> How can I make sure that "%res" returns the "res45" and "res46" in each of
> the destination basic blocks ?
>
> Thanks,
> Malhar
>
> ------------------------------
> *From:* Nemanja Ivanovic <nemanja.i.ibm at gmail.com>
> *Sent:* Friday, May 26, 2017 3:53:52 PM
> *To:* Jajoo, Malhar
> *Cc:* llvm-dev at lists.llvm.org
> *Subject:* Re: [llvm-dev] Moving instructions from source Basic Block to
> dest Basic Block
>
> 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/1e695bb0/attachment.html>


More information about the llvm-dev mailing list