Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support controlled-SWAP's in kernel builder #924

Merged
merged 10 commits into from
Dec 18, 2023
Prev Previous commit
Next Next commit
revert bridge changes
Signed-off-by: A.M. Santana <[email protected]>
  • Loading branch information
anthony-santana committed Dec 18, 2023
commit 4aa052c425316ed7cb53ddf05e281fc5354d4044
61 changes: 13 additions & 48 deletions lib/Optimizer/CodeGen/LowerToQIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,57 +727,22 @@ class TwoTargetRewrite : public ConvertOpWithControls<OP> {
ModuleOp parentModule = instOp->template getParentOfType<ModuleOp>();
auto context = parentModule->getContext();
auto qirFunctionName = std::string(cudaq::opt::QIRQISPrefix) + instName;
auto qubitIndexType = cudaq::opt::getQubitType(context);

auto qubitIndexType = cudaq::opt::getQubitType(context);
SmallVector<Type> tmpArgTypes = {qubitIndexType, qubitIndexType};

// FIXME: once code works, simplify these conditional checks and their returns

if (numControls == 0) {
SmallVector<Type> tmpArgTypes = {qubitIndexType, qubitIndexType};

FlatSymbolRefAttr symbolRef = cudaq::opt::factory::createLLVMFunctionSymbol(
qirFunctionName, /*return type=*/LLVM::LLVMVoidType::get(context),
std::move(tmpArgTypes), parentModule);

// FIXME: Do we want to use any fast math flags?
// TODO: Looks like bugs in the MLIR cmake files don't install this any
// longer.
// auto fastMathFlags = LLVM::FMFAttr::get(context, {});
// Create the CallOp for this quantum instruction
rewriter.replaceOpWithNewOp<LLVM::CallOp>(
instOp, TypeRange{}, symbolRef,
adaptor.getOperands() /*, fastMathFlags*/);
return success();
}

// // This will be a controlled-operation.
// qirFunctionName += "__ctl";
// auto qirArrayType = cudaq::opt::getArrayType(context);
// SmallVector<Type> tmpArgTypes = {qirArrayType, qubitIndexType, qubitIndexType};

// // // __quantum__qis__NAME__ctl(Array*, Qubit*, Qubit*) Type
// // auto instOpQISFunctionType = LLVM::LLVMFunctionType::get(
// // LLVM::LLVMVoidType::get(context), {qirArrayType, qubitIndexType, qubitIndexType});

// // Get the function pointer for the ctrl operation
// auto qirFunctionSymbolRef = cudaq::opt::factory::createLLVMFunctionSymbol(
// qirFunctionName, LLVM::LLVMVoidType::get(context),
// tmpArgTypes, parentModule);

// // Get the first control's type
// auto control = *instOp.getControls().begin();
// Type type = control.getType();
// auto instOperands = adaptor.getOperands();
// if (numControls == 1 && type.isa<quake::VeqType>()) {
// // if (negatedQubitCtrls)
// // return instOp.emitError("unsupported controlled op " + instName +
// // " with vector of ctrl qubits");
// // Operands are already an Array* and Qubit*.
// rewriter.replaceOpWithNewOp<LLVM::CallOp>(
// instOp, TypeRange{}, qirFunctionSymbolRef, instOperands);
// return success();
// }
FlatSymbolRefAttr symbolRef = cudaq::opt::factory::createLLVMFunctionSymbol(
qirFunctionName, /*return type=*/LLVM::LLVMVoidType::get(context),
std::move(tmpArgTypes), parentModule);

// FIXME: Do we want to use any fast math flags?
// TODO: Looks like bugs in the MLIR cmake files don't install this any
// longer.
// auto fastMathFlags = LLVM::FMFAttr::get(context, {});
// Create the CallOp for this quantum instruction
rewriter.replaceOpWithNewOp<LLVM::CallOp>(
instOp, TypeRange{}, symbolRef,
adaptor.getOperands() /*, fastMathFlags*/);
return success();
}
};
Expand Down