Skip to content

Commit 448713e

Browse files
committed
[mlir][emitc] Add address-of and dereference ops
EmitC currently models C's `&` and `*` operators via its `apply` op, which has several drawbacks: - Representing multiple opcodes (selected by an attribute) in a single op complicates the code by adding a second, attribute-based selection layer on top of MLIR's standard isa<> mechanism. - Its pre-lvalue semantics combines dereferencing with memory access and allows taking the address of SSA values. This patch adds two distinct ops to model these C operators. These ops are lvalue-based and therefore don't incur any side-effects. EmitC passes were converted to use the new ops instead of `apply` which is now deprecated, to be retired in the future.
1 parent 5613e4a commit 448713e

File tree

12 files changed

+214
-26
lines changed

12 files changed

+214
-26
lines changed

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

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,37 @@ def EmitC_FileOp
116116
let skipDefaultBuilders = 1;
117117
}
118118

119+
def EmitC_AddressOfOp : EmitC_Op<"address_of", [
120+
CExpressionInterface,
121+
TypesMatchWith<"input and result reference the same type", "reference", "result",
122+
"emitc::PointerType::get(::llvm::cast<emitc::LValueType>($_self).getValueType())">
123+
]> {
124+
let summary = "Address operation";
125+
let description = [{
126+
This operation models the C & (address of) operator for a single operand,
127+
which must be an emitc.lvalue, and returns an emitc pointer to its location.
128+
129+
Example:
130+
131+
```mlir
132+
// Custom form of applying the & operator.
133+
%0 = emitc.address_of %arg0 : (!emitc.lvalue<i32>) -> !emitc.ptr<i32>
134+
```
135+
}];
136+
let arguments = (ins EmitC_LValueType:$reference);
137+
let results = (outs EmitC_PointerType:$result);
138+
let assemblyFormat = [{
139+
$reference `:` qualified(type($reference)) attr-dict
140+
}];
141+
let hasVerifier = 1;
142+
143+
let extraClassDeclaration = [{
144+
bool hasSideEffects() {
145+
return false;
146+
}
147+
}];
148+
}
149+
119150
def EmitC_AddOp : EmitC_BinaryOp<"add", []> {
120151
let summary = "Addition operation";
121152
let description = [{
@@ -140,7 +171,7 @@ def EmitC_AddOp : EmitC_BinaryOp<"add", []> {
140171
}
141172

142173
def EmitC_ApplyOp : EmitC_Op<"apply", [CExpressionInterface]> {
143-
let summary = "Apply operation";
174+
let summary = "Deprecated (use address_of/dereference)";
144175
let description = [{
145176
With the `emitc.apply` operation the operators & (address of) and * (contents of)
146177
can be applied to a single operand.
@@ -439,6 +470,31 @@ def EmitC_ConstantOp
439470
}];
440471
}
441472

473+
def EmitC_DereferenceOp : EmitC_Op<"dereference", [
474+
TypesMatchWith<"input and result reference the same type", "pointer", "result",
475+
"emitc::LValueType::get(::llvm::cast<emitc::PointerType>($_self).getPointee())">
476+
]> {
477+
let summary = "Dereference operation";
478+
let description = [{
479+
This operation models the C * (dereference) operator, which must be of
480+
!emitc.ptr<> type, returning an !emitc.lvalue<> the value pointed to by the
481+
pointer.
482+
483+
Example:
484+
485+
```mlir
486+
// Custom form of the dereference operator.
487+
%0 = emitc.dereference %arg0 : (!emitc.ptr<i32>) -> !emitc.lvalue<i32>
488+
```
489+
}];
490+
let arguments = (ins EmitC_PointerType:$pointer);
491+
let results = (outs EmitC_LValueType:$result);
492+
let assemblyFormat = [{
493+
$pointer `:` qualified(type($pointer)) attr-dict
494+
}];
495+
let hasVerifier = 1;
496+
}
497+
442498
def EmitC_DivOp : EmitC_BinaryOp<"div", []> {
443499
let summary = "Division operation";
444500
let description = [{

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,19 @@ class EmitC_LValueOf<list<Type> allowedTypes> :
185185
"::mlir::emitc::LValueType"
186186
>;
187187

188+
class EmitC_TypesMatchOnElementType<
189+
string summary, string lhsArg, string rhsArg, string transformL, string transformR,
190+
string comparator = "std::equal_to<>()"
191+
> : PredOpTrait<summary, CPred<comparator # "(" #
192+
!subst("$_self", "$" # lhsArg # ".getType()", transformL) #
193+
", " #
194+
!subst("$_self", "$" # rhsArg # ".getType()", transformL) #
195+
")">
196+
> {
197+
string lhs = lhsArg;
198+
string rhs = rhsArg;
199+
string transformerL = transformL;
200+
string transformerR = transformR;
201+
}
202+
188203
#endif // MLIR_DIALECT_EMITC_IR_EMITCTYPES

mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitC.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static Value calculateMemrefTotalSizeBytes(Location loc, MemRefType memrefType,
122122
return totalSizeBytes.getResult();
123123
}
124124

125-
static emitc::ApplyOp
125+
static emitc::AddressOfOp
126126
createPointerFromEmitcArray(Location loc, OpBuilder &builder,
127127
TypedValue<emitc::ArrayType> arrayValue) {
128128

@@ -133,9 +133,9 @@ createPointerFromEmitcArray(Location loc, OpBuilder &builder,
133133
llvm::SmallVector<mlir::Value> indices(arrayType.getRank(), zeroIndex);
134134
emitc::SubscriptOp subPtr =
135135
emitc::SubscriptOp::create(builder, loc, arrayValue, ValueRange(indices));
136-
emitc::ApplyOp ptr = emitc::ApplyOp::create(
136+
emitc::AddressOfOp ptr = emitc::AddressOfOp::create(
137137
builder, loc, emitc::PointerType::get(arrayType.getElementType()),
138-
builder.getStringAttr("&"), subPtr);
138+
subPtr);
139139

140140
return ptr;
141141
}
@@ -225,12 +225,12 @@ struct ConvertCopy final : public OpConversionPattern<memref::CopyOp> {
225225

226226
auto srcArrayValue =
227227
cast<TypedValue<emitc::ArrayType>>(operands.getSource());
228-
emitc::ApplyOp srcPtr =
228+
emitc::AddressOfOp srcPtr =
229229
createPointerFromEmitcArray(loc, rewriter, srcArrayValue);
230230

231231
auto targetArrayValue =
232232
cast<TypedValue<emitc::ArrayType>>(operands.getTarget());
233-
emitc::ApplyOp targetPtr =
233+
emitc::AddressOfOp targetPtr =
234234
createPointerFromEmitcArray(loc, rewriter, targetArrayValue);
235235

236236
emitc::CallOpaqueOp memCpyCall = emitc::CallOpaqueOp::create(
@@ -319,8 +319,8 @@ struct ConvertGetGlobal final
319319
emitc::GetGlobalOp globalLValue = emitc::GetGlobalOp::create(
320320
rewriter, op.getLoc(), lvalueType, operands.getNameAttr());
321321
emitc::PointerType pointerType = emitc::PointerType::get(resultTy);
322-
rewriter.replaceOpWithNewOp<emitc::ApplyOp>(
323-
op, pointerType, rewriter.getStringAttr("&"), globalLValue);
322+
rewriter.replaceOpWithNewOp<emitc::AddressOfOp>(op, pointerType,
323+
globalLValue);
324324
return success();
325325
}
326326
rewriter.replaceOpWithNewOp<emitc::GetGlobalOp>(op, resultTy,

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,21 @@ FailureOr<SmallVector<ReplacementItem>> parseFormatString(
225225
return items;
226226
}
227227

228+
//===----------------------------------------------------------------------===//
229+
// AddressOfOp
230+
//===----------------------------------------------------------------------===//
231+
232+
LogicalResult AddressOfOp::verify() {
233+
emitc::LValueType referenceType = getReference().getType();
234+
emitc::PointerType resultType = getResult().getType();
235+
236+
if (referenceType.getValueType() != resultType.getPointee())
237+
return emitOpError("requires result to be a pointer to the type "
238+
"referenced by operand");
239+
240+
return success();
241+
}
242+
228243
//===----------------------------------------------------------------------===//
229244
// AddOp
230245
//===----------------------------------------------------------------------===//
@@ -379,6 +394,20 @@ LogicalResult emitc::ConstantOp::verify() {
379394

380395
OpFoldResult emitc::ConstantOp::fold(FoldAdaptor adaptor) { return getValue(); }
381396

397+
//===----------------------------------------------------------------------===//
398+
// DereferenceOp
399+
//===----------------------------------------------------------------------===//
400+
401+
LogicalResult DereferenceOp::verify() {
402+
emitc::PointerType pointerType = getPointer().getType();
403+
404+
if (pointerType.getPointee() != getResult().getType().getValueType())
405+
return emitOpError("requires result to be an lvalue of the type "
406+
"pointed to by operand");
407+
408+
return success();
409+
}
410+
382411
//===----------------------------------------------------------------------===//
383412
// ExpressionOp
384413
//===----------------------------------------------------------------------===//

mlir/lib/Target/Cpp/TranslateToCpp.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static inline LogicalResult interleaveCommaWithError(const Container &c,
7070
/// imply higher precedence.
7171
static FailureOr<int> getOperatorPrecedence(Operation *operation) {
7272
return llvm::TypeSwitch<Operation *, FailureOr<int>>(operation)
73+
.Case<emitc::AddressOfOp>([&](auto op) { return 15; })
7374
.Case<emitc::AddOp>([&](auto op) { return 12; })
7475
.Case<emitc::ApplyOp>([&](auto op) { return 15; })
7576
.Case<emitc::BitwiseAndOp>([&](auto op) { return 7; })
@@ -393,6 +394,15 @@ static bool shouldBeInlined(ExpressionOp expressionOp) {
393394
return false;
394395
}
395396

397+
static LogicalResult printOperation(CppEmitter &emitter,
398+
emitc::DereferenceOp dereferenceOp) {
399+
std::string out;
400+
llvm::raw_string_ostream ss(out);
401+
ss << "*" << emitter.getOrCreateName(dereferenceOp.getPointer());
402+
emitter.cacheDeferredOpResult(dereferenceOp.getResult(), out);
403+
return success();
404+
}
405+
396406
static LogicalResult printOperation(CppEmitter &emitter,
397407
emitc::GetFieldOp getFieldOp) {
398408
emitter.cacheDeferredOpResult(getFieldOp.getResult(),
@@ -476,6 +486,17 @@ static LogicalResult printConstantOp(CppEmitter &emitter, Operation *operation,
476486
return emitter.emitAttribute(operation->getLoc(), value);
477487
}
478488

489+
static LogicalResult printOperation(CppEmitter &emitter,
490+
emitc::AddressOfOp addressOfOp) {
491+
raw_ostream &os = emitter.ostream();
492+
Operation &op = *addressOfOp.getOperation();
493+
494+
if (failed(emitter.emitAssignPrefix(op)))
495+
return failure();
496+
os << "&";
497+
return emitter.emitOperand(addressOfOp.getReference());
498+
}
499+
479500
static LogicalResult printOperation(CppEmitter &emitter,
480501
emitc::ConstantOp constantOp) {
481502
Operation *operation = constantOp.getOperation();
@@ -1769,14 +1790,14 @@ LogicalResult CppEmitter::emitOperation(Operation &op, bool trailingSemicolon) {
17691790
.Case<cf::BranchOp, cf::CondBranchOp>(
17701791
[&](auto op) { return printOperation(*this, op); })
17711792
// EmitC ops.
1772-
.Case<emitc::AddOp, emitc::ApplyOp, emitc::AssignOp,
1773-
emitc::BitwiseAndOp, emitc::BitwiseLeftShiftOp,
1793+
.Case<emitc::AddressOfOp, emitc::AddOp, emitc::ApplyOp,
1794+
emitc::AssignOp, emitc::BitwiseAndOp, emitc::BitwiseLeftShiftOp,
17741795
emitc::BitwiseNotOp, emitc::BitwiseOrOp,
17751796
emitc::BitwiseRightShiftOp, emitc::BitwiseXorOp, emitc::CallOp,
17761797
emitc::CallOpaqueOp, emitc::CastOp, emitc::ClassOp,
17771798
emitc::CmpOp, emitc::ConditionalOp, emitc::ConstantOp,
1778-
emitc::DeclareFuncOp, emitc::DivOp, emitc::DoOp,
1779-
emitc::ExpressionOp, emitc::FieldOp, emitc::FileOp,
1799+
emitc::DeclareFuncOp, emitc::DereferenceOp, emitc::DivOp,
1800+
emitc::DoOp, emitc::ExpressionOp, emitc::FieldOp, emitc::FileOp,
17801801
emitc::ForOp, emitc::FuncOp, emitc::GetFieldOp,
17811802
emitc::GetGlobalOp, emitc::GlobalOp, emitc::IfOp,
17821803
emitc::IncludeOp, emitc::LiteralOp, emitc::LoadOp,

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ func.func @alloc_copy(%arg0: memref<999xi32>) {
2626
// CHECK: %[[UNREALIZED_CONVERSION_CAST_1:.*]] = builtin.unrealized_conversion_cast %[[CAST_0]] : !emitc.ptr<i32> to !emitc.array<999xi32>
2727
// CHECK: %[[VAL_1:.*]] = "emitc.constant"() <{value = 0 : index}> : () -> index
2828
// CHECK: %[[SUBSCRIPT_0:.*]] = emitc.subscript %[[UNREALIZED_CONVERSION_CAST_0]]{{\[}}%[[VAL_1]]] : (!emitc.array<999xi32>, index) -> !emitc.lvalue<i32>
29-
// CHECK: %[[APPLY_0:.*]] = emitc.apply "&"(%[[SUBSCRIPT_0]]) : (!emitc.lvalue<i32>) -> !emitc.ptr<i32>
29+
// CHECK: %[[ADDRESS_OF_0:.*]] = emitc.address_of %[[SUBSCRIPT_0]] : !emitc.lvalue<i32>
3030
// CHECK: %[[VAL_2:.*]] = "emitc.constant"() <{value = 0 : index}> : () -> index
3131
// CHECK: %[[SUBSCRIPT_1:.*]] = emitc.subscript %[[UNREALIZED_CONVERSION_CAST_1]]{{\[}}%[[VAL_2]]] : (!emitc.array<999xi32>, index) -> !emitc.lvalue<i32>
32-
// CHECK: %[[APPLY_1:.*]] = emitc.apply "&"(%[[SUBSCRIPT_1]]) : (!emitc.lvalue<i32>) -> !emitc.ptr<i32>
32+
// CHECK: %[[ADDRESS_OF_1:.*]] = emitc.address_of %[[SUBSCRIPT_1]] : !emitc.lvalue<i32>
3333
// CHECK: %[[CALL_OPAQUE_2:.*]] = emitc.call_opaque "sizeof"() {args = [i32]} : () -> !emitc.size_t
3434
// CHECK: %[[VAL_3:.*]] = "emitc.constant"() <{value = 999 : index}> : () -> index
3535
// CHECK: %[[MUL_1:.*]] = emitc.mul %[[CALL_OPAQUE_2]], %[[VAL_3]] : (!emitc.size_t, index) -> !emitc.size_t
36-
// CHECK: emitc.call_opaque "memcpy"(%[[APPLY_1]], %[[APPLY_0]], %[[MUL_1]]) : (!emitc.ptr<i32>, !emitc.ptr<i32>, !emitc.size_t) -> ()
36+
// CHECK: emitc.call_opaque "memcpy"(%[[ADDRESS_OF_1]], %[[ADDRESS_OF_0]], %[[MUL_1]]) : (!emitc.ptr<i32>, !emitc.ptr<i32>, !emitc.size_t) -> ()
3737
// CHECK: %[[CALL_OPAQUE_3:.*]] = emitc.call_opaque "sizeof"() {args = [i32]} : () -> !emitc.size_t
3838
// CHECK: %[[VAL_4:.*]] = "emitc.constant"() <{value = 999 : index}> : () -> index
3939
// CHECK: %[[MUL_2:.*]] = emitc.mul %[[CALL_OPAQUE_3]], %[[VAL_4]] : (!emitc.size_t, index) -> !emitc.size_t
@@ -42,13 +42,13 @@ func.func @alloc_copy(%arg0: memref<999xi32>) {
4242
// CHECK: %[[UNREALIZED_CONVERSION_CAST_2:.*]] = builtin.unrealized_conversion_cast %[[CAST_1]] : !emitc.ptr<i32> to !emitc.array<999xi32>
4343
// CHECK: %[[VAL_5:.*]] = "emitc.constant"() <{value = 0 : index}> : () -> index
4444
// CHECK: %[[SUBSCRIPT_2:.*]] = emitc.subscript %[[UNREALIZED_CONVERSION_CAST_0]]{{\[}}%[[VAL_5]]] : (!emitc.array<999xi32>, index) -> !emitc.lvalue<i32>
45-
// CHECK: %[[APPLY_2:.*]] = emitc.apply "&"(%[[SUBSCRIPT_2]]) : (!emitc.lvalue<i32>) -> !emitc.ptr<i32>
45+
// CHECK: %[[ADDRESS_OF_2:.*]] = emitc.address_of %[[SUBSCRIPT_2]] : !emitc.lvalue<i32>
4646
// CHECK: %[[VAL_6:.*]] = "emitc.constant"() <{value = 0 : index}> : () -> index
4747
// CHECK: %[[SUBSCRIPT_3:.*]] = emitc.subscript %[[UNREALIZED_CONVERSION_CAST_2]]{{\[}}%[[VAL_6]]] : (!emitc.array<999xi32>, index) -> !emitc.lvalue<i32>
48-
// CHECK: %[[APPLY_3:.*]] = emitc.apply "&"(%[[SUBSCRIPT_3]]) : (!emitc.lvalue<i32>) -> !emitc.ptr<i32>
48+
// CHECK: %[[ADDRESS_OF_3:.*]] = emitc.address_of %[[SUBSCRIPT_3]] : !emitc.lvalue<i32>
4949
// CHECK: %[[CALL_OPAQUE_5:.*]] = emitc.call_opaque "sizeof"() {args = [i32]} : () -> !emitc.size_t
5050
// CHECK: %[[VAL_7:.*]] = "emitc.constant"() <{value = 999 : index}> : () -> index
5151
// CHECK: %[[MUL_3:.*]] = emitc.mul %[[CALL_OPAQUE_5]], %[[VAL_7]] : (!emitc.size_t, index) -> !emitc.size_t
52-
// CHECK: emitc.call_opaque "memcpy"(%[[APPLY_3]], %[[APPLY_2]], %[[MUL_3]]) : (!emitc.ptr<i32>, !emitc.ptr<i32>, !emitc.size_t) -> ()
52+
// CHECK: emitc.call_opaque "memcpy"(%[[ADDRESS_OF_3]], %[[ADDRESS_OF_2]], %[[MUL_3]]) : (!emitc.ptr<i32>, !emitc.ptr<i32>, !emitc.size_t) -> ()
5353
// CHECK: return
5454
// CHECK: }

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ func.func @copying(%arg0 : memref<9x4x5x7xf32>, %arg1 : memref<9x4x5x7xf32>) {
1717
// CHECK: %[[UNREALIZED_CONVERSION_CAST_1:.*]] = builtin.unrealized_conversion_cast %[[ARG0]] : memref<9x4x5x7xf32> to !emitc.array<9x4x5x7xf32>
1818
// CHECK: %[[VAL_0:.*]] = "emitc.constant"() <{value = 0 : index}> : () -> index
1919
// CHECK: %[[SUBSCRIPT_0:.*]] = emitc.subscript %[[UNREALIZED_CONVERSION_CAST_1]]{{\[}}%[[VAL_0]], %[[VAL_0]], %[[VAL_0]], %[[VAL_0]]] : (!emitc.array<9x4x5x7xf32>, index, index, index, index) -> !emitc.lvalue<f32>
20-
// CHECK: %[[APPLY_0:.*]] = emitc.apply "&"(%[[SUBSCRIPT_0]]) : (!emitc.lvalue<f32>) -> !emitc.ptr<f32>
20+
// CHECK: %[[ADDRESS_OF_0:.*]] = emitc.address_of %[[SUBSCRIPT_0]] : !emitc.lvalue<f32>
2121
// CHECK: %[[VAL_1:.*]] = "emitc.constant"() <{value = 0 : index}> : () -> index
2222
// CHECK: %[[SUBSCRIPT_1:.*]] = emitc.subscript %[[UNREALIZED_CONVERSION_CAST_0]]{{\[}}%[[VAL_1]], %[[VAL_1]], %[[VAL_1]], %[[VAL_1]]] : (!emitc.array<9x4x5x7xf32>, index, index, index, index) -> !emitc.lvalue<f32>
23-
// CHECK: %[[APPLY_1:.*]] = emitc.apply "&"(%[[SUBSCRIPT_1]]) : (!emitc.lvalue<f32>) -> !emitc.ptr<f32>
23+
// CHECK: %[[ADDRESS_OF_1:.*]] = emitc.address_of %[[SUBSCRIPT_1]] : !emitc.lvalue<f32>
2424
// CHECK: %[[CALL_OPAQUE_0:.*]] = emitc.call_opaque "sizeof"() {args = [f32]} : () -> !emitc.size_t
2525
// CHECK: %[[VAL_2:.*]] = "emitc.constant"() <{value = 1260 : index}> : () -> index
2626
// CHECK: %[[MUL_0:.*]] = emitc.mul %[[CALL_OPAQUE_0]], %[[VAL_2]] : (!emitc.size_t, index) -> !emitc.size_t
27-
// CHECK: emitc.call_opaque "memcpy"(%[[APPLY_1]], %[[APPLY_0]], %[[MUL_0]]) : (!emitc.ptr<f32>, !emitc.ptr<f32>, !emitc.size_t) -> ()
27+
// CHECK: emitc.call_opaque "memcpy"(%[[ADDRESS_OF_1]], %[[ADDRESS_OF_0]], %[[MUL_0]]) : (!emitc.ptr<f32>, !emitc.ptr<f32>, !emitc.size_t) -> ()
2828
// CHECK: return
2929
// CHECK: }
3030

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ module @globals {
5353
// CHECK-NEXT: emitc.get_global @public_global : !emitc.array<3x7xf32>
5454
%0 = memref.get_global @public_global : memref<3x7xf32>
5555
// CHECK-NEXT: emitc.get_global @__constant_xi32 : !emitc.lvalue<i32>
56-
// CHECK-NEXT: emitc.apply "&"(%1) : (!emitc.lvalue<i32>) -> !emitc.ptr<i32>
56+
// CHECK-NEXT: emitc.address_of %1 : !emitc.lvalue<i32>
5757
%1 = memref.get_global @__constant_xi32 : memref<i32>
5858
return
5959
}

mlir/test/Dialect/EmitC/invalid_ops.mlir

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,3 +914,19 @@ func.func @test_for_unmatch_type(%arg0: index) {
914914
) : (index, index, index) -> ()
915915
return
916916
}
917+
918+
// -----
919+
920+
func.func @address_of(%arg0: !emitc.lvalue<i32>) {
921+
// expected-error @+1 {{failed to verify that input and result reference the same type}}
922+
%1 = "emitc.address_of"(%arg0) : (!emitc.lvalue<i32>) -> !emitc.ptr<i8>
923+
return
924+
}
925+
926+
// -----
927+
928+
func.func @dereference(%arg0: !emitc.ptr<i32>) {
929+
// expected-error @+1 {{failed to verify that input and result reference the same type}}
930+
%1 = "emitc.dereference"(%arg0) : (!emitc.ptr<i32>) -> !emitc.lvalue<i8>
931+
return
932+
}

mlir/test/Dialect/EmitC/ops.mlir

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,13 @@ func.func @do(%arg0 : !emitc.ptr<i32>) {
355355

356356
return
357357
}
358+
359+
func.func @address_of(%arg0: !emitc.lvalue<i32>) {
360+
%1 = emitc.address_of %arg0 : !emitc.lvalue<i32>
361+
return
362+
}
363+
364+
func.func @dereference(%arg0: !emitc.ptr<i32>) {
365+
%1 = emitc.dereference %arg0 : !emitc.ptr<i32>
366+
return
367+
}

0 commit comments

Comments
 (0)