CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
117 lines
3.6 KiB
C++
117 lines
3.6 KiB
C++
//===- BlotMapVector.h - A MapVector with the blot operation ----*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_LIB_TRANSFORMS_OBJCARC_BLOTMAPVECTOR_H
|
|
#define LLVM_LIB_TRANSFORMS_OBJCARC_BLOTMAPVECTOR_H
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
#include <cassert>
|
|
#include <cstddef>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
namespace llvm {
|
|
|
|
/// An associative container with fast insertion-order (deterministic)
|
|
/// iteration over its elements. Plus the special blot operation.
|
|
template <class KeyT, class ValueT> class BlotMapVector {
|
|
/// Map keys to indices in Vector.
|
|
using MapTy = DenseMap<KeyT, size_t>;
|
|
MapTy Map;
|
|
|
|
/// Keys and values.
|
|
using VectorTy = std::vector<std::pair<KeyT, ValueT>>;
|
|
VectorTy Vector;
|
|
|
|
public:
|
|
#ifdef EXPENSIVE_CHECKS
|
|
~BlotMapVector() {
|
|
assert(Vector.size() >= Map.size()); // May differ due to blotting.
|
|
for (typename MapTy::const_iterator I = Map.begin(), E = Map.end(); I != E;
|
|
++I) {
|
|
assert(I->second < Vector.size());
|
|
assert(Vector[I->second].first == I->first);
|
|
}
|
|
for (typename VectorTy::const_iterator I = Vector.begin(), E = Vector.end();
|
|
I != E; ++I)
|
|
assert(!I->first || (Map.count(I->first) &&
|
|
Map[I->first] == size_t(I - Vector.begin())));
|
|
}
|
|
#endif
|
|
|
|
using iterator = typename VectorTy::iterator;
|
|
using const_iterator = typename VectorTy::const_iterator;
|
|
|
|
iterator begin() { return Vector.begin(); }
|
|
iterator end() { return Vector.end(); }
|
|
const_iterator begin() const { return Vector.begin(); }
|
|
const_iterator end() const { return Vector.end(); }
|
|
|
|
ValueT &operator[](const KeyT &Arg) {
|
|
std::pair<typename MapTy::iterator, bool> Pair = Map.try_emplace(Arg);
|
|
if (Pair.second) {
|
|
size_t Num = Vector.size();
|
|
Pair.first->second = Num;
|
|
Vector.push_back(std::make_pair(Arg, ValueT()));
|
|
return Vector[Num].second;
|
|
}
|
|
return Vector[Pair.first->second].second;
|
|
}
|
|
|
|
std::pair<iterator, bool> insert(const std::pair<KeyT, ValueT> &InsertPair) {
|
|
std::pair<typename MapTy::iterator, bool> Pair =
|
|
Map.insert(std::make_pair(InsertPair.first, size_t(0)));
|
|
if (Pair.second) {
|
|
size_t Num = Vector.size();
|
|
Pair.first->second = Num;
|
|
Vector.push_back(InsertPair);
|
|
return std::make_pair(Vector.begin() + Num, true);
|
|
}
|
|
return std::make_pair(Vector.begin() + Pair.first->second, false);
|
|
}
|
|
|
|
iterator find(const KeyT &Key) {
|
|
typename MapTy::iterator It = Map.find(Key);
|
|
if (It == Map.end())
|
|
return Vector.end();
|
|
return Vector.begin() + It->second;
|
|
}
|
|
|
|
const_iterator find(const KeyT &Key) const {
|
|
typename MapTy::const_iterator It = Map.find(Key);
|
|
if (It == Map.end())
|
|
return Vector.end();
|
|
return Vector.begin() + It->second;
|
|
}
|
|
|
|
/// This is similar to erase, but instead of removing the element from the
|
|
/// vector, it just zeros out the key in the vector. This leaves iterators
|
|
/// intact, but clients must be prepared for zeroed-out keys when iterating.
|
|
void blot(const KeyT &Key) {
|
|
typename MapTy::iterator It = Map.find(Key);
|
|
if (It == Map.end())
|
|
return;
|
|
Vector[It->second].first = KeyT();
|
|
Map.erase(It);
|
|
}
|
|
|
|
void clear() {
|
|
Map.clear();
|
|
Vector.clear();
|
|
}
|
|
|
|
bool empty() const {
|
|
assert(Map.empty() == Vector.empty());
|
|
return Map.empty();
|
|
}
|
|
};
|
|
|
|
} // end namespace llvm
|
|
|
|
#endif // LLVM_LIB_TRANSFORMS_OBJCARC_BLOTMAPVECTOR_H
|