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

Stepan Dyatkovskiy STPWORLD at narod.ru
Sat Feb 11 01:52:01 PST 2012


Hi all. I just finished new classes for PR1255.

NEW CLASS.
As was proposed by Chris in recent PR1255 related posts, I selected ConstantArrays as case ranges set "holder" object. The array items are may be ConstantVectors with single item, and ConstantVectors with two items (that means single number and range respectively). Though I think that it would be better to hide the parsing of ConstantArray and create new class that will use ConstantArray inside.
New class should contain two features:
- bool isSatisfies(ConstantInt *V) method (need better name?). Returns "true" if the given value satisfies this case.
- Case's ranges and values enumeration. In some passes we need to analize each case (SwitchLowering for example).
At first I tried to use ConstatArray as a parent for new class. But ConstantArray::get(...) method may produce zeroinitalizers and data aggregators. How to wrap them with this way? So I declined the idea of inharitance from some concrete class.
I decided to use member "Constant*" pointer in new class that will refer to the "holder" object. In this case it may be either ConstantArray or some data aggregator: 
class Wrapper {
  Constant* Holder;

  // Some functionality that works with holder.
  ...
}
How to call this class? Currently I call it ConstantRangesSet (the constant set of integer ranges). But probably ConstantClustersSet will sound better?

FACTORY AND UNIFIED CLUSTERIFY
I also propose to implement the factory that allows to build case object with user friendly way. I called it CRSBuilder by now.
Currenly I implemented the factory that allows add, remove pairs of range+successor. It also allows add existing ConstantRangesSet decompiling it to separated ranges. Factory can emit either clusters set (single case range + successor) or the set of "ConstantRangesSet + Successor" pairs. CRSBuilder also allows you to emit single ConstantRangesSet object ignoring successor value.
So you can use it either as builder for new cases set for SwitchInst. Or for clusterification of existing cases set.
Just call Factory.optimize() and it'll emitted optimized and sorted clusters collection for you!
I tested clusterification on SelectionDAGBuilder - it works fine.
Factory is a template. There are two params: SuccessorClass and IsReadonly. So you can specify what successor you need (BB or MBB). And you can also restrict your factory to use values in read-only mode (SelectionDAGBuilder need IsReadonly=true).

I attached the patch with new classes for review.

What do you think about this, guys?

-Stepan.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cr-0.7.17-newclasses.patch
Type: application/octet-stream
Size: 18087 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120211/862811d4/attachment.obj>


More information about the llvm-commits mailing list