[PATCH] D138339: [FuzzMutate] New strategy `ShuffleBlockStrategy`

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 18 16:49:13 PST 2022


arsenm added inline comments.


================
Comment at: llvm/include/llvm/FuzzMutate/IRMutator.h:130
+
+  using IRMutationStrategy::mutate;
+  void mutate(BasicBlock &BB, RandomIRBuilder &IB) override;
----------------
Why do you need this?


================
Comment at: llvm/lib/FuzzMutate/IRMutator.cpp:309
+  for (Instruction *I : AliveInsts) {
+    I->removeFromParent();
+  }
----------------
You can do this in the first loop, and use a range loop with make_early_inc_range(BB.getFirstInsertionPt(), BB.getTerminator())


================
Comment at: llvm/lib/FuzzMutate/IRMutator.cpp:313
+  // Shuffle these instructions using topological sort.
+  auto getAliveParents = [&AliveInsts](Instruction *I) {
+    SmallSet<Instruction *, 4> Parents;
----------------
The only 2 users I see of this set immediately discard the result and see if it's empty. You can just check the predicate directly without the set


================
Comment at: llvm/lib/FuzzMutate/IRMutator.cpp:317
+      Instruction *P = dyn_cast<Instruction>(O);
+      if (AliveInsts.count(P) != 0)
+        Parents.insert(P);
----------------
Don't need != 0


================
Comment at: llvm/lib/FuzzMutate/IRMutator.cpp:317
+      Instruction *P = dyn_cast<Instruction>(O);
+      if (AliveInsts.count(P) != 0)
+        Parents.insert(P);
----------------
arsenm wrote:
> Don't need != 0
Probably should avoid inserting null into the set 


================
Comment at: llvm/lib/FuzzMutate/IRMutator.cpp:326
+      Instruction *P = dyn_cast<Instruction>(U);
+      if (AliveInsts.count(P) != 0)
+        Children.insert(P);
----------------
Avoid inserting null, don't need != 0


================
Comment at: llvm/lib/FuzzMutate/IRMutator.cpp:334
+  for (Instruction *I : AliveInsts) {
+    if (getAliveParents(I).size() == 0)
+      Roots.insert(I);
----------------
.empty


================
Comment at: llvm/lib/FuzzMutate/IRMutator.cpp:338
+  // Topological sort by randomly selecting a node without a parent, or root.
+  while (Roots.size() != 0) {
+    auto RS = makeSampler<Instruction *>(IB.Rand);
----------------
!Roots.empty


================
Comment at: llvm/lib/FuzzMutate/IRMutator.cpp:347
+    for (Instruction *Child : getAliveChildren(Root)) {
+      if (getAliveParents(Child).size() == 0) {
+        Roots.insert(Child);
----------------
.empty


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138339



More information about the llvm-commits mailing list