<p dir="ltr"><br>
On Aug 24, 2013 5:59 AM, "Benjamin Kramer" <<a href="mailto:benny.kra@googlemail.com">benny.kra@googlemail.com</a>> wrote:<br>
><br>
> Author: d0k<br>
> Date: Sat Aug 24 07:54:27 2013<br>
> New Revision: 189169<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=189169&view=rev">http://llvm.org/viewvc/llvm-project?rev=189169&view=rev</a><br>
> Log:<br>
> Add a function object to compare the first or second component of a std::pair.</p>
<p dir="ltr">Handy. Is (or should) this modeled after any standard library feature in c++11 (or beyond)?</p>
<p dir="ltr">><br>
> Replace instances of this scattered around the code base.<br>
><br>
> Modified:<br>
> llvm/trunk/include/llvm/ADT/STLExtras.h<br>
> llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp<br>
> llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp<br>
> llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp<br>
> llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp<br>
><br>
> Modified: llvm/trunk/include/llvm/ADT/STLExtras.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/STLExtras.h?rev=189169&r1=189168&r2=189169&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/STLExtras.h?rev=189169&r1=189168&r2=189169&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/ADT/STLExtras.h (original)<br>
> +++ llvm/trunk/include/llvm/ADT/STLExtras.h Sat Aug 24 07:54:27 2013<br>
> @@ -217,6 +217,22 @@ inline tier<T1, T2> tie(T1& f, T2& s) {<br>
> return tier<T1, T2>(f, s);<br>
> }<br>
><br>
> +/// \brief Function object to check whether the first component of a std::pair<br>
> +/// compares less than the first component of another std::pair.<br>
> +struct less_first {<br>
> + template <typename T> bool operator()(const T &lhs, const T &rhs) const {<br>
> + return lhs.first < rhs.first;<br>
> + }<br>
> +};<br>
> +<br>
> +/// \brief Function object to check whether the second component of a std::pair<br>
> +/// compares less than the second component of another std::pair.<br>
> +struct less_second {<br>
> + template <typename T> bool operator()(const T &lhs, const T &rhs) const {<br>
> + return lhs.second < rhs.second;<br>
> + }<br>
> +};<br>
> +<br>
> //===----------------------------------------------------------------------===//<br>
> // Extra additions for arrays<br>
> //===----------------------------------------------------------------------===//<br>
><br>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=189169&r1=189168&r2=189169&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=189169&r1=189168&r2=189169&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)<br>
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Sat Aug 24 07:54:27 2013<br>
> @@ -1287,12 +1287,6 @@ void AsmPrinter::EmitLLVMUsedList(const<br>
> }<br>
> }<br>
><br>
> -typedef std::pair<unsigned, Constant*> Structor;<br>
> -<br>
> -static bool priority_order(const Structor& lhs, const Structor& rhs) {<br>
> - return lhs.first < rhs.first;<br>
> -}<br>
> -<br>
> /// EmitXXStructorList - Emit the ctor or dtor list taking into account the init<br>
> /// priority.<br>
> void AsmPrinter::EmitXXStructorList(const Constant *List, bool isCtor) {<br>
> @@ -1309,6 +1303,7 @@ void AsmPrinter::EmitXXStructorList(cons<br>
> !isa<PointerType>(ETy->getTypeAtIndex(1U))) return; // Not (int, ptr).<br>
><br>
> // Gather the structors in a form that's convenient for sorting by priority.<br>
> + typedef std::pair<unsigned, Constant *> Structor;<br>
> SmallVector<Structor, 8> Structors;<br>
> for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {<br>
> ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i));<br>
> @@ -1324,7 +1319,7 @@ void AsmPrinter::EmitXXStructorList(cons<br>
> // Emit the function pointers in the target-specific order<br>
> const DataLayout *TD = TM.getDataLayout();<br>
> unsigned Align = Log2_32(TD->getPointerPrefAlignment());<br>
> - std::stable_sort(Structors.begin(), Structors.end(), priority_order);<br>
> + std::stable_sort(Structors.begin(), Structors.end(), less_first());<br>
> for (unsigned i = 0, e = Structors.size(); i != e; ++i) {<br>
> const MCSection *OutputSection =<br>
> (isCtor ?<br>
><br>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=189169&r1=189168&r2=189169&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=189169&r1=189168&r2=189169&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)<br>
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Sat Aug 24 07:54:27 2013<br>
> @@ -108,16 +108,8 @@ DwarfPubNames("generate-dwarf-pubnames",<br>
> clEnumVal(Disable, "Disabled"), clEnumValEnd),<br>
> cl::init(Default));<br>
><br>
> -namespace {<br>
> - const char *const DWARFGroupName = "DWARF Emission";<br>
> - const char *const DbgTimerName = "DWARF Debug Writer";<br>
> -<br>
> - struct CompareFirst {<br>
> - template <typename T> bool operator()(const T &lhs, const T &rhs) const {<br>
> - return lhs.first < rhs.first;<br>
> - }<br>
> - };<br>
> -} // end anonymous namespace<br>
> +static const char *const DWARFGroupName = "DWARF Emission";<br>
> +static const char *const DbgTimerName = "DWARF Debug Writer";<br>
><br>
> //===----------------------------------------------------------------------===//<br>
><br>
> @@ -625,7 +617,7 @@ DIE *DwarfDebug::constructScopeDIE(Compi<br>
> ImportedEntityMap::const_iterator> Range = std::equal_range(<br>
> ScopesWithImportedEntities.begin(), ScopesWithImportedEntities.end(),<br>
> std::pair<const MDNode *, const MDNode *>(DS, (const MDNode*)0),<br>
> - CompareFirst());<br>
> + less_first());<br>
> if (Children.empty() && Range.first == Range.second)<br>
> return NULL;<br>
> ScopeDIE = constructLexicalScopeDIE(TheCU, Scope);<br>
> @@ -879,7 +871,7 @@ void DwarfDebug::beginModule() {<br>
> DIImportedEntity(ImportedEntities.getElement(i)).getContext(),<br>
> ImportedEntities.getElement(i)));<br>
> std::sort(ScopesWithImportedEntities.begin(),<br>
> - ScopesWithImportedEntities.end(), CompareFirst());<br>
> + ScopesWithImportedEntities.end(), less_first());<br>
> DIArray GVs = CUNode.getGlobalVariables();<br>
> for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i)<br>
> CU->createGlobalVariableDIE(GVs.getElement(i));<br>
><br>
> Modified: llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp?rev=189169&r1=189168&r2=189169&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp?rev=189169&r1=189168&r2=189169&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp (original)<br>
> +++ llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp Sat Aug 24 07:54:27 2013<br>
> @@ -690,15 +690,6 @@ void ScheduleDAGSDNodes::VerifyScheduled<br>
> }<br>
> #endif // NDEBUG<br>
><br>
> -namespace {<br>
> - struct OrderSorter {<br>
> - bool operator()(const std::pair<unsigned, MachineInstr*> &A,<br>
> - const std::pair<unsigned, MachineInstr*> &B) {<br>
> - return A.first < B.first;<br>
> - }<br>
> - };<br>
> -}<br>
> -<br>
> /// ProcessSDDbgValues - Process SDDbgValues associated with this node.<br>
> static void<br>
> ProcessSDDbgValues(SDNode *N, SelectionDAG *DAG, InstrEmitter &Emitter,<br>
> @@ -857,7 +848,7 @@ EmitSchedule(MachineBasicBlock::iterator<br>
><br>
> // Sort the source order instructions and use the order to insert debug<br>
> // values.<br>
> - std::sort(Orders.begin(), Orders.end(), OrderSorter());<br>
> + std::sort(Orders.begin(), Orders.end(), less_first());<br>
><br>
> SDDbgInfo::DbgIterator DI = DAG->DbgBegin();<br>
> SDDbgInfo::DbgIterator DE = DAG->DbgEnd();<br>
><br>
> Modified: llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp?rev=189169&r1=189168&r2=189169&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp?rev=189169&r1=189168&r2=189169&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp (original)<br>
> +++ llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp Sat Aug 24 07:54:27 2013<br>
> @@ -431,16 +431,6 @@ static bool rewriteSingleStoreAlloca(All<br>
> return true;<br>
> }<br>
><br>
> -namespace {<br>
> -/// This is a helper predicate used to search by the first element of a pair.<br>
> -struct StoreIndexSearchPredicate {<br>
> - bool operator()(const std::pair<unsigned, StoreInst *> &LHS,<br>
> - const std::pair<unsigned, StoreInst *> &RHS) {<br>
> - return LHS.first < RHS.first;<br>
> - }<br>
> -};<br>
> -}<br>
> -<br>
> /// Many allocas are only used within a single basic block. If this is the<br>
> /// case, avoid traversing the CFG and inserting a lot of potentially useless<br>
> /// PHI nodes by just performing a single linear pass over the basic block<br>
> @@ -473,8 +463,7 @@ static void promoteSingleBlockAlloca(All<br>
><br>
> // Sort the stores by their index, making it efficient to do a lookup with a<br>
> // binary search.<br>
> - std::sort(StoresByIndex.begin(), StoresByIndex.end(),<br>
> - StoreIndexSearchPredicate());<br>
> + std::sort(StoresByIndex.begin(), StoresByIndex.end(), less_first());<br>
><br>
> // Walk all of the loads from this alloca, replacing them with the nearest<br>
> // store above them, if any.<br>
> @@ -489,7 +478,7 @@ static void promoteSingleBlockAlloca(All<br>
> StoresByIndexTy::iterator I =<br>
> std::lower_bound(StoresByIndex.begin(), StoresByIndex.end(),<br>
> std::make_pair(LoadIdx, static_cast<StoreInst *>(0)),<br>
> - StoreIndexSearchPredicate());<br>
> + less_first());<br>
><br>
> if (I == StoresByIndex.begin())<br>
> // If there is no store before this load, the load takes the undef value.<br>
> @@ -849,16 +838,6 @@ void PromoteMem2Reg::ComputeLiveInBlocks<br>
> }<br>
> }<br>
><br>
> -namespace {<br>
> -typedef std::pair<DomTreeNode *, unsigned> DomTreeNodePair;<br>
> -<br>
> -struct DomTreeNodeCompare {<br>
> - bool operator()(const DomTreeNodePair &LHS, const DomTreeNodePair &RHS) {<br>
> - return LHS.second < RHS.second;<br>
> - }<br>
> -};<br>
> -} // end anonymous namespace<br>
> -<br>
> /// At this point, we're committed to promoting the alloca using IDF's, and the<br>
> /// standard SSA construction algorithm. Determine which blocks need phi nodes<br>
> /// and see if we can optimize out some work by avoiding insertion of dead phi<br>
> @@ -876,9 +855,9 @@ void PromoteMem2Reg::DetermineInsertionP<br>
><br>
> // Use a priority queue keyed on dominator tree level so that inserted nodes<br>
> // are handled from the bottom of the dominator tree upwards.<br>
> - typedef std::priority_queue<DomTreeNodePair,<br>
> - SmallVector<DomTreeNodePair, 32>,<br>
> - DomTreeNodeCompare> IDFPriorityQueue;<br>
> + typedef std::pair<DomTreeNode *, unsigned> DomTreeNodePair;<br>
> + typedef std::priority_queue<DomTreeNodePair, SmallVector<DomTreeNodePair, 32>,<br>
> + less_second> IDFPriorityQueue;<br>
> IDFPriorityQueue PQ;<br>
><br>
> for (SmallPtrSet<BasicBlock *, 32>::const_iterator I = DefBlocks.begin(),<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</p>