summaryrefslogtreecommitdiff
path: root/mlir/lib/IR
diff options
context:
space:
mode:
Diffstat (limited to 'mlir/lib/IR')
-rw-r--r--mlir/lib/IR/AffineExpr.cpp2
-rw-r--r--mlir/lib/IR/AsmPrinter.cpp7
-rw-r--r--mlir/lib/IR/Diagnostics.cpp21
-rw-r--r--mlir/lib/IR/Location.cpp4
-rw-r--r--mlir/lib/IR/PDL/PDLPatternMatch.cpp3
-rw-r--r--mlir/lib/IR/PatternLoggingListener.cpp28
-rw-r--r--mlir/lib/IR/PatternMatch.cpp12
-rw-r--r--mlir/lib/IR/SymbolTable.cpp5
-rw-r--r--mlir/lib/IR/Value.cpp2
9 files changed, 40 insertions, 44 deletions
diff --git a/mlir/lib/IR/AffineExpr.cpp b/mlir/lib/IR/AffineExpr.cpp
index 0652202fe331..e55a666d6766 100644
--- a/mlir/lib/IR/AffineExpr.cpp
+++ b/mlir/lib/IR/AffineExpr.cpp
@@ -8,7 +8,6 @@
#include <cmath>
#include <cstdint>
-#include <limits>
#include <utility>
#include "AffineExprDetail.h"
@@ -16,7 +15,6 @@
#include "mlir/IR/AffineExprVisitor.h"
#include "mlir/IR/AffineMap.h"
#include "mlir/IR/IntegerSet.h"
-#include "mlir/Support/TypeID.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/MathExtras.h"
#include <numeric>
diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index f95ad290a198..de52fbd3f215 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -40,7 +40,7 @@
#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/Debug.h"
+#include "llvm/Support/DebugLog.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Regex.h"
@@ -2070,9 +2070,8 @@ static OpPrintingFlags verifyOpAndAdjustFlags(Operation *op,
return failure();
});
if (failed(verify(op))) {
- LLVM_DEBUG(llvm::dbgs()
- << DEBUG_TYPE << ": '" << op->getName()
- << "' failed to verify and will be printed in generic form\n");
+ LDBG() << op->getName()
+ << "' failed to verify and will be printed in generic form";
printerFlags.printGenericOpForm();
}
diff --git a/mlir/lib/IR/Diagnostics.cpp b/mlir/lib/IR/Diagnostics.cpp
index 3e337951bcd3..776b5c6588c7 100644
--- a/mlir/lib/IR/Diagnostics.cpp
+++ b/mlir/lib/IR/Diagnostics.cpp
@@ -821,15 +821,7 @@ SourceMgrDiagnosticVerifierHandler::SourceMgrDiagnosticVerifierHandler(
for (unsigned i = 0, e = mgr.getNumBuffers(); i != e; ++i)
(void)impl->computeExpectedDiags(out, mgr, mgr.getMemoryBuffer(i + 1));
- // Register a handler to verify the diagnostics.
- setHandler([&](Diagnostic &diag) {
- // Process the main diagnostics.
- process(diag);
-
- // Process each of the notes.
- for (auto &note : diag.getNotes())
- process(note);
- });
+ registerInContext(ctx);
}
SourceMgrDiagnosticVerifierHandler::SourceMgrDiagnosticVerifierHandler(
@@ -862,6 +854,17 @@ LogicalResult SourceMgrDiagnosticVerifierHandler::verify() {
return impl->status;
}
+void SourceMgrDiagnosticVerifierHandler::registerInContext(MLIRContext *ctx) {
+ ctx->getDiagEngine().registerHandler([&](Diagnostic &diag) {
+ // Process the main diagnostics.
+ process(diag);
+
+ // Process each of the notes.
+ for (auto &note : diag.getNotes())
+ process(note);
+ });
+}
+
/// Process a single diagnostic.
void SourceMgrDiagnosticVerifierHandler::process(Diagnostic &diag) {
return process(diag.getLocation(), diag.str(), diag.getSeverity());
diff --git a/mlir/lib/IR/Location.cpp b/mlir/lib/IR/Location.cpp
index f897546f36ba..23e70c6449fe 100644
--- a/mlir/lib/IR/Location.cpp
+++ b/mlir/lib/IR/Location.cpp
@@ -18,13 +18,9 @@
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
-#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/TrailingObjects.h"
#include <cassert>
-#include <iterator>
-#include <memory>
-#include <optional>
#include <tuple>
#include <utility>
diff --git a/mlir/lib/IR/PDL/PDLPatternMatch.cpp b/mlir/lib/IR/PDL/PDLPatternMatch.cpp
index 28b39dd75e26..62a71aa2c1da 100644
--- a/mlir/lib/IR/PDL/PDLPatternMatch.cpp
+++ b/mlir/lib/IR/PDL/PDLPatternMatch.cpp
@@ -7,10 +7,7 @@
//
//===----------------------------------------------------------------------===//
-#include "mlir/IR/IRMapping.h"
-#include "mlir/IR/Iterators.h"
#include "mlir/IR/PatternMatch.h"
-#include "mlir/IR/RegionKindInterface.h"
#include "llvm/Support/InterleavedRange.h"
using namespace mlir;
diff --git a/mlir/lib/IR/PatternLoggingListener.cpp b/mlir/lib/IR/PatternLoggingListener.cpp
index ce2123ae1a19..0db13ab5b775 100644
--- a/mlir/lib/IR/PatternLoggingListener.cpp
+++ b/mlir/lib/IR/PatternLoggingListener.cpp
@@ -1,50 +1,48 @@
#include "mlir/IR/PatternMatch.h"
-#include "llvm/Support/Debug.h"
+#include "llvm/Support/DebugLog.h"
#define DEBUG_TYPE "pattern-logging-listener"
-#define DBGS() (llvm::dbgs() << "[" << DEBUG_TYPE << "] ")
-#define LDBG(X) LLVM_DEBUG(DBGS() << X << "\n")
using namespace mlir;
void RewriterBase::PatternLoggingListener::notifyOperationInserted(
Operation *op, InsertPoint previous) {
- LDBG(patternName << " | notifyOperationInserted"
- << " | " << op->getName());
+ LDBG() << patternName << " | notifyOperationInserted"
+ << " | " << op->getName();
ForwardingListener::notifyOperationInserted(op, previous);
}
void RewriterBase::PatternLoggingListener::notifyOperationModified(
Operation *op) {
- LDBG(patternName << " | notifyOperationModified"
- << " | " << op->getName());
+ LDBG() << patternName << " | notifyOperationModified"
+ << " | " << op->getName();
ForwardingListener::notifyOperationModified(op);
}
void RewriterBase::PatternLoggingListener::notifyOperationReplaced(
Operation *op, Operation *newOp) {
- LDBG(patternName << " | notifyOperationReplaced (with op)"
- << " | " << op->getName() << " | " << newOp->getName());
+ LDBG() << patternName << " | notifyOperationReplaced (with op)"
+ << " | " << op->getName() << " | " << newOp->getName();
ForwardingListener::notifyOperationReplaced(op, newOp);
}
void RewriterBase::PatternLoggingListener::notifyOperationReplaced(
Operation *op, ValueRange replacement) {
- LDBG(patternName << " | notifyOperationReplaced (with values)"
- << " | " << op->getName());
+ LDBG() << patternName << " | notifyOperationReplaced (with values)"
+ << " | " << op->getName();
ForwardingListener::notifyOperationReplaced(op, replacement);
}
void RewriterBase::PatternLoggingListener::notifyOperationErased(
Operation *op) {
- LDBG(patternName << " | notifyOperationErased"
- << " | " << op->getName());
+ LDBG() << patternName << " | notifyOperationErased"
+ << " | " << op->getName();
ForwardingListener::notifyOperationErased(op);
}
void RewriterBase::PatternLoggingListener::notifyPatternBegin(
const Pattern &pattern, Operation *op) {
- LDBG(patternName << " | notifyPatternBegin"
- << " | " << op->getName());
+ LDBG() << patternName << " | notifyPatternBegin"
+ << " | " << op->getName();
ForwardingListener::notifyPatternBegin(pattern, op);
}
diff --git a/mlir/lib/IR/PatternMatch.cpp b/mlir/lib/IR/PatternMatch.cpp
index 1e6084822a99..9332f55bd939 100644
--- a/mlir/lib/IR/PatternMatch.cpp
+++ b/mlir/lib/IR/PatternMatch.cpp
@@ -7,8 +7,6 @@
//===----------------------------------------------------------------------===//
#include "mlir/IR/PatternMatch.h"
-#include "mlir/Config/mlir-config.h"
-#include "mlir/IR/IRMapping.h"
#include "mlir/IR/Iterators.h"
#include "mlir/IR/RegionKindInterface.h"
#include "llvm/ADT/SmallPtrSet.h"
@@ -158,6 +156,11 @@ void RewriterBase::eraseOp(Operation *op) {
assert(op->use_empty() && "expected 'op' to have no uses");
auto *rewriteListener = dyn_cast_if_present<Listener>(listener);
+ // If the current insertion point is before the erased operation, we adjust
+ // the insertion point to be after the operation.
+ if (getInsertionPoint() == op->getIterator())
+ setInsertionPointAfter(op);
+
// Fast path: If no listener is attached, the op can be dropped in one go.
if (!rewriteListener) {
op->erase();
@@ -322,6 +325,11 @@ void RewriterBase::inlineBlockBefore(Block *source, Block *dest,
moveOpBefore(&source->front(), dest, before);
}
+ // If the current insertion point is within the source block, adjust the
+ // insertion point to the destination block.
+ if (getInsertionBlock() == source)
+ setInsertionPoint(dest, getInsertionPoint());
+
// Erase the source block.
assert(source->empty() && "expected 'source' to be empty");
eraseBlock(source);
diff --git a/mlir/lib/IR/SymbolTable.cpp b/mlir/lib/IR/SymbolTable.cpp
index aaa4d5617eb4..87b47992905e 100644
--- a/mlir/lib/IR/SymbolTable.cpp
+++ b/mlir/lib/IR/SymbolTable.cpp
@@ -10,7 +10,6 @@
#include "mlir/IR/Builders.h"
#include "mlir/IR/OpImplementation.h"
#include "llvm/ADT/SetVector.h"
-#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringSwitch.h"
#include <optional>
@@ -121,7 +120,7 @@ SymbolTable::SymbolTable(Operation *symbolTableOp)
"expected operation to have SymbolTable trait");
assert(symbolTableOp->getNumRegions() == 1 &&
"expected operation to have a single region");
- assert(llvm::hasSingleElement(symbolTableOp->getRegion(0)) &&
+ assert(symbolTableOp->getRegion(0).hasOneBlock() &&
"expected operation to have a single block");
StringAttr symbolNameId = StringAttr::get(symbolTableOp->getContext(),
@@ -484,7 +483,7 @@ LogicalResult detail::verifySymbolTable(Operation *op) {
if (op->getNumRegions() != 1)
return op->emitOpError()
<< "Operations with a 'SymbolTable' must have exactly one region";
- if (!llvm::hasSingleElement(op->getRegion(0)))
+ if (!op->getRegion(0).hasOneBlock())
return op->emitOpError()
<< "Operations with a 'SymbolTable' must have exactly one block";
diff --git a/mlir/lib/IR/Value.cpp b/mlir/lib/IR/Value.cpp
index 7b3a9462a091..fa550e4d5d5d 100644
--- a/mlir/lib/IR/Value.cpp
+++ b/mlir/lib/IR/Value.cpp
@@ -8,9 +8,7 @@
#include "mlir/IR/Value.h"
#include "mlir/IR/Block.h"
-#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Operation.h"
-#include "llvm/ADT/SmallPtrSet.h"
using namespace mlir;
using namespace mlir::detail;