From 1e65676a12c61815acb65990d9269611ad544c78 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Patrik=20H=C3=A4gglund?= Date: Wed, 14 Nov 2012 09:04:56 +0000 Subject: [PATCH] Revert some redundant parts of r142605. This seems like redundant leftovers from r142288 - exposing TargetData::parseSpecifier to LLParser - which got reverted. Removes redunant td != NULL checks in parseSpecifier, and simplifies the interface to parseSpecifier and init. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167924 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/DataLayout.h | 20 ++++++++------------ lib/VMCore/DataLayout.cpp | 36 +++++++++++++++--------------------- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/include/llvm/DataLayout.h b/include/llvm/DataLayout.h index 24ad05f17f3..7d8eace1b62 100644 --- a/include/llvm/DataLayout.h +++ b/include/llvm/DataLayout.h @@ -148,9 +148,9 @@ private: return &align != &InvalidPointerElem; } - /// Initialise a DataLayout object with default values, ensure that the - /// target data pass is registered. - void init(); + /// Parses a target data specification string. Returns an error message + /// if the string is malformed, or the empty string on success. + std::string parseSpecifier(StringRef LayoutDescription); public: /// Default ctor. @@ -162,17 +162,9 @@ public: /// Constructs a DataLayout from a specification string. See init(). explicit DataLayout(StringRef LayoutDescription) : ImmutablePass(ID) { - std::string errMsg = parseSpecifier(LayoutDescription, this); - assert(errMsg == "" && "Invalid target data layout string."); - (void)errMsg; + init(LayoutDescription); } - /// Parses a target data specification string. Returns an error message - /// if the string is malformed, or the empty string on success. Optionally - /// initialises a DataLayout object if passed a non-null pointer. - static std::string parseSpecifier(StringRef LayoutDescription, - DataLayout* td = 0); - /// Initialize target data from properties stored in the module. explicit DataLayout(const Module *M); @@ -187,6 +179,10 @@ public: ~DataLayout(); // Not virtual, do not subclass this class + /// Parse a data layout string (with fallback to default values). Ensure that + /// the data layout pass is registered. + void init(StringRef LayoutDescription); + /// Layout endianness... bool isLittleEndian() const { return LittleEndian; } bool isBigEndian() const { return !LittleEndian; } diff --git a/lib/VMCore/DataLayout.cpp b/lib/VMCore/DataLayout.cpp index 19cf0f5cd3e..72dcb99b6d8 100644 --- a/lib/VMCore/DataLayout.cpp +++ b/lib/VMCore/DataLayout.cpp @@ -159,7 +159,7 @@ static int getInt(StringRef R) { return Result; } -void DataLayout::init() { +void DataLayout::init(StringRef Desc) { initializeDataLayoutPass(*PassRegistry::getPassRegistry()); LayoutMap = 0; @@ -180,12 +180,13 @@ void DataLayout::init() { setAlignment(VECTOR_ALIGN, 16, 16, 128); // v16i8, v8i16, v4i32, ... setAlignment(AGGREGATE_ALIGN, 0, 8, 0); // struct setPointerAlignment(0, 8, 8, 8); -} -std::string DataLayout::parseSpecifier(StringRef Desc, DataLayout *td) { + std::string errMsg = parseSpecifier(Desc); + assert(errMsg == "" && "Invalid target data layout string."); + (void)errMsg; +} - if (td) - td->init(); +std::string DataLayout::parseSpecifier(StringRef Desc) { while (!Desc.empty()) { std::pair Split = Desc.split('-'); @@ -203,12 +204,10 @@ std::string DataLayout::parseSpecifier(StringRef Desc, DataLayout *td) { switch (Specifier[0]) { case 'E': - if (td) - td->LittleEndian = false; + LittleEndian = false; break; case 'e': - if (td) - td->LittleEndian = true; + LittleEndian = true; break; case 'p': { int AddrSpace = 0; @@ -240,9 +239,8 @@ std::string DataLayout::parseSpecifier(StringRef Desc, DataLayout *td) { if (PointerPrefAlignBits == 0) PointerPrefAlignBits = PointerABIAlignBits; - if (td) - td->setPointerAlignment(AddrSpace, PointerABIAlignBits/8, - PointerPrefAlignBits/8, PointerMemSizeBits/8); + setPointerAlignment(AddrSpace, PointerABIAlignBits/8, + PointerPrefAlignBits/8, PointerMemSizeBits/8); break; } case 'i': @@ -284,9 +282,8 @@ std::string DataLayout::parseSpecifier(StringRef Desc, DataLayout *td) { unsigned PrefAlign = PrefAlignBits / 8; if (PrefAlign == 0) PrefAlign = ABIAlign; + setAlignment(AlignType, ABIAlign, PrefAlign, Size); - if (td) - td->setAlignment(AlignType, ABIAlign, PrefAlign, Size); break; } case 'n': // Native integer types. @@ -297,8 +294,8 @@ std::string DataLayout::parseSpecifier(StringRef Desc, DataLayout *td) { return std::string("invalid native integer size \'") + Specifier.str() + "\', must be a positive integer."; } - if (td && Width != 0) - td->LegalIntWidths.push_back(Width); + if (Width != 0) + LegalIntWidths.push_back(Width); Split = Token.split(':'); Specifier = Split.first; Token = Split.second; @@ -310,8 +307,7 @@ std::string DataLayout::parseSpecifier(StringRef Desc, DataLayout *td) { return "invalid natural stack alignment (S-field), " "must be a positive 8-bit multiple"; } - if (td) - td->StackNaturalAlign = StackNaturalAlignBits / 8; + StackNaturalAlign = StackNaturalAlignBits / 8; break; } default: @@ -333,9 +329,7 @@ DataLayout::DataLayout() : ImmutablePass(ID) { DataLayout::DataLayout(const Module *M) : ImmutablePass(ID) { - std::string errMsg = parseSpecifier(M->getDataLayout(), this); - assert(errMsg == "" && "Module M has malformed data layout string."); - (void)errMsg; + init(M->getDataLayout()); } void -- 2.34.1