Program refactor

* Decouple binary program handling from Program object
* Add binary formats multiplexer
* Improve Elf format support

Change-Id: Ic22aff40173532e14825d70b82ec53fcc5fa9fdf
This commit is contained in:
Jaroslaw Chodor
2020-01-25 19:18:48 +01:00
parent cb964f9e72
commit a53e26342a
96 changed files with 3917 additions and 2023 deletions

View File

@@ -13,6 +13,7 @@ set(NEO_COMPILER_INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/compiler_interface.inl
${CMAKE_CURRENT_SOURCE_DIR}/create_main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/default_cache_config.h
${CMAKE_CURRENT_SOURCE_DIR}/intermediate_representations.h
${CMAKE_CURRENT_SOURCE_DIR}/linker.h
${CMAKE_CURRENT_SOURCE_DIR}/linker.cpp
${CMAKE_CURRENT_SOURCE_DIR}/compiler_options/compiler_options_base.h

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2019 Intel Corporation
* Copyright (C) 2017-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -106,8 +106,9 @@ class CompilerInterface {
CompilerInterface &operator=(CompilerInterface &&) = delete;
virtual ~CompilerInterface();
static CompilerInterface *createInstance(std::unique_ptr<CompilerCache> cache, bool requireFcl) {
auto instance = new CompilerInterface();
template <typename CompilerInterfaceT = CompilerInterface>
static CompilerInterfaceT *createInstance(std::unique_ptr<CompilerCache> cache, bool requireFcl) {
auto instance = new CompilerInterfaceT();
if (!instance->initialize(std::move(cache), requireFcl)) {
delete instance;
instance = nullptr;
@@ -137,7 +138,7 @@ class CompilerInterface {
MOCKABLE_VIRTUAL TranslationOutput::ErrorCode getSipKernelBinary(NEO::Device &device, SipKernelType type, std::vector<char> &retBinary);
protected:
bool initialize(std::unique_ptr<CompilerCache> cache, bool requireFcl);
MOCKABLE_VIRTUAL bool initialize(std::unique_ptr<CompilerCache> cache, bool requireFcl);
MOCKABLE_VIRTUAL bool loadFcl();
MOCKABLE_VIRTUAL bool loadIgc();

View File

@@ -0,0 +1,36 @@
/*
* Copyright (C) 2019-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "core/utilities/arrayref.h"
#include "core/utilities/const_stringref.h"
#include <algorithm>
#include <cstdint>
namespace NEO {
static constexpr ConstStringRef llvmBcMagic = "BC\xc0\xde";
static constexpr ConstStringRef spirvMagic = "\x07\x23\x02\x03";
static constexpr ConstStringRef spirvMagicInv = "\x03\x02\x23\x07";
inline bool hasSameMagic(ConstStringRef expectedMagic, ArrayRef<const uint8_t> binary) {
auto binaryMagicLen = std::min(expectedMagic.size(), binary.size());
ConstStringRef binaryMagic(reinterpret_cast<const char *>(binary.begin()), binaryMagicLen);
return expectedMagic == binaryMagic;
}
inline bool isLlvmBitcode(ArrayRef<const uint8_t> binary) {
return hasSameMagic(llvmBcMagic, binary);
}
inline bool isSpirVBitcode(ArrayRef<const uint8_t> binary) {
return hasSameMagic(spirvMagic, binary) || hasSameMagic(spirvMagicInv, binary);
}
} // namespace NEO