diff --git a/clang/include/clang/CIR/Dialect/IR/CIRDialect.h b/clang/include/clang/CIR/Dialect/IR/CIRDialect.h index be928d1ee19b..699153b353b9 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRDialect.h +++ b/clang/include/clang/CIR/Dialect/IR/CIRDialect.h @@ -36,58 +36,6 @@ #include "clang/CIR/Interfaces/CIRLoopOpInterface.h" #include "clang/CIR/Interfaces/CIROpInterfaces.h" -namespace mlir { -namespace OpTrait { - -namespace impl { -// These functions are out-of-line implementations of the methods in the -// corresponding trait classes. This avoids them being template -// instantiated/duplicated. -LogicalResult verifySameFirstOperandAndResultType(Operation *op); -LogicalResult verifySameSecondOperandAndResultType(Operation *op); -LogicalResult verifySameFirstSecondOperandAndResultType(Operation *op); -} // namespace impl - -/// This class provides verification for ops that are known to have the same -/// first operand and result type. -/// -template -class SameFirstOperandAndResultType - : public TraitBase { -public: - static llvm::LogicalResult verifyTrait(Operation *op) { - return impl::verifySameFirstOperandAndResultType(op); - } -}; - -/// This class provides verification for ops that are known to have the same -/// second operand and result type. -/// -template -class SameSecondOperandAndResultType - : public TraitBase { -public: - static llvm::LogicalResult verifyTrait(Operation *op) { - return impl::verifySameSecondOperandAndResultType(op); - } -}; - -/// This class provides verification for ops that are known to have the same -/// first, second operand and result type. -/// -template -class SameFirstSecondOperandAndResultType - : public TraitBase { -public: - static llvm::LogicalResult verifyTrait(Operation *op) { - return impl::verifySameFirstSecondOperandAndResultType(op); - } -}; - -} // namespace OpTrait - -} // namespace mlir - namespace cir { void buildTerminatedBody(mlir::OpBuilder &builder, mlir::Location loc); } // namespace cir diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td index 543aa1efb569..c58d86850c6f 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td @@ -82,17 +82,6 @@ class LLVMLoweringInfo { class CIR_Op traits = []> : Op, LLVMLoweringInfo; -//===----------------------------------------------------------------------===// -// CIR Op Traits -//===----------------------------------------------------------------------===// - -def SameFirstOperandAndResultType : - NativeOpTrait<"SameFirstOperandAndResultType">; -def SameSecondOperandAndResultType : - NativeOpTrait<"SameSecondOperandAndResultType">; -def SameFirstSecondOperandAndResultType : - NativeOpTrait<"SameFirstSecondOperandAndResultType">; - //===----------------------------------------------------------------------===// // CastOp //===----------------------------------------------------------------------===// @@ -329,7 +318,7 @@ def PtrDiffOp : CIR_Op<"ptr_diff", [Pure, SameTypeOperands]> { //===----------------------------------------------------------------------===// def PtrStrideOp : CIR_Op<"ptr_stride", - [Pure, SameFirstOperandAndResultType]> { + [Pure, AllTypesMatch<["base", "result"]>]> { let summary = "Pointer access with stride"; let description = [{ Given a base pointer as first operand, provides a new pointer after applying diff --git a/clang/include/clang/CIR/Dialect/IR/CIRStdOps.td b/clang/include/clang/CIR/Dialect/IR/CIRStdOps.td index 4f845a3cc548..c222aea5352a 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRStdOps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIRStdOps.td @@ -53,7 +53,7 @@ class CIRStdOp traits = []>: def StdFindOp : CIRStdOp<"find", (ins CIR_AnyType:$first, CIR_AnyType:$last, CIR_AnyType:$pattern), (outs CIR_AnyType:$result), - [SameFirstSecondOperandAndResultType]>; + [AllTypesMatch<["first", "last", "result"]>]>; def IterBeginOp: CIRStdOp<"begin", (ins CIR_AnyType:$container), (outs CIR_AnyType:$result)>; diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp index aaec48b23553..814a3e2091f6 100644 --- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp @@ -3256,54 +3256,6 @@ LogicalResult cir::AwaitOp::verify() { return success(); } -//===----------------------------------------------------------------------===// -// CIR defined traits -//===----------------------------------------------------------------------===// - -LogicalResult -mlir::OpTrait::impl::verifySameFirstOperandAndResultType(Operation *op) { - if (failed(verifyAtLeastNOperands(op, 1)) || failed(verifyOneResult(op))) - return failure(); - - auto type = op->getResult(0).getType(); - auto opType = op->getOperand(0).getType(); - - if (type != opType) - return op->emitOpError() - << "requires the same type for first operand and result"; - - return success(); -} - -LogicalResult -mlir::OpTrait::impl::verifySameSecondOperandAndResultType(Operation *op) { - if (failed(verifyAtLeastNOperands(op, 2)) || failed(verifyOneResult(op))) - return failure(); - - auto type = op->getResult(0).getType(); - auto opType = op->getOperand(1).getType(); - - if (type != opType) - return op->emitOpError() - << "requires the same type for second operand and result"; - - return success(); -} - -LogicalResult -mlir::OpTrait::impl::verifySameFirstSecondOperandAndResultType(Operation *op) { - if (failed(verifyAtLeastNOperands(op, 3)) || failed(verifyOneResult(op))) - return failure(); - - auto checkType = op->getResult(0).getType(); - if (checkType != op->getOperand(0).getType() && - checkType != op->getOperand(1).getType()) - return op->emitOpError() - << "requires the same type for first, second operand and result"; - - return success(); -} - //===----------------------------------------------------------------------===// // CIR attributes // FIXME: move all of these to CIRAttrs.cpp diff --git a/clang/test/CIR/IR/invalid.cir b/clang/test/CIR/IR/invalid.cir index a2341bd9119c..535a76552f2a 100644 --- a/clang/test/CIR/IR/invalid.cir +++ b/clang/test/CIR/IR/invalid.cir @@ -99,7 +99,7 @@ cir.func @s1() { cir.func @badstride(%x: !cir.ptr>) { %idx = cir.const #cir.int<2> : !cir.int - %4 = cir.ptr_stride(%x : !cir.ptr>, %idx : !cir.int), !cir.ptr // expected-error {{requires the same type for first operand and result}} + %4 = cir.ptr_stride(%x : !cir.ptr>, %idx : !cir.int), !cir.ptr // expected-error {{op failed to verify that all of {base, result} have same type}} cir.return }