Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 5e38090

Browse files
authored
Updates for QIR validation (#1250)
* Type renaming * Removing redudant setModulePassManager * Fixing recursion * Refactoring filenames * Renaming directory * Updating names and files * Formatting * Changing default to interop friendly * Updating base profile * Styling * Updating logger * Fixing style * Removing comment * Moving testing to run before linting * Updating CMake * Attempting to solve tests issue * Updating according to PR comments
1 parent d77793c commit 5e38090

24 files changed

+537
-62
lines changed

src/Passes/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ doxygen:
1515

1616

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

2020
linux-ci: linux-docker
2121
docker run -it --rm -t qir-passes-ubuntu:latest ./manage runci
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
add_executable(qat Qat/Qat.cpp Qat/QatConfig.cpp)
22

33
target_link_libraries(qat ${llvm_libs})
4-
target_link_libraries(qat TransformationRulesPass Rules AllocationManager Commandline Generators Profile Validator ValidationPass)
4+
target_link_libraries(qat Logging TransformationRulesPass Rules AllocationManager Commandline Generators Profile Validator ValidationPass )

src/Passes/Source/CMakeLists.txt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
11
cmake_minimum_required(VERSION 3.4.3)
22

3+
microsoft_add_library(Logging)
4+
35
microsoft_add_library(TestTools)
4-
microsoft_add_library_tests(TestTools Generators)
6+
microsoft_add_library_tests(TestTools Generators Logging)
57

68
microsoft_add_library(Commandline)
7-
microsoft_add_library_tests(Commandline)
9+
microsoft_add_library_tests(Commandline Logging)
810

911
microsoft_add_library(Profile)
1012
microsoft_add_library_tests(Profile)
1113

1214
microsoft_add_library(Validator)
13-
microsoft_add_library_tests(Validator ValidationPass)
14-
microsoft_add_library(ValidationPass)
15+
target_link_libraries(Validator PRIVATE Logging)
16+
17+
microsoft_add_library_tests(Validator ValidationPass Logging)
18+
microsoft_add_library(ValidationPass Logging)
1519

1620
microsoft_add_library(AllocationManager)
17-
microsoft_add_library_tests(AllocationManager)
21+
microsoft_add_library_tests(AllocationManager Logging)
1822

1923
microsoft_add_library(TransformationRulesPass)
2024
target_link_libraries(TransformationRulesPass PRIVATE Rules Commandline AllocationManager)
21-
microsoft_add_library_tests(TransformationRulesPass Rules TransformationRulesPass AllocationManager Commandline Generators Validator ValidationPass)
25+
microsoft_add_library_tests(TransformationRulesPass Rules TransformationRulesPass AllocationManager Commandline Generators Validator ValidationPass Logging)
2226

2327

2428
microsoft_add_library(Rules)
25-
microsoft_add_library_tests(Rules Rules TransformationRulesPass AllocationManager Commandline Generators)
29+
microsoft_add_library_tests(Rules Rules TransformationRulesPass AllocationManager Commandline Generators Logging)
2630

2731
target_link_libraries(Rules PRIVATE AllocationManager)
2832

2933
microsoft_add_library(Generators)
3034
target_link_libraries(Generators PRIVATE Rules Commandline AllocationManager TransformationRulesPass Profile Validator ValidationPass)
31-
microsoft_add_library_tests(Generators Rules TransformationRulesPass AllocationManager Commandline Generators)
35+
microsoft_add_library_tests(Generators Rules TransformationRulesPass AllocationManager Commandline Generators Logging)
3236

3337
add_subdirectory(Apps)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
#include "Logging/CommentLogger.hpp"
5+
6+
#include "Llvm/Llvm.hpp"
7+
8+
#include <vector>
9+
10+
namespace microsoft
11+
{
12+
namespace quantum
13+
{
14+
15+
void CommentLogger::debug(String const& message)
16+
{
17+
llvm::errs() << "debug - " << location_name_ << ":" << location_row_ << "," << location_col_ << " - " << message
18+
<< "\n";
19+
}
20+
21+
void CommentLogger::info(String const& message)
22+
{
23+
llvm::errs() << "info - " << location_name_ << ":" << location_row_ << "," << location_col_ << " - " << message
24+
<< "\n";
25+
}
26+
27+
void CommentLogger::warning(String const& message)
28+
{
29+
llvm::errs() << "warning - " << location_name_ << ":" << location_row_ << "," << location_col_ << " - "
30+
<< message << "\n";
31+
}
32+
33+
void CommentLogger::error(String const& message)
34+
{
35+
llvm::errs() << "error - " << location_name_ << ":" << location_row_ << "," << location_col_ << " - " << message
36+
<< "\n";
37+
}
38+
39+
void CommentLogger::internalError(String const& message)
40+
{
41+
llvm::errs() << "internal error - " << location_name_ << ":" << location_row_ << "," << location_col_ << " - "
42+
<< message << "\n";
43+
}
44+
45+
void CommentLogger::setLocation(String const& name, uint64_t row, uint64_t col)
46+
{
47+
location_name_ = name;
48+
location_row_ = row;
49+
location_col_ = col;
50+
}
51+
52+
} // namespace quantum
53+
} // namespace microsoft
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#pragma once
2+
// Copyright (c) Microsoft Corporation.
3+
// Licensed under the MIT License.
4+
5+
#include "Logging/ILogger.hpp"
6+
7+
#include <vector>
8+
9+
namespace microsoft
10+
{
11+
namespace quantum
12+
{
13+
14+
/// Concrete ILogger implementation that prints all messages as IR comments to llvm::errs().
15+
class CommentLogger : public ILogger
16+
{
17+
public:
18+
// Interface implementation
19+
//
20+
21+
/// Adds a debug message to the list.
22+
void debug(String const& message) override;
23+
24+
/// Adds an info message to the list.
25+
void info(String const& message) override;
26+
27+
/// Adds a warning message to the list.
28+
void warning(String const& message) override;
29+
30+
/// Adds an error message to the list.
31+
void error(String const& message) override;
32+
33+
/// Adds an internal error message to the list.
34+
void internalError(String const& message) override;
35+
36+
/// Function that allows to set the current location.
37+
void setLocation(String const& name, uint64_t row, uint64_t col) override;
38+
39+
private:
40+
String location_name_{""};
41+
uint64_t location_row_{0};
42+
uint64_t location_col_{0};
43+
};
44+
45+
} // namespace quantum
46+
} // namespace microsoft
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
#include "Logging/ILogger.hpp"
5+
6+
#include <cstdint>
7+
#include <string>
8+
9+
namespace microsoft
10+
{
11+
namespace quantum
12+
{
13+
ILogger::~ILogger() = default;
14+
}
15+
} // namespace microsoft

src/Passes/Source/Logging/ILogger.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace quantum
2626
ILogger& operator=(ILogger const&) = default;
2727
ILogger& operator=(ILogger&&) = default;
2828

29-
virtual ~ILogger() = default;
29+
virtual ~ILogger();
3030

3131
// Abstract interface methods
3232
//

src/Passes/Source/Logging/LogCollection.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,10 @@ namespace quantum
4242
current_location_.col = col;
4343
}
4444

45+
LogCollection::Messages const& LogCollection::messages() const
46+
{
47+
return messages_;
48+
}
49+
4550
} // namespace quantum
4651
} // namespace microsoft

src/Passes/Source/Logging/LogCollection.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ namespace quantum
6666
/// Function that allows to set the current location.
6767
void setLocation(String const& name, uint64_t row, uint64_t col) override;
6868

69+
/// Accessor to the messages
70+
Messages const& messages() const;
71+
6972
private:
7073
Location current_location_{}; ///< Holds current location.
7174
Messages messages_; ///< All messages emitted.

src/Passes/Source/Rules/Factory.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,11 +632,25 @@ namespace quantum
632632

633633
void RuleFactory::disableStringSupport()
634634
{
635+
removeFunctionCall("__quantum__rt__fail");
636+
removeFunctionCall("__quantum__rt__message");
637+
removeFunctionCall("__quantum__rt__string_update_alias_count");
638+
635639
removeFunctionCall("__quantum__rt__string_create");
640+
removeFunctionCall("__quantum__rt__string_get_data");
641+
removeFunctionCall("__quantum__rt__string_get_length");
636642
removeFunctionCall("__quantum__rt__string_update_reference_count");
637-
removeFunctionCall("__quantum__rt__string_update_alias_count");
638-
removeFunctionCall("__quantum__rt__message");
639-
removeFunctionCall("__quantum__rt__fail");
643+
removeFunctionCall("__quantum__rt__string_concatenate");
644+
removeFunctionCall("__quantum__rt__string_equal");
645+
646+
removeFunctionCall("__quantum__rt__int_to_string");
647+
removeFunctionCall("__quantum__rt__double_to_string");
648+
removeFunctionCall("__quantum__rt__bool_to_string");
649+
removeFunctionCall("__quantum__rt__result_to_string");
650+
removeFunctionCall("__quantum__rt__pauli_to_string");
651+
removeFunctionCall("__quantum__rt__qubit_to_string");
652+
removeFunctionCall("__quantum__rt__range_to_string");
653+
removeFunctionCall("__quantum__rt__bigint_to_string");
640654
}
641655

642656
ReplacementRulePtr RuleFactory::addRule(ReplacementRule&& rule)

0 commit comments

Comments
 (0)