Why MachineBasicBlcok doesn't have transferPredecessors() ?

Hi

I want to ask a question.

(Maybe it is a trivial question.)

I found that there is transferSuccessors() in MachineBasicBlcok

So that when manipulating MachineBasicBlock,
we can use transferSuccessors to update the CFG easily.

Why there is not transferPredecessors in MachineBasicBlcok ?

Thank you

What would you want to use it for? If it's for splitting a block: the
common pattern for splitting seems to be to create a new block that
will be the successor of the old one rather than the other way around.
One good reason for this is that doing it this way only requires
fixing up (target-independent) phi instructions, while doing it the
other way around would require fixing up the (target-specific!) branch
instructions.

Cheers,
Nicolai

for example

I want to insert a new machine bb “before” a specific machine bb.

or split a mbb and keep the later one as the original one.

(to keep the label/Blackadder’s correct
t)
(or keep other property of mbb)

so I need to transfer the original mbb’s predecessor to the new mbb.

Nicolai Hähnle <nhaehnle@gmail.com> 於 2020年3月13日 週五 23:57 寫道:

for example

I want to insert a new machine bb “before” a specific machine bb.

or split a mbb and keep the later one as the original one.
(to keep the label/Blackadder's correct
t)

Can you explain why that would make a difference? Basic block labels
ought to be irrelevant for codegen.

(or keep other property of mbb)

What property?

Cheers,
Nicolai

寄件者: PenYiWang <s89162504@gmail.com>

If you are working at the MachineInstr level, try using setPostInstrSymbol to place your own label after the call in question. That is the reliable way of getting the address of a specific instruction.

The label which I used is generated from BlockAddress in llvm ir level.

/*
I pass these BlockAddress to the global variable in my own program , by using GlobalVariable’s setinitializer.

I want to print all the address of call instruction “exactly” , in the elf binary.
*/

Maybe what I really need is the way to “move” the label which is generated from BlockAddress.

I want to move the label from “sub rsp” or “mov rdi” to exactly the call instruction.

But I don’t know how to get the label and move.

Then I split the MachineBasicBlock.

That’s why I want to insert a mbb before another, so I need to update the cfg, and transfer the predecessor of mbb.

Thank you for tell me about setPostInstrSymbol.

But setPostInstrSymbol may not solve my problem.

setPostInstrSymbol can give me label.

but, I already have the label, and I need to adjust the label.

Thank you !

Reid Kleckner <rnk@google.com> 於 2020年3月14日 週六 23:20 寫道: