Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Passes/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ doxygen:


linux-docker:
docker build -f Docker/CI.Ubuntu20.dockerfile -t qir-passes-ubuntu:latest .
docker build --no-cache -f Docker/CI.Ubuntu20.dockerfile -t qir-passes-ubuntu:latest .

linux-ci: linux-docker
docker run -it --rm -t qir-passes-ubuntu:latest ./manage runci
Expand Down
2 changes: 1 addition & 1 deletion src/Passes/Source/Apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_executable(qat Qat/Qat.cpp Qat/QatConfig.cpp)

target_link_libraries(qat ${llvm_libs})
target_link_libraries(qat TransformationRulesPass Rules AllocationManager Commandline Generators Profile Validator ValidationPass)
target_link_libraries(qat Logging TransformationRulesPass Rules AllocationManager Commandline Generators Profile Validator ValidationPass )
20 changes: 12 additions & 8 deletions src/Passes/Source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
cmake_minimum_required(VERSION 3.4.3)

microsoft_add_library(Logging)

microsoft_add_library(TestTools)
microsoft_add_library_tests(TestTools Generators)
microsoft_add_library_tests(TestTools Generators Logging)

microsoft_add_library(Commandline)
microsoft_add_library_tests(Commandline)
microsoft_add_library_tests(Commandline Logging)

microsoft_add_library(Profile)
microsoft_add_library_tests(Profile)

microsoft_add_library(Validator)
microsoft_add_library_tests(Validator ValidationPass)
microsoft_add_library(ValidationPass)
target_link_libraries(Validator PRIVATE Logging)

microsoft_add_library_tests(Validator ValidationPass Logging)
microsoft_add_library(ValidationPass Logging)

microsoft_add_library(AllocationManager)
microsoft_add_library_tests(AllocationManager)
microsoft_add_library_tests(AllocationManager Logging)

microsoft_add_library(TransformationRulesPass)
target_link_libraries(TransformationRulesPass PRIVATE Rules Commandline AllocationManager)
microsoft_add_library_tests(TransformationRulesPass Rules TransformationRulesPass AllocationManager Commandline Generators Validator ValidationPass)
microsoft_add_library_tests(TransformationRulesPass Rules TransformationRulesPass AllocationManager Commandline Generators Validator ValidationPass Logging)


microsoft_add_library(Rules)
microsoft_add_library_tests(Rules Rules TransformationRulesPass AllocationManager Commandline Generators)
microsoft_add_library_tests(Rules Rules TransformationRulesPass AllocationManager Commandline Generators Logging)

target_link_libraries(Rules PRIVATE AllocationManager)

microsoft_add_library(Generators)
target_link_libraries(Generators PRIVATE Rules Commandline AllocationManager TransformationRulesPass Profile Validator ValidationPass)
microsoft_add_library_tests(Generators Rules TransformationRulesPass AllocationManager Commandline Generators)
microsoft_add_library_tests(Generators Rules TransformationRulesPass AllocationManager Commandline Generators Logging)

add_subdirectory(Apps)
53 changes: 53 additions & 0 deletions src/Passes/Source/Logging/CommentLogger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#include "Logging/CommentLogger.hpp"

#include "Llvm/Llvm.hpp"

#include <vector>

namespace microsoft
{
namespace quantum
{

void CommentLogger::debug(String const& message)
{
llvm::errs() << "debug - " << location_name_ << ":" << location_row_ << "," << location_col_ << " - " << message
<< "\n";
}

void CommentLogger::info(String const& message)
{
llvm::errs() << "info - " << location_name_ << ":" << location_row_ << "," << location_col_ << " - " << message
<< "\n";
}

void CommentLogger::warning(String const& message)
{
llvm::errs() << "warning - " << location_name_ << ":" << location_row_ << "," << location_col_ << " - "
<< message << "\n";
}

void CommentLogger::error(String const& message)
{
llvm::errs() << "error - " << location_name_ << ":" << location_row_ << "," << location_col_ << " - " << message
<< "\n";
}

void CommentLogger::internalError(String const& message)
{
llvm::errs() << "internal error - " << location_name_ << ":" << location_row_ << "," << location_col_ << " - "
<< message << "\n";
}

void CommentLogger::setLocation(String const& name, uint64_t row, uint64_t col)
{
location_name_ = name;
location_row_ = row;
location_col_ = col;
}

} // namespace quantum
} // namespace microsoft
46 changes: 46 additions & 0 deletions src/Passes/Source/Logging/CommentLogger.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#include "Logging/ILogger.hpp"

#include <vector>

namespace microsoft
{
namespace quantum
{

/// Concrete ILogger implementation that prints all messages as IR comments to llvm::errs().
class CommentLogger : public ILogger
{
public:
// Interface implementation
//

/// Adds a debug message to the list.
void debug(String const& message) override;

/// Adds an info message to the list.
void info(String const& message) override;

/// Adds a warning message to the list.
void warning(String const& message) override;

/// Adds an error message to the list.
void error(String const& message) override;

/// Adds an internal error message to the list.
void internalError(String const& message) override;

/// Function that allows to set the current location.
void setLocation(String const& name, uint64_t row, uint64_t col) override;

private:
String location_name_{""};
uint64_t location_row_{0};
uint64_t location_col_{0};
};

} // namespace quantum
} // namespace microsoft
15 changes: 15 additions & 0 deletions src/Passes/Source/Logging/ILogger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#include "Logging/ILogger.hpp"

#include <cstdint>
#include <string>

namespace microsoft
{
namespace quantum
{
ILogger::~ILogger() = default;
}
} // namespace microsoft
2 changes: 1 addition & 1 deletion src/Passes/Source/Logging/ILogger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace quantum
ILogger& operator=(ILogger const&) = default;
ILogger& operator=(ILogger&&) = default;

virtual ~ILogger() = default;
virtual ~ILogger();

// Abstract interface methods
//
Expand Down
5 changes: 5 additions & 0 deletions src/Passes/Source/Logging/LogCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,10 @@ namespace quantum
current_location_.col = col;
}

LogCollection::Messages const& LogCollection::messages() const
{
return messages_;
}

} // namespace quantum
} // namespace microsoft
3 changes: 3 additions & 0 deletions src/Passes/Source/Logging/LogCollection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ namespace quantum
/// Function that allows to set the current location.
void setLocation(String const& name, uint64_t row, uint64_t col) override;

/// Accessor to the messages
Messages const& messages() const;

private:
Location current_location_{}; ///< Holds current location.
Messages messages_; ///< All messages emitted.
Expand Down
20 changes: 17 additions & 3 deletions src/Passes/Source/Rules/Factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,11 +632,25 @@ namespace quantum

void RuleFactory::disableStringSupport()
{
removeFunctionCall("__quantum__rt__fail");
removeFunctionCall("__quantum__rt__message");
removeFunctionCall("__quantum__rt__string_update_alias_count");

removeFunctionCall("__quantum__rt__string_create");
removeFunctionCall("__quantum__rt__string_get_data");
removeFunctionCall("__quantum__rt__string_get_length");
removeFunctionCall("__quantum__rt__string_update_reference_count");
removeFunctionCall("__quantum__rt__string_update_alias_count");
removeFunctionCall("__quantum__rt__message");
removeFunctionCall("__quantum__rt__fail");
removeFunctionCall("__quantum__rt__string_concatenate");
removeFunctionCall("__quantum__rt__string_equal");

removeFunctionCall("__quantum__rt__int_to_string");
removeFunctionCall("__quantum__rt__double_to_string");
removeFunctionCall("__quantum__rt__bool_to_string");
removeFunctionCall("__quantum__rt__result_to_string");
removeFunctionCall("__quantum__rt__pauli_to_string");
removeFunctionCall("__quantum__rt__qubit_to_string");
removeFunctionCall("__quantum__rt__range_to_string");
removeFunctionCall("__quantum__rt__bigint_to_string");
}

ReplacementRulePtr RuleFactory::addRule(ReplacementRule&& rule)
Expand Down
73 changes: 73 additions & 0 deletions src/Passes/Source/Rules/Notation/Call.hpp.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#pragma once
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

/// @defgroup shorthandNotation Shorthand Notation

<<<<<<< HEAD
#include "Rules/Notation/Call.ipp"
#include "Rules/Notation/Phi.ipp"
#include "Rules/Patterns/AnyPattern.hpp"
#include "Rules/Patterns/CallPattern.hpp"
#include "Rules/Patterns/Instruction.hpp"
#include "Rules/Patterns/PhiPattern.hpp"
=======
#include "Rules/IOperandPrototype.hpp"
>>>>>>> main

#include "Llvm/Llvm.hpp"

#include <unordered_map>
#include <vector>

namespace microsoft
{
namespace quantum
{
namespace notation
{

using IOperandPrototypePtr = std::shared_ptr<IOperandPrototype>;

/// Shorthand notations are made to make it possible to match patterns in the QIR. This part of the
/// library focuses on making it easy to express advance patterns in just a few lines and specify
/// what parts of the IR is of interest to the replacer function. An example is following pattern
///
/// ```
/// auto get_one = call("__quantum__rt__result_get_one");
/// addRule(
/// {branch("cond"_cap = call("__quantum__rt__result_equal", "result"_cap = _, "one"_cap =
/// get_one), _, _),
/// replace_branch_positive});
///
/// ```
///
/// which matches IRs of the form
///
/// ```
/// %1 = call %Result* @__quantum__rt__result_get_one()
/// %2 = call i1 @__quantum__rt__result_equal(%Result* %0, %Result* %1)
/// br i1 %2, label %then0__1, label %continue__1
/// ```
///
/// The pattern futher specifies that as a successful match is obtained, a table capturing
/// certain values must be created. In the above example, the table would contain three
/// entries: `cond`, `result` and `one` each of which would point to a a llvm::Value*
/// in the QIR. This allows the replacement function to easily manipulate the DAG in these
/// three places (four if you include the main captured value which is always passed to the
/// replacement function).

/// Shorthand notation to match an instruction for a function call.
/// The resulting IOperandPrototype matches a function call with arguments
/// as specified by the arguments given. For instance,
///
/// ```
/// addRule({call("foo", _, _), deleteInstruction()});
/// ```
///
/// matches a call to the function `foo` with exactly two arguments.
template <typename... Args> IOperandPrototypePtr call(std::string const& name, Args... args);

} // namespace notation
} // namespace quantum
} // namespace microsoft
2 changes: 2 additions & 0 deletions src/Passes/Source/Rules/Notation/Notation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace quantum
{
return [](ReplacementRule::Builder&, ReplacementRule::Value* val, ReplacementRule::Captures&,
ReplacementRule::Replacements& replacements) {
auto type = val->getType();
val->replaceAllUsesWith(llvm::UndefValue::get(type));
replacements.push_back({llvm::dyn_cast<llvm::Instruction>(val), nullptr});
return true;
};
Expand Down
2 changes: 1 addition & 1 deletion src/Passes/Source/TestTools/IrManipulationTestHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ source_filename = "IrManipulationTestHelper.ll"
{
script += "declare " + op + "\n";
}
script += "\nattributes #0 = { \"EntryPoint\" }\n";
script += "\nattributes #0 = { \"InteropFriendly\" }\n";
return script;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ namespace quantum
}
else
{

// Otherwise we apply to all sections of the code.
replacements_.clear();
for (auto& function : module)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace quantum
bool clone_functions_{true};
bool transform_execution_path_only_{true};
uint64_t max_recursion_{512};
std::string entry_point_attr_{"EntryPoint"};
std::string entry_point_attr_{"InteropFriendly"};

bool simplify_prior_transformation_{true};

Expand Down
7 changes: 4 additions & 3 deletions src/Passes/Source/ValidationPass/ValidationPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace quantum
{
opcodes_[opname] = 1;
}

auto call_instr = llvm::dyn_cast<llvm::CallBase>(&instr);
if (call_instr != nullptr)
{
Expand Down Expand Up @@ -75,7 +76,7 @@ namespace quantum
{
if (allowed_ops.find(k.first) == allowed_ops.end())
{
llvm::errs() << "; Error: '" << k.first << "' is not allowed for this profile.\n";
logger_->error("'" + k.first + "' is not allowed for this profile.");
}
}
}
Expand All @@ -87,14 +88,14 @@ namespace quantum
{
if (allowed_functions.find(k.first) == allowed_functions.end())
{
llvm::errs() << "; Error: '" << k.first << "' is not allowed for this profile.\n";
logger_->error("'" + k.first + "' is not allowed for this profile.");
}
}
}

if (!config_.allowInternalCalls() && !internal_calls_.empty())
{
llvm::errs() << "; Error: Calls to custom defined functions not allowed\n";
logger_->error("Calls to custom defined functions not allowed.");
raise_exception = true;
}

Expand Down
Loading