diff --git a/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h b/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h index 3d7ccd55ee042..72cb92b3d70be 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h @@ -27,6 +27,7 @@ #include "llvm/CodeGen/SwiftErrorValueTracking.h" #include "llvm/CodeGen/SwitchLoweringUtils.h" #include "llvm/Support/Allocator.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/CodeGen.h" #include #include @@ -87,19 +88,27 @@ class IRTranslator : public MachineFunctionPass { inline const_vreg_iterator vregs_end() const { return ValToVRegs.end(); } VRegListT *getVRegs(const Value &V) { + if (auto *H = probeHotV(V)) return H; auto It = ValToVRegs.find(&V); - if (It != ValToVRegs.end()) + if (It != ValToVRegs.end()) { + pushHotV(V, It->second); return It->second; - - return insertVRegs(V); + } + auto *P = insertVRegs(V); + pushHotV(V, P); + return P; } OffsetListT *getOffsets(const Value &V) { + if (auto *H = probeHotT(V)) return H; auto It = TypeToOffsets.find(V.getType()); - if (It != TypeToOffsets.end()) + if (It != TypeToOffsets.end()) { + pushHotT(V, It->second); return It->second; - - return insertOffsets(V); + } + auto *P = insertOffsets(V); + pushHotT(V, P); + return P; } const_vreg_iterator findVRegs(const Value &V) const { @@ -113,9 +122,52 @@ class IRTranslator : public MachineFunctionPass { TypeToOffsets.clear(); VRegAlloc.DestroyAll(); OffsetAlloc.DestroyAll(); + // Clear the small hot caches. + for (unsigned i=0;i FrameIndices; + /// Tiny ring buffer cache for frequently accessed FrameIndices. + /// Avoids DenseMap lookup when there are repeated queries for the same allocas. + static constexpr unsigned FIHotN = 8; + struct FIHot { + const AllocaInst *AI = nullptr; + int FI = 0; + }; + FIHot FIHotCache[FIHotN]; + unsigned FIHotHead = 0; + SwiftErrorValueTracking SwiftError; /// \name Methods for translating form LLVM IR to MachineInstr.