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

Stepan Dyatkovskiy stpworld at narod.ru
Fri Mar 23 05:40:08 PDT 2012


Hi Chris.

// Some range class it may be ConstantRange as Duncan proposed.
class Range {
   APInt Low;
   APInt High;

   public:

   // Some interface here (getLow, getHigh, <, >, isInRange and so on).
}

class ConstantRangesSet {
   std::vector<Range> Ranges;

   /// Checks is the given constant satisfies this case.
   bool isSatisfies(const APInt& N);

   /// Returns number of ranges.
   unsigned getNumItems() const;

   /// Returns set item with given index.
   const Range& getItem(unsigned idx);
}

SingleNumber is APInt instead.

-Stepan.

Chris Lattner wrote:
>
> 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