Skip to content

Commit dfa4e49

Browse files
xlaukolanza
authored andcommitted
[CIR] Remove redundant operation traits and use AllTypesMatch instead (llvm#1679)
1 parent a0b7a8b commit dfa4e49

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
@@ -3255,54 +3255,6 @@ LogicalResult cir::AwaitOp::verify() {
32553255
return success();
32563256
}
32573257

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