88
99#include " mlir/Conversion/Normalize/Normalize.h"
1010
11- #include " mlir/Dialect/Arith/IR/Arith.h"
12- #include " mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
1311#include " mlir/Dialect/Func/IR/FuncOps.h"
14- #include " mlir/Dialect/LLVMIR/LLVMDialect.h"
15- #include " mlir/Dialect/SCF/IR/SCF.h"
1612#include " mlir/Dialect/Vector/Utils/VectorUtils.h"
1713#include " mlir/IR/AsmState.h"
18- #include " mlir/IR/TypeUtilities.h"
1914#include " mlir/Pass/Pass.h"
15+ #include " mlir/Support/LLVM.h"
2016#include " llvm/ADT/Hashing.h"
21- #include " llvm/Support/FormatVariadic.h"
22- #include " llvm/Support/raw_ostream.h"
2317
2418#include < iomanip>
2519#include < sstream>
@@ -49,21 +43,19 @@ struct NormalizePass : public impl::NormalizeBase<NormalizePass> {
4943 bool isOutput (Operation &op) const noexcept ;
5044 void reorderOperations (const SmallVector<Operation *, 16 > &outputs);
5145 void reorderOperation (Operation *used, Operation *user,
52- llvm:: SmallPtrSet<const Operation *, 32 > &visited);
46+ SmallPtrSet<const Operation *, 32 > &visited);
5347 void renameOperations (const SmallVector<Operation *, 16 > &outputs);
5448 void renameOperation (Operation *op,
5549 SmallPtrSet<const Operation *, 32 > &visited);
5650 bool isInitialOperation (Operation *const op) const noexcept ;
57- void
58- nameAsInitialOperation (Operation *op,
59- llvm::SmallPtrSet<const Operation *, 32 > &visited);
60- void
61- nameAsRegularOperation (Operation *op,
62- llvm::SmallPtrSet<const Operation *, 32 > &visited);
51+ void nameAsInitialOperation (Operation *op,
52+ SmallPtrSet<const Operation *, 32 > &visited);
53+ void nameAsRegularOperation (Operation *op,
54+ SmallPtrSet<const Operation *, 32 > &visited);
6355 bool hasOnlyImmediateOperands (Operation *const op) const noexcept ;
64- llvm:: SetVector<int >
56+ SetVector<int >
6557 getOutputFootprint (Operation *op,
66- llvm:: SmallPtrSet<const Operation *, 32 > &visited) const ;
58+ SmallPtrSet<const Operation *, 32 > &visited) const ;
6759 void appendRenamedOperands (Operation *op, SmallString<512 > &name);
6860 void reorderOperationOperandsByName (Operation *op);
6961 OpPrintingFlags flags{};
@@ -90,7 +82,7 @@ void NormalizePass::runOnOperation() {
9082
9183void NormalizePass::renameOperations (
9284 const SmallVector<Operation *, 16 > &outputs) {
93- llvm:: SmallPtrSet<const Operation *, 32 > visited;
85+ SmallPtrSet<const Operation *, 32 > visited;
9486
9587 for (auto *op : outputs)
9688 renameOperation (op, visited);
@@ -175,7 +167,7 @@ std::string inline split(std::string_view str, const char &delimiter,
175167// / arguments, void is appended, else a hash of the definition of the operation
176168// / is appended.
177169void NormalizePass::nameAsInitialOperation (
178- Operation *op, llvm:: SmallPtrSet<const Operation *, 32 > &visited) {
170+ Operation *op, SmallPtrSet<const Operation *, 32 > &visited) {
179171
180172 for (Value operand : op->getOperands ())
181173 if (Operation *defOp = operand.getDefiningOp ())
@@ -196,7 +188,7 @@ void NormalizePass::nameAsInitialOperation(
196188 name.append (" vl" + std::to_string (hash).substr (0 , 5 ));
197189
198190 if (auto call = dyn_cast<func::CallOp>(op)) {
199- llvm:: StringRef callee = call.getCallee ();
191+ StringRef callee = call.getCallee ();
200192 name.append (callee.str ());
201193 }
202194
@@ -233,7 +225,7 @@ void NormalizePass::nameAsInitialOperation(
233225// / CallOp. A regular operation must have operands, thus the renaming is further
234226// / handled in appendRenamedOperands.
235227void NormalizePass::nameAsRegularOperation (
236- Operation *op, llvm:: SmallPtrSet<const Operation *, 32 > &visited) {
228+ Operation *op, SmallPtrSet<const Operation *, 32 > &visited) {
237229
238230 for (Value operand : op->getOperands ())
239231 if (Operation *defOp = operand.getDefiningOp ())
@@ -260,7 +252,7 @@ void NormalizePass::nameAsRegularOperation(
260252 name.append (" op" + std::to_string (hash).substr (0 , 5 ));
261253
262254 if (auto call = dyn_cast<func::CallOp>(op)) {
263- llvm:: StringRef callee = call.getCallee ();
255+ StringRef callee = call.getCallee ();
264256 name.append (callee.str ());
265257 }
266258
@@ -318,7 +310,7 @@ void NormalizePass::appendRenamedOperands(Operation *op,
318310 }
319311
320312 if (op->hasTrait <OpTrait::IsCommutative>())
321- llvm:: sort (operands.begin (), operands.end ());
313+ sort (operands.begin (), operands.end ());
322314
323315 name.append (" $" );
324316 for (size_t i = 0 , size_ = operands.size (); i < size_; ++i) {
@@ -350,10 +342,9 @@ void NormalizePass::reorderOperationOperandsByName(Operation *op) {
350342 }
351343
352344 if (op->hasTrait <OpTrait::IsCommutative>()) {
353- llvm::sort (
354- operands.begin (), operands.end (), [](const auto &a, const auto &b) {
355- return llvm::StringRef (a.first ).compare_insensitive (b.first ) < 0 ;
356- });
345+ sort (operands.begin (), operands.end (), [](const auto &a, const auto &b) {
346+ return StringRef (a.first ).compare_insensitive (b.first ) < 0 ;
347+ });
357348 }
358349
359350 for (size_t i = 0 , size_ = operands.size (); i < size_; i++) {
@@ -365,7 +356,7 @@ void NormalizePass::reorderOperationOperandsByName(Operation *op) {
365356// / operation and reducing the def-use distance.
366357void NormalizePass::reorderOperations (
367358 const SmallVector<Operation *, 16 > &outputs) {
368- llvm:: SmallPtrSet<const Operation *, 32 > visited;
359+ SmallPtrSet<const Operation *, 32 > visited;
369360 for (auto *const op : outputs)
370361 for (Value operand : op->getOperands ())
371362 if (Operation *defOp = operand.getDefiningOp ())
@@ -374,7 +365,7 @@ void NormalizePass::reorderOperations(
374365
375366void NormalizePass::reorderOperation (
376367 Operation *used, Operation *user,
377- llvm:: SmallPtrSet<const Operation *, 32 > &visited) {
368+ SmallPtrSet<const Operation *, 32 > &visited) {
378369 if (!visited.count (used)) {
379370 visited.insert (used);
380371
@@ -426,9 +417,9 @@ bool NormalizePass::isOutput(Operation &op) const noexcept {
426417// / Helper method returning indices (distance from the beginning of the basic
427418// / block) of output operations using the given operation. Walks down the
428419// / def-use tree recursively
429- llvm:: SetVector<int > NormalizePass::getOutputFootprint (
430- Operation *op, llvm:: SmallPtrSet<const Operation *, 32 > &visited) const {
431- llvm:: SetVector<int > outputsVec;
420+ SetVector<int > NormalizePass::getOutputFootprint (
421+ Operation *op, SmallPtrSet<const Operation *, 32 > &visited) const {
422+ SetVector<int > outputsVec;
432423 if (!visited.count (op)) {
433424 visited.insert (op);
434425
@@ -449,8 +440,7 @@ llvm::SetVector<int> NormalizePass::getOutputFootprint(
449440 for (OpOperand &use : op->getUses ()) {
450441 Operation *useOp = use.getOwner ();
451442 if (useOp) {
452- llvm::SetVector<int > outputsUsingUop =
453- getOutputFootprint (useOp, visited);
443+ SetVector<int > outputsUsingUop = getOutputFootprint (useOp, visited);
454444
455445 outputsVec.insert (outputsUsingUop.begin (), outputsUsingUop.end ());
456446 }
0 commit comments