Loading mlir/parsers/qasm3/tests/test_modifiers.cpp +27 −0 Original line number Diff line number Diff line Loading @@ -490,6 +490,33 @@ pow(2) @ ctrl @ t q, qq; std::cout << "LLVM:\n" << llvm << "\n"; } // Modifier block in a kernel definition: // Note: we chase use-def for gate def: TEST(qasm3VisitorTester, checkModifierInKernelDef) { const std::string check_nested = R"#(OPENQASM 3; gate test1 q, qq { h q; ctrl @ x q, qq; x qq; } gate test2 q, qq { h q; ctrl @ pow(4) @ x q, qq; x qq; } gate test3 q, qq { h q; inv @ ctrl @ pow(4) @ t q, qq; x qq; } )#"; auto llvm = qcor::mlir_compile(check_nested, "nested", qcor::OutputType::LLVMIR, false, 0); std::cout << "LLVM:\n" << llvm << "\n"; } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); auto ret = RUN_ALL_TESTS(); Loading mlir/parsers/qasm3/visitor_handlers/quantum_types_handler.cpp +16 −6 Original line number Diff line number Diff line Loading @@ -170,10 +170,20 @@ antlrcpp::Any qasm3_visitor::visitQuantumGateDefinition( } mlir::Value last_user = arg; auto users = last_user.getUsers(); while (!users.empty()) { // Get the first and only user auto only_user = *users.begin(); auto user_iter = users.begin(); for (const auto &user : users) { // Only chase use-def chain on the top-level ops // i.e., direct children of this kernel (FuncOp) // e.g., skip ops inside a modifier region. if (llvm::dyn_cast_or_null<mlir::FuncOp>(user->getParentOp())) { break; } ++user_iter; } // Get the first and only user (quantum ops: value semantics ops or // modifier regions, kernel calls) auto only_user = *user_iter; // figure out which operand idx last_user // corresponds to Loading Loading
mlir/parsers/qasm3/tests/test_modifiers.cpp +27 −0 Original line number Diff line number Diff line Loading @@ -490,6 +490,33 @@ pow(2) @ ctrl @ t q, qq; std::cout << "LLVM:\n" << llvm << "\n"; } // Modifier block in a kernel definition: // Note: we chase use-def for gate def: TEST(qasm3VisitorTester, checkModifierInKernelDef) { const std::string check_nested = R"#(OPENQASM 3; gate test1 q, qq { h q; ctrl @ x q, qq; x qq; } gate test2 q, qq { h q; ctrl @ pow(4) @ x q, qq; x qq; } gate test3 q, qq { h q; inv @ ctrl @ pow(4) @ t q, qq; x qq; } )#"; auto llvm = qcor::mlir_compile(check_nested, "nested", qcor::OutputType::LLVMIR, false, 0); std::cout << "LLVM:\n" << llvm << "\n"; } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); auto ret = RUN_ALL_TESTS(); Loading
mlir/parsers/qasm3/visitor_handlers/quantum_types_handler.cpp +16 −6 Original line number Diff line number Diff line Loading @@ -170,10 +170,20 @@ antlrcpp::Any qasm3_visitor::visitQuantumGateDefinition( } mlir::Value last_user = arg; auto users = last_user.getUsers(); while (!users.empty()) { // Get the first and only user auto only_user = *users.begin(); auto user_iter = users.begin(); for (const auto &user : users) { // Only chase use-def chain on the top-level ops // i.e., direct children of this kernel (FuncOp) // e.g., skip ops inside a modifier region. if (llvm::dyn_cast_or_null<mlir::FuncOp>(user->getParentOp())) { break; } ++user_iter; } // Get the first and only user (quantum ops: value semantics ops or // modifier regions, kernel calls) auto only_user = *user_iter; // figure out which operand idx last_user // corresponds to Loading