<div dir="ltr"><div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">+// This needs to be shared between the instantiations of Find<></span><br style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">
<span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">+typedef std::pair<std::string,std::</span><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">string> KeyWithType;</span><br style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">
<span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">+static SmallSet<KeyWithType,10> reportedAsUnrecognized;</span><br style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">+</span><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"><br>
</span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">This is introducing a global into the libraries, which is verboten. Please revert and find a design that doesn't require the global.</span></div>
</div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">This should have been caught in pre-commit review.</span></div>
<div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">+</span><br></div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">+  /// Find KV in array using binary search.</span><br style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">
<span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">+  /// T should be either SubtargetFeatureKV or SubtargetInfoKV</span><br style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">+  template<typename T></span><br style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">
<span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">+  static const T *Find(StringRef Key, const T *Array, size_t Length,</span><br style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">
<span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">+                       const char* KeyType);</span><br><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"><br></span></div>
<div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">This should be `find` according to the naming convention. Also, You should use ArrayRef instead of a raw pointer + length. Maybe a more descriptive name than `find` would be useful as well.</span></div>
<div><br></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">-- Sean Silva</span></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jan 23, 2014 at 6:31 AM, Artyom Skrobov <span dir="ltr"><<a href="mailto:Artyom.Skrobov@arm.com" target="_blank">Artyom.Skrobov@arm.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: askrobov<br>
Date: Thu Jan 23 05:31:38 2014<br>
New Revision: 199886<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=199886&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=199886&view=rev</a><br>
Log:<br>
Prevent repetitive warnings for unrecognized processors and features<br>
<br>
Added:<br>
    llvm/trunk/test/MC/ARM/unrecognized.ll<br>
Modified:<br>
    llvm/trunk/include/llvm/MC/SubtargetFeature.h<br>
    llvm/trunk/lib/MC/MCSubtargetInfo.cpp<br>
    llvm/trunk/lib/MC/SubtargetFeature.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/MC/SubtargetFeature.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/SubtargetFeature.h?rev=199886&r1=199885&r2=199886&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/SubtargetFeature.h?rev=199886&r1=199885&r2=199886&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/include/llvm/MC/SubtargetFeature.h (original)<br>
+++ llvm/trunk/include/llvm/MC/SubtargetFeature.h Thu Jan 23 05:31:38 2014<br>
@@ -101,6 +101,12 @@ public:<br>
<br>
   /// Adds the default features for the specified target triple.<br>
   void getDefaultSubtargetFeatures(const Triple& Triple);<br>
+<br>
+  /// Find KV in array using binary search.<br>
+  /// T should be either SubtargetFeatureKV or SubtargetInfoKV<br>
+  template<typename T><br>
+  static const T *Find(StringRef Key, const T *Array, size_t Length,<br>
+                       const char* KeyType);<br>
 };<br>
<br>
 } // End namespace llvm<br>
<br>
Modified: llvm/trunk/lib/MC/MCSubtargetInfo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCSubtargetInfo.cpp?rev=199886&r1=199885&r2=199886&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCSubtargetInfo.cpp?rev=199886&r1=199885&r2=199886&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/MC/MCSubtargetInfo.cpp (original)<br>
+++ llvm/trunk/lib/MC/MCSubtargetInfo.cpp Thu Jan 23 05:31:38 2014<br>
@@ -96,14 +96,11 @@ MCSubtargetInfo::getSchedModelForCPU(Str<br>
 #endif<br>
<br>
   // Find entry<br>
-  const SubtargetInfoKV *Found =<br>
-    std::lower_bound(ProcSchedModels, ProcSchedModels+NumProcs, CPU);<br>
-  if (Found == ProcSchedModels+NumProcs || StringRef(Found->Key) != CPU) {<br>
-    errs() << "'" << CPU<br>
-           << "' is not a recognized processor for this target"<br>
-           << " (ignoring processor)\n";<br>
+  const SubtargetInfoKV *Found = SubtargetFeatures::Find(CPU, ProcSchedModels,<br>
+                                                         NumProcs, "processor");<br>
+  if (!Found)<br>
     return &MCSchedModel::DefaultSchedModel;<br>
-  }<br>
+<br>
   assert(Found->Value && "Missing processor SchedModel value");<br>
   return (const MCSchedModel *)Found->Value;<br>
 }<br>
<br>
Modified: llvm/trunk/lib/MC/SubtargetFeature.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/SubtargetFeature.cpp?rev=199886&r1=199885&r2=199886&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/SubtargetFeature.cpp?rev=199886&r1=199885&r2=199886&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/MC/SubtargetFeature.cpp (original)<br>
+++ llvm/trunk/lib/MC/SubtargetFeature.cpp Thu Jan 23 05:31:38 2014<br>
@@ -11,9 +11,11 @@<br>
 //<br>
 //===----------------------------------------------------------------------===//<br>
<br>
+#include "llvm/ADT/SmallSet.h"<br>
 #include "llvm/MC/SubtargetFeature.h"<br>
 #include "llvm/Support/Debug.h"<br>
 #include "llvm/Support/Format.h"<br>
+#include "llvm/Support/SourceMgr.h"<br>
 #include "llvm/Support/raw_ostream.h"<br>
 #include <algorithm><br>
 #include <cassert><br>
@@ -118,19 +120,42 @@ void SubtargetFeatures::AddFeature(const<br>
   }<br>
 }<br>
<br>
+// This needs to be shared between the instantiations of Find<><br>
+typedef std::pair<std::string,std::string> KeyWithType;<br>
+static SmallSet<KeyWithType,10> reportedAsUnrecognized;<br>
+<br>
 /// Find KV in array using binary search.<br>
-static const SubtargetFeatureKV *Find(StringRef S, const SubtargetFeatureKV *A,<br>
-                                      size_t L) {<br>
+template<typename T><br>
+const T *SubtargetFeatures::Find(StringRef Key, const T *Array, size_t Length,<br>
+                                 const char* KeyType) {<br>
   // Determine the end of the array<br>
-  const SubtargetFeatureKV *Hi = A + L;<br>
+  const T *Hi = Array + Length;<br>
   // Binary search the array<br>
-  const SubtargetFeatureKV *F = std::lower_bound(A, Hi, S);<br>
+  const T *F = std::lower_bound(Array, Hi, Key);<br>
   // If not found then return NULL<br>
-  if (F == Hi || StringRef(F->Key) != S) return NULL;<br>
+  if (F == Hi || StringRef(F->Key) != Key) {<br>
+    // If not yet reported, report now<br>
+    KeyWithType current(KeyType, Key);<br>
+    if(!reportedAsUnrecognized.count(current)) {<br>
+      SmallString<1024> storage;<br>
+      StringRef message = ("'" + Key +<br>
+                           "' is not a recognized " + KeyType +<br>
+                           " for this target (ignoring " + KeyType +<br>
+                           ")").toStringRef(storage);<br>
+      SMDiagnostic(StringRef(), SourceMgr::DK_Warning, message)<br>
+        .print(0, errs());<br>
+      reportedAsUnrecognized.insert(current);<br>
+    }<br>
+    return NULL;<br>
+  }<br>
   // Return the found array item<br>
   return F;<br>
 }<br>
<br>
+// Instantiate with <SubtargetInfoKV> for use in MCSubtargetInfo<br>
+template const SubtargetInfoKV *SubtargetFeatures::Find<SubtargetInfoKV><br>
+  (StringRef Key, const SubtargetInfoKV *Array, size_t Length, const char* KeyType);<br>
+<br>
 /// getLongestEntryLength - Return the length of the longest entry in the table.<br>
 ///<br>
 static size_t getLongestEntryLength(const SubtargetFeatureKV *Table,<br>
@@ -228,7 +253,7 @@ SubtargetFeatures::ToggleFeature(uint64_<br>
                                  size_t FeatureTableSize) {<br>
   // Find feature in table.<br>
   const SubtargetFeatureKV *FeatureEntry =<br>
-    Find(StripFlag(Feature), FeatureTable, FeatureTableSize);<br>
+    Find(StripFlag(Feature), FeatureTable, FeatureTableSize, "feature");<br>
   // If there is a match<br>
   if (FeatureEntry) {<br>
     if ((Bits & FeatureEntry->Value) == FeatureEntry->Value) {<br>
@@ -242,10 +267,6 @@ SubtargetFeatures::ToggleFeature(uint64_<br>
       // For each feature that this implies, set it.<br>
       SetImpliedBits(Bits, FeatureEntry, FeatureTable, FeatureTableSize);<br>
     }<br>
-  } else {<br>
-    errs() << "'" << Feature<br>
-           << "' is not a recognized feature for this target"<br>
-           << " (ignoring feature)\n";<br>
   }<br>
<br>
   return Bits;<br>
@@ -280,7 +301,8 @@ uint64_t SubtargetFeatures::getFeatureBi<br>
<br>
   // Find CPU entry if CPU name is specified.<br>
   if (!CPU.empty()) {<br>
-    const SubtargetFeatureKV *CPUEntry = Find(CPU, CPUTable, CPUTableSize);<br>
+    const SubtargetFeatureKV *CPUEntry = Find(CPU, CPUTable, CPUTableSize,<br>
+                                              "processor");<br>
     // If there is a match<br>
     if (CPUEntry) {<br>
       // Set base feature bits<br>
@@ -292,10 +314,6 @@ uint64_t SubtargetFeatures::getFeatureBi<br>
         if (CPUEntry->Value & FE.Value)<br>
           SetImpliedBits(Bits, &FE, FeatureTable, FeatureTableSize);<br>
       }<br>
-    } else {<br>
-      errs() << "'" << CPU<br>
-             << "' is not a recognized processor for this target"<br>
-             << " (ignoring processor)\n";<br>
     }<br>
   }<br>
<br>
@@ -309,7 +327,7 @@ uint64_t SubtargetFeatures::getFeatureBi<br>
<br>
     // Find feature in table.<br>
     const SubtargetFeatureKV *FeatureEntry =<br>
-                       Find(StripFlag(Feature), FeatureTable, FeatureTableSize);<br>
+            Find(StripFlag(Feature), FeatureTable, FeatureTableSize, "feature");<br>
     // If there is a match<br>
     if (FeatureEntry) {<br>
       // Enable/disable feature in bits<br>
@@ -324,10 +342,6 @@ uint64_t SubtargetFeatures::getFeatureBi<br>
         // For each feature that implies this, clear it.<br>
         ClearImpliedBits(Bits, FeatureEntry, FeatureTable, FeatureTableSize);<br>
       }<br>
-    } else {<br>
-      errs() << "'" << Feature<br>
-             << "' is not a recognized feature for this target"<br>
-             << " (ignoring feature)\n";<br>
     }<br>
   }<br>
<br>
<br>
Added: llvm/trunk/test/MC/ARM/unrecognized.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/unrecognized.ll?rev=199886&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/unrecognized.ll?rev=199886&view=auto</a><br>

==============================================================================<br>
--- llvm/trunk/test/MC/ARM/unrecognized.ll (added)<br>
+++ llvm/trunk/test/MC/ARM/unrecognized.ll Thu Jan 23 05:31:38 2014<br>
@@ -0,0 +1,15 @@<br>
+; RUN: llc -mcpu=invalid -o /dev/null %s 2>&1 | FileCheck %s --check-prefix=CPU<br>
+; CPU:     'invalid' is not a recognized processor for this target (ignoring processor)<br>
+; CPU-NOT: 'invalid' is not a recognized processor for this target (ignoring processor)<br>
+<br>
+; RUN: llc -mattr=+foo,+bar -o /dev/null %s 2>&1 | FileCheck %s --check-prefix=FEATURE<br>
+; FEATURE:      'foo' is not a recognized feature for this target (ignoring feature)<br>
+; FEATURE-NEXT: 'bar' is not a recognized feature for this target (ignoring feature)<br>
+; FEATURE-NOT:  'foo' is not a recognized feature for this target (ignoring feature)<br>
+; FEATURE-NOT:  'bar' is not a recognized feature for this target (ignoring feature)<br>
+<br>
+define void @foo() {<br>
+entry:<br>
+  ret void<br>
+}<br>
+<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>