Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:50

0001 //===---------------------- TableManager.h ----------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // Fix edge for edge that needs an entry to reference the target symbol
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_EXECUTIONENGINE_JITLINK_TABLEMANAGER_H
0014 #define LLVM_EXECUTIONENGINE_JITLINK_TABLEMANAGER_H
0015 
0016 #include "llvm/ExecutionEngine/JITLink/JITLink.h"
0017 #include "llvm/Support/Debug.h"
0018 
0019 namespace llvm {
0020 namespace jitlink {
0021 
0022 /// A CRTP base for tables that are built on demand, e.g. Global Offset Tables
0023 /// and Procedure Linkage Tables.
0024 /// The getEntyrForTarget function returns the table entry corresponding to the
0025 /// given target, calling down to the implementation class to build an entry if
0026 /// one does not already exist.
0027 template <typename TableManagerImplT> class TableManager {
0028 public:
0029   /// Return the constructed entry
0030   ///
0031   /// Use parameter G to construct the entry for target symbol
0032   Symbol &getEntryForTarget(LinkGraph &G, Symbol &Target) {
0033     assert(Target.hasName() && "Edge cannot point to anonymous target");
0034 
0035     auto EntryI = Entries.find(Target.getName());
0036 
0037     // Build the entry if it doesn't exist.
0038     if (EntryI == Entries.end()) {
0039       auto &Entry = impl().createEntry(G, Target);
0040       DEBUG_WITH_TYPE("jitlink", {
0041         dbgs() << "    Created " << impl().getSectionName() << " entry for "
0042                << Target.getName() << ": " << Entry << "\n";
0043       });
0044       EntryI = Entries.insert(std::make_pair(Target.getName(), &Entry)).first;
0045     }
0046 
0047     assert(EntryI != Entries.end() && "Could not get entry symbol");
0048     DEBUG_WITH_TYPE("jitlink", {
0049       dbgs() << "    Using " << impl().getSectionName() << " entry "
0050              << *EntryI->second << "\n";
0051     });
0052     return *EntryI->second;
0053   }
0054 
0055   /// Register a pre-existing entry.
0056   ///
0057   /// Objects may include pre-existing table entries (e.g. for GOTs).
0058   /// This method can be used to register those entries so that they will not
0059   /// be duplicated by createEntry  the first time that getEntryForTarget is
0060   /// called.
0061   bool registerPreExistingEntry(Symbol &Target, Symbol &Entry) {
0062     assert(Target.hasName() && "Edge cannot point to anonymous target");
0063     auto Res = Entries.insert({
0064         Target.getName(),
0065         &Entry,
0066     });
0067     return Res.second;
0068   }
0069 
0070 private:
0071   TableManagerImplT &impl() { return static_cast<TableManagerImplT &>(*this); }
0072   DenseMap<orc::SymbolStringPtr, Symbol *> Entries;
0073 };
0074 
0075 } // namespace jitlink
0076 } // namespace llvm
0077 
0078 #endif