[llvm-commits] Reworked SwitchInst prototype with case-ranges.

Stepan Dyatkovskiy stpworld at narod.ru
Sun Aug 26 10:55:39 PDT 2012

Stepan Dyatkovskiy wrote:
> Hi all, please find the new SwitchInst prototype with case ranges in
> attachment.
> Main features.
> 1. Ranges are stored in flat ordered numbers collection (thanks to
> Duncan and Chandler for this idea). Range [Low, High) may be represented
> as Low=collection[i], High=collection[i+1]. Thus all set of integers is
> covered. The collection is terminated by the wrapped range:
>    Low=collection[collection.size()-1], High=collection[0].
> For each collection item we also assign BasicBlock, Range+BasicBlock
> will called "Cluster". E.g.:
>    [1 -> Default] [2 -> Successor0] [5 -> Successor1] [8 -> Successor2]
>    That means that we have 3 clusters:
>    [2, 5) -> Successor0
>    [5, 8) -> Successor1
>    [8, 1) -> Successor2 // This range is wrapped.
> 2. I introduced successor ID (SID).
> We need associate successors with case-ranges. But both ranges and
> successors collections may be changed asynchronously:
>    Successors may change its indices during 'remove' operation.
>    Ranges may be removed.
> But we need to keep always actual successor information for each range.
> Even if successor was replaced by optimizer or its index was changed.
> That's why SID was introduced, it will the same always. In that case
> several SIDs may be assigned to the same successor after optimization.
> 3. Ranges directed to the default successor are always skipped during
> iteration. Thus when user invokes getNumRanges, he got number of
> non-default ranges. When user gets iterator case_begin(), he got
> iterator to the first non-default range. And so on.
> Probably its is less generic way. But it helps to reduce ranges
> processing time. Since we process default after all, as some kind of
> remainder.
> 4. Support for clusterification. Iterator has method
> getClusterAndGoNext. This method allows to iterate over merged ranges
> with the same successor and neighbouring borders. So if you need to
> collect optimized clusters you just should use
> CaseIt::getClusterAndGoNext instead of standard ++ operation.
> P.S.: IntegersSubset, IntegersSubsetMapping and IntegersSubsetTest will
> go away. I excluded these changes from current patch for better and
> cleaner looking.
> Thanks,
> -Stepan.

More information about the llvm-commits mailing list