[C++11] Modernize the IR library a bit.

No functionality change.

llvm-svn: 203465
This commit is contained in:
Benjamin Kramer
2014-03-10 15:03:06 +00:00
parent 059e4b158c
commit 3ad5c96268
8 changed files with 50 additions and 78 deletions

View File

@@ -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,