From d8f817ae7f4241a9ea23140805aaeb724a0ac851 Mon Sep 17 00:00:00 2001 From: EdB Date: Thu, 23 Apr 2015 20:13:51 +0200 Subject: [PATCH] clover: remove util/compat Acked-by: Francisco Jerez Reviewed-by: Tom Stellard --- .../state_trackers/clover/Makefile.sources | 1 - .../state_trackers/clover/api/program.cpp | 14 +- .../state_trackers/clover/core/compiler.hpp | 4 +- .../state_trackers/clover/core/error.hpp | 2 - .../state_trackers/clover/core/kernel.cpp | 2 +- .../state_trackers/clover/core/module.cpp | 39 +-- .../state_trackers/clover/core/module.hpp | 19 +- .../state_trackers/clover/core/program.cpp | 2 +- .../state_trackers/clover/core/program.hpp | 2 +- .../state_trackers/clover/llvm/invocation.cpp | 20 +- .../state_trackers/clover/tgsi/compiler.cpp | 5 +- .../state_trackers/clover/util/compat.hpp | 313 ------------------ 12 files changed, 56 insertions(+), 367 deletions(-) delete mode 100644 src/gallium/state_trackers/clover/util/compat.hpp diff --git a/src/gallium/state_trackers/clover/Makefile.sources b/src/gallium/state_trackers/clover/Makefile.sources index 03eb754e903..fa96774183e 100644 --- a/src/gallium/state_trackers/clover/Makefile.sources +++ b/src/gallium/state_trackers/clover/Makefile.sources @@ -45,7 +45,6 @@ CPP_SOURCES := \ util/adaptor.hpp \ util/algebra.hpp \ util/algorithm.hpp \ - util/compat.hpp \ util/factor.hpp \ util/functional.hpp \ util/lazy.hpp \ diff --git a/src/gallium/state_trackers/clover/api/program.cpp b/src/gallium/state_trackers/clover/api/program.cpp index 913d195a16f..e9b1f384344 100644 --- a/src/gallium/state_trackers/clover/api/program.cpp +++ b/src/gallium/state_trackers/clover/api/program.cpp @@ -23,6 +23,8 @@ #include "api/util.hpp" #include "core/program.hpp" +#include + using namespace clover; namespace { @@ -94,12 +96,12 @@ clCreateProgramWithBinary(cl_context d_ctx, cl_uint n, return { CL_INVALID_VALUE, {} }; try { - compat::istream::buffer_t bin(p, l); - compat::istream s(bin); + std::stringbuf bin( { (char*)p, l } ); + std::istream s(&bin); return { CL_SUCCESS, module::deserialize(s) }; - } catch (compat::istream::error &e) { + } catch (std::istream::failure &e) { return { CL_INVALID_BINARY, {} }; } }, @@ -279,10 +281,10 @@ clGetProgramInfo(cl_program d_prog, cl_program_info param, case CL_PROGRAM_BINARIES: buf.as_matrix() = map([&](const device &dev) { - compat::ostream::buffer_t bin; - compat::ostream s(bin); + std::stringbuf bin; + std::ostream s(&bin); prog.binary(dev).serialize(s); - return bin; + return bin.str(); }, prog.devices()); break; diff --git a/src/gallium/state_trackers/clover/core/compiler.hpp b/src/gallium/state_trackers/clover/core/compiler.hpp index 62c0f476040..c68aa39db85 100644 --- a/src/gallium/state_trackers/clover/core/compiler.hpp +++ b/src/gallium/state_trackers/clover/core/compiler.hpp @@ -23,14 +23,12 @@ #ifndef CLOVER_CORE_COMPILER_HPP #define CLOVER_CORE_COMPILER_HPP -#include "util/compat.hpp" #include "core/error.hpp" #include "core/module.hpp" #include "pipe/p_defines.h" namespace clover { - typedef compat::vector > header_map; + typedef std::vector > header_map; module compile_program_llvm(const std::string &source, const header_map &headers, diff --git a/src/gallium/state_trackers/clover/core/error.hpp b/src/gallium/state_trackers/clover/core/error.hpp index 805a0eceb6a..eb65d629cdd 100644 --- a/src/gallium/state_trackers/clover/core/error.hpp +++ b/src/gallium/state_trackers/clover/core/error.hpp @@ -27,8 +27,6 @@ #include -#include "util/compat.hpp" - namespace clover { class command_queue; class context; diff --git a/src/gallium/state_trackers/clover/core/kernel.cpp b/src/gallium/state_trackers/clover/core/kernel.cpp index 442762c4773..0756f068553 100644 --- a/src/gallium/state_trackers/clover/core/kernel.cpp +++ b/src/gallium/state_trackers/clover/core/kernel.cpp @@ -192,7 +192,7 @@ kernel::exec_context::bind(intrusive_ptr _q, if (st) _q->pipe->delete_compute_state(_q->pipe, st); - cs.prog = msec.data.begin(); + cs.prog = &(msec.data[0]); cs.req_local_mem = mem_local; cs.req_input_mem = input.size(); st = q->pipe->create_compute_state(q->pipe, &cs); diff --git a/src/gallium/state_trackers/clover/core/module.cpp b/src/gallium/state_trackers/clover/core/module.cpp index f098b05312b..a6c5b98d8e0 100644 --- a/src/gallium/state_trackers/clover/core/module.cpp +++ b/src/gallium/state_trackers/clover/core/module.cpp @@ -21,6 +21,7 @@ // #include +#include #include "core/module.hpp" @@ -33,20 +34,20 @@ namespace { /// Serialize the specified object. template void - _proc(compat::ostream &os, const T &x) { + _proc(std::ostream &os, const T &x) { _serializer::proc(os, x); } /// Deserialize the specified object. template void - _proc(compat::istream &is, T &x) { + _proc(std::istream &is, T &x) { _serializer::proc(is, x); } template T - _proc(compat::istream &is) { + _proc(std::istream &is) { T x; _serializer::proc(is, x); return x; @@ -64,12 +65,12 @@ namespace { struct _serializer::value>::type> { static void - proc(compat::ostream &os, const T &x) { + proc(std::ostream &os, const T &x) { os.write(reinterpret_cast(&x), sizeof(x)); } static void - proc(compat::istream &is, T &x) { + proc(std::istream &is, T &x) { is.read(reinterpret_cast(&x), sizeof(x)); } @@ -81,11 +82,11 @@ namespace { /// (De)serialize a vector. template - struct _serializer, + struct _serializer, typename std::enable_if< !std::is_scalar::value>::type> { static void - proc(compat::ostream &os, const compat::vector &v) { + proc(std::ostream &os, const std::vector &v) { _proc(os, v.size()); for (size_t i = 0; i < v.size(); i++) @@ -93,7 +94,7 @@ namespace { } static void - proc(compat::istream &is, compat::vector &v) { + proc(std::istream &is, std::vector &v) { v.resize(_proc(is)); for (size_t i = 0; i < v.size(); i++) @@ -101,7 +102,7 @@ namespace { } static void - proc(module::size_t &sz, const compat::vector &v) { + proc(module::size_t &sz, const std::vector &v) { sz += sizeof(uint32_t); for (size_t i = 0; i < v.size(); i++) @@ -110,25 +111,25 @@ namespace { }; template - struct _serializer, + struct _serializer, typename std::enable_if< std::is_scalar::value>::type> { static void - proc(compat::ostream &os, const compat::vector &v) { + proc(std::ostream &os, const std::vector &v) { _proc(os, v.size()); - os.write(reinterpret_cast(v.begin()), + os.write(reinterpret_cast(&v[0]), v.size() * sizeof(T)); } static void - proc(compat::istream &is, compat::vector &v) { + proc(std::istream &is, std::vector &v) { v.resize(_proc(is)); - is.read(reinterpret_cast(v.begin()), + is.read(reinterpret_cast(&v[0]), v.size() * sizeof(T)); } static void - proc(module::size_t &sz, const compat::vector &v) { + proc(module::size_t &sz, const std::vector &v) { sz += sizeof(uint32_t) + sizeof(T) * v.size(); } }; @@ -137,13 +138,13 @@ namespace { template<> struct _serializer { static void - proc(compat::ostream &os, const std::string &s) { + proc(std::ostream &os, const std::string &s) { _proc(os, s.size()); os.write(&s[0], s.size() * sizeof(std::string::value_type)); } static void - proc(compat::istream &is, std::string &s) { + proc(std::istream &is, std::string &s) { s.resize(_proc(is)); is.read(&s[0], s.size() * sizeof(std::string::value_type)); } @@ -209,12 +210,12 @@ namespace { namespace clover { void - module::serialize(compat::ostream &os) const { + module::serialize(std::ostream &os) const { _proc(os, *this); } module - module::deserialize(compat::istream &is) { + module::deserialize(std::istream &is) { return _proc(is); } diff --git a/src/gallium/state_trackers/clover/core/module.hpp b/src/gallium/state_trackers/clover/core/module.hpp index 46112a38c91..9d656885945 100644 --- a/src/gallium/state_trackers/clover/core/module.hpp +++ b/src/gallium/state_trackers/clover/core/module.hpp @@ -23,7 +23,8 @@ #ifndef CLOVER_CORE_MODULE_HPP #define CLOVER_CORE_MODULE_HPP -#include "util/compat.hpp" +#include +#include namespace clover { struct module { @@ -40,14 +41,14 @@ namespace clover { }; section(resource_id id, enum type type, size_t size, - const compat::vector &data) : + const std::vector &data) : id(id), type(type), size(size), data(data) { } section() : id(0), type(text), size(0), data() { } resource_id id; type type; size_t size; - compat::vector data; + std::vector data; }; struct argument { @@ -101,22 +102,22 @@ namespace clover { struct symbol { symbol(const std::string &name, resource_id section, - size_t offset, const compat::vector &args) : + size_t offset, const std::vector &args) : name(name), section(section), offset(offset), args(args) { } symbol() : name(), section(0), offset(0), args() { } std::string name; resource_id section; size_t offset; - compat::vector args; + std::vector args; }; - void serialize(compat::ostream &os) const; - static module deserialize(compat::istream &is); + void serialize(std::ostream &os) const; + static module deserialize(std::istream &is); size_t size() const; - compat::vector syms; - compat::vector
secs; + std::vector syms; + std::vector
secs; }; } diff --git a/src/gallium/state_trackers/clover/core/program.cpp b/src/gallium/state_trackers/clover/core/program.cpp index 50ac01b4ee6..0d6cc402db7 100644 --- a/src/gallium/state_trackers/clover/core/program.cpp +++ b/src/gallium/state_trackers/clover/core/program.cpp @@ -106,7 +106,7 @@ program::build_log(const device &dev) const { return _logs.count(&dev) ? _logs.find(&dev)->second : ""; } -const compat::vector & +const std::vector & program::symbols() const { if (_binaries.empty()) throw error(CL_INVALID_PROGRAM_EXECUTABLE); diff --git a/src/gallium/state_trackers/clover/core/program.hpp b/src/gallium/state_trackers/clover/core/program.hpp index 661fa03102c..183145e2073 100644 --- a/src/gallium/state_trackers/clover/core/program.hpp +++ b/src/gallium/state_trackers/clover/core/program.hpp @@ -60,7 +60,7 @@ namespace clover { std::string build_opts(const device &dev) const; std::string build_log(const device &dev) const; - const compat::vector &symbols() const; + const std::vector &symbols() const; unsigned kernel_ref_count() const; diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp index 21579094a94..7d2d941407e 100644 --- a/src/gallium/state_trackers/clover/llvm/invocation.cpp +++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp @@ -340,11 +340,11 @@ namespace { PM.run(*mod); } - compat::vector + std::vector get_kernel_args(const llvm::Module *mod, const std::string &kernel_name, const clang::LangAS::Map &address_spaces) { - compat::vector args; + std::vector args; llvm::Function *kernel_func = mod->getFunction(kernel_name); llvm::DataLayout TD(mod); @@ -449,15 +449,16 @@ namespace { for (unsigned i = 0; i < kernels.size(); ++i) { std::string kernel_name = kernels[i]->getName(); - compat::vector args = + std::vector args = get_kernel_args(mod, kernel_name, address_spaces); m.syms.push_back(module::symbol(kernel_name, 0, i, args )); } header.num_bytes = llvm_bitcode.size(); - std::string data; - data.insert(0, (char*)(&header), sizeof(header)); + std::vector data; + data.insert(data.end(), (char*)(&header), + (char*)(&header) + sizeof(header)); data.insert(data.end(), llvm_bitcode.begin(), llvm_bitcode.end()); m.secs.push_back(module::section(0, module::section::text, @@ -622,15 +623,16 @@ namespace { // Store the generated ELF binary in the module's text section. header.num_bytes = code.size(); - std::string data; - data.append((char*)(&header), sizeof(header)); - data.append(code.begin(), code.end()); + std::vector data; + data.insert(data.end(), (char*)(&header), + (char*)(&header) + sizeof(header)); + data.insert(data.end(), code.begin(), code.end()); m.secs.push_back(module::section(0, module::section::text, header.num_bytes, data)); for (std::map::iterator i = kernel_offsets.begin(), e = kernel_offsets.end(); i != e; ++i) { - compat::vector args = + std::vector args = get_kernel_args(mod, i->first, address_spaces); m.syms.push_back(module::symbol(i->first, 0, i->second, args )); } diff --git a/src/gallium/state_trackers/clover/tgsi/compiler.cpp b/src/gallium/state_trackers/clover/tgsi/compiler.cpp index 9e959f7bb2e..b70104e7604 100644 --- a/src/gallium/state_trackers/clover/tgsi/compiler.cpp +++ b/src/gallium/state_trackers/clover/tgsi/compiler.cpp @@ -40,7 +40,7 @@ namespace { std::istringstream ts(line); std::string name, tok; module::size_t offset; - compat::vector args; + std::vector args; if (!(ts >> name)) continue; @@ -83,7 +83,8 @@ namespace { throw build_error("translate failed"); unsigned sz = tgsi_num_tokens(prog) * sizeof(tgsi_token); - m.secs.push_back({ 0, module::section::text, sz, { (char *)prog, sz } }); + std::vector data( (char *)prog, (char *)prog + sz ); + m.secs.push_back({ 0, module::section::text, sz, data }); } } diff --git a/src/gallium/state_trackers/clover/util/compat.hpp b/src/gallium/state_trackers/clover/util/compat.hpp deleted file mode 100644 index dc063344c3c..00000000000 --- a/src/gallium/state_trackers/clover/util/compat.hpp +++ /dev/null @@ -1,313 +0,0 @@ -// -// Copyright 2012 Francisco Jerez -// -// 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. -// - -#ifndef CLOVER_UTIL_COMPAT_HPP -#define CLOVER_UTIL_COMPAT_HPP - -#include -#include -#include -#include -#include - -namespace clover { - namespace compat { - // XXX - For cases where we can't rely on STL... I.e. the - // interface between code compiled as C++98 and C++11 - // source. Get rid of this as soon as everything can be - // compiled as C++11. - - namespace detail { - template - bool - ranges_equal(const R &a, const S &b) { - if (a.size() != b.size()) - return false; - - for (size_t i = 0; i < a.size(); ++i) - if (a[i] != b[i]) - return false; - - return true; - } - } - - template - class vector { - protected: - static T * - alloc(int n, const T *q, int m) { - T *p = reinterpret_cast(std::malloc(n * sizeof(T))); - - for (int i = 0; i < m; ++i) - new(&p[i]) T(q[i]); - - return p; - } - - static void - free(int n, T *p) { - for (int i = 0; i < n; ++i) - p[i].~T(); - - std::free(p); - } - - public: - typedef T *iterator; - typedef const T *const_iterator; - typedef T value_type; - typedef T &reference; - typedef const T &const_reference; - typedef std::ptrdiff_t difference_type; - typedef std::size_t size_type; - - vector() : p(NULL), _size(0), _capacity(0) { - } - - vector(const vector &v) : - p(alloc(v._size, v.p, v._size)), - _size(v._size), _capacity(v._size) { - } - - vector(const_iterator p, size_type n) : - p(alloc(n, p, n)), _size(n), _capacity(n) { - } - - template - vector(const C &v) : - p(alloc(v.size(), NULL, 0)), _size(0), - _capacity(v.size()) { - for (typename C::const_iterator it = v.begin(); it != v.end(); ++it) - new(&p[_size++]) T(*it); - } - - ~vector() { - free(_size, p); - } - - vector & - operator=(const vector &v) { - free(_size, p); - - p = alloc(v._size, v.p, v._size); - _size = v._size; - _capacity = v._size; - - return *this; - } - - bool - operator==(const vector &v) const { - return detail::ranges_equal(*this, v); - } - - void - reserve(size_type n) { - if (_capacity < n) { - T *q = alloc(n, p, _size); - free(_size, p); - - p = q; - _capacity = n; - } - } - - void - resize(size_type n, T x = T()) { - if (n <= _size) { - for (size_type i = n; i < _size; ++i) - p[i].~T(); - - } else { - reserve(n); - - for (size_type i = _size; i < n; ++i) - new(&p[i]) T(x); - } - - _size = n; - } - - void - push_back(const T &x) { - reserve(_size + 1); - new(&p[_size]) T(x); - ++_size; - } - - size_type - size() const { - return _size; - } - - size_type - capacity() const { - return _capacity; - } - - iterator - begin() { - return p; - } - - const_iterator - begin() const { - return p; - } - - iterator - end() { - return p + _size; - } - - const_iterator - end() const { - return p + _size; - } - - reference - operator[](size_type i) { - return p[i]; - } - - const_reference - operator[](size_type i) const { - return p[i]; - } - - private: - iterator p; - size_type _size; - size_type _capacity; - }; - - template - class vector_ref { - public: - typedef T *iterator; - typedef const T *const_iterator; - typedef T value_type; - typedef T &reference; - typedef const T &const_reference; - typedef std::ptrdiff_t difference_type; - typedef std::size_t size_type; - - vector_ref(iterator p, size_type n) : p(p), n(n) { - } - - template - vector_ref(C &v) : p(&*v.begin()), n(v.size()) { - } - - bool - operator==(const vector_ref &v) const { - return detail::ranges_equal(*this, v); - } - - size_type - size() const { - return n; - } - - iterator - begin() { - return p; - } - - const_iterator - begin() const { - return p; - } - - iterator - end() { - return p + n; - } - - const_iterator - end() const { - return p + n; - } - - reference - operator[](int i) { - return p[i]; - } - - const_reference - operator[](int i) const { - return p[i]; - } - - private: - iterator p; - size_type n; - }; - - class istream { - public: - typedef vector_ref buffer_t; - - class error { - public: - virtual ~error() {} - }; - - istream(const buffer_t &buf) : buf(buf), offset(0) {} - - void - read(char *p, size_t n) { - if (offset + n > buf.size()) - throw error(); - - std::memcpy(p, buf.begin() + offset, n); - offset += n; - } - - private: - const buffer_t &buf; - size_t offset; - }; - - class ostream { - public: - typedef vector buffer_t; - - ostream(buffer_t &buf) : buf(buf), offset(buf.size()) {} - - void - write(const char *p, size_t n) { - buf.resize(offset + n); - std::memcpy(buf.begin() + offset, p, n); - offset += n; - } - - private: - buffer_t &buf; - size_t offset; - }; - - } -} - -#endif -- 2.30.2