Fix Neon builtin pointer argument checking for "sret" builtins.

The code for checking Neon builtin pointer argument types was assuming that
there would only be one pointer argument.  But, for vld2-4 builtins, the first
argument is a special sret pointer where the result will be stored.  So,
instead of scanning all the arguments to find a pointer, have TableGen figure
out the index of the pointer argument that needs checking.  That's better than
scanning all the arguments regardless.  <rdar://problem/10448804>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144834 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/utils/TableGen/NeonEmitter.cpp b/utils/TableGen/NeonEmitter.cpp
index fec16b9..589fbde 100644
--- a/utils/TableGen/NeonEmitter.cpp
+++ b/utils/TableGen/NeonEmitter.cpp
@@ -1336,14 +1336,32 @@
         mask |= 1 << GetNeonEnum(Proto, TypeVec[ti]);
       }
     }
-    bool HasPtr = (Proto.find('p') != std::string::npos);
-    bool HasConstPtr = (Proto.find('c') != std::string::npos);
+
+    // Check if the builtin function has a pointer or const pointer argument.
+    int PtrArgNum = -1;
+    bool HasConstPtr = false;
+    for (unsigned arg = 1, arge = Proto.size(); arg != arge; ++arg) {
+      char ArgType = Proto[arg];
+      if (ArgType == 'c') {
+        HasConstPtr = true;
+        PtrArgNum = arg - 1;
+        break;
+      }
+      if (ArgType == 'p') {
+        PtrArgNum = arg - 1;
+        break;
+      }
+    }
+    // For sret builtins, adjust the pointer argument index.
+    if (PtrArgNum >= 0 && (Proto[0] >= '2' && Proto[0] <= '4'))
+      PtrArgNum += 1;
+
     if (mask) {
       OS << "case ARM::BI__builtin_neon_"
          << MangleName(name, TypeVec[si], ClassB)
          << ": mask = " << "0x" << utohexstr(mask);
-      if (HasPtr)
-        OS << "; HasPtr = true";
+      if (PtrArgNum >= 0)
+        OS << "; PtrArgNum = " << PtrArgNum;
       if (HasConstPtr)
         OS << "; HasConstPtr = true";
       OS << "; break;\n";
@@ -1352,8 +1370,8 @@
       OS << "case ARM::BI__builtin_neon_"
          << MangleName(name, TypeVec[qi], ClassB)
          << ": mask = " << "0x" << utohexstr(qmask);
-      if (HasPtr)
-        OS << "; HasPtr = true";
+      if (PtrArgNum >= 0)
+        OS << "; PtrArgNum = " << PtrArgNum;
       if (HasConstPtr)
         OS << "; HasConstPtr = true";
       OS << "; break;\n";