From 1908755e8e196eb8a873a6ed2c7268e4ecd65d10 Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Wed, 29 Jan 2025 13:54:40 -0800 Subject: [PATCH] [MemProf] Constify a couple of methods used during cloning This also helps ensure we don't inadvartently create map entries by forcing use of at() instead of operator[]. --- .../IPO/MemProfContextDisambiguation.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp index 03e2e7089202d..d83beae4d6433 100644 --- a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp +++ b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp @@ -677,18 +677,18 @@ class CallsiteContextGraph { /// Computes the alloc type corresponding to the given context ids, by /// unioning their recorded alloc types. - uint8_t computeAllocType(DenseSet &ContextIds); + uint8_t computeAllocType(DenseSet &ContextIds) const; /// Returns the allocation type of the intersection of the contexts of two /// nodes (based on their provided context id sets), optimized for the case /// when Node1Ids is smaller than Node2Ids. uint8_t intersectAllocTypesImpl(const DenseSet &Node1Ids, - const DenseSet &Node2Ids); + const DenseSet &Node2Ids) const; /// Returns the allocation type of the intersection of the contexts of two /// nodes (based on their provided context id sets). uint8_t intersectAllocTypes(const DenseSet &Node1Ids, - const DenseSet &Node2Ids); + const DenseSet &Node2Ids) const; /// Create a clone of Edge's callee and move Edge to that new callee node, /// performing the necessary context id and allocation type updates. @@ -1152,12 +1152,12 @@ void CallsiteContextGraph::ContextNode:: template uint8_t CallsiteContextGraph::computeAllocType( - DenseSet &ContextIds) { + DenseSet &ContextIds) const { uint8_t BothTypes = (uint8_t)AllocationType::Cold | (uint8_t)AllocationType::NotCold; uint8_t AllocType = (uint8_t)AllocationType::None; for (auto Id : ContextIds) { - AllocType |= (uint8_t)ContextIdToAllocationType[Id]; + AllocType |= (uint8_t)ContextIdToAllocationType.at(Id); // Bail early if alloc type reached both, no further refinement. if (AllocType == BothTypes) return AllocType; @@ -1168,14 +1168,15 @@ uint8_t CallsiteContextGraph::computeAllocType( template uint8_t CallsiteContextGraph::intersectAllocTypesImpl( - const DenseSet &Node1Ids, const DenseSet &Node2Ids) { + const DenseSet &Node1Ids, + const DenseSet &Node2Ids) const { uint8_t BothTypes = (uint8_t)AllocationType::Cold | (uint8_t)AllocationType::NotCold; uint8_t AllocType = (uint8_t)AllocationType::None; for (auto Id : Node1Ids) { if (!Node2Ids.count(Id)) continue; - AllocType |= (uint8_t)ContextIdToAllocationType[Id]; + AllocType |= (uint8_t)ContextIdToAllocationType.at(Id); // Bail early if alloc type reached both, no further refinement. if (AllocType == BothTypes) return AllocType; @@ -1185,7 +1186,8 @@ CallsiteContextGraph::intersectAllocTypesImpl( template uint8_t CallsiteContextGraph::intersectAllocTypes( - const DenseSet &Node1Ids, const DenseSet &Node2Ids) { + const DenseSet &Node1Ids, + const DenseSet &Node2Ids) const { if (Node1Ids.size() < Node2Ids.size()) return intersectAllocTypesImpl(Node1Ids, Node2Ids); else