[PATCH] D146507: [clang][dataflow][NFC] Eliminate StmtToEnvMap interface.
Martin Böhme via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 28 00:28:46 PDT 2023
mboehme updated this revision to Diff 508907.
mboehme added a comment.
Rebase to head
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D146507/new/
https://reviews.llvm.org/D146507
Files:
clang/include/clang/Analysis/FlowSensitive/Transfer.h
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===================================================================
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -40,29 +40,6 @@
namespace clang {
namespace dataflow {
-class StmtToEnvMapImpl : public StmtToEnvMap {
-public:
- StmtToEnvMapImpl(
- const ControlFlowContext &CFCtx,
- llvm::ArrayRef<std::optional<TypeErasedDataflowAnalysisState>>
- BlockToState)
- : CFCtx(CFCtx), BlockToState(BlockToState) {}
-
- const Environment *getEnvironment(const Stmt &S) const override {
- auto BlockIt = CFCtx.getStmtToBlock().find(&ignoreCFGOmittedNodes(S));
- assert(BlockIt != CFCtx.getStmtToBlock().end());
- if (!CFCtx.isBlockReachable(*BlockIt->getSecond()))
- return nullptr;
- const auto &State = BlockToState[BlockIt->getSecond()->getBlockID()];
- assert(State);
- return &State->Env;
- }
-
-private:
- const ControlFlowContext &CFCtx;
- llvm::ArrayRef<std::optional<TypeErasedDataflowAnalysisState>> BlockToState;
-};
-
/// Returns the index of `Block` in the successors of `Pred`.
static int blockIndexInPredecessor(const CFGBlock &Pred,
const CFGBlock &Block) {
@@ -269,7 +246,7 @@
TypeErasedDataflowAnalysisState PredState = *MaybePredState;
if (Analysis.builtinOptions()) {
if (const Stmt *PredTerminatorStmt = Pred->getTerminatorStmt()) {
- const StmtToEnvMapImpl StmtToEnv(AC.CFCtx, AC.BlockStates);
+ const StmtToEnvMap StmtToEnv(AC.CFCtx, AC.BlockStates);
auto [Cond, CondValue] =
TerminatorVisitor(StmtToEnv, PredState.Env,
blockIndexInPredecessor(*Pred, Block))
@@ -304,7 +281,7 @@
AnalysisContext &AC) {
const Stmt *S = Elt.getStmt();
assert(S != nullptr);
- transfer(StmtToEnvMapImpl(AC.CFCtx, AC.BlockStates), *S, InputState.Env);
+ transfer(StmtToEnvMap(AC.CFCtx, AC.BlockStates), *S, InputState.Env);
}
/// Built-in transfer function for `CFGInitializer`.
Index: clang/include/clang/Analysis/FlowSensitive/Transfer.h
===================================================================
--- clang/include/clang/Analysis/FlowSensitive/Transfer.h
+++ clang/include/clang/Analysis/FlowSensitive/Transfer.h
@@ -17,6 +17,7 @@
#include "clang/AST/Stmt.h"
#include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
+#include "clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h"
namespace clang {
namespace dataflow {
@@ -24,12 +25,26 @@
/// Maps statements to the environments of basic blocks that contain them.
class StmtToEnvMap {
public:
- virtual ~StmtToEnvMap() = default;
-
- /// Retrieves the environment of the basic block that contains `S`.
- /// If `S` is reachable, returns a non-null pointer to the environment.
- /// If `S` is not reachable, returns nullptr.
- virtual const Environment *getEnvironment(const Stmt &S) const = 0;
+ StmtToEnvMap(const ControlFlowContext &CFCtx,
+ llvm::ArrayRef<std::optional<TypeErasedDataflowAnalysisState>>
+ BlockToState)
+ : CFCtx(CFCtx), BlockToState(BlockToState) {}
+
+ /// Returns the environment of the basic block that contains `S`.
+ /// The result is guaranteed never to be null.
+ virtual const Environment *getEnvironment(const Stmt &S) const {
+ auto BlockIt = CFCtx.getStmtToBlock().find(&ignoreCFGOmittedNodes(S));
+ assert(BlockIt != CFCtx.getStmtToBlock().end());
+ if (!CFCtx.isBlockReachable(*BlockIt->getSecond()))
+ return nullptr;
+ const auto &State = BlockToState[BlockIt->getSecond()->getBlockID()];
+ assert(State);
+ return &State->Env;
+ }
+
+private:
+ const ControlFlowContext &CFCtx;
+ llvm::ArrayRef<std::optional<TypeErasedDataflowAnalysisState>> BlockToState;
};
/// Evaluates `S` and updates `Env` accordingly.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146507.508907.patch
Type: text/x-patch
Size: 4050 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230328/dda421b5/attachment.bin>
More information about the cfe-commits
mailing list