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
|
/*========================== begin_copyright_notice ============================
Copyright (C) 2017-2021 Intel Corporation
SPDX-License-Identifier: MIT
============================= end_copyright_notice ===========================*/
//
// This file contains a table of extra information about the llvm.genx.*
// intrinsics, used by the vISA register allocator and function writer to
// decide exactly what operand type to use. The more usual approach in an LLVM
// target is to have an intrinsic map to an instruction in instruction
// selection, then have register category information on the instruction. But
// we are not using the target independent code generator, we are generating
// code directly from LLVM IR.
//
//===----------------------------------------------------------------------===//
#include "IGC/common/StringMacros.hpp"
#include "GenXIntrinsics.h"
#include "IsaDescription.h"
#include "visa_igc_common_header.h"
#include "llvm/GenXIntrinsics/GenXIntrinsics.h"
#include "llvm/IR/Constants.h"
#include "llvmWrapper/IR/Instructions.h"
#include "llvm/IR/Intrinsics.h"
#include "llvmWrapper/IR/DerivedTypes.h"
#include "Probe/Assertion.h"
using namespace llvm;
// In this table:
//
// Each ALU and shared function intrinsic has a record giving information
// about its operands, and how it is written as a vISA instruction. The
// record has an initial field giving the intrinsic ID, then a number of
// fields where each corresponds to a field in the vISA instruction.
//
// A field may be several values combined with the | operator. The first
// value is the operand category (GENERAL etc), or one of a set of
// non-register operand categories (LITERAL, BYTE), or END to terminate
// the record. Other modifier values may be combined, such as SIGNED.
// The LLVM IR argument index plus 1 is also combined in, or 0 for the
// return value.
// Video Analytics intrinsic helper macros, mainly to avoid large blocks
// of near-identical code in the intrinsics look-up table and also to
// aid readability.
// Region access intrinsics do not appear in this table
const GenXIntrinsicInfo::TableType &GenXIntrinsicInfo::getTable() {
static TableType Table = {
#include "GenXIntrinsicInfoTable.inc"
};
return Table;
}
// Get the category and modifier for an arg idx (-1 means return value).
// The returned ArgInfo struct contains just the short read from the table,
// and has methods for accessing the various fields.
GenXIntrinsicInfo::ArgInfo GenXIntrinsicInfo::getArgInfo(int Idx) const {
// Read through the fields in the table to find the one with the right
// arg index...
for (auto AI : getInstDesc())
if (AI.isRealArgOrRet() && AI.getArgIdx() == Idx)
return AI;
// Field with requested arg index was not found.
return ArgInfo{};
}
// Return the starting point of any trailing null (zero) arguments
// for this call. If the intrinsic does not have a ARGCOUNT descriptor
// this will always return the number of operands to the call (ie, there
// is no trailing null zone), even if there are some trailing nulls.
unsigned GenXIntrinsicInfo::getTrailingNullZoneStart(CallInst *CI) const {
auto AI =
std::find_if(getInstDesc().begin(), getInstDesc().end(),
[](auto Arg) { return Arg.getCategory() == ARGCOUNT; });
if (AI == getInstDesc().end())
return CI->getNumOperands();
unsigned BaseArg = AI->getArgIdx();
unsigned TrailingNullStart = BaseArg;
for (unsigned Idx = BaseArg; Idx < IGCLLVM::getNumArgOperands(CI); ++Idx) {
if (auto CA = dyn_cast<Constant>(CI->getArgOperand(Idx)))
if (CA->isNullValue())
continue;
TrailingNullStart = Idx + 1;
}
return std::max(TrailingNullStart, BaseArg + AI->getArgCountMin());
}
/***********************************************************************
* getExecSizeAllowedBits : get bitmap of which execsize values are allowed
* for this intrinsic
*
* Return: bit N set if execution size 1<<N is allowed
*/
unsigned GenXIntrinsicInfo::getExecSizeAllowedBits() const {
for (auto AI : getInstDesc()) {
if (!AI.isGeneral()) {
switch (AI.getCategory()) {
case EXECSIZE:
return 0x3f;
case EXECSIZE_GE2:
return 0x3e;
case EXECSIZE_GE4:
return 0x3c;
case EXECSIZE_GE8:
return 0x38;
case EXECSIZE_NOT2:
return 0x3d;
}
}
}
return 0x3f;
}
/***********************************************************************
* getPredAllowed : determine if this intrinsic is allowed to have
* a predicated destination mask.
*
* Return: true if it permitted, false otherwise.
*/
bool GenXIntrinsicInfo::getPredAllowed() const {
// Simply search the intrinsic description for an IMPLICITPRED
// entry. Not very efficient, but the situations where this
// check is needed are expected to be infrequent.
return any_of(getInstDesc(),
[](auto AI) { return AI.getCategory() == IMPLICITPRED; });
}
/***********************************************************************
* isElementWise : determine if this intrinsic has element-wise semantics.
*/
bool GenXIntrinsicInfo::isElementWise() const {
return any_of(getInstDesc(),
[](auto AI) { return AI.getCategory() == ELEMENTWISE; });
}
unsigned GenXIntrinsicInfo::getOverridedExecSize(CallInst *CI,
const GenXSubtarget *ST) {
auto CalledF = CI->getCalledFunction();
IGC_ASSERT(CalledF);
auto ID = GenXIntrinsic::getGenXIntrinsicID(CalledF);
if (isGenXIntrinsic(ID)) {
// We check the lsc intrinsic by name or we need to introduce a range of lsc
// intrinsics.
if (ID == GenXIntrinsic::genx_lsc_load2d_stateless ||
ID == GenXIntrinsic::genx_lsc_store2d_stateless)
return 1;
StringRef Name = CalledF->getName();
StringRef LSCPrefix = "llvm.genx.lsc.";
if (Name.startswith(LSCPrefix))
// Check if this is a block message from predicate type.
return !CI->getArgOperand(0)->getType()->isVectorTy();
}
switch (ID) {
default:
break;
// Exec size of intrinsics with channels are inferred from address operand.
case GenXIntrinsic::genx_gather4_scaled2:
case GenXIntrinsic::genx_gather4_masked_scaled2:
case GenXIntrinsic::genx_gather4_masked_scaled2_predef_surface:
return cast<IGCLLVM::FixedVectorType>(
CI->getArgOperand(4 /*address operand idx*/)->getType())
->getNumElements();
case GenXIntrinsic::genx_raw_send:
case GenXIntrinsic::genx_raw_sends:
case GenXIntrinsic::genx_raw_send_noresult:
case GenXIntrinsic::genx_raw_sends_noresult:
return 16;
case GenXIntrinsic::genx_subb:
case GenXIntrinsic::genx_addc:
if (auto *VT =
dyn_cast<IGCLLVM::FixedVectorType>(CI->getOperand(0)->getType()))
return VT->getNumElements();
return 1;
case GenXIntrinsic::genx_dpas:
case GenXIntrinsic::genx_dpas2:
case GenXIntrinsic::genx_dpas_nosrc0:
case GenXIntrinsic::genx_dpasw:
case GenXIntrinsic::genx_dpasw_nosrc0: {
unsigned Width = ST ? ST->dpasWidth() : 8;
return Width;
}
}
return 0;
}
|