From f25eba16870ce5f6c7771093696aa0593fead04e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20H=C3=B6lscher?= Date: Wed, 20 Apr 2022 09:55:54 +0200 Subject: [PATCH] Setup now based on llvm toolchain. --- .gitignore | 5 +- .vscode/launch.json | 17 ++++- CMakeLists.txt | 111 +++++++++++++++++++++++++++++++ CacheAnalysisPass/CMakeLists.txt | 44 ++++++++++++ Dockerfile | 1 + README.md | 46 +++++++------ helper.sh | 4 +- 7 files changed, 202 insertions(+), 26 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 CacheAnalysisPass/CMakeLists.txt diff --git a/.gitignore b/.gitignore index aa797a9..56676df 100644 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,9 @@ build *.out *.dot *.png -*.txt .gitconfig .vscode-server .gnupg -.bash_history \ No newline at end of file +.bash_history +.cache/ +compile_commands.json \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 06d3d05..dd7c177 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,7 +5,22 @@ "version": "0.2.0", "configurations": [ { - "name": "DBG fft1", + "type": "lldb", + "request": "launch", + "name": "LLDB fft1", + "program": "/usr/bin/opt", + "args": [ + "-load-pass-plugin", + "${workspaceFolder}/build/libCacheAnalysisPass.so", + "-passes=lru-misses", + "${workspaceFolder}/test/fft1.ll", + "-o", + "/dev/null" + ], + "cwd": "${workspaceFolder}" + }, + { + "name": "gdb fft1", "type": "cppdbg", "request": "launch", "program": "/usr/bin/opt", diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e904e1c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,111 @@ +cmake_minimum_required(VERSION 3.13.4) +project(RTSA-lab01-CacheAnalysis) + +#=============================================================================== +# 1. VERIFY LLVM INSTALLATION DIR +# This is just a bit of a sanity checking. +#=============================================================================== +set(LT_LLVM_INSTALL_DIR "" CACHE PATH "LLVM installation directory") + +# 1.1 Check the "include| directory +set(LT_LLVM_INCLUDE_DIR "${LT_LLVM_INSTALL_DIR}/include/llvm") +if(NOT EXISTS "${LT_LLVM_INCLUDE_DIR}") +message(FATAL_ERROR + " LT_LLVM_INSTALL_DIR (${LT_LLVM_INCLUDE_DIR}) is invalid.") +endif() + +# 1.2 Check that the LLVMConfig.cmake file exists (the location depends on the +# OS) +set(LT_VALID_INSTALLATION FALSE) + +# Ubuntu + Darwin +if(EXISTS "${LT_LLVM_INSTALL_DIR}/lib/cmake/llvm/LLVMConfig.cmake") + set(LT_VALID_INSTALLATION TRUE) +endif() + +# Fedora +if(EXISTS "${LT_LLVM_INSTALL_DIR}/lib64/cmake/llvm/LLVMConfig.cmake") + set(LT_VALID_INSTALLATION TRUE) +endif() + +if(NOT ${LT_VALID_INSTALLATION}) + message(FATAL_ERROR + "LLVM installation directory, (${LT_LLVM_INSTALL_DIR}), is invalid. Couldn't + find LLVMConfig.cmake.") +endif() + +#=============================================================================== +# 2. LOAD LLVM CONFIGURATION +# For more: http://llvm.org/docs/CMake.html#embedding-llvm-in-your-project +#=============================================================================== +# Add the location of LLVMConfig.cmake to CMake search paths (so that +# find_package can locate it) +# Note: On Fedora, when using the pre-compiled binaries installed with `dnf`, +# LLVMConfig.cmake is located in "/usr/lib64/cmake/llvm". But this path is +# among other paths that will be checked by default when using +# `find_package(llvm)`. So there's no need to add it here. +list(APPEND CMAKE_PREFIX_PATH "${LT_LLVM_INSTALL_DIR}/lib/cmake/llvm/") + +find_package(LLVM 13.0.0 REQUIRED CONFIG) + +# Another sanity check +if(NOT "13" VERSION_EQUAL "${LLVM_VERSION_MAJOR}") + message(FATAL_ERROR "Found LLVM ${LLVM_VERSION_MAJOR}, but need LLVM 13") +endif() + +message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") +message(STATUS "Using LLVMConfig.cmake in: ${LT_LLVM_INSTALL_DIR}") + +message("LLVM STATUS: + Definitions ${LLVM_DEFINITIONS} + Includes ${LLVM_INCLUDE_DIRS} + Libraries ${LLVM_LIBRARY_DIRS} + Targets ${LLVM_TARGETS_TO_BUILD}" +) + +# Set the LLVM header and library paths +include_directories(SYSTEM ${LLVM_INCLUDE_DIRS}) +link_directories(${LLVM_LIBRARY_DIRS}) +add_definitions(${LLVM_DEFINITIONS}) + +#=============================================================================== +# 3. LLVM-TUTOR BUILD CONFIGURATION +#=============================================================================== +# Use the same C++ standard as LLVM does +set(CMAKE_CXX_STANDARD 14 CACHE STRING "") + +# Build type +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Debug CACHE + STRING "Build type (default Debug):" FORCE) +endif() + +# Compiler flags +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall\ + -fdiagnostics-color=always") + +# LLVM is normally built without RTTI. Be consistent with that. +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. +include(CheckCXXCompilerFlag) +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() + +# Set the build directories +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") + +#=============================================================================== +# 4. ADD SUB-TARGETS +# Doing this at the end so that all definitions and link/include paths are +# available for the sub-projects. +#=============================================================================== +add_subdirectory(CacheAnalysisPass) # Use your pass name here. +add_subdirectory(lib) \ No newline at end of file diff --git a/CacheAnalysisPass/CMakeLists.txt b/CacheAnalysisPass/CMakeLists.txt new file mode 100644 index 0000000..7b5c776 --- /dev/null +++ b/CacheAnalysisPass/CMakeLists.txt @@ -0,0 +1,44 @@ +cmake_minimum_required(VERSION 3.13.4) +project(CacheAnalysisPass) + +#=============================================================================== +# 1. LOAD LLVM CONFIGURATION +#=============================================================================== +# Set this to a valid LLVM installation dir +set(LT_LLVM_INSTALL_DIR "" CACHE PATH "LLVM installation directory") + +# Add the location of LLVMConfig.cmake to CMake search paths (so that +# find_package can locate it) +list(APPEND CMAKE_PREFIX_PATH "${LT_LLVM_INSTALL_DIR}/lib/cmake/llvm/") + +# FIXME: This is a warkaround for #25. Remove once resolved and use +# find_package(LLVM 11.0.0 REQUIRED CONFIG) instead. +find_package(LLVM REQUIRED CONFIG) + +# CacheAnalysisPass includes headers from LLVM - update the include paths accordingly +include_directories(SYSTEM ${LLVM_INCLUDE_DIRS}, "${CMAKE_CURRENT_SOURCE_DIR}/../include") + +#=============================================================================== +# 2. LLVM-TUTOR BUILD CONFIGURATION +#=============================================================================== +# Use the same C++ standard as LLVM does +set(CMAKE_CXX_STANDARD 14 CACHE STRING "") + +# LLVM is normally built without RTTI. Be consistent with that. +if(NOT LLVM_ENABLE_RTTI) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") +endif() + +#=============================================================================== +# 3. ADD THE TARGET +#=============================================================================== +add_library(CacheAnalysisPass SHARED + # List your source files here. + CacheAnalysisPass.cpp +) + + +# Allow undefined symbols in shared objects on Darwin (this is the default +# behaviour on Linux) +target_link_libraries(CacheAnalysisPass + "$<$:-undefined dynamic_lookup>") diff --git a/Dockerfile b/Dockerfile index 7b675b5..4d35ca1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,7 @@ RUN pacman -Syu --noconfirm \ llvm \ clang \ gdb \ + lldb \ python-pip \ fish \ zsh diff --git a/README.md b/README.md index f120363..cb11027 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ The Project can build, tested and Evaluated with the Helper Script. ## Disclaimer -This is the first time we provide this exercise. +This is the first time we provide this exercise. Should you encounter something you think is a Bug, please let me know, during lab sessions. Also keep track of the Repository as I may add more features to the script. @@ -18,26 +18,26 @@ If this is not your preferred Setup, take a look in the Docker file for the depe Also we do not support the usage of Windows, Linux is free of charge so get a copy. -### Setting Docker up: +### Setting Docker up 1.) install docker and VS Code on your Distribution. -https://docs.docker.com/get-docker/ + -https://code.visualstudio.com/ + For this setup you cannot use the OSS version of VS code or the version from Snap, as the remote development extensions will not work. 2.) We recommend you install the following extensions in vs code -C/C++, -clangd, -Docker and +clangd, +CodeLLDB, +Docker and Remote Development 3.) Use the helper script to build and run a Container - $ ./helper.sh docker + ./helper.sh docker This will build a docker image and run a Docker container with the current directory mounted. @@ -59,25 +59,27 @@ You can also set the following variables in the CacheAnalysisPass/CacheAnalysisP ## Use the Helper script -### Initial Setup: +### Initial Setup - $ ./helper.sh all + ./helper.sh all To get a list of what the helper script can do simply type - $ ./helper.sh + ./helper.sh + +### Run -### Run: Run the pass on a single test. fft1 is recommended during development. - $ ./helper.sh run fft1 + ./helper.sh run fft1 -### Eval: -Runs the Pass on a set of tests and also prints the expected results. +### Eval + +Runs the Pass on a set of tests and also prints the expected results. This will be used to measure correctness of you implementation. - $ ./helper.sh eval + ./helper.sh eval ## Use the Terminal (Obsolete if script is used) @@ -85,12 +87,12 @@ This section is not needed, fi you are using the script but for the sake of comp Initial Setup: - $ mkdir build - $ cd build - $ cmake -DLT_LLVM_INSTALL_DIR=$LLVM_DIR ../CacheAnalysisPass/ - $ make - $ cd .. + mkdir build + cd build + cmake -DLT_LLVM_INSTALL_DIR=$LLVM_DIR ../CacheAnalysisPass/ + make + cd .. Run: - $ opt -load-pass-plugin build/libCacheAnalysisPass.so -passes=lru-misses test/crc.ll \ No newline at end of file + opt -load-pass-plugin build/libCacheAnalysisPass.so -passes=lru-misses test/crc.ll diff --git a/helper.sh b/helper.sh index 2f0e384..3c55765 100755 --- a/helper.sh +++ b/helper.sh @@ -10,7 +10,9 @@ config () { mkdir build cd build echo "==== Configuring cmake ====" - cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DLT_LLVM_INSTALL_DIR=$LLVM_DIR ../CacheAnalysisPass/ + cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DLT_LLVM_INSTALL_DIR=$LLVM_DIR ../CacheAnalysisPass/ + cd .. + mv build/compile_commands.json compile_commands.json echo "==== Done! ====" }