[mlir] Remove a bunch of unnecessary dialect dependencies

A lot of dialects have dependencies that are unnecessary, either because of copy/paste
of files when creating things or some other means. This commit cleans up a bunch of
the simple ones:

* Copy/Paste or missed during refactoring
Most of the dependencies cleaned up here look like copy/paste errors when creating
new dialects/transformations, or because the dependency wasn't removed during a
refactoring (e.g. when splitting the standard dialect).

* Unnecessary hard coding of constant operations in matchers
There are a few instances where a dialect had a dependency because it
was hardcoding checks for constant operations instead of using the better m_Constant
approach.

Differential Revision: https://reviews.llvm.org/D118062
This commit is contained in:
River Riddle 2022-01-24 11:41:00 -08:00
parent 88c1df64bd
commit 65e7cd13bb
16 changed files with 19 additions and 32 deletions

View File

@ -15,7 +15,6 @@
include "mlir/Dialect/DLTI/DLTIBase.td"
include "mlir/Dialect/GPU/GPUBase.td"
include "mlir/Dialect/LLVMIR/LLVMOpBase.td"
include "mlir/IR/EnumAttr.td"
include "mlir/IR/FunctionInterfaces.td"
include "mlir/IR/SymbolInterfaces.td"

View File

@ -15,7 +15,6 @@
#include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"

View File

@ -16,7 +16,6 @@
#include "mlir/Dialect/GPU/GPUDialect.h"
#include "mlir/Dialect/GPU/Passes.h"
#include "mlir/Dialect/GPU/Utils.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/IR/BlockAndValueMapping.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/PatternMatch.h"

View File

@ -17,7 +17,6 @@
#include "mlir/Dialect/GPU/GPUDialect.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/SCF/SCF.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/IR/ImplicitLocOpBuilder.h"
#include "mlir/Pass/Pass.h"

View File

@ -8,8 +8,6 @@ add_mlir_dialect_library(MLIROpenACC
MLIROpenACCOpsIncGen
LINK_LIBS PUBLIC
MLIRArithmetic
MLIRIR
MLIRStandard
)

View File

@ -7,12 +7,11 @@
// =============================================================================
#include "mlir/Dialect/OpenACC/OpenACC.h"
#include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
#include "mlir/Dialect/OpenACC/OpenACCOpsEnums.cpp.inc"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/DialectImplementation.h"
#include "mlir/IR/Matchers.h"
#include "mlir/IR/OpImplementation.h"
#include "mlir/Transforms/DialectConversion.h"
#include "llvm/ADT/TypeSwitch.h"
@ -175,14 +174,17 @@ struct RemoveConstantIfCondition : public OpRewritePattern<OpTy> {
LogicalResult matchAndRewrite(OpTy op,
PatternRewriter &rewriter) const override {
// Early return if there is no condition.
if (!op.ifCond())
Value ifCond = op.ifCond();
if (!ifCond)
return success();
auto constOp = op.ifCond().template getDefiningOp<arith::ConstantOp>();
if (constOp && constOp.getValue().template cast<IntegerAttr>().getInt())
rewriter.updateRootInPlace(op, [&]() { op.ifCondMutable().erase(0); });
else if (constOp)
rewriter.eraseOp(op);
IntegerAttr constAttr;
if (matchPattern(ifCond, m_Constant(&constAttr))) {
if (constAttr.getInt())
rewriter.updateRootInPlace(op, [&]() { op.ifCondMutable().erase(0); });
else
rewriter.eraseOp(op);
}
return success();
}

View File

@ -12,7 +12,6 @@
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
#include "mlir/Dialect/LLVMIR/LLVMTypes.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/DialectImplementation.h"
#include "mlir/IR/OpImplementation.h"

View File

@ -22,6 +22,5 @@ add_mlir_dialect_library(MLIRQuant
MLIRPass
MLIRSideEffectInterfaces
MLIRSupport
MLIRStandard
MLIRTransformUtils
)

View File

@ -12,7 +12,6 @@
#include "mlir/Dialect/Quant/QuantOps.h"
#include "mlir/Dialect/Quant/QuantizeUtils.h"
#include "mlir/Dialect/Quant/UniformSupport.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Matchers.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"

View File

@ -12,7 +12,6 @@ add_mlir_dialect_library(MLIRSCF
MLIRBufferization
MLIRIR
MLIRLoopLikeInterface
MLIRMemRef
MLIRSideEffectInterfaces
MLIRStandard
)

View File

@ -9,14 +9,13 @@
#include "mlir/Dialect/SCF/SCF.h"
#include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
#include "mlir/Dialect/Bufferization/IR/Bufferization.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"
#include "mlir/IR/BlockAndValueMapping.h"
#include "mlir/IR/Matchers.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Support/MathExtras.h"
#include "mlir/Transforms/InliningUtils.h"
using namespace mlir;
using namespace mlir::scf;

View File

@ -19,6 +19,5 @@ add_mlir_dialect_library(MLIRShape
MLIRInferTypeOpInterface
MLIRIR
MLIRSideEffectInterfaces
MLIRStandard
MLIRTensor
)

View File

@ -12,7 +12,6 @@
#include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
#include "mlir/Dialect/CommonFolders.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"
#include "mlir/Dialect/Traits.h"
#include "mlir/IR/Builders.h"

View File

@ -1,5 +1,4 @@
include "mlir/Dialect/Shape/IR/ShapeOps.td"
include "mlir/Dialect/StandardOps/IR/Ops.td"
include "mlir/Dialect/Tensor/IR/TensorOps.td"
def AllInputShapesEq : Constraint<CPred< [{

View File

@ -9,9 +9,7 @@ add_mlir_dialect_library(MLIRSparseTensor
MLIRSparseTensorOpsIncGen
LINK_LIBS PUBLIC
MLIRArithmetic
MLIRDialect
MLIRIR
MLIRStandard
MLIRSupport
)

View File

@ -6,11 +6,10 @@
//
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
#include "mlir/Dialect/SparseTensor/IR/SparseTensor.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/DialectImplementation.h"
#include "mlir/IR/Matchers.h"
#include "mlir/IR/OpImplementation.h"
#include "llvm/ADT/TypeSwitch.h"
@ -194,8 +193,9 @@ mlir::sparse_tensor::getSparseTensorEncoding(Type type) {
//===----------------------------------------------------------------------===//
static LogicalResult isInBounds(Value dim, Value tensor) {
if (auto constantOp = dim.getDefiningOp<arith::ConstantOp>()) {
unsigned d = constantOp.getValue().cast<IntegerAttr>().getInt();
IntegerAttr constantAttr;
if (matchPattern(dim, m_Constant(&constantAttr))) {
unsigned d = constantAttr.getInt();
if (d >= tensor.getType().cast<RankedTensorType>().getRank())
return failure();
}
@ -227,11 +227,12 @@ static LogicalResult verify(InitOp op) {
for (unsigned i = 0; i < rank; i++) {
if (shape[i] == ShapedType::kDynamicSize)
continue;
auto constantOp = op.sizes()[i].getDefiningOp<arith::ConstantOp>();
if (!constantOp ||
constantOp.getValue().cast<IntegerAttr>().getInt() != shape[i])
IntegerAttr constantAttr;
if (!matchPattern(op.sizes()[i], m_Constant(&constantAttr)) ||
constantAttr.getInt() != shape[i]) {
return op.emitError("unexpected mismatch with static dimension size ")
<< shape[i];
}
}
return success();
}