[LLVMdev] Steps to addDestination
Tim Northover
t.p.northover at gmail.com
Thu Jul 25 00:08:20 PDT 2013
Hi Rasha,
> for(rit=Result.begin();rit!=Result.end();++rit)
> {
> Value* Address= BlockAddress::get (*rit);
>
> IndirectBrInst *IBI = IndirectBrInst::Create(Address, Result.size(),i->getTerminator() );
> IBI->addDestination((*rit));
> }
This would be creating a block looking something like:
[ Do stuff ]
indirectbr i8* blockaddress(@foo, %result1), [label %result1]
indirectbr i8* blockaddress(@foo, %result2), [label %result2]
[...]
indirectbr i8* blockaddress(@foo, %resultN), [label %resultN]
which isn't valid LLVM IR. Each basic block has to have a single
branch at the end so you need to create the IndirectBrInst outside the
loop.
How do you decide which of the results you want to jump to at
run-time? I think that's the key question you have to answer. You want
to emit LLVM IR to make this decision and produce a single Value
representing it, then use the value just once to create a single
indirectbr.
Your code might look like:
Value *Address = emitCodeToChooseResult(Results, Loc);
IndirectBrInst *IBI = IndirectBrInst::Create(Address, Result.size(), i);
for (rit = Result.begin(); rit != Result.end(); ++rit)
IBI->addDestination(*rit);
Cheers.
Tim.
More information about the llvm-dev
mailing list