mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 23:03:02 +08:00
[2/N] Program refactor - gather compiler options
Change-Id: I0a614be73fbd87184be2dfea407582a58c27b0bc
This commit is contained in:
committed by
sys_ocldev
parent
49ad839818
commit
72a1542140
@@ -14,6 +14,9 @@ set(NEO_COMPILER_INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/create_main.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/linker.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/linker.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/compiler_options/compiler_options_base.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/compiler_options/compiler_options_base.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/compiler_options${BRANCH_DIR_SUFFIX}/compiler_options.h
|
||||
)
|
||||
|
||||
set_property(GLOBAL PROPERTY NEO_COMPILER_INTERFACE ${NEO_COMPILER_INTERFACE})
|
||||
|
||||
10
core/compiler_interface/compiler_options/compiler_options.h
Normal file
10
core/compiler_interface/compiler_options/compiler_options.h
Normal file
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/compiler_interface/compiler_options/compiler_options_base.h"
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "compiler_options_base.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace NEO {
|
||||
namespace CompilerOptions {
|
||||
|
||||
bool contains(const char *options, ConstStringRef optionToFind) {
|
||||
auto it = strstr(options, optionToFind.data());
|
||||
while (it != nullptr) {
|
||||
const auto delimiter = it[optionToFind.size()];
|
||||
if ((' ' == delimiter) || ('\0' == delimiter)) {
|
||||
if ((it == options) || (it[-1] == ' ')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
it = strstr(it + 1, optionToFind.data());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool contains(const std::string &options, ConstStringRef optionToFind) {
|
||||
return contains(options.c_str(), optionToFind);
|
||||
}
|
||||
|
||||
TokenizedString tokenize(ConstStringRef src) {
|
||||
TokenizedString ret;
|
||||
const char *it = src.begin();
|
||||
while (it < src.end()) {
|
||||
const char *beg = it;
|
||||
while ((beg < src.end()) && (*beg == ' ')) {
|
||||
++beg;
|
||||
}
|
||||
const char *end = beg;
|
||||
while ((end < src.end()) && (*end != ' ')) {
|
||||
++end;
|
||||
}
|
||||
it = end;
|
||||
if (end != beg) {
|
||||
ret.push_back(ConstStringRef(beg, end - beg));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
} // namespace CompilerOptions
|
||||
} // namespace NEO
|
||||
145
core/compiler_interface/compiler_options/compiler_options_base.h
Normal file
145
core/compiler_interface/compiler_options/compiler_options_base.h
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/utilities/const_stringref.h"
|
||||
#include "core/utilities/stackvec.h"
|
||||
|
||||
namespace NEO {
|
||||
namespace CompilerOptions {
|
||||
static constexpr ConstStringRef greaterThan4gbBuffersRequired = "-cl-intel-greater-than-4GB-buffer-required";
|
||||
static constexpr ConstStringRef hasBufferOffsetArg = "-cl-intel-has-buffer-offset-arg";
|
||||
static constexpr ConstStringRef kernelDebugEnable = "-cl-kernel-debug-enable";
|
||||
static constexpr ConstStringRef arch32bit = "-m32";
|
||||
static constexpr ConstStringRef arch64bit = "-m64";
|
||||
static constexpr ConstStringRef debugKernelEnable = "-cl-kernel-debug-enable";
|
||||
static constexpr ConstStringRef optDisable = "-cl-opt-disable";
|
||||
static constexpr ConstStringRef argInfo = "-cl-kernel-arg-info";
|
||||
static constexpr ConstStringRef gtpinRera = "-cl-intel-gtpin-rera";
|
||||
static constexpr ConstStringRef finiteMathOnly = "-cl-finite-math-only";
|
||||
static constexpr ConstStringRef fastRelaxedMath = "-cl-fast-relaxed-math";
|
||||
static constexpr ConstStringRef preserveVec3Type = "-fpreserve-vec3-type";
|
||||
static constexpr ConstStringRef createLibrary = "-create-library";
|
||||
static constexpr ConstStringRef generateDebugInfo = "-g";
|
||||
static constexpr ConstStringRef bindlessBuffers = "-cl-intel-use-bindless-buffers";
|
||||
static constexpr ConstStringRef bindlessImages = "-cl-intel-use-bindless-images";
|
||||
static constexpr ConstStringRef uniformWorkgroupSize = "-cl-uniform-work-group-size";
|
||||
|
||||
constexpr size_t nullterminateSize = 1U;
|
||||
constexpr size_t spaceSeparatorSize = 1U;
|
||||
|
||||
template <size_t Length>
|
||||
constexpr size_t length(const char (&array)[Length]) {
|
||||
return Length;
|
||||
}
|
||||
|
||||
constexpr size_t length(ConstStringRef string) {
|
||||
return string.length();
|
||||
}
|
||||
|
||||
inline size_t length(const std::string &string) {
|
||||
return string.length();
|
||||
}
|
||||
|
||||
constexpr size_t length(const char *string) {
|
||||
return constLength(string);
|
||||
}
|
||||
|
||||
constexpr const char *data(ConstStringRef string) {
|
||||
return string.data();
|
||||
}
|
||||
|
||||
inline const char *data(const std::string &string) {
|
||||
return string.data();
|
||||
}
|
||||
|
||||
constexpr const char *data(const char *string) {
|
||||
return string;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr size_t concatenationLength(const T &t) {
|
||||
return length(t);
|
||||
}
|
||||
|
||||
template <typename T, typename... RestT>
|
||||
constexpr size_t concatenationLength(const T &arg, const RestT &... rest) {
|
||||
return length(arg) + spaceSeparatorSize + concatenationLength(rest...);
|
||||
}
|
||||
|
||||
template <typename ContainerT, typename T>
|
||||
inline void concatenateAppend(ContainerT &out, T &&arg) {
|
||||
if ((false == out.empty()) && (*out.rbegin() != ' ')) {
|
||||
out.push_back(' ');
|
||||
}
|
||||
out.insert(out.end(), data(arg), data(arg) + length(arg));
|
||||
}
|
||||
|
||||
template <typename ContainerT, typename T, typename... RestT>
|
||||
inline void concatenateAppend(ContainerT &out, T &&arg, RestT &&... rest) {
|
||||
concatenateAppend(out, std::forward<T>(arg));
|
||||
concatenateAppend(out, std::forward<RestT>(rest)...);
|
||||
}
|
||||
|
||||
template <typename T, typename... RestT>
|
||||
inline std::string concatenate(T &&arg, RestT &&... rest) {
|
||||
std::string ret;
|
||||
ret.reserve(nullterminateSize + concatenationLength(arg, rest...));
|
||||
concatenateAppend(ret, std::forward<T>(arg), std::forward<RestT>(rest)...);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <size_t NumOptions>
|
||||
constexpr size_t concatenationLength(const ConstStringRef (&options)[NumOptions]) {
|
||||
size_t ret = 0U;
|
||||
for (auto opt : options) {
|
||||
ret += spaceSeparatorSize + opt.length();
|
||||
}
|
||||
return (ret != 0U) ? ret - nullterminateSize : 0U;
|
||||
}
|
||||
|
||||
template <size_t MaxLength = 256>
|
||||
class ConstConcatenation {
|
||||
public:
|
||||
template <size_t NumOptions>
|
||||
constexpr ConstConcatenation(const ConstStringRef (&options)[NumOptions]) {
|
||||
size_t i = 0U;
|
||||
for (auto opt : options) {
|
||||
for (size_t j = 0U, e = opt.length(); j < e; ++j, ++i) {
|
||||
storage[i] = opt[j];
|
||||
}
|
||||
storage[i] = ' ';
|
||||
++i;
|
||||
}
|
||||
length = i;
|
||||
if (i > 0U) {
|
||||
storage[i - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
constexpr operator ConstStringRef() const {
|
||||
return ConstStringRef(storage, (length > 0U) ? (length - 1) : 0U);
|
||||
}
|
||||
|
||||
constexpr operator const char *() const {
|
||||
return storage;
|
||||
}
|
||||
|
||||
protected:
|
||||
char storage[MaxLength + nullterminateSize] = {};
|
||||
size_t length = 0U;
|
||||
};
|
||||
|
||||
bool contains(const char *options, ConstStringRef optionToFind);
|
||||
|
||||
bool contains(const std::string &options, ConstStringRef optionToFind);
|
||||
|
||||
using TokenizedString = StackVec<ConstStringRef, 32>;
|
||||
TokenizedString tokenize(ConstStringRef src);
|
||||
} // namespace CompilerOptions
|
||||
} // namespace NEO
|
||||
Reference in New Issue
Block a user