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

Update with experimental support for LLVM 6.0.0 #2595

Merged
merged 16 commits into from
Apr 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ branches:
environment:
matrix:
- llvm: 3.9.1
- llvm: 4.0.1
- llvm: 5.0.1
- llvm: 6.0.0

configuration:
- release
Expand Down
27 changes: 27 additions & 0 deletions .ci-dockerfiles/llvm-6.0.0/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM ubuntu:14.04

ENV LLVM_VERSION 6.0.0

RUN apt-get update \
&& apt-get install -y \
apt-transport-https \
build-essential \
g++ \
git \
libncurses5-dev \
libssl-dev \
make \
wget \
xz-utils \
zlib1g-dev \
&& cd /tmp \
&& wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre2-10.21.tar.bz2 \
&& tar xjvf pcre2-10.21.tar.bz2 \
&& cd pcre2-10.21 \
&& ./configure --prefix=/usr \
&& make \
&& sudo make install \
&& cd / \
&& rm -rf /tmp/pcre* \
&& wget -O - http://releases.llvm.org/${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-x86_64-linux-gnu-ubuntu-14.04.tar.xz \
| tar xJf - --no-same-owner --strip-components 1 -C /usr/local/ clang+llvm-${LLVM_VERSION}-x86_64-linux-gnu-ubuntu-14.04
21 changes: 21 additions & 0 deletions .ci-dockerfiles/llvm-6.0.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Build image

```bash
docker build -t ponylang/ponyc-ci:llvm-6.0.0 .
```

# Run image to test

Will get you a bash shell in the image to try cloning Pony into where you can test a build to make sure everything will work before pushing

```bash
docker run --name ponyc-ci-llvm-600 --rm -i -t ponylang/ponyc-ci:llvm-6.0.0 bash
```

# Push to dockerhub

You'll need credentials for the ponylang dockerhub account. Talk to @jemc or @seantallen for access

```bash
docker push ponylang/ponyc-ci:llvm-6.0.0
```
14 changes: 14 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ jobs:
steps:
- checkout
- run: find . -name '*.bash' -exec shellcheck {} \;
llvm-600-debug:
docker:
- image: ponylang/ponyc-ci:llvm-6.0.0
steps:
- checkout
- run: make test-ci config=debug default_pic=true
llvm-600-release:
docker:
- image: ponylang/ponyc-ci:llvm-6.0.0
steps:
- checkout
- run: make test-ci config=release default_pic=true
llvm-501-debug:
docker:
- image: ponylang/ponyc-ci:llvm-5.0.1
Expand Down Expand Up @@ -61,6 +73,8 @@ workflows:
jobs:
- verify-changelog
- validate-shell-scripts
- llvm-600-debug
- llvm-600-release
- llvm-501-debug
- llvm-501-release
- llvm-401-debug
Expand Down
40 changes: 19 additions & 21 deletions .travis_script.bash
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,6 @@ case "${TRAVIS_OS_NAME}" in
make clean
brew uninstall llvm@3.9

# 4.0.x
brew install llvm@4
brew link --overwrite --force llvm@4
ln -fs "$(which llvm-config)" llvmsym/llvm-config-4.0
ln -fs "$(which clang++)" llvmsym/clang++-4.0

export CC1=clang-4.0
export CXX1=clang++-4.0
#echo "Running LLVM 4.0 config=debug build..."
#export config=debug
#ponyc-test
echo "Running LLVM 4.0 config=release build..."
export config=release
ponyc-test

make clean
brew uninstall llvm@4

# 5.0.x
brew install llvm@5
brew link --overwrite --force llvm@5
Expand All @@ -75,15 +57,31 @@ case "${TRAVIS_OS_NAME}" in

export CC1=clang-5.0
export CXX1=clang++-5.0
#echo "Running LLVM 5.0 config=debug build..."
#export config=debug
#ponyc-test
echo "Running LLVM 5.0 config=release build..."
export config=release
ponyc-test

make clean
brew uninstall llvm@5

# 6.0.x
# There is no llvm@6 package right now, so this will break once LLVM 7
Copy link
Member

@jemc jemc Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

# is released. Hopefully when they do that there will be a llvm@6 package
# at which point both `brew install llvm` and `brew uninstall llvm`
# should be updated to replace `llvm` with `llvm@6`
brew install llvm
brew link --overwrite --force llvm
ln -fs "$(which llvm-config)" llvmsym/llvm-config-6.0
ln -fs "$(which clang++)" llvmsym/clang++-6.0

export CC1=clang-6.0
export CXX1=clang++-6.0
echo "Running LLVM 6.0 config=release build..."
export config=release
ponyc-test

make clean
brew uninstall llvm
fi
;;

Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ endif
ifndef LLVM_CONFIG
ifneq (,$(shell which /usr/local/opt/llvm/bin/llvm-config 2> /dev/null))
LLVM_CONFIG = /usr/local/opt/llvm/bin/llvm-config
else ifneq (,$(shell which llvm-config-6.0 2> /dev/null))
LLVM_CONFIG = llvm-config-6.0
else ifneq (,$(shell which llvm-config-3.9 2> /dev/null))
LLVM_CONFIG = llvm-config-3.9
else ifneq (,$(shell which /usr/local/opt/llvm@3.9/bin/llvm-config 2> /dev/null))
Expand Down Expand Up @@ -261,6 +263,8 @@ else ifeq ($(llvm_version),5.0.0)
$(warning WARNING: LLVM 5 support is experimental and may result in decreased performance or crashes)
else ifeq ($(llvm_version),5.0.1)
$(warning WARNING: LLVM 5 support is experimental and may result in decreased performance or crashes)
else ifeq ($(llvm_version),6.0.0)
$(warning WARNING: LLVM 6 support is experimental and may result in decreased performance or crashes)
else
$(warning WARNING: Unsupported LLVM version: $(llvm_version))
$(warning Please use LLVM 3.9.1)
Expand Down Expand Up @@ -615,12 +619,12 @@ define CONFIGURE_COMPILER
compiler := $(CC)
flags := $(ALL_CFLAGS) $(CFLAGS)
endif

ifeq ($(suffix $(1)),.bc)
compiler := $(CC)
flags := $(ALL_CFLAGS) $(CFLAGS)
endif

ifeq ($(suffix $(1)),.ll)
compiler := $(CC)
flags := $(ALL_CFLAGS) $(CFLAGS) -Wno-override-module
Expand Down
23 changes: 23 additions & 0 deletions src/libponyc/codegen/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#include "ponyassert.h"

#include <platform.h>
#if PONY_LLVM >= 600
#include <llvm-c/DebugInfo.h>
#endif
#include <llvm-c/Initialization.h>
#include <llvm-c/Linker.h>
#include <llvm-c/Support.h>
Expand Down Expand Up @@ -672,10 +675,22 @@ static bool init_module(compile_t* c, ast_t* program, pass_opt_t* opt, bool jit)
c->builder = LLVMCreateBuilderInContext(c->context);
c->di = LLVMNewDIBuilder(c->module);

#if PONY_LLVM < 600
// TODO: what LANG id should be used?
c->di_unit = LLVMDIBuilderCreateCompileUnit(c->di, 0x0004,
package_filename(package), package_path(package), "ponyc-" PONY_VERSION,
c->opt->release);
#else
const char* filename = package_filename(package);
const char* dirname = package_path(package);
const char* version = "ponyc-" PONY_VERSION;
LLVMMetadataRef fileRef = LLVMDIBuilderCreateFile(c->di, filename,
strlen(filename), dirname, strlen(dirname));
c->di_unit = LLVMDIBuilderCreateCompileUnit(c->di,
LLVMDWARFSourceLanguageC_plus_plus, fileRef, version, strlen(version),
opt->release, "", 0, 0, "", 0, LLVMDWARFEmissionFull,
0, false, false);
#endif

// Empty frame stack.
c->frame = NULL;
Expand Down Expand Up @@ -722,6 +737,14 @@ bool codegen_merge_runtime_bitcode(compile_t* c)
return true;
}

#if PONY_LLVM == 600
// TODO: remove for 6.0.1: https://reviews.llvm.org/D44140
PONY_EXTERN_C_BEGIN
extern void LLVMInitializeInstCombine_Pony(LLVMPassRegistryRef R);
PONY_EXTERN_C_END
#define LLVMInitializeInstCombine LLVMInitializeInstCombine_Pony
#endif

bool codegen_llvm_init()
{
LLVMLoadLibraryPermanently(NULL);
Expand Down
2 changes: 2 additions & 0 deletions src/libponyc/codegen/gendebug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void LLVMDIBuilderDestroy(LLVMDIBuilderRef d)
delete pd;
}

#if PONY_LLVM < 600
void LLVMDIBuilderFinalize(LLVMDIBuilderRef d)
{
unwrap(d)->finalize();
Expand Down Expand Up @@ -101,6 +102,7 @@ LLVMMetadataRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef d, const char* file)

return wrap(pd->createFile(filename, dir));
}
#endif

LLVMMetadataRef LLVMDIBuilderCreateNamespace(LLVMDIBuilderRef d,
LLVMMetadataRef scope, const char* name, LLVMMetadataRef file, unsigned line)
Expand Down
9 changes: 7 additions & 2 deletions src/libponyc/codegen/gendebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include <platform.h>
#include <llvm-c/Core.h>
#if PONY_LLVM >= 600
#include <llvm-c/DebugInfo.h>
#endif

PONY_EXTERN_C_BEGIN

Expand Down Expand Up @@ -46,16 +49,18 @@ LLVMDIBuilderRef LLVMNewDIBuilder(LLVMModuleRef m);

void LLVMDIBuilderDestroy(LLVMDIBuilderRef d);

#if PONY_LLVM < 600
void LLVMDIBuilderFinalize(LLVMDIBuilderRef d);

LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(LLVMDIBuilderRef d,
unsigned lang, const char* file, const char* dir, const char* producer,
int optimized);

LLVMMetadataRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef d, const char* file);
#endif

LLVMMetadataRef LLVMDIBuilderCreateNamespace(LLVMDIBuilderRef d,
LLVMMetadataRef scope, const char* name, LLVMMetadataRef file,
LLVMMetadataRef LLVMDIBuilderCreateNamespace(LLVMDIBuilderRef d,
LLVMMetadataRef scope, const char* name, LLVMMetadataRef file,
unsigned line);

LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef d,
Expand Down
17 changes: 15 additions & 2 deletions src/libponyc/codegen/genopt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#include <llvm/Transforms/Utils/Cloning.h>
#include <llvm/ADT/SmallSet.h>

#if PONY_LLVM >= 600
#include <llvm-c/DebugInfo.h>
#endif

#include "../../libponyrt/mem/heap.h"
#include "ponyassert.h"

Expand Down Expand Up @@ -87,6 +91,15 @@ static void print_transform(compile_t* c, Instruction* i, const char* s)
}
}

// TODO: remove for 6.0.1: https://reviews.llvm.org/D44140
#if PONY_LLVM == 600
PONY_EXTERN_C_BEGIN
void LLVMInitializeInstCombine_Pony(LLVMPassRegistryRef R) {
initializeInstructionCombiningPassPass(*unwrap(R));
}
PONY_EXTERN_C_END
#endif

class HeapToStack : public FunctionPass
{
public:
Expand Down Expand Up @@ -302,9 +315,9 @@ class HeapToStack : public FunctionPass
}

case Instruction::Load:
// This is a workaround for a problem with LLVM 4 & 5 on *nix when
// This is a workaround for a problem with LLVM 4 & 5 on *nix when
// hoisting loads (see #2303, #2061, #1592).
// TODO: figure out the real reason LLVM 4 and 5 produce bad code
// TODO: figure out the real reason LLVM 4 and 5 produce bad code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we figured out whether LLVM 6 also produces this bad code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there are still problems with LLVM 6 on Linux, but different from 4 & 5. @Praetonus was going to look at it again in his copious free time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I turned on the workaround again for the time being, which is why the CI tests are passing.

// when hoisting stack allocated loads.
#if PONY_LLVM >= 400 && !defined(_MSC_VER)
// fall through
Expand Down
8 changes: 8 additions & 0 deletions src/libponyc/codegen/gentype.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include <stdlib.h>
#include <string.h>

#if PONY_LLVM >= 600
#include <llvm-c/DebugInfo.h>
#endif

static size_t tbaa_metadata_hash(tbaa_metadata_t* a)
{
return ponyint_hash_ptr(a->name);
Expand Down Expand Up @@ -391,7 +395,11 @@ static void make_debug_info(compile_t* c, reach_type_t* t)
file = "";

compile_type_t* c_t = (compile_type_t*)t->c_type;
#if PONY_LLVM < 600
c_t->di_file = LLVMDIBuilderCreateFile(c->di, file);
#else
c_t->di_file = LLVMDIBuilderCreateFile(c->di, file, strlen(file), "", 0);
#endif

switch(t->underlying)
{
Expand Down
12 changes: 10 additions & 2 deletions src/libponyc/codegen/host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ LLVMTargetMachineRef codegen_machine(LLVMTargetRef target, pass_opt_t* opt,
if(opt->pic || opt->library)
reloc = Reloc::PIC_;

CodeModel::Model model = jit ? CodeModel::JITDefault : CodeModel::Default;

CodeGenOpt::Level opt_level =
opt->release ? CodeGenOpt::Aggressive : CodeGenOpt::None;

Expand All @@ -49,8 +47,14 @@ LLVMTargetMachineRef codegen_machine(LLVMTargetRef target, pass_opt_t* opt,

Target* t = reinterpret_cast<Target*>(target);

#if PONY_LLVM < 600
CodeModel::Model model = jit ? CodeModel::JITDefault : CodeModel::Default;
TargetMachine* m = t->createTargetMachine(opt->triple, opt->cpu,
opt->features, options, reloc, model, opt_level);
#else
TargetMachine* m = t->createTargetMachine(opt->triple, opt->cpu,
opt->features, options, reloc, llvm::None, opt_level, jit);
#endif

return reinterpret_cast<LLVMTargetMachineRef>(m);
}
Expand Down Expand Up @@ -105,7 +109,11 @@ char* LLVMGetHostCPUFeatures()

void LLVMSetUnsafeAlgebra(LLVMValueRef inst)
{
#if PONY_LLVM < 600
unwrap<Instruction>(inst)->setHasUnsafeAlgebra(true);
#else // See https://reviews.llvm.org/D39304 for this change
unwrap<Instruction>(inst)->setHasAllowReassoc(true);
#endif
}

void LLVMSetNoUnsignedWrap(LLVMValueRef inst)
Expand Down
Loading