[llvm-commits] PATCH: new Value::getThruSplat API

Dan Gohman gohman at apple.com
Sat Oct 30 09:27:51 PDT 2010


On Oct 29, 2010, at 7:28 PM, Nick Lewycky <nlewycky at google.com> wrote:

> On 27 October 2010 17:42, Dan Gohman <gohman at apple.com> wrote:

> It might be nice to
> push it into the API though, and have
>  ConstantInt *getAsConstantInt();
>  ConstantFP *getAsConstantFP();
> instead though, if you're going to be doing this a lot.
> 
> I'm not a fan, it sounds as though you could get any Value as a ConstantInt/FP which just doesn't make sense.

They'd reurn null if the Value is not a ConstantInt/FP, or vector thereof.

  if (ConstantInt *CI = C->getAsConstantInt())

seems pretty readable.  And it would avoid the double-dyncast issue.  But I'm not attatched.

Or if you like:

  if (ConstantInt *CI = C->getAs<ConstantInt>())

clang uses some idioms like this, for example. *shrug*

> 
> > The most radical alternative API would be to factor out a common base that represents a ConstantInt+ConstantVector(with splat) and another for ConstantFP+ConstantVector(with splat), then teach ConstantVector to return such a splatted CV from its getter. Sadly if you follow this through to its conclusion, you end up using multiple inheritance in the Constant hierarchy which causes all sorts of forms of pain.
> 
> I agree, don't do MI. But I think if you wanted to take this approach, you could
> make ConstantInt and ConstantFP capable of having vector types, but not be
> subclasses of ConstantVector. ConstantVector would just be for cases where it's
> really necessary to have an array of operands. This sounds like a big and scary
> change, though there are some reasons it might not have to be.
> 
> With this approach, vector ConstantAggregateZero could go away.
> 
> Doing that would force me to audit every single use of ConstantInt and ConstantFP to make sure they're okay with splat vectors instead of real int's/fp's, and adding tests on the type if necessary. Do you think that would be a better API at the end of the day? My proposed patch would be more of an opt-in approach.

I think it's worth considering.  All of the relevant operators are overloaded for vector
these days; constants are the only remaining IR construct using different opcodes
for the same operations in scalar and vector.`

The SelectionDAG IR has already taken some steps in this direction.
The main complication has been code which looks at the size of a type to
determine its precision.  Each instance is easy to fix once found though.

Dan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20101030/46bef5a6/attachment.html>


More information about the llvm-commits mailing list