Documentation for microsoft::quantum::TargetQisMappingPass

microsoft::quantum::TargetQisMappingPass

More...

#include <Passes/TargetQisMappingPass/TargetQisMappingPass.hpp>

Inherits from llvm::PassInfoMixin< TargetQisMappingPass >

Public Types

Name
using ReplacementRule::Replacements Replacements
using llvm::Instruction Instruction
using std::vector< ReplacementRule > Rules
using llvm::Value Value
using ReplacementRule::Builder Builder
using IAllocationManager::AllocationManagerPtr AllocationManagerPtr
using RuleSet::Captures Captures
using std::unordered_map< std::string, llvm::ConstantInt * > ConstantArguments
using ILogger::ILoggerPtr ILoggerPtr
using std::vector< llvm::Instruction * > DeletableInstructions
using std::function< llvm::Value (llvm::Value , DeletableInstructions &)> InstructionModifier

Public Functions

Name
TargetQisMappingPass(RuleSet && rule_set, TargetQisMappingPassConfiguration const & config)
Custom default constructor.
TargetQisMappingPass(TargetQisMappingPass const & )
Copy construction is banned.
TargetQisMappingPass(TargetQisMappingPass && ) =default
We allow move semantics.
~TargetQisMappingPass() =default
Default destruction.
TargetQisMappingPass & operator=(TargetQisMappingPass const & )
Copy assignment is banned.
TargetQisMappingPass & operator=(TargetQisMappingPass && ) =default
Move assignment is permitted.
llvm::PreservedAnalyses run(llvm::Module & module, llvm::ModuleAnalysisManager & mam)
bool runOnFunction(llvm::Function & function, InstructionModifier const & modifier)
void processReplacements()
Applies each of the replacements in the replacements_ variable.
void setupCopyAndExpand()
Configuration function for copy and expand to setup the necessary rules.
void runCopyAndExpand(llvm::Module & module, llvm::ModuleAnalysisManager & mam)
llvm::Value * copyAndExpand(llvm::Value * input, DeletableInstructions & schedule_instruction_deletion)
llvm::Function * expandFunctionCall(llvm::Function & callee, ConstantArguments const & const_args ={})
Copies the function body and replace function arguments whenever arguments are constant.
void constantFoldFunction(llvm::Function & callee)
Folds all constant expression in function.
void addConstExprRule(ReplacementRule && rule)
Helper function to create replacements for constant expressions.
void runDetectActiveCode(llvm::Module & module, llvm::ModuleAnalysisManager & mam)
void runDeleteDeadCode(llvm::Module & module, llvm::ModuleAnalysisManager & mam)
llvm::Value * detectActiveCode(llvm::Value * input, DeletableInstructions & )
llvm::Value * deleteDeadCode(llvm::Value * input, DeletableInstructions & )
bool isActive(llvm::Value * value) const
void followUsers(llvm::Value * value)
void runReplacePhi(llvm::Module & module, llvm::ModuleAnalysisManager & mam)
void runApplyRules(llvm::Module & module, llvm::ModuleAnalysisManager & mam)
bool onQubitRelease(llvm::Instruction * instruction, Captures & captures)
bool onQubitAllocate(llvm::Instruction * instruction, Captures & captures)
void setLogger(ILoggerPtr logger)
bool isRequired()
Whether or not this pass is required to run.

Detailed Description

class microsoft::quantum::TargetQisMappingPass;

This class applies a set of transformation rules to the IR to transform it into a new IR. The rules are added using the RuleSet class which allows the developer to create one or more rules on how to transform the IR.

The module executes the following steps:

┌─────────────────┐
│  Apply adaptor  │
└─────────────────┘
         │                ┌───────────────────────────────┐
         ├───────────────▶│   Copy and expand functions   │──┐
         │     clone      └───────────────────────────────┘  │
         │   functions?                   │ delete dead      │
         │                                ▼    code?         │
         │                ┌───────────────────────────────┐  │
         ├───────────────▶│     Determine active code     │  │
         │  delete dead   └───────────────────────────────┘  │
         │     code?                      │                  │ leave dead
         │                                ▼                  │    code?
         │                ┌───────────────────────────────┐  │
         │                │      Simplify phi nodes       │  │
         │                └───────────────────────────────┘  │
         │                                │                  │
         │                                ▼                  │
         │                ┌───────────────────────────────┐  │
         │                │       Delete dead code        │  │
         │                └───────────────────────────────┘  │
         │                                │                  │
         │                                ▼                  │
         │  fallback      ┌───────────────────────────────┐  │
         └───────────────▶│          Apply rules          │◀─┘
                          └───────────────────────────────┘

Copying and expanding functions identifies function calls and identifies compile time constants passed to the function. It then copies the full implementation of the function, replacing all compile-time constants (and hence changing the function signature). That is, if a function call f(x, 9) is identified, it is replaced with f.1(x) where f.1 is a copy of f with second argument written into the function.

Public Types Documentation

using Replacements

using microsoft::quantum::TargetQisMappingPass::Replacements =  ReplacementRule::Replacements;

using Instruction

using microsoft::quantum::TargetQisMappingPass::Instruction =  llvm::Instruction;

using Rules

using microsoft::quantum::TargetQisMappingPass::Rules =  std::vector<ReplacementRule>;

using Value

using microsoft::quantum::TargetQisMappingPass::Value =  llvm::Value;

using Builder

using microsoft::quantum::TargetQisMappingPass::Builder =  ReplacementRule::Builder;

using AllocationManagerPtr

using microsoft::quantum::TargetQisMappingPass::AllocationManagerPtr =  IAllocationManager::AllocationManagerPtr;

using Captures

using microsoft::quantum::TargetQisMappingPass::Captures =  RuleSet::Captures;

using ConstantArguments

using microsoft::quantum::TargetQisMappingPass::ConstantArguments =  std::unordered_map<std::string, llvm::ConstantInt*>;

using ILoggerPtr

using microsoft::quantum::TargetQisMappingPass::ILoggerPtr =  ILogger::ILoggerPtr;

using DeletableInstructions

using microsoft::quantum::TargetQisMappingPass::DeletableInstructions =  std::vector<llvm::Instruction*>;

using InstructionModifier

using microsoft::quantum::TargetQisMappingPass::InstructionModifier =  std::function<llvm::Value*(llvm::Value*, DeletableInstructions&)>;

Public Functions Documentation

function TargetQisMappingPass

TargetQisMappingPass(
    RuleSet && rule_set,
    TargetQisMappingPassConfiguration const & config
)

Custom default constructor.

function TargetQisMappingPass

TargetQisMappingPass(
    TargetQisMappingPass const & 
)

Copy construction is banned.

function TargetQisMappingPass

TargetQisMappingPass(
    TargetQisMappingPass && 
) =default

We allow move semantics.

function ~TargetQisMappingPass

~TargetQisMappingPass() =default

Default destruction.

function operator=

TargetQisMappingPass & operator=(
    TargetQisMappingPass const & 
)

Copy assignment is banned.

function operator=

TargetQisMappingPass & operator=(
    TargetQisMappingPass && 
) =default

Move assignment is permitted.

function run

llvm::PreservedAnalyses run(
    llvm::Module & module,
    llvm::ModuleAnalysisManager & mam
)

Implements the transformation analysis which uses the supplied ruleset to make substitutions in each function.

function runOnFunction

bool runOnFunction(
    llvm::Function & function,
    InstructionModifier const & modifier
)

Generic function to apply a instructionModifier (lambda function) to every instruction in the function function. This method follows the execution path to the extend possible and deals with branching if the branch statement can be evaluated at compile time.

function processReplacements

void processReplacements()

Applies each of the replacements in the replacements_ variable.

function setupCopyAndExpand

void setupCopyAndExpand()

Configuration function for copy and expand to setup the necessary rules.

function runCopyAndExpand

void runCopyAndExpand(
    llvm::Module & module,
    llvm::ModuleAnalysisManager & mam
)

Main function for running the copy and expand functionality. This function first identifies the entry point and then follows every execution path to copy the callee function for every call instruction encountered. This makes that every call in the code has its own unique callee function which ensures that when allocating qubits or results, the assigned registers are not accidentally reused.

function copyAndExpand

llvm::Value * copyAndExpand(
    llvm::Value * input,
    DeletableInstructions & schedule_instruction_deletion
)

Test whether the instruction is a call instruction and copy the callee in case it is. This function collects instructions which are scheduled for deletion at a later point.

function expandFunctionCall

llvm::Function * expandFunctionCall(
    llvm::Function & callee,
    ConstantArguments const & const_args ={}
)

Copies the function body and replace function arguments whenever arguments are constant.

function constantFoldFunction

void constantFoldFunction(
    llvm::Function & callee
)

Folds all constant expression in function.

function addConstExprRule

void addConstExprRule(
    ReplacementRule && rule
)

Helper function to create replacements for constant expressions.

function runDetectActiveCode

void runDetectActiveCode(
    llvm::Module & module,
    llvm::ModuleAnalysisManager & mam
)

function runDeleteDeadCode

void runDeleteDeadCode(
    llvm::Module & module,
    llvm::ModuleAnalysisManager & mam
)

function detectActiveCode

llvm::Value * detectActiveCode(
    llvm::Value * input,
    DeletableInstructions & 
)

function deleteDeadCode

llvm::Value * deleteDeadCode(
    llvm::Value * input,
    DeletableInstructions & 
)

function isActive

bool isActive(
    llvm::Value * value
) const

function followUsers

void followUsers(
    llvm::Value * value
)

function runReplacePhi

void runReplacePhi(
    llvm::Module & module,
    llvm::ModuleAnalysisManager & mam
)

Function which replaces phi nodes which refer to inactive blocks. That is, in cases where branch statement evaluates at compile time, only one block will be marked as active. For those case we can eliminate the phi nodes. In the case where branch statements cannot be evaluated all are marked as active. In this case, phi nodes are left unchanged.

function runApplyRules

void runApplyRules(
    llvm::Module & module,
    llvm::ModuleAnalysisManager & mam
)

function onQubitRelease

bool onQubitRelease(
    llvm::Instruction * instruction,
    Captures & captures
)

function onQubitAllocate

bool onQubitAllocate(
    llvm::Instruction * instruction,
    Captures & captures
)

function setLogger

void setLogger(
    ILoggerPtr logger
)

function isRequired

static bool isRequired()

Whether or not this pass is required to run.


Updated on 1 August 2023 at 16:25:10 UTC