xref: /llvm-project/llvm/lib/CodeGen/MachineModuleInfoImpls.cpp (revision b5cc19e572855136eb4080208a9bd5ecef785aa3)
1 //===- llvm/CodeGen/MachineModuleInfoImpls.cpp ----------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements object-file format specific implementations of
10 // MachineModuleInfoImpl.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/CodeGen/MachineModuleInfoImpls.h"
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/MC/MCSymbol.h"
18 
19 using namespace llvm;
20 
21 //===----------------------------------------------------------------------===//
22 // MachineModuleInfoMachO
23 //===----------------------------------------------------------------------===//
24 
25 // Out of line virtual method.
26 void MachineModuleInfoMachO::anchor() {}
27 void MachineModuleInfoELF::anchor() {}
28 void MachineModuleInfoCOFF::anchor() {}
29 void MachineModuleInfoWasm::anchor() {}
30 
31 using PairTy = std::pair<MCSymbol *, MachineModuleInfoImpl::StubValueTy>;
32 static int SortSymbolPair(const PairTy *LHS, const PairTy *RHS) {
33   return LHS->first->getName().compare(RHS->first->getName());
34 }
35 
36 MachineModuleInfoImpl::SymbolListTy MachineModuleInfoImpl::getSortedStubs(
37     DenseMap<MCSymbol *, MachineModuleInfoImpl::StubValueTy> &Map) {
38   MachineModuleInfoImpl::SymbolListTy List(Map.begin(), Map.end());
39 
40   array_pod_sort(List.begin(), List.end(), SortSymbolPair);
41 
42   Map.clear();
43   return List;
44 }
45 
46 template <typename MachineModuleInfoTarget>
47 static typename MachineModuleInfoTarget::AuthStubListTy getAuthGVStubListHelper(
48     DenseMap<MCSymbol *, typename MachineModuleInfoTarget::AuthStubInfo>
49         &AuthPtrStubs) {
50   typename MachineModuleInfoTarget::AuthStubListTy List(AuthPtrStubs.begin(),
51                                                         AuthPtrStubs.end());
52 
53   if (!List.empty())
54     llvm::sort(List.begin(), List.end(),
55                [](const typename MachineModuleInfoTarget::AuthStubPairTy &LHS,
56                   const typename MachineModuleInfoTarget::AuthStubPairTy &RHS) {
57                  return LHS.first->getName() < RHS.first->getName();
58                });
59 
60   AuthPtrStubs.clear();
61   return List;
62 }
63 
64 MachineModuleInfoELF::AuthStubListTy MachineModuleInfoELF::getAuthGVStubList() {
65   return getAuthGVStubListHelper<MachineModuleInfoELF>(AuthPtrStubs);
66 }
67