Discussion:
[Mesa-dev] [PATCH 2/3] clover: Cleanup compat code for llvm < 3.9
Jan Vesely
2018-05-22 23:43:19 UTC
Permalink
Signed-off-by: Jan Vesely <***@rutgers.edu>
---
I've confirmed that simple piglits run on turks(llvm-7) and
carrizo(llvm-6,7). Travis says it builds ok for all supported llvm
versions.

.../clover/llvm/codegen/native.cpp | 7 +-
.../state_trackers/clover/llvm/compat.hpp | 109 +-----------------
.../state_trackers/clover/llvm/invocation.cpp | 25 ++--
3 files changed, 20 insertions(+), 121 deletions(-)

diff --git a/src/gallium/state_trackers/clover/llvm/codegen/native.cpp b/src/gallium/state_trackers/clover/llvm/codegen/native.cpp
index 4b589ef50c..a6c9ba1f52 100644
--- a/src/gallium/state_trackers/clover/llvm/codegen/native.cpp
+++ b/src/gallium/state_trackers/clover/llvm/codegen/native.cpp
@@ -114,8 +114,7 @@ namespace {

std::unique_ptr<TargetMachine> tm {
t->createTargetMachine(target.triple, target.cpu, "", {},
- compat::default_reloc_model,
- compat::default_code_model,
+ ::llvm::None, compat::default_code_model,
::llvm::CodeGenOpt::Default) };
if (!tm)
fail(r_log, build_error(),
@@ -124,10 +123,10 @@ namespace {
::llvm::SmallVector<char, 1024> data;

{
- compat::pass_manager pm;
+ ::llvm::legacy::PassManager pm;
::llvm::raw_svector_ostream os { data };

- mod.setDataLayout(compat::get_data_layout(*tm));
+ mod.setDataLayout(tm->createDataLayout());
tm->Options.MCOptions.AsmVerbose =
(ft == TargetMachine::CGFT_AssemblyFile);

diff --git a/src/gallium/state_trackers/clover/llvm/compat.hpp b/src/gallium/state_trackers/clover/llvm/compat.hpp
index 96ba798970..8f2f128048 100644
--- a/src/gallium/state_trackers/clover/llvm/compat.hpp
+++ b/src/gallium/state_trackers/clover/llvm/compat.hpp
@@ -54,15 +54,8 @@
#include <llvm/Support/ErrorOr.h>
#endif

-#if HAVE_LLVM >= 0x0307
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/Analysis/TargetLibraryInfo.h>
-#else
-#include <llvm/PassManager.h>
-#include <llvm/Target/TargetLibraryInfo.h>
-#include <llvm/Target/TargetSubtargetInfo.h>
-#include <llvm/Support/FormattedStream.h>
-#endif

#include <clang/Basic/TargetInfo.h>
#include <clang/Frontend/CodeGenOptions.h>
@@ -71,12 +64,6 @@
namespace clover {
namespace llvm {
namespace compat {
-#if HAVE_LLVM >= 0x0307
- typedef ::llvm::TargetLibraryInfoImpl target_library_info;
-#else
- typedef ::llvm::TargetLibraryInfo target_library_info;
-#endif
-
template<typename T, typename AS>
unsigned target_address_space(const T &target, const AS lang_as) {
const auto &map = target.getAddressSpaceMap();
@@ -95,19 +82,6 @@ namespace clover {
const clang::LangStandard::Kind lang_opencl10 = clang::LangStandard::lang_opencl;
#endif

- inline void
- set_lang_defaults(clang::CompilerInvocation &inv,
- clang::LangOptions &lopts, clang::InputKind ik,
- const ::llvm::Triple &t,
- clang::PreprocessorOptions &ppopts,
- clang::LangStandard::Kind std) {
-#if HAVE_LLVM >= 0x0309
- inv.setLangDefaults(lopts, ik, t, ppopts, std);
-#else
- inv.setLangDefaults(lopts, ik, std);
-#endif
- }
-
inline void
add_link_bitcode_file(clang::CodeGenOptions &opts,
const std::string &path) {
@@ -118,78 +92,8 @@ namespace clover {
F.PropagateAttrs = true;
F.LinkFlags = ::llvm::Linker::Flags::None;
opts.LinkBitcodeFiles.emplace_back(F);
-#elif HAVE_LLVM >= 0x0308
- opts.LinkBitcodeFiles.emplace_back(::llvm::Linker::Flags::None, path);
-#else
- opts.LinkBitcodeFile = path;
-#endif
- }
-
-#if HAVE_LLVM >= 0x0307
- typedef ::llvm::legacy::PassManager pass_manager;
-#else
- typedef ::llvm::PassManager pass_manager;
-#endif
-
- inline void
- add_data_layout_pass(pass_manager &pm) {
-#if HAVE_LLVM < 0x0307
- pm.add(new ::llvm::DataLayoutPass());
-#endif
- }
-
- inline void
- add_internalize_pass(pass_manager &pm,
- const std::vector<std::string> &names) {
-#if HAVE_LLVM >= 0x0309
- pm.add(::llvm::createInternalizePass(
- [=](const ::llvm::GlobalValue &gv) {
- return std::find(names.begin(), names.end(),
- gv.getName()) != names.end();
- }));
#else
- pm.add(::llvm::createInternalizePass(std::vector<const char *>(
- map(std::mem_fn(&std::string::data), names))));
-#endif
- }
-
- inline std::unique_ptr< ::llvm::Linker>
- create_linker(::llvm::Module &mod) {
-#if HAVE_LLVM >= 0x0308
- return std::unique_ptr< ::llvm::Linker>(new ::llvm::Linker(mod));
-#else
- return std::unique_ptr< ::llvm::Linker>(new ::llvm::Linker(&mod));
-#endif
- }
-
- inline bool
- link_in_module(::llvm::Linker &linker,
- std::unique_ptr< ::llvm::Module> mod) {
-#if HAVE_LLVM >= 0x0308
- return linker.linkInModule(std::move(mod));
-#else
- return linker.linkInModule(mod.get());
-#endif
- }
-
-#if HAVE_LLVM >= 0x0307
- typedef ::llvm::raw_svector_ostream &raw_ostream_to_emit_file;
-#else
- typedef ::llvm::formatted_raw_ostream raw_ostream_to_emit_file;
-#endif
-
-#if HAVE_LLVM >= 0x0307
- typedef ::llvm::DataLayout data_layout;
-#else
- typedef const ::llvm::DataLayout *data_layout;
-#endif
-
- inline data_layout
- get_data_layout(::llvm::TargetMachine &tm) {
-#if HAVE_LLVM >= 0x0307
- return tm.createDataLayout();
-#else
- return tm.getSubtargetImpl()->getDataLayout();
+ opts.LinkBitcodeFiles.emplace_back(::llvm::Linker::Flags::None, path);
#endif
}

@@ -199,12 +103,6 @@ namespace clover {
const auto default_code_model = ::llvm::CodeModel::Default;
#endif

-#if HAVE_LLVM >= 0x0309
- const auto default_reloc_model = ::llvm::None;
-#else
- const auto default_reloc_model = ::llvm::Reloc::Default;
-#endif
-
template<typename M, typename F> void
handle_module_error(M &mod, const F &f) {
#if HAVE_LLVM >= 0x0400
@@ -250,11 +148,10 @@ namespace clover {
template<typename TM, typename PM, typename OS, typename FT>
bool add_passes_to_emit_file(TM &tm, PM &pm, OS &os, FT &ft)
{
- compat::raw_ostream_to_emit_file fos(os);
#if HAVE_LLVM >= 0x0700
- return tm.addPassesToEmitFile(pm, fos, nullptr, ft);
+ return tm.addPassesToEmitFile(pm, os, nullptr, ft);
#else
- return tm.addPassesToEmitFile(pm, fos, ft);
+ return tm.addPassesToEmitFile(pm, os, ft);
#endif
}
}
diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp
index b2c64bc48f..0a677ce2ea 100644
--- a/src/gallium/state_trackers/clover/llvm/invocation.cpp
+++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp
@@ -216,7 +216,7 @@ namespace {
// http://www.llvm.org/bugs/show_bug.cgi?id=19735
c->getDiagnosticOpts().ShowCarets = false;

- compat::set_lang_defaults(c->getInvocation(), c->getLangOpts(),
+ c->getInvocation().setLangDefaults(c->getLangOpts(),
compat::ik_opencl, ::llvm::Triple(target.triple),
c->getPreprocessorOpts(),
get_language_version(opts, device_clc_version));
@@ -314,9 +314,7 @@ namespace {
void
optimize(Module &mod, unsigned optimization_level,
bool internalize_symbols) {
- compat::pass_manager pm;
-
- compat::add_data_layout_pass(pm);
+ ::llvm::legacy::PassManager pm;

// By default, the function internalizer pass will look for a function
// called "main" and then mark all other functions as internal. Marking
@@ -330,13 +328,19 @@ namespace {
// list of kernel functions to the internalizer. The internalizer will
// treat the functions in the list as "main" functions and internalize
// all of the other functions.
- if (internalize_symbols)
- compat::add_internalize_pass(pm, map(std::mem_fn(&Function::getName),
- get_kernels(mod)));
+ if (internalize_symbols) {
+ std::vector<std::string> names =
+ map(std::mem_fn(&Function::getName), get_kernels(mod));
+ pm.add(::llvm::createInternalizePass(
+ [=](const ::llvm::GlobalValue &gv) {
+ return std::find(names.begin(), names.end(),
+ gv.getName()) != names.end();
+ }));
+ }

::llvm::PassManagerBuilder pmb;
pmb.OptLevel = optimization_level;
- pmb.LibraryInfo = new compat::target_library_info(
+ pmb.LibraryInfo = new ::llvm::TargetLibraryInfoImpl(
::llvm::Triple(mod.getTargetTriple()));
pmb.populateModulePassManager(pm);
pm.run(mod);
@@ -346,11 +350,10 @@ namespace {
link(LLVMContext &ctx, const clang::CompilerInstance &c,
const std::vector<module> &modules, std::string &r_log) {
std::unique_ptr<Module> mod { new Module("link", ctx) };
- auto linker = compat::create_linker(*mod);
+ std::unique_ptr< ::llvm::Linker> linker { new ::llvm::Linker(*mod) };

for (auto &m : modules) {
- if (compat::link_in_module(*linker,
- parse_module_library(m, ctx, r_log)))
+ if (linker->linkInModule(parse_module_library(m, ctx, r_log)))
throw build_error();
}
--
2.17.0
Jan Vesely
2018-05-22 23:43:20 UTC
Permalink
Signed-off-by: Jan Vesely <***@rutgers.edu>
---
.travis.yml | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)

diff --git a/.travis.yml b/.travis.yml
index e3471d47ac..33dcbcc8da 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -290,6 +290,41 @@ matrix:
- libx11-xcb-dev
- libelf-dev
- libunwind8-dev
+ - env:
+ # NOTE: Analogous to SWR above, building Clover is quite slow.
+ - LABEL="make Gallium ST Clover LLVM-6.0"
+ - BUILD=make
+ - MAKEFLAGS="-j4"
+ - MAKE_CHECK_COMMAND="true"
+ - LLVM_VERSION=6.0
+ - LLVM_CONFIG="llvm-config-${LLVM_VERSION}"
+ - OVERRIDE_CC=gcc-4.8
+ - OVERRIDE_CXX=g++-4.8
+ - DRI_LOADERS="--disable-glx --disable-gbm --disable-egl"
+ - DRI_DRIVERS=""
+ - GALLIUM_ST="--disable-dri --enable-opencl --enable-opencl-icd --enable-llvm --disable-xa --disable-nine --disable-xvmc --disable-vdpau --disable-va --disable-omx-bellagio --disable-gallium-osmesa"
+ - GALLIUM_DRIVERS="r600,radeonsi"
+ - VULKAN_DRIVERS=""
+ - LIBUNWIND_FLAGS="--enable-libunwind"
+ addons:
+ apt:
+ sources:
+ - llvm-toolchain-trusty-6.0
+ # llvm-6 depends on gcc-4.9 which is not in main repo
+ - ubuntu-toolchain-r-test
+ packages:
+ - libclc-dev
+ # From sources above
+ - llvm-6.0-dev
+ - clang-6.0
+ - libclang-6.0-dev
+ # Common
+ - xz-utils
+ - x11proto-xf86vidmode-dev
+ - libexpat1-dev
+ - libx11-xcb-dev
+ - libelf-dev
+ - libunwind8-dev
- env:
- LABEL="make Gallium ST Other"
- BUILD=make
--
2.17.0
Aaron Watry
2018-05-24 18:08:06 UTC
Permalink
r332881 added an extra parameter to the emit function.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=106619
---
.../state_trackers/clover/llvm/codegen/native.cpp | 3 +--
src/gallium/state_trackers/clover/llvm/compat.hpp | 10 ++++++++++
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/gallium/state_trackers/clover/llvm/codegen/native.cpp b/src/gallium/state_trackers/clover/llvm/codegen/native.cpp
index 409f8ac32f..4b589ef50c 100644
--- a/src/gallium/state_trackers/clover/llvm/codegen/native.cpp
+++ b/src/gallium/state_trackers/clover/llvm/codegen/native.cpp
@@ -126,13 +126,12 @@ namespace {
{
compat::pass_manager pm;
::llvm::raw_svector_ostream os { data };
- compat::raw_ostream_to_emit_file fos(os);
mod.setDataLayout(compat::get_data_layout(*tm));
tm->Options.MCOptions.AsmVerbose =
(ft == TargetMachine::CGFT_AssemblyFile);
- if (tm->addPassesToEmitFile(pm, fos, ft))
+ if (compat::add_passes_to_emit_file(*tm, pm, os, ft))
Looks like you need to add another space here to stay consistent with
the existing indentation.
fail(r_log, build_error(), "TargetMachine can't emit this file");
pm.run(mod);
diff --git a/src/gallium/state_trackers/clover/llvm/compat.hpp b/src/gallium/state_trackers/clover/llvm/compat.hpp
index 2e070b2eef..96ba798970 100644
--- a/src/gallium/state_trackers/clover/llvm/compat.hpp
+++ b/src/gallium/state_trackers/clover/llvm/compat.hpp
@@ -245,6 +245,16 @@ namespace clover {
::llvm::WriteBitcodeToFile(mod, os);
#else
::llvm::WriteBitcodeToFile(&mod, os);
+#endif
+ }
Add an empty line before this function to separate it from the previous?

With those changes, this one is Tested/Reviewed-By: Aaron Watry
<***@gmail.com>

Patch 2 and 3 are Reviewed-by: Aaron Watry <***@gmail.com>

I've only tested patch 2 on LLVM 7 with a couple CTS tests as a smoke
test, and patch 3 is just visually reviewed/diffed with the existing
LLVM 5 configuration.

--Aaron
+ template<typename TM, typename PM, typename OS, typename FT>
+ bool add_passes_to_emit_file(TM &tm, PM &pm, OS &os, FT &ft)
+ {
+ compat::raw_ostream_to_emit_file fos(os);
+#if HAVE_LLVM >= 0x0700
+ return tm.addPassesToEmitFile(pm, fos, nullptr, ft);
+#else
+ return tm.addPassesToEmitFile(pm, fos, ft);
#endif
}
}
--
2.17.0
_______________________________________________
mesa-dev mailing list
https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Jan Vesely
2018-05-24 22:41:27 UTC
Permalink
Post by Aaron Watry
r332881 added an extra parameter to the emit function.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=106619
---
.../state_trackers/clover/llvm/codegen/native.cpp | 3 +--
src/gallium/state_trackers/clover/llvm/compat.hpp | 10 ++++++++++
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/gallium/state_trackers/clover/llvm/codegen/native.cpp b/src/gallium/state_trackers/clover/llvm/codegen/native.cpp
index 409f8ac32f..4b589ef50c 100644
--- a/src/gallium/state_trackers/clover/llvm/codegen/native.cpp
+++ b/src/gallium/state_trackers/clover/llvm/codegen/native.cpp
@@ -126,13 +126,12 @@ namespace {
{
compat::pass_manager pm;
::llvm::raw_svector_ostream os { data };
- compat::raw_ostream_to_emit_file fos(os);
mod.setDataLayout(compat::get_data_layout(*tm));
tm->Options.MCOptions.AsmVerbose =
(ft == TargetMachine::CGFT_AssemblyFile);
- if (tm->addPassesToEmitFile(pm, fos, ft))
+ if (compat::add_passes_to_emit_file(*tm, pm, os, ft))
Looks like you need to add another space here to stay consistent with
the existing indentation.
fail(r_log, build_error(), "TargetMachine can't emit this file");
pm.run(mod);
diff --git a/src/gallium/state_trackers/clover/llvm/compat.hpp b/src/gallium/state_trackers/clover/llvm/compat.hpp
index 2e070b2eef..96ba798970 100644
--- a/src/gallium/state_trackers/clover/llvm/compat.hpp
+++ b/src/gallium/state_trackers/clover/llvm/compat.hpp
@@ -245,6 +245,16 @@ namespace clover {
::llvm::WriteBitcodeToFile(mod, os);
#else
::llvm::WriteBitcodeToFile(&mod, os);
+#endif
+ }
Add an empty line before this function to separate it from the previous?
With those changes, this one is Tested/Reviewed-By: Aaron Watry
I've only tested patch 2 on LLVM 7 with a couple CTS tests as a smoke
test, and patch 3 is just visually reviewed/diffed with the existing
LLVM 5 configuration.
thanks. I've made the whitespace changes locally. I also modified patch
3 to use gcc-4.9 for build since llvm-6 package brings it in anyway
(and depends on libgcc-4.9)

Jan
Post by Aaron Watry
--Aaron
+ template<typename TM, typename PM, typename OS, typename FT>
+ bool add_passes_to_emit_file(TM &tm, PM &pm, OS &os, FT &ft)
+ {
+ compat::raw_ostream_to_emit_file fos(os);
+#if HAVE_LLVM >= 0x0700
+ return tm.addPassesToEmitFile(pm, fos, nullptr, ft);
+#else
+ return tm.addPassesToEmitFile(pm, fos, ft);
#endif
}
}
--
2.17.0
_______________________________________________
mesa-dev mailing list
https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Loading...