Setup now based on llvm toolchain.

This commit is contained in:
Nils Hölscher 2022-04-20 09:55:54 +02:00
parent b7bf7342d2
commit f25eba1687
7 changed files with 202 additions and 26 deletions

5
.gitignore vendored
View File

@ -2,8 +2,9 @@ build
*.out
*.dot
*.png
*.txt
.gitconfig
.vscode-server
.gnupg
.bash_history
.bash_history
.cache/
compile_commands.json

17
.vscode/launch.json vendored
View File

@ -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",

111
CMakeLists.txt Normal file
View File

@ -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)

View File

@ -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
"$<$<PLATFORM_ID:Darwin>:-undefined dynamic_lookup>")

View File

@ -10,6 +10,7 @@ RUN pacman -Syu --noconfirm \
llvm \
clang \
gdb \
lldb \
python-pip \
fish \
zsh

View File

@ -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://docs.docker.com/get-docker/>
https://code.visualstudio.com/
<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
opt -load-pass-plugin build/libCacheAnalysisPass.so -passes=lru-misses test/crc.ll

View File

@ -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! ===="
}