Skip to content

Commit

Permalink
Revert "Revert "Use statepoints to compute stack roots when invoking …
Browse files Browse the repository at this point in the history
…koreCollect (#426)""

This reverts commit ff5e88b.
  • Loading branch information
Dwight Guth committed Oct 6, 2021
1 parent ff5e88b commit 14ebc76
Show file tree
Hide file tree
Showing 29 changed files with 874 additions and 292 deletions.
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 @@ -81,7 +81,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

0 comments on commit 14ebc76

Please sign in to comment.