You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2020/05/28 19:16:26 UTC
[arrow] branch master updated: ARROW-8968: [C++][Gandiva] set data
layout for pre-compiled IR to llvm::module
This is an automated email from the ASF dual-hosted git repository.
wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new bbc3e30 ARROW-8968: [C++][Gandiva] set data layout for pre-compiled IR to llvm::module
bbc3e30 is described below
commit bbc3e30c9da89db4315a57cb0e42d6c21e507aaa
Author: Kazuaki Ishizaki <is...@jp.ibm.com>
AuthorDate: Thu May 28 14:15:43 2020 -0500
ARROW-8968: [C++][Gandiva] set data layout for pre-compiled IR to llvm::module
This PR explicitly sets data layout for pre-compiled IR to `llvm:module`. Without the PR, the following warning message is shown at link time of gandiva.
Most of this code comes from https://reviews.llvm.org/D80130 by @imaihal in llvm.
```
~/arrow/cpp/src/gandiva$ ../../build/debug/gandiva-binary-test -V
Running main() from /home/ishizaki/arrow/cpp/googletest_ep-prefix/src/googletest_ep/googletest/src/gtest_main.cc
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from TestBinary
[ RUN ] TestBinary.TestSimple
warning: Linking two modules of different data layouts: 'precompiled' is 'E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64' whereas 'codegen' is 'E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64'
[ OK ] TestBinary.TestSimple (41 ms)
[----------] 1 test from TestBinary (41 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (41 ms total)
[ PASSED ] 1 test.
```
Closes #7295 from kiszk/ARROW-8968
Authored-by: Kazuaki Ishizaki <is...@jp.ibm.com>
Signed-off-by: Wes McKinney <we...@apache.org>
---
LICENSE.txt | 5 +++--
cpp/src/gandiva/engine.cc | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/LICENSE.txt b/LICENSE.txt
index 113a894..170b76c 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1068,8 +1068,9 @@ support library is itself covered by the above license.
--------------------------------------------------------------------------------
-3rdparty dependency LLVM is statically linked in certain binary
-distributions. LLVM has the following license:
+3rdparty dependency LLVM is statically linked in certain binary distributions.
+Additionally some sections of source code have been derived from sources in LLVM
+and have been clearly labeled as such. LLVM has the following license:
==============================================================================
LLVM Release License
diff --git a/cpp/src/gandiva/engine.cc b/cpp/src/gandiva/engine.cc
index d1e1aff..ad73751 100644
--- a/cpp/src/gandiva/engine.cc
+++ b/cpp/src/gandiva/engine.cc
@@ -51,7 +51,9 @@
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/IR/Verifier.h>
#include <llvm/Linker/Linker.h>
+#include <llvm/MC/SubtargetFeature.h>
#include <llvm/Support/DynamicLibrary.h>
+#include <llvm/Support/TargetRegistry.h>
#include <llvm/Support/TargetSelect.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/Transforms/IPO.h>
@@ -150,6 +152,40 @@ Status Engine::Make(const std::shared_ptr<Configuration>& conf,
return Status::OK();
}
+// This method was modified from its original version for a part of MLIR
+// Original source from
+// https://github.com/llvm/llvm-project/blob/9f2ce5b915a505a5488a5cf91bb0a8efa9ddfff7/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
+// The original copyright notice follows.
+
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+static void SetDataLayout(llvm::Module* module) {
+ auto target_triple = llvm::sys::getDefaultTargetTriple();
+ std::string error_message;
+ auto target = llvm::TargetRegistry::lookupTarget(target_triple, error_message);
+ if (!target) {
+ return;
+ }
+
+ std::string cpu(llvm::sys::getHostCPUName());
+ llvm::SubtargetFeatures features;
+ llvm::StringMap<bool> host_features;
+
+ if (llvm::sys::getHostCPUFeatures(host_features)) {
+ for (auto& f : host_features) {
+ features.AddFeature(f.first(), f.second);
+ }
+ }
+
+ std::unique_ptr<llvm::TargetMachine> machine(
+ target->createTargetMachine(target_triple, cpu, features.getString(), {}, {}));
+
+ module->setDataLayout(machine->createDataLayout());
+}
+// end of the mofified method from MLIR
+
// Handling for pre-compiled IR libraries.
Status Engine::LoadPreCompiledIR() {
auto bitcode = llvm::StringRef(reinterpret_cast<const char*>(kPrecompiledBitcode),
@@ -178,6 +214,9 @@ Status Engine::LoadPreCompiledIR() {
}
std::unique_ptr<llvm::Module> ir_module = move(module_or_error.get());
+ // set dataLayout
+ SetDataLayout(ir_module.get());
+
ARROW_RETURN_IF(llvm::verifyModule(*ir_module, &llvm::errs()),
Status::CodeGenError("verify of IR Module failed"));
ARROW_RETURN_IF(llvm::Linker::linkModules(*module_, move(ir_module)),