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

[WIP] Support LLVM12 #503

Merged
merged 15 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from 10 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
17 changes: 15 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
os: ['ubuntu-16.04', 'ubuntu-18.04', 'macos-10.15']
llvm: ['3.8', '5.0', '6.0', '7', '8', '9', '10', '11']
llvm: ['3.8', '5.0', '6.0', '7', '8', '9', '10', '11', '12']
cmake: ['0', '1']
cuda: ['0', '1']
static: ['0', '1']
Expand All @@ -38,10 +38,12 @@ jobs:
llvm: '10'
- os: 'ubuntu-16.04'
llvm: '11'
- os: 'ubuntu-16.04'
llvm: '12'
- os: 'ubuntu-18.04'
llvm: '3.8'

# macOS: exclude LLVM 5.0, 8-11 make, cuda/no-static/no-slib
# macOS: exclude LLVM 5.0, 8-12 make, cuda/no-static/no-slib
- os: 'macos-10.15'
llvm: '5.0'
- os: 'macos-10.15'
Expand All @@ -56,6 +58,9 @@ jobs:
- os: 'macos-10.15'
llvm: '11'
cmake: '0'
- os: 'macos-10.15'
llvm: '12'
cmake: '0'
- os: 'macos-10.15'
cuda: '1'
- os: 'macos-10.15'
Expand Down Expand Up @@ -103,6 +108,8 @@ jobs:
cuda: '1'
- llvm: '11'
cuda: '1'
- llvm: '12'
cuda: '1'

# no-static: only LLVM 8
- llvm: '3.8'
Expand All @@ -119,6 +126,8 @@ jobs:
static: '0'
- llvm: '11'
static: '0'
- llvm: '12'
static: '0'

# no-slib: only LLVM 9
- llvm: '3.8'
Expand All @@ -135,6 +144,8 @@ jobs:
slib: '0'
- llvm: '11'
slib: '0'
- llvm: '12'
slib: '0'

# Moonjit: only LLVM 9
- llvm: '3.8'
Expand All @@ -151,6 +162,8 @@ jobs:
lua: 'moonjit'
- llvm: '11'
lua: 'moonjit'
- llvm: '12'
lua: 'moonjit'
steps:
- uses: actions/checkout@v1
- run: ./travis.sh
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ LLVMVERGT4 := $(shell expr $(LLVM_VERSION) \>= 40)

FLAGS += -DLLVM_VERSION=$(LLVM_VERSION)

LLVM_NEEDS_CXX14="100 110 111"
LLVM_NEEDS_CXX14="100 110 111 120"
ifneq (,$(findstring $(LLVM_VERSION),$(LLVM_NEEDS_CXX14)))
CPPFLAGS += -std=c++1y # GCC 5 does not support -std=c++14 flag
else
Expand Down
2 changes: 1 addition & 1 deletion src/llvmheaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
#include "llvmheaders_90.h"
#elif LLVM_VERSION == 100
#include "llvmheaders_100.h"
#elif LLVM_VERSION >= 110 && LLVM_VERSION < 120
#elif LLVM_VERSION >= 110 && LLVM_VERSION < 130
Jcd1230 marked this conversation as resolved.
Show resolved Hide resolved
#include "llvmheaders_110.h"
#else
#error "unsupported LLVM version"
Expand Down
30 changes: 25 additions & 5 deletions src/tcompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ extern "C" {
#if LLVM_VERSION < 50
#include "llvm/ExecutionEngine/MCJIT.h"
#else
#if LLVM_VERSION < 120
#include "llvm/ExecutionEngine/OrcMCJITReplacement.h"
#endif
#endif

#include "llvm/Support/Atomic.h"
#include "llvm/Support/FileSystem.h"
Expand Down Expand Up @@ -390,7 +392,10 @@ static void InitializeJIT(TerraCompilationUnit *CU) {
#else
.setMCJITMemoryManager(std::make_unique<TerraSectionMemoryManager>(CU))
#endif
.setUseOrcMCJITReplacement(true);
#if LLVM_VERSION < 120
.setUseOrcMCJITReplacement(true)
#endif
;
#endif

CU->ee = eb.create();
Expand Down Expand Up @@ -952,13 +957,21 @@ struct CCallingConv {
}

template <typename FnOrCall>
void addSRetAttr(FnOrCall *r, int idx) {
void addSRetAttr(FnOrCall *r, int idx, Type *ty) {
#if LLVM_VERSION < 120
r->addAttribute(idx, Attribute::StructRet);
#else
r->addAttribute(idx, Attribute::getWithStructRetType(*CU->TT->ctx, ty));
#endif
r->addAttribute(idx, Attribute::NoAlias);
}
template <typename FnOrCall>
void addByValAttr(FnOrCall *r, int idx) {
void addByValAttr(FnOrCall *r, int idx, Type *ty) {
#if LLVM_VERSION < 120
r->addAttribute(idx, Attribute::ByVal);
#else
r->addAttribute(idx, Attribute::getWithByValType(*CU->TT->ctx, ty));
#endif
}
template <typename FnOrCall>
void addExtAttrIfNeeded(TType *t, FnOrCall *r, int idx) {
Expand All @@ -971,14 +984,14 @@ struct CCallingConv {
addExtAttrIfNeeded(info->returntype.type, r, 0);
int argidx = 1;
if (info->returntype.kind == C_AGGREGATE_MEM) {
addSRetAttr(r, argidx);
addSRetAttr(r, argidx, info->returntype.cctype);
argidx++;
}
for (size_t i = 0; i < info->paramtypes.size(); i++) {
Argument *v = &info->paramtypes[i];
if (v->kind == C_AGGREGATE_MEM) {
#ifndef _WIN32
addByValAttr(r, argidx);
addByValAttr(r, argidx, v->cctype);
#endif
}
addExtAttrIfNeeded(v->type, r, argidx);
Expand Down Expand Up @@ -2488,9 +2501,16 @@ struct FunctionEmitter {
DEBUG_ONLY(T) {
MDNode *scope = debugScopeForFile(customfilename ? customfilename
: obj->string("filename"));
#if LLVM_VERSION < 120
B->SetCurrentDebugLocation(DebugLoc::get(
customfilename ? customlinenumber : obj->number("linenumber"), 0,
scope));
#else
B->SetCurrentDebugLocation(DILocation::get(
scope->getContext(),
customfilename ? customlinenumber : obj->number("linenumber"), 0,
scope));
#endif
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/tcwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,14 @@ class IncludeCVisitor : public RecursiveASTVisitor<IncludeCVisitor> {
}
CStyleCastExpr *CreateCast(QualType Ty, CastKind Kind, Expr *E) {
TypeSourceInfo *TInfo = Context->getTrivialTypeSourceInfo(Ty, SourceLocation());
#if LLVM_VERSION < 120
return CStyleCastExpr::Create(*Context, Ty, VK_RValue, Kind, E, 0, TInfo,
SourceLocation(), SourceLocation());
#else
return CStyleCastExpr::Create(*Context, Ty, VK_RValue, Kind, E, 0,
FPOptionsOverride::getFromOpaqueInt(0), TInfo,
SourceLocation(), SourceLocation());
#endif
}
IntegerLiteral *LiteralZero() {
unsigned IntSize = static_cast<unsigned>(Context->getTypeSize(Context->IntTy));
Expand Down
19 changes: 17 additions & 2 deletions travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ fi

if [[ $(uname) = Linux ]]; then
sudo apt-get update -qq
if [[ $LLVM_CONFIG = llvm-config-11 ]]; then
if [[ $LLVM_CONFIG = llvm-config-12 ]]; then
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository -y "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-12 main"
for i in {1..5}; do sudo apt-get update -qq && break || sleep 15; done
sudo apt-get install -y llvm-12-dev clang-12 libclang-12-dev libedit-dev
export CMAKE_PREFIX_PATH=/usr/lib/llvm-12:/usr/share/llvm-12
if [[ -n $STATIC_LLVM && $STATIC_LLVM -eq 0 ]]; then
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/lib/llvm-12/lib"
fi
elif [[ $LLVM_CONFIG = llvm-config-11 ]]; then
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository -y "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main"
for i in {1..5}; do sudo apt-get update -qq && break || sleep 15; done
Expand Down Expand Up @@ -81,7 +90,13 @@ if [[ $(uname) = Linux ]]; then
fi

if [[ $(uname) = Darwin ]]; then
if [[ $LLVM_CONFIG = llvm-config-11 ]]; then
if [[ $LLVM_CONFIG = llvm-config-12 ]]; then
curl -L -O https://github.com/elliottslaughter/llvm-build/releases/download/llvm-12.0.1/clang+llvm-12.0.1-x86_64-apple-darwin.tar.xz
tar xf clang+llvm-12.0.1-x86_64-apple-darwin.tar.xz
ln -s clang+llvm-12.0.1-x86_64-apple-darwin/bin/llvm-config llvm-config-12
ln -s clang+llvm-12.0.1-x86_64-apple-darwin/bin/clang clang-12
export CMAKE_PREFIX_PATH=$PWD/clang+llvm-12.0.1-x86_64-apple-darwin
elif [[ $LLVM_CONFIG = llvm-config-11 ]]; then
curl -L -O https://github.com/elliottslaughter/llvm-build/releases/download/llvm-11.0.1/clang+llvm-11.0.1-x86_64-apple-darwin.tar.xz
tar xf clang+llvm-11.0.1-x86_64-apple-darwin.tar.xz
ln -s clang+llvm-11.0.1-x86_64-apple-darwin/bin/llvm-config llvm-config-11
Expand Down