Skip to content

Commit 349cd62

Browse files
author
Simon Camphausen
committed
[wip] lvalue refactor
1 parent 1aadeb3 commit 349cd62

File tree

16 files changed

+208
-142
lines changed

16 files changed

+208
-142
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -835,12 +835,12 @@ def EmitC_LogicalOrOp : EmitC_BinaryOp<"logical_or", [CExpression]> {
835835
let assemblyFormat = "operands attr-dict `:` type(operands)";
836836
}
837837

838-
def EmitC_LValueToRValueOp : EmitC_Op<"lvalue_to_rvalue", [
838+
def EmitC_LValueLoadOp : EmitC_Op<"lvalue_load", [
839839
TypesMatchWith<"result type matches value type of 'operand'",
840840
"operand", "result",
841841
"::llvm::cast<LValueType>($_self).getValue()">
842842
]> {
843-
let summary = "lvalue to rvalue conversion operation";
843+
let summary = "load an lvalue by assigning it to a local variable";
844844
let description = [{}];
845845

846846
let arguments = (ins EmitC_LValueType:$operand);
@@ -1025,7 +1025,7 @@ def EmitC_VariableOp : EmitC_Op<"variable", []> {
10251025
}];
10261026

10271027
let arguments = (ins EmitC_OpaqueOrTypedAttr:$value);
1028-
let results = (outs EmitC_LValueType);
1028+
let results = (outs AnyTypeOf<[EmitC_ArrayType, EmitC_LValueType]>);
10291029

10301030
let hasVerifier = 1;
10311031
}

mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitC.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ struct ConvertAlloca final : public OpConversionPattern<memref::AllocaOp> {
4545
return rewriter.notifyMatchFailure(op.getLoc(), "cannot convert type");
4646
}
4747
auto noInit = emitc::OpaqueAttr::get(getContext(), "");
48+
4849
rewriter.replaceOpWithNewOp<emitc::VariableOp>(op, resultTy, noInit);
50+
4951
return success();
5052
}
5153
};
@@ -137,12 +139,7 @@ struct ConvertLoad final : public OpConversionPattern<memref::LoadOp> {
137139
auto subscript = rewriter.create<emitc::SubscriptOp>(
138140
op.getLoc(), arrayValue, operands.getIndices());
139141

140-
auto noInit = emitc::OpaqueAttr::get(getContext(), "");
141-
auto var =
142-
rewriter.create<emitc::VariableOp>(op.getLoc(), resultTy, noInit);
143-
144-
rewriter.create<emitc::AssignOp>(op.getLoc(), var, subscript);
145-
rewriter.replaceOp(op, var);
142+
rewriter.replaceOpWithNewOp<emitc::LValueLoadOp>(op, resultTy, subscript);
146143
return success();
147144
}
148145
};
@@ -161,6 +158,7 @@ struct ConvertStore final : public OpConversionPattern<memref::StoreOp> {
161158

162159
auto subscript = rewriter.create<emitc::SubscriptOp>(
163160
op.getLoc(), arrayValue, operands.getIndices());
161+
164162
rewriter.replaceOpWithNewOp<emitc::AssignOp>(op, subscript,
165163
operands.getValue());
166164
return success();

mlir/lib/Conversion/SCFToEmitC/SCFToEmitC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static void assignValues(ValueRange values, SmallVector<Value> &variables,
8686

8787
// TODO: Make sure this is safe, as this moves operations with memory
8888
// effects.
89-
if (auto op = dyn_cast_if_present<emitc::LValueToRValueOp>(
89+
if (auto op = dyn_cast_if_present<emitc::LValueLoadOp>(
9090
value.getDefiningOp())) {
9191
rewriter.moveOpBefore(op, assign);
9292
}
@@ -125,7 +125,7 @@ static void replaceUsers(PatternRewriter &rewriter,
125125

126126
rewriter.setInsertionPoint(op);
127127
Value rValue =
128-
rewriter.create<emitc::LValueToRValueOp>(loc, from.getType(), to);
128+
rewriter.create<emitc::LValueLoadOp>(loc, from.getType(), to);
129129
operand.set(rValue);
130130
}
131131
}

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ void mlir::emitc::buildTerminatedBody(OpBuilder &builder, Location loc) {
6161
bool mlir::emitc::isSupportedEmitCType(Type type) {
6262
if (llvm::isa<emitc::OpaqueType>(type))
6363
return true;
64+
if (auto lType = llvm::dyn_cast<emitc::LValueType>(type))
65+
return isSupportedEmitCType(lType.getValue());
6466
if (auto ptrType = llvm::dyn_cast<emitc::PointerType>(type))
6567
return isSupportedEmitCType(ptrType.getPointee());
6668
if (auto arrayType = llvm::dyn_cast<emitc::ArrayType>(type)) {
@@ -779,7 +781,7 @@ LogicalResult emitc::LiteralOp::verify() {
779781
// LValueToRValueOp
780782
//===----------------------------------------------------------------------===//
781783

782-
LogicalResult emitc::LValueToRValueOp::verify() {
784+
LogicalResult emitc::LValueLoadOp::verify() {
783785
Type operandType = getOperand().getType();
784786
Type resultType = getResult().getType();
785787
if (!llvm::isa<emitc::LValueType>(operandType))
@@ -888,9 +890,10 @@ LogicalResult emitc::SubscriptOp::verify() {
888890
}
889891
// Check element type.
890892
Type elementType = arrayType.getElementType();
891-
if (elementType != getType()) {
893+
Type resultType = getType().getValue();
894+
if (elementType != resultType) {
892895
return emitOpError() << "on array operand requires element type ("
893-
<< elementType << ") and result type (" << getType()
896+
<< elementType << ") and result type (" << resultType
894897
<< ") to match";
895898
}
896899
return success();
@@ -914,9 +917,10 @@ LogicalResult emitc::SubscriptOp::verify() {
914917
}
915918
// Check pointee type.
916919
Type pointeeType = pointerType.getPointee();
917-
if (pointeeType != getType()) {
920+
Type resultType = getType().getValue();
921+
if (pointeeType != resultType) {
918922
return emitOpError() << "on pointer operand requires pointee type ("
919-
<< pointeeType << ") and result type (" << getType()
923+
<< pointeeType << ") and result type (" << resultType
920924
<< ") to match";
921925
}
922926
return success();

mlir/lib/Target/Cpp/TranslateToCpp.cpp

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,11 @@ static LogicalResult printOperation(CppEmitter &emitter,
378378
}
379379

380380
static LogicalResult printOperation(CppEmitter &emitter,
381-
emitc::LValueToRValueOp lValueToRValueOp) {
382-
// Add name to cache so that `hasValueInScope` works.
383-
emitter.getOrCreateName(lValueToRValueOp.getResult());
384-
return success();
381+
emitc::LValueLoadOp lValueLoadOp) {
382+
if (failed(emitter.emitAssignPrefix(*lValueLoadOp)))
383+
return failure();
384+
385+
return emitter.emitOperand(lValueLoadOp.getOperand());
385386
}
386387

387388
static LogicalResult printOperation(CppEmitter &emitter,
@@ -961,7 +962,7 @@ static LogicalResult printFunctionBody(CppEmitter &emitter,
961962
// regions.
962963
WalkResult result =
963964
functionOp->walk<WalkOrder::PreOrder>([&](Operation *op) -> WalkResult {
964-
if (isa<emitc::LiteralOp, emitc::LValueToRValueOp>(op) ||
965+
if (isa<emitc::LiteralOp>(op) ||
965966
(isa<emitc::ApplyOp>(op) &&
966967
cast<emitc::ApplyOp>(op).getApplicableOperator() == "*") ||
967968
isa<emitc::ExpressionOp>(op->getParentOp()) ||
@@ -1153,15 +1154,6 @@ std::string CppEmitter::getSubscriptName(emitc::SubscriptOp op) {
11531154
StringRef CppEmitter::getOrCreateName(Value val) {
11541155
if (auto literal = dyn_cast_if_present<emitc::LiteralOp>(val.getDefiningOp()))
11551156
return literal.getValue();
1156-
if (auto lValueToRValue =
1157-
dyn_cast_if_present<emitc::LValueToRValueOp>(val.getDefiningOp())) {
1158-
Value operand = lValueToRValue.getOperand();
1159-
valueMapper.insert(val, "***UNUSED***");
1160-
1161-
assert(hasValueInScope(operand));
1162-
1163-
return getOrCreateName(operand);
1164-
}
11651157
if (!valueMapper.count(val)) {
11661158
if (auto subscript =
11671159
dyn_cast_if_present<emitc::SubscriptOp>(val.getDefiningOp())) {
@@ -1428,7 +1420,7 @@ LogicalResult CppEmitter::emitVariableAssignment(OpResult result) {
14281420

14291421
LogicalResult CppEmitter::emitVariableDeclaration(OpResult result,
14301422
bool trailingSemicolon) {
1431-
if (isa<emitc::SubscriptOp>(result.getDefiningOp()))
1423+
if (isa<emitc::SubscriptOp, emitc::GetGlobalOp>(result.getDefiningOp()))
14321424
return success();
14331425
if (hasValueInScope(result)) {
14341426
return result.getDefiningOp()->emitError(
@@ -1532,11 +1524,11 @@ LogicalResult CppEmitter::emitOperation(Operation &op, bool trailingSemicolon) {
15321524
emitc::ConditionalOp, emitc::ConstantOp, emitc::DeclareFuncOp,
15331525
emitc::DivOp, emitc::ExpressionOp, emitc::ForOp, emitc::FuncOp,
15341526
emitc::GlobalOp, emitc::GetGlobalOp, emitc::IfOp,
1535-
emitc::IncludeOp, emitc::LogicalAndOp,
1536-
emitc::LValueToRValueOp, emitc::LogicalNotOp, emitc::RemOp,
1537-
emitc::LogicalOrOp, emitc::MulOp, emitc::ReturnOp,
1538-
emitc::SubOp, emitc::SubscriptOp, emitc::UnaryMinusOp,
1539-
emitc::UnaryPlusOp, emitc::VariableOp, emitc::VerbatimOp>(
1527+
emitc::IncludeOp, emitc::LogicalAndOp, emitc::LogicalNotOp,
1528+
emitc::LValueLoadOp, emitc::RemOp, emitc::LogicalOrOp,
1529+
emitc::MulOp, emitc::ReturnOp, emitc::SubOp, emitc::SubscriptOp,
1530+
emitc::UnaryMinusOp, emitc::UnaryPlusOp, emitc::VariableOp,
1531+
emitc::VerbatimOp>(
15401532
[&](auto op) { return printOperation(*this, op); })
15411533
// Func ops.
15421534
.Case<func::CallOp, func::FuncOp, func::ReturnOp>(
@@ -1549,7 +1541,8 @@ LogicalResult CppEmitter::emitOperation(Operation &op, bool trailingSemicolon) {
15491541
if (failed(status))
15501542
return failure();
15511543

1552-
if (isa<emitc::LiteralOp, emitc::LValueToRValueOp, emitc::SubscriptOp, emitc::GetGlobalOp>(op))
1544+
if (isa<emitc::LiteralOp, emitc::SubscriptOp,
1545+
emitc::GetGlobalOp>(op))
15531546
return success();
15541547

15551548
if (getEmittedExpression() ||

mlir/test/Conversion/SCFToEmitC/for.mlir

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ func.func @for_yield(%arg0 : index, %arg1 : index, %arg2 : index) -> (f32, f32)
5252
// CHECK-NEXT: emitc.assign %[[VAL_3]] : f32 to %[[VAL_5]] : <f32>
5353
// CHECK-NEXT: emitc.assign %[[VAL_4]] : f32 to %[[VAL_6]] : <f32>
5454
// CHECK-NEXT: emitc.for %[[VAL_7:.*]] = %[[VAL_0]] to %[[VAL_1]] step %[[VAL_2]] {
55-
// CHECK-NEXT: %[[VAL_8:.*]] = emitc.lvalue_to_rvalue %[[VAL_5]] : <f32>
56-
// CHECK-NEXT: %[[VAL_9:.*]] = emitc.lvalue_to_rvalue %[[VAL_6]] : <f32>
55+
// CHECK-NEXT: %[[VAL_8:.*]] = emitc.lvalue_load %[[VAL_5]] : <f32>
56+
// CHECK-NEXT: %[[VAL_9:.*]] = emitc.lvalue_load %[[VAL_6]] : <f32>
5757
// CHECK-NEXT: %[[VAL_10:.*]] = arith.addf %[[VAL_8]], %[[VAL_9]] : f32
5858
// CHECK-NEXT: emitc.assign %[[VAL_10]] : f32 to %[[VAL_5]] : <f32>
5959
// CHECK-NEXT: emitc.assign %[[VAL_10]] : f32 to %[[VAL_6]] : <f32>
6060
// CHECK-NEXT: }
61-
// CHECK-NEXT: %[[VAL_11:.*]] = emitc.lvalue_to_rvalue %[[VAL_5]] : <f32>
62-
// CHECK-NEXT: %[[VAL_12:.*]] = emitc.lvalue_to_rvalue %[[VAL_6]] : <f32>
61+
// CHECK-NEXT: %[[VAL_11:.*]] = emitc.lvalue_load %[[VAL_5]] : <f32>
62+
// CHECK-NEXT: %[[VAL_12:.*]] = emitc.lvalue_load %[[VAL_6]] : <f32>
6363
// CHECK-NEXT: return %[[VAL_11]], %[[VAL_12]] : f32, f32
6464
// CHECK-NEXT: }
6565

@@ -81,17 +81,17 @@ func.func @nested_for_yield(%arg0 : index, %arg1 : index, %arg2 : index) -> f32
8181
// CHECK-NEXT: emitc.assign %[[VAL_3]] : f32 to %[[VAL_4]] : <f32>
8282
// CHECK-NEXT: emitc.for %[[VAL_5:.*]] = %[[VAL_0]] to %[[VAL_1]] step %[[VAL_2]] {
8383
// CHECK-NEXT: %[[VAL_6:.*]] = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<f32>
84-
// CHECK-NEXT: %[[VAL_7:.*]] = emitc.lvalue_to_rvalue %[[VAL_4]] : <f32>
84+
// CHECK-NEXT: %[[VAL_7:.*]] = emitc.lvalue_load %[[VAL_4]] : <f32>
8585
// CHECK-NEXT: emitc.assign %[[VAL_7]] : f32 to %[[VAL_6]] : <f32>
8686
// CHECK-NEXT: emitc.for %[[VAL_8:.*]] = %[[VAL_0]] to %[[VAL_1]] step %[[VAL_2]] {
87-
// CHECK-NEXT: %[[VAL_9:.*]] = emitc.lvalue_to_rvalue %[[VAL_6]] : <f32>
88-
// CHECK-NEXT: %[[VAL_10:.*]] = emitc.lvalue_to_rvalue %[[VAL_6]] : <f32>
87+
// CHECK-NEXT: %[[VAL_9:.*]] = emitc.lvalue_load %[[VAL_6]] : <f32>
88+
// CHECK-NEXT: %[[VAL_10:.*]] = emitc.lvalue_load %[[VAL_6]] : <f32>
8989
// CHECK-NEXT: %[[VAL_11:.*]] = arith.addf %[[VAL_10]], %[[VAL_9]] : f32
9090
// CHECK-NEXT: emitc.assign %[[VAL_11]] : f32 to %[[VAL_6]] : <f32>
9191
// CHECK-NEXT: }
92-
// CHECK-NEXT: %[[VAL_12:.*]] = emitc.lvalue_to_rvalue %[[VAL_6]] : <f32>
92+
// CHECK-NEXT: %[[VAL_12:.*]] = emitc.lvalue_load %[[VAL_6]] : <f32>
9393
// CHECK-NEXT: emitc.assign %[[VAL_12]] : f32 to %[[VAL_4]] : <f32>
9494
// CHECK-NEXT: }
95-
// CHECK-NEXT: %[[VAL_13:.*]] = emitc.lvalue_to_rvalue %[[VAL_4]] : <f32>
95+
// CHECK-NEXT: %[[VAL_13:.*]] = emitc.lvalue_load %[[VAL_4]] : <f32>
9696
// CHECK-NEXT: return %[[VAL_13]] : f32
9797
// CHECK-NEXT: }

mlir/test/Conversion/SCFToEmitC/if.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func.func @test_if_yield(%arg0: i1, %arg1: f32) -> (i32, f64) {
6666
// CHECK-NEXT: emitc.assign %[[VAL_7]] : i32 to %[[VAL_3]] : <i32>
6767
// CHECK-NEXT: emitc.assign %[[VAL_8]] : f64 to %[[VAL_4]] : <f64>
6868
// CHECK-NEXT: }
69-
// CHECK-NEXT: %[[VAL_9:.*]] = emitc.lvalue_to_rvalue %[[VAL_3]] : <i32>
70-
// CHECK-NEXT: %[[VAL_10:.*]] = emitc.lvalue_to_rvalue %[[VAL_4]] : <f64>
69+
// CHECK-NEXT: %[[VAL_9:.*]] = emitc.lvalue_load %[[VAL_3]] : <i32>
70+
// CHECK-NEXT: %[[VAL_10:.*]] = emitc.lvalue_load %[[VAL_4]] : <f64>
7171
// CHECK-NEXT: return %[[VAL_9]], %[[VAL_10]] : i32, f64
7272
// CHECK-NEXT: }

mlir/test/Dialect/EmitC/invalid_ops.mlir

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,47 +392,47 @@ func.func @logical_or_resulterror(%arg0: i32, %arg1: i32) {
392392

393393
func.func @test_subscript_array_indices_mismatch(%arg0: !emitc.array<4x8xf32>, %arg1: index) {
394394
// expected-error @+1 {{'emitc.subscript' op on array operand requires number of indices (1) to match the rank of the array type (2)}}
395-
%0 = emitc.subscript %arg0[%arg1] : (!emitc.array<4x8xf32>, index) -> f32
395+
%0 = emitc.subscript %arg0[%arg1] : (!emitc.array<4x8xf32>, index) -> !emitc.lvalue<f32>
396396
return
397397
}
398398

399399
// -----
400400

401401
func.func @test_subscript_array_index_type_mismatch(%arg0: !emitc.array<4x8xf32>, %arg1: index, %arg2: f32) {
402402
// expected-error @+1 {{'emitc.subscript' op on array operand requires index operand 1 to be integer-like, but got 'f32'}}
403-
%0 = emitc.subscript %arg0[%arg1, %arg2] : (!emitc.array<4x8xf32>, index, f32) -> f32
403+
%0 = emitc.subscript %arg0[%arg1, %arg2] : (!emitc.array<4x8xf32>, index, f32) -> !emitc.lvalue<f32>
404404
return
405405
}
406406

407407
// -----
408408

409409
func.func @test_subscript_array_type_mismatch(%arg0: !emitc.array<4x8xf32>, %arg1: index, %arg2: index) {
410410
// expected-error @+1 {{'emitc.subscript' op on array operand requires element type ('f32') and result type ('i32') to match}}
411-
%0 = emitc.subscript %arg0[%arg1, %arg2] : (!emitc.array<4x8xf32>, index, index) -> i32
411+
%0 = emitc.subscript %arg0[%arg1, %arg2] : (!emitc.array<4x8xf32>, index, index) -> !emitc.lvalue<i32>
412412
return
413413
}
414414

415415
// -----
416416

417417
func.func @test_subscript_ptr_indices_mismatch(%arg0: !emitc.ptr<f32>, %arg1: index) {
418418
// expected-error @+1 {{'emitc.subscript' op on pointer operand requires one index operand, but got 2}}
419-
%0 = emitc.subscript %arg0[%arg1, %arg1] : (!emitc.ptr<f32>, index, index) -> f32
419+
%0 = emitc.subscript %arg0[%arg1, %arg1] : (!emitc.ptr<f32>, index, index) -> !emitc.lvalue<f32>
420420
return
421421
}
422422

423423
// -----
424424

425425
func.func @test_subscript_ptr_index_type_mismatch(%arg0: !emitc.ptr<f32>, %arg1: f64) {
426426
// expected-error @+1 {{'emitc.subscript' op on pointer operand requires index operand to be integer-like, but got 'f64'}}
427-
%0 = emitc.subscript %arg0[%arg1] : (!emitc.ptr<f32>, f64) -> f32
427+
%0 = emitc.subscript %arg0[%arg1] : (!emitc.ptr<f32>, f64) -> !emitc.lvalue<f32>
428428
return
429429
}
430430

431431
// -----
432432

433433
func.func @test_subscript_ptr_type_mismatch(%arg0: !emitc.ptr<f32>, %arg1: index) {
434434
// expected-error @+1 {{'emitc.subscript' op on pointer operand requires pointee type ('f32') and result type ('f64') to match}}
435-
%0 = emitc.subscript %arg0[%arg1] : (!emitc.ptr<f32>, index) -> f64
435+
%0 = emitc.subscript %arg0[%arg1] : (!emitc.ptr<f32>, index) -> !emitc.lvalue<f64>
436436
return
437437
}
438438

mlir/test/Dialect/EmitC/invalid_types.mlir

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,47 +101,47 @@ func.func @illegal_float_type(%arg0: f80, %arg1: f80) {
101101
// -----
102102

103103
func.func @illegal_pointee_type() {
104-
// expected-error @+1 {{'emitc.variable' op result #0 must be type supported by EmitC, but got '!emitc.ptr<i11>'}}
105-
%v = "emitc.variable"(){value = #emitc.opaque<"">} : () -> !emitc.ptr<i11>
104+
// expected-error @+1 {{'emitc.constant' op result #0 must be type supported by EmitC, but got '!emitc.ptr<i11>'}}
105+
%v = "emitc.constant"(){value = #emitc.opaque<"">} : () -> !emitc.ptr<i11>
106106
return
107107
}
108108

109109
// -----
110110

111111
func.func @illegal_non_static_tensor_shape_type() {
112-
// expected-error @+1 {{'emitc.variable' op result #0 must be type supported by EmitC, but got 'tensor<?xf32>'}}
113-
%v = "emitc.variable"(){value = #emitc.opaque<"">} : () -> tensor<?xf32>
112+
// expected-error @+1 {{'emitc.constant' op result #0 must be type supported by EmitC, but got 'tensor<?xf32>'}}
113+
%v = "emitc.constant"(){value = #emitc.opaque<"">} : () -> tensor<?xf32>
114114
return
115115
}
116116

117117
// -----
118118

119119
func.func @illegal_tensor_array_element_type() {
120-
// expected-error @+1 {{'emitc.variable' op result #0 must be type supported by EmitC, but got 'tensor<!emitc.array<9xi16>>'}}
121-
%v = "emitc.variable"(){value = #emitc.opaque<"">} : () -> tensor<!emitc.array<9xi16>>
120+
// expected-error @+1 {{'emitc.constant' op result #0 must be type supported by EmitC, but got 'tensor<!emitc.array<9xi16>>'}}
121+
%v = "emitc.constant"(){value = #emitc.opaque<"">} : () -> tensor<!emitc.array<9xi16>>
122122
return
123123
}
124124

125125
// -----
126126

127127
func.func @illegal_tensor_integer_element_type() {
128-
// expected-error @+1 {{'emitc.variable' op result #0 must be type supported by EmitC, but got 'tensor<9xi11>'}}
129-
%v = "emitc.variable"(){value = #emitc.opaque<"">} : () -> tensor<9xi11>
128+
// expected-error @+1 {{'emitc.constant' op result #0 must be type supported by EmitC, but got 'tensor<9xi11>'}}
129+
%v = "emitc.constant"(){value = #emitc.opaque<"">} : () -> tensor<9xi11>
130130
return
131131
}
132132

133133
// -----
134134

135135
func.func @illegal_tuple_array_element_type() {
136-
// expected-error @+1 {{'emitc.variable' op result #0 must be type supported by EmitC, but got 'tuple<!emitc.array<9xf32>, f32>'}}
137-
%v = "emitc.variable"(){value = #emitc.opaque<"">} : () -> tuple<!emitc.array<9xf32>, f32>
136+
// expected-error @+1 {{'emitc.constant' op result #0 must be type supported by EmitC, but got 'tuple<!emitc.array<9xf32>, f32>'}}
137+
%v = "emitc.constant"(){value = #emitc.opaque<"">} : () -> tuple<!emitc.array<9xf32>, f32>
138138
return
139139
}
140140

141141
// -----
142142

143143
func.func @illegal_tuple_float_element_type() {
144-
// expected-error @+1 {{'emitc.variable' op result #0 must be type supported by EmitC, but got 'tuple<i32, f80>'}}
145-
%v = "emitc.variable"(){value = #emitc.opaque<"">} : () -> tuple<i32, f80>
144+
// expected-error @+1 {{'emitc.constant' op result #0 must be type supported by EmitC, but got 'tuple<i32, f80>'}}
145+
%v = "emitc.constant"(){value = #emitc.opaque<"">} : () -> tuple<i32, f80>
146146
return
147147
}

mlir/test/Dialect/EmitC/ops.mlir

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ func.func @test_for_not_index_induction(%arg0 : i16, %arg1 : i16, %arg2 : i16) {
215215
}
216216

217217
func.func @test_subscript(%arg0 : !emitc.array<2x3xf32>, %arg1 : !emitc.ptr<i32>, %arg2 : !emitc.opaque<"std::map<char, int>">, %idx0 : index, %idx1 : i32, %idx2 : !emitc.opaque<"char">) {
218-
%0 = emitc.subscript %arg0[%idx0, %idx1] : (!emitc.array<2x3xf32>, index, i32) -> f32
219-
%1 = emitc.subscript %arg1[%idx0] : (!emitc.ptr<i32>, index) -> i32
220-
%2 = emitc.subscript %arg2[%idx2] : (!emitc.opaque<"std::map<char, int>">, !emitc.opaque<"char">) -> !emitc.opaque<"int">
218+
%0 = emitc.subscript %arg0[%idx0, %idx1] : (!emitc.array<2x3xf32>, index, i32) -> !emitc.lvalue<f32>
219+
%1 = emitc.subscript %arg1[%idx0] : (!emitc.ptr<i32>, index) -> !emitc.lvalue<i32>
220+
%2 = emitc.subscript %arg2[%idx2] : (!emitc.opaque<"std::map<char, int>">, !emitc.opaque<"char">) -> !emitc.lvalue<!emitc.opaque<"int">>
221221
return
222222
}
223223

@@ -242,6 +242,7 @@ emitc.global const @myconstant : !emitc.array<2xi16> = dense<2>
242242

243243
func.func @use_global(%i: index) -> f32 {
244244
%0 = emitc.get_global @myglobal : !emitc.array<2xf32>
245-
%1 = emitc.subscript %0[%i] : (!emitc.array<2xf32>, index) -> f32
246-
return %1 : f32
245+
%1 = emitc.subscript %0[%i] : (!emitc.array<2xf32>, index) -> !emitc.lvalue<f32>
246+
%2 = emitc.lvalue_load %1 : <f32>
247+
return %2 : f32
247248
}

mlir/test/Target/Cpp/common-cpp.mlir

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@ func.func @apply(%arg0: i32) -> !emitc.ptr<i32> {
8686
// CHECK: int32_t* [[V2]] = &[[V1]];
8787
%0 = emitc.apply "&"(%arg0) : (i32) -> !emitc.ptr<i32>
8888
// CHECK: int32_t [[V3]];
89-
// CHECK: [[V3]] = *[[V2]];
90-
%1 = emitc.apply "*"(%0) : (!emitc.ptr<i32>) -> (!emitc.lvalue<i32>)
9189
%2 = "emitc.variable"() {value = #emitc.opaque<"">} : () -> !emitc.lvalue<i32>
92-
%3 = emitc.lvalue_to_rvalue %1 : !emitc.lvalue<i32>
90+
%1 = emitc.apply "*"(%0) : (!emitc.ptr<i32>) -> (!emitc.lvalue<i32>)
91+
%3 = emitc.lvalue_load %1 : !emitc.lvalue<i32>
92+
// CHECK: int32_t [[V4]] = *[[V2]];
93+
// CHECK: [[V3]] = [[V4]];
9394
emitc.assign %3 : i32 to %2 : !emitc.lvalue<i32>
9495
return %0 : !emitc.ptr<i32>
9596
}

0 commit comments

Comments
 (0)