Skip to content

Commit c62a510

Browse files
Merge branch 'main' into qibo_backend
2 parents f9c33a3 + d5bea81 commit c62a510

34 files changed

+926
-611
lines changed

include/cudaq/Optimizer/CodeGen/Passes.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,10 @@ namespace cudaq::opt {
3535
/// \deprecated Replaced by the convert to QIR API pipeline.
3636
void addQIRProfilePipeline(mlir::OpPassManager &pm, llvm::StringRef convertTo);
3737

38-
void addQIRProfileVerify(mlir::OpPassManager &pm, llvm::StringRef convertTo);
39-
4038
void addLowerToCCPipeline(mlir::OpPassManager &pm);
4139
void addWiresetToProfileQIRPipeline(mlir::OpPassManager &pm,
4240
llvm::StringRef profile);
4341

44-
/// Verify that all `CallOp` targets are QIR- or NVQIR-defined functions or in
45-
/// the provided allowed list.
46-
std::unique_ptr<mlir::Pass>
47-
createVerifyNVQIRCallOpsPass(const std::vector<llvm::StringRef> &allowedFuncs);
48-
4942
// Use the addQIRProfilePipeline() for the following passes.
5043
std::unique_ptr<mlir::Pass>
5144
createQIRToQIRProfilePass(llvm::StringRef convertTo);

include/cudaq/Optimizer/CodeGen/Passes.td

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -156,38 +156,6 @@ def RemoveMeasurements : Pass<"remove-measurements"> {
156156
}];
157157
}
158158

159-
def VerifyNVQIRCallOps :
160-
Pass<"verify-nvqir-call-ops", "mlir::LLVM::LLVMFuncOp"> {
161-
let summary =
162-
"Verify that all LLVM CallOps' callees are NVQIR compliant";
163-
let description = [{
164-
This is a function pass to verify that all function calls within the
165-
function body are referring to pre-defined allowed functions or QIR
166-
functions, i.e., starting with a __quantum prefix, or NVQIR runtime
167-
functions.
168-
}];
169-
170-
let options = [
171-
ListOption<"allowedFuncs", "allowed-funcs", "llvm::StringRef",
172-
"Allowed list of functions in addition to NVQIR-defined function.">
173-
];
174-
175-
let constructor = "cudaq::opt::createVerifyNVQIRCallOpsPass({})";
176-
}
177-
178-
def VerifyQIRProfile : Pass<"verify-qir-profile", "mlir::LLVM::LLVMFuncOp"> {
179-
let summary = "Verify that the output conforms to the specific profile";
180-
let description = [{
181-
This pass scans over functions in the LLVM-IR dialect to make sure they
182-
conform to the QIR specific profile.
183-
}];
184-
185-
let options = [
186-
Option<"convertTo", "convert-to", "std::string", "\"qir-base\"",
187-
"Which QIR profile to convert to (default is 'qir-base')">
188-
];
189-
}
190-
191159
def WireSetToProfileQIR : Pass<"wireset-to-profile-qir", "mlir::func::FuncOp"> {
192160
let summary = "Convert quake using wire sets to a profile of QIR";
193161
let description = [{

include/cudaq/Optimizer/CodeGen/QIROpaqueStructTypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
/// This file provides the opaque struct types to be used with the obsolete LLVM
1212
/// typed pointer type.
1313

14+
#include "cudaq/Optimizer/Dialect/CC/CCTypes.h"
1415
#include "mlir/Conversion/LLVMCommon/TypeConverter.h"
1516
#include "mlir/Dialect/LLVMIR/LLVMTypes.h"
1617

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/****************************************************************-*- C++ -*-****
2+
* Copyright (c) 2026 NVIDIA Corporation & Affiliates. *
3+
* All rights reserved. *
4+
* *
5+
* This source code and the accompanying materials are made available under *
6+
* the terms of the Apache License 2.0 which accompanies this distribution. *
7+
******************************************************************************/
8+
9+
#pragma once
10+
11+
#include "mlir/IR/BuiltinOps.h"
12+
#include "mlir/Support/LogicalResult.h"
13+
14+
namespace cudaq::verifier {
15+
16+
/**
17+
Verify that the MLIR module only calls functions that are within the set of
18+
valid targets for NVQIR.
19+
*/
20+
mlir::LogicalResult checkNvqirCalls(mlir::ModuleOp module);
21+
} // namespace cudaq::verifier
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/****************************************************************-*- C++ -*-****
2+
* Copyright (c) 2026 NVIDIA Corporation & Affiliates. *
3+
* All rights reserved. *
4+
* *
5+
* This source code and the accompanying materials are made available under *
6+
* the terms of the Apache License 2.0 which accompanies this distribution. *
7+
******************************************************************************/
8+
9+
#pragma once
10+
11+
#include "mlir/IR/BuiltinOps.h"
12+
#include "mlir/Support/LogicalResult.h"
13+
14+
namespace cudaq::verifier {
15+
16+
/// Verify some QIR constraints when the IR is lowered to LLVM-IR dialect.
17+
mlir::LogicalResult checkQIRLLVMIRDialect(mlir::ModuleOp module,
18+
mlir::StringRef profile);
19+
} // namespace cudaq::verifier

include/cudaq/Verifier/QIRSpec.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/****************************************************************-*- C++ -*-****
2+
* Copyright (c) 2026 NVIDIA Corporation & Affiliates. *
3+
* All rights reserved. *
4+
* *
5+
* This source code and the accompanying materials are made available under *
6+
* the terms of the Apache License 2.0 which accompanies this distribution. *
7+
******************************************************************************/
8+
9+
#pragma once
10+
11+
#include "mlir/IR/BuiltinOps.h"
12+
#include "mlir/Support/LogicalResult.h"
13+
14+
namespace llvm {
15+
class Module;
16+
}
17+
18+
namespace cudaq::verifier {
19+
20+
struct LLVMVerifierOptions {
21+
bool isBaseProfile : 1;
22+
bool isAdaptiveProfile : 1;
23+
bool allowAllInstructions : 1;
24+
bool integerComputations : 1;
25+
bool floatComputations : 1;
26+
};
27+
28+
/// Verify that only LLVM instructions allowed by the QIR specification.
29+
mlir::LogicalResult verifyLLVMInstructions(llvm::Module *llvmModule,
30+
LLVMVerifierOptions options);
31+
} // namespace cudaq::verifier

lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ if (NOT CUDAQ_DISABLE_CPP_FRONTEND)
1212
endif()
1313
add_subdirectory(Optimizer)
1414
add_subdirectory(Support)
15+
add_subdirectory(Verifier)

lib/Optimizer/CodeGen/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ add_cudaq_library(OptCodeGen
3131
ReturnToOutputLog.cpp
3232
TranslateToIQMJson.cpp
3333
TranslateToOpenQASM.cpp
34-
VerifyNVQIRCalls.cpp
35-
VerifyQIRProfile.cpp
3634
WireSetsToProfileQIR.cpp
3735

3836
DEPENDS
@@ -43,6 +41,7 @@ add_cudaq_library(OptCodeGen
4341
OptCodeGenPassIncGen
4442
OptTransformsPassIncGen
4543
QuakeDialect
44+
cudaq-qir-verifier
4645

4746
LINK_LIBS PUBLIC
4847
CCDialect

lib/Optimizer/CodeGen/ConvertToQIRProfile.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -594,17 +594,10 @@ std::unique_ptr<Pass> cudaq::opt::createQIRProfilePreparationPass() {
594594
//===----------------------------------------------------------------------===//
595595
// The various passes defined here should be added as a pass pipeline.
596596

597-
void cudaq::opt::addQIRProfileVerify(OpPassManager &pm,
598-
llvm::StringRef convertTo) {
599-
VerifyQIRProfileOptions vqpo = {convertTo.str()};
600-
pm.addNestedPass<LLVM::LLVMFuncOp>(createVerifyQIRProfile(vqpo));
601-
}
602-
603597
void cudaq::opt::addQIRProfilePipeline(OpPassManager &pm,
604598
llvm::StringRef convertTo) {
605599
assert(convertTo == "qir-adaptive" || convertTo == "qir-base");
606600
pm.addPass(createQIRProfilePreparationPass());
607601
pm.addNestedPass<LLVM::LLVMFuncOp>(createConvertToQIRFuncPass(convertTo));
608602
pm.addPass(createQIRToQIRProfilePass(convertTo));
609-
addQIRProfileVerify(pm, convertTo);
610603
}

lib/Optimizer/CodeGen/Pipelines.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ struct TargetCodegenPipelineOptions
2222
*this, "loops-may-have-break",
2323
llvm::cl::desc("Enable break statements in loops."),
2424
llvm::cl::init(true)};
25-
PassOptions::Option<bool> appendDeprecatedVerifier{
26-
*this, "append-verifier",
27-
llvm::cl::desc("Append the QIR verifier pipeline."),
28-
llvm::cl::init(false)};
2925
PassOptions::Option<std::string> target{
3026
*this, "convert-to", llvm::cl::desc("Conversion target specifier."),
3127
llvm::cl::init("")};
@@ -107,17 +103,13 @@ void createTargetCodegenPipeline(PassManager &pm,
107103
pm.addPass(createConvertMathToFuncs());
108104
pm.addPass(createSymbolDCEPass());
109105
pm.addPass(cudaq::opt::createCCToLLVM());
110-
if (options.appendDeprecatedVerifier)
111-
cudaq::opt::addQIRProfileVerify(pm, options.target);
112106
}
113107

114108
template <bool isJIT>
115109
void createTargetCodegenPipeline(PassManager &pm, StringRef convertTo) {
116110
auto convertFields = convertTo.split(':');
117111
TargetCodegenPipelineOptions opts;
118112
opts.allowBreaksInLoops = convertFields.first == "qir-adaptive";
119-
opts.appendDeprecatedVerifier =
120-
convertFields.first != "qir" && convertFields.first != "qir-full";
121113
opts.target = convertTo.str();
122114
createTargetCodegenPipeline<isJIT>(pm, opts);
123115
}

0 commit comments

Comments
 (0)