mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
[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
This commit is contained in:
@@ -219,8 +219,8 @@ public:
|
|||||||
/// The width is specified in bits.
|
/// The width is specified in bits.
|
||||||
///
|
///
|
||||||
bool isLegalInteger(unsigned Width) const {
|
bool isLegalInteger(unsigned Width) const {
|
||||||
for (unsigned i = 0, e = (unsigned)LegalIntWidths.size(); i != e; ++i)
|
for (unsigned LegalIntWidth : LegalIntWidths)
|
||||||
if (LegalIntWidths[i] == Width)
|
if (LegalIntWidth == Width)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -283,8 +283,8 @@ public:
|
|||||||
/// only supports i32 as a native integer type, then i27 fits in a legal
|
/// only supports i32 as a native integer type, then i27 fits in a legal
|
||||||
// integer type but i45 does not.
|
// integer type but i45 does not.
|
||||||
bool fitsInLegalInteger(unsigned Width) const {
|
bool fitsInLegalInteger(unsigned Width) const {
|
||||||
for (unsigned i = 0, e = (unsigned)LegalIntWidths.size(); i != e; ++i)
|
for (unsigned LegalIntWidth : LegalIntWidths)
|
||||||
if (Width <= LegalIntWidths[i])
|
if (Width <= LegalIntWidth)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -174,11 +174,8 @@ public:
|
|||||||
/// given name, an offset and a parent in the TBAA type DAG.
|
/// given name, an offset and a parent in the TBAA type DAG.
|
||||||
MDNode *createTBAAScalarTypeNode(StringRef Name, MDNode *Parent,
|
MDNode *createTBAAScalarTypeNode(StringRef Name, MDNode *Parent,
|
||||||
uint64_t Offset = 0) {
|
uint64_t Offset = 0) {
|
||||||
SmallVector<Value *, 4> Ops(3);
|
ConstantInt *Off = ConstantInt::get(Type::getInt64Ty(Context), Offset);
|
||||||
Type *Int64 = IntegerType::get(Context, 64);
|
Value *Ops[3] = { createString(Name), Parent, Off };
|
||||||
Ops[0] = createString(Name);
|
|
||||||
Ops[1] = Parent;
|
|
||||||
Ops[2] = ConstantInt::get(Int64, Offset);
|
|
||||||
return MDNode::get(Context, Ops);
|
return MDNode::get(Context, Ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -178,8 +178,8 @@ public:
|
|||||||
// delete.
|
// delete.
|
||||||
//
|
//
|
||||||
void dropAllReferences() {
|
void dropAllReferences() {
|
||||||
for (op_iterator i = op_begin(), e = op_end(); i != e; ++i)
|
for (Use &U : operands())
|
||||||
i->set(0);
|
U.set(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// replaceUsesOfWith - Replaces all references to the "From" definition with
|
/// replaceUsesOfWith - Replaces all references to the "From" definition with
|
||||||
|
@@ -185,8 +185,7 @@ void DataLayout::reset(StringRef Desc) {
|
|||||||
ManglingMode = MM_None;
|
ManglingMode = MM_None;
|
||||||
|
|
||||||
// Default alignments
|
// Default alignments
|
||||||
for (int I = 0, N = array_lengthof(DefaultAlignments); I < N; ++I) {
|
for (const LayoutAlignElem &E : DefaultAlignments) {
|
||||||
const LayoutAlignElem &E = DefaultAlignments[I];
|
|
||||||
setAlignment((AlignTypeEnum)E.AlignType, E.ABIAlign, E.PrefAlign,
|
setAlignment((AlignTypeEnum)E.AlignType, E.ABIAlign, E.PrefAlign,
|
||||||
E.TypeBitWidth);
|
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(abi_align <= pref_align && "Preferred alignment worse than ABI!");
|
||||||
assert(pref_align < (1 << 16) && "Alignment doesn't fit in bitfield");
|
assert(pref_align < (1 << 16) && "Alignment doesn't fit in bitfield");
|
||||||
assert(bit_width < (1 << 24) && "Bit width 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) {
|
for (LayoutAlignElem &Elem : Alignments) {
|
||||||
if (Alignments[i].AlignType == (unsigned)align_type &&
|
if (Elem.AlignType == (unsigned)align_type &&
|
||||||
Alignments[i].TypeBitWidth == bit_width) {
|
Elem.TypeBitWidth == bit_width) {
|
||||||
// Update the abi, preferred alignments.
|
// Update the abi, preferred alignments.
|
||||||
Alignments[i].ABIAlign = abi_align;
|
Elem.ABIAlign = abi_align;
|
||||||
Alignments[i].PrefAlign = pref_align;
|
Elem.PrefAlign = pref_align;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -384,15 +383,12 @@ DataLayout::setAlignment(AlignTypeEnum align_type, unsigned abi_align,
|
|||||||
pref_align, bit_width));
|
pref_align, bit_width));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool comparePointerAlignElem(const PointerAlignElem &A,
|
|
||||||
uint32_t AddressSpace) {
|
|
||||||
return A.AddressSpace < AddressSpace;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataLayout::PointersTy::iterator
|
DataLayout::PointersTy::iterator
|
||||||
DataLayout::findPointerLowerBound(uint32_t AddressSpace) {
|
DataLayout::findPointerLowerBound(uint32_t AddressSpace) {
|
||||||
return std::lower_bound(Pointers.begin(), Pointers.end(), 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,
|
void DataLayout::setPointerAlignment(uint32_t AddrSpace, unsigned ABIAlign,
|
||||||
@@ -472,11 +468,10 @@ class StructLayoutMap {
|
|||||||
LayoutInfoTy LayoutInfo;
|
LayoutInfoTy LayoutInfo;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~StructLayoutMap() {
|
~StructLayoutMap() {
|
||||||
// Remove any layouts.
|
// Remove any layouts.
|
||||||
for (LayoutInfoTy::iterator I = LayoutInfo.begin(), E = LayoutInfo.end();
|
for (const auto &I : LayoutInfo) {
|
||||||
I != E; ++I) {
|
StructLayout *Value = I.second;
|
||||||
StructLayout *Value = I->second;
|
|
||||||
Value->~StructLayout();
|
Value->~StructLayout();
|
||||||
free(Value);
|
free(Value);
|
||||||
}
|
}
|
||||||
@@ -485,9 +480,6 @@ public:
|
|||||||
StructLayout *&operator[](StructType *STy) {
|
StructLayout *&operator[](StructType *STy) {
|
||||||
return LayoutInfo[STy];
|
return LayoutInfo[STy];
|
||||||
}
|
}
|
||||||
|
|
||||||
// for debugging...
|
|
||||||
virtual void dump() const {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
@@ -550,10 +542,7 @@ std::string DataLayout::getStringRepresentation() const {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (PointersTy::const_iterator I = Pointers.begin(), E = Pointers.end();
|
for (const PointerAlignElem &PI : Pointers) {
|
||||||
I != E; ++I) {
|
|
||||||
const PointerAlignElem &PI = *I;
|
|
||||||
|
|
||||||
// Skip default.
|
// Skip default.
|
||||||
if (PI.AddressSpace == 0 && PI.ABIAlign == 8 && PI.PrefAlign == 8 &&
|
if (PI.AddressSpace == 0 && PI.ABIAlign == 8 && PI.PrefAlign == 8 &&
|
||||||
PI.TypeByteWidth == 8)
|
PI.TypeByteWidth == 8)
|
||||||
@@ -568,12 +557,9 @@ std::string DataLayout::getStringRepresentation() const {
|
|||||||
OS << ':' << PI.PrefAlign*8;
|
OS << ':' << PI.PrefAlign*8;
|
||||||
}
|
}
|
||||||
|
|
||||||
const LayoutAlignElem *DefaultStart = DefaultAlignments;
|
for (const LayoutAlignElem &AI : Alignments) {
|
||||||
const LayoutAlignElem *DefaultEnd =
|
if (std::find(std::begin(DefaultAlignments), std::end(DefaultAlignments),
|
||||||
DefaultStart + array_lengthof(DefaultAlignments);
|
AI) != std::end(DefaultAlignments))
|
||||||
for (unsigned i = 0, e = Alignments.size(); i != e; ++i) {
|
|
||||||
const LayoutAlignElem &AI = Alignments[i];
|
|
||||||
if (std::find(DefaultStart, DefaultEnd, AI) != DefaultEnd)
|
|
||||||
continue;
|
continue;
|
||||||
OS << '-' << (char)AI.AlignType;
|
OS << '-' << (char)AI.AlignType;
|
||||||
if (AI.TypeBitWidth)
|
if (AI.TypeBitWidth)
|
||||||
@@ -731,17 +717,15 @@ Type *DataLayout::getIntPtrType(Type *Ty) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Type *DataLayout::getSmallestLegalIntType(LLVMContext &C, unsigned Width) const {
|
Type *DataLayout::getSmallestLegalIntType(LLVMContext &C, unsigned Width) const {
|
||||||
for (unsigned i = 0, e = (unsigned)LegalIntWidths.size(); i != e; ++i)
|
for (unsigned LegalIntWidth : LegalIntWidths)
|
||||||
if (Width <= LegalIntWidths[i])
|
if (Width <= LegalIntWidth)
|
||||||
return Type::getIntNTy(C, LegalIntWidths[i]);
|
return Type::getIntNTy(C, LegalIntWidth);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned DataLayout::getLargestLegalIntTypeSize() const {
|
unsigned DataLayout::getLargestLegalIntTypeSize() const {
|
||||||
unsigned MaxWidth = 0;
|
auto Max = std::max_element(LegalIntWidths.begin(), LegalIntWidths.end());
|
||||||
for (unsigned i = 0, e = (unsigned)LegalIntWidths.size(); i != e; ++i)
|
return Max != LegalIntWidths.end() ? *Max : 0;
|
||||||
MaxWidth = std::max<unsigned>(MaxWidth, LegalIntWidths[i]);
|
|
||||||
return MaxWidth;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t DataLayout::getIndexedOffset(Type *ptrTy,
|
uint64_t DataLayout::getIndexedOffset(Type *ptrTy,
|
||||||
|
@@ -281,9 +281,8 @@ bool Instruction::isIdenticalToWhenDefined(const Instruction *I) const {
|
|||||||
|
|
||||||
// We have two instructions of identical opcode and #operands. Check to see
|
// We have two instructions of identical opcode and #operands. Check to see
|
||||||
// if all operands are the same.
|
// if all operands are the same.
|
||||||
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
|
if (!std::equal(op_begin(), op_end(), I->op_begin()))
|
||||||
if (getOperand(i) != I->getOperand(i))
|
return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
// Check special state that is a part of some instructions.
|
// Check special state that is a part of some instructions.
|
||||||
if (const LoadInst *LI = dyn_cast<LoadInst>(this))
|
if (const LoadInst *LI = dyn_cast<LoadInst>(this))
|
||||||
@@ -323,11 +322,8 @@ bool Instruction::isIdenticalToWhenDefined(const Instruction *I) const {
|
|||||||
RMWI->getSynchScope() == cast<AtomicRMWInst>(I)->getSynchScope();
|
RMWI->getSynchScope() == cast<AtomicRMWInst>(I)->getSynchScope();
|
||||||
if (const PHINode *thisPHI = dyn_cast<PHINode>(this)) {
|
if (const PHINode *thisPHI = dyn_cast<PHINode>(this)) {
|
||||||
const PHINode *otherPHI = cast<PHINode>(I);
|
const PHINode *otherPHI = cast<PHINode>(I);
|
||||||
for (unsigned i = 0, e = thisPHI->getNumOperands(); i != e; ++i) {
|
return std::equal(thisPHI->block_begin(), thisPHI->block_end(),
|
||||||
if (thisPHI->getIncomingBlock(i) != otherPHI->getIncomingBlock(i))
|
otherPHI->block_begin());
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -552,8 +548,8 @@ Instruction *Instruction::clone() const {
|
|||||||
// new one.
|
// new one.
|
||||||
SmallVector<std::pair<unsigned, MDNode*>, 4> TheMDs;
|
SmallVector<std::pair<unsigned, MDNode*>, 4> TheMDs;
|
||||||
getAllMetadataOtherThanDebugLoc(TheMDs);
|
getAllMetadataOtherThanDebugLoc(TheMDs);
|
||||||
for (unsigned i = 0, e = TheMDs.size(); i != e; ++i)
|
for (const auto &MD : TheMDs)
|
||||||
New->setMetadata(TheMDs[i].first, TheMDs[i].second);
|
New->setMetadata(MD.first, MD.second);
|
||||||
|
|
||||||
New->setDebugLoc(getDebugLoc());
|
New->setDebugLoc(getDebugLoc());
|
||||||
return New;
|
return New;
|
||||||
|
@@ -1578,11 +1578,11 @@ bool ShuffleVectorInst::isValidOperands(const Value *V1, const Value *V2,
|
|||||||
|
|
||||||
if (const ConstantVector *MV = dyn_cast<ConstantVector>(Mask)) {
|
if (const ConstantVector *MV = dyn_cast<ConstantVector>(Mask)) {
|
||||||
unsigned V1Size = cast<VectorType>(V1->getType())->getNumElements();
|
unsigned V1Size = cast<VectorType>(V1->getType())->getNumElements();
|
||||||
for (unsigned i = 0, e = MV->getNumOperands(); i != e; ++i) {
|
for (Value *Op : MV->operands()) {
|
||||||
if (ConstantInt *CI = dyn_cast<ConstantInt>(MV->getOperand(i))) {
|
if (ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
|
||||||
if (CI->uge(V1Size*2))
|
if (CI->uge(V1Size*2))
|
||||||
return false;
|
return false;
|
||||||
} else if (!isa<UndefValue>(MV->getOperand(i))) {
|
} else if (!isa<UndefValue>(Op)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1702,8 +1702,7 @@ ExtractValueInst::ExtractValueInst(const ExtractValueInst &EVI)
|
|||||||
//
|
//
|
||||||
Type *ExtractValueInst::getIndexedType(Type *Agg,
|
Type *ExtractValueInst::getIndexedType(Type *Agg,
|
||||||
ArrayRef<unsigned> Idxs) {
|
ArrayRef<unsigned> Idxs) {
|
||||||
for (unsigned CurIdx = 0; CurIdx != Idxs.size(); ++CurIdx) {
|
for (unsigned Index : Idxs) {
|
||||||
unsigned Index = Idxs[CurIdx];
|
|
||||||
// We can't use CompositeType::indexValid(Index) here.
|
// We can't use CompositeType::indexValid(Index) here.
|
||||||
// indexValid() always returns true for arrays because getelementptr allows
|
// indexValid() always returns true for arrays because getelementptr allows
|
||||||
// out-of-bounds indices. Since we don't allow those for extractvalue and
|
// out-of-bounds indices. Since we don't allow those for extractvalue and
|
||||||
|
@@ -224,8 +224,8 @@ MDNode *MDNode::getMDNode(LLVMContext &Context, ArrayRef<Value*> Vals,
|
|||||||
// Note that if the operands are later nulled out, the node will be
|
// Note that if the operands are later nulled out, the node will be
|
||||||
// removed from the uniquing map.
|
// removed from the uniquing map.
|
||||||
FoldingSetNodeID ID;
|
FoldingSetNodeID ID;
|
||||||
for (unsigned i = 0; i != Vals.size(); ++i)
|
for (Value *V : Vals)
|
||||||
ID.AddPointer(Vals[i]);
|
ID.AddPointer(V);
|
||||||
|
|
||||||
void *InsertPoint;
|
void *InsertPoint;
|
||||||
MDNode *N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
|
MDNode *N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
|
||||||
@@ -236,8 +236,7 @@ MDNode *MDNode::getMDNode(LLVMContext &Context, ArrayRef<Value*> Vals,
|
|||||||
bool isFunctionLocal = false;
|
bool isFunctionLocal = false;
|
||||||
switch (FL) {
|
switch (FL) {
|
||||||
case FL_Unknown:
|
case FL_Unknown:
|
||||||
for (unsigned i = 0; i != Vals.size(); ++i) {
|
for (Value *V : Vals) {
|
||||||
Value *V = Vals[i];
|
|
||||||
if (!V) continue;
|
if (!V) continue;
|
||||||
if (isFunctionLocalValue(V)) {
|
if (isFunctionLocalValue(V)) {
|
||||||
isFunctionLocal = true;
|
isFunctionLocal = true;
|
||||||
@@ -649,9 +648,9 @@ void Instruction::setMetadata(unsigned KindID, MDNode *Node) {
|
|||||||
setHasMetadataHashEntry(true);
|
setHasMetadataHashEntry(true);
|
||||||
} else {
|
} else {
|
||||||
// Handle replacement of an existing value.
|
// Handle replacement of an existing value.
|
||||||
for (unsigned i = 0, e = Info.size(); i != e; ++i)
|
for (auto &P : Info)
|
||||||
if (Info[i].first == KindID) {
|
if (P.first == KindID) {
|
||||||
Info[i].second = Node;
|
P.second = Node;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -697,10 +696,9 @@ MDNode *Instruction::getMetadataImpl(unsigned KindID) const {
|
|||||||
LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
|
LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
|
||||||
assert(!Info.empty() && "bit out of sync with hash table");
|
assert(!Info.empty() && "bit out of sync with hash table");
|
||||||
|
|
||||||
for (LLVMContextImpl::MDMapTy::iterator I = Info.begin(), E = Info.end();
|
for (const auto &I : Info)
|
||||||
I != E; ++I)
|
if (I.first == KindID)
|
||||||
if (I->first == KindID)
|
return I.second;
|
||||||
return I->second;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -271,8 +271,7 @@ getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const {
|
|||||||
const NamedMDNode *ModFlags = getModuleFlagsMetadata();
|
const NamedMDNode *ModFlags = getModuleFlagsMetadata();
|
||||||
if (!ModFlags) return;
|
if (!ModFlags) return;
|
||||||
|
|
||||||
for (unsigned i = 0, e = ModFlags->getNumOperands(); i != e; ++i) {
|
for (const MDNode *Flag : ModFlags->operands()) {
|
||||||
MDNode *Flag = ModFlags->getOperand(i);
|
|
||||||
if (Flag->getNumOperands() >= 3 && isa<ConstantInt>(Flag->getOperand(0)) &&
|
if (Flag->getNumOperands() >= 3 && isa<ConstantInt>(Flag->getOperand(0)) &&
|
||||||
isa<MDString>(Flag->getOperand(1))) {
|
isa<MDString>(Flag->getOperand(1))) {
|
||||||
// Check the operands of the MDNode before accessing the operands.
|
// Check the operands of the MDNode before accessing the operands.
|
||||||
@@ -291,8 +290,7 @@ getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const {
|
|||||||
Value *Module::getModuleFlag(StringRef Key) const {
|
Value *Module::getModuleFlag(StringRef Key) const {
|
||||||
SmallVector<Module::ModuleFlagEntry, 8> ModuleFlags;
|
SmallVector<Module::ModuleFlagEntry, 8> ModuleFlags;
|
||||||
getModuleFlagsMetadata(ModuleFlags);
|
getModuleFlagsMetadata(ModuleFlags);
|
||||||
for (unsigned I = 0, E = ModuleFlags.size(); I < E; ++I) {
|
for (const ModuleFlagEntry &MFE : ModuleFlags) {
|
||||||
const ModuleFlagEntry &MFE = ModuleFlags[I];
|
|
||||||
if (Key == MFE.Key->getString())
|
if (Key == MFE.Key->getString())
|
||||||
return MFE.Val;
|
return MFE.Val;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user