1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
|
/*========================== begin_copyright_notice ============================
Copyright (C) 2017-2021 Intel Corporation
SPDX-License-Identifier: MIT
============================= end_copyright_notice ===========================*/
#pragma once
#include "Compiler/CISACodeGen/CISACodeGen.h"
#include "Compiler/CISACodeGen/WIAnalysis.hpp"
#include "Compiler/MetaDataApi/MetaDataApi.h"
#include "GenISAIntrinsics/GenIntrinsics.h"
#include <vector>
#include <set>
#include <map>
#include <string>
namespace llvm
{
class LLVMContext;
class Function;
class Type;
}
namespace IGC
{
/// @brief ImplicitArg is used for representing the implict information that is passed from the
/// OpenCL runtime to IGC, characterize it and allow IGC to use it.
/// @Author Marina Yatsina
class ImplicitArg {
public:
/// @brief Type of implicit information passed from the OpenCL runtime
enum ArgType {
R0,
START_ID = R0,
PAYLOAD_HEADER,
// WI information
WORK_DIM,
NUM_GROUPS,
GLOBAL_SIZE,
LOCAL_SIZE,
ENQUEUED_LOCAL_WORK_SIZE,
LOCAL_ID_X,
LOCAL_ID_Y,
LOCAL_ID_Z,
// Pointer bases and buffers
CONSTANT_BASE,
GLOBAL_BASE,
PRIVATE_BASE,
PRINTF_BUFFER,
// Buffer offset (for stateless to stateful optim)
BUFFER_OFFSET,
// Aggregates
STRUCT_START,
CONSTANT_REG_FP32 = STRUCT_START,
CONSTANT_REG_QWORD,
CONSTANT_REG_DWORD,
CONSTANT_REG_WORD,
CONSTANT_REG_BYTE,
STRUCT_END = CONSTANT_REG_BYTE,
// Images
IMAGES_START,
IMAGE_HEIGHT = IMAGES_START,
IMAGE_WIDTH,
IMAGE_DEPTH,
IMAGE_NUM_MIP_LEVELS,
IMAGE_CHANNEL_DATA_TYPE,
IMAGE_CHANNEL_ORDER,
IMAGE_SRGB_CHANNEL_ORDER,
IMAGE_ARRAY_SIZE,
IMAGE_NUM_SAMPLES,
SAMPLER_ADDRESS,
SAMPLER_NORMALIZED,
SAMPLER_SNAP_WA,
FLAT_IMAGE_BASEOFFSET,
FLAT_IMAGE_HEIGHT,
FLAT_IMAGE_WIDTH,
FLAT_IMAGE_PITCH,
IMAGES_END = FLAT_IMAGE_PITCH,
// VME
VME_MB_BLOCK_TYPE,
VME_SUBPIXEL_MODE,
VME_SAD_ADJUST_MODE,
VME_SEARCH_PATH_TYPE,
// Device Enqueue
DEVICE_ENQUEUE_DEFAULT_DEVICE_QUEUE,
DEVICE_ENQUEUE_EVENT_POOL,
DEVICE_ENQUEUE_MAX_WORKGROUP_SIZE,
DEVICE_ENQUEUE_PARENT_EVENT,
DEVICE_ENQUEUE_PREFERED_WORKGROUP_MULTIPLE,
GET_OBJECT_ID,
GET_BLOCK_SIMD_SIZE,
// GAS
LOCAL_MEMORY_STATELESS_WINDOW_START_ADDRESS,
LOCAL_MEMORY_STATELESS_WINDOW_SIZE,
PRIVATE_MEMORY_STATELESS_SIZE,
STAGE_IN_GRID_ORIGIN,
STAGE_IN_GRID_SIZE,
SYNC_BUFFER,
// Raytracing args
RT_GLOBAL_BUFFER_POINTER,
RT_LOCAL_BUFFER_POINTER,
RT_INLINED_DATA,
RT_STACK_ID,
// Bindless buffer (for stateless to bindless optim)
BINDLESS_OFFSET,
// Pointer to implicit arguments prepared by runtime
IMPLICIT_ARG_BUFFER_PTR,
NUM_IMPLICIT_ARGS
};
/// @brief This set type is used to contain function arguments
typedef std::set<int> ArgValSet;
/// @brief This map type is used to map implicit argument types to
/// sets that contain the relevant Values.
typedef std::map<ImplicitArg::ArgType, ArgValSet> ArgMap;
typedef std::pair<ImplicitArg::ArgType, unsigned int> StructArgElement;
typedef std::vector<StructArgElement> StructArgList;
/// @brief LLVM Type
enum ValType {
BYTE,
SHORT,
INT,
LONG,
FP32,
CONSTPTR,
PRIVATEPTR,
GLOBALPTR
};
enum ValAlign {
ALIGN_QWORD,
ALIGN_DWORD,
ALIGN_GRF,
ALIGN_PTR
};
ImplicitArg(
const ArgType& argType,
const std::string& name,
const ValType valType,
WIAnalysis::WIDependancy dependency,
unsigned int nbElement,
ValAlign align,
bool isConstantBuf);
ImplicitArg(
const ArgType& argType,
const std::string& name,
const ValType valType,
WIAnalysis::WIDependancy dependency,
unsigned int nbElement,
ValAlign align,
bool isConstantBuf,
llvm::GenISAIntrinsic::ID GenIntrinsicID);
/// @brief Getter functions
ArgType getArgType() const;
const std::string& getName() const;
llvm::Type* getLLVMType(llvm::LLVMContext& context) const;
WIAnalysis::WIDependancy getDependency() const;
unsigned int getAllocateSize(const llvm::DataLayout& DL) const;
unsigned int getNumberElements() const;
VISA_Type getVISAType(const llvm::DataLayout& DL) const;
IGC::e_alignment getAlignType(const llvm::DataLayout& DL) const;
size_t getAlignment(const llvm::DataLayout& DL) const;
unsigned int getPointerSize(const llvm::DataLayout& DL) const;
bool isConstantBuf() const;
bool isLocalIDs() const;
llvm::GenISAIntrinsic::ID getGenIntrinsicID() const;
private:
const ArgType m_argType;
const std::string m_name;
const ValType m_valType;
const WIAnalysis::WIDependancy m_dependency;
const unsigned int m_nbElement;
const ValAlign m_align;
const bool m_isConstantBuf;
const llvm::GenISAIntrinsic::ID m_GenIntrinsicID;
};
/// @brief ImplicitArgs is used for accessing the actual implict information that is passed from
/// the OpenCL runtime to IGC.
/// @Author Marina Yatsina
class ImplicitArgs {
public:
// Constructors
ImplicitArgs() {}
/// @brief Constructor.
/// Constructs the function's implicit arguments based on the given function's metadata
/// It actually constructs a mapping to a subset of IMPLICIT_ARGS
/// @param func the function to get impilcit args for.
/// @param the metadata utils object
ImplicitArgs(const llvm::Function& func, const IGCMD::MetaDataUtils* pMdUtils);
/// @brief Returns the number of implicit arguments that are passed from the runtime
/// @return The number of implicit arguments
unsigned int size() const;
/// @brief Returns the i-th implicit argument
/// @param i The implicit argument index
/// @return The i-th implicit argument
const ImplicitArg& operator[](unsigned int i) const;
/// @brief Returns the index of the appropriate implicit argument based on the given argument type
/// @param argType The implicit argument type
/// @return The implicit argument's index for a given argument type
unsigned int getArgIndex(ImplicitArg::ArgType argType) const;
/// @brief Returns the index of the appropriate implicit image or sampler argument
/// based on the given argument type and the associated image argument
/// @param argType The implicit argument type
/// (height/width/depth for images, normalized/address/snapwa for samplers)
/// @param image The associated image/sampler argument
/// @return The implicit argument's index for a given argument type
unsigned int getImageArgIndex(ImplicitArg::ArgType argType, const llvm::Argument* image) const;
/// @brief Returns the index of the appropriate implicit argument
/// based on the given argument type and the argument number
/// @param argType The implicit argument type
/// (height/width/depth for images, normalized/address/snapwa for samplers)
/// @param argNum The explicit argument number of the type
/// @return The implicit argument's index for a given argument type
unsigned int getNumberedArgIndex(ImplicitArg::ArgType argType, int argNum) const;
/// @brief Returns the argument type of the argument at the given index
/// @param i The implicit argument index
/// @return The argument type of the argument at the given index
ImplicitArg::ArgType getArgType(unsigned int i) const;
/// @brief Returns the argument type of the given matching intrinsic ID
/// @param i The GenISAIntrinsic ID
/// @return The argument type
static ImplicitArg::ArgType getArgType(llvm::GenISAIntrinsic::ID id);
/// @brief Returns the argument dependency of the given matching intrinsic ID
/// @param i The GenISAIntrinsic ID
/// @return The argument dependency
static IGC::WIAnalysis::WIDependancy getArgDep(llvm::GenISAIntrinsic::ID id);
/// @brief Returns if the given arg type supports the GenISAIntrinsic instruction
/// @param i The ImplicitArg type
/// @return If intrinsic supported
static bool hasIntrinsicSupport(ImplicitArg::ArgType i);
/// @brief Returns the explicit argument number of the given implicit argument index
/// @param i The implicit argument index
/// @return The explicit argument number of the given implicit argument index
int32_t getExplicitArgNum(uint index) const;
/// @brief Returns the structure offset of the given implicit argument index
/// @param i The implicit argument index
/// @return The structure offset of the given implicit argument index
int32_t getStructArgOffset(uint index) const;
/// @brief Creates implict arguments metadata for the given function based on the given implicit arguments
/// it should receive. If implicit metadata exists, it adds to it.
/// @param F The function for which to create the implicit argument's metadata
/// @param implicitArgs The implicit argument that are required by the given function
/// @param pMdUtils The Metadata API object
static void addImplicitArgs(llvm::Function& F, const llvm::SmallVectorImpl<ImplicitArg::ArgType>& implicitArgs, const IGCMD::MetaDataUtils* pMdUtils);
//TODO doc
/// @brief Creates implict image arguments metadata for the given function based on the given implicit image
/// arguments it should receive. If implicit image metadata exists, it adds to it.
/// @param F The function for which to create the implicit argument's metadata
/// @param argMap A map of implict argument types to the Value pointers to the arguments
/// @param pMdUtils The Metadata API object
static void addImageArgs(llvm::Function& F, const ImplicitArg::ArgMap& argMap, const IGCMD::MetaDataUtils* pMdUtils);
// TODO doc
static void addStructArgs(llvm::Function& F, const llvm::Argument* A, const ImplicitArg::StructArgList& S, const IGCMD::MetaDataUtils* pMdUtils);
/// @brief Creates implict arguments metadata for the given function based on the given implicit arguments
/// it should receive. If implicit metadata exists, it adds to it.
/// @param F The function for which to create the implicit argument's metadata
/// @param argMap A map of implict argument types to the set of numbers of arguments
/// @param pMdUtils The Metadata API object
static void addNumberedArgs(llvm::Function& F, const ImplicitArg::ArgMap& argMap, const IGCMD::MetaDataUtils* pMdUtils);
/// @brief Create implicit arguments metadata for the given function. It adds one
/// implicit argument for each explicit pointer argument to global or constant buffer.
/// @param F The function for which to create the implicit argument's metadata
/// @param pMdUtils The Metadata API object
static void addBufferOffsetArgs(llvm::Function& F, const IGCMD::MetaDataUtils* pMdUtils, IGC::ModuleMetaData* modMD);
/// @brief Create implicit arguments metadata for the given function. It adds one
/// implicit argument for each explicit pointer argument to global or constant buffer.
/// @param F The function for which to create the implicit argument's metadata
/// @param pMdUtils The Metadata API object
static void addBindlessOffsetArgs(llvm::Function& F, const IGCMD::MetaDataUtils* pMdUtils, IGC::ModuleMetaData* modMD);
/// @brief Check if the given implicit argument type exist in the(implicit) function argument associated
/// @param argType The type of the implict argument that should be checked
/// @return true if the argument exist, false otherwise.
bool isImplicitArgExist(ImplicitArg::ArgType argType) const;
static bool isImplicitArgExist(llvm::Function& F, ImplicitArg::ArgType argType, const IGCMD::MetaDataUtils* pMdUtils);
/// @brief Returns the (implicit) function argument associated with the given implicit argument type
/// @param F The Function for which the implict argument should be returned
/// @param argType The type of the implict argument that should be returned
/// @return The (implicit) function argument associated with the given argument type
/// In case the argument doesn't exist, return nullptr
llvm::Argument* getImplicitArg(llvm::Function &F, ImplicitArg::ArgType argType) const;
/// @brief Returns the (implicit) function argument associated with the given implicit argument type
/// and argument number
/// @param F The Function for which the implict argument should be returned
/// @param argType The type of the implict argument that should be returned
/// @param argNum The explicit argument number of the type
/// @return The (implicit) function argument associated with the given argument type and number
/// In case the argument doesn't exist, return nullptr
llvm::Argument* getNumberedImplicitArg(llvm::Function &F, ImplicitArg::ArgType argType, int argNum) const;
/// @brief Returns true if the given argument type is an image or sampler.
/// @param argType The argument type to check.
static bool isImplicitImage(ImplicitArg::ArgType argType);
/// @brief Returns true if the given argument type is a struct
/// @param argType The argument type to check.
static bool isImplicitStruct(ImplicitArg::ArgType argType);
llvm::Value* getImplicitArgValue(llvm::Function& F, ImplicitArg::ArgType argType, const IGCMD::MetaDataUtils* pMdUtils);
private:
/// @brief The function's metadata information.
IGCMD::FunctionInfoMetaDataHandle m_funcInfoMD;
static bool isImplicitArgExist(
const IGCMD::FunctionInfoMetaDataHandle& funcInfo,
ImplicitArg::ArgType argType);
};
} // namespace IGC
|