[llvm] bc03a9c - Simplify the TableManager class and move it into a public header.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 18 18:28:24 PDT 2021


Author: Lang Hames
Date: 2021-10-18T18:20:33-07:00
New Revision: bc03a9c066bf9990a1d595cb80ad51ae40fb759a

URL: https://github.com/llvm/llvm-project/commit/bc03a9c066bf9990a1d595cb80ad51ae40fb759a
DIFF: https://github.com/llvm/llvm-project/commit/bc03a9c066bf9990a1d595cb80ad51ae40fb759a.diff

LOG: Simplify the TableManager class and move it into a public header.

Moves visitEdge into the TableManager derivatives, replacing the fixEdgeKind
methods in those classes. The visitEdge method takes on responsibility for
updating the edge target, as well as its kind.

Added: 
    llvm/include/llvm/ExecutionEngine/JITLink/TableManager.h

Modified: 
    llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp

Removed: 
    llvm/lib/ExecutionEngine/JITLink/TableManager.h


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/JITLink/TableManager.h b/llvm/include/llvm/ExecutionEngine/JITLink/TableManager.h
similarity index 82%
rename from llvm/lib/ExecutionEngine/JITLink/TableManager.h
rename to llvm/include/llvm/ExecutionEngine/JITLink/TableManager.h
index e03948b49b219..315a35682acba 100644
--- a/llvm/lib/ExecutionEngine/JITLink/TableManager.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/TableManager.h
@@ -21,19 +21,13 @@
 namespace llvm {
 namespace jitlink {
 
-/// Table like section manager
+/// A CRTP base for tables that are built on demand, e.g. Global Offset Tables
+/// and Procedure Linkage Tables.
+/// The getEntyrForTarget function returns the table entry corresponding to the
+/// given target, calling down to the implementation class to build an entry if
+/// one does not already exist.
 template <typename TableManagerImplT> class TableManager {
 public:
-  /// Visit edge, return true if the edge was dealt with, otherwise return
-  /// false(let other managers to visit).
-  bool visitEdge(LinkGraph &G, Block *B, Edge &E) {
-    if (impl().fixEdgeKind(G, B, E)) {
-      fixTarget(G, E);
-      return true;
-    }
-    return false;
-  }
-
   /// Return the constructed entry
   ///
   /// Use parameter G to construct the entry for target symbol
@@ -61,10 +55,6 @@ template <typename TableManagerImplT> class TableManager {
   }
 
 private:
-  void fixTarget(LinkGraph &G, Edge &E) {
-    E.setTarget(getEntryForTarget(G, E.getTarget()));
-  }
-
   TableManagerImplT &impl() { return static_cast<TableManagerImplT &>(*this); }
   DenseMap<StringRef, Symbol *> Entries;
 };

diff  --git a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
index 191588e3f2b4d..7153a3feccf4c 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
@@ -12,6 +12,7 @@
 
 #include "llvm/ExecutionEngine/JITLink/ELF_x86_64.h"
 #include "llvm/ExecutionEngine/JITLink/JITLink.h"
+#include "llvm/ExecutionEngine/JITLink/TableManager.h"
 #include "llvm/ExecutionEngine/JITLink/x86_64.h"
 #include "llvm/Object/ELFObjectFile.h"
 #include "llvm/Support/Endian.h"
@@ -21,7 +22,6 @@
 #include "ELFLinkGraphBuilder.h"
 #include "JITLinkGeneric.h"
 #include "PerGraphGOTAndPLTStubsBuilder.h"
-#include "TableManager.h"
 
 #define DEBUG_TYPE "jitlink"
 
@@ -43,8 +43,8 @@ class GOTTableManager_ELF_x86_64
   // Nice name for table
   StringRef getTableName() { return "GOT"; }
 
-  bool fixEdgeKind(LinkGraph &G, Block *B, Edge &E) {
-    Edge::Kind KindToSet = E.getKind();
+  bool visitEdge(LinkGraph &G, Block *B, Edge &E) {
+    Edge::Kind KindToSet = Edge::Invalid;
     switch (E.getKind()) {
     case x86_64::Delta64FromGOT: {
       // we need to make sure that the GOT section exists, but don't otherwise
@@ -70,6 +70,8 @@ class GOTTableManager_ELF_x86_64
     default:
       return false;
     }
+    assert(KindToSet != Edge::Invalid &&
+           "Fell through switch, but no new kind to set");
     LLVM_DEBUG({
       dbgs() << "  Fixing " << G.getEdgeKindName(E.getKind()) << " edge at "
              << formatv("{0:x}", B->getFixupAddress(E)) << " ("
@@ -77,6 +79,7 @@ class GOTTableManager_ELF_x86_64
              << formatv("{0:x}", E.getOffset()) << ")\n";
     });
     E.setKind(KindToSet);
+    E.setTarget(getEntryForTarget(G, E.getTarget()));
     return true;
   }
 
@@ -111,7 +114,7 @@ class PLTTableManager_ELF_x86_64
   StringRef getTableName() { return "PLT"; }
 
   static const uint8_t StubContent[6];
-  bool fixEdgeKind(LinkGraph &G, Block *B, Edge &E) {
+  bool visitEdge(LinkGraph &G, Block *B, Edge &E) {
     if (E.getKind() == x86_64::BranchPCRel32 && !E.getTarget().isDefined()) {
       LLVM_DEBUG({
         dbgs() << "  Fixing " << G.getEdgeKindName(E.getKind()) << " edge at "
@@ -122,6 +125,7 @@ class PLTTableManager_ELF_x86_64
       // Set the edge kind to Branch32ToPtrJumpStubBypassable to enable it to
       // be optimized when the target is in-range.
       E.setKind(x86_64::BranchPCRel32ToPtrJumpStubBypassable);
+      E.setTarget(getEntryForTarget(G, E.getTarget()));
       return true;
     }
     return false;
@@ -161,7 +165,7 @@ class TLSInfoTableManager_ELF_x86_64
 
   StringRef getTableName() { return "TLSInfo"; }
 
-  bool fixEdgeKind(LinkGraph &G, Block *B, Edge &E) {
+  bool visitEdge(LinkGraph &G, Block *B, Edge &E) {
     if (E.getKind() == x86_64::RequestTLSDescInGOTAndTransformToDelta32) {
       LLVM_DEBUG({
         dbgs() << "  Fixing " << G.getEdgeKindName(E.getKind()) << " edge at "
@@ -170,6 +174,7 @@ class TLSInfoTableManager_ELF_x86_64
                << formatv("{0:x}", E.getOffset()) << ")\n";
       });
       E.setKind(x86_64::Delta32);
+      E.setTarget(getEntryForTarget(G, E.getTarget()));
       return true;
     }
     return false;


        


More information about the llvm-commits mailing list