Add hasByValArgument() to test if a call instruction has byval argument(s).
authorEvan Cheng <evan.cheng@apple.com>
Sat, 12 Jan 2008 18:57:32 +0000 (18:57 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Sat, 12 Jan 2008 18:57:32 +0000 (18:57 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45913 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Instructions.h
lib/VMCore/Instructions.cpp

index 1594a0ace67f5d380e2dd7597231a04aa0205164..76190f146d50312f690d16839646b5c232bb0b06 100644 (file)
@@ -944,6 +944,9 @@ public:
   /// @brief Determine if the call returns a structure.
   bool isStructReturn() const;
 
+  /// @brief Determine if any call argument is an aggregate passed by value.
+  bool hasByValArgument() const;
+
   /// getCalledFunction - Return the function being called by this instruction
   /// if it is a direct call.  If it is a call through a function pointer,
   /// return null.
index d8bcb31a4766f64616aad56b9bbcf8a9e05f5731..a9cc275b548c1d5335426b2f31287edb7743dd20 100644 (file)
@@ -404,6 +404,17 @@ bool CallInst::isStructReturn() const {
   return paramHasAttr(1, ParamAttr::StructRet);
 }
 
+/// @brief Determine if any call argument is an aggregate passed by value.
+bool CallInst::hasByValArgument() const {
+  const Value *Callee = getCalledValue();
+  const PointerType *CalleeTy = cast<PointerType>(Callee->getType());
+  const FunctionType *FTy = cast<FunctionType>(CalleeTy->getElementType());
+  for (unsigned i = 1, e = FTy->getNumParams()+1; i != e; ++i)
+    if (paramHasAttr(i, ParamAttr::ByVal))
+      return true;
+  return false;
+}
+
 void CallInst::setDoesNotThrow(bool doesNotThrow) {
   const ParamAttrsList *PAL = getParamAttrs();
   if (doesNotThrow)