[clang] [clang][ssaf] Add EntityId and EntityIdTable for efficient entity handling (PR #171660)
Gábor Horváth via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 11 03:13:00 PST 2025
================
@@ -0,0 +1,40 @@
+//===- EntityIdTable.cpp ----------------------------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Analysis/Scalable/Model/EntityIdTable.h"
+#include <cassert>
+
+namespace clang {
+namespace ssaf {
+
+EntityId EntityIdTable::getId(const EntityName &Name) {
+ const auto It = Entities.find(Name);
+ if (It == Entities.end()) {
+ EntityId Id(Entities.size());
+ Entities.emplace(Name, Id);
+ return Id;
+ }
+
+ return It->second;
+}
+
+bool EntityIdTable::exists(const EntityName &Name) const {
+ return Entities.find(Name) != Entities.end();
+}
+
+void EntityIdTable::forEach(
+ std::function<void(const EntityName &, EntityId)> Callback) const {
----------------
Xazax-hun wrote:
This function does not escape the scope. Should this be an `llvm::function_ref` instead?
https://github.com/llvm/llvm-project/pull/171660
More information about the cfe-commits
mailing list