Skip to content

Commit c61d828

Browse files
author
Simon Camphausen
committed
Fix tests
1 parent 349cd62 commit c61d828

File tree

7 files changed

+66
-40
lines changed

7 files changed

+66
-40
lines changed

mlir/include/mlir/Dialect/EmitC/IR/EmitC.td

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,11 +1263,22 @@ def EmitC_SubscriptOp : EmitC_Op<"subscript", []> {
12631263

12641264
let builders = [
12651265
OpBuilder<(ins "TypedValue<ArrayType>":$array, "ValueRange":$indices), [{
1266-
build($_builder, $_state, array.getType().getElementType(), array, indices);
1266+
build(
1267+
$_builder,
1268+
$_state,
1269+
emitc::LValueType::get(array.getType().getElementType()),
1270+
array,
1271+
indices
1272+
);
12671273
}]>,
12681274
OpBuilder<(ins "TypedValue<PointerType>":$pointer, "Value":$index), [{
1269-
build($_builder, $_state, pointer.getType().getPointee(), pointer,
1270-
ValueRange{index});
1275+
build(
1276+
$_builder,
1277+
$_state,
1278+
emitc::LValueType::get(pointer.getType().getPointee()),
1279+
pointer,
1280+
ValueRange{index}
1281+
);
12711282
}]>
12721283
];
12731284

mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitC.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,12 @@ struct ConvertStore final : public OpConversionPattern<memref::StoreOp> {
158158

159159
auto subscript = rewriter.create<emitc::SubscriptOp>(
160160
op.getLoc(), arrayValue, operands.getIndices());
161-
162-
rewriter.replaceOpWithNewOp<emitc::AssignOp>(op, subscript,
161+
162+
subscript.dump();
163+
subscript.getResult().dump();
164+
operands.getValue().dump();
165+
166+
rewriter.replaceOpWithNewOp<emitc::AssignOp>(op, subscript.getResult(),
163167
operands.getValue());
164168
return success();
165169
}

mlir/lib/Dialect/EmitC/IR/EmitC.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,23 +206,18 @@ LogicalResult ApplyOp::verify() {
206206
/// The assign op requires that the assigned value's type matches the
207207
/// assigned-to variable type.
208208
LogicalResult emitc::AssignOp::verify() {
209-
Value variable = getVar();
209+
TypedValue<emitc::LValueType> variable = getVar();
210210

211211
if (!variable.getDefiningOp())
212212
return emitOpError() << "cannot assign to block argument";
213-
if (!llvm::isa<emitc::LValueType>(variable.getType()))
214-
return emitOpError() << "requires first operand (" << variable
215-
<< ") to be an lvalue";
216213

217214
Type valueType = getValue().getType();
218-
Type variableType = variable.getType().cast<emitc::LValueType>().getValue();
215+
Type variableType = variable.getType().getValue();
219216
if (variableType != valueType)
220217
return emitOpError() << "requires value's type (" << valueType
221218
<< ") to match variable's type (" << variableType
222219
<< ")\n variable: " << variable
223220
<< "\n value: " << getValue() << "\n";
224-
if (isa<ArrayType>(variableType))
225-
return emitOpError() << "cannot assign to array type";
226221
return success();
227222
}
228223

@@ -1021,9 +1016,13 @@ emitc::ArrayType::cloneWith(std::optional<ArrayRef<int64_t>> shape,
10211016
LogicalResult mlir::emitc::LValueType::verify(
10221017
llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
10231018
mlir::Type value) {
1019+
if (llvm::isa<emitc::ArrayType>(value)) {
1020+
return emitError()
1021+
<< "!emitc.lvalue cannot wrap !emitc.array type";
1022+
}
10241023
if (llvm::isa<emitc::LValueType>(value)) {
10251024
return emitError()
1026-
<< "!emitc.lvalue type cannot be nested inside another type";
1025+
<< "!emitc.lvalue types cannot be nested";
10271026
}
10281027
return success();
10291028
}

mlir/test/Conversion/MemRefToEmitC/memref-to-emitc.mlir

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
// CHECK-LABEL: memref_store
44
// CHECK-SAME: %[[v:.*]]: f32, %[[i:.*]]: index, %[[j:.*]]: index
55
func.func @memref_store(%v : f32, %i: index, %j: index) {
6-
// CHECK: %[[ALLOCA:.*]] = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.array<4x8xf32>
6+
// CHECK-NEXT: %[[ALLOCA:.*]] = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.array<4x8xf32>
77
%0 = memref.alloca() : memref<4x8xf32>
88

9-
// CHECK: %[[SUBSCRIPT:.*]] = emitc.subscript %[[ALLOCA]][%[[i]], %[[j]]] : (!emitc.array<4x8xf32>, index, index) -> f32
10-
// CHECK: emitc.assign %[[v]] : f32 to %[[SUBSCRIPT:.*]] : f32
9+
// CHECK-NEXT: %[[SUBSCRIPT:.*]] = emitc.subscript %[[ALLOCA]][%[[i]], %[[j]]] : (!emitc.array<4x8xf32>, index, index) -> !emitc.lvalue<f32>
10+
// CHECK-NEXT: emitc.assign %[[v]] : f32 to %[[SUBSCRIPT]] : <f32>
1111
memref.store %v, %0[%i, %j] : memref<4x8xf32>
1212
return
1313
}
@@ -17,14 +17,13 @@ func.func @memref_store(%v : f32, %i: index, %j: index) {
1717
// CHECK-LABEL: memref_load
1818
// CHECK-SAME: %[[i:.*]]: index, %[[j:.*]]: index
1919
func.func @memref_load(%i: index, %j: index) -> f32 {
20-
// CHECK: %[[ALLOCA:.*]] = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.array<4x8xf32>
20+
// CHECK-NEXT: %[[ALLOCA:.*]] = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.array<4x8xf32>
2121
%0 = memref.alloca() : memref<4x8xf32>
2222

23-
// CHECK: %[[LOAD:.*]] = emitc.subscript %[[ALLOCA]][%[[i]], %[[j]]] : (!emitc.array<4x8xf32>, index, index) -> f32
24-
// CHECK: %[[VAR:.*]] = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> f32
25-
// CHECK: emitc.assign %[[LOAD]] : f32 to %[[VAR]] : f32
23+
// CHECK-NEXT: %[[SUBSCRIPT:.*]] = emitc.subscript %[[ALLOCA]][%[[i]], %[[j]]] : (!emitc.array<4x8xf32>, index, index) -> !emitc.lvalue<f32>
24+
// CHECK-NEXT: %[[LOAD:.*]] = emitc.lvalue_load %[[SUBSCRIPT]] : <f32>
2625
%1 = memref.load %0[%i, %j] : memref<4x8xf32>
27-
// CHECK: return %[[VAR]] : f32
26+
// CHECK-NEXT: return %[[LOAD]] : f32
2827
return %1 : f32
2928
}
3029

@@ -33,14 +32,15 @@ func.func @memref_load(%i: index, %j: index) -> f32 {
3332
// CHECK-LABEL: globals
3433
module @globals {
3534
memref.global "private" constant @internal_global : memref<3x7xf32> = dense<4.0>
36-
// CHECK: emitc.global static const @internal_global : !emitc.array<3x7xf32> = dense<4.000000e+00>
35+
// CHECK-NEXT: emitc.global static const @internal_global : !emitc.array<3x7xf32> = dense<4.000000e+00>
3736
memref.global @public_global : memref<3x7xf32>
38-
// CHECK: emitc.global extern @public_global : !emitc.array<3x7xf32>
37+
// CHECK-NEXT: emitc.global extern @public_global : !emitc.array<3x7xf32>
3938
memref.global @uninitialized_global : memref<3x7xf32> = uninitialized
40-
// CHECK: emitc.global extern @uninitialized_global : !emitc.array<3x7xf32>
39+
// CHECK-NEXT: emitc.global extern @uninitialized_global : !emitc.array<3x7xf32>
4140

41+
// CHECK-LABEL: use_global
4242
func.func @use_global() {
43-
// CHECK: emitc.get_global @public_global : !emitc.array<3x7xf32>
43+
// CHECK-NEXT: emitc.get_global @public_global : !emitc.array<3x7xf32>
4444
%0 = memref.get_global @public_global : memref<3x7xf32>
4545
return
4646
}

mlir/test/Dialect/EmitC/invalid_ops.mlir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ func.func @test_assign_type_mismatch(%arg1: f32) {
252252
// -----
253253

254254
func.func @test_assign_to_array(%arg1: !emitc.array<4xi32>) {
255-
%v = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<!emitc.array<4xi32>>
256-
// expected-error @+1 {{'emitc.assign' op cannot assign to array type}}
257-
emitc.assign %arg1 : !emitc.array<4xi32> to %v : !emitc.lvalue<!emitc.array<4xi32>>
255+
%v = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.array<4xi32>
256+
// expected-error @+1 {{invalid kind of Type specified}}
257+
emitc.assign %arg1 : !emitc.array<4xi32> to %v : !emitc.array<4xi32>
258258
return
259259
}
260260

mlir/test/Target/Cpp/for.mlir

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,17 @@ func.func @test_for_yield() {
7575
// CPP-DEFAULT-NEXT: [[SI:[^ ]*]] = [[S0]];
7676
// CPP-DEFAULT-NEXT: [[PI:[^ ]*]] = [[P0]];
7777
// CPP-DEFAULT-NEXT: for (size_t [[ITER:[^ ]*]] = [[START]]; [[ITER]] < [[STOP]]; [[ITER]] += [[STEP]]) {
78-
// CPP-DEFAULT-NEXT: int32_t [[SN:[^ ]*]] = add([[SI]], [[ITER]]);
79-
// CPP-DEFAULT-NEXT: float [[PN:[^ ]*]] = mul([[PI]], [[ITER]]);
78+
// CPP-DEFAULT-NEXT: int32_t [[SI_LOAD:[^ ]*]] = [[SI]];
79+
// CPP-DEFAULT-NEXT: int32_t [[SN:[^ ]*]] = add([[SI_LOAD]], [[ITER]]);
80+
// CPP-DEFAULT-NEXT: float [[PI_LOAD:[^ ]*]] = [[PI]];
81+
// CPP-DEFAULT-NEXT: float [[PN:[^ ]*]] = mul([[PI_LOAD]], [[ITER]]);
8082
// CPP-DEFAULT-NEXT: [[SI]] = [[SN]];
8183
// CPP-DEFAULT-NEXT: [[PI]] = [[PN]];
8284
// CPP-DEFAULT-NEXT: }
83-
// CPP-DEFAULT-NEXT: [[SE]] = [[SI]];
84-
// CPP-DEFAULT-NEXT: [[PE]] = [[PI]];
85+
// CPP-DEFAULT-NEXT: int32_t [[SI_LOAD2:[^ ]*]] = [[SI]];
86+
// CPP-DEFAULT-NEXT: [[SE]] = [[SI_LOAD2]];
87+
// CPP-DEFAULT-NEXT: float [[PI_LOAD2:[^ ]*]] = [[PI]];
88+
// CPP-DEFAULT-NEXT: [[PE]] = [[PI_LOAD2]];
8589
// CPP-DEFAULT-NEXT: return;
8690

8791
// CPP-DECLTOP: void test_for_yield() {
@@ -94,8 +98,12 @@ func.func @test_for_yield() {
9498
// CPP-DECLTOP-NEXT: float [[PE:[^ ]*]];
9599
// CPP-DECLTOP-NEXT: int32_t [[SI:[^ ]*]];
96100
// CPP-DECLTOP-NEXT: float [[PI:[^ ]*]];
101+
// CPP-DECLTOP-NEXT: int32_t [[SI_LOAD:[^ ]*]];
97102
// CPP-DECLTOP-NEXT: int32_t [[SN:[^ ]*]];
103+
// CPP-DECLTOP-NEXT: float [[PI_LOAD:[^ ]*]];
98104
// CPP-DECLTOP-NEXT: float [[PN:[^ ]*]];
105+
// CPP-DECLTOP-NEXT: int32_t [[SI_LOAD2:[^ ]*]];
106+
// CPP-DECLTOP-NEXT: float [[PI_LOAD2:[^ ]*]];
99107
// CPP-DECLTOP-NEXT: [[START]] = 0;
100108
// CPP-DECLTOP-NEXT: [[STOP]] = 10;
101109
// CPP-DECLTOP-NEXT: [[STEP]] = 1;
@@ -105,16 +113,20 @@ func.func @test_for_yield() {
105113
// CPP-DECLTOP-NEXT: ;
106114
// CPP-DECLTOP-NEXT: ;
107115
// CPP-DECLTOP-NEXT: ;
108-
// CPP-DECLTOP-NEXT: [[SI:[^ ]*]] = [[S0]];
109-
// CPP-DECLTOP-NEXT: [[PI:[^ ]*]] = [[P0]];
116+
// CPP-DECLTOP-NEXT: [[SI]] = [[S0]];
117+
// CPP-DECLTOP-NEXT: [[PI]] = [[P0]];
110118
// CPP-DECLTOP-NEXT: for (size_t [[ITER:[^ ]*]] = [[START]]; [[ITER]] < [[STOP]]; [[ITER]] += [[STEP]]) {
111-
// CPP-DECLTOP-NEXT: [[SN]] = add([[SI]], [[ITER]]);
112-
// CPP-DECLTOP-NEXT: [[PN]] = mul([[PI]], [[ITER]]);
119+
// CPP-DECLTOP-NEXT: [[SI_LOAD]] = [[SI]];
120+
// CPP-DECLTOP-NEXT: [[SN]] = add([[SI_LOAD]], [[ITER]]);
121+
// CPP-DECLTOP-NEXT: [[PI_LOAD]] = [[PI]];
122+
// CPP-DECLTOP-NEXT: [[PN]] = mul([[PI_LOAD]], [[ITER]]);
113123
// CPP-DECLTOP-NEXT: [[SI]] = [[SN]];
114124
// CPP-DECLTOP-NEXT: [[PI]] = [[PN]];
115125
// CPP-DECLTOP-NEXT: }
116-
// CPP-DECLTOP-NEXT: [[SE]] = [[SI]];
117-
// CPP-DECLTOP-NEXT: [[PE]] = [[PI]];
126+
// CPP-DECLTOP-NEXT: [[SI_LOAD2]] = [[SI]];
127+
// CPP-DECLTOP-NEXT: [[SE]] = [[SI_LOAD2]];
128+
// CPP-DECLTOP-NEXT: [[PI_LOAD2]] = [[PI]];
129+
// CPP-DECLTOP-NEXT: [[PE]] = [[PI_LOAD2]];
118130
// CPP-DECLTOP-NEXT: return;
119131

120132
func.func @test_for_yield_2() {

mlir/test/Target/Cpp/variable.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ func.func @emitc_variable() {
99
%c4 = "emitc.variable"(){value = 255 : ui8} : () -> !emitc.lvalue<ui8>
1010
%c5 = "emitc.variable"(){value = #emitc.opaque<"">} : () -> !emitc.lvalue<!emitc.ptr<i32>>
1111
%c6 = "emitc.variable"(){value = #emitc.opaque<"NULL">} : () -> !emitc.lvalue<!emitc.ptr<i32>>
12-
%c7 = "emitc.variable"(){value = #emitc.opaque<"">} : () -> !emitc.lvalue<!emitc.array<3x7xi32>>
13-
%c8 = "emitc.variable"(){value = #emitc.opaque<"">} : () -> !emitc.lvalue<!emitc.array<5x!emitc.ptr<i8>>>
12+
%c7 = "emitc.variable"(){value = #emitc.opaque<"">} : () -> !emitc.array<3x7xi32>
13+
%c8 = "emitc.variable"(){value = #emitc.opaque<"">} : () -> !emitc.array<5x!emitc.ptr<i8>>
1414
return
1515
}
1616
// CPP-DEFAULT: void emitc_variable() {

0 commit comments

Comments
 (0)