Documentation for microsoft::quantum::IrManipulationTestHelper
microsoft::quantum::IrManipulationTestHelper
Public Types
Name | |
---|---|
using std::string | String |
using std::vector< String > | Strings |
using llvm::LLVMContext | LLVMContext |
using llvm::SMDiagnostic | SMDiagnostic |
using llvm::Module | Module |
using std::unique_ptr< LLVMContext > | ContextPtr |
using std::unique_ptr< Module > | ModulePtr |
using llvm::OptimizationLevel | OptimizationLevel |
using std::shared_ptr< QirAdaptorFactory > | GeneratorPtr |
Public Functions
Name | |
---|---|
IrManipulationTestHelper() =default | |
IrManipulationTestHelper(IrManipulationTestHelper const & ) | |
IrManipulationTestHelper & | operator=(IrManipulationTestHelper const & ) |
IrManipulationTestHelper(IrManipulationTestHelper && ) | |
IrManipulationTestHelper & | operator=(IrManipulationTestHelper && ) |
String | toString() const Generates a string for the IR currently held in the module. |
Strings | toBodyInstructions(String const & block_name ="") Generates a list of instructions for the main function in the module. |
TestProgram | toProgram() |
bool | hasInstructionSequence(Strings const & instructions, String const & block_name ="") |
void | applyQirAdaptor(GeneratorPtr const & generator, OptimizationLevel const & optimization_level =OptimizationLevel::O0, bool debug =false) |
bool | validateQirAdaptor(GeneratorPtr const & generator, String const & target_name ="generic", bool debug =false) |
bool | containsValidationErrors(GeneratorPtr const & generator, String const & target_name, Strings const & errors, bool debug =false) const |
bool | containsExactValidationErrors(GeneratorPtr const & generator, String const & target_name, Strings const & errors, bool debug =false) const |
void | declareOpaque(String const & name) |
void | declareFunction(String const & declaration) |
bool | fromBodyString(String const & body, String const & args ="") |
String | generateScript(String const & body, String const & args ="") const Generates a script given the body of the main function. |
bool | fromString(String const & data) |
String | getErrorMessage() const Gets an error message if the compilation failed. |
bool | isModuleBroken() Whether or not the module is broken. |
ModulePtr & | module() Returns a reference to the module. |
Public Types Documentation
using String
using microsoft::quantum::IrManipulationTestHelper::String = std::string;
using Strings
using microsoft::quantum::IrManipulationTestHelper::Strings = std::vector<String>;
using LLVMContext
using microsoft::quantum::IrManipulationTestHelper::LLVMContext = llvm::LLVMContext;
using SMDiagnostic
using microsoft::quantum::IrManipulationTestHelper::SMDiagnostic = llvm::SMDiagnostic;
using Module
using microsoft::quantum::IrManipulationTestHelper::Module = llvm::Module;
using ContextPtr
using microsoft::quantum::IrManipulationTestHelper::ContextPtr = std::unique_ptr<LLVMContext>;
using ModulePtr
using microsoft::quantum::IrManipulationTestHelper::ModulePtr = std::unique_ptr<Module>;
using OptimizationLevel
using microsoft::quantum::IrManipulationTestHelper::OptimizationLevel = llvm::OptimizationLevel;
using GeneratorPtr
using microsoft::quantum::IrManipulationTestHelper::GeneratorPtr = std::shared_ptr<QirAdaptorFactory>;
Public Functions Documentation
function IrManipulationTestHelper
IrManipulationTestHelper() =default
function IrManipulationTestHelper
IrManipulationTestHelper(
IrManipulationTestHelper const &
)
function operator=
IrManipulationTestHelper & operator=(
IrManipulationTestHelper const &
)
function IrManipulationTestHelper
IrManipulationTestHelper(
IrManipulationTestHelper &&
)
function operator=
IrManipulationTestHelper & operator=(
IrManipulationTestHelper &&
)
function toString
String toString() const
Generates a string for the IR currently held in the module.
function toBodyInstructions
Strings toBodyInstructions(
String const & block_name =""
)
Generates a list of instructions for the main function in the module.
function toProgram
TestProgram toProgram()
function hasInstructionSequence
bool hasInstructionSequence(
Strings const & instructions,
String const & block_name =""
)
Tests whether the main body contains a sequence of instructions. This function ignores instructions in-between the instruction set given. If block name is specified then only instructions within this block are extracted
function applyQirAdaptor
void applyQirAdaptor(
GeneratorPtr const & generator,
OptimizationLevel const & optimization_level =OptimizationLevel::O0,
bool debug =false
)
Applies a adaptor to the module to allow which transforms the IR. This allow us to write small adaptors to test a single piece of transformation.
function validateQirAdaptor
bool validateQirAdaptor(
GeneratorPtr const & generator,
String const & target_name ="generic",
bool debug =false
)
Validates a adaptor to the module to allow which transforms the IR. This allow us to write small adaptors to test a single piece of transformation.
function containsValidationErrors
bool containsValidationErrors(
GeneratorPtr const & generator,
String const & target_name,
Strings const & errors,
bool debug =false
) const
Tests whether a given set of errors (LLVM hints) are present in the validation errors for a specific adaptor. This method only checks if errors are present but does not fail if there are more errors than requested through the API.
function containsExactValidationErrors
bool containsExactValidationErrors(
GeneratorPtr const & generator,
String const & target_name,
Strings const & errors,
bool debug =false
) const
Tests whether a given set of errors (LLVM hints) are present in the validation errors for a specific adaptor. In contrast to containsValidationErrors, this function expect an exact match in the actual and expected errors.
function declareOpaque
void declareOpaque(
String const & name
)
Declares a opaque type. Only the name of the type should be supplied to this function. Example usage
irmanip.declareOpaque("Qubit");
function declareFunction
void declareFunction(
String const & declaration
)
Declares a function. The full signature should be supplied to as the first argument. Example usage
irmanip.declareOpaque("%Result* @__quantum__rt__result_get_zero()");
function fromBodyString
bool fromBodyString(
String const & body,
String const & args =""
)
Creates an LLVM module given a function body. This function makes use of the inputs from IrManipulationTestHelper::declareOpaque and IrManipulationTestHelper::declareFunction to construct the full IR. Example usage:
irmanip.fromBodyString(R"script(
%leftMessage = call %Qubit* @__quantum__rt__qubit_allocate()
call void @__quantum__qis__h__body(%Qubit* %leftMessage)
)script");
Returns false if the IR is invalid.
function generateScript
String generateScript(
String const & body,
String const & args =""
) const
Generates a script given the body of the main function.
function fromString
bool fromString(
String const & data
)
Creates an LLVM module given from a fully specified IR. This function ignores all inputs from IrManipulationTestHelper::declareOpaque and IrManipulationTestHelper::declareFunction.
Returns false if the IR is invalid.
function getErrorMessage
String getErrorMessage() const
Gets an error message if the compilation failed.
function isModuleBroken
bool isModuleBroken()
Whether or not the module is broken.
function module
ModulePtr & module()
Returns a reference to the module.
Updated on 1 August 2023 at 16:25:10 UTC