return builder.create<ConstSizeOp>(loc, type, value.cast<IntegerAttr>());
if (type.isa<WitnessType>())
return builder.create<ConstWitnessOp>(loc, type, value.cast<BoolAttr>());
- if (type.isa<IndexType>())
+ if (ConstantOp::isBuildableWith(value, type))
return builder.create<ConstantOp>(loc, type, value);
return nullptr;
}
#include "mlir/Transforms/FoldUtils.h"
-#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/Matchers.h"
#include "mlir/IR/Operation.h"
assert(matchPattern(constOp, m_Constant()));
return constOp;
}
-
- // If the dialect is unable to materialize a constant, check to see if the
- // standard constant can be used.
- if (ConstantOp::isBuildableWith(value, type))
- return builder.create<ConstantOp>(loc, type, value);
return nullptr;
}
allowUnknownOperations();
}
+Operation *TestDialect::materializeConstant(OpBuilder &builder, Attribute value,
+ Type type, Location loc) {
+ return builder.create<TestOpConstant>(loc, type, value);
+}
+
static Type parseTestType(MLIRContext *ctxt, DialectAsmParser &parser,
llvm::SetVector<Type> &stack) {
StringRef typeTag;
// CHECK-LABEL: testConstOp
func @testConstOp() -> (i32) {
- // CHECK-NEXT: [[C0:%.+]] = constant 1
+ // CHECK-NEXT: [[C0:%.+]] = "test.constant"() {value = 1
%0 = "test.constant"() {value = 1 : i32} : () -> i32
// CHECK-NEXT: return [[C0]]
// CHECK-LABEL: testConstOpUsed
func @testConstOpUsed() -> (i32) {
- // CHECK-NEXT: [[C0:%.+]] = constant 1
+ // CHECK-NEXT: [[C0:%.+]] = "test.constant"() {value = 1
%0 = "test.constant"() {value = 1 : i32} : () -> i32
// CHECK-NEXT: [[V0:%.+]] = "test.op_s"([[C0]])
// CHECK-LABEL: testConstOpReplaced
func @testConstOpReplaced() -> (i32) {
- // CHECK-NEXT: [[C0:%.+]] = constant 1
+ // CHECK-NEXT: [[C0:%.+]] = "test.constant"() {value = 1
%0 = "test.constant"() {value = 1 : i32} : () -> i32
%1 = "test.constant"() {value = 2 : i32} : () -> i32
// CHECK-LABEL: testConstOpMatchFailure
func @testConstOpMatchFailure() -> (i64) {
- // CHECK-DAG: [[C0:%.+]] = constant 1
+ // CHECK-DAG: [[C0:%.+]] = "test.constant"() {value = 1
%0 = "test.constant"() {value = 1 : i64} : () -> i64
- // CHECK-DAG: [[C1:%.+]] = constant 2
+ // CHECK-DAG: [[C1:%.+]] = "test.constant"() {value = 2
%1 = "test.constant"() {value = 2 : i64} : () -> i64
// CHECK: [[V0:%.+]] = "test.op_r"([[C0]], [[C1]])
// CHECK-LABEL: testConstOpMatchNonConst
func @testConstOpMatchNonConst(%arg0 : i32) -> (i32) {
- // CHECK-DAG: [[C0:%.+]] = constant 1
+ // CHECK-DAG: [[C0:%.+]] = "test.constant"() {value = 1
%0 = "test.constant"() {value = 1 : i32} : () -> i32
// CHECK: [[V0:%.+]] = "test.op_r"([[C0]], %arg0)