[LLVMdev] SwitchInst::addCase with BlockAddress

Carlo Alberto Ferraris cafxx at strayorange.com
Mon Aug 1 03:03:55 PDT 2011


Nella citazione lunedì 1 agosto 2011 08:13:12, Eli Friedman ha scritto:
> On Sun, Jul 31, 2011 at 7:36 AM, Carlo Alberto Ferraris
> <cafxx at strayorange.com>  wrote:
>> I'm trying to figure out how to feed a blockaddress to a switch condition
>> AND destination (basically emulating an indirectbr via a switch; I know it's
>> not a good approach, I'm just experimenting).
>> Suppose I have the following:
>>
>> SwitchInst *s = SwitchInst::Create(...);
>> BasicBlock *bb = ...;
>> PtrToIntInst k = new PtrToIntInst(BlockAddress::get(bb),<TYPE>, "", s);
>> s->addCase(k, bb);
>> ...
>>
>> is this reasonable? what should I put in place of<TYPE>  (the type to cast
>> to)?
> 
> You can't do that; switch cases are required to be constant integers,
> and a blockaddress are not constant integers (at least not at
> compile-time).
> 
> You can use an explicit comparison+branch, though.

BlockAddress is a class derived from Constant, so I thought it was 
meant to be, well, constant.
Besides, as
 I wrote, it is possible to get a ConstantExpr from a 
BlockAddress via ConstantExpr::getPointerCast (that in turn calls 
ConstantExpr::getPtrToInt).
Unfortunately, getPointerCast returns a Constant, not a ConstantInt; 
moreover, dyn_cast<ConstantInt> on that Constant returns null.
What I'm missing is, therefore, how do I get a ConstantInt out of a 
Constant obtained via ConstantExpr::getPointerCast?


-- 
Carlo Alberto Ferraris <cafxx at strayorange.com 
<mailto:cafxx at strayorange.com>>
website/blog <http://cafxx.strayorange.com> - +39 333 7643 235

-------------- next part --------------
A non-text attachment was scrubbed...
Name: cafxx.vcf
Type: text/x-vcard
Size: 233 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110801/c654fa18/attachment.vcf>


More information about the llvm-dev mailing list