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
Show all changes
54 commits
Select commit Hold shift + click to select a range
e7402c5
Adding Python to the CI process
troels-im Aug 2, 2021
7c8acd6
Creating development script
troels-im Aug 2, 2021
330da4b
Udpating development script
troels-im Aug 2, 2021
2628e75
Disabling Linux for the time being
troels-im Aug 2, 2021
730decd
Reactivating linux CI
troels-im Aug 2, 2021
fafdab5
Removing the need for virtualenv
troels-im Aug 2, 2021
8eb3909
Updating linux image
troels-im Aug 2, 2021
6c8627b
Updating name of linux build
troels-im Aug 2, 2021
8ab6158
Updating name of linux build
troels-im Aug 2, 2021
6a2f111
Updating working directory
troels-im Aug 2, 2021
50d753b
Updating scripts
troels-im Aug 2, 2021
62955a4
Fixing linux path and updating clang search function
troels-im Aug 2, 2021
25f402e
Upgrading clang-format to version 11
troels-im Aug 2, 2021
65bde43
Formatting to LLVM 11 toolchain
troels-im Aug 2, 2021
c7bde93
Removing visibility check in CMake
troels-im Aug 2, 2021
8e3b886
Forcing Clang as compiler
troels-im Aug 2, 2021
1ce8619
Removing llvm-toolchain-11
troels-im Aug 2, 2021
47897bc
Improving search for clang tidy
troels-im Aug 2, 2021
2c0504a
Extending Clang tidy search
troels-im Aug 2, 2021
1c70da9
Fixing apt install
troels-im Aug 2, 2021
60e0a02
Fixing apt install
troels-im Aug 2, 2021
008c9d4
Refactoring names and updating windows
troels-im Aug 2, 2021
ce61df0
Minor Windows CI update
troels-im Aug 2, 2021
54d8725
Improving search for excutables
troels-im Aug 2, 2021
b992737
Adding Windos debug and OS X CI
troels-im Aug 2, 2021
4e191d0
Fixing OS X tests
troels-im Aug 2, 2021
f69e473
Updating links and paths to executables
troels-im Aug 2, 2021
d1f79f5
Updating OS X build
troels-im Aug 2, 2021
25b8dd9
Attempting to fix Windows build
troels-im Aug 2, 2021
c37361a
Fixing CMake config
troels-im Aug 2, 2021
81ed163
Attempting to fix Windows path
troels-im Aug 2, 2021
abd1c7c
Adding message to CMake
troels-im Aug 2, 2021
05d01c2
Updating with VCWhere
troels-im Aug 2, 2021
4dc626f
Updating CI for Windows
troels-im Aug 2, 2021
0acead5
Disabling CMake install
troels-im Aug 2, 2021
287fffd
Changing to Conda package manager
troels-im Aug 2, 2021
0cca8ec
Adding conda environment
troels-im Aug 2, 2021
69c7c62
Adding conda environment
troels-im Aug 2, 2021
b2e5059
Updating the environment
troels-im Aug 2, 2021
5df0095
Updating conda
troels-im Aug 2, 2021
76cad51
Attempting to load LLVM in CMake
troels-im Aug 2, 2021
be473a6
Disbaling Windows CI
troels-im Aug 4, 2021
f622d68
Update build/test.ps1
troels-im Aug 5, 2021
7bb0516
Update build/passes-linux.yml
troels-im Aug 5, 2021
20b15d4
Update src/Passes/site-packages/TasksCI/toolchain.py
troels-im Aug 5, 2021
2b81233
Update build/passes-linux.yml
troels-im Aug 6, 2021
b534ee2
Update build/passes-linux.yml
troels-im Aug 6, 2021
4e50ac1
Update build/passes-linux.yml
troels-im Aug 6, 2021
2ab0638
Update build/passes-linux.yml
troels-im Aug 6, 2021
0c89e25
Merge branch 'features/llvm-passes' into feature/passes-ci-integration
bettinaheim Aug 10, 2021
429e521
Build issue
bettinaheim Aug 10, 2021
bb2a40e
Fixing style
troels-im Aug 10, 2021
16d4cd3
Fixing style
troels-im Aug 10, 2021
43a97f8
Fixing missing function
troels-im Aug 10, 2021
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
18 changes: 16 additions & 2 deletions build/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,27 @@ schedules:
- main
always: true

pool:
vmImage: windows-latest

jobs:
- job: Build
steps:
- template: init.yml
- template: steps.yml
- template: wrap-up.yml
pool:
vmImage: windows-latest

- job: LinuxBuild
steps:
- template: passes-linux.yml
pool:
vmImage: ubuntu-20.04

- job: MacOSBuild
steps:
- template: passes-mac.yml
pool:
vmImage: macOS-latest

- job: Style
steps:
Expand All @@ -43,3 +55,5 @@ jobs:

- script: dotnet tool run fantomas -- --check --recurse .
displayName: Fantomas
pool:
vmImage: windows-latest
6 changes: 6 additions & 0 deletions build/init.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ steps:
inputs:
command: 'custom'
customCommand: 'install -g npm@latest'

- task: UsePythonVersion@0
inputs:
versionSpec: "3.9"
addToPath: true
architecture: "x64"
14 changes: 14 additions & 0 deletions build/passes-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

steps:
- script: |
sudo apt update -y
sudo apt install -y clang-11 cmake clang-format-11 clang-tidy-11
sudo apt-get install -y llvm-11 lldb-11 llvm-11-dev libllvm11 llvm-11-runtime
export CC=clang-11
export CXX=clang++
cd src/Passes/

pip install -r requirements.txt
chmod +x manage
./manage runci
displayName: Linux build and CI for passes
19 changes: 19 additions & 0 deletions build/passes-mac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

steps:
- script: |
brew install llvm@11
brew install cmake
brew install [email protected]
brew unlink [email protected] && brew link [email protected]

# Updating paths
export PATH="/usr/local/opt/python/libexec/bin:$PATH"
export PATH="/usr/local/opt/llvm@11/bin:$PATH"
export LDFLAGS="${LDFLAGS} -L/usr/local/opt/llvm@11/lib"
export CPPFLAGS="${CPPFLAGS} -I/usr/local/opt/llvm@11/include"

cd src/Passes/
pip install -r requirements.txt
chmod +x manage
./manage runci

35 changes: 35 additions & 0 deletions build/passes-windows.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

$ErrorActionPreference = 'Continue'

python --version
pip --version

# Installing requirements for CI
cd ../src/Passes/
pip install -r requirements.txt



# Installing Clang, CMake and LLVM
if (!(Get-Command clang -ErrorAction SilentlyContinue)) {
& (Join-Path $env:CONDA scripts conda.exe) install -c conda-forge llvm-tools=11.1.0
& (Join-Path $env:CONDA scripts conda.exe) install -c conda-forge llvmdev=11.1.0
}

refreshenv
$env:Path += ";C:\Miniconda\Library\LLVM\bin\"
$env:LLVM = "C:\Miniconda\Library\LLVM\"

cmd.exe /c "call `"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat`" && set > %temp%\vcvars.txt"

Get-Content "$env:temp\vcvars.txt" | Foreach-Object {
if ($_ -match "^(.*?)=(.*)$") {
Set-Content "env:\$($matches[1])" $matches[2]
}
}


# Running CI
python manage runci
6 changes: 6 additions & 0 deletions build/steps.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
steps:
# Windows CI is disabled until we have a fully working
# configuration of LLVM with CMake
# - pwsh: ./passes-windows.ps1
# displayName: "Passes style, build & test"
# workingDirectory: $(System.DefaultWorkingDirectory)/build

- pwsh: ./build.ps1
displayName: "Build all"
workingDirectory: $(System.DefaultWorkingDirectory)/build
Expand Down
1 change: 1 addition & 0 deletions build/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function Test-One {
}
}


Test-One '../QsCompiler.sln'
Test-One '../QsFmt.sln'

Expand Down
19 changes: 9 additions & 10 deletions src/Passes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
cmake_minimum_required(VERSION 3.4.3)

project(QSharpPasses)
project(Passes)

if (WIN32)
message(STATUS "Adding C:\\Program Files\\LLVM\\lib to LLVM paths")
find_package(LLVM REQUIRED PATHS "C:\\Program Files\\LLVM\\lib" CONFIG )
else()
find_package(LLVM REQUIRED CONFIG)
endif()


find_package(LLVM REQUIRED CONFIG)
include(CheckCXXCompilerFlag)

message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
Expand All @@ -25,14 +32,6 @@ if(NOT LLVM_ENABLE_RTTI)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
endif()

# -fvisibility-inlines-hidden is set when building LLVM and on Darwin warnings
# are triggered if llvm-tutor is built without this flag (though otherwise it
# builds fine). For consistency, add it here too.
check_cxx_compiler_flag("-fvisibility-inlines-hidden" SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG)
if (${SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG} EQUAL "1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden")
endif()

# We export the compile commands which are needed by clang-tidy
# to run the static analysis
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,19 @@ llvm::PassPluginLibraryInfo getExpandStaticAllocationPluginInfo()
using namespace microsoft::quantum;
using namespace llvm;

return {
LLVM_PLUGIN_API_VERSION, "ExpandStaticAllocation", LLVM_VERSION_STRING,
[](PassBuilder& pb)
{
// Registering the pass
pb.registerPipelineParsingCallback(
[](StringRef name, FunctionPassManager& fpm, ArrayRef<PassBuilder::PipelineElement> /*unused*/)
{
if (name == "expand-static-allocation")
{
fpm.addPass(ExpandStaticAllocationPass());
return true;
}
return {LLVM_PLUGIN_API_VERSION, "ExpandStaticAllocation", LLVM_VERSION_STRING, [](PassBuilder& pb) {
// Registering the pass
pb.registerPipelineParsingCallback(
[](StringRef name, FunctionPassManager& fpm, ArrayRef<PassBuilder::PipelineElement> /*unused*/) {
if (name == "expand-static-allocation")
{
fpm.addPass(ExpandStaticAllocationPass());
return true;
}

return false;
});
}};
return false;
});
}};
}
} // namespace

Expand Down
43 changes: 20 additions & 23 deletions src/Passes/libs/OpsCounter/LibOpsCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,27 @@ llvm::PassPluginLibraryInfo getOpsCounterPluginInfo()
using namespace microsoft::quantum;
using namespace llvm;

return {
LLVM_PLUGIN_API_VERSION, "OpsCounter", LLVM_VERSION_STRING,
[](PassBuilder& pb)
{
// Registering the printer
pb.registerPipelineParsingCallback(
[](StringRef name, FunctionPassManager& fpm, ArrayRef<PassBuilder::PipelineElement> /*unused*/)
{
if (name == "print<operation-counter>")
{
return {LLVM_PLUGIN_API_VERSION, "OpsCounter", LLVM_VERSION_STRING, [](PassBuilder& pb) {
// Registering the printer
pb.registerPipelineParsingCallback(
[](StringRef name, FunctionPassManager& fpm, ArrayRef<PassBuilder::PipelineElement> /*unused*/) {
if (name == "print<operation-counter>")
{
fpm.addPass(OpsCounterPrinter(llvm::errs()));
return true;
}
return false;
});

pb.registerVectorizerStartEPCallback(
[](llvm::FunctionPassManager& fpm, llvm::PassBuilder::OptimizationLevel /*level*/) {
fpm.addPass(OpsCounterPrinter(llvm::errs()));
return true;
}
return false;
});

pb.registerVectorizerStartEPCallback(
[](llvm::FunctionPassManager& fpm, llvm::PassBuilder::OptimizationLevel /*level*/)
{ fpm.addPass(OpsCounterPrinter(llvm::errs())); });

// Registering the analysis module
pb.registerAnalysisRegistrationCallback([](FunctionAnalysisManager& fam)
{ fam.registerPass([] { return OpsCounterAnalytics(); }); });
}};
});

// Registering the analysis module
pb.registerAnalysisRegistrationCallback(
[](FunctionAnalysisManager& fam) { fam.registerPass([] { return OpsCounterAnalytics(); }); });
}};
}

} // namespace
Expand Down
4 changes: 4 additions & 0 deletions src/Passes/libs/OpsCounter/OpsCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ namespace quantum
{
for (auto& instruction : basic_block)
{
/*
TODO(tfr): Enable this block once we upgrade to LLVM 12 or above
if (instruction.isDebugOrPseudoInst())
{
continue;
}
*/

auto name = instruction.getOpcodeName();

if (opcode_map.find(name) == opcode_map.end())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,28 @@ llvm::PassPluginLibraryInfo getQubitAllocationAnalysisPluginInfo()
using namespace microsoft::quantum;
using namespace llvm;

return {
LLVM_PLUGIN_API_VERSION, "QubitAllocationAnalysis", LLVM_VERSION_STRING,
[](PassBuilder& pb)
{
// Registering a printer for the anaylsis
pb.registerPipelineParsingCallback(
[](StringRef name, FunctionPassManager& fpm, ArrayRef<PassBuilder::PipelineElement> /*unused*/)
{
if (name == "print<qubit-allocation-analysis>")
{
return {LLVM_PLUGIN_API_VERSION, "QubitAllocationAnalysis", LLVM_VERSION_STRING, [](PassBuilder& pb) {
// Registering a printer for the anaylsis
pb.registerPipelineParsingCallback(
[](StringRef name, FunctionPassManager& fpm, ArrayRef<PassBuilder::PipelineElement> /*unused*/) {
if (name == "print<qubit-allocation-analysis>")
{
fpm.addPass(QubitAllocationAnalysisPrinter(llvm::errs()));
return true;
}
return false;
});

pb.registerVectorizerStartEPCallback(
[](llvm::FunctionPassManager& fpm, llvm::PassBuilder::OptimizationLevel /*level*/) {
fpm.addPass(QubitAllocationAnalysisPrinter(llvm::errs()));
return true;
}
return false;
});

pb.registerVectorizerStartEPCallback(
[](llvm::FunctionPassManager& fpm, llvm::PassBuilder::OptimizationLevel /*level*/)
{ fpm.addPass(QubitAllocationAnalysisPrinter(llvm::errs())); });
});

// Registering the analysis module
pb.registerAnalysisRegistrationCallback(
[](FunctionAnalysisManager& fam)
{ fam.registerPass([] { return QubitAllocationAnalysisAnalytics(); }); });
}};
// Registering the analysis module
pb.registerAnalysisRegistrationCallback([](FunctionAnalysisManager& fam) {
fam.registerPass([] { return QubitAllocationAnalysisAnalytics(); });
});
}};
}

} // namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ namespace quantum
void QubitAllocationAnalysisAnalytics::analyseCall(Instruction& instruction)
{
// Skipping debug code
/*
TODO(tfr): enable in LLVM12
if (instruction.isDebugOrPseudoInst())
{
return;
}
*/

// Recovering the call information
auto* call_instr = llvm::dyn_cast<llvm::CallBase>(&instruction);
Expand Down
7 changes: 5 additions & 2 deletions src/Passes/site-packages/TasksCI/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .settings import PROJECT_ROOT
from .toolchain import discover_formatter
from typing import Union, List, Callable
import difflib

OptionalInt = Union[int, None]
OptionalStr = Union[str, None]
Expand Down Expand Up @@ -91,8 +92,10 @@ def enforce_formatting(filename: str, contents: str, cursor: int, fix_issues: bo
with open(filename, "w") as filebuffer:
filebuffer.write(formatted)
return cursor, False

logger.error("{} was not correctly formatted.".format(filename))
else:
logger.error("{} was not correctly formatted.".format(filename))
sys.stdout.writelines(difflib.unified_diff(contents, formatted,
fromfile=filename, tofile="formatted_{}".format(filename)))
return cursor, True

return cursor, False
Expand Down
Loading