summaryrefslogtreecommitdiff
path: root/lib/IR/DataLayout.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2014-03-10 15:03:06 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2014-03-10 15:03:06 +0000
commit6e9eeab69f0ce496d0120f9718e026f319d2ab01 (patch)
treef389bfb8de421b8380413c1f04454c2dbbea203c /lib/IR/DataLayout.cpp
parente1820a6a4e5cfd1a41bd40ce6c21635d04289fec (diff)
downloadllvm-6e9eeab69f0ce496d0120f9718e026f319d2ab01.tar.gz
llvm-6e9eeab69f0ce496d0120f9718e026f319d2ab01.tar.bz2
llvm-6e9eeab69f0ce496d0120f9718e026f319d2ab01.tar.xz
[C++11] Modernize the IR library a bit.
No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203465 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR/DataLayout.cpp')
-rw-r--r--lib/IR/DataLayout.cpp58
1 files changed, 21 insertions, 37 deletions
diff --git a/lib/IR/DataLayout.cpp b/lib/IR/DataLayout.cpp
index e6ca17a6eb..5654e15ae3 100644
--- a/lib/IR/DataLayout.cpp
+++ b/lib/IR/DataLayout.cpp
@@ -185,8 +185,7 @@ void DataLayout::reset(StringRef Desc) {
ManglingMode = MM_None;
// Default alignments
- for (int I = 0, N = array_lengthof(DefaultAlignments); I < N; ++I) {
- const LayoutAlignElem &E = DefaultAlignments[I];
+ for (const LayoutAlignElem &E : DefaultAlignments) {
setAlignment((AlignTypeEnum)E.AlignType, E.ABIAlign, E.PrefAlign,
E.TypeBitWidth);
}
@@ -370,12 +369,12 @@ DataLayout::setAlignment(AlignTypeEnum align_type, unsigned abi_align,
assert(abi_align <= pref_align && "Preferred alignment worse than ABI!");
assert(pref_align < (1 << 16) && "Alignment doesn't fit in bitfield");
assert(bit_width < (1 << 24) && "Bit width doesn't fit in bitfield");
- for (unsigned i = 0, e = Alignments.size(); i != e; ++i) {
- if (Alignments[i].AlignType == (unsigned)align_type &&
- Alignments[i].TypeBitWidth == bit_width) {
+ for (LayoutAlignElem &Elem : Alignments) {
+ if (Elem.AlignType == (unsigned)align_type &&
+ Elem.TypeBitWidth == bit_width) {
// Update the abi, preferred alignments.
- Alignments[i].ABIAlign = abi_align;
- Alignments[i].PrefAlign = pref_align;
+ Elem.ABIAlign = abi_align;
+ Elem.PrefAlign = pref_align;
return;
}
}
@@ -384,15 +383,12 @@ DataLayout::setAlignment(AlignTypeEnum align_type, unsigned abi_align,
pref_align, bit_width));
}
-static bool comparePointerAlignElem(const PointerAlignElem &A,
- uint32_t AddressSpace) {
- return A.AddressSpace < AddressSpace;
-}
-
DataLayout::PointersTy::iterator
DataLayout::findPointerLowerBound(uint32_t AddressSpace) {
return std::lower_bound(Pointers.begin(), Pointers.end(), AddressSpace,
- comparePointerAlignElem);
+ [](const PointerAlignElem &A, uint32_t AddressSpace) {
+ return A.AddressSpace < AddressSpace;
+ });
}
void DataLayout::setPointerAlignment(uint32_t AddrSpace, unsigned ABIAlign,
@@ -472,11 +468,10 @@ class StructLayoutMap {
LayoutInfoTy LayoutInfo;
public:
- virtual ~StructLayoutMap() {
+ ~StructLayoutMap() {
// Remove any layouts.
- for (LayoutInfoTy::iterator I = LayoutInfo.begin(), E = LayoutInfo.end();
- I != E; ++I) {
- StructLayout *Value = I->second;
+ for (const auto &I : LayoutInfo) {
+ StructLayout *Value = I.second;
Value->~StructLayout();
free(Value);
}
@@ -485,9 +480,6 @@ public:
StructLayout *&operator[](StructType *STy) {
return LayoutInfo[STy];
}
-
- // for debugging...
- virtual void dump() const {}
};
} // end anonymous namespace
@@ -550,10 +542,7 @@ std::string DataLayout::getStringRepresentation() const {
break;
}
- for (PointersTy::const_iterator I = Pointers.begin(), E = Pointers.end();
- I != E; ++I) {
- const PointerAlignElem &PI = *I;
-
+ for (const PointerAlignElem &PI : Pointers) {
// Skip default.
if (PI.AddressSpace == 0 && PI.ABIAlign == 8 && PI.PrefAlign == 8 &&
PI.TypeByteWidth == 8)
@@ -568,12 +557,9 @@ std::string DataLayout::getStringRepresentation() const {
OS << ':' << PI.PrefAlign*8;
}
- const LayoutAlignElem *DefaultStart = DefaultAlignments;
- const LayoutAlignElem *DefaultEnd =
- DefaultStart + array_lengthof(DefaultAlignments);
- for (unsigned i = 0, e = Alignments.size(); i != e; ++i) {
- const LayoutAlignElem &AI = Alignments[i];
- if (std::find(DefaultStart, DefaultEnd, AI) != DefaultEnd)
+ for (const LayoutAlignElem &AI : Alignments) {
+ if (std::find(std::begin(DefaultAlignments), std::end(DefaultAlignments),
+ AI) != std::end(DefaultAlignments))
continue;
OS << '-' << (char)AI.AlignType;
if (AI.TypeBitWidth)
@@ -731,17 +717,15 @@ Type *DataLayout::getIntPtrType(Type *Ty) const {
}
Type *DataLayout::getSmallestLegalIntType(LLVMContext &C, unsigned Width) const {
- for (unsigned i = 0, e = (unsigned)LegalIntWidths.size(); i != e; ++i)
- if (Width <= LegalIntWidths[i])
- return Type::getIntNTy(C, LegalIntWidths[i]);
+ for (unsigned LegalIntWidth : LegalIntWidths)
+ if (Width <= LegalIntWidth)
+ return Type::getIntNTy(C, LegalIntWidth);
return 0;
}
unsigned DataLayout::getLargestLegalIntTypeSize() const {
- unsigned MaxWidth = 0;
- for (unsigned i = 0, e = (unsigned)LegalIntWidths.size(); i != e; ++i)
- MaxWidth = std::max<unsigned>(MaxWidth, LegalIntWidths[i]);
- return MaxWidth;
+ auto Max = std::max_element(LegalIntWidths.begin(), LegalIntWidths.end());
+ return Max != LegalIntWidths.end() ? *Max : 0;
}
uint64_t DataLayout::getIndexedOffset(Type *ptrTy,