[LLVMdev] Inverse of ConstantFP::get and similar functions?

Stephen Lin swlin at post.harvard.edu
Mon Jul 22 10:19:04 PDT 2013


I noticed that ConstantFP::get automatically returns the appropriately
types Constant depending on the LLVM type passed in (i.e. if called
with a vector, it returns a splat vector with the given constant).

Is there any simple way to do the inverse of this function? i.e.,
given a llvm::Value, check whether it is either a scalar of the given
constant value or a splat vector with the given constant value? I
can't seem to find any, and it doesn't look like the pattern matching
interface provides something similar to this either.

If this doesn't exist, then I propose adding static versions of all
the various ConstantFoo::isBar() functions, which take a value as a
parameter and check that the value is of a constant of the appropriate
type and value (checking for vectors matching the predicate in the
vector case).

For example:

   static bool ConstantFP::isExactlyValue(Value *V, double D);

would return true is V is ConstantFP, a splat ConstantVector, or a
ConstantDataVector with the appropriate type. Similarly,

   static bool ConstantFP::isZero(Value *V);

would return true if V is a ConstantFP with zero of either sign, a
ConstantVector or ConstantDataVector with all zeros of either sign, or
a zero initializer...

Anyone have any thoughts, and/or can point me to somewhere where this
kind of thing is already implemented?


More information about the llvm-dev mailing list