For those following along, this also helped -O0 quite a bit too.<div><br></div><div>My perf runs show a 22% improvement in the 'clang -O0' time for the linked bitcode of 177.mesa, and looking at the slowest to compile file that Bill Wendling identified, 'get.c', I see a 20% improvement in the 'clang -O0' time for that individual file as well.<br>
<br><div class="gmail_quote">On Tue, Mar 6, 2012 at 6:33 PM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@gmail.com">chandlerc@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: chandlerc<br>
Date: Tue Mar  6 20:33:09 2012<br>
New Revision: 152197<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=152197&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=152197&view=rev</a><br>
Log:<br>
Cache the sized-ness of struct types, once we reach the steady state of<br>
"is sized". This prevents every query to isSized() from recursing over<br>
every sub-type of a struct type. This could get *very* slow for<br>
extremely deep nesting of structs, as in 177.mesa.<br>
<br>
This change is a 45% speedup for 'opt -O2' of 177.mesa.linked.bc, and<br>
likely a significant speedup for other cases as well. It even impacts<br>
-O0 cases because so many part of the code try to check whether a type<br>
is sized.<br>
<br>
Thanks for the review from Nick Lewycky and Benjamin Kramer on IRC.<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/DerivedTypes.h<br>
    llvm/trunk/lib/VMCore/Type.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/DerivedTypes.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DerivedTypes.h?rev=152197&r1=152196&r2=152197&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DerivedTypes.h?rev=152197&r1=152196&r2=152197&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/include/llvm/DerivedTypes.h (original)<br>
+++ llvm/trunk/include/llvm/DerivedTypes.h Tue Mar  6 20:33:09 2012<br>
@@ -195,9 +195,10 @@<br>
     // This is the contents of the SubClassData field.<br>
     SCDB_HasBody = 1,<br>
     SCDB_Packed = 2,<br>
-    SCDB_IsLiteral = 4<br>
+    SCDB_IsLiteral = 4,<br>
+    SCDB_IsSized = 8<br>
   };<br>
-<br>
+<br>
   /// SymbolTableEntry - For a named struct that actually has a name, this is a<br>
   /// pointer to the symbol table entry (maintained by LLVMContext) for the<br>
   /// struct.  This is null if the type is an literal struct or if it is<br>
@@ -248,6 +249,9 @@<br>
   /// isOpaque - Return true if this is a type with an identity that has no body<br>
   /// specified yet.  These prints as 'opaque' in .ll files.<br>
   bool isOpaque() const { return (getSubclassData() & SCDB_HasBody) == 0; }<br>
+<br>
+  /// isSized - Return true if this is a sized type.<br>
+  bool isSized() const;<br>
<br>
   /// hasName - Return true if this is a named struct that has a non-empty name.<br>
   bool hasName() const { return SymbolTableEntry != 0; }<br>
<br>
Modified: llvm/trunk/lib/VMCore/Type.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Type.cpp?rev=152197&r1=152196&r2=152197&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Type.cpp?rev=152197&r1=152196&r2=152197&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/VMCore/Type.cpp (original)<br>
+++ llvm/trunk/lib/VMCore/Type.cpp Tue Mar  6 20:33:09 2012<br>
@@ -185,16 +185,7 @@<br>
   if (!this->isStructTy())<br>
     return false;<br>
<br>
-  // Opaque structs have no size.<br>
-  if (cast<StructType>(this)->isOpaque())<br>
-    return false;<br>
-<br>
-  // Okay, our struct is sized if all of the elements are.<br>
-  for (subtype_iterator I = subtype_begin(), E = subtype_end(); I != E; ++I)<br>
-    if (!(*I)->isSized())<br>
-      return false;<br>
-<br>
-  return true;<br>
+  return cast<StructType>(this)->isSized();<br>
 }<br>
<br>
 //===----------------------------------------------------------------------===//<br>
@@ -579,6 +570,26 @@<br>
   return llvm::StructType::create(Ctx, StructFields, Name);<br>
 }<br>
<br>
+bool StructType::isSized() const {<br>
+  if ((getSubclassData() & SCDB_IsSized) != 0)<br>
+    return true;<br>
+  if (isOpaque())<br>
+    return false;<br>
+<br>
+  // Okay, our struct is sized if all of the elements are, but if one of the<br>
+  // elements is opaque, the struct isn't sized *yet*, but may become sized in<br>
+  // the future, so just bail out without caching.<br>
+  for (element_iterator I = element_begin(), E = element_end(); I != E; ++I)<br>
+    if (!(*I)->isSized())<br>
+      return false;<br>
+<br>
+  // Here we cheat a bit and cast away const-ness. The goal is to memoize when<br>
+  // we find a sized type, as types can only move from opaque to sized, not the<br>
+  // other way.<br>
+  const_cast<StructType*>(this)->setSubclassData(<br>
+    getSubclassData() | SCDB_IsSized);<br>
+  return true;<br>
+}<br>
<br>
 StringRef StructType::getName() const {<br>
   assert(!isLiteral() && "Literal structs never have names");<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>