Skip to content

Commit

Permalink
[ltsmaster] Add support for LLVM 6
Browse files Browse the repository at this point in the history
Adds the necessary changes to support LLVM 6.
  • Loading branch information
redstar committed Feb 28, 2018
1 parent 4d580ea commit 22eaa34
Show file tree
Hide file tree
Showing 10 changed files with 1,494 additions and 13 deletions.
18 changes: 16 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ sudo: false

matrix:
include:
- os: linux
env: LLVM_VERSION=6.0.0-rc3
- os: linux
env: LLVM_VERSION=5.0.1
- os: linux
Expand All @@ -23,6 +25,7 @@ matrix:

cache:
directories:
- llvm-6.0.0-rc3
- llvm-5.0.1
- llvm-4.0.1
- llvm-4.0.0
Expand Down Expand Up @@ -55,7 +58,11 @@ before_install:
export LLVM_ARCH="x86_64-apple-darwin";
fi;
if [ -z "$(ls -A llvm-$LLVM_VERSION)" ]; then
wget -O llvm-$LLVM_VERSION.tar.xz http://llvm.org/releases/$LLVM_VERSION/clang+llvm-$LLVM_VERSION-${LLVM_ARCH}.tar.xz;
if [ "${LLVM_VERSION}" = "6.0.0-rc3" ]; then
wget -O llvm-$LLVM_VERSION.tar.xz http://prereleases.llvm.org/6.0.0/rc3/clang+llvm-6.0.0-rc3-x86_64-linux-gnu-debian8.tar.xz;
else
wget -O llvm-$LLVM_VERSION.tar.xz http://llvm.org/releases/$LLVM_VERSION/clang+llvm-$LLVM_VERSION-${LLVM_ARCH}.tar.xz;
fi;
mkdir llvm-$LLVM_VERSION;
tar -xf llvm-$LLVM_VERSION.tar.xz --strip 1 -C llvm-$LLVM_VERSION;
fi;
Expand All @@ -64,7 +71,14 @@ before_install:
export LLVM_CONFIG="llvm-$LLVM_VERSION/bin/llvm-config";

install:
- if [ "${TRAVIS_OS_NAME}" = "linux" ]; then export CC="gcc-4.9"; export CXX="g++-4.9"; fi
-
if [ "${TRAVIS_OS_NAME}" = "linux" ]; then
if [ "${LLVM_VERSION}" = "6.0.0-rc3" ]; then
export CC="$PWD/llvm-$LLVM_VERSION/bin/clang"; export CXX="$PWD/llvm-$LLVM_VERSION/bin/clang++";
else
export CC="gcc-4.9"; export CXX="g++-4.9";
fi
fi
-
if [ "${TRAVIS_OS_NAME}" = "osx" ]; then
brew update; brew install ninja libconfig;
Expand Down
3 changes: 2 additions & 1 deletion cmake/Modules/FindLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
# We also want an user-specified LLVM_ROOT_DIR to take precedence over the
# system default locations such as /usr/local/bin. Executing find_program()
# multiples times is the approach recommended in the docs.
set(llvm_config_names llvm-config-5.0 llvm-config50
set(llvm_config_names llvm-config-6.0 llvm-config60
llvm-config-5.0 llvm-config50
llvm-config-4.0 llvm-config40
llvm-config-3.9 llvm-config39
llvm-config-3.8 llvm-config38
Expand Down
7 changes: 6 additions & 1 deletion driver/cl_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,15 @@ cl::opt<llvm::Reloc::Model> mRelocModel(
"Relocatable external references, non-relocatable code")));

cl::opt<llvm::CodeModel::Model> mCodeModel(
"code-model", cl::desc("Code model"), cl::init(llvm::CodeModel::Default),
"code-model", cl::desc("Code model"),
#if LDC_LLVM_VER < 600
cl::init(llvm::CodeModel::Default),
#endif
clEnumValues(
#if LDC_LLVM_VER < 600
clEnumValN(llvm::CodeModel::Default, "default",
"Target default code model"),
#endif
clEnumValN(llvm::CodeModel::Small, "small", "Small code model"),
clEnumValN(llvm::CodeModel::Kernel, "kernel", "Kernel code model"),
clEnumValN(llvm::CodeModel::Medium, "medium", "Medium code model"),
Expand Down
8 changes: 7 additions & 1 deletion driver/ldmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@ char *concat(const char *a, int b) {
*/
int execute(const std::string &exePath, const char **args) {
std::string errorMsg;
int rc = ls::ExecuteAndWait(exePath, args, nullptr, nullptr, 0, 0, &errorMsg);
int rc = ls::ExecuteAndWait(exePath, args, nullptr,
#if LDC_LLVM_VER >= 600
{},
#else
nullptr,
#endif
0, 0, &errorMsg);
if (!errorMsg.empty()) {
error("Error executing %s: %s", exePath.c_str(), errorMsg.c_str());
}
Expand Down
14 changes: 12 additions & 2 deletions driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
#if LDC_LLVM_VER >= 306
#if LDC_LLVM_VER >= 600
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#elif LDC_LLVM_VER >= 306
#include "llvm/Target/TargetSubtargetInfo.h"
#endif
#include "llvm/LinkAllIR.h"
Expand Down Expand Up @@ -140,7 +142,11 @@ void printVersion(llvm::raw_ostream &OS) {
// redirecting stdout to a file.
OS.flush();

llvm::TargetRegistry::printRegisteredTargetsForVersion();
llvm::TargetRegistry::printRegisteredTargetsForVersion(
#if LDC_LLVM_VER >= 600
OS
#endif
);

exit(EXIT_SUCCESS);
}
Expand Down Expand Up @@ -342,7 +348,11 @@ static void parseCommandLine(int argc, char **argv, Strings &sourceFiles,

final_args.insert(final_args.end(), &argv[1], &argv[argc]);

#if LDC_LLVM_VER >= 600
cl::SetVersionPrinter(&printVersion);
#else
cl::SetVersionPrinter(&printVersionStdout);
#endif

hideLLVMOptions();
cl::ParseCommandLineOptions(final_args.size(),
Expand Down
4 changes: 3 additions & 1 deletion driver/toobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
#if LDC_LLVM_VER >= 307
#include "llvm/Analysis/TargetTransformInfo.h"
#endif
#if LDC_LLVM_VER >= 306
#if LDC_LLVM_VER >= 600
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#elif LDC_LLVM_VER >= 306
#include "llvm/Target/TargetSubtargetInfo.h"
#endif
#include "llvm/IR/Module.h"
Expand Down
7 changes: 6 additions & 1 deletion driver/tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ int executeToolAndWait(const std::string &tool,
// Execute tool.
std::string errstr;
if (int status = llvm::sys::ExecuteAndWait(tool, &realargs[0], nullptr,
nullptr, 0, 0, &errstr)) {
#if LDC_LLVM_VER >= 600
{},
#else
nullptr,
#endif
0, 0, &errstr)) {
error(Loc(), "%s failed with status: %d", tool.c_str(), status);
if (!errstr.empty()) {
error(Loc(), "message: %s", errstr.c_str());
Expand Down
8 changes: 6 additions & 2 deletions gen/dibuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void ldc::DIBuilder::SetValue(const Loc &loc, llvm::Value *value,
unsigned charnum = (loc.linnum ? loc.charnum : 0);
auto debugLoc = llvm::DebugLoc::get(loc.linnum, charnum, GetCurrentScope());
#if LDC_LLVM_VER < 307
llvm::Instruction *instr = DBuilder.insertDbgValueIntrinsic(value, divar,
llvm::Instruction *instr = DBuilder.insertDbgValueIntrinsic(value, 0, divar,
#if LDC_LLVM_VER >= 306
diexpr,
#endif
Expand Down Expand Up @@ -864,7 +864,11 @@ void ldc::DIBuilder::EmitValue(llvm::Value *val, VarDeclaration *vd) {
}

llvm::Instruction *instr =
DBuilder.insertDbgValueIntrinsic(val, 0, debugVariable,
DBuilder.insertDbgValueIntrinsic(val,
#if LDC_LLVM_VER < 600
0,
#endif
debugVariable,
#if LDC_LLVM_VER >= 306
DBuilder.createExpression(),
#endif
Expand Down
Loading

0 comments on commit 22eaa34

Please sign in to comment.