================ @@ -0,0 +1,144 @@ +//===- DerivedAnalysis.h --------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// +// Defines DerivedAnalysisBase (type-erased base known to AnalysisDriver) and +// the typed intermediate DerivedAnalysis<ResultT, DepResultTs...> that +// concrete analyses inherit from. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_CORE_ANALYSIS_DERIVEDANALYSIS_H +#define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_CORE_ANALYSIS_DERIVEDANALYSIS_H + +#include "clang/ScalableStaticAnalysisFramework/Core/Analysis/AnalysisBase.h" +#include "clang/ScalableStaticAnalysisFramework/Core/Analysis/AnalysisName.h" +#include "clang/ScalableStaticAnalysisFramework/Core/Analysis/AnalysisResult.h" +#include "clang/ScalableStaticAnalysisFramework/Core/Analysis/AnalysisTraits.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/ErrorHandling.h" +#include <map> +#include <memory> +#include <vector> + +namespace clang::ssaf { + +class AnalysisDriver; +class AnalysisRegistry; + +/// Type-erased base for derived analyses. Known to AnalysisDriver. +/// +/// Not subclassed directly -- use DerivedAnalysis<ResultT, DepResultTs...>. +/// A derived analysis consumes previously produced AnalysisResult objects +/// and computes a new one via an initialize/step/finalize lifecycle. +class DerivedAnalysisBase : public AnalysisBase { + friend class AnalysisDriver; + +protected: + DerivedAnalysisBase() : AnalysisBase(AnalysisBase::Kind::Derived) {} + +private: + /// Called once with the dependency results before the step() loop. + /// + /// \param DepResults Immutable results of all declared dependencies, keyed + /// by AnalysisName. Guaranteed to contain every name + /// returned by dependencyNames(). + virtual llvm::Error initialize( + const std::map<AnalysisName, const AnalysisResult *> &DepResults) = 0; + + /// Performs one pass. Returns true if another pass is needed; false when + /// converged. + virtual llvm::Expected<bool> step() = 0; ---------------- aviralg wrote:
Error propagation is important at every point. I know llvm::Expected<bool> is costly but it is probably nothing compared to the amount of work done at each step. The alternative is for the analysis author to store error in some local variable, return false from step, and return the error in finalize. But I find it too stateful and ugly. https://github.com/llvm/llvm-project/pull/186813 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
