llvm-project/llvm/lib/Analysis/EphemeralValuesCache.cpp
vporpo 08dda4dcbf
[Analysis][EphemeralValuesCache][InlineCost] Ephemeral values caching for the CallAnalyzer (#130210)
This patch does two things:

1. It implements an ephemeral values cache analysis pass that collects the ephemeral values of a function and caches them for fast lookups. The collection of the ephemeral values is done lazily when the user calls `EphemeralValuesCache::ephValues()`.

2. It adds caching of ephemeral values using the `EphemeralValuesCache` to speed up `CallAnalyzer::analyze()`. Without caching this can take a long time to run in cases where the function contains a large number of `@llvm.assume()` calls and a large number of callsites. The time is spent in `collectEphemeralvalues()`.
2025-03-19 18:18:45 -07:00

29 lines
905 B
C++

//===- EphemeralValuesCache.cpp - Cache collecting ephemeral values -------===//
//
// 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 "llvm/Analysis/EphemeralValuesCache.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/CodeMetrics.h"
namespace llvm {
void EphemeralValuesCache::collectEphemeralValues() {
CodeMetrics::collectEphemeralValues(&F, &AC, EphValues);
Collected = true;
}
AnalysisKey EphemeralValuesAnalysis::Key;
EphemeralValuesCache
EphemeralValuesAnalysis::run(Function &F, FunctionAnalysisManager &FAM) {
auto &AC = FAM.getResult<AssumptionAnalysis>(F);
return EphemeralValuesCache(F, AC);
}
} // namespace llvm