Add an isSwiftError predicate to Value
authorArnold Schwaighofer <aschwaighofer@apple.com>
Sat, 10 Sep 2016 18:14:54 +0000 (18:14 +0000)
committerArnold Schwaighofer <aschwaighofer@apple.com>
Sat, 10 Sep 2016 18:14:54 +0000 (18:14 +0000)
llvm-svn: 281143

llvm/include/llvm/IR/Value.h
llvm/lib/IR/Value.cpp

index b3d318cf47f32bb34da804c743fdbfa6c279bd38..bb673521c47c13dd7c61e08e4769b02a6b6ed7f1 100644 (file)
@@ -448,6 +448,12 @@ public:
   /// \brief Return true if there is metadata referencing this value.
   bool isUsedByMetadata() const { return IsUsedByMD; }
 
+  /// \brief Return true if this value is a swifterror value.
+  ///
+  /// swifterror values can be either a function argument or an alloca with a
+  /// swifterror attribute.
+  bool isSwiftError() const;
+
   /// \brief Strip off pointer casts, all-zero GEPs, and aliases.
   ///
   /// Returns the original uncasted value.  If this is called on a non-pointer
index be704a778a83cf3cd18655b05aba2d129936c434..a1dfb37bf90e8ab46ae182a42e1a5a5294737157 100644 (file)
@@ -664,6 +664,16 @@ void Value::reverseUseList() {
   Head->setPrev(&UseList);
 }
 
+bool Value::isSwiftError() const {
+  auto *Arg = dyn_cast<Argument>(this);
+  if (Arg)
+    return Arg->hasSwiftErrorAttr();
+  auto *Alloca = dyn_cast<AllocaInst>(this);
+  if (!Alloca)
+    return false;
+  return Alloca->isSwiftError();
+}
+
 //===----------------------------------------------------------------------===//
 //                             ValueHandleBase Class
 //===----------------------------------------------------------------------===//