Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use statepoints to compute stack roots when invoking koreCollect #426

Merged
merged 52 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
ffe639c
add llvm file with opaque function definitions
Sep 16, 2021
0058ebd
add llvm pass
Sep 16, 2021
5a2d363
implement getMangledTypeStr
Sep 16, 2021
5b6e368
introduce references to address space 1
Sep 16, 2021
30fbd4b
refactor allocateTerm
Sep 16, 2021
8015af1
add statepoint gc strategy
Sep 16, 2021
d759779
add noreturn to finish_rewriting
Sep 16, 2021
1a42209
add missing typed alloction functions
Sep 16, 2021
3235cba
add code to retrieve stack map
Sep 16, 2021
33b0e3a
parse stack map when application boots
Sep 16, 2021
3147aca
remove manual root tracking
Sep 16, 2021
aef8fb1
use libunwind to walk stack for roots
Sep 16, 2021
6fd8455
wire up gc in scripts
Sep 16, 2021
5ccc1ab
use tailcc instead of fastcc
Sep 16, 2021
b8d8a1f
add gc-leaf-function attribute to tail calls
Sep 17, 2021
02d3be8
fix bug involving match reason functions
Sep 17, 2021
c4f3c2f
reverse order of relocations in llvm pass
Sep 20, 2021
d98282e
fixes for llvm 10
Sep 20, 2021
86f5505
fix llvm pass for llvm 10
Sep 20, 2021
f863345
fix bug on mac os
Sep 20, 2021
57dc7b1
fix cmake
Sep 20, 2021
8c17c37
use LLVM_VERSION_MAJOR
Sep 20, 2021
ae3b32a
fix mac os
Sep 20, 2021
49d42ff
link against libunwind
Sep 20, 2021
4eb0e39
fix name mangling issue on mac os
Sep 20, 2021
dfb2aa3
fix ciscript
Sep 20, 2021
dcffd89
fix linking against libunwind on mac os
Sep 20, 2021
858d46e
add back missing dependencies on libunwind
Sep 20, 2021
41ff0a1
try to fix nix on mac os
Sep 21, 2021
c6efa16
add comments
Sep 23, 2021
2a9a860
add LLVM_LINK variable to cmake
Sep 23, 2021
6ecbbce
install opaque.ll in separate directory
Sep 23, 2021
c54f9c7
change llvm-kompile script to invoke llvm-link
Sep 23, 2021
d16142c
make sure opaque functions will actually get inlined
Sep 23, 2021
a0aad5e
break long line
Sep 23, 2021
a33c4a1
skip constants in stack map
Sep 23, 2021
2a4d904
remove gc-leaf-function attribute from tail calls
Sep 24, 2021
b565cca
add llvm pass to mark tail calls as gc-leaf-function
Sep 24, 2021
49e4322
fix gc offsets
Sep 24, 2021
19dba83
Merge commit '47ab1c422' into statepoint2
Sep 27, 2021
cdfbd18
Merge branch 'master' into statepoint2
Sep 27, 2021
c972f6e
format new files
Sep 27, 2021
bd4844c
fix bug on llvm 10
Sep 27, 2021
5ad632e
fix format
Sep 27, 2021
8f468f6
don't reverse on older llvm
Sep 27, 2021
e08509c
use slightly lower threshold for iterated optimization on nix
Sep 27, 2021
8749cc0
fix code review comments
Sep 27, 2021
f8d46e8
fix llvm 12
Sep 27, 2021
7ead94f
Merge branch 'master' into statepoint2
Sep 27, 2021
8fb9cad
Fix merge conflict
Sep 27, 2021
9a84a61
Update lib/llvm/EmitGCLayoutInfo.cpp
Sep 29, 2021
e99d9ca
Update MarkTailCallsAsGCLeaf.cpp
Sep 29, 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
16 changes: 14 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,31 @@ install(
DESTINATION lib/kllvm/llvm/main
)

install(
FILES runtime/opaque/opaque.ll
DESTINATION lib/kllvm/llvm/opaque
)

find_program(OPT opt-12)
find_program(OPT opt-11)
find_program(OPT opt-10)
find_program(OPT opt)
find_program(LLVM_LINK llvm-link-12)
find_program(LLVM_LINK llvm-link-11)
find_program(LLVM_LINK llvm-link-10)
find_program(LLVM_LINK llvm-link)
find_program(LLC llc-12)
find_program(LLC llc-11)
find_program(LLC llc-10)
find_program(LLC llc)
if(${OPT} STREQUAL "OPT-NOTFOUND")
message(FATAL_ERROR "Could not find an opt binary. Is llvm installed on your PATH?")
endif()
if(${LLC} STREQUAL "OPT-NOTFOUND")
message(FATAL_ERROR "Could not find an llvm binary. Is llvm installed on your PATH?")
if(${LLC} STREQUAL "LLC-NOTFOUND")
message(FATAL_ERROR "Could not find an llc binary. Is llvm installed on your PATH?")
endif()
if(${LLVM_LINK} STREQUAL "LLVM_LINK-NOTFOUND")
message(FATAL_ERROR "Could not find an llvm-link binary. Is llvm installed on your PATH?")
endif()

file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV TZ America/Chicago
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
apt-get install -y git cmake clang-10 llvm-10-tools lld-10 zlib1g-dev flex libboost-test-dev libgmp-dev libmpfr-dev libyaml-dev libjemalloc-dev curl maven pkg-config
apt-get install -y git cmake clang-10 llvm-10-tools lld-10 zlib1g-dev flex libboost-test-dev libgmp-dev libmpfr-dev libyaml-dev libjemalloc-dev libunwind-dev curl maven pkg-config

ARG USER_ID=1000
ARG GROUP_ID=1000
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.arch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM archlinux:base

RUN pacman -Syyu --noconfirm && \
pacman -S --noconfirm base-devel git cmake clang llvm lld flex boost gmp mpfr libyaml jemalloc curl maven pkg-config
pacman -S --noconfirm base-devel git cmake clang llvm lld flex boost gmp mpfr libyaml jemalloc libunwind curl maven pkg-config

ARG USER_ID=1000
ARG GROUP_ID=1000
Expand Down
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
On Ubuntu 20.04:
```shell
sudo apt-get update
sudo apt-get install git cmake clang-10 llvm-10-tools lld-10 zlib1g-dev flex libboost-test-dev libgmp-dev libmpfr-dev libyaml-dev libjemalloc-dev curl maven pkg-config
sudo apt-get install git cmake clang-10 llvm-10-tools lld-10 zlib1g-dev flex libboost-test-dev libgmp-dev libmpfr-dev libyaml-dev libjemalloc-dev libunwind-dev curl maven pkg-config
git clone https://github.com/kframework/llvm-backend --recursive
cd llvm-backend
mkdir build
Expand Down
21 changes: 18 additions & 3 deletions bin/llvm-kompile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ if [ $# -lt 3 ]; then
fi
mod="$(mktemp tmp.XXXXXXXXXX)"
modopt="$(mktemp tmp.XXXXXXXXXX)"
trap "rm -rf $dt_dir $mod $modopt" INT TERM EXIT
modcombined="$(mktemp tmp.XXXXXXXXXX)"
modcombinedopt="$(mktemp tmp.XXXXXXXXXX)"
trap "rm -rf $dt_dir $mod $modopt $modcombined $modcombinedopt" INT TERM EXIT
definition="$1"
shift
compile=true
Expand All @@ -31,12 +33,25 @@ if $compile; then
-g)
debug=1
;;
-O[0-3])
opt_flags="$arg"
;;
-O.)
echo "$0: invalid optimization level"
exit 1
;;
*)
;;
esac
done

# code generation
"$(dirname "$0")"/llvm-kompile-codegen "$definition" "$dt_dir"/dt.yaml "$dt_dir" $debug > "$mod"
@OPT@ -mem2reg -tailcallelim -tailcallopt "$mod" -o "$modopt"

# optimization
@OPT@ -load "$(dirname "$0")"/../lib/kllvm/libLLVMPass.so -mem2reg -tailcallelim $opt_flags -mark-tail-calls-as-gc-leaf -rewrite-statepoints-for-gc -dce -emit-gc-layout-info "$mod" -o "$modopt"
@LLVM_LINK@ "$modopt" "$(dirname "$0")"/../lib/kllvm/llvm/opaque/opaque.ll -o "$modcombined"
@OPT@ "$modcombined" -always-inline -o "$modcombinedopt"
else
main="$1"
shift
Expand All @@ -45,4 +60,4 @@ fi
if [[ "$OSTYPE" != "darwin"* ]]; then
flags=-fuse-ld=lld
fi
"$(dirname "$0")"/llvm-kompile-clang "$modopt" "$main" @LLVM_KOMPILE_LTO@ -fno-stack-protector $flags "$@"
"$(dirname "$0")"/llvm-kompile-clang "$modcombinedopt" "$main" @LLVM_KOMPILE_LTO@ -fno-stack-protector $flags "$@"
10 changes: 5 additions & 5 deletions bin/llvm-kompile-clang
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fi

if [[ "$OSTYPE" == "darwin"* ]]; then
libraries="-liconv -lncurses"
flags="-L/usr/local/opt/libffi/lib -L/usr/local/lib -Wl,-u,_sort_table -I /usr/local/include"
flags="-L/usr/local/opt/libffi/lib -L/usr/local/lib -L$(dirname "@LLC@")/../lib -Wl,-u,_sort_table -I /usr/local/include"
else
libraries="-ltinfo"
flags="-Wl,-u,sort_table"
Expand All @@ -84,7 +84,7 @@ if ! $save_temps; then
fi

if [ "$lto" = "lto" ]; then
flags="$flags -flto -Wl,-mllvm,-tailcallopt"
flags="$flags -flto"
files=("$LIBDIR"/llvm/*.ll)
if ! $link; then
mv "$modopt" "$output_file"
Expand All @@ -96,13 +96,13 @@ else
if ! $link; then
modasm="$output_file"
fi
run @LLC@ -tailcallopt "$modopt" -mtriple=@BACKEND_TARGET_TRIPLE@ -filetype=obj $llc_opt_flags $llc_flags -o "$modasm"
run @LLC@ "$modopt" -mtriple=@BACKEND_TARGET_TRIPLE@ -filetype=obj $llc_opt_flags $llc_flags -o "$modasm"
modopt="$modasm"
fi
if $link; then
for file in "$LIBDIR"/llvm/*.ll; do
tmp="$tmpdir/`basename "$file"`.o"
run @LLC@ -tailcallopt "$file" -mtriple=@BACKEND_TARGET_TRIPLE@ -filetype=obj $llc_opt_flags $llc_flags -o "$tmp"
run @LLC@ "$file" -mtriple=@BACKEND_TARGET_TRIPLE@ -filetype=obj $llc_opt_flags $llc_flags -o "$tmp"
files+=("$tmp")
done
fi
Expand All @@ -111,7 +111,7 @@ fi
if [ "$main" = "static" ]; then
all_libraries=
else
all_libraries="$libraries -lgmp -lmpfr -lpthread -ldl -lffi -ljemalloc"
all_libraries="$libraries -lgmp -lmpfr -lpthread -ldl -lffi -ljemalloc -lunwind"
fi

if $link; then
Expand Down
6 changes: 3 additions & 3 deletions ciscript
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
export PATH=$HOME/.cargo/bin:$HOME/.local/bin:$PATH

if [[ "$OSTYPE" == "darwin"* ]]; then
export PATH="/usr/local/opt/flex/bin:/usr/local/opt/llvm@6/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/llvm@6/lib -L/usr/local/opt/flex/lib"
export CPPFLAGS="-I/usr/local/opt/llvm@6/include -I/usr/local/opt/flex/include"
export PATH="/usr/local/opt/flex/bin:/usr/local/opt/llvm@12/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/llvm@12/lib -L/usr/local/opt/flex/lib"
export CPPFLAGS="-I/usr/local/opt/llvm@12/include -I/usr/local/opt/flex/include"
export FLEX_EXECUTABLE="/usr/local/opt/flex/bin/flex"
fi

Expand Down
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ let
mkdir -p "$out/bin"
cp ${llvm-backend.src}/bin/llvm-kompile-testing "$out/bin"
sed -i "$out/bin/llvm-kompile-testing" \
-e '/@PROJECT_SOURCE_DIR@/ c ${java} -jar ${jar} $definition qbaL $dt_dir 1'
-e '/@PROJECT_SOURCE_DIR@/ c ${java} -jar ${jar} $definition qbaL $dt_dir 9/10'
chmod +x "$out/bin/llvm-kompile-testing"
patchShebangs "$out/bin/llvm-kompile-testing"
'';
Expand Down
24 changes: 18 additions & 6 deletions include/kllvm/codegen/CreateTerm.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CreateTerm {
llvm::Value *
createHook(KORECompositePattern *hookAtt, KORECompositePattern *pattern);
llvm::Value *createFunctionCall(
std::string name, KORECompositePattern *pattern, bool sret, bool fastcc);
std::string name, KORECompositePattern *pattern, bool sret, bool tailcc);
llvm::Value *
notInjectionCase(KORECompositePattern *constructor, llvm::Value *val);

Expand Down Expand Up @@ -52,12 +52,12 @@ class CreateTerm {
* function actually returns void and the return value is via a pointe. Note
* that this can be set to true even if the function does not return a struct,
* in which case its value is ignored. load: if the function returns a struct
* via sret, then if load is true, we load the value fastcc: true if we should
* use the fastcc calling convention returned from the function before
* via sret, then if load is true, we load the value tailcc: true if we should
* use the tailcc calling convention returned from the function before
* returning it. */
llvm::Value *createFunctionCall(
std::string name, ValueType returnCat,
const std::vector<llvm::Value *> &args, bool sret, bool fastcc);
const std::vector<llvm::Value *> &args, bool sret, bool tailcc);

llvm::BasicBlock *getCurrentBlock() const { return CurrentBlock; }
};
Expand Down Expand Up @@ -103,11 +103,23 @@ llvm::Type *getParamType(ValueType sort, llvm::Module *Module);
void addAbort(llvm::BasicBlock *block, llvm::Module *Module);

llvm::Value *allocateTerm(
llvm::Type *AllocType, llvm::BasicBlock *block,
ValueType Cat, llvm::Type *AllocType, llvm::BasicBlock *block,
const char *allocFn = "koreAlloc");
llvm::Value *allocateTerm(
ValueType Cat, llvm::Type *AllocType, llvm::Value *Len,
llvm::BasicBlock *block, const char *allocFn = "koreAlloc");
llvm::Value *allocateTermNoReloc(
llvm::Type *AllocType, llvm::BasicBlock *block,
const char *allocFn = "koreAllocAlwaysGC");
llvm::Value *allocateTermNoReloc(
llvm::Type *AllocType, llvm::Value *Len, llvm::BasicBlock *block,
const char *allocFn = "koreAlloc");
const char *allocFn = "koreAllocAlwaysGC");

// see comment on runtime/opaque/opaque.ll for explanation about why these
// functions exist
llvm::Value *addrspaceCast0to1(llvm::Value *val, llvm::BasicBlock *block);
llvm::Value *addrspaceCast1to0(llvm::Value *val, llvm::BasicBlock *block);
llvm::Value *ptrToInt(llvm::Value *val, llvm::BasicBlock *block);
} // namespace kllvm

#endif // CREATE_TERM_H
5 changes: 5 additions & 0 deletions include/kllvm/codegen/Util.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#ifndef KLLVM_UTIL_H
#define KLLVM_UTIL_H

#include "kllvm/ast/AST.h"
#include "llvm/IR/Module.h"

namespace kllvm {

// Returns a reference to the function declaration for a memory allocation
// function with the given name, adding a declaration to the current module if
// one does not yet exist
llvm::Function *
koreHeapAlloc(ValueType Cat, std::string name, llvm::Module *module);
llvm::Function *koreHeapAlloc(std::string name, llvm::Module *module);

// If Value is an instance of llvm::Function, cast and return. Otherwise, print
Expand All @@ -29,6 +32,8 @@ static llvm::Function *getOrInsertFunction(llvm::Module *module, Ts... Args) {

llvm::StructType *getTypeByName(llvm::Module *module, std::string name);

std::string getMangledTypeStr(llvm::Type *Ty, bool &HasUnnamedType);

} // namespace kllvm

#endif // KLLVM_UTIL_H
4 changes: 3 additions & 1 deletion include/runtime/collect.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ using map_impl = map::iterator::tree_t;
using set_node = set::iterator::node_t;
using set_impl = set::iterator::tree_t;

void parseStackMap(void);

extern "C" {
extern size_t numBytesLiveAtCollection[1 << AGE_WIDTH];
bool during_gc(void);
Expand All @@ -36,7 +38,7 @@ void migrate_map(void *m);
void migrate_set(void *s);
void migrate_collection_node(void **nodePtr);
void setKoreMemoryFunctionsForGMP(void);
void koreCollect(void **, uint8_t, layoutitem *);
void koreCollect(void);
}

#ifdef GC_DBG
Expand Down
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
add_subdirectory(parser)
add_subdirectory(ast)
add_subdirectory(codegen)
add_subdirectory(llvm)

separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
add_definitions(${LLVM_DEFINITIONS_LIST})
Loading