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

Stepan Dyatkovskiy STPWORLD at narod.ru
Fri Apr 27 12:37:47 PDT 2012


ping.


25.04.2012, 23:09, "Stepan Dyatkovskiy" <STPWORLD at narod.ru>:
> Hi Chris. I commited new classes in r155464. I want to realize points summarized here:
> http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120305/138780.html
>
> And more generally I propose to start very-very carefully (watch for buildbots, take in account all remarks and so on) go within this way:
>
> 0. Implement new classes. Classes doesn't affect anything. They still work with ConstantInt base values at this stage.
> 1. Fictitious replacement of current ConstantInt case values with ConstantRangesSet. Case ranges set will still hold single value, and ConstantInt *getCaseValue() will return it. But additionally implement new method in SwitchInst that allows to work with case ranges. Currenly I think it should be some wrapper that returns either single value or ConstantRangesSet object.
> 2. Step-by-step replacement of old "ConstantInt* getCaseValue()" with new alternative. Modify algorithms for all passes that works with SwitchInst. But don't modify LLParser and BitcodeReader/Writer. Still hold single value in each ConstantRangesSet object. On this stage some parts of LLVM will use old-style methods, and some ones new-style.
> 3. After all getCaseValue() usages will removed and whole LLVM and its clients will work in new style - modify LLParser, Reader and Writer. Remove getCaseValue().
> 4. Replace ConstantInt*-based case ranges set items with APInt ones.
>
> Can you give me your approval for that?
> Thanks.
>
> -Stepan.
>
> 26.03.2012, 18:26, "Stepan Dyatkovskiy" <STPWORLD at narod.ru>:
>
>>  ping
>>
>>  23.03.2012, 16:40, "Stepan Dyatkovskiy" <stpworld at narod.ru>:
>>>   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
>>>   _______________________________________________
>>>   llvm-commits mailing list
>>>   llvm-commits at cs.uiuc.edu
>>>   http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list