[Mlir-commits] [mlir] Fix block merging (PR #97697)

Jakub Kuderski llvmlistbot at llvm.org
Mon Jul 8 08:20:32 PDT 2024


================
@@ -674,6 +679,64 @@ static bool ableToUpdatePredOperands(Block *block) {
   return true;
 }
 
+/// Prunes the redundant list of arguments. E.g., if we are passing an argument
+/// list like [x, y, z, x] this would return [x, y, z] and it would update the
+/// `block` (to whom the argument are passed to) accordingly
+static void
+pruneRedundantArguments(SmallVector<SmallVector<Value, 8>, 2> &newArguments,
+                        RewriterBase &rewriter, Block *block) {
+  SmallVector<SmallVector<Value, 8>, 2> newArgumentsPruned(
+      newArguments.size(), SmallVector<Value, 8>());
+
+  if (!newArguments.empty()) {
+    llvm::DenseMap<unsigned, unsigned> toReplace;
+    // Go through the first list of arguments (list 0)
+    for (unsigned j = 0; j < newArguments[0].size(); j++) {
----------------
kuhar wrote:

Use `enumerate` or calculate the end value once: https://llvm.org/docs/CodingStandards.html#don-t-evaluate-end-every-time-through-a-loop

Also `++j`

https://github.com/llvm/llvm-project/pull/97697


More information about the Mlir-commits mailing list