mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-23 16:19:52 +00:00
Add a function object to compare the first or second component of a std::pair.
Replace instances of this scattered around the code base. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189169 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -217,6 +217,22 @@ inline tier<T1, T2> tie(T1& f, T2& s) {
|
|||||||
return tier<T1, T2>(f, s);
|
return tier<T1, T2>(f, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \brief Function object to check whether the first component of a std::pair
|
||||||
|
/// compares less than the first component of another std::pair.
|
||||||
|
struct less_first {
|
||||||
|
template <typename T> bool operator()(const T &lhs, const T &rhs) const {
|
||||||
|
return lhs.first < rhs.first;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// \brief Function object to check whether the second component of a std::pair
|
||||||
|
/// compares less than the second component of another std::pair.
|
||||||
|
struct less_second {
|
||||||
|
template <typename T> bool operator()(const T &lhs, const T &rhs) const {
|
||||||
|
return lhs.second < rhs.second;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// Extra additions for arrays
|
// Extra additions for arrays
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|||||||
@@ -1287,12 +1287,6 @@ void AsmPrinter::EmitLLVMUsedList(const ConstantArray *InitList) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef std::pair<unsigned, Constant*> Structor;
|
|
||||||
|
|
||||||
static bool priority_order(const Structor& lhs, const Structor& rhs) {
|
|
||||||
return lhs.first < rhs.first;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// EmitXXStructorList - Emit the ctor or dtor list taking into account the init
|
/// EmitXXStructorList - Emit the ctor or dtor list taking into account the init
|
||||||
/// priority.
|
/// priority.
|
||||||
void AsmPrinter::EmitXXStructorList(const Constant *List, bool isCtor) {
|
void AsmPrinter::EmitXXStructorList(const Constant *List, bool isCtor) {
|
||||||
@@ -1309,6 +1303,7 @@ void AsmPrinter::EmitXXStructorList(const Constant *List, bool isCtor) {
|
|||||||
!isa<PointerType>(ETy->getTypeAtIndex(1U))) return; // Not (int, ptr).
|
!isa<PointerType>(ETy->getTypeAtIndex(1U))) return; // Not (int, ptr).
|
||||||
|
|
||||||
// Gather the structors in a form that's convenient for sorting by priority.
|
// Gather the structors in a form that's convenient for sorting by priority.
|
||||||
|
typedef std::pair<unsigned, Constant *> Structor;
|
||||||
SmallVector<Structor, 8> Structors;
|
SmallVector<Structor, 8> Structors;
|
||||||
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
|
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
|
||||||
ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i));
|
ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i));
|
||||||
@@ -1324,7 +1319,7 @@ void AsmPrinter::EmitXXStructorList(const Constant *List, bool isCtor) {
|
|||||||
// Emit the function pointers in the target-specific order
|
// Emit the function pointers in the target-specific order
|
||||||
const DataLayout *TD = TM.getDataLayout();
|
const DataLayout *TD = TM.getDataLayout();
|
||||||
unsigned Align = Log2_32(TD->getPointerPrefAlignment());
|
unsigned Align = Log2_32(TD->getPointerPrefAlignment());
|
||||||
std::stable_sort(Structors.begin(), Structors.end(), priority_order);
|
std::stable_sort(Structors.begin(), Structors.end(), less_first());
|
||||||
for (unsigned i = 0, e = Structors.size(); i != e; ++i) {
|
for (unsigned i = 0, e = Structors.size(); i != e; ++i) {
|
||||||
const MCSection *OutputSection =
|
const MCSection *OutputSection =
|
||||||
(isCtor ?
|
(isCtor ?
|
||||||
|
|||||||
@@ -108,16 +108,8 @@ DwarfPubNames("generate-dwarf-pubnames", cl::Hidden,
|
|||||||
clEnumVal(Disable, "Disabled"), clEnumValEnd),
|
clEnumVal(Disable, "Disabled"), clEnumValEnd),
|
||||||
cl::init(Default));
|
cl::init(Default));
|
||||||
|
|
||||||
namespace {
|
static const char *const DWARFGroupName = "DWARF Emission";
|
||||||
const char *const DWARFGroupName = "DWARF Emission";
|
static const char *const DbgTimerName = "DWARF Debug Writer";
|
||||||
const char *const DbgTimerName = "DWARF Debug Writer";
|
|
||||||
|
|
||||||
struct CompareFirst {
|
|
||||||
template <typename T> bool operator()(const T &lhs, const T &rhs) const {
|
|
||||||
return lhs.first < rhs.first;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // end anonymous namespace
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
@@ -625,7 +617,7 @@ DIE *DwarfDebug::constructScopeDIE(CompileUnit *TheCU, LexicalScope *Scope) {
|
|||||||
ImportedEntityMap::const_iterator> Range = std::equal_range(
|
ImportedEntityMap::const_iterator> Range = std::equal_range(
|
||||||
ScopesWithImportedEntities.begin(), ScopesWithImportedEntities.end(),
|
ScopesWithImportedEntities.begin(), ScopesWithImportedEntities.end(),
|
||||||
std::pair<const MDNode *, const MDNode *>(DS, (const MDNode*)0),
|
std::pair<const MDNode *, const MDNode *>(DS, (const MDNode*)0),
|
||||||
CompareFirst());
|
less_first());
|
||||||
if (Children.empty() && Range.first == Range.second)
|
if (Children.empty() && Range.first == Range.second)
|
||||||
return NULL;
|
return NULL;
|
||||||
ScopeDIE = constructLexicalScopeDIE(TheCU, Scope);
|
ScopeDIE = constructLexicalScopeDIE(TheCU, Scope);
|
||||||
@@ -879,7 +871,7 @@ void DwarfDebug::beginModule() {
|
|||||||
DIImportedEntity(ImportedEntities.getElement(i)).getContext(),
|
DIImportedEntity(ImportedEntities.getElement(i)).getContext(),
|
||||||
ImportedEntities.getElement(i)));
|
ImportedEntities.getElement(i)));
|
||||||
std::sort(ScopesWithImportedEntities.begin(),
|
std::sort(ScopesWithImportedEntities.begin(),
|
||||||
ScopesWithImportedEntities.end(), CompareFirst());
|
ScopesWithImportedEntities.end(), less_first());
|
||||||
DIArray GVs = CUNode.getGlobalVariables();
|
DIArray GVs = CUNode.getGlobalVariables();
|
||||||
for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i)
|
for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i)
|
||||||
CU->createGlobalVariableDIE(GVs.getElement(i));
|
CU->createGlobalVariableDIE(GVs.getElement(i));
|
||||||
|
|||||||
@@ -690,15 +690,6 @@ void ScheduleDAGSDNodes::VerifyScheduledSequence(bool isBottomUp) {
|
|||||||
}
|
}
|
||||||
#endif // NDEBUG
|
#endif // NDEBUG
|
||||||
|
|
||||||
namespace {
|
|
||||||
struct OrderSorter {
|
|
||||||
bool operator()(const std::pair<unsigned, MachineInstr*> &A,
|
|
||||||
const std::pair<unsigned, MachineInstr*> &B) {
|
|
||||||
return A.first < B.first;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ProcessSDDbgValues - Process SDDbgValues associated with this node.
|
/// ProcessSDDbgValues - Process SDDbgValues associated with this node.
|
||||||
static void
|
static void
|
||||||
ProcessSDDbgValues(SDNode *N, SelectionDAG *DAG, InstrEmitter &Emitter,
|
ProcessSDDbgValues(SDNode *N, SelectionDAG *DAG, InstrEmitter &Emitter,
|
||||||
@@ -857,7 +848,7 @@ EmitSchedule(MachineBasicBlock::iterator &InsertPos) {
|
|||||||
|
|
||||||
// Sort the source order instructions and use the order to insert debug
|
// Sort the source order instructions and use the order to insert debug
|
||||||
// values.
|
// values.
|
||||||
std::sort(Orders.begin(), Orders.end(), OrderSorter());
|
std::sort(Orders.begin(), Orders.end(), less_first());
|
||||||
|
|
||||||
SDDbgInfo::DbgIterator DI = DAG->DbgBegin();
|
SDDbgInfo::DbgIterator DI = DAG->DbgBegin();
|
||||||
SDDbgInfo::DbgIterator DE = DAG->DbgEnd();
|
SDDbgInfo::DbgIterator DE = DAG->DbgEnd();
|
||||||
|
|||||||
@@ -431,16 +431,6 @@ static bool rewriteSingleStoreAlloca(AllocaInst *AI, AllocaInfo &Info,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
|
||||||
/// This is a helper predicate used to search by the first element of a pair.
|
|
||||||
struct StoreIndexSearchPredicate {
|
|
||||||
bool operator()(const std::pair<unsigned, StoreInst *> &LHS,
|
|
||||||
const std::pair<unsigned, StoreInst *> &RHS) {
|
|
||||||
return LHS.first < RHS.first;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Many allocas are only used within a single basic block. If this is the
|
/// Many allocas are only used within a single basic block. If this is the
|
||||||
/// case, avoid traversing the CFG and inserting a lot of potentially useless
|
/// case, avoid traversing the CFG and inserting a lot of potentially useless
|
||||||
/// PHI nodes by just performing a single linear pass over the basic block
|
/// PHI nodes by just performing a single linear pass over the basic block
|
||||||
@@ -473,8 +463,7 @@ static void promoteSingleBlockAlloca(AllocaInst *AI, const AllocaInfo &Info,
|
|||||||
|
|
||||||
// Sort the stores by their index, making it efficient to do a lookup with a
|
// Sort the stores by their index, making it efficient to do a lookup with a
|
||||||
// binary search.
|
// binary search.
|
||||||
std::sort(StoresByIndex.begin(), StoresByIndex.end(),
|
std::sort(StoresByIndex.begin(), StoresByIndex.end(), less_first());
|
||||||
StoreIndexSearchPredicate());
|
|
||||||
|
|
||||||
// Walk all of the loads from this alloca, replacing them with the nearest
|
// Walk all of the loads from this alloca, replacing them with the nearest
|
||||||
// store above them, if any.
|
// store above them, if any.
|
||||||
@@ -489,7 +478,7 @@ static void promoteSingleBlockAlloca(AllocaInst *AI, const AllocaInfo &Info,
|
|||||||
StoresByIndexTy::iterator I =
|
StoresByIndexTy::iterator I =
|
||||||
std::lower_bound(StoresByIndex.begin(), StoresByIndex.end(),
|
std::lower_bound(StoresByIndex.begin(), StoresByIndex.end(),
|
||||||
std::make_pair(LoadIdx, static_cast<StoreInst *>(0)),
|
std::make_pair(LoadIdx, static_cast<StoreInst *>(0)),
|
||||||
StoreIndexSearchPredicate());
|
less_first());
|
||||||
|
|
||||||
if (I == StoresByIndex.begin())
|
if (I == StoresByIndex.begin())
|
||||||
// If there is no store before this load, the load takes the undef value.
|
// If there is no store before this load, the load takes the undef value.
|
||||||
@@ -849,16 +838,6 @@ void PromoteMem2Reg::ComputeLiveInBlocks(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
|
||||||
typedef std::pair<DomTreeNode *, unsigned> DomTreeNodePair;
|
|
||||||
|
|
||||||
struct DomTreeNodeCompare {
|
|
||||||
bool operator()(const DomTreeNodePair &LHS, const DomTreeNodePair &RHS) {
|
|
||||||
return LHS.second < RHS.second;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // end anonymous namespace
|
|
||||||
|
|
||||||
/// At this point, we're committed to promoting the alloca using IDF's, and the
|
/// At this point, we're committed to promoting the alloca using IDF's, and the
|
||||||
/// standard SSA construction algorithm. Determine which blocks need phi nodes
|
/// standard SSA construction algorithm. Determine which blocks need phi nodes
|
||||||
/// and see if we can optimize out some work by avoiding insertion of dead phi
|
/// and see if we can optimize out some work by avoiding insertion of dead phi
|
||||||
@@ -876,9 +855,9 @@ void PromoteMem2Reg::DetermineInsertionPoint(AllocaInst *AI, unsigned AllocaNum,
|
|||||||
|
|
||||||
// Use a priority queue keyed on dominator tree level so that inserted nodes
|
// Use a priority queue keyed on dominator tree level so that inserted nodes
|
||||||
// are handled from the bottom of the dominator tree upwards.
|
// are handled from the bottom of the dominator tree upwards.
|
||||||
typedef std::priority_queue<DomTreeNodePair,
|
typedef std::pair<DomTreeNode *, unsigned> DomTreeNodePair;
|
||||||
SmallVector<DomTreeNodePair, 32>,
|
typedef std::priority_queue<DomTreeNodePair, SmallVector<DomTreeNodePair, 32>,
|
||||||
DomTreeNodeCompare> IDFPriorityQueue;
|
less_second> IDFPriorityQueue;
|
||||||
IDFPriorityQueue PQ;
|
IDFPriorityQueue PQ;
|
||||||
|
|
||||||
for (SmallPtrSet<BasicBlock *, 32>::const_iterator I = DefBlocks.begin(),
|
for (SmallPtrSet<BasicBlock *, 32>::const_iterator I = DefBlocks.begin(),
|
||||||
|
|||||||
Reference in New Issue
Block a user