From e6dda2fee7eb38ee035d4bcc32496bab89bd5967 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Fri, 6 Jul 2018 14:52:36 +0000 Subject: [PATCH] [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. llvm-svn: 336442 --- llvm/include/llvm/IR/Constant.h | 4 ++++ llvm/lib/IR/Constants.cpp | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/llvm/include/llvm/IR/Constant.h b/llvm/include/llvm/IR/Constant.h index af5d548..5fdf0ea 100644 --- a/llvm/include/llvm/IR/Constant.h +++ b/llvm/include/llvm/IR/Constant.h @@ -87,6 +87,10 @@ public: /// floating-point constant with all NaN elements. 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 /// things like constant expressions that could divide by zero. bool canTrap() const; diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 3ea7598..032793e 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -254,6 +254,16 @@ bool Constant::isNaN() const { return true; } +bool Constant::containsUndefElement() const { + if (!getType()->isVectorTy()) + return false; + for (unsigned i = 0, e = getType()->getVectorNumElements(); i != e; ++i) + if (isa(getAggregateElement(i))) + return true; + + return false; +} + /// Constructor to create a '0' constant of arbitrary type. Constant *Constant::getNullValue(Type *Ty) { switch (Ty->getTypeID()) { -- 2.7.4