From: Lang Hames Date: Tue, 19 Oct 2021 01:11:48 +0000 (-0700) Subject: Simplify the TableManager class and move it into a public header. X-Git-Tag: upstream/15.0.7~28274 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bc03a9c066bf9990a1d595cb80ad51ae40fb759a;p=platform%2Fupstream%2Fllvm.git 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. --- 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 e03948b..315a356 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 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 @@ public: } private: - void fixTarget(LinkGraph &G, Edge &E) { - E.setTarget(getEntryForTarget(G, E.getTarget())); - } - TableManagerImplT &impl() { return static_cast(*this); } DenseMap Entries; }; diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp index 191588e..7153a3f 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 @@ public: // 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 @@ public: 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 @@ public: << formatv("{0:x}", E.getOffset()) << ")\n"; }); E.setKind(KindToSet); + E.setTarget(getEntryForTarget(G, E.getTarget())); return true; } @@ -111,7 +114,7 @@ public: 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 @@ public: // 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 @@ public: 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 @@ public: << formatv("{0:x}", E.getOffset()) << ")\n"; }); E.setKind(x86_64::Delta32); + E.setTarget(getEntryForTarget(G, E.getTarget())); return true; } return false;