[llvm-commits] [llvm] r152197 - in /llvm/trunk: include/llvm/DerivedTypes.h lib/VMCore/Type.cpp
Bill Wendling
wendling at apple.com
Tue Mar 6 23:46:29 PST 2012
Yay!!! :-)
-bw
On Mar 6, 2012, at 7:00 PM, Chandler Carruth wrote:
> For those following along, this also helped -O0 quite a bit too.
>
> 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.
>
> On Tue, Mar 6, 2012 at 6:33 PM, Chandler Carruth <chandlerc at gmail.com> wrote:
> Author: chandlerc
> Date: Tue Mar 6 20:33:09 2012
> New Revision: 152197
>
> URL: http://llvm.org/viewvc/llvm-project?rev=152197&view=rev
> Log:
> Cache the sized-ness of struct types, once we reach the steady state of
> "is sized". This prevents every query to isSized() from recursing over
> every sub-type of a struct type. This could get *very* slow for
> extremely deep nesting of structs, as in 177.mesa.
>
> This change is a 45% speedup for 'opt -O2' of 177.mesa.linked.bc, and
> likely a significant speedup for other cases as well. It even impacts
> -O0 cases because so many part of the code try to check whether a type
> is sized.
>
> Thanks for the review from Nick Lewycky and Benjamin Kramer on IRC.
>
> Modified:
> llvm/trunk/include/llvm/DerivedTypes.h
> llvm/trunk/lib/VMCore/Type.cpp
>
> Modified: llvm/trunk/include/llvm/DerivedTypes.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DerivedTypes.h?rev=152197&r1=152196&r2=152197&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/DerivedTypes.h (original)
> +++ llvm/trunk/include/llvm/DerivedTypes.h Tue Mar 6 20:33:09 2012
> @@ -195,9 +195,10 @@
> // This is the contents of the SubClassData field.
> SCDB_HasBody = 1,
> SCDB_Packed = 2,
> - SCDB_IsLiteral = 4
> + SCDB_IsLiteral = 4,
> + SCDB_IsSized = 8
> };
> -
> +
> /// SymbolTableEntry - For a named struct that actually has a name, this is a
> /// pointer to the symbol table entry (maintained by LLVMContext) for the
> /// struct. This is null if the type is an literal struct or if it is
> @@ -248,6 +249,9 @@
> /// isOpaque - Return true if this is a type with an identity that has no body
> /// specified yet. These prints as 'opaque' in .ll files.
> bool isOpaque() const { return (getSubclassData() & SCDB_HasBody) == 0; }
> +
> + /// isSized - Return true if this is a sized type.
> + bool isSized() const;
>
> /// hasName - Return true if this is a named struct that has a non-empty name.
> bool hasName() const { return SymbolTableEntry != 0; }
>
> Modified: llvm/trunk/lib/VMCore/Type.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Type.cpp?rev=152197&r1=152196&r2=152197&view=diff
> ==============================================================================
> --- llvm/trunk/lib/VMCore/Type.cpp (original)
> +++ llvm/trunk/lib/VMCore/Type.cpp Tue Mar 6 20:33:09 2012
> @@ -185,16 +185,7 @@
> if (!this->isStructTy())
> return false;
>
> - // Opaque structs have no size.
> - if (cast<StructType>(this)->isOpaque())
> - return false;
> -
> - // Okay, our struct is sized if all of the elements are.
> - for (subtype_iterator I = subtype_begin(), E = subtype_end(); I != E; ++I)
> - if (!(*I)->isSized())
> - return false;
> -
> - return true;
> + return cast<StructType>(this)->isSized();
> }
>
> //===----------------------------------------------------------------------===//
> @@ -579,6 +570,26 @@
> return llvm::StructType::create(Ctx, StructFields, Name);
> }
>
> +bool StructType::isSized() const {
> + if ((getSubclassData() & SCDB_IsSized) != 0)
> + return true;
> + if (isOpaque())
> + return false;
> +
> + // Okay, our struct is sized if all of the elements are, but if one of the
> + // elements is opaque, the struct isn't sized *yet*, but may become sized in
> + // the future, so just bail out without caching.
> + for (element_iterator I = element_begin(), E = element_end(); I != E; ++I)
> + if (!(*I)->isSized())
> + return false;
> +
> + // Here we cheat a bit and cast away const-ness. The goal is to memoize when
> + // we find a sized type, as types can only move from opaque to sized, not the
> + // other way.
> + const_cast<StructType*>(this)->setSubclassData(
> + getSubclassData() | SCDB_IsSized);
> + return true;
> +}
>
> StringRef StructType::getName() const {
> assert(!isLiteral() && "Literal structs never have names");
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list