[LLVMdev] how to get MachineBasicBlock of a BasicBlock
Jeff Kunkel
jdkunk3 at gmail.com
Fri Oct 15 07:46:20 PDT 2010
So a simple revision
typedef struct findBlock {
const BasicBlock * block;
std::vector<MachineBasicBlock*> * blocks
findBlock( BasicBlock * block, std::vector<MachineBasicBlock*> * blocks )
: block(block), blocks(blocks) {}
void operator( MachineBasicBlock * mbb ) {
if( mbb->getBasicBlock() == block)
blocks.push_back(mbb);
}
} findBlock;
std::vector<MachineBasicBlock*> blocks
std::for_each( machineFunction.begin(), machineFunction.end(),
findBlock( basicBlock, blocks ) );
Jeff Kunkel
On Fri, Oct 15, 2010 at 8:51 AM, David Meyer <pdox at google.com> wrote:
> Also note: there may be multiple MachineBasicBlock's for a single
> BasicBlock.
> - David M
>
> On Fri, Oct 15, 2010 at 4:59 AM, Jeff Kunkel <jdkunk3 at gmail.com> wrote:
>>
>> I don't think you can.
>>
>> The BasicBlock is a member of MachineBasicBlock. It is not inherited,
>> so it cannot be cast. The number of the MachineBasicBlock is not the
>> same as any BasicBlock values. So
>> MachineFunction::getMachineBasicBlock( BasicBlock::{get the number} )
>> cannot work. I do not see much in the basic block which can identify
>> it.
>>
>> So you can search for it.
>>
>> typedef struct findBlock {
>> BasicBlock * block;
>> findBlock( BasicBlock * block ) : block(block) {}
>> bool operator( MachineBasicBlock * mbb ) { return
>> mbb->getBasicBlock() == block; }
>> } findBlock;
>> MachineBasicBlock = *std::find( machineFunction.begin(),
>> machineFunction.end(),
>> findBlock( basicBlock ) );
>>
>> -Thanks
>> -Jeff Kunkel
>>
>> 2010/10/15 徐敏 <xm1988 at mail.ustc.edu.cn>:
>> > Hello, we can get BasicBlock from MachineBasicBlock through
>> > MachineBasicBlock::getBasicBlock() function, but how can I get
>> > MachineBasicBlock of a BasicBlock?
>> > Thank you!
>> >
>> >
>> >
>> >
>> > _______________________________________________
>> > LLVM Developers mailing list
>> > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
>> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>> >
>> >
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
More information about the llvm-dev
mailing list