Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 0 additions & 52 deletions clang/include/clang/CIR/Dialect/IR/CIRDialect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename ConcreteType>
class SameFirstOperandAndResultType
: public TraitBase<ConcreteType, SameFirstOperandAndResultType> {
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 <typename ConcreteType>
class SameSecondOperandAndResultType
: public TraitBase<ConcreteType, SameSecondOperandAndResultType> {
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 <typename ConcreteType>
class SameFirstSecondOperandAndResultType
: public TraitBase<ConcreteType, SameFirstSecondOperandAndResultType> {
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
Expand Down
13 changes: 1 addition & 12 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,6 @@ class LLVMLoweringInfo {
class CIR_Op<string mnemonic, list<Trait> traits = []> :
Op<CIR_Dialect, mnemonic, traits>, LLVMLoweringInfo;

//===----------------------------------------------------------------------===//
// CIR Op Traits
//===----------------------------------------------------------------------===//

def SameFirstOperandAndResultType :
NativeOpTrait<"SameFirstOperandAndResultType">;
def SameSecondOperandAndResultType :
NativeOpTrait<"SameSecondOperandAndResultType">;
def SameFirstSecondOperandAndResultType :
NativeOpTrait<"SameFirstSecondOperandAndResultType">;

//===----------------------------------------------------------------------===//
// CastOp
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/CIR/Dialect/IR/CIRStdOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CIRStdOp<string functionName, dag args, dag res, list<Trait> 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)>;
Expand Down
48 changes: 0 additions & 48 deletions clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/IR/invalid.cir
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ cir.func @s1() {

cir.func @badstride(%x: !cir.ptr<!cir.int<s, 32>>) {
%idx = cir.const #cir.int<2> : !cir.int<s, 32>
%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}}
%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}}
cir.return
}

Expand Down
Loading