[Mlir-commits] [llvm] [mlir] [mlir] Add Normalize pass (PR #162266)
Jacques Pienaar
llvmlistbot at llvm.org
Fri Oct 24 04:49:39 PDT 2025
================
@@ -0,0 +1,461 @@
+//===- Normalize.cpp - Conversion from MLIR to its canonical form ---------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Conversion/Normalize/Normalize.h"
+
+#include "mlir/Dialect/Arith/IR/Arith.h"
+#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
+#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
+#include "mlir/Dialect/SCF/IR/SCF.h"
+#include "mlir/Dialect/Vector/Utils/VectorUtils.h"
+#include "mlir/IR/AsmState.h"
+#include "mlir/IR/TypeUtilities.h"
+#include "mlir/Pass/Pass.h"
+#include "llvm/ADT/Hashing.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include <iomanip>
+#include <sstream>
+
+namespace mlir {
+#define GEN_PASS_DEF_NORMALIZE
+#include "mlir/Conversion/Passes.h.inc"
+} // namespace mlir
+
+using namespace mlir;
+
+#define DEBUG_TYPE "normalize"
+
+namespace {
+/// NormalizePass aims to transform MLIR into it's normal form
+struct NormalizePass : public impl::NormalizeBase<NormalizePass> {
+ NormalizePass() = default;
+
+ void runOnOperation() override;
+
+private:
+ // Random constant for hashing, so the state isn't zero.
+ const uint64_t magicHashConstant = 0x6acaa36bef8325c5ULL;
+ void
+ collectOutputOperations(Block &block,
+ SmallVector<Operation *, 16> &outputs) const noexcept;
+ bool isOutput(Operation &op) const noexcept;
+ void reorderOperations(const SmallVector<Operation *, 16> &outputs);
+ void reorderOperation(Operation *used, Operation *user,
+ llvm::SmallPtrSet<const Operation *, 32> &visited);
----------------
jpienaar wrote:
Include mlir/Support/LLVM.h and then you can elide some of these namespacing.
https://github.com/llvm/llvm-project/pull/162266
More information about the Mlir-commits
mailing list