| 1 |
/*========================== begin_copyright_notice ============================ |
| 2 |
|
| 3 |
Copyright (C) 2017-2021 Intel Corporation |
| 4 |
|
| 5 |
SPDX-License-Identifier: MIT |
| 6 |
|
| 7 |
============================= end_copyright_notice ===========================*/ |
| 8 |
|
| 9 |
#ifndef _IGA_ENCODER_WRAPPER_HPP |
| 10 |
#define _IGA_ENCODER_WRAPPER_HPP |
| 11 |
|
| 12 |
#include "../IR/Kernel.hpp" |
| 13 |
#include "iga.h" |
| 14 |
|
| 15 |
#include <ostream> |
| 16 |
|
| 17 |
// entry point for binary encoding of a IGA IR kernel |
| 18 |
class KernelEncoder { |
| 19 |
void *m_buf = nullptr; |
| 20 |
uint32_t m_binarySize = 0; |
| 21 |
iga::Kernel *m_kernel = nullptr; |
| 22 |
bool m_autoCompact = false; |
| 23 |
// enable IGA swsb set |
| 24 |
bool m_enableAutoDeps = false; |
| 25 |
// swsb encoding mode |
| 26 |
iga::SWSB_ENCODE_MODE m_swsbEncodeMode = |
| 27 |
iga::SWSB_ENCODE_MODE::SWSBInvalidMode; |
| 28 |
|
| 29 |
public: |
| 30 |
// @param compact: auto compact instructions if applicable |
| 31 |
// @param noCompactFisrtEightInst: Force NOCOMPACT the first 8 instructions in |
| 32 |
// this encoding unit |
| 33 |
// The first eight instructions must be in the same bb |
| 34 |
// This can be set simulataneously with compact. The first 8 instructions |
| 35 |
// will not be cmopacted even if it is compactable |
| 36 |
KernelEncoder(iga::Kernel *k, bool compact) |
| 37 |
: m_kernel(k), m_autoCompact(compact) {} |
| 38 |
|
| 39 |
iga_status_t encode(std::ostream &os); |
| 40 |
void *getBinary() const { return m_buf; } |
| 41 |
uint32_t getBinarySize() const { return m_binarySize; } |
| 42 |
|
| 43 |
// patchImmValue - Decode the first instruction start from binary, and patch |
| 44 |
// the imm field to given val input type - the type of given immediate value |
| 45 |
// input val - the given immediate value |
| 46 |
// return - true on success, false if any error |
| 47 |
// This function is used by visa to patch the add or mov instructions' imm |
| 48 |
// field for the indirect call |
| 49 |
// FIXME: Move this api to somewhere else that's more apporopriate |
| 50 |
static bool patchImmValue(const iga::Model &model, unsigned char *binary, |
| 51 |
iga::Type type, const iga::ImmVal &val); |
| 52 |
|
| 53 |
// set swsb encoding mode. If not set, the encoding mode will be derived from |
| 54 |
// platform |
| 55 |
void setSWSBEncodingMode(iga::SWSB_ENCODE_MODE mode) { |
| 56 |
m_swsbEncodeMode = mode; |
| 57 |
} |
| 58 |
|
| 59 |
// enable IGA swsb set. When enabled, the original swsb in the input |
| 60 |
// instructions will be obsoleted |
| 61 |
void enableIGAAutoDeps(bool enable = true) { m_enableAutoDeps = enable; } |
| 62 |
|
| 63 |
}; |
| 64 |
|
| 65 |
#endif // _IGA_ENCODER_WRAPPER_HPP |