TableManager.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===---------------------- TableManager.h ----------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // Fix edge for edge that needs an entry to reference the target symbol
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_EXECUTIONENGINE_JITLINK_TABLEMANAGER_H
  18. #define LLVM_EXECUTIONENGINE_JITLINK_TABLEMANAGER_H
  19. #include "llvm/ExecutionEngine/JITLink/JITLink.h"
  20. #include "llvm/Support/Debug.h"
  21. namespace llvm {
  22. namespace jitlink {
  23. /// A CRTP base for tables that are built on demand, e.g. Global Offset Tables
  24. /// and Procedure Linkage Tables.
  25. /// The getEntyrForTarget function returns the table entry corresponding to the
  26. /// given target, calling down to the implementation class to build an entry if
  27. /// one does not already exist.
  28. template <typename TableManagerImplT> class TableManager {
  29. public:
  30. /// Return the constructed entry
  31. ///
  32. /// Use parameter G to construct the entry for target symbol
  33. Symbol &getEntryForTarget(LinkGraph &G, Symbol &Target) {
  34. assert(Target.hasName() && "Edge cannot point to anonymous target");
  35. auto EntryI = Entries.find(Target.getName());
  36. // Build the entry if it doesn't exist.
  37. if (EntryI == Entries.end()) {
  38. auto &Entry = impl().createEntry(G, Target);
  39. DEBUG_WITH_TYPE("jitlink", {
  40. dbgs() << " Created " << impl().getSectionName() << "entry for "
  41. << Target.getName() << ": " << Entry << "\n";
  42. });
  43. EntryI = Entries.insert(std::make_pair(Target.getName(), &Entry)).first;
  44. }
  45. assert(EntryI != Entries.end() && "Could not get entry symbol");
  46. DEBUG_WITH_TYPE("jitlink", {
  47. dbgs() << " Using " << impl().getSectionName() << " entry "
  48. << *EntryI->second << "\n";
  49. });
  50. return *EntryI->second;
  51. }
  52. private:
  53. TableManagerImplT &impl() { return static_cast<TableManagerImplT &>(*this); }
  54. DenseMap<StringRef, Symbol *> Entries;
  55. };
  56. } // namespace jitlink
  57. } // namespace llvm
  58. #endif
  59. #ifdef __GNUC__
  60. #pragma GCC diagnostic pop
  61. #endif