Skip to content

Commit 8a86e6a

Browse files
[MemProf] Constify a couple of methods used during cloning (#124994)
This also helps ensure we don't inadvartently create map entries by forcing use of at() instead of operator[].
1 parent 5921295 commit 8a86e6a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -677,18 +677,18 @@ class CallsiteContextGraph {
677677

678678
/// Computes the alloc type corresponding to the given context ids, by
679679
/// unioning their recorded alloc types.
680-
uint8_t computeAllocType(DenseSet<uint32_t> &ContextIds);
680+
uint8_t computeAllocType(DenseSet<uint32_t> &ContextIds) const;
681681

682682
/// Returns the allocation type of the intersection of the contexts of two
683683
/// nodes (based on their provided context id sets), optimized for the case
684684
/// when Node1Ids is smaller than Node2Ids.
685685
uint8_t intersectAllocTypesImpl(const DenseSet<uint32_t> &Node1Ids,
686-
const DenseSet<uint32_t> &Node2Ids);
686+
const DenseSet<uint32_t> &Node2Ids) const;
687687

688688
/// Returns the allocation type of the intersection of the contexts of two
689689
/// nodes (based on their provided context id sets).
690690
uint8_t intersectAllocTypes(const DenseSet<uint32_t> &Node1Ids,
691-
const DenseSet<uint32_t> &Node2Ids);
691+
const DenseSet<uint32_t> &Node2Ids) const;
692692

693693
/// Create a clone of Edge's callee and move Edge to that new callee node,
694694
/// performing the necessary context id and allocation type updates.
@@ -1152,12 +1152,12 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::ContextNode::
11521152

11531153
template <typename DerivedCCG, typename FuncTy, typename CallTy>
11541154
uint8_t CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::computeAllocType(
1155-
DenseSet<uint32_t> &ContextIds) {
1155+
DenseSet<uint32_t> &ContextIds) const {
11561156
uint8_t BothTypes =
11571157
(uint8_t)AllocationType::Cold | (uint8_t)AllocationType::NotCold;
11581158
uint8_t AllocType = (uint8_t)AllocationType::None;
11591159
for (auto Id : ContextIds) {
1160-
AllocType |= (uint8_t)ContextIdToAllocationType[Id];
1160+
AllocType |= (uint8_t)ContextIdToAllocationType.at(Id);
11611161
// Bail early if alloc type reached both, no further refinement.
11621162
if (AllocType == BothTypes)
11631163
return AllocType;
@@ -1168,14 +1168,15 @@ uint8_t CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::computeAllocType(
11681168
template <typename DerivedCCG, typename FuncTy, typename CallTy>
11691169
uint8_t
11701170
CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::intersectAllocTypesImpl(
1171-
const DenseSet<uint32_t> &Node1Ids, const DenseSet<uint32_t> &Node2Ids) {
1171+
const DenseSet<uint32_t> &Node1Ids,
1172+
const DenseSet<uint32_t> &Node2Ids) const {
11721173
uint8_t BothTypes =
11731174
(uint8_t)AllocationType::Cold | (uint8_t)AllocationType::NotCold;
11741175
uint8_t AllocType = (uint8_t)AllocationType::None;
11751176
for (auto Id : Node1Ids) {
11761177
if (!Node2Ids.count(Id))
11771178
continue;
1178-
AllocType |= (uint8_t)ContextIdToAllocationType[Id];
1179+
AllocType |= (uint8_t)ContextIdToAllocationType.at(Id);
11791180
// Bail early if alloc type reached both, no further refinement.
11801181
if (AllocType == BothTypes)
11811182
return AllocType;
@@ -1185,7 +1186,8 @@ CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::intersectAllocTypesImpl(
11851186

11861187
template <typename DerivedCCG, typename FuncTy, typename CallTy>
11871188
uint8_t CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::intersectAllocTypes(
1188-
const DenseSet<uint32_t> &Node1Ids, const DenseSet<uint32_t> &Node2Ids) {
1189+
const DenseSet<uint32_t> &Node1Ids,
1190+
const DenseSet<uint32_t> &Node2Ids) const {
11891191
if (Node1Ids.size() < Node2Ids.size())
11901192
return intersectAllocTypesImpl(Node1Ids, Node2Ids);
11911193
else

0 commit comments

Comments
 (0)