[llvm] [InlineCost] Cache collectEphemeralValues() to save compile time (PR #130210)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 20 10:01:44 PDT 2025
================
@@ -0,0 +1,60 @@
+//===- llvm/Analysis/EphemeralValuesCache.h ---------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// This pass caches ephemeral values, i.e., values that are only used by
+// @llvm.assume intrinsics, for cheap access after the initial collection.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_ANALYSIS_EPHEMERALVALUESCACHE_H
+#define LLVM_ANALYSIS_EPHEMERALVALUESCACHE_H
+
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/IR/PassManager.h"
+
+namespace llvm {
+
+class Function;
+class AssumptionCache;
+class Value;
+
+/// A cache of ephemeral values within a function.
+class EphemeralValuesCache {
+ SmallPtrSet<const Value *, 32> EphValues;
+ Function &F;
+ AssumptionCache &AC;
+ bool Collected = false;
+
+ void collectEphemeralValues();
+
+public:
+ EphemeralValuesCache(Function &F, AssumptionCache &AC) : F(F), AC(AC) {}
+ void clear() {
+ EphValues.clear();
+ Collected = false;
+ }
+ const SmallPtrSetImpl<const Value *> &ephValues() {
----------------
vporpo wrote:
Do you mean removing the indirection by incorporating the functionality of the `EphemeralValuesCache` inside the `EphemeralValuesAnalysis` class? Isn't it better to follow the two-class design where you implement the analysis in one class and have a separate wrapper class for the pass in case someone needs to use the analysis without a pass ?
As for the eager vs lazy approach, my guess is that lazy is preferable because it may save you some compile time if you don't end up calling the analysis, but I don't feel strongly about it.
https://github.com/llvm/llvm-project/pull/130210
More information about the llvm-commits
mailing list