[llvm-commits] New classes for PR1255: Should enhance LLVM switch instruction to take case ranges.

Chris Lattner clattner at apple.com
Wed Mar 21 21:14:55 PDT 2012


On Mar 11, 2012, at 1:00 AM, Stepan Dyatkovskiy wrote:

> Hi Chris.
> 
> Summary of previous discussion:
> 1. Finally ConstantInt should be replaced with APInt.
> 2. How to store case ranges. I remind your last proposal:
> 
> [quote]
> 
> The mapping of the range to entries in CaseValues could look like this:
> 
> [N, N+1] -> Single element in CaseValues indicates the case value for the destination.
> [MAXINT, MININT] -> The entire case is "default"
> Otherwise, the pair indicates a series of ranges (inclusive).  If one of the ranges is MAXINT/MININT, then it is the default case.  For example [0, 4, 6,6]  would handle 0,1,2,3,4,6.  [4,6, MAXINT,MININT] would handle 4,5,6 and default.
> 
> [/quote]
> 
> My proposal was to create ConstantRangesSet that will store all numbers and ranges for complex case. I still propose to use this schema.
> You can ask what about most probable case, when for most of successors will be the only case value?
> OK. We can create collection for "classic" cases  vector<pair<SingleNumber,Success> > too. Then finally on the top level we have 2 collections:
> class SwitchInst {
> ..
>  vector<pair<SingleNumber, BasicBlock*> > ClassicCases;
>  vector<pair<ConstantRangesSet, BasicBlock> > ComplexCases;
> ..
> }
> 
> So, what do you think about this?

This approach seems sensible to me.  Can you sketch out what SingleNumber and ConstantRangesSet look like?

-Chris



More information about the llvm-commits mailing list