[PATCH] D115235: [clang][dataflow] Implement a basic algorithm for dataflow analysis

Gábor Horváth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 8 09:18:12 PST 2021


xazax.hun accepted this revision.
xazax.hun added a comment.

Thanks!



================
Comment at: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp:35
+    TypeErasedDataflowAnalysis &Analysis) {
+  TypeErasedDataflowAnalysisState State = {Analysis.typeErasedInitialElement(),
+                                           InitEnv};
----------------
sgatev wrote:
> xazax.hun wrote:
> > I did not catch this earlier, but I wonder if we should pass the block in to `typeErasedInitialElement`. There are some analysis where the initial element might be different for certain nodes. E.g. here is the algorithms for computing dominators from wikipedia:
> > ```
> >  // dominator of the start node is the start itself
> >  Dom(n0) = {n0}
> >  // for all other nodes, set all nodes as the dominators
> >  for each n in N - {n0}
> >      Dom(n) = N;
> >  // iteratively eliminate nodes that are not dominators
> >  while changes in any Dom(n)
> >      for each n in N - {n0}:
> >          Dom(n) = {n} union with intersection over Dom(p) for all p in pred(n)
> > ```
> > 
> > Here the initial analysis state for the entry node differs from the initial state for the rest of the nodes. 
> Good point, though, I'm not sure if this algorithm is the best choice for such an analysis. It seems that in that case we don't need to evaluate the statements in the basic blocks, right? Perhaps we can generalize the algorithm or offer a separate one for more efficient implementation of such analyses. I added a FIXME and will consider this a bit more.
Dominators is one example, but there might be other analyses where the initial state differs :)
Since this change is really easy to make, I'm ok deferring this until we see the actual need.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115235/new/

https://reviews.llvm.org/D115235



More information about the cfe-commits mailing list