Browse Source

[Constant] add undef element query for vector constants; NFC

This is likely to be used in D48987 and similar patches, 
so adding it as an NFC preliminary step.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336442 91177308-0d34-0410-b5e6-96231b3b80d8
Sanjay Patel 7 years ago
parent
commit
58b0c3857a
2 changed files with 14 additions and 0 deletions
  1. 4 0
      include/llvm/IR/Constant.h
  2. 10 0
      lib/IR/Constants.cpp

+ 4 - 0
include/llvm/IR/Constant.h

@@ -87,6 +87,10 @@ public:
   /// floating-point constant with all NaN elements.
   /// floating-point constant with all NaN elements.
   bool isNaN() const;
   bool isNaN() const;
 
 
+  /// Return true if this is a vector constant that includes any undefined
+  /// elements.
+  bool containsUndefElement() const;
+
   /// Return true if evaluation of this constant could trap. This is true for
   /// Return true if evaluation of this constant could trap. This is true for
   /// things like constant expressions that could divide by zero.
   /// things like constant expressions that could divide by zero.
   bool canTrap() const;
   bool canTrap() const;

+ 10 - 0
lib/IR/Constants.cpp

@@ -254,6 +254,16 @@ bool Constant::isNaN() const {
   return true;
   return true;
 }
 }
 
 
+bool Constant::containsUndefElement() const {
+  if (!getType()->isVectorTy())
+    return false;
+  for (unsigned i = 0, e = getType()->getVectorNumElements(); i != e; ++i)
+    if (isa<UndefValue>(getAggregateElement(i)))
+      return true;
+
+  return false;
+}
+
 /// Constructor to create a '0' constant of arbitrary type.
 /// Constructor to create a '0' constant of arbitrary type.
 Constant *Constant::getNullValue(Type *Ty) {
 Constant *Constant::getNullValue(Type *Ty) {
   switch (Ty->getTypeID()) {
   switch (Ty->getTypeID()) {