xref: /llvm-project/llvm/lib/CodeGen/MachineModuleInfoImpls.cpp (revision 149178d92bf4d405e71fabb4d93204292f89acc2)
1 //===- llvm/CodeGen/MachineModuleInfoImpls.cpp ----------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements object-file format specific implementations of
11 // MachineModuleInfoImpl.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "llvm/CodeGen/MachineModuleInfoImpls.h"
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/MC/MCSymbol.h"
18 #include <cstdlib>
19 #include <utility>
20 
21 using namespace llvm;
22 
23 //===----------------------------------------------------------------------===//
24 // MachineModuleInfoMachO
25 //===----------------------------------------------------------------------===//
26 
27 // Out of line virtual method.
28 void MachineModuleInfoMachO::anchor() {}
29 void MachineModuleInfoELF::anchor() {}
30 
31 static int SortSymbolPair(const void *LHS, const void *RHS) {
32   using PairTy = std::pair<MCSymbol *, MachineModuleInfoImpl::StubValueTy>;
33 
34   const MCSymbol *LHSS = ((const PairTy *)LHS)->first;
35   const MCSymbol *RHSS = ((const PairTy *)RHS)->first;
36   return LHSS->getName().compare(RHSS->getName());
37 }
38 
39 MachineModuleInfoImpl::SymbolListTy MachineModuleInfoImpl::getSortedStubs(
40     DenseMap<MCSymbol *, MachineModuleInfoImpl::StubValueTy> &Map) {
41   MachineModuleInfoImpl::SymbolListTy List(Map.begin(), Map.end());
42 
43   if (!List.empty())
44     qsort(&List[0], List.size(), sizeof(List[0]), SortSymbolPair);
45 
46   Map.clear();
47   return List;
48 }
49