LLVM  10.0.0svn
BasicGOTAndStubsBuilder.h
Go to the documentation of this file.
1 //===--- BasicGOTAndStubsBuilder.h - Generic GOT/Stub creation --*- C++ -*-===//
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 // A base for simple GOT and stub creation.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_EXECUTIONENGINE_JITLINK_BASICGOTANDSTUBSBUILDER_H
14 #define LLVM_LIB_EXECUTIONENGINE_JITLINK_BASICGOTANDSTUBSBUILDER_H
15 
17 
18 namespace llvm {
19 namespace jitlink {
20 
21 template <typename BuilderImpl> class BasicGOTAndStubsBuilder {
22 public:
24 
25  void run() {
26  // We're going to be adding new atoms, but we don't want to iterate over
27  // the newly added ones, so just copy the existing atoms out.
28  std::vector<DefinedAtom *> DAs(G.defined_atoms().begin(),
29  G.defined_atoms().end());
30 
31  for (auto *DA : DAs)
32  for (auto &E : DA->edges())
33  if (impl().isGOTEdge(E))
34  impl().fixGOTEdge(E, getGOTEntryAtom(E.getTarget()));
35  else if (impl().isExternalBranchEdge(E))
36  impl().fixExternalBranchEdge(E, getStubAtom(E.getTarget()));
37  }
38 
39 protected:
41  assert(Target.hasName() && "GOT edge cannot point to anonymous target");
42 
43  auto GOTEntryI = GOTEntries.find(Target.getName());
44 
45  // Build the entry if it doesn't exist.
46  if (GOTEntryI == GOTEntries.end()) {
47  auto &GOTEntry = impl().createGOTEntry(Target);
48  GOTEntryI =
49  GOTEntries.insert(std::make_pair(Target.getName(), &GOTEntry)).first;
50  }
51 
52  assert(GOTEntryI != GOTEntries.end() && "Could not get GOT entry atom");
53  return *GOTEntryI->second;
54  }
55 
57  assert(Target.hasName() &&
58  "External branch edge can not point to an anonymous target");
59  auto StubI = Stubs.find(Target.getName());
60 
61  if (StubI == Stubs.end()) {
62  auto &StubAtom = impl().createStub(Target);
63  StubI = Stubs.insert(std::make_pair(Target.getName(), &StubAtom)).first;
64  }
65 
66  assert(StubI != Stubs.end() && "Count not get stub atom");
67  return *StubI->second;
68  }
69 
71 
72 private:
73  BuilderImpl &impl() { return static_cast<BuilderImpl &>(*this); }
74 
77 };
78 
79 } // end namespace jitlink
80 } // end namespace llvm
81 
82 #endif // LLVM_LIB_EXECUTIONENGINE_JITLINK_BASICGOTANDSTUBSBUILDER_H
This class represents lattice values for constants.
Definition: AllocatorList.h:23
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Target - Wrapper for Target specific information.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())