Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Schweitz <[email protected]>
  • Loading branch information
schweitzpgi committed Jan 24, 2025
1 parent ec68971 commit 9490165
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/Optimizer/Builder/Intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ static constexpr IntrinsicCode intrinsicTable[] = {
func.func private @__quantum__qis__custom_unitary(!cc.ptr<complex<f64>>, !qir_array, !qir_array, !qir_charptr)
func.func private @__quantum__qis__custom_unitary__adj(!cc.ptr<complex<f64>>, !qir_array, !qir_array, !qir_charptr)
llvm.func @generalizedInvokeWithRotationsControlsTargets(i64, i64, i64, i64, !qir_llvmptr, ...)
llvm.func @generalizedInvokeWithRotationsControlsTargets(i64, i64, i64, i64, !qir_llvmptr, ...) attributes {sym_visibility = "private"}
)#"},

// Declarations for base and adaptive profile QIR functions used by codegen.
Expand Down
4 changes: 3 additions & 1 deletion lib/Optimizer/CodeGen/ConvertToQIRAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,8 @@ struct QuakeToQIRAPIPass
return hasQuakeType(pty.getElementType());
if (auto cty = dyn_cast<cudaq::cc::CallableType>(ty))
return hasQuakeType(cty.getSignature());
if (auto cty = dyn_cast<cudaq::cc::IndirectCallableType>(ty))
return hasQuakeType(cty.getSignature());
if (auto fty = dyn_cast<FunctionType>(ty)) {
for (auto t : fty.getInputs())
if (hasQuakeType(t))
Expand Down Expand Up @@ -1852,8 +1854,8 @@ void cudaq::opt::addConvertToQIRAPIPipeline(OpPassManager &pm, StringRef api,
pm.addPass(cudaq::opt::createLowerToCG());
pm.addPass(cudaq::opt::createQuakeToQIRAPI(apiOpt));
pm.addPass(createCanonicalizerPass());
pm.addPass(cudaq::opt::createGlobalizeArrayValues());
pm.addPass(cudaq::opt::createQuakeToQIRAPIFinal());
pm.addPass(cudaq::opt::createGlobalizeArrayValues());
}

namespace {
Expand Down
2 changes: 1 addition & 1 deletion lib/Optimizer/CodeGen/VerifyNVQIRCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct VerifyNVQIRCallOpsPass
return WalkResult::interrupt();
} else if (!isa<LLVM::AddressOfOp, LLVM::AllocaOp, LLVM::BitcastOp,
LLVM::ExtractValueOp, LLVM::GEPOp, LLVM::InsertValueOp,
LLVM::LoadOp, LLVM::StoreOp>(op)) {
LLVM::IntToPtrOp, LLVM::LoadOp, LLVM::StoreOp>(op)) {
// No pointers allowed except for the above operations.
for (auto oper : op->getOperands()) {
if (isa<LLVM::LLVMPointerType>(oper.getType())) {
Expand Down
28 changes: 17 additions & 11 deletions lib/Optimizer/Transforms/GlobalizeArrayValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,18 @@ struct ConstantArrayPattern

LogicalResult matchAndRewrite(cudaq::cc::ConstantArrayOp conarr,
PatternRewriter &rewriter) const override {
if (!conarr->hasOneUse())
return failure();
auto store = dyn_cast<cudaq::cc::StoreOp>(*conarr->getUsers().begin());
if (!store)
return failure();
auto alloca = store.getPtrvalue().getDefiningOp<cudaq::cc::AllocaOp>();
if (!alloca)
return failure();
SmallVector<cudaq::cc::AllocaOp> allocas;
SmallVector<cudaq::cc::StoreOp> stores;
for (auto *usr : conarr->getUsers()) {
auto store = dyn_cast<cudaq::cc::StoreOp>(usr);
if (!store)
return failure();
auto alloca = store.getPtrvalue().getDefiningOp<cudaq::cc::AllocaOp>();
if (!alloca)
return failure();
stores.push_back(store);
allocas.push_back(alloca);
}
auto func = conarr->getParentOfType<func::FuncOp>();
if (!func)
return failure();
Expand All @@ -114,9 +118,11 @@ struct ConstantArrayPattern
if (failed(convertArrayAttrToGlobalConstant(ctx, conarr.getLoc(), valueAttr,
module, globalName, eleTy)))
return failure();
rewriter.replaceOpWithNewOp<cudaq::cc::AddressOfOp>(
alloca, alloca.getType(), globalName);
rewriter.eraseOp(store);
for (auto alloca : allocas)
rewriter.replaceOpWithNewOp<cudaq::cc::AddressOfOp>(
alloca, alloca.getType(), globalName);
for (auto store : stores)
rewriter.eraseOp(store);
rewriter.eraseOp(conarr);
return success();
}
Expand Down
1 change: 0 additions & 1 deletion test/Translate/emit-mlir.qke
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ func.func @test_func(%p : i32) {

// CHECK: llvm.func @__quantum__rt__qubit_allocate_array(i64) -> !llvm.ptr<struct<"Array", opaque>> attributes {sym_visibility = "private"}
// CHECK: llvm.func @__quantum__rt__qubit_release_array(!llvm.ptr<struct<"Array", opaque>>) attributes {sym_visibility = "private"}
// CHECK: llvm.func @generalizedInvokeWithRotationsControlsTargets(i64, i64, i64, i64, !llvm.ptr<i8>, ...)
1 change: 1 addition & 0 deletions tools/cudaq-qpud/RestServerMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* This source code and the accompanying materials are made available under *
* the terms of the Apache License 2.0 which accompanies this distribution. *
******************************************************************************/

#include "common/GPUInfo.h"
#include "common/Registry.h"
#include "common/RemoteKernelExecutor.h"
Expand Down

0 comments on commit 9490165

Please sign in to comment.