Loading mlir/dialect/include/Quantum/QuantumOps.td +8 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ def ArgvType : OpaqueType<"quantum", "ArgvType", "opaque argv type">; def QregType : OpaqueType<"quantum", "QregType", "opaque qreg type">; def StringType : OpaqueType<"quantum", "StringType", "opaque string type">; def TupleType : OpaqueType<"quantum", "Tuple", "opaque tuple type">; def CallableType : OpaqueType<"quantum", "Callable", "opaque callable type">; def QallocOp : QuantumOp<"qalloc", []> { let arguments = (ins AnyI64Attr:$size, StrAttr:$name); Loading Loading @@ -181,4 +182,11 @@ def TupleUnpackOp : QuantumOp<"tupleUnpack", []> { p << "q.tupleUnpack" << "(" << op.tuple() << ") : " << op.result().getType(); }]; } def CreateCallableOp : QuantumOp<"createCallable", []> { let arguments = (ins FlatSymbolRefAttr:$functors); let results = (outs CallableType:$callable); let printer = [{ auto op = *this; p << "q.createCallable" << "(" << op.functors() << ") : " << op.callable().getType(); }]; } #endif // Quantum_OPS No newline at end of file mlir/parsers/qasm3/visitor_handlers/subroutine_handler.cpp +15 −5 Original line number Diff line number Diff line #include "qasm3_visitor.hpp" namespace { void add_body_wrapper(mlir::OpBuilder &builder, const std::string &func_name, mlir::ModuleOp& moduleOp, mlir::FuncOp& wrapped_func) { void add_body_wrapper(mlir::OpBuilder &builder, const std::string &func_name, mlir::ModuleOp &moduleOp, mlir::FuncOp &wrapped_func) { // define internal void @body__wrapper(%Tuple* %capture-tuple, %Tuple* // %arg-tuple, %Tuple* %result-tuple) const std::string wrapper_fn_name = func_name + "__body__wrapper"; Loading @@ -10,6 +11,10 @@ void add_body_wrapper(mlir::OpBuilder &builder, const std::string &func_name, ml llvm::StringRef tuple_type_name("Tuple"); mlir::Identifier dialect = mlir::Identifier::get("quantum", context); auto tuple_type = mlir::OpaqueType::get(context, dialect, tuple_type_name); llvm::StringRef callable_type_name("Callable"); auto callable_type = mlir::OpaqueType::get(context, dialect, callable_type_name); const std::vector<mlir::Type> argument_types{tuple_type, tuple_type, tuple_type}; auto func_type = builder.getFunctionType(argument_types, llvm::None); Loading @@ -25,12 +30,17 @@ void add_body_wrapper(mlir::OpBuilder &builder, const std::string &func_name, ml mlir::Value arg_tuple = arguments[1]; auto fn_type = wrapped_func.getType().cast<mlir::FunctionType>(); mlir::TypeRange arg_types(fn_type.getInputs()); auto unpackOp = builder.create<mlir::quantum::TupleUnpackOp>(builder.getUnknownLoc(), arg_types, arg_tuple); auto unpackOp = builder.create<mlir::quantum::TupleUnpackOp>( builder.getUnknownLoc(), arg_types, arg_tuple); auto call_op = builder.create<mlir::CallOp>(builder.getUnknownLoc(), wrapped_func, unpackOp.result()); builder.restoreInsertionPoint(main_block); moduleOp.push_back(function_op); builder.setInsertionPointToStart(&moduleOp.getRegion().getBlocks().front()); auto callable_create_op = builder.create<mlir::quantum::CreateCallableOp>( builder.getUnknownLoc(), callable_type, builder.getSymbolRefAttr(function_op)); builder.restoreInsertionPoint(main_block); } }; // namespace namespace qcor { Loading Loading
mlir/dialect/include/Quantum/QuantumOps.td +8 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ def ArgvType : OpaqueType<"quantum", "ArgvType", "opaque argv type">; def QregType : OpaqueType<"quantum", "QregType", "opaque qreg type">; def StringType : OpaqueType<"quantum", "StringType", "opaque string type">; def TupleType : OpaqueType<"quantum", "Tuple", "opaque tuple type">; def CallableType : OpaqueType<"quantum", "Callable", "opaque callable type">; def QallocOp : QuantumOp<"qalloc", []> { let arguments = (ins AnyI64Attr:$size, StrAttr:$name); Loading Loading @@ -181,4 +182,11 @@ def TupleUnpackOp : QuantumOp<"tupleUnpack", []> { p << "q.tupleUnpack" << "(" << op.tuple() << ") : " << op.result().getType(); }]; } def CreateCallableOp : QuantumOp<"createCallable", []> { let arguments = (ins FlatSymbolRefAttr:$functors); let results = (outs CallableType:$callable); let printer = [{ auto op = *this; p << "q.createCallable" << "(" << op.functors() << ") : " << op.callable().getType(); }]; } #endif // Quantum_OPS No newline at end of file
mlir/parsers/qasm3/visitor_handlers/subroutine_handler.cpp +15 −5 Original line number Diff line number Diff line #include "qasm3_visitor.hpp" namespace { void add_body_wrapper(mlir::OpBuilder &builder, const std::string &func_name, mlir::ModuleOp& moduleOp, mlir::FuncOp& wrapped_func) { void add_body_wrapper(mlir::OpBuilder &builder, const std::string &func_name, mlir::ModuleOp &moduleOp, mlir::FuncOp &wrapped_func) { // define internal void @body__wrapper(%Tuple* %capture-tuple, %Tuple* // %arg-tuple, %Tuple* %result-tuple) const std::string wrapper_fn_name = func_name + "__body__wrapper"; Loading @@ -10,6 +11,10 @@ void add_body_wrapper(mlir::OpBuilder &builder, const std::string &func_name, ml llvm::StringRef tuple_type_name("Tuple"); mlir::Identifier dialect = mlir::Identifier::get("quantum", context); auto tuple_type = mlir::OpaqueType::get(context, dialect, tuple_type_name); llvm::StringRef callable_type_name("Callable"); auto callable_type = mlir::OpaqueType::get(context, dialect, callable_type_name); const std::vector<mlir::Type> argument_types{tuple_type, tuple_type, tuple_type}; auto func_type = builder.getFunctionType(argument_types, llvm::None); Loading @@ -25,12 +30,17 @@ void add_body_wrapper(mlir::OpBuilder &builder, const std::string &func_name, ml mlir::Value arg_tuple = arguments[1]; auto fn_type = wrapped_func.getType().cast<mlir::FunctionType>(); mlir::TypeRange arg_types(fn_type.getInputs()); auto unpackOp = builder.create<mlir::quantum::TupleUnpackOp>(builder.getUnknownLoc(), arg_types, arg_tuple); auto unpackOp = builder.create<mlir::quantum::TupleUnpackOp>( builder.getUnknownLoc(), arg_types, arg_tuple); auto call_op = builder.create<mlir::CallOp>(builder.getUnknownLoc(), wrapped_func, unpackOp.result()); builder.restoreInsertionPoint(main_block); moduleOp.push_back(function_op); builder.setInsertionPointToStart(&moduleOp.getRegion().getBlocks().front()); auto callable_create_op = builder.create<mlir::quantum::CreateCallableOp>( builder.getUnknownLoc(), callable_type, builder.getSymbolRefAttr(function_op)); builder.restoreInsertionPoint(main_block); } }; // namespace namespace qcor { Loading