[PATCH] D153491: [dataflow] Avoid copying environment

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 21 19:27:30 PDT 2023


sammccall created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This appears to be just an accidental copy rather than move from a scratch
variable.
As well as doing redundant work, these copies introduce extra SAT variables
which make debugging harder (each Enviroment has a unique FC token).

Example flow condition before:

  (B0:1 = V15)
  (B1:1 = V8)
  (B2:1 = V10)
  (B3:1 = (V4 & (!V7 => V6)))
  (V10 = (B3:1 & !V7))
  (V12 = B1:1)
  (V13 = B2:1)
  (V15 = (V12 | V13))
  (V3 = V2)
  (V4 = V3)
  (V8 = (B3:1 & !!V7))
  B0:1
  V2

after:

  (B0:1 = (V9 | V10))
  (B1:1 = (B3:1 & !!V6))
  (B2:1 = (B3:1 & !V6))
  (B3:1 = (V3 & (!V6 => V5)))
  (V10 = B2:1)
  (V3 = V2)
  (V9 = B1:1)
  B0:1
  V2

(with labelling from D153488 <https://reviews.llvm.org/D153488>)

There are also some more copies that can be avoided here (when multiple blocks
without terminating statements are joined), but they're less trivial, so I'll
put those in another patch.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153491

Files:
  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
@@ -269,7 +269,7 @@
     // initialize the state of each basic block differently.
     MaybeState.emplace(Analysis.typeErasedInitialElement(), AC.InitEnv);
   }
-  return *MaybeState;
+  return std::move(*MaybeState);
 }
 
 /// Built-in transfer function for `CFGStmt`.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153491.533453.patch
Type: text/x-patch
Size: 545 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230622/19a158c0/attachment.bin>


More information about the cfe-commits mailing list