[llvm] r197740 - Change getStringRepresentation to skip defaults.

Alp Toker alp at nuanti.com
Fri Dec 20 10:34:12 PST 2013


On 20/12/2013 17:47, Sean Silva wrote:
>
>
>
> On Thu, Dec 19, 2013 at 4:03 PM, Rafael Espindola 
> <rafael.espindola at gmail.com <mailto:rafael.espindola at gmail.com>> wrote:
>
>     Author: rafael
>     Date: Thu Dec 19 17:03:03 2013
>     New Revision: 197740
>
>     URL: http://llvm.org/viewvc/llvm-project?rev=197740&view=rev
>     Log:
>     Change getStringRepresentation to skip defaults.
>
>     I have a pending change for clang to use getStringRepresentation
>     to check
>     that its DataLayout is in sync with llvm's.
>
>
> What is the reason that we don't just have a single point of truth for 
> this? Phrased another way: why is it necessary to maintain these 
> DataLayout strings independently, once in clang and once in LLVM core?

Hi Sean,

It's just a matter of someone finding the time to split the DataLayout 
strings out of TargetMachine so clang can continue to work without 
making it mandatory to build all targets.

Until then asserting that they match in builds where the information is 
available is a step in the right direction.

Alp.



>
> -- Sean Silva
>
>
>     getStringRepresentation is not called from llvm itself, so far it
>     is mostly
>     a debugging aid, so the shorter strings are an independent
>     improvement.
>
>     Modified:
>         llvm/trunk/lib/IR/DataLayout.cpp
>
>     Modified: llvm/trunk/lib/IR/DataLayout.cpp
>     URL:
>     http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DataLayout.cpp?rev=197740&r1=197739&r2=197740&view=diff
>     ==============================================================================
>     --- llvm/trunk/lib/IR/DataLayout.cpp (original)
>     +++ llvm/trunk/lib/IR/DataLayout.cpp Thu Dec 19 17:03:03 2013
>     @@ -18,6 +18,7 @@
>
>      #include "llvm/IR/DataLayout.h"
>      #include "llvm/ADT/DenseMap.h"
>     +#include "llvm/ADT/STLExtras.h"
>      #include "llvm/IR/Constants.h"
>      #include "llvm/IR/DerivedTypes.h"
>      #include "llvm/IR/Module.h"
>     @@ -151,6 +152,21 @@ DataLayout::InvalidPointerElem = { 0U, 0
>      //                       DataLayout Class Implementation
>      //===----------------------------------------------------------------------===//
>
>     +static LayoutAlignElem DefaultAlignments[] = {
>     +  { INTEGER_ALIGN, 1, 1, 1 },    // i1
>     +  { INTEGER_ALIGN, 8, 1, 1 },    // i8
>     +  { INTEGER_ALIGN, 16, 2, 2 },   // i16
>     +  { INTEGER_ALIGN, 32, 4, 4 },   // i32
>     +  { INTEGER_ALIGN, 64, 4, 8 },   // i64
>     +  { FLOAT_ALIGN, 16, 2, 2 },     // half
>     +  { FLOAT_ALIGN, 32, 4, 4 },     // float
>     +  { FLOAT_ALIGN, 64, 8, 8 },     // double
>     +  { FLOAT_ALIGN, 128, 16, 16 },  // ppcf128, quad, ...
>     +  { VECTOR_ALIGN, 64, 8, 8 },    // v2i32, v1i64, ...
>     +  { VECTOR_ALIGN, 128, 16, 16 }, // v16i8, v8i16, v4i32, ...
>     +  { AGGREGATE_ALIGN, 0, 0, 8 }   // struct
>     +};
>     +
>      void DataLayout::init(StringRef Desc) {
>      initializeDataLayoutPass(*PassRegistry::getPassRegistry());
>
>     @@ -159,18 +175,11 @@ void DataLayout::init(StringRef Desc) {
>        StackNaturalAlign = 0;
>
>        // Default alignments
>     -  setAlignment(INTEGER_ALIGN,   1,  1, 1);   // i1
>     -  setAlignment(INTEGER_ALIGN,   1,  1, 8);   // i8
>     -  setAlignment(INTEGER_ALIGN,   2,  2, 16);  // i16
>     -  setAlignment(INTEGER_ALIGN,   4,  4, 32);  // i32
>     -  setAlignment(INTEGER_ALIGN,   4,  8, 64);  // i64
>     -  setAlignment(FLOAT_ALIGN,     2,  2, 16);  // half
>     -  setAlignment(FLOAT_ALIGN,     4,  4, 32);  // float
>     -  setAlignment(FLOAT_ALIGN,     8,  8, 64);  // double
>     -  setAlignment(FLOAT_ALIGN,    16, 16, 128); // ppcf128, quad, ...
>     -  setAlignment(VECTOR_ALIGN,    8,  8, 64);  // v2i32, v1i64, ...
>     -  setAlignment(VECTOR_ALIGN,   16, 16, 128); // v16i8, v8i16,
>     v4i32, ...
>     -  setAlignment(AGGREGATE_ALIGN, 0,  8,  0);  // struct
>     +  for (int I = 0, N = array_lengthof(DefaultAlignments); I < N;
>     ++I) {
>     +    LayoutAlignElem &E = DefaultAlignments[I];
>     +    setAlignment((AlignTypeEnum)E.AlignType, E.ABIAlign, E.PrefAlign,
>     +                 E.TypeBitWidth);
>     +  }
>        setPointerAlignment(0, 8, 8, 8);
>
>        parseSpecifier(Desc);
>     @@ -483,19 +492,34 @@ std::string DataLayout::getStringReprese
>        for (SmallVectorImpl<unsigned>::iterator asb = addrSpaces.begin(),
>            ase = addrSpaces.end(); asb != ase; ++asb) {
>          const PointerAlignElem &PI = Pointers.find(*asb)->second;
>     +
>     +    // Skip default.
>     +    if (PI.AddressSpace == 0 && PI.ABIAlign == 8 && PI.PrefAlign
>     == 8 &&
>     +        PI.TypeByteWidth == 8)
>     +      continue;
>     +
>          OS << "-p";
>          if (PI.AddressSpace) {
>            OS << PI.AddressSpace;
>          }
>     -     OS << ":" << PI.TypeByteWidth*8 << ':' << PI.ABIAlign*8
>     -        << ':' << PI.PrefAlign*8;
>     +    OS << ":" << PI.TypeByteWidth*8 << ':' << PI.ABIAlign*8;
>     +    if (PI.PrefAlign != PI.ABIAlign)
>     +      OS << ':' << PI.PrefAlign*8;
>        }
>     -  OS << "-S" << StackNaturalAlign*8;
>
>     +  LayoutAlignElem *DefaultStart = DefaultAlignments;
>     +  LayoutAlignElem *DefaultEnd =
>     +      DefaultStart + array_lengthof(DefaultAlignments);
>        for (unsigned i = 0, e = Alignments.size(); i != e; ++i) {
>          const LayoutAlignElem &AI = Alignments[i];
>     -    OS << '-' << (char)AI.AlignType << AI.TypeBitWidth << ':'
>     -       << AI.ABIAlign*8 << ':' << AI.PrefAlign*8;
>     +    if (std::find(DefaultStart, DefaultEnd, AI) != DefaultEnd)
>     +      continue;
>     +    OS << '-' << (char)AI.AlignType;
>     +    if (AI.TypeBitWidth)
>     +      OS << AI.TypeBitWidth;
>     +    OS << ':' << AI.ABIAlign*8;
>     +    if (AI.ABIAlign != AI.PrefAlign)
>     +      OS << ':' << AI.PrefAlign*8;
>        }
>
>        if (!LegalIntWidths.empty()) {
>     @@ -504,6 +528,10 @@ std::string DataLayout::getStringReprese
>          for (unsigned i = 1, e = LegalIntWidths.size(); i != e; ++i)
>            OS << ':' << (unsigned)LegalIntWidths[i];
>        }
>     +
>     +  if (StackNaturalAlign)
>     +    OS << "-S" << StackNaturalAlign*8;
>     +
>        return OS.str();
>      }
>
>
>
>     _______________________________________________
>     llvm-commits mailing list
>     llvm-commits at cs.uiuc.edu <mailto: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

-- 
http://www.nuanti.com
the browser experts




More information about the llvm-commits mailing list