Skip to content
Open
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
5 changes: 4 additions & 1 deletion ex4-beautiful-dialect/include/toy/ToyOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ def FuncOp : ToyOp<"func", [

def CallOp : ToyOp<"call", [CallOpInterface]> {
let summary = "call operation";
let arguments = (ins SymbolRefAttr:$callee, Variadic<AnyType>:$arg_operands);
let arguments = (ins SymbolRefAttr:$callee,
Variadic<AnyType>:$arg_operands,
OptionalAttr<DictArrayAttr>:$arg_attrs,
OptionalAttr<DictArrayAttr>:$res_attrs);
let results = (outs AnyType:$result);
let assemblyFormat = "$callee `(` $arg_operands `)` attr-dict `:` functional-type($arg_operands, results)";
let extraClassDeclaration = [{
Expand Down
5 changes: 4 additions & 1 deletion ex5-pass/include/toy/ToyOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ def FuncOp : ToyOp<"func", [

def CallOp : ToyOp<"call", [CallOpInterface]> {
let summary = "call operation";
let arguments = (ins SymbolRefAttr:$callee, Variadic<AnyType>:$arg_operands);
let arguments = (ins SymbolRefAttr:$callee,
Variadic<AnyType>:$arg_operands,
OptionalAttr<DictArrayAttr>:$arg_attrs,
OptionalAttr<DictArrayAttr>:$res_attrs);
let results = (outs AnyType:$result);
let assemblyFormat = "$callee `(` $arg_operands `)` attr-dict `:` functional-type($arg_operands, results)";
let extraClassDeclaration = [{
Expand Down
1 change: 1 addition & 0 deletions ex5-pass/lib/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ add_mlir_library(
DCE.cpp
DEPENDS
MLIRToyTransformsIncGen
MLIRToyIncGen
)
5 changes: 4 additions & 1 deletion ex6-pattern/include/toy/ToyOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ def FuncOp : ToyOp<"func", [

def CallOp : ToyOp<"call", [CallOpInterface]> {
let summary = "call operation";
let arguments = (ins SymbolRefAttr:$callee, Variadic<AnyType>:$arg_operands);
let arguments = (ins SymbolRefAttr:$callee,
Variadic<AnyType>:$arg_operands,
OptionalAttr<DictArrayAttr>:$arg_attrs,
OptionalAttr<DictArrayAttr>:$res_attrs);
let results = (outs AnyType:$result);
let assemblyFormat = "$callee `(` $arg_operands `)` attr-dict `:` functional-type($arg_operands, results)";
let extraClassDeclaration = [{
Expand Down
5 changes: 4 additions & 1 deletion ex7-convert/include/toy/ToyOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ def FuncOp : ToyOp<"func", [

def CallOp : ToyOp<"call", [CallOpInterface]> {
let summary = "call operation";
let arguments = (ins SymbolRefAttr:$callee, Variadic<AnyType>:$arg_operands);
let arguments = (ins SymbolRefAttr:$callee,
Variadic<AnyType>:$arg_operands,
OptionalAttr<DictArrayAttr>:$arg_attrs,
OptionalAttr<DictArrayAttr>:$res_attrs);
let results = (outs AnyType:$result);
let assemblyFormat = "$callee `(` $arg_operands `)` attr-dict `:` functional-type($arg_operands, results)";
let extraClassDeclaration = [{
Expand Down
12 changes: 6 additions & 6 deletions ex7-convert/lib/Transforms/ConvertToyToArith.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ struct ReturnOpPat: OpConversionPattern<ReturnOp> {
using OpConversionPattern<ReturnOp>::OpConversionPattern;
LogicalResult matchAndRewrite(ReturnOp op, ReturnOpAdaptor adaptor, ConversionPatternRewriter & rewriter) const {
auto data = adaptor.getData();
rewriter.startRootUpdate(op);
op.getDataMutable().assign(data);
rewriter.finalizeRootUpdate(op);
rewriter.modifyOpInPlace(op, [&]() {
op.getDataMutable().assign(data);
});
return success();
}
};
Expand All @@ -69,7 +69,7 @@ struct CallOpPat: OpConversionPattern<CallOp> {
LogicalResult matchAndRewrite(CallOp op, CallOpAdaptor adaptor, ConversionPatternRewriter & rewriter) const {
SmallVector<Type> resTypes;
assert(succeeded(getTypeConverter()->convertTypes(op->getResultTypes(), resTypes)));
rewriter.replaceOpWithNewOp<CallOp>(op, resTypes, op.getCallee(), adaptor.getOperands());
rewriter.replaceOpWithNewOp<CallOp>(op, resTypes, op.getCallee(), adaptor.getOperands(), op.getArgAttrsAttr(), op.getResAttrsAttr());
return success();
}
};
Expand All @@ -90,10 +90,10 @@ struct ConvertToyToArithPass : toy::impl::ConvertToyToArithBase<ConvertToyToArit
};
target.addDynamicallyLegalOp<ReturnOp, CallOp>(checkValid);
TypeConverter converter;
converter.addConversion([&](ToyIntegerType t) -> std::optional<IntegerType> {
converter.addConversion([&](ToyIntegerType t) -> IntegerType {
return IntegerType::get(&getContext(), t.getWidth());
});
converter.addTargetMaterialization([](OpBuilder& builder, Type resultType, ValueRange inputs, Location loc) -> std::optional<Value> {
converter.addTargetMaterialization([](OpBuilder& builder, Type resultType, ValueRange inputs, Location loc) -> Value {
return builder.create<UnrealizedConversionCastOp>(loc, resultType, inputs).getResult(0);
});
RewritePatternSet patterns(&getContext());
Expand Down