aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers
diff options
context:
space:
mode:
authorFrancisco Jerez <[email protected]>2016-05-17 16:03:00 +0200
committerFrancisco Jerez <[email protected]>2016-07-11 20:34:33 -0700
commit8195637363c9a5d979831405390157b11ecfc170 (patch)
tree88b8bf52a8c81ef37dc285bceec09744f45a688b /src/gallium/state_trackers
parent71ac9820d6c612a3a0cd8fcea87f7f2bde82d640 (diff)
clover/llvm: Split bitcode codegen into separate file.
Reviewed-by: Serge Martin <[email protected]> Tested-by: Jan Vesely <[email protected]>
Diffstat (limited to 'src/gallium/state_trackers')
-rw-r--r--src/gallium/state_trackers/clover/Makefile.sources1
-rw-r--r--src/gallium/state_trackers/clover/llvm/codegen.hpp7
-rw-r--r--src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp76
-rw-r--r--src/gallium/state_trackers/clover/llvm/invocation.cpp35
4 files changed, 84 insertions, 35 deletions
diff --git a/src/gallium/state_trackers/clover/Makefile.sources b/src/gallium/state_trackers/clover/Makefile.sources
index 2f456110d22..bf0a5331938 100644
--- a/src/gallium/state_trackers/clover/Makefile.sources
+++ b/src/gallium/state_trackers/clover/Makefile.sources
@@ -54,6 +54,7 @@ CPP_SOURCES := \
util/tuple.hpp
LLVM_SOURCES := \
+ llvm/codegen/bitcode.cpp \
llvm/codegen/common.cpp \
llvm/codegen.hpp \
llvm/compat.hpp \
diff --git a/src/gallium/state_trackers/clover/llvm/codegen.hpp b/src/gallium/state_trackers/clover/llvm/codegen.hpp
index 23f3b17e112..929bbda004f 100644
--- a/src/gallium/state_trackers/clover/llvm/codegen.hpp
+++ b/src/gallium/state_trackers/clover/llvm/codegen.hpp
@@ -38,6 +38,13 @@
namespace clover {
namespace llvm {
module
+ build_module_bitcode(const ::llvm::Module &mod,
+ const clang::CompilerInstance &c);
+
+ std::string
+ print_module_bitcode(const ::llvm::Module &mod);
+
+ module
build_module_common(const ::llvm::Module &mod,
const std::vector<char> &code,
const std::map<std::string, unsigned> &offsets,
diff --git a/src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp b/src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp
new file mode 100644
index 00000000000..d2baa07fdf9
--- /dev/null
+++ b/src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp
@@ -0,0 +1,76 @@
+//
+// Copyright 2012-2016 Francisco Jerez
+// Copyright 2012-2016 Advanced Micro Devices, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+///
+/// \file
+/// Trivial codegen back-end that simply passes through the existing LLVM IR
+/// and formats it so it can be consumed by pipe drivers.
+///
+
+#include "llvm/codegen.hpp"
+#include "llvm/metadata.hpp"
+#include "core/error.hpp"
+#include "util/algorithm.hpp"
+
+#include <map>
+#include <llvm/Bitcode/ReaderWriter.h>
+#include <llvm/Support/raw_ostream.h>
+
+using namespace clover;
+using namespace clover::llvm;
+
+namespace {
+ std::map<std::string, unsigned>
+ get_symbol_offsets(const ::llvm::Module &mod) {
+ std::map<std::string, unsigned> offsets;
+ unsigned i = 0;
+
+ for (const auto &name : map(std::mem_fn(&::llvm::Function::getName),
+ get_kernels(mod)))
+ offsets[name] = i++;
+
+ return offsets;
+ }
+
+ std::vector<char>
+ emit_code(const ::llvm::Module &mod) {
+ ::llvm::SmallVector<char, 1024> data;
+ ::llvm::raw_svector_ostream os { data };
+ WriteBitcodeToFile(&mod, os);
+ return { os.str().begin(), os.str().end() };
+ }
+}
+
+module
+clover::llvm::build_module_bitcode(const ::llvm::Module &mod,
+ const clang::CompilerInstance &c) {
+ return build_module_common(mod, emit_code(mod), get_symbol_offsets(mod), c);
+}
+
+std::string
+clover::llvm::print_module_bitcode(const ::llvm::Module &mod) {
+ std::string s;
+ ::llvm::raw_string_ostream os { s };
+ mod.print(os, NULL);
+ return os.str();
+}
diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp
index 857ae2ab3a7..54e2866966b 100644
--- a/src/gallium/state_trackers/clover/llvm/invocation.cpp
+++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp
@@ -250,41 +250,6 @@ namespace {
pm.run(mod);
}
- std::map<std::string, unsigned>
- get_symbol_offsets(const ::llvm::Module &mod) {
- std::map<std::string, unsigned> offsets;
- unsigned i = 0;
-
- for (const auto &name : map(std::mem_fn(&::llvm::Function::getName),
- get_kernels(mod)))
- offsets[name] = i++;
-
- return offsets;
- }
-
- std::vector<char>
- emit_code(const ::llvm::Module &mod) {
- ::llvm::SmallVector<char, 1024> data;
- ::llvm::raw_svector_ostream os { data };
- WriteBitcodeToFile(&mod, os);
- return { os.str().begin(), os.str().end() };
- }
-
- module
- build_module_bitcode(const ::llvm::Module &mod,
- const clang::CompilerInstance &c) {
- return build_module_common(mod, emit_code(mod), get_symbol_offsets(mod),
- c);
- }
-
- std::string
- print_module_bitcode(const ::llvm::Module &mod) {
- std::string s;
- ::llvm::raw_string_ostream os { s };
- mod.print(os, NULL);
- return os.str();
- }
-
std::vector<char>
emit_code(::llvm::Module &mod, const target &target,
TargetMachine::CodeGenFileType ft,