Skip to content

Commit dd5986c

Browse files
authored
[CIR] Remove redundant operation traits and use AllTypesMatch instead (#1679)
1 parent bd610ad commit dd5986c

File tree

5 files changed

+3
-114
lines changed

5 files changed

+3
-114
lines changed

clang/include/clang/CIR/Dialect/IR/CIRDialect.h

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -36,58 +36,6 @@
3636
#include "clang/CIR/Interfaces/CIRLoopOpInterface.h"
3737
#include "clang/CIR/Interfaces/CIROpInterfaces.h"
3838

39-
namespace mlir {
40-
namespace OpTrait {
41-
42-
namespace impl {
43-
// These functions are out-of-line implementations of the methods in the
44-
// corresponding trait classes. This avoids them being template
45-
// instantiated/duplicated.
46-
LogicalResult verifySameFirstOperandAndResultType(Operation *op);
47-
LogicalResult verifySameSecondOperandAndResultType(Operation *op);
48-
LogicalResult verifySameFirstSecondOperandAndResultType(Operation *op);
49-
} // namespace impl
50-
51-
/// This class provides verification for ops that are known to have the same
52-
/// first operand and result type.
53-
///
54-
template <typename ConcreteType>
55-
class SameFirstOperandAndResultType
56-
: public TraitBase<ConcreteType, SameFirstOperandAndResultType> {
57-
public:
58-
static llvm::LogicalResult verifyTrait(Operation *op) {
59-
return impl::verifySameFirstOperandAndResultType(op);
60-
}
61-
};
62-
63-
/// This class provides verification for ops that are known to have the same
64-
/// second operand and result type.
65-
///
66-
template <typename ConcreteType>
67-
class SameSecondOperandAndResultType
68-
: public TraitBase<ConcreteType, SameSecondOperandAndResultType> {
69-
public:
70-
static llvm::LogicalResult verifyTrait(Operation *op) {
71-
return impl::verifySameSecondOperandAndResultType(op);
72-
}
73-
};
74-
75-
/// This class provides verification for ops that are known to have the same
76-
/// first, second operand and result type.
77-
///
78-
template <typename ConcreteType>
79-
class SameFirstSecondOperandAndResultType
80-
: public TraitBase<ConcreteType, SameFirstSecondOperandAndResultType> {
81-
public:
82-
static llvm::LogicalResult verifyTrait(Operation *op) {
83-
return impl::verifySameFirstSecondOperandAndResultType(op);
84-
}
85-
};
86-
87-
} // namespace OpTrait
88-
89-
} // namespace mlir
90-
9139
namespace cir {
9240
void buildTerminatedBody(mlir::OpBuilder &builder, mlir::Location loc);
9341
} // namespace cir

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,6 @@ class LLVMLoweringInfo {
8282
class CIR_Op<string mnemonic, list<Trait> traits = []> :
8383
Op<CIR_Dialect, mnemonic, traits>, LLVMLoweringInfo;
8484

85-
//===----------------------------------------------------------------------===//
86-
// CIR Op Traits
87-
//===----------------------------------------------------------------------===//
88-
89-
def SameFirstOperandAndResultType :
90-
NativeOpTrait<"SameFirstOperandAndResultType">;
91-
def SameSecondOperandAndResultType :
92-
NativeOpTrait<"SameSecondOperandAndResultType">;
93-
def SameFirstSecondOperandAndResultType :
94-
NativeOpTrait<"SameFirstSecondOperandAndResultType">;
95-
9685
//===----------------------------------------------------------------------===//
9786
// CastOp
9887
//===----------------------------------------------------------------------===//
@@ -329,7 +318,7 @@ def PtrDiffOp : CIR_Op<"ptr_diff", [Pure, SameTypeOperands]> {
329318
//===----------------------------------------------------------------------===//
330319

331320
def PtrStrideOp : CIR_Op<"ptr_stride",
332-
[Pure, SameFirstOperandAndResultType]> {
321+
[Pure, AllTypesMatch<["base", "result"]>]> {
333322
let summary = "Pointer access with stride";
334323
let description = [{
335324
Given a base pointer as first operand, provides a new pointer after applying

clang/include/clang/CIR/Dialect/IR/CIRStdOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class CIRStdOp<string functionName, dag args, dag res, list<Trait> traits = []>:
5353
def StdFindOp : CIRStdOp<"find",
5454
(ins CIR_AnyType:$first, CIR_AnyType:$last, CIR_AnyType:$pattern),
5555
(outs CIR_AnyType:$result),
56-
[SameFirstSecondOperandAndResultType]>;
56+
[AllTypesMatch<["first", "last", "result"]>]>;
5757
def IterBeginOp: CIRStdOp<"begin",
5858
(ins CIR_AnyType:$container),
5959
(outs CIR_AnyType:$result)>;

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,54 +3256,6 @@ LogicalResult cir::AwaitOp::verify() {
32563256
return success();
32573257
}
32583258

3259-
//===----------------------------------------------------------------------===//
3260-
// CIR defined traits
3261-
//===----------------------------------------------------------------------===//
3262-
3263-
LogicalResult
3264-
mlir::OpTrait::impl::verifySameFirstOperandAndResultType(Operation *op) {
3265-
if (failed(verifyAtLeastNOperands(op, 1)) || failed(verifyOneResult(op)))
3266-
return failure();
3267-
3268-
auto type = op->getResult(0).getType();
3269-
auto opType = op->getOperand(0).getType();
3270-
3271-
if (type != opType)
3272-
return op->emitOpError()
3273-
<< "requires the same type for first operand and result";
3274-
3275-
return success();
3276-
}
3277-
3278-
LogicalResult
3279-
mlir::OpTrait::impl::verifySameSecondOperandAndResultType(Operation *op) {
3280-
if (failed(verifyAtLeastNOperands(op, 2)) || failed(verifyOneResult(op)))
3281-
return failure();
3282-
3283-
auto type = op->getResult(0).getType();
3284-
auto opType = op->getOperand(1).getType();
3285-
3286-
if (type != opType)
3287-
return op->emitOpError()
3288-
<< "requires the same type for second operand and result";
3289-
3290-
return success();
3291-
}
3292-
3293-
LogicalResult
3294-
mlir::OpTrait::impl::verifySameFirstSecondOperandAndResultType(Operation *op) {
3295-
if (failed(verifyAtLeastNOperands(op, 3)) || failed(verifyOneResult(op)))
3296-
return failure();
3297-
3298-
auto checkType = op->getResult(0).getType();
3299-
if (checkType != op->getOperand(0).getType() &&
3300-
checkType != op->getOperand(1).getType())
3301-
return op->emitOpError()
3302-
<< "requires the same type for first, second operand and result";
3303-
3304-
return success();
3305-
}
3306-
33073259
//===----------------------------------------------------------------------===//
33083260
// CIR attributes
33093261
// FIXME: move all of these to CIRAttrs.cpp

clang/test/CIR/IR/invalid.cir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ cir.func @s1() {
9999

100100
cir.func @badstride(%x: !cir.ptr<!cir.int<s, 32>>) {
101101
%idx = cir.const #cir.int<2> : !cir.int<s, 32>
102-
%4 = cir.ptr_stride(%x : !cir.ptr<!cir.int<s, 32>>, %idx : !cir.int<s, 32>), !cir.ptr<!cir.float> // expected-error {{requires the same type for first operand and result}}
102+
%4 = cir.ptr_stride(%x : !cir.ptr<!cir.int<s, 32>>, %idx : !cir.int<s, 32>), !cir.ptr<!cir.float> // expected-error {{op failed to verify that all of {base, result} have same type}}
103103
cir.return
104104
}
105105

0 commit comments

Comments
 (0)