forked from NVIDIA/cuda-quantum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The QIR codegen is one of the oldest pieces of the project and really
shows its age at this point. It was written before much of the rest of the core was implemented or even designed. These changes replace the existing QIR codegen for the C++ compiler. Unfortunately, there are a number of semantics violations from Python that need to be fixed before it can be switched over. Therefore, this PR leaves Python intact and using the old codegen passes. The purpose of these changes is two-fold. 1. Instead of converting all of the IR to the LLVM-IR dialect at the same time as converting to QIR, these two steps are bifurcated. This allows us to convert the quake dialect to other higher level operations first and before LLVM-IR dialect is introduced. This will be beneficial in short order... 2. Instead of piecemealing different flavors of QIR in completely ad hoc spaghetti plate passes, the flavor of QIR is specified as a mixin modifier class for a singular set of steps to convert to any flavor of QIR. This does mean that one will no longer be able to convert to the LLVM-IR dialect with QIR calls and then change their mind from chocolate QIR to strawberry QIR much later. Notes: - Remove the option to disable the qir profile preparation pass. This pass is not optional. The IR will be translated to an invalid state if the required function declarations are not created at all. - Make it clear that AggressiveEarlyInlining is a pipeline. Refactor the registration functions so that we're not block-copying things between the core and python (which was dropping things on the floor already). - Add a new pass, convert to QIR API. This pass will replace the cascade of passes to convert to full QIR and then convert some more to base profile or adaptive profile. - Refactor QIRFunctionNames.h. - Add a raft of declarations to the intrinsics table. This will dramatically reduce the amount of code in codegen and make maintenance much easier. - Add the analysis and prep pass. - Improve pipeline locality and performance. - Use the new code in the default code gen path for C++. - Workarounds for issue NVIDIA#2541 and issue NVIDIA#2539. Keep the old codegen for python. Too many bugs. - Update tests. Fix bugs in mock servers. Have python kernel builder add the cudaq-kernel attribute. (See issue 2541.) Signed-off-by: Eric Schweitz <[email protected]>
- Loading branch information
1 parent
7903c8b
commit 12a59ca
Showing
118 changed files
with
3,705 additions
and
1,126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/****************************************************************-*- C++ -*-**** | ||
* Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. * | ||
* All rights reserved. * | ||
* * | ||
* This source code and the accompanying materials are made available under * | ||
* the terms of the Apache License 2.0 which accompanies this distribution. * | ||
******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
/// This file provides the opaque struct types to be used with the obsolete LLVM | ||
/// typed pointer type. | ||
|
||
#include "mlir/Conversion/LLVMCommon/TypeConverter.h" | ||
#include "mlir/Dialect/LLVMIR/LLVMTypes.h" | ||
|
||
namespace cudaq { | ||
inline mlir::Type getQuantumTypeByName(mlir::StringRef type, | ||
mlir::MLIRContext *context) { | ||
return mlir::LLVM::LLVMStructType::getOpaque(type, context); | ||
} | ||
|
||
namespace opt { | ||
|
||
// The following type creators are deprecated and should only be used in the | ||
// older codegen passes. Use the creators in the cg namespace immediately below | ||
// instead. | ||
inline mlir::Type getOpaquePointerType(mlir::MLIRContext *context) { | ||
return mlir::LLVM::LLVMPointerType::get(context); | ||
} | ||
|
||
inline mlir::Type getQubitType(mlir::MLIRContext *context) { | ||
return mlir::LLVM::LLVMPointerType::get( | ||
getQuantumTypeByName("Qubit", context)); | ||
} | ||
|
||
inline mlir::Type getArrayType(mlir::MLIRContext *context) { | ||
return mlir::LLVM::LLVMPointerType::get( | ||
getQuantumTypeByName("Array", context)); | ||
} | ||
|
||
inline mlir::Type getResultType(mlir::MLIRContext *context) { | ||
return mlir::LLVM::LLVMPointerType::get( | ||
getQuantumTypeByName("Result", context)); | ||
} | ||
|
||
inline mlir::Type getCharPointerType(mlir::MLIRContext *context) { | ||
return mlir::LLVM::LLVMPointerType::get(mlir::IntegerType::get(context, 8)); | ||
} | ||
|
||
void initializeTypeConversions(mlir::LLVMTypeConverter &typeConverter); | ||
|
||
} // namespace opt | ||
|
||
namespace cg { | ||
|
||
// The following type creators replace the ones above. They are configurable on | ||
// the fly to either use opaque structs or opaque pointers. The default is to | ||
// use pointers to opaque structs, which is no longer supported in modern LLVM. | ||
|
||
inline mlir::Type getOpaquePointerType(mlir::MLIRContext *context) { | ||
return cc::PointerType::get(mlir::NoneType::get(context)); | ||
} | ||
|
||
inline mlir::Type getQubitType(mlir::MLIRContext *context, | ||
bool useOpaquePtr = false) { | ||
if (useOpaquePtr) | ||
return getOpaquePointerType(context); | ||
return cc::PointerType::get(getQuantumTypeByName("Qubit", context)); | ||
} | ||
|
||
inline mlir::Type getArrayType(mlir::MLIRContext *context, | ||
bool useOpaquePtr = false) { | ||
if (useOpaquePtr) | ||
return getOpaquePointerType(context); | ||
return cc::PointerType::get(getQuantumTypeByName("Array", context)); | ||
} | ||
|
||
inline mlir::Type getResultType(mlir::MLIRContext *context, | ||
bool useOpaquePtr = false) { | ||
if (useOpaquePtr) | ||
return getOpaquePointerType(context); | ||
return cc::PointerType::get(getQuantumTypeByName("Result", context)); | ||
} | ||
|
||
inline mlir::Type getCharPointerType(mlir::MLIRContext *context, | ||
bool useOpaquePtr = false) { | ||
if (useOpaquePtr) | ||
return getOpaquePointerType(context); | ||
return cc::PointerType::get(mlir::IntegerType::get(context, 8)); | ||
} | ||
|
||
} // namespace cg | ||
} // namespace cudaq |
File renamed without changes.
Oops, something went wrong.