Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / lib / memprof / memprof_mibmap.cpp
blob32f0796c8f241a9778b7bc1d12ad1514491c62f7
1 //===-- memprof_mibmap.cpp -----------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is a part of MemProfiler, a memory profiler.
11 //===----------------------------------------------------------------------===//
13 #include "memprof_mibmap.h"
14 #include "profile/MemProfData.inc"
15 #include "sanitizer_common/sanitizer_allocator_internal.h"
16 #include "sanitizer_common/sanitizer_mutex.h"
18 namespace __memprof {
19 using ::llvm::memprof::MemInfoBlock;
21 void InsertOrMerge(const uptr Id, const MemInfoBlock &Block, MIBMapTy &Map) {
22 MIBMapTy::Handle h(&Map, static_cast<uptr>(Id), /*remove=*/false,
23 /*create=*/true);
24 if (h.created()) {
25 LockedMemInfoBlock *lmib =
26 (LockedMemInfoBlock *)InternalAlloc(sizeof(LockedMemInfoBlock));
27 lmib->mutex.Init();
28 lmib->mib = Block;
29 *h = lmib;
30 } else {
31 LockedMemInfoBlock *lmib = *h;
32 SpinMutexLock lock(&lmib->mutex);
33 lmib->mib.Merge(Block);
37 } // namespace __memprof