<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Dec 19, 2013 at 4:03 PM, Rafael Espindola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@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: rafael<br>
Date: Thu Dec 19 17:03:03 2013<br>
New Revision: 197740<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=197740&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=197740&view=rev</a><br>
Log:<br>
Change getStringRepresentation to skip defaults.<br>
<br>
I have a pending change for clang to use getStringRepresentation to check<br>
that its DataLayout is in sync with llvm's.<br></blockquote><div><br></div><div>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?</div>
<div><br></div><div>-- Sean Silva</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
getStringRepresentation is not called from llvm itself, so far it is mostly<br>
a debugging aid, so the shorter strings are an independent improvement.<br>
<br>
Modified:<br>
llvm/trunk/lib/IR/DataLayout.cpp<br>
<br>
Modified: llvm/trunk/lib/IR/DataLayout.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DataLayout.cpp?rev=197740&r1=197739&r2=197740&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DataLayout.cpp?rev=197740&r1=197739&r2=197740&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/IR/DataLayout.cpp (original)<br>
+++ llvm/trunk/lib/IR/DataLayout.cpp Thu Dec 19 17:03:03 2013<br>
@@ -18,6 +18,7 @@<br>
<br>
#include "llvm/IR/DataLayout.h"<br>
#include "llvm/ADT/DenseMap.h"<br>
+#include "llvm/ADT/STLExtras.h"<br>
#include "llvm/IR/Constants.h"<br>
#include "llvm/IR/DerivedTypes.h"<br>
#include "llvm/IR/Module.h"<br>
@@ -151,6 +152,21 @@ DataLayout::InvalidPointerElem = { 0U, 0<br>
// DataLayout Class Implementation<br>
//===----------------------------------------------------------------------===//<br>
<br>
+static LayoutAlignElem DefaultAlignments[] = {<br>
+ { INTEGER_ALIGN, 1, 1, 1 }, // i1<br>
+ { INTEGER_ALIGN, 8, 1, 1 }, // i8<br>
+ { INTEGER_ALIGN, 16, 2, 2 }, // i16<br>
+ { INTEGER_ALIGN, 32, 4, 4 }, // i32<br>
+ { INTEGER_ALIGN, 64, 4, 8 }, // i64<br>
+ { FLOAT_ALIGN, 16, 2, 2 }, // half<br>
+ { FLOAT_ALIGN, 32, 4, 4 }, // float<br>
+ { FLOAT_ALIGN, 64, 8, 8 }, // double<br>
+ { FLOAT_ALIGN, 128, 16, 16 }, // ppcf128, quad, ...<br>
+ { VECTOR_ALIGN, 64, 8, 8 }, // v2i32, v1i64, ...<br>
+ { VECTOR_ALIGN, 128, 16, 16 }, // v16i8, v8i16, v4i32, ...<br>
+ { AGGREGATE_ALIGN, 0, 0, 8 } // struct<br>
+};<br>
+<br>
void DataLayout::init(StringRef Desc) {<br>
initializeDataLayoutPass(*PassRegistry::getPassRegistry());<br>
<br>
@@ -159,18 +175,11 @@ void DataLayout::init(StringRef Desc) {<br>
StackNaturalAlign = 0;<br>
<br>
// Default alignments<br>
- setAlignment(INTEGER_ALIGN, 1, 1, 1); // i1<br>
- setAlignment(INTEGER_ALIGN, 1, 1, 8); // i8<br>
- setAlignment(INTEGER_ALIGN, 2, 2, 16); // i16<br>
- setAlignment(INTEGER_ALIGN, 4, 4, 32); // i32<br>
- setAlignment(INTEGER_ALIGN, 4, 8, 64); // i64<br>
- setAlignment(FLOAT_ALIGN, 2, 2, 16); // half<br>
- setAlignment(FLOAT_ALIGN, 4, 4, 32); // float<br>
- setAlignment(FLOAT_ALIGN, 8, 8, 64); // double<br>
- setAlignment(FLOAT_ALIGN, 16, 16, 128); // ppcf128, quad, ...<br>
- setAlignment(VECTOR_ALIGN, 8, 8, 64); // v2i32, v1i64, ...<br>
- setAlignment(VECTOR_ALIGN, 16, 16, 128); // v16i8, v8i16, v4i32, ...<br>
- setAlignment(AGGREGATE_ALIGN, 0, 8, 0); // struct<br>
+ for (int I = 0, N = array_lengthof(DefaultAlignments); I < N; ++I) {<br>
+ LayoutAlignElem &E = DefaultAlignments[I];<br>
+ setAlignment((AlignTypeEnum)E.AlignType, E.ABIAlign, E.PrefAlign,<br>
+ E.TypeBitWidth);<br>
+ }<br>
setPointerAlignment(0, 8, 8, 8);<br>
<br>
parseSpecifier(Desc);<br>
@@ -483,19 +492,34 @@ std::string DataLayout::getStringReprese<br>
for (SmallVectorImpl<unsigned>::iterator asb = addrSpaces.begin(),<br>
ase = addrSpaces.end(); asb != ase; ++asb) {<br>
const PointerAlignElem &PI = Pointers.find(*asb)->second;<br>
+<br>
+ // Skip default.<br>
+ if (PI.AddressSpace == 0 && PI.ABIAlign == 8 && PI.PrefAlign == 8 &&<br>
+ PI.TypeByteWidth == 8)<br>
+ continue;<br>
+<br>
OS << "-p";<br>
if (PI.AddressSpace) {<br>
OS << PI.AddressSpace;<br>
}<br>
- OS << ":" << PI.TypeByteWidth*8 << ':' << PI.ABIAlign*8<br>
- << ':' << PI.PrefAlign*8;<br>
+ OS << ":" << PI.TypeByteWidth*8 << ':' << PI.ABIAlign*8;<br>
+ if (PI.PrefAlign != PI.ABIAlign)<br>
+ OS << ':' << PI.PrefAlign*8;<br>
}<br>
- OS << "-S" << StackNaturalAlign*8;<br>
<br>
+ LayoutAlignElem *DefaultStart = DefaultAlignments;<br>
+ LayoutAlignElem *DefaultEnd =<br>
+ DefaultStart + array_lengthof(DefaultAlignments);<br>
for (unsigned i = 0, e = Alignments.size(); i != e; ++i) {<br>
const LayoutAlignElem &AI = Alignments[i];<br>
- OS << '-' << (char)AI.AlignType << AI.TypeBitWidth << ':'<br>
- << AI.ABIAlign*8 << ':' << AI.PrefAlign*8;<br>
+ if (std::find(DefaultStart, DefaultEnd, AI) != DefaultEnd)<br>
+ continue;<br>
+ OS << '-' << (char)AI.AlignType;<br>
+ if (AI.TypeBitWidth)<br>
+ OS << AI.TypeBitWidth;<br>
+ OS << ':' << AI.ABIAlign*8;<br>
+ if (AI.ABIAlign != AI.PrefAlign)<br>
+ OS << ':' << AI.PrefAlign*8;<br>
}<br>
<br>
if (!LegalIntWidths.empty()) {<br>
@@ -504,6 +528,10 @@ std::string DataLayout::getStringReprese<br>
for (unsigned i = 1, e = LegalIntWidths.size(); i != e; ++i)<br>
OS << ':' << (unsigned)LegalIntWidths[i];<br>
}<br>
+<br>
+ if (StackNaturalAlign)<br>
+ OS << "-S" << StackNaturalAlign*8;<br>
+<br>
return OS.str();<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></div>