| 1 |
//===- SPIRVInstruction.h - Class to represent SPIRV instruction -- C++ -*-===// |
| 2 |
// |
| 3 |
// The LLVM/SPIRV Translator |
| 4 |
// |
| 5 |
// This file is distributed under the University of Illinois Open Source |
| 6 |
// License. See LICENSE.TXT for details. |
| 7 |
// |
| 8 |
// Copyright (c) 2014 Advanced Micro Devices, Inc. All rights reserved. |
| 9 |
// |
| 10 |
// Permission is hereby granted, free of charge, to any person obtaining a |
| 11 |
// copy of this software and associated documentation files (the "Software"), |
| 12 |
// to deal with the Software without restriction, including without limitation |
| 13 |
// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 14 |
// and/or sell copies of the Software, and to permit persons to whom the |
| 15 |
// Software is furnished to do so, subject to the following conditions: |
| 16 |
// |
| 17 |
// Redistributions of source code must retain the above copyright notice, |
| 18 |
// this list of conditions and the following disclaimers. |
| 19 |
// Redistributions in binary form must reproduce the above copyright notice, |
| 20 |
// this list of conditions and the following disclaimers in the documentation |
| 21 |
// and/or other materials provided with the distribution. |
| 22 |
// Neither the names of Advanced Micro Devices, Inc., nor the names of its |
| 23 |
// contributors may be used to endorse or promote products derived from this |
| 24 |
// Software without specific prior written permission. |
| 25 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 26 |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 27 |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 28 |
// CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 29 |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 30 |
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH |
| 31 |
// THE SOFTWARE. |
| 32 |
// |
| 33 |
//===----------------------------------------------------------------------===// |
| 34 |
/// \file |
| 35 |
/// |
| 36 |
/// This file defines Instruction class for SPIR-V. |
| 37 |
/// |
| 38 |
//===----------------------------------------------------------------------===// |
| 39 |
|
| 40 |
#ifndef SPIRV_LIBSPIRV_SPIRVINSTRUCTION_H |
| 41 |
#define SPIRV_LIBSPIRV_SPIRVINSTRUCTION_H |
| 42 |
|
| 43 |
#include "SPIRVBasicBlock.h" |
| 44 |
#include "SPIRVEnum.h" |
| 45 |
#include "SPIRVFunction.h" |
| 46 |
#include "SPIRVIsValidEnum.h" |
| 47 |
#include "SPIRVOpCode.h" |
| 48 |
#include "SPIRVStream.h" |
| 49 |
#include "SPIRVValue.h" |
| 50 |
|
| 51 |
#include <cassert> |
| 52 |
#include <functional> |
| 53 |
#include <iostream> |
| 54 |
#include <unordered_set> |
| 55 |
#include <utility> |
| 56 |
#include <vector> |
| 57 |
|
| 58 |
namespace SPIRV { |
| 59 |
|
| 60 |
typedef std::vector<SPIRVValue *> ValueVec; |
| 61 |
typedef std::pair<ValueVec::iterator, ValueVec::iterator> ValueRange; |
| 62 |
|
| 63 |
class SPIRVBasicBlock; |
| 64 |
class SPIRVFunction; |
| 65 |
|
| 66 |
bool isSpecConstantOpAllowedOp(Op OC); |
| 67 |
|
| 68 |
class SPIRVComponentExecutionScope { |
| 69 |
public: |
| 70 |
SPIRVComponentExecutionScope(Scope TheScope = ScopeInvocation) |
| 71 |
: ExecScope(TheScope) {} |
| 72 |
Scope ExecScope; |
| 73 |
}; |
| 74 |
|
| 75 |
class SPIRVComponentMemorySemanticsMask { |
| 76 |
public: |
| 77 |
SPIRVComponentMemorySemanticsMask(SPIRVWord TheSema = SPIRVWORD_MAX) |
| 78 |
: MemSema(TheSema) {} |
| 79 |
SPIRVWord MemSema; |
| 80 |
}; |
| 81 |
|
| 82 |
class SPIRVComponentOperands { |
| 83 |
public: |
| 84 |
SPIRVComponentOperands(){}; |
| 85 |
SPIRVComponentOperands(const std::vector<SPIRVValue *> &TheOperands) |
| 86 |
: Operands(TheOperands){}; |
| 87 |
SPIRVComponentOperands(std::vector<SPIRVValue *> &&TheOperands) |
| 88 |
: Operands(std::move(TheOperands)){}; |
| 89 |
std::vector<SPIRVValue *> getCompOperands() { return Operands; } |
| 90 |
std::vector<SPIRVType *> getCompOperandTypes() { |
| 91 |
std::vector<SPIRVType *> Tys; |
| 92 |
for (auto &I : getCompOperands()) |
| 93 |
Tys.push_back(I->getType()); |
| 94 |
return Tys; |
| 95 |
} |
| 96 |
|
| 97 |
protected: |
| 98 |
std::vector<SPIRVValue *> Operands; |
| 99 |
}; |
| 100 |
|
| 101 |
class SPIRVInstruction : public SPIRVValue { |
| 102 |
public: |
| 103 |
// Complete constructor for instruction with type and id |
| 104 |
SPIRVInstruction(unsigned TheWordCount, Op TheOC, SPIRVType *TheType, |
| 105 |
SPIRVId TheId, SPIRVBasicBlock *TheBB); |
| 106 |
// Complete constructor for instruction with module, type and id |
| 107 |
SPIRVInstruction(unsigned TheWordCount, Op TheOC, SPIRVType *TheType, |
| 108 |
SPIRVId TheId, SPIRVBasicBlock *TheBB, SPIRVModule *TheBM); |
| 109 |
// Complete constructor for instruction with id but no type |
| 110 |
SPIRVInstruction(unsigned TheWordCount, Op TheOC, SPIRVId TheId, |
| 111 |
SPIRVBasicBlock *TheBB); |
| 112 |
// Complete constructor for instruction without type and id |
| 113 |
SPIRVInstruction(unsigned TheWordCount, Op TheOC, SPIRVBasicBlock *TheBB); |
| 114 |
// Complete constructor for instruction with type but no id |
| 115 |
SPIRVInstruction(unsigned TheWordCount, Op TheOC, SPIRVType *TheType, |
| 116 |
SPIRVBasicBlock *TheBB); |
| 117 |
// Special constructor for debug instruction |
| 118 |
SPIRVInstruction(unsigned TheWordCount, Op TheOC, SPIRVType *TheType, |
| 119 |
SPIRVId TheId, SPIRVModule *TheBM, |
| 120 |
SPIRVBasicBlock *TheBB = nullptr); |
| 121 |
|
| 122 |
// Incomplete constructor |
| 123 |
SPIRVInstruction(Op TheOC = OpNop) |
| 124 |
: SPIRVValue(TheOC), BB(NULL), DebugScope(nullptr) {} |
| 125 |
|
| 126 |
bool isInst() const override { return true; } |
| 127 |
SPIRVBasicBlock *getParent() const { return BB; } |
| 128 |
SPIRVInstruction *getPrevious() const { return BB->getPrevious(this); } |
| 129 |
SPIRVInstruction *getNext() const { return BB->getNext(this); } |
| 130 |
virtual std::vector<SPIRVValue *> getOperands(); |
| 131 |
std::vector<SPIRVType *> getOperandTypes(); |
| 132 |
static std::vector<SPIRVType *> |
| 133 |
getOperandTypes(const std::vector<SPIRVValue *> &Ops); |
| 134 |
|
| 135 |
void setParent(SPIRVBasicBlock *); |
| 136 |
void setScope(SPIRVEntry *) override; |
| 137 |
void addFPRoundingMode(SPIRVFPRoundingModeKind Kind) { |
| 138 |
addDecorate(DecorationFPRoundingMode, Kind); |
| 139 |
} |
| 140 |
void eraseFPRoundingMode() { eraseDecorate(DecorationFPRoundingMode); } |
| 141 |
void setSaturatedConversion(bool Enable) { |
| 142 |
if (Enable) |
| 143 |
addDecorate(DecorationSaturatedConversion); |
| 144 |
else |
| 145 |
eraseDecorate(DecorationSaturatedConversion); |
| 146 |
} |
| 147 |
bool hasFPRoundingMode(SPIRVFPRoundingModeKind *Kind = nullptr) { |
| 148 |
SPIRVWord V; |
| 149 |
auto Found = hasDecorate(DecorationFPRoundingMode, 0, &V); |
| 150 |
if (Found && Kind) |
| 151 |
*Kind = static_cast<SPIRVFPRoundingModeKind>(V); |
| 152 |
return Found; |
| 153 |
} |
| 154 |
bool isSaturatedConversion() { |
| 155 |
return hasDecorate(DecorationSaturatedConversion) || |
| 156 |
OpCode == OpSatConvertSToU || OpCode == OpSatConvertUToS; |
| 157 |
} |
| 158 |
|
| 159 |
SPIRVBasicBlock *getBasicBlock() const { return BB; } |
| 160 |
|
| 161 |
void setBasicBlock(SPIRVBasicBlock *TheBB) { |
| 162 |
BB = TheBB; |
| 163 |
if (TheBB) |
| 164 |
setModule(TheBB->getModule()); |
| 165 |
} |
| 166 |
|
| 167 |
void setDebugScope(SPIRVEntry *Scope) { DebugScope = Scope; } |
| 168 |
|
| 169 |
SPIRVEntry *getDebugScope() const { return DebugScope; } |
| 170 |
|
| 171 |
protected: |
| 172 |
void validate() const override { SPIRVValue::validate(); } |
| 173 |
|
| 174 |
private: |
| 175 |
SPIRVBasicBlock *BB; |
| 176 |
SPIRVEntry *DebugScope; |
| 177 |
}; |
| 178 |
|
| 179 |
class SPIRVInstTemplateBase : public SPIRVInstruction { |
| 180 |
public: |
| 181 |
/// Create an empty instruction. Mainly for getting format information, |
| 182 |
/// e.g. whether an operand is literal. |
| 183 |
static SPIRVInstTemplateBase *create(Op TheOC) { |
| 184 |
auto Inst = static_cast<SPIRVInstTemplateBase *>(SPIRVEntry::create(TheOC)); |
| 185 |
assert(Inst); |
| 186 |
Inst->init(); |
| 187 |
return Inst; |
| 188 |
} |
| 189 |
/// Create a instruction without operands. |
| 190 |
static SPIRVInstTemplateBase *create(Op TheOC, SPIRVType *TheType, |
| 191 |
SPIRVId TheId, SPIRVBasicBlock *TheBB, |
| 192 |
SPIRVModule *TheModule) { |
| 193 |
auto Inst = create(TheOC); |
| 194 |
Inst->init(TheType, TheId, TheBB, TheModule); |
| 195 |
return Inst; |
| 196 |
} |
| 197 |
/// Create a complete and valid instruction. |
| 198 |
static SPIRVInstTemplateBase *create(Op TheOC, SPIRVType *TheType, |
| 199 |
SPIRVId TheId, |
| 200 |
const std::vector<SPIRVWord> &TheOps, |
| 201 |
SPIRVBasicBlock *TheBB, |
| 202 |
SPIRVModule *TheModule) { |
| 203 |
auto Inst = create(TheOC); |
| 204 |
Inst->init(TheType, TheId, TheBB, TheModule); |
| 205 |
Inst->setOpWords(TheOps); |
| 206 |
Inst->validate(); |
| 207 |
return Inst; |
| 208 |
} |
| 209 |
SPIRVInstTemplateBase(Op OC = OpNop) |
| 210 |
: SPIRVInstruction(OC), HasVariWC(false) { |
| 211 |
init(); |
| 212 |
} |
| 213 |
~SPIRVInstTemplateBase() override {} |
| 214 |
SPIRVInstTemplateBase *init(SPIRVType *TheType, SPIRVId TheId, |
| 215 |
SPIRVBasicBlock *TheBB, SPIRVModule *TheModule) { |
| 216 |
assert((TheBB || TheModule) && "Invalid BB or Module"); |
| 217 |
if (TheBB) |
| 218 |
setBasicBlock(TheBB); |
| 219 |
else { |
| 220 |
setModule(TheModule); |
| 221 |
} |
| 222 |
setId(hasId() ? TheId : SPIRVID_INVALID); |
| 223 |
setType(hasType() ? TheType : nullptr); |
| 224 |
return this; |
| 225 |
} |
| 226 |
virtual void init() {} |
| 227 |
virtual void initImpl(Op OC, bool HasId = true, SPIRVWord WC = 0, |
| 228 |
bool VariWC = false, unsigned Lit1 = ~0U, |
| 229 |
unsigned Lit2 = ~0U, unsigned Lit3 = ~0U) { |
| 230 |
OpCode = OC; |
| 231 |
if (!HasId) { |
| 232 |
setHasNoId(); |
| 233 |
setHasNoType(); |
| 234 |
} |
| 235 |
if (WC) |
| 236 |
SPIRVEntry::setWordCount(WC); |
| 237 |
setHasVariableWordCount(VariWC); |
| 238 |
addLit(Lit1); |
| 239 |
addLit(Lit2); |
| 240 |
addLit(Lit3); |
| 241 |
} |
| 242 |
bool isOperandLiteral(unsigned I) const override { return Lit.count(I); } |
| 243 |
void addLit(unsigned L) { |
| 244 |
if (L != ~0U) |
| 245 |
Lit.insert(L); |
| 246 |
} |
| 247 |
/// \return Expected number of operands. If the instruction has variable |
| 248 |
/// number of words, return the minimum. |
| 249 |
SPIRVWord getExpectedNumOperands() const { |
| 250 |
assert(WordCount > 0 && "Word count not initialized"); |
| 251 |
auto Exp = WordCount - 1; |
| 252 |
if (hasId()) |
| 253 |
--Exp; |
| 254 |
if (hasType()) |
| 255 |
--Exp; |
| 256 |
return Exp; |
| 257 |
} |
| 258 |
virtual void setOpWordsAndValidate(const std::vector<SPIRVWord> &TheOps) { |
| 259 |
setOpWords(TheOps); |
| 260 |
validate(); |
| 261 |
} |
| 262 |
virtual void setOpWords(const std::vector<SPIRVWord> &TheOps) { |
| 263 |
SPIRVWord WC = TheOps.size() + 1; |
| 264 |
if (hasId()) |
| 265 |
++WC; |
| 266 |
if (hasType()) |
| 267 |
++WC; |
| 268 |
if (WordCount) { |
| 269 |
if (WordCount == WC) { |
| 270 |
// do nothing |
| 271 |
} else { |
| 272 |
assert(HasVariWC && WC >= WordCount && "Invalid word count"); |
| 273 |
SPIRVEntry::setWordCount(WC); |
| 274 |
} |
| 275 |
} else |
| 276 |
SPIRVEntry::setWordCount(WC); |
| 277 |
Ops = TheOps; |
| 278 |
// The required SPIR-V version depends on the operands for some |
| 279 |
// instructions. |
| 280 |
updateModuleVersion(); |
| 281 |
} |
| 282 |
void setWordCount(SPIRVWord TheWordCount) override { |
| 283 |
SPIRVEntry::setWordCount(TheWordCount); |
| 284 |
auto NumOps = WordCount - 1; |
| 285 |
if (hasId()) |
| 286 |
--NumOps; |
| 287 |
if (hasType()) |
| 288 |
--NumOps; |
| 289 |
Ops.resize(NumOps); |
| 290 |
} |
| 291 |
|
| 292 |
std::vector<SPIRVWord> &getOpWords() { return Ops; } |
| 293 |
|
| 294 |
const std::vector<SPIRVWord> &getOpWords() const { return Ops; } |
| 295 |
|
| 296 |
SPIRVWord getOpWord(int I) const { return Ops[I]; } |
| 297 |
|
| 298 |
/// Get operand as value. |
| 299 |
/// If the operand is a literal, return it as a uint32 constant. |
| 300 |
const SPIRVValue *getOpValue(int I) const { |
| 301 |
return isOperandLiteral(I) ? Module->getLiteralAsConstant(Ops[I]) |
| 302 |
: getValue(Ops[I]); |
| 303 |
} |
| 304 |
|
| 305 |
SPIRVValue *getOpValue(int I) { |
| 306 |
return isOperandLiteral(I) ? Module->getLiteralAsConstant(Ops[I]) |
| 307 |
: getValue(Ops[I]); |
| 308 |
} |
| 309 |
|
| 310 |
std::vector<SPIRVValue *> getOperands() override { |
| 311 |
std::vector<SPIRVValue *> VOps; |
| 312 |
for (size_t I = 0, E = Ops.size(); I != E; ++I) |
| 313 |
VOps.push_back(getOperand(I)); |
| 314 |
return VOps; |
| 315 |
} |
| 316 |
|
| 317 |
std::vector<SPIRVEntry *> getNonLiteralOperands() const override { |
| 318 |
std::vector<SPIRVEntry *> Operands; |
| 319 |
for (size_t I = 0, E = Ops.size(); I < E; ++I) |
| 320 |
if (!isOperandLiteral(I)) |
| 321 |
Operands.push_back(getEntry(Ops[I])); |
| 322 |
return Operands; |
| 323 |
} |
| 324 |
|
| 325 |
virtual const SPIRVValue *getOperand(unsigned I) const { |
| 326 |
return getOpValue(I); |
| 327 |
} |
| 328 |
|
| 329 |
virtual SPIRVValue *getOperand(unsigned I) { |
| 330 |
return getOpValue(I); |
| 331 |
} |
| 332 |
|
| 333 |
bool hasExecScope() const { return SPIRV::hasExecScope(OpCode); } |
| 334 |
|
| 335 |
bool hasGroupOperation() const { return SPIRV::hasGroupOperation(OpCode); } |
| 336 |
|
| 337 |
bool getSPIRVGroupOperation(SPIRVGroupOperationKind &GroupOp) const { |
| 338 |
if (!hasGroupOperation()) |
| 339 |
return false; |
| 340 |
GroupOp = static_cast<SPIRVGroupOperationKind>(Ops[1]); |
| 341 |
return true; |
| 342 |
} |
| 343 |
|
| 344 |
Scope getExecutionScope() const { |
| 345 |
if (!hasExecScope()) |
| 346 |
return ScopeInvocation; |
| 347 |
return static_cast<Scope>( |
| 348 |
static_cast<SPIRVConstant *>(getValue(Ops[0]))->getZExtIntValue()); |
| 349 |
} |
| 350 |
|
| 351 |
bool hasVariableWordCount() const { return HasVariWC; } |
| 352 |
|
| 353 |
void setHasVariableWordCount(bool VariWC) { HasVariWC = VariWC; } |
| 354 |
|
| 355 |
protected: |
| 356 |
void encode(spv_ostream &O) const override { |
| 357 |
auto E = getEncoder(O); |
| 358 |
if (hasType()) |
| 359 |
E << Type; |
| 360 |
if (hasId()) |
| 361 |
E << Id; |
| 362 |
E << Ops; |
| 363 |
} |
| 364 |
void decode(std::istream &I) override { |
| 365 |
auto D = getDecoder(I); |
| 366 |
if (hasType()) |
| 367 |
D >> Type; |
| 368 |
if (hasId()) |
| 369 |
D >> Id; |
| 370 |
D >> Ops; |
| 371 |
} |
| 372 |
std::vector<SPIRVWord> Ops; |
| 373 |
bool HasVariWC; |
| 374 |
std::unordered_set<unsigned> Lit; // Literal operand index |
| 375 |
}; |
| 376 |
|
| 377 |
template <typename BT = SPIRVInstTemplateBase, Op OC = OpNop, bool HasId = true, |
| 378 |
SPIRVWord WC = 0, bool HasVariableWC = false, unsigned Literal1 = ~0U, |
| 379 |
unsigned Literal2 = ~0U, unsigned Literal3 = ~0U> |
| 380 |
class SPIRVInstTemplate : public BT { |
| 381 |
public: |
| 382 |
typedef BT BaseTy; |
| 383 |
SPIRVInstTemplate() { init(); } |
| 384 |
~SPIRVInstTemplate() override {} |
| 385 |
void init() override { |
| 386 |
this->initImpl(OC, HasId, WC, HasVariableWC, Literal1, Literal2, Literal3); |
| 387 |
} |
| 388 |
}; |
| 389 |
|
| 390 |
class SPIRVMemoryAccess { |
| 391 |
public: |
| 392 |
SPIRVMemoryAccess(const std::vector<SPIRVWord> &TheMemoryAccess) |
| 393 |
: TheMemoryAccessMask(0), Alignment(0), SrcAlignment(0), |
| 394 |
AliasScopeInstID(0), NoAliasInstID(0) { |
| 395 |
memoryAccessUpdate(TheMemoryAccess); |
| 396 |
} |
| 397 |
|
| 398 |
SPIRVMemoryAccess() |
| 399 |
: TheMemoryAccessMask(0), Alignment(0), SrcAlignment(0), |
| 400 |
AliasScopeInstID(0), NoAliasInstID(0) {} |
| 401 |
|
| 402 |
void memoryAccessUpdate(const std::vector<SPIRVWord> &MemoryAccess) { |
| 403 |
if (!MemoryAccess.size()) |
| 404 |
return; |
| 405 |
assert(MemoryAccess.size() > 0 && "Invalid memory access operand size"); |
| 406 |
assert(MemoryAccess.size() < 5 && "Invalid memory access operand size"); |
| 407 |
TheMemoryAccessMask = MemoryAccess[0]; |
| 408 |
size_t MemAccessNumParam = 1; |
| 409 |
if (MemoryAccess[0] & MemoryAccessAlignedMask) { |
| 410 |
assert(MemoryAccess.size() > 1 && "Alignment operand is missing"); |
| 411 |
Alignment = MemoryAccess[MemAccessNumParam++]; |
| 412 |
} |
| 413 |
if (MemoryAccess[0] & MemoryAccessAliasScopeINTELMaskMask) { |
| 414 |
assert(MemoryAccess.size() > MemAccessNumParam && |
| 415 |
"Aliasing operand is missing"); |
| 416 |
AliasScopeInstID = MemoryAccess[MemAccessNumParam++]; |
| 417 |
} |
| 418 |
if (MemoryAccess[0] & MemoryAccessNoAliasINTELMaskMask) { |
| 419 |
assert(MemoryAccess.size() > MemAccessNumParam && |
| 420 |
"Aliasing operand is missing"); |
| 421 |
NoAliasInstID = MemoryAccess[MemAccessNumParam++]; |
| 422 |
} |
| 423 |
|
| 424 |
// Exit if there is no second memory operand mask |
| 425 |
if (MemoryAccess.size() == MemAccessNumParam) |
| 426 |
return; |
| 427 |
|
| 428 |
size_t SecondMaskId = MemAccessNumParam++; |
| 429 |
if (MemoryAccess[SecondMaskId] & MemoryAccessAlignedMask) { |
| 430 |
assert(MemoryAccess.size() > MemAccessNumParam && |
| 431 |
"Alignment operand is missing"); |
| 432 |
SrcAlignment = MemoryAccess[MemAccessNumParam]; |
| 433 |
} |
| 434 |
} |
| 435 |
SPIRVWord isVolatile() const { |
| 436 |
return getMemoryAccessMask() & MemoryAccessVolatileMask; |
| 437 |
} |
| 438 |
SPIRVWord isNonTemporal() const { |
| 439 |
return getMemoryAccessMask() & MemoryAccessNontemporalMask; |
| 440 |
} |
| 441 |
SPIRVWord isAliasScope() const { |
| 442 |
return getMemoryAccessMask() & MemoryAccessAliasScopeINTELMaskMask; |
| 443 |
} |
| 444 |
SPIRVWord isNoAlias() const { |
| 445 |
return getMemoryAccessMask() & MemoryAccessNoAliasINTELMaskMask; |
| 446 |
} |
| 447 |
SPIRVWord getMemoryAccessMask() const { return TheMemoryAccessMask; } |
| 448 |
SPIRVWord getAlignment() const { return Alignment; } |
| 449 |
SPIRVWord getSrcAlignment() const { return SrcAlignment; } |
| 450 |
SPIRVWord getAliasScopeInstID() const { return AliasScopeInstID; } |
| 451 |
SPIRVWord getNoAliasInstID() const { return NoAliasInstID; } |
| 452 |
|
| 453 |
protected: |
| 454 |
SPIRVWord TheMemoryAccessMask; |
| 455 |
SPIRVWord Alignment; |
| 456 |
SPIRVWord SrcAlignment; |
| 457 |
SPIRVId AliasScopeInstID; |
| 458 |
SPIRVId NoAliasInstID; |
| 459 |
}; |
| 460 |
|
| 461 |
class SPIRVVariable : public SPIRVInstruction { |
| 462 |
public: |
| 463 |
// Complete constructor for integer constant |
| 464 |
SPIRVVariable(SPIRVType *TheType, SPIRVId TheId, SPIRVValue *TheInitializer, |
| 465 |
const std::string &TheName, |
| 466 |
SPIRVStorageClassKind TheStorageClass, SPIRVBasicBlock *TheBB, |
| 467 |
SPIRVModule *TheM) |
| 468 |
: SPIRVInstruction(TheInitializer ? 5 : 4, OpVariable, TheType, TheId, |
| 469 |
TheBB, TheM), |
| 470 |
StorageClass(TheStorageClass) { |
| 471 |
if (TheInitializer) |
| 472 |
Initializer.push_back(TheInitializer->getId()); |
| 473 |
Name = TheName; |
| 474 |
validate(); |
| 475 |
} |
| 476 |
// Incomplete constructor |
| 477 |
SPIRVVariable() |
| 478 |
: SPIRVInstruction(OpVariable), StorageClass(StorageClassFunction) {} |
| 479 |
|
| 480 |
SPIRVStorageClassKind getStorageClass() const { return StorageClass; } |
| 481 |
SPIRVValue *getInitializer() const { |
| 482 |
if (Initializer.empty()) |
| 483 |
return nullptr; |
| 484 |
assert(Initializer.size() == 1); |
| 485 |
return getValue(Initializer[0]); |
| 486 |
} |
| 487 |
bool isConstant() const { return hasDecorate(DecorationConstant); } |
| 488 |
bool isBuiltin(SPIRVBuiltinVariableKind *BuiltinKind = nullptr) const { |
| 489 |
SPIRVWord Kind; |
| 490 |
bool Found = hasDecorate(DecorationBuiltIn, 0, &Kind); |
| 491 |
if (!Found) |
| 492 |
return false; |
| 493 |
if (BuiltinKind) |
| 494 |
*BuiltinKind = static_cast<SPIRVBuiltinVariableKind>(Kind); |
| 495 |
return true; |
| 496 |
} |
| 497 |
void setBuiltin(SPIRVBuiltinVariableKind Kind) { |
| 498 |
assert(isValid(Kind)); |
| 499 |
addDecorate(new SPIRVDecorate(DecorationBuiltIn, this, Kind)); |
| 500 |
} |
| 501 |
void setIsConstant(bool Is) { |
| 502 |
if (Is) |
| 503 |
addDecorate(new SPIRVDecorate(DecorationConstant, this)); |
| 504 |
else |
| 505 |
eraseDecorate(DecorationConstant); |
| 506 |
} |
| 507 |
std::vector<SPIRVEntry *> getNonLiteralOperands() const override { |
| 508 |
if (SPIRVValue *V = getInitializer()) |
| 509 |
return std::vector<SPIRVEntry *>(1, V); |
| 510 |
return std::vector<SPIRVEntry *>(); |
| 511 |
} |
| 512 |
|
| 513 |
protected: |
| 514 |
void validate() const override { |
| 515 |
SPIRVValue::validate(); |
| 516 |
assert(isValid(StorageClass)); |
| 517 |
assert(Initializer.size() == 1 || Initializer.empty()); |
| 518 |
assert(getType()->isTypePointer()); |
| 519 |
} |
| 520 |
void setWordCount(SPIRVWord TheWordCount) override { |
| 521 |
SPIRVEntry::setWordCount(TheWordCount); |
| 522 |
Initializer.resize(WordCount - 4); |
| 523 |
} |
| 524 |
_SPIRV_DEF_ENCDEC4(Type, Id, StorageClass, Initializer) |
| 525 |
|
| 526 |
SPIRVStorageClassKind StorageClass; |
| 527 |
std::vector<SPIRVId> Initializer; |
| 528 |
}; |
| 529 |
|
| 530 |
class SPIRVStore : public SPIRVInstruction, public SPIRVMemoryAccess { |
| 531 |
public: |
| 532 |
const static SPIRVWord FixedWords = 3; |
| 533 |
// Complete constructor |
| 534 |
SPIRVStore(SPIRVId PointerId, SPIRVId ValueId, |
| 535 |
const std::vector<SPIRVWord> &TheMemoryAccess, |
| 536 |
SPIRVBasicBlock *TheBB) |
| 537 |
: SPIRVInstruction(FixedWords + TheMemoryAccess.size(), OpStore, TheBB), |
| 538 |
SPIRVMemoryAccess(TheMemoryAccess), MemoryAccess(TheMemoryAccess), |
| 539 |
PtrId(PointerId), ValId(ValueId) { |
| 540 |
setAttr(); |
| 541 |
validate(); |
| 542 |
assert(TheBB && "Invalid BB"); |
| 543 |
} |
| 544 |
// Incomplete constructor |
| 545 |
SPIRVStore() |
| 546 |
: SPIRVInstruction(OpStore), SPIRVMemoryAccess(), PtrId(SPIRVID_INVALID), |
| 547 |
ValId(SPIRVID_INVALID) { |
| 548 |
setAttr(); |
| 549 |
} |
| 550 |
|
| 551 |
SPIRVValue *getSrc() const { return getValue(ValId); } |
| 552 |
SPIRVValue *getDst() const { return getValue(PtrId); } |
| 553 |
|
| 554 |
protected: |
| 555 |
void setAttr() { |
| 556 |
setHasNoType(); |
| 557 |
setHasNoId(); |
| 558 |
} |
| 559 |
|
| 560 |
void setWordCount(SPIRVWord TheWordCount) override { |
| 561 |
SPIRVEntry::setWordCount(TheWordCount); |
| 562 |
MemoryAccess.resize(TheWordCount - FixedWords); |
| 563 |
} |
| 564 |
void encode(spv_ostream &O) const override { |
| 565 |
getEncoder(O) << PtrId << ValId << MemoryAccess; |
| 566 |
} |
| 567 |
|
| 568 |
void decode(std::istream &I) override { |
| 569 |
getDecoder(I) >> PtrId >> ValId >> MemoryAccess; |
| 570 |
memoryAccessUpdate(MemoryAccess); |
| 571 |
} |
| 572 |
|
| 573 |
void validate() const override { |
| 574 |
SPIRVInstruction::validate(); |
| 575 |
if (getSrc()->isForward() || getDst()->isForward()) |
| 576 |
return; |
| 577 |
assert(getValueType(PtrId)->getPointerElementType() == |
| 578 |
getValueType(ValId) && |
| 579 |
"Inconsistent operand types"); |
| 580 |
} |
| 581 |
|
| 582 |
private: |
| 583 |
std::vector<SPIRVWord> MemoryAccess; |
| 584 |
SPIRVId PtrId; |
| 585 |
SPIRVId ValId; |
| 586 |
}; |
| 587 |
|
| 588 |
class SPIRVLoad : public SPIRVInstruction, public SPIRVMemoryAccess { |
| 589 |
public: |
| 590 |
const static SPIRVWord FixedWords = 4; |
| 591 |
// Complete constructor |
| 592 |
SPIRVLoad(SPIRVId TheId, SPIRVId PointerId, |
| 593 |
const std::vector<SPIRVWord> &TheMemoryAccess, |
| 594 |
SPIRVBasicBlock *TheBB) |
| 595 |
: SPIRVInstruction( |
| 596 |
FixedWords + TheMemoryAccess.size(), OpLoad, |
| 597 |
TheBB->getValueType(PointerId)->getPointerElementType(), TheId, |
| 598 |
TheBB), |
| 599 |
SPIRVMemoryAccess(TheMemoryAccess), PtrId(PointerId), |
| 600 |
MemoryAccess(TheMemoryAccess) { |
| 601 |
validate(); |
| 602 |
assert(TheBB && "Invalid BB"); |
| 603 |
} |
| 604 |
// Incomplete constructor |
| 605 |
SPIRVLoad() |
| 606 |
: SPIRVInstruction(OpLoad), SPIRVMemoryAccess(), PtrId(SPIRVID_INVALID) {} |
| 607 |
|
| 608 |
SPIRVValue *getSrc() const { return Module->get<SPIRVValue>(PtrId); } |
| 609 |
|
| 610 |
protected: |
| 611 |
void setWordCount(SPIRVWord TheWordCount) override { |
| 612 |
SPIRVEntry::setWordCount(TheWordCount); |
| 613 |
MemoryAccess.resize(TheWordCount - FixedWords); |
| 614 |
} |
| 615 |
|
| 616 |
void encode(spv_ostream &O) const override { |
| 617 |
getEncoder(O) << Type << Id << PtrId << MemoryAccess; |
| 618 |
} |
| 619 |
|
| 620 |
void decode(std::istream &I) override { |
| 621 |
getDecoder(I) >> Type >> Id >> PtrId >> MemoryAccess; |
| 622 |
memoryAccessUpdate(MemoryAccess); |
| 623 |
} |
| 624 |
|
| 625 |
void validate() const override { |
| 626 |
SPIRVInstruction::validate(); |
| 627 |
assert((getValue(PtrId)->isForward() || |
| 628 |
Type == getValueType(PtrId)->getPointerElementType()) && |
| 629 |
"Inconsistent types"); |
| 630 |
} |
| 631 |
|
| 632 |
private: |
| 633 |
SPIRVId PtrId; |
| 634 |
std::vector<SPIRVWord> MemoryAccess; |
| 635 |
}; |
| 636 |
|
| 637 |
class SPIRVBinary : public SPIRVInstTemplateBase { |
| 638 |
protected: |
| 639 |
void validate() const override { |
| 640 |
SPIRVId Op1 = Ops[0]; |
| 641 |
SPIRVId Op2 = Ops[1]; |
| 642 |
SPIRVType *Op1Ty, *Op2Ty; |
| 643 |
SPIRVInstruction::validate(); |
| 644 |
if (getValue(Op1)->isForward() || getValue(Op2)->isForward()) |
| 645 |
return; |
| 646 |
if (getValueType(Op1)->isTypeVector()) { |
| 647 |
Op1Ty = getValueType(Op1)->getVectorComponentType(); |
| 648 |
Op2Ty = getValueType(Op2)->getVectorComponentType(); |
| 649 |
assert(getValueType(Op1)->getVectorComponentCount() == |
| 650 |
getValueType(Op2)->getVectorComponentCount() && |
| 651 |
"Inconsistent Vector component width"); |
| 652 |
} else if (getValueType(Op1)->isTypeCooperativeMatrixKHR()) { |
| 653 |
Op1Ty = getValueType(Op1)->getVectorComponentType(); |
| 654 |
Op2Ty = getValueType(Op2)->getVectorComponentType(); |
| 655 |
assert(Op1Ty == Op2Ty && "Inconsistent Cooperative matrix types"); |
| 656 |
} else { |
| 657 |
Op1Ty = getValueType(Op1); |
| 658 |
Op2Ty = getValueType(Op2); |
| 659 |
} |
| 660 |
|
| 661 |
(void)Op1Ty; |
| 662 |
(void)Op2Ty; |
| 663 |
if (isBinaryOpCode(OpCode)) { |
| 664 |
assert(getValueType(Op1) == getValueType(Op2) && |
| 665 |
"Invalid type for binary instruction"); |
| 666 |
assert((Op1Ty->isTypeInt() || Op2Ty->isTypeFloat()) && |
| 667 |
"Invalid type for Binary instruction"); |
| 668 |
assert((Op1Ty->getBitWidth() == Op2Ty->getBitWidth()) && |
| 669 |
"Inconsistent BitWidth"); |
| 670 |
} else if (isShiftOpCode(OpCode)) { |
| 671 |
assert((Op1Ty->isTypeInt() || Op2Ty->isTypeInt()) && |
| 672 |
"Invalid type for shift instruction"); |
| 673 |
} else if (isLogicalOpCode(OpCode)) { |
| 674 |
assert((Op1Ty->isTypeBool() || Op2Ty->isTypeBool()) && |
| 675 |
"Invalid type for logical instruction"); |
| 676 |
} else if (isBitwiseOpCode(OpCode)) { |
| 677 |
assert((Op1Ty->isTypeInt() || Op2Ty->isTypeInt()) && |
| 678 |
"Invalid type for bitwise instruction"); |
| 679 |
assert((Op1Ty->getIntegerBitWidth() == Op2Ty->getIntegerBitWidth()) && |
| 680 |
"Inconsistent BitWidth"); |
| 681 |
} else if (isBinaryPtrOpCode(OpCode)) { |
| 682 |
assert((Op1Ty->isTypePointer() && Op2Ty->isTypePointer()) && |
| 683 |
"Invalid types for PtrEqual, PtrNotEqual, or PtrDiff instruction"); |
| 684 |
assert(static_cast<SPIRVTypePointer *>(Op1Ty)->getElementType() == |
| 685 |
static_cast<SPIRVTypePointer *>(Op2Ty)->getElementType() && |
| 686 |
"Invalid types for PtrEqual, PtrNotEqual, or PtrDiff instruction"); |
| 687 |
} else { |
| 688 |
assert(0 && "Invalid op code!"); |
| 689 |
} |
| 690 |
} |
| 691 |
SPIRVWord getRequiredSPIRVVersion() const override { |
| 692 |
if (isBinaryPtrOpCode(OpCode)) |
| 693 |
return static_cast<SPIRVWord>(VersionNumber::SPIRV_1_4); |
| 694 |
return static_cast<SPIRVWord>(VersionNumber::SPIRV_1_0); |
| 695 |
} |
| 696 |
SPIRVCapVec getRequiredCapability() const override { |
| 697 |
if (OpCode == OpDot) { |
| 698 |
const SPIRVType *OpTy = getValueType(Ops[0]); |
| 699 |
if (OpTy && OpTy->isTypeVector()) { |
| 700 |
OpTy = OpTy->getVectorComponentType(); |
| 701 |
if (OpTy && OpTy->isTypeFloat(16, FPEncodingBFloat16KHR)) { |
| 702 |
return getVec(CapabilityBFloat16DotProductKHR); |
| 703 |
} |
| 704 |
} |
| 705 |
} |
| 706 |
return SPIRVInstruction::getRequiredCapability(); |
| 707 |
} |
| 708 |
}; |
| 709 |
|
| 710 |
template <Op OC> |
| 711 |
class SPIRVBinaryInst |
| 712 |
: public SPIRVInstTemplate<SPIRVBinary, OC, true, 5, false> {}; |
| 713 |
|
| 714 |
#define _SPIRV_OP(x) typedef SPIRVBinaryInst<Op##x> SPIRV##x; |
| 715 |
_SPIRV_OP(IAdd) |
| 716 |
_SPIRV_OP(IAddCarry) |
| 717 |
_SPIRV_OP(FAdd) |
| 718 |
_SPIRV_OP(ISub) |
| 719 |
_SPIRV_OP(ISubBorrow) |
| 720 |
_SPIRV_OP(FSub) |
| 721 |
_SPIRV_OP(IMul) |
| 722 |
_SPIRV_OP(FMul) |
| 723 |
_SPIRV_OP(SMulExtended) |
| 724 |
_SPIRV_OP(UMulExtended) |
| 725 |
_SPIRV_OP(UDiv) |
| 726 |
_SPIRV_OP(SDiv) |
| 727 |
_SPIRV_OP(FDiv) |
| 728 |
_SPIRV_OP(SRem) |
| 729 |
_SPIRV_OP(SMod) |
| 730 |
_SPIRV_OP(FRem) |
| 731 |
_SPIRV_OP(FMod) |
| 732 |
_SPIRV_OP(UMod) |
| 733 |
_SPIRV_OP(ShiftLeftLogical) |
| 734 |
_SPIRV_OP(ShiftRightLogical) |
| 735 |
_SPIRV_OP(ShiftRightArithmetic) |
| 736 |
_SPIRV_OP(LogicalAnd) |
| 737 |
_SPIRV_OP(LogicalOr) |
| 738 |
_SPIRV_OP(LogicalEqual) |
| 739 |
_SPIRV_OP(LogicalNotEqual) |
| 740 |
_SPIRV_OP(BitwiseAnd) |
| 741 |
_SPIRV_OP(BitwiseOr) |
| 742 |
_SPIRV_OP(BitwiseXor) |
| 743 |
_SPIRV_OP(Dot) |
| 744 |
_SPIRV_OP(PtrEqual) |
| 745 |
_SPIRV_OP(PtrNotEqual) |
| 746 |
_SPIRV_OP(PtrDiff) |
| 747 |
#undef _SPIRV_OP |
| 748 |
|
| 749 |
template <Op TheOpCode> class SPIRVInstNoOperand : public SPIRVInstruction { |
| 750 |
public: |
| 751 |
// Complete constructor |
| 752 |
SPIRVInstNoOperand(SPIRVBasicBlock *TheBB) |
| 753 |
: SPIRVInstruction(1, TheOpCode, TheBB) { |
| 754 |
setAttr(); |
| 755 |
validate(); |
| 756 |
} |
| 757 |
// Incomplete constructor |
| 758 |
SPIRVInstNoOperand() : SPIRVInstruction(TheOpCode) { setAttr(); } |
| 759 |
|
| 760 |
protected: |
| 761 |
void setAttr() { |
| 762 |
setHasNoId(); |
| 763 |
setHasNoType(); |
| 764 |
} |
| 765 |
_SPIRV_DEF_ENCDEC0 |
| 766 |
}; |
| 767 |
|
| 768 |
typedef SPIRVInstNoOperand<OpReturn> SPIRVReturn; |
| 769 |
typedef SPIRVInstNoOperand<OpUnreachable> SPIRVUnreachable; |
| 770 |
|
| 771 |
class SPIRVReturnValue : public SPIRVInstruction { |
| 772 |
public: |
| 773 |
static const Op OC = OpReturnValue; |
| 774 |
// Complete constructor |
| 775 |
SPIRVReturnValue(SPIRVValue *TheReturnValue, SPIRVBasicBlock *TheBB) |
| 776 |
: SPIRVInstruction(2, OC, TheBB), ReturnValueId(TheReturnValue->getId()) { |
| 777 |
setAttr(); |
| 778 |
validate(); |
| 779 |
assert(TheBB && "Invalid BB"); |
| 780 |
} |
| 781 |
// Incomplete constructor |
| 782 |
SPIRVReturnValue() : SPIRVInstruction(OC), ReturnValueId(SPIRVID_INVALID) { |
| 783 |
setAttr(); |
| 784 |
} |
| 785 |
|
| 786 |
SPIRVValue *getReturnValue() const { return getValue(ReturnValueId); } |
| 787 |
|
| 788 |
protected: |
| 789 |
void setAttr() { |
| 790 |
setHasNoId(); |
| 791 |
setHasNoType(); |
| 792 |
} |
| 793 |
_SPIRV_DEF_ENCDEC1(ReturnValueId) |
| 794 |
void validate() const override { SPIRVInstruction::validate(); } |
| 795 |
SPIRVId ReturnValueId; |
| 796 |
}; |
| 797 |
|
| 798 |
class SPIRVBranch : public SPIRVInstruction { |
| 799 |
public: |
| 800 |
static const Op OC = OpBranch; |
| 801 |
// Complete constructor |
| 802 |
SPIRVBranch(SPIRVLabel *TheTargetLabel, SPIRVBasicBlock *TheBB) |
| 803 |
: SPIRVInstruction(2, OC, TheBB), TargetLabelId(TheTargetLabel->getId()) { |
| 804 |
validate(); |
| 805 |
assert(TheBB && "Invalid BB"); |
| 806 |
} |
| 807 |
// Incomplete constructor |
| 808 |
SPIRVBranch() : SPIRVInstruction(OC), TargetLabelId(SPIRVID_INVALID) { |
| 809 |
setHasNoId(); |
| 810 |
setHasNoType(); |
| 811 |
} |
| 812 |
SPIRVValue *getTargetLabel() const { return getValue(TargetLabelId); } |
| 813 |
|
| 814 |
protected: |
| 815 |
_SPIRV_DEF_ENCDEC1(TargetLabelId) |
| 816 |
void validate() const override { |
| 817 |
SPIRVInstruction::validate(); |
| 818 |
assert(WordCount == 2); |
| 819 |
assert(OpCode == OC); |
| 820 |
assert(getTargetLabel()->isLabel() || getTargetLabel()->isForward()); |
| 821 |
} |
| 822 |
SPIRVId TargetLabelId; |
| 823 |
}; |
| 824 |
|
| 825 |
class SPIRVBranchConditional : public SPIRVInstruction { |
| 826 |
public: |
| 827 |
static const Op OC = OpBranchConditional; |
| 828 |
// Complete constructor |
| 829 |
SPIRVBranchConditional(SPIRVValue *TheCondition, SPIRVLabel *TheTrueLabel, |
| 830 |
SPIRVLabel *TheFalseLabel, SPIRVBasicBlock *TheBB) |
| 831 |
: SPIRVInstruction(4, OC, TheBB), ConditionId(TheCondition->getId()), |
| 832 |
TrueLabelId(TheTrueLabel->getId()), |
| 833 |
FalseLabelId(TheFalseLabel->getId()) { |
| 834 |
validate(); |
| 835 |
} |
| 836 |
SPIRVBranchConditional(SPIRVValue *TheCondition, SPIRVLabel *TheTrueLabel, |
| 837 |
SPIRVLabel *TheFalseLabel, SPIRVBasicBlock *TheBB, |
| 838 |
SPIRVWord TrueWeight, SPIRVWord FalseWeight) |
| 839 |
: SPIRVInstruction(6, OC, TheBB), ConditionId(TheCondition->getId()), |
| 840 |
TrueLabelId(TheTrueLabel->getId()), |
| 841 |
FalseLabelId(TheFalseLabel->getId()) { |
| 842 |
BranchWeights.push_back(TrueWeight); |
| 843 |
BranchWeights.push_back(FalseWeight); |
| 844 |
validate(); |
| 845 |
assert(TheBB && "Invalid BB"); |
| 846 |
} |
| 847 |
// Incomplete constructor |
| 848 |
SPIRVBranchConditional() |
| 849 |
: SPIRVInstruction(OC), ConditionId(SPIRVID_INVALID), |
| 850 |
TrueLabelId(SPIRVID_INVALID), FalseLabelId(SPIRVID_INVALID) { |
| 851 |
setHasNoId(); |
| 852 |
setHasNoType(); |
| 853 |
} |
| 854 |
SPIRVValue *getCondition() const { return getValue(ConditionId); } |
| 855 |
SPIRVLabel *getTrueLabel() const { return get<SPIRVLabel>(TrueLabelId); } |
| 856 |
SPIRVLabel *getFalseLabel() const { return get<SPIRVLabel>(FalseLabelId); } |
| 857 |
|
| 858 |
protected: |
| 859 |
void setWordCount(SPIRVWord TheWordCount) override { |
| 860 |
SPIRVEntry::setWordCount(TheWordCount); |
| 861 |
BranchWeights.resize(TheWordCount - 4); |
| 862 |
} |
| 863 |
_SPIRV_DEF_ENCDEC4(ConditionId, TrueLabelId, FalseLabelId, BranchWeights) |
| 864 |
void validate() const override { |
| 865 |
SPIRVInstruction::validate(); |
| 866 |
assert(WordCount == 4 || WordCount == 6); |
| 867 |
assert(WordCount == BranchWeights.size() + 4); |
| 868 |
assert(OpCode == OC); |
| 869 |
assert(getCondition()->isForward() || |
| 870 |
getCondition()->getType()->isTypeBool()); |
| 871 |
assert(getTrueLabel()->isForward() || getTrueLabel()->isLabel()); |
| 872 |
assert(getFalseLabel()->isForward() || getFalseLabel()->isLabel()); |
| 873 |
if (Module->isAllowedToUseVersion(VersionNumber::SPIRV_1_6)) |
| 874 |
assert(TrueLabelId != FalseLabelId); |
| 875 |
} |
| 876 |
SPIRVId ConditionId; |
| 877 |
SPIRVId TrueLabelId; |
| 878 |
SPIRVId FalseLabelId; |
| 879 |
std::vector<SPIRVWord> BranchWeights; |
| 880 |
}; |
| 881 |
|
| 882 |
class SPIRVPhi : public SPIRVInstruction { |
| 883 |
public: |
| 884 |
static const Op OC = OpPhi; |
| 885 |
static const SPIRVWord FixedWordCount = 3; |
| 886 |
SPIRVPhi(SPIRVType *TheType, SPIRVId TheId, |
| 887 |
const std::vector<SPIRVValue *> &ThePairs, SPIRVBasicBlock *BB) |
| 888 |
: SPIRVInstruction(ThePairs.size() + FixedWordCount, OC, TheType, TheId, |
| 889 |
BB) { |
| 890 |
Pairs = getIds(ThePairs); |
| 891 |
validate(); |
| 892 |
assert(BB && "Invalid BB"); |
| 893 |
} |
| 894 |
SPIRVPhi() : SPIRVInstruction(OC) {} |
| 895 |
std::vector<SPIRVValue *> getPairs() { return getValues(Pairs); } |
| 896 |
void addPair(SPIRVValue *Value, SPIRVBasicBlock *BB) { |
| 897 |
Pairs.push_back(Value->getId()); |
| 898 |
Pairs.push_back(BB->getId()); |
| 899 |
WordCount = Pairs.size() + FixedWordCount; |
| 900 |
validate(); |
| 901 |
} |
| 902 |
void setPairs(const std::vector<SPIRVValue *> &ThePairs) { |
| 903 |
Pairs = getIds(ThePairs); |
| 904 |
WordCount = Pairs.size() + FixedWordCount; |
| 905 |
validate(); |
| 906 |
} |
| 907 |
void foreachPair( |
| 908 |
std::function<void(SPIRVValue *, SPIRVBasicBlock *, size_t)> Func) { |
| 909 |
for (size_t I = 0, E = Pairs.size() / 2; I != E; ++I) { |
| 910 |
SPIRVEntry *Value, *BB; |
| 911 |
if (!Module->exist(Pairs[2 * I], &Value) || |
| 912 |
!Module->exist(Pairs[2 * I + 1], &BB)) |
| 913 |
continue; |
| 914 |
Func(static_cast<SPIRVValue *>(Value), static_cast<SPIRVBasicBlock *>(BB), |
| 915 |
I); |
| 916 |
} |
| 917 |
} |
| 918 |
void |
| 919 |
foreachPair(std::function<void(SPIRVValue *, SPIRVBasicBlock *)> Func) const { |
| 920 |
for (size_t I = 0, E = Pairs.size() / 2; I != E; ++I) { |
| 921 |
SPIRVEntry *Value, *BB; |
| 922 |
if (!Module->exist(Pairs[2 * I], &Value) || |
| 923 |
!Module->exist(Pairs[2 * I + 1], &BB)) |
| 924 |
continue; |
| 925 |
Func(static_cast<SPIRVValue *>(Value), |
| 926 |
static_cast<SPIRVBasicBlock *>(BB)); |
| 927 |
} |
| 928 |
} |
| 929 |
void setWordCount(SPIRVWord TheWordCount) override { |
| 930 |
SPIRVEntry::setWordCount(TheWordCount); |
| 931 |
Pairs.resize(TheWordCount - FixedWordCount); |
| 932 |
} |
| 933 |
_SPIRV_DEF_ENCDEC3(Type, Id, Pairs) |
| 934 |
void validate() const override { |
| 935 |
assert(WordCount == Pairs.size() + FixedWordCount); |
| 936 |
assert(OpCode == OC); |
| 937 |
assert(Pairs.size() % 2 == 0); |
| 938 |
foreachPair([=](SPIRVValue *IncomingV, SPIRVBasicBlock *IncomingBB) { |
| 939 |
assert(IncomingV->isForward() || IncomingV->getType() == Type); |
| 940 |
assert(IncomingBB->isBasicBlock() || IncomingBB->isForward()); |
| 941 |
}); |
| 942 |
SPIRVInstruction::validate(); |
| 943 |
} |
| 944 |
|
| 945 |
protected: |
| 946 |
std::vector<SPIRVId> Pairs; |
| 947 |
}; |
| 948 |
|
| 949 |
class SPIRVFPGARegINTELInstBase : public SPIRVInstTemplateBase { |
| 950 |
public: |
| 951 |
SPIRVCapVec getRequiredCapability() const override { |
| 952 |
return getVec(CapabilityFPGARegINTEL); |
| 953 |
} |
| 954 |
|
| 955 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 956 |
return ExtensionID::SPV_INTEL_fpga_reg; |
| 957 |
} |
| 958 |
|
| 959 |
protected: |
| 960 |
void validate() const override { |
| 961 |
SPIRVInstruction::validate(); |
| 962 |
|
| 963 |
assert(OpCode == OpFPGARegINTEL && |
| 964 |
"Invalid op code for FPGARegINTEL instruction"); |
| 965 |
assert(getType() == getValueType(Ops[0]) && "Inconsistent type"); |
| 966 |
} |
| 967 |
}; |
| 968 |
|
| 969 |
typedef SPIRVInstTemplate<SPIRVFPGARegINTELInstBase, OpFPGARegINTEL, true, 4> |
| 970 |
SPIRVFPGARegINTEL; |
| 971 |
|
| 972 |
class SPIRVCompare : public SPIRVInstTemplateBase { |
| 973 |
protected: |
| 974 |
void validate() const override { |
| 975 |
auto Op1 = Ops[0]; |
| 976 |
auto Op2 = Ops[1]; |
| 977 |
SPIRVType *Op1Ty, *Op2Ty, *ResTy; |
| 978 |
SPIRVInstruction::validate(); |
| 979 |
if (getValue(Op1)->isForward() || getValue(Op2)->isForward()) |
| 980 |
return; |
| 981 |
|
| 982 |
(void)Op1Ty; |
| 983 |
(void)Op2Ty; |
| 984 |
(void)ResTy; |
| 985 |
if (getValueType(Op1)->isTypeVector()) { |
| 986 |
Op1Ty = getValueType(Op1)->getVectorComponentType(); |
| 987 |
Op2Ty = getValueType(Op2)->getVectorComponentType(); |
| 988 |
ResTy = Type->getVectorComponentType(); |
| 989 |
assert(getValueType(Op1)->getVectorComponentCount() == |
| 990 |
getValueType(Op2)->getVectorComponentCount() && |
| 991 |
"Inconsistent Vector component width"); |
| 992 |
} else { |
| 993 |
Op1Ty = getValueType(Op1); |
| 994 |
Op2Ty = getValueType(Op2); |
| 995 |
ResTy = Type; |
| 996 |
} |
| 997 |
assert(isCmpOpCode(OpCode) && "Invalid op code for cmp inst"); |
| 998 |
if (OpCode == OpLessOrGreater) |
| 999 |
assert(this->getModule()->getSPIRVVersion() <= |
| 1000 |
static_cast<SPIRVWord>(VersionNumber::SPIRV_1_5) && |
| 1001 |
"OpLessOrGreater is removed starting from SPIR-V 1.6"); |
| 1002 |
assert((ResTy->isTypeBool() || ResTy->isTypeInt()) && |
| 1003 |
"Invalid type for compare instruction"); |
| 1004 |
assert(Op1Ty == Op2Ty && "Inconsistent types"); |
| 1005 |
} |
| 1006 |
}; |
| 1007 |
|
| 1008 |
template <Op OC> |
| 1009 |
class SPIRVCmpInst |
| 1010 |
: public SPIRVInstTemplate<SPIRVCompare, OC, true, 5, false> {}; |
| 1011 |
|
| 1012 |
#define _SPIRV_OP(x) typedef SPIRVCmpInst<Op##x> SPIRV##x; |
| 1013 |
_SPIRV_OP(IEqual) |
| 1014 |
_SPIRV_OP(FOrdEqual) |
| 1015 |
_SPIRV_OP(FUnordEqual) |
| 1016 |
_SPIRV_OP(INotEqual) |
| 1017 |
_SPIRV_OP(FOrdNotEqual) |
| 1018 |
_SPIRV_OP(FUnordNotEqual) |
| 1019 |
_SPIRV_OP(ULessThan) |
| 1020 |
_SPIRV_OP(SLessThan) |
| 1021 |
_SPIRV_OP(FOrdLessThan) |
| 1022 |
_SPIRV_OP(FUnordLessThan) |
| 1023 |
_SPIRV_OP(UGreaterThan) |
| 1024 |
_SPIRV_OP(SGreaterThan) |
| 1025 |
_SPIRV_OP(FOrdGreaterThan) |
| 1026 |
_SPIRV_OP(FUnordGreaterThan) |
| 1027 |
_SPIRV_OP(ULessThanEqual) |
| 1028 |
_SPIRV_OP(SLessThanEqual) |
| 1029 |
_SPIRV_OP(FOrdLessThanEqual) |
| 1030 |
_SPIRV_OP(FUnordLessThanEqual) |
| 1031 |
_SPIRV_OP(UGreaterThanEqual) |
| 1032 |
_SPIRV_OP(SGreaterThanEqual) |
| 1033 |
_SPIRV_OP(FOrdGreaterThanEqual) |
| 1034 |
_SPIRV_OP(FUnordGreaterThanEqual) |
| 1035 |
_SPIRV_OP(LessOrGreater) |
| 1036 |
_SPIRV_OP(Ordered) |
| 1037 |
_SPIRV_OP(Unordered) |
| 1038 |
#undef _SPIRV_OP |
| 1039 |
|
| 1040 |
class SPIRVSelectBase : public SPIRVInstTemplateBase { |
| 1041 |
public: |
| 1042 |
SPIRVValue *getCondition() { return getValue(Ops[0]); } |
| 1043 |
SPIRVValue *getTrueValue() { return getValue(Ops[1]); } |
| 1044 |
SPIRVValue *getFalseValue() { return getValue(Ops[2]); } |
| 1045 |
|
| 1046 |
protected: |
| 1047 |
void validate() const override { |
| 1048 |
SPIRVId Condition = Ops[0]; |
| 1049 |
SPIRVId Op1 = Ops[1]; |
| 1050 |
SPIRVId Op2 = Ops[2]; |
| 1051 |
|
| 1052 |
SPIRVInstruction::validate(); |
| 1053 |
if (getValue(Condition)->isForward() || getValue(Op1)->isForward() || |
| 1054 |
getValue(Op2)->isForward()) |
| 1055 |
return; |
| 1056 |
|
| 1057 |
SPIRVType *ConTy = getValueType(Condition)->isTypeVector() |
| 1058 |
? getValueType(Condition)->getVectorComponentType() |
| 1059 |
: getValueType(Condition); |
| 1060 |
(void)ConTy; |
| 1061 |
assert(ConTy->isTypeBool() && "Invalid type"); |
| 1062 |
assert(getType() == getValueType(Op1) && getType() == getValueType(Op2) && |
| 1063 |
"Inconsistent type"); |
| 1064 |
} |
| 1065 |
}; |
| 1066 |
|
| 1067 |
typedef SPIRVInstTemplate<SPIRVSelectBase, OpSelect, true, 6> SPIRVSelect; |
| 1068 |
|
| 1069 |
class SPIRVSelectionMerge : public SPIRVInstruction { |
| 1070 |
public: |
| 1071 |
static const Op OC = OpSelectionMerge; |
| 1072 |
static const SPIRVWord FixedWordCount = 3; |
| 1073 |
|
| 1074 |
SPIRVSelectionMerge(SPIRVId TheMergeBlock, SPIRVWord TheSelectionControl, |
| 1075 |
SPIRVBasicBlock *BB) |
| 1076 |
: SPIRVInstruction(3, OC, BB), MergeBlock(TheMergeBlock), |
| 1077 |
SelectionControl(TheSelectionControl) { |
| 1078 |
validate(); |
| 1079 |
assert(BB && "Invalid BB"); |
| 1080 |
} |
| 1081 |
|
| 1082 |
SPIRVSelectionMerge() |
| 1083 |
: SPIRVInstruction(OC), MergeBlock(SPIRVID_INVALID), |
| 1084 |
SelectionControl(SPIRVWORD_MAX) { |
| 1085 |
setHasNoId(); |
| 1086 |
setHasNoType(); |
| 1087 |
} |
| 1088 |
|
| 1089 |
SPIRVId getMergeBlock() { return MergeBlock; } |
| 1090 |
SPIRVWord getSelectionControl() { return SelectionControl; } |
| 1091 |
|
| 1092 |
_SPIRV_DEF_ENCDEC2(MergeBlock, SelectionControl) |
| 1093 |
|
| 1094 |
protected: |
| 1095 |
SPIRVId MergeBlock; |
| 1096 |
SPIRVWord SelectionControl; |
| 1097 |
}; |
| 1098 |
|
| 1099 |
class SPIRVLoopMerge : public SPIRVInstruction { |
| 1100 |
public: |
| 1101 |
static const Op OC = OpLoopMerge; |
| 1102 |
static const SPIRVWord FixedWordCount = 4; |
| 1103 |
|
| 1104 |
SPIRVLoopMerge(SPIRVId TheMergeBlock, SPIRVId TheContinueTarget, |
| 1105 |
SPIRVWord TheLoopControl, |
| 1106 |
std::vector<SPIRVWord> TheLoopControlParameters, |
| 1107 |
SPIRVBasicBlock *BB) |
| 1108 |
: SPIRVInstruction(FixedWordCount + TheLoopControlParameters.size(), OC, |
| 1109 |
BB), |
| 1110 |
MergeBlock(TheMergeBlock), ContinueTarget(TheContinueTarget), |
| 1111 |
LoopControl(TheLoopControl), |
| 1112 |
LoopControlParameters(TheLoopControlParameters) { |
| 1113 |
validate(); |
| 1114 |
assert(BB && "Invalid BB"); |
| 1115 |
} |
| 1116 |
|
| 1117 |
SPIRVLoopMerge() |
| 1118 |
: SPIRVInstruction(OC), MergeBlock(SPIRVID_MAX), |
| 1119 |
ContinueTarget(SPIRVID_MAX), LoopControl(SPIRVWORD_MAX) { |
| 1120 |
setHasNoId(); |
| 1121 |
setHasNoType(); |
| 1122 |
} |
| 1123 |
|
| 1124 |
SPIRVId getMergeBlock() { return MergeBlock; } |
| 1125 |
SPIRVId getContinueTarget() { return ContinueTarget; } |
| 1126 |
SPIRVWord getLoopControl() const { return LoopControl; } |
| 1127 |
std::vector<SPIRVWord> getLoopControlParameters() const { |
| 1128 |
return LoopControlParameters; |
| 1129 |
} |
| 1130 |
|
| 1131 |
void setWordCount(SPIRVWord TheWordCount) override { |
| 1132 |
SPIRVEntry::setWordCount(TheWordCount); |
| 1133 |
LoopControlParameters.resize(TheWordCount - FixedWordCount); |
| 1134 |
} |
| 1135 |
_SPIRV_DEF_ENCDEC4(MergeBlock, ContinueTarget, LoopControl, |
| 1136 |
LoopControlParameters) |
| 1137 |
|
| 1138 |
protected: |
| 1139 |
SPIRVId MergeBlock; |
| 1140 |
SPIRVId ContinueTarget; |
| 1141 |
SPIRVWord LoopControl; |
| 1142 |
std::vector<SPIRVWord> LoopControlParameters; |
| 1143 |
}; |
| 1144 |
|
| 1145 |
class SPIRVSwitch : public SPIRVInstruction { |
| 1146 |
public: |
| 1147 |
static const Op OC = OpSwitch; |
| 1148 |
static const SPIRVWord FixedWordCount = 3; |
| 1149 |
typedef std::vector<SPIRVWord> LiteralTy; |
| 1150 |
typedef std::pair<LiteralTy, SPIRVBasicBlock *> PairTy; |
| 1151 |
|
| 1152 |
SPIRVSwitch(SPIRVValue *TheSelect, SPIRVBasicBlock *TheDefault, |
| 1153 |
const std::vector<PairTy> &ThePairs, SPIRVBasicBlock *BB) |
| 1154 |
: SPIRVInstruction(FixedWordCount, OC, BB), Select(TheSelect->getId()), |
| 1155 |
Default(TheDefault->getId()) { |
| 1156 |
|
| 1157 |
if (!ThePairs.empty()) |
| 1158 |
SPIRVEntry::setWordCount( |
| 1159 |
ThePairs.size() * (ThePairs.at(0).first.size() + 1) + FixedWordCount); |
| 1160 |
|
| 1161 |
for (auto &I : ThePairs) { |
| 1162 |
for (auto &U : I.first) |
| 1163 |
Pairs.push_back(U); |
| 1164 |
Pairs.push_back(I.second->getId()); |
| 1165 |
} |
| 1166 |
validate(); |
| 1167 |
assert(BB && "Invalid BB"); |
| 1168 |
} |
| 1169 |
SPIRVSwitch() |
| 1170 |
: SPIRVInstruction(OC), Select(SPIRVWORD_MAX), Default(SPIRVWORD_MAX) { |
| 1171 |
setHasNoId(); |
| 1172 |
setHasNoType(); |
| 1173 |
} |
| 1174 |
std::vector<SPIRVValue *> getPairs() const { return getValues(Pairs); } |
| 1175 |
SPIRVValue *getSelect() const { return getValue(Select); } |
| 1176 |
SPIRVBasicBlock *getDefault() const { |
| 1177 |
return static_cast<SPIRVBasicBlock *>(getValue(Default)); |
| 1178 |
} |
| 1179 |
size_t getLiteralSize() const { |
| 1180 |
unsigned ByteWidth = getSelect()->getType()->getBitWidth() / 8; |
| 1181 |
unsigned Remainder = (ByteWidth % sizeof(SPIRVWord)) != 0; |
| 1182 |
return (ByteWidth / sizeof(SPIRVWord)) + Remainder; |
| 1183 |
} |
| 1184 |
size_t getPairSize() const { return getLiteralSize() + 1; } |
| 1185 |
size_t getNumPairs() const { return Pairs.size() / getPairSize(); } |
| 1186 |
void |
| 1187 |
foreachPair(std::function<void(LiteralTy, SPIRVBasicBlock *)> Func) const { |
| 1188 |
unsigned PairSize = getPairSize(); |
| 1189 |
for (size_t I = 0, E = getNumPairs(); I != E; ++I) { |
| 1190 |
SPIRVEntry *BB; |
| 1191 |
LiteralTy Literals; |
| 1192 |
if (!Module->exist(Pairs[PairSize * I + getLiteralSize()], &BB)) |
| 1193 |
continue; |
| 1194 |
|
| 1195 |
for (size_t J = 0; J < getLiteralSize(); ++J) { |
| 1196 |
Literals.push_back(Pairs.at(PairSize * I + J)); |
| 1197 |
} |
| 1198 |
Func(Literals, static_cast<SPIRVBasicBlock *>(BB)); |
| 1199 |
} |
| 1200 |
} |
| 1201 |
void setWordCount(SPIRVWord TheWordCount) override { |
| 1202 |
SPIRVEntry::setWordCount(TheWordCount); |
| 1203 |
Pairs.resize(TheWordCount - FixedWordCount); |
| 1204 |
} |
| 1205 |
_SPIRV_DEF_ENCDEC3(Select, Default, Pairs) |
| 1206 |
void validate() const override { |
| 1207 |
assert(WordCount == Pairs.size() + FixedWordCount); |
| 1208 |
assert(OpCode == OC); |
| 1209 |
assert(Pairs.size() % getPairSize() == 0); |
| 1210 |
foreachPair([=](LiteralTy Literals, SPIRVBasicBlock *BB) { |
| 1211 |
assert(BB->isBasicBlock() || BB->isForward()); |
| 1212 |
}); |
| 1213 |
SPIRVInstruction::validate(); |
| 1214 |
} |
| 1215 |
|
| 1216 |
protected: |
| 1217 |
SPIRVId Select; |
| 1218 |
SPIRVId Default; |
| 1219 |
std::vector<SPIRVWord> Pairs; |
| 1220 |
}; |
| 1221 |
|
| 1222 |
class SPIRVVectorTimesScalar : public SPIRVInstruction { |
| 1223 |
public: |
| 1224 |
static const Op OC = OpVectorTimesScalar; |
| 1225 |
static const SPIRVWord FixedWordCount = 4; |
| 1226 |
// Complete constructor |
| 1227 |
SPIRVVectorTimesScalar(SPIRVType *TheType, SPIRVId TheId, SPIRVId TheVector, |
| 1228 |
SPIRVId TheScalar, SPIRVBasicBlock *BB) |
| 1229 |
: SPIRVInstruction(5, OC, TheType, TheId, BB), Vector(TheVector), |
| 1230 |
Scalar(TheScalar) { |
| 1231 |
validate(); |
| 1232 |
assert(BB && "Invalid BB"); |
| 1233 |
} |
| 1234 |
// Incomplete constructor |
| 1235 |
SPIRVVectorTimesScalar() |
| 1236 |
: SPIRVInstruction(OC), Vector(SPIRVID_INVALID), Scalar(SPIRVID_INVALID) { |
| 1237 |
} |
| 1238 |
SPIRVValue *getVector() const { return getValue(Vector); } |
| 1239 |
SPIRVValue *getScalar() const { return getValue(Scalar); } |
| 1240 |
|
| 1241 |
std::vector<SPIRVValue *> getOperands() override { |
| 1242 |
std::vector<SPIRVId> Operands; |
| 1243 |
Operands.push_back(Vector); |
| 1244 |
Operands.push_back(Scalar); |
| 1245 |
return getValues(Operands); |
| 1246 |
} |
| 1247 |
|
| 1248 |
void setWordCount(SPIRVWord FixedWordCount) override { |
| 1249 |
SPIRVEntry::setWordCount(FixedWordCount); |
| 1250 |
} |
| 1251 |
_SPIRV_DEF_ENCDEC4(Type, Id, Vector, Scalar) |
| 1252 |
void validate() const override { |
| 1253 |
SPIRVInstruction::validate(); |
| 1254 |
if (getValue(Vector)->isForward() || getValue(Scalar)->isForward()) |
| 1255 |
return; |
| 1256 |
|
| 1257 |
assert(getValueType(Vector)->isTypeVector() && |
| 1258 |
getValueType(Vector)->getVectorComponentType()->isTypeFloat() && |
| 1259 |
"First operand must be a vector of floating-point type"); |
| 1260 |
assert(getValueType(getId())->isTypeVector() && |
| 1261 |
getValueType(getId())->getVectorComponentType()->isTypeFloat() && |
| 1262 |
"Result type must be a vector of floating-point type"); |
| 1263 |
assert( |
| 1264 |
getValueType(Vector)->getVectorComponentType() == |
| 1265 |
getValueType(getId())->getVectorComponentType() && |
| 1266 |
"Scalar must have the same type as the Component Type in Result Type"); |
| 1267 |
SPIRVInstruction::validate(); |
| 1268 |
} |
| 1269 |
|
| 1270 |
protected: |
| 1271 |
SPIRVId Vector; |
| 1272 |
SPIRVId Scalar; |
| 1273 |
}; |
| 1274 |
|
| 1275 |
class SPIRVVectorTimesMatrix : public SPIRVInstruction { |
| 1276 |
public: |
| 1277 |
static const Op OC = OpVectorTimesMatrix; |
| 1278 |
static const SPIRVWord FixedWordCount = 4; |
| 1279 |
|
| 1280 |
// Complete constructor |
| 1281 |
SPIRVVectorTimesMatrix(SPIRVType *TheType, SPIRVId TheId, SPIRVId TheVector, |
| 1282 |
SPIRVId TheMatrix, SPIRVBasicBlock *BB) |
| 1283 |
: SPIRVInstruction(5, OC, TheType, TheId, BB), Vector(TheVector), |
| 1284 |
Matrix(TheMatrix) { |
| 1285 |
validate(); |
| 1286 |
assert(BB && "Invalid BB"); |
| 1287 |
} |
| 1288 |
|
| 1289 |
// Incomplete constructor |
| 1290 |
SPIRVVectorTimesMatrix() |
| 1291 |
: SPIRVInstruction(OC), Vector(SPIRVID_INVALID), Matrix(SPIRVID_INVALID) { |
| 1292 |
} |
| 1293 |
|
| 1294 |
SPIRVValue *getVector() const { return getValue(Vector); } |
| 1295 |
SPIRVValue *getMatrix() const { return getValue(Matrix); } |
| 1296 |
|
| 1297 |
std::vector<SPIRVValue *> getOperands() override { |
| 1298 |
std::vector<SPIRVId> Operands; |
| 1299 |
Operands.push_back(Vector); |
| 1300 |
Operands.push_back(Matrix); |
| 1301 |
return getValues(Operands); |
| 1302 |
} |
| 1303 |
|
| 1304 |
void setWordCount(SPIRVWord FixedWordCount) override { |
| 1305 |
SPIRVEntry::setWordCount(FixedWordCount); |
| 1306 |
} |
| 1307 |
|
| 1308 |
_SPIRV_DEF_ENCDEC4(Type, Id, Vector, Matrix) |
| 1309 |
|
| 1310 |
void validate() const override { |
| 1311 |
SPIRVInstruction::validate(); |
| 1312 |
if (getValue(Vector)->isForward() || getValue(Matrix)->isForward()) |
| 1313 |
return; |
| 1314 |
|
| 1315 |
SPIRVType *Ty = getType()->getScalarType(); |
| 1316 |
SPIRVType *MTy = getValueType(Matrix)->getScalarType(); |
| 1317 |
SPIRVType *VTy = getValueType(Vector)->getScalarType(); |
| 1318 |
|
| 1319 |
(void)Ty; |
| 1320 |
(void)MTy; |
| 1321 |
(void)VTy; |
| 1322 |
assert(Ty->isTypeFloat() && "Invalid result type for OpVectorTimesMatrix"); |
| 1323 |
assert(VTy->isTypeFloat() && "Invalid Vector type for OpVectorTimesMatrix"); |
| 1324 |
assert(MTy->isTypeFloat() && "Invalid Matrix type for OpVectorTimesMatrix"); |
| 1325 |
|
| 1326 |
assert(Ty == MTy && Ty == VTy && "Mismatch float type"); |
| 1327 |
} |
| 1328 |
|
| 1329 |
private: |
| 1330 |
SPIRVId Vector; |
| 1331 |
SPIRVId Matrix; |
| 1332 |
}; |
| 1333 |
|
| 1334 |
class SPIRVMatrixTimesScalar : public SPIRVInstruction { |
| 1335 |
public: |
| 1336 |
static const Op OC = OpMatrixTimesScalar; |
| 1337 |
static const SPIRVWord FixedWordCount = 4; |
| 1338 |
// Complete constructor |
| 1339 |
SPIRVMatrixTimesScalar(SPIRVType *TheType, SPIRVId TheId, SPIRVId TheMatrix, |
| 1340 |
SPIRVId TheScalar, SPIRVBasicBlock *BB) |
| 1341 |
: SPIRVInstruction(5, OC, TheType, TheId, BB), Matrix(TheMatrix), |
| 1342 |
Scalar(TheScalar) { |
| 1343 |
validate(); |
| 1344 |
assert(BB && "Invalid BB"); |
| 1345 |
} |
| 1346 |
// Incomplete constructor |
| 1347 |
SPIRVMatrixTimesScalar() |
| 1348 |
: SPIRVInstruction(OC), Matrix(SPIRVID_INVALID), Scalar(SPIRVID_INVALID) { |
| 1349 |
} |
| 1350 |
SPIRVValue *getMatrix() const { return getValue(Matrix); } |
| 1351 |
SPIRVValue *getScalar() const { return getValue(Scalar); } |
| 1352 |
|
| 1353 |
std::vector<SPIRVValue *> getOperands() override { |
| 1354 |
std::vector<SPIRVId> Operands; |
| 1355 |
Operands.push_back(Matrix); |
| 1356 |
Operands.push_back(Scalar); |
| 1357 |
return getValues(Operands); |
| 1358 |
} |
| 1359 |
|
| 1360 |
void setWordCount(SPIRVWord FixedWordCount) override { |
| 1361 |
SPIRVEntry::setWordCount(FixedWordCount); |
| 1362 |
} |
| 1363 |
|
| 1364 |
_SPIRV_DEF_ENCDEC4(Type, Id, Matrix, Scalar) |
| 1365 |
|
| 1366 |
void validate() const override { |
| 1367 |
SPIRVInstruction::validate(); |
| 1368 |
if (getValue(Matrix)->isForward() || getValue(Scalar)->isForward()) |
| 1369 |
return; |
| 1370 |
|
| 1371 |
SPIRVType *Ty = getType()->getScalarType(); |
| 1372 |
SPIRVType *MTy = getValueType(Matrix)->getScalarType(); |
| 1373 |
SPIRVType *STy = getValueType(Scalar); |
| 1374 |
|
| 1375 |
(void)Ty; |
| 1376 |
(void)MTy; |
| 1377 |
(void)STy; |
| 1378 |
assert(Ty && Ty->isTypeFloat() && |
| 1379 |
"Invalid result type for OpMatrixTimesScalar"); |
| 1380 |
assert(MTy && MTy->isTypeFloat() && |
| 1381 |
"Invalid Matrix type for OpMatrixTimesScalar"); |
| 1382 |
assert(STy->isTypeFloat() && "Invalid Scalar type for OpMatrixTimesScalar"); |
| 1383 |
assert(Ty == MTy && Ty == STy && "Mismatch float type"); |
| 1384 |
} |
| 1385 |
|
| 1386 |
private: |
| 1387 |
SPIRVId Matrix; |
| 1388 |
SPIRVId Scalar; |
| 1389 |
}; |
| 1390 |
|
| 1391 |
class SPIRVMatrixTimesVector : public SPIRVInstruction { |
| 1392 |
public: |
| 1393 |
static const Op OC = OpMatrixTimesVector; |
| 1394 |
static const SPIRVWord FixedWordCount = 4; |
| 1395 |
|
| 1396 |
// Complete constructor |
| 1397 |
SPIRVMatrixTimesVector(SPIRVType *TheType, SPIRVId TheId, SPIRVId TheMatrix, |
| 1398 |
SPIRVId TheVector, SPIRVBasicBlock *BB) |
| 1399 |
: SPIRVInstruction(5, OC, TheType, TheId, BB), Matrix(TheMatrix), |
| 1400 |
Vector(TheVector) { |
| 1401 |
validate(); |
| 1402 |
assert(BB && "Invalid BB"); |
| 1403 |
} |
| 1404 |
|
| 1405 |
// Incomplete constructor |
| 1406 |
SPIRVMatrixTimesVector() |
| 1407 |
: SPIRVInstruction(OC), Matrix(SPIRVID_INVALID), Vector(SPIRVID_INVALID) { |
| 1408 |
} |
| 1409 |
|
| 1410 |
SPIRVValue *getMatrix() const { return getValue(Matrix); } |
| 1411 |
|
| 1412 |
SPIRVValue *getVector() const { return getValue(Vector); } |
| 1413 |
|
| 1414 |
std::vector<SPIRVValue *> getOperands() override { |
| 1415 |
std::vector<SPIRVId> Operands; |
| 1416 |
Operands.push_back(Matrix); |
| 1417 |
Operands.push_back(Vector); |
| 1418 |
return getValues(Operands); |
| 1419 |
} |
| 1420 |
|
| 1421 |
void setWordCount(SPIRVWord FixedWordCount) override { |
| 1422 |
SPIRVEntry::setWordCount(FixedWordCount); |
| 1423 |
} |
| 1424 |
|
| 1425 |
_SPIRV_DEF_ENCDEC4(Type, Id, Matrix, Vector) |
| 1426 |
|
| 1427 |
void validate() const override { |
| 1428 |
SPIRVInstruction::validate(); |
| 1429 |
if (getValue(Matrix)->isForward() || getValue(Vector)->isForward()) |
| 1430 |
return; |
| 1431 |
SPIRVType *Ty = getType()->getScalarType(); |
| 1432 |
SPIRVType *MTy = getValueType(Matrix)->getScalarType(); |
| 1433 |
SPIRVType *VTy = getValueType(Vector)->getScalarType(); |
| 1434 |
|
| 1435 |
(void)Ty; |
| 1436 |
(void)MTy; |
| 1437 |
(void)VTy; |
| 1438 |
assert(Ty->isTypeFloat() && "Invalid result type for OpMatrixTimesVector"); |
| 1439 |
assert(MTy->isTypeFloat() && "Invalid Matrix type for OpMatrixTimesVector"); |
| 1440 |
assert(VTy->isTypeFloat() && "Invalid Vector type for OpMatrixTimesVector"); |
| 1441 |
|
| 1442 |
assert(Ty == MTy && Ty == VTy && "Mismatch float type"); |
| 1443 |
} |
| 1444 |
|
| 1445 |
private: |
| 1446 |
SPIRVId Matrix; |
| 1447 |
SPIRVId Vector; |
| 1448 |
}; |
| 1449 |
|
| 1450 |
class SPIRVMatrixTimesMatrix : public SPIRVInstruction { |
| 1451 |
public: |
| 1452 |
static const Op OC = OpMatrixTimesMatrix; |
| 1453 |
static const SPIRVWord FixedWordCount = 4; |
| 1454 |
|
| 1455 |
// Complete constructor |
| 1456 |
SPIRVMatrixTimesMatrix(SPIRVType *TheType, SPIRVId TheId, SPIRVId M1, |
| 1457 |
SPIRVId M2, SPIRVBasicBlock *BB) |
| 1458 |
: SPIRVInstruction(5, OC, TheType, TheId, BB), LeftMatrix(M1), |
| 1459 |
RightMatrix(M2) { |
| 1460 |
validate(); |
| 1461 |
assert(BB && "Invalid BB"); |
| 1462 |
} |
| 1463 |
|
| 1464 |
// Incomplete constructor |
| 1465 |
SPIRVMatrixTimesMatrix() |
| 1466 |
: SPIRVInstruction(OC), LeftMatrix(SPIRVID_INVALID), |
| 1467 |
RightMatrix(SPIRVID_INVALID) {} |
| 1468 |
|
| 1469 |
SPIRVValue *getLeftMatrix() const { return getValue(LeftMatrix); } |
| 1470 |
|
| 1471 |
SPIRVValue *getRightMatrix() const { return getValue(RightMatrix); } |
| 1472 |
|
| 1473 |
std::vector<SPIRVValue *> getOperands() override { |
| 1474 |
std::vector<SPIRVId> Operands; |
| 1475 |
Operands.push_back(LeftMatrix); |
| 1476 |
Operands.push_back(RightMatrix); |
| 1477 |
return getValues(Operands); |
| 1478 |
} |
| 1479 |
|
| 1480 |
void setWordCount(SPIRVWord FixedWordCount) override { |
| 1481 |
SPIRVEntry::setWordCount(FixedWordCount); |
| 1482 |
} |
| 1483 |
|
| 1484 |
_SPIRV_DEF_ENCDEC4(Type, Id, LeftMatrix, RightMatrix) |
| 1485 |
|
| 1486 |
void validate() const override { |
| 1487 |
SPIRVInstruction::validate(); |
| 1488 |
if (getValue(LeftMatrix)->isForward() || getValue(RightMatrix)->isForward()) |
| 1489 |
return; |
| 1490 |
|
| 1491 |
SPIRVType *Ty = getType()->getScalarType(); |
| 1492 |
SPIRVType *LMTy = getValueType(LeftMatrix)->getScalarType(); |
| 1493 |
SPIRVType *RMTy = getValueType(RightMatrix)->getScalarType(); |
| 1494 |
|
| 1495 |
(void)Ty; |
| 1496 |
(void)LMTy; |
| 1497 |
(void)RMTy; |
| 1498 |
assert(Ty->isTypeFloat() && "Invalid result type for OpMatrixTimesMatrix"); |
| 1499 |
assert(LMTy->isTypeFloat() && |
| 1500 |
"Invalid Matrix type for OpMatrixTimesMatrix"); |
| 1501 |
assert(RMTy->isTypeFloat() && |
| 1502 |
"Invalid Matrix type for OpMatrixTimesMatrix"); |
| 1503 |
|
| 1504 |
assert(Ty == LMTy && Ty == RMTy && "Mismatch float type"); |
| 1505 |
} |
| 1506 |
|
| 1507 |
private: |
| 1508 |
SPIRVId LeftMatrix; |
| 1509 |
SPIRVId RightMatrix; |
| 1510 |
}; |
| 1511 |
|
| 1512 |
class SPIRVTranspose : public SPIRVInstruction { |
| 1513 |
public: |
| 1514 |
static const Op OC = OpTranspose; |
| 1515 |
static const SPIRVWord FixedWordCount = 3; |
| 1516 |
|
| 1517 |
// Complete constructor |
| 1518 |
SPIRVTranspose(SPIRVType *TheType, SPIRVId TheId, SPIRVId TheMatrix, |
| 1519 |
SPIRVBasicBlock *BB) |
| 1520 |
: SPIRVInstruction(4, OC, TheType, TheId, BB), Matrix(TheMatrix) { |
| 1521 |
validate(); |
| 1522 |
assert(BB && "Invalid BB"); |
| 1523 |
} |
| 1524 |
|
| 1525 |
// Incomplete constructor |
| 1526 |
SPIRVTranspose() : SPIRVInstruction(OC), Matrix(SPIRVID_INVALID) {} |
| 1527 |
|
| 1528 |
SPIRVValue *getMatrix() const { return getValue(Matrix); } |
| 1529 |
|
| 1530 |
std::vector<SPIRVValue *> getOperands() override { |
| 1531 |
std::vector<SPIRVId> Operands; |
| 1532 |
Operands.push_back(Matrix); |
| 1533 |
return getValues(Operands); |
| 1534 |
} |
| 1535 |
|
| 1536 |
void setWordCount(SPIRVWord FixedWordCount) override { |
| 1537 |
SPIRVEntry::setWordCount(FixedWordCount); |
| 1538 |
} |
| 1539 |
|
| 1540 |
_SPIRV_DEF_ENCDEC3(Type, Id, Matrix) |
| 1541 |
|
| 1542 |
void validate() const override { |
| 1543 |
SPIRVInstruction::validate(); |
| 1544 |
if (getValue(Matrix)->isForward()) |
| 1545 |
return; |
| 1546 |
|
| 1547 |
SPIRVType *Ty = getType()->getScalarType(); |
| 1548 |
SPIRVType *MTy = getValueType(Matrix)->getScalarType(); |
| 1549 |
|
| 1550 |
(void)Ty; |
| 1551 |
(void)MTy; |
| 1552 |
|
| 1553 |
assert(Ty->isTypeFloat() && "Invalid result type for OpTranspose"); |
| 1554 |
assert(Ty == MTy && "Mismatch float type"); |
| 1555 |
} |
| 1556 |
|
| 1557 |
private: |
| 1558 |
SPIRVId Matrix; |
| 1559 |
}; |
| 1560 |
|
| 1561 |
class SPIRVSizeOfInstBase : public SPIRVInstTemplateBase { |
| 1562 |
protected: |
| 1563 |
SPIRVWord getRequiredSPIRVVersion() const override { |
| 1564 |
return static_cast<SPIRVWord>(VersionNumber::SPIRV_1_1); |
| 1565 |
} |
| 1566 |
}; |
| 1567 |
|
| 1568 |
typedef SPIRVInstTemplate<SPIRVSizeOfInstBase, OpSizeOf, true, 4, false> |
| 1569 |
SPIRVSizeOf; |
| 1570 |
|
| 1571 |
class SPIRVUnary : public SPIRVInstTemplateBase { |
| 1572 |
protected: |
| 1573 |
void validate() const override { |
| 1574 |
auto Op = Ops[0]; |
| 1575 |
SPIRVInstruction::validate(); |
| 1576 |
if (getValue(Op)->isForward()) |
| 1577 |
return; |
| 1578 |
if (isGenericNegateOpCode(OpCode)) { |
| 1579 |
SPIRVType *ResTy = |
| 1580 |
Type->isTypeVector() || Type->isTypeCooperativeMatrixKHR() |
| 1581 |
? Type->getVectorComponentType() |
| 1582 |
: Type; |
| 1583 |
SPIRVType *OpTy = |
| 1584 |
Type->isTypeVector() || Type->isTypeCooperativeMatrixKHR() |
| 1585 |
? getValueType(Op)->getVectorComponentType() |
| 1586 |
: getValueType(Op); |
| 1587 |
|
| 1588 |
(void)ResTy; |
| 1589 |
(void)OpTy; |
| 1590 |
assert(getType() == getValueType(Op) && "Inconsistent type"); |
| 1591 |
assert((ResTy->isTypeInt() || ResTy->isTypeFloat()) && |
| 1592 |
"Invalid type for Generic Negate instruction"); |
| 1593 |
assert((ResTy->getBitWidth() == OpTy->getBitWidth()) && |
| 1594 |
"Invalid bitwidth for Generic Negate instruction"); |
| 1595 |
assert((Type->isTypeVector() |
| 1596 |
? (Type->getVectorComponentCount() == |
| 1597 |
getValueType(Op)->getVectorComponentCount()) |
| 1598 |
: 1) && |
| 1599 |
"Invalid vector component Width for Generic Negate instruction"); |
| 1600 |
} |
| 1601 |
} |
| 1602 |
}; |
| 1603 |
|
| 1604 |
template <Op OC> |
| 1605 |
class SPIRVUnaryInst |
| 1606 |
: public SPIRVInstTemplate<SPIRVUnary, OC, true, 4, false> {}; |
| 1607 |
|
| 1608 |
#define _SPIRV_OP(x) typedef SPIRVUnaryInst<Op##x> SPIRV##x; |
| 1609 |
_SPIRV_OP(ConvertFToU) |
| 1610 |
_SPIRV_OP(ConvertFToS) |
| 1611 |
_SPIRV_OP(ConvertSToF) |
| 1612 |
_SPIRV_OP(ConvertUToF) |
| 1613 |
_SPIRV_OP(UConvert) |
| 1614 |
_SPIRV_OP(SConvert) |
| 1615 |
_SPIRV_OP(FConvert) |
| 1616 |
_SPIRV_OP(SatConvertSToU) |
| 1617 |
_SPIRV_OP(SatConvertUToS) |
| 1618 |
_SPIRV_OP(ConvertPtrToU) |
| 1619 |
_SPIRV_OP(ConvertUToPtr) |
| 1620 |
_SPIRV_OP(PtrCastToGeneric) |
| 1621 |
_SPIRV_OP(GenericCastToPtr) |
| 1622 |
_SPIRV_OP(CrossWorkgroupCastToPtrINTEL) |
| 1623 |
_SPIRV_OP(PtrCastToCrossWorkgroupINTEL) |
| 1624 |
_SPIRV_OP(Bitcast) |
| 1625 |
_SPIRV_OP(SNegate) |
| 1626 |
_SPIRV_OP(FNegate) |
| 1627 |
_SPIRV_OP(Not) |
| 1628 |
_SPIRV_OP(LogicalNot) |
| 1629 |
_SPIRV_OP(IsNan) |
| 1630 |
_SPIRV_OP(IsInf) |
| 1631 |
_SPIRV_OP(IsFinite) |
| 1632 |
_SPIRV_OP(IsNormal) |
| 1633 |
_SPIRV_OP(SignBitSet) |
| 1634 |
_SPIRV_OP(Any) |
| 1635 |
_SPIRV_OP(All) |
| 1636 |
_SPIRV_OP(BitCount) |
| 1637 |
_SPIRV_OP(ArithmeticFenceEXT) |
| 1638 |
#undef _SPIRV_OP |
| 1639 |
|
| 1640 |
class SPIRVAccessChainBase : public SPIRVInstTemplateBase { |
| 1641 |
public: |
| 1642 |
SPIRVValue *getBase() { return this->getValue(this->Ops[0]); } |
| 1643 |
std::vector<SPIRVValue *> getIndices() const { |
| 1644 |
std::vector<SPIRVWord> IndexWords(this->Ops.begin() + 1, this->Ops.end()); |
| 1645 |
return this->getValues(IndexWords); |
| 1646 |
} |
| 1647 |
bool isInBounds() { |
| 1648 |
return OpCode == OpInBoundsAccessChain || |
| 1649 |
OpCode == OpInBoundsPtrAccessChain; |
| 1650 |
} |
| 1651 |
bool hasPtrIndex() { |
| 1652 |
return OpCode == OpPtrAccessChain || OpCode == OpInBoundsPtrAccessChain; |
| 1653 |
} |
| 1654 |
}; |
| 1655 |
|
| 1656 |
template <Op OC, unsigned FixedWC> |
| 1657 |
class SPIRVAccessChainGeneric |
| 1658 |
: public SPIRVInstTemplate<SPIRVAccessChainBase, OC, true, FixedWC, true> { |
| 1659 |
}; |
| 1660 |
|
| 1661 |
typedef SPIRVAccessChainGeneric<OpAccessChain, 4> SPIRVAccessChain; |
| 1662 |
typedef SPIRVAccessChainGeneric<OpInBoundsAccessChain, 4> |
| 1663 |
SPIRVInBoundsAccessChain; |
| 1664 |
typedef SPIRVAccessChainGeneric<OpPtrAccessChain, 5> SPIRVPtrAccessChain; |
| 1665 |
typedef SPIRVAccessChainGeneric<OpInBoundsPtrAccessChain, 5> |
| 1666 |
SPIRVInBoundsPtrAccessChain; |
| 1667 |
|
| 1668 |
class SPIRVLoopControlINTEL : public SPIRVInstruction { |
| 1669 |
public: |
| 1670 |
static const Op OC = OpLoopControlINTEL; |
| 1671 |
static const SPIRVWord FixedWordCount = 2; |
| 1672 |
|
| 1673 |
SPIRVLoopControlINTEL(SPIRVWord TheLoopControl, |
| 1674 |
std::vector<SPIRVWord> TheLoopControlParameters, |
| 1675 |
SPIRVBasicBlock *BB) |
| 1676 |
: SPIRVInstruction(FixedWordCount + TheLoopControlParameters.size(), OC, |
| 1677 |
BB), |
| 1678 |
LoopControl(TheLoopControl), |
| 1679 |
LoopControlParameters(TheLoopControlParameters) { |
| 1680 |
validate(); |
| 1681 |
assert(BB && "Invalid BB"); |
| 1682 |
} |
| 1683 |
|
| 1684 |
SPIRVLoopControlINTEL() : SPIRVInstruction(OC), LoopControl(SPIRVWORD_MAX) { |
| 1685 |
setHasNoId(); |
| 1686 |
setHasNoType(); |
| 1687 |
} |
| 1688 |
|
| 1689 |
SPIRVWord getLoopControl() const { return LoopControl; } |
| 1690 |
|
| 1691 |
std::vector<SPIRVWord> getLoopControlParameters() const { |
| 1692 |
return LoopControlParameters; |
| 1693 |
} |
| 1694 |
|
| 1695 |
SPIRVCapVec getRequiredCapability() const override { |
| 1696 |
return getVec(CapabilityUnstructuredLoopControlsINTEL); |
| 1697 |
} |
| 1698 |
|
| 1699 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 1700 |
return ExtensionID::SPV_INTEL_unstructured_loop_controls; |
| 1701 |
} |
| 1702 |
|
| 1703 |
void setWordCount(SPIRVWord TheWordCount) override { |
| 1704 |
SPIRVEntry::setWordCount(TheWordCount); |
| 1705 |
LoopControlParameters.resize(TheWordCount - FixedWordCount); |
| 1706 |
} |
| 1707 |
_SPIRV_DEF_ENCDEC2(LoopControl, LoopControlParameters) |
| 1708 |
|
| 1709 |
protected: |
| 1710 |
SPIRVWord LoopControl; |
| 1711 |
std::vector<SPIRVWord> LoopControlParameters; |
| 1712 |
}; |
| 1713 |
|
| 1714 |
template <Op OC, SPIRVWord FixedWordCount> |
| 1715 |
class SPIRVFunctionCallGeneric : public SPIRVInstruction { |
| 1716 |
public: |
| 1717 |
SPIRVFunctionCallGeneric(SPIRVType *TheType, SPIRVId TheId, |
| 1718 |
const std::vector<SPIRVWord> &TheArgs, |
| 1719 |
SPIRVBasicBlock *BB) |
| 1720 |
: SPIRVInstruction(TheArgs.size() + FixedWordCount, OC, TheType, TheId, |
| 1721 |
BB), |
| 1722 |
Args(TheArgs) { |
| 1723 |
SPIRVFunctionCallGeneric::validate(); |
| 1724 |
assert(BB && "Invalid BB"); |
| 1725 |
} |
| 1726 |
SPIRVFunctionCallGeneric(SPIRVType *TheType, SPIRVId TheId, |
| 1727 |
const std::vector<SPIRVValue *> &TheArgs, |
| 1728 |
SPIRVBasicBlock *BB) |
| 1729 |
: SPIRVInstruction(TheArgs.size() + FixedWordCount, OC, TheType, TheId, |
| 1730 |
BB) { |
| 1731 |
Args = getIds(TheArgs); |
| 1732 |
SPIRVFunctionCallGeneric::validate(); |
| 1733 |
assert(BB && "Invalid BB"); |
| 1734 |
} |
| 1735 |
|
| 1736 |
SPIRVFunctionCallGeneric(SPIRVModule *BM, SPIRVWord ResId, SPIRVType *TheType, |
| 1737 |
const std::vector<SPIRVWord> &TheArgs) |
| 1738 |
: SPIRVInstruction(TheArgs.size() + FixedWordCount, OC, TheType, ResId, |
| 1739 |
BM), |
| 1740 |
Args(TheArgs) {} |
| 1741 |
|
| 1742 |
SPIRVFunctionCallGeneric() : SPIRVInstruction(OC) {} |
| 1743 |
const std::vector<SPIRVWord> &getArguments() const { return Args; } |
| 1744 |
void setArguments(const std::vector<SPIRVWord> &A) { |
| 1745 |
Args = A; |
| 1746 |
setWordCount(Args.size() + FixedWordCount); |
| 1747 |
} |
| 1748 |
std::vector<SPIRVValue *> getArgumentValues() { return getValues(Args); } |
| 1749 |
std::vector<SPIRVType *> getArgumentValueTypes() const { |
| 1750 |
std::vector<SPIRVType *> ArgTypes; |
| 1751 |
for (auto &I : Args) |
| 1752 |
ArgTypes.push_back(getValue(I)->getType()); |
| 1753 |
return ArgTypes; |
| 1754 |
} |
| 1755 |
void setWordCount(SPIRVWord TheWordCount) override { |
| 1756 |
SPIRVEntry::setWordCount(TheWordCount); |
| 1757 |
Args.resize(TheWordCount - FixedWordCount); |
| 1758 |
} |
| 1759 |
void validate() const override { SPIRVInstruction::validate(); } |
| 1760 |
|
| 1761 |
protected: |
| 1762 |
std::vector<SPIRVWord> Args; |
| 1763 |
}; |
| 1764 |
|
| 1765 |
class SPIRVFunctionCall : public SPIRVFunctionCallGeneric<OpFunctionCall, 4> { |
| 1766 |
public: |
| 1767 |
SPIRVFunctionCall(SPIRVId TheId, SPIRVFunction *TheFunction, |
| 1768 |
const std::vector<SPIRVWord> &TheArgs, SPIRVBasicBlock *BB); |
| 1769 |
SPIRVFunctionCall() : FunctionId(SPIRVID_INVALID) {} |
| 1770 |
SPIRVFunction *getFunction() const { return get<SPIRVFunction>(FunctionId); } |
| 1771 |
_SPIRV_DEF_ENCDEC4(Type, Id, FunctionId, Args) |
| 1772 |
void validate() const override; |
| 1773 |
bool isOperandLiteral(unsigned Index) const override { return false; } |
| 1774 |
|
| 1775 |
protected: |
| 1776 |
SPIRVId FunctionId; |
| 1777 |
}; |
| 1778 |
|
| 1779 |
class SPIRVFunctionPointerCallINTEL |
| 1780 |
: public SPIRVFunctionCallGeneric<OpFunctionPointerCallINTEL, 4> { |
| 1781 |
public: |
| 1782 |
SPIRVFunctionPointerCallINTEL(SPIRVId TheId, SPIRVValue *TheCalledValue, |
| 1783 |
SPIRVType *TheReturnType, |
| 1784 |
const std::vector<SPIRVWord> &TheArgs, |
| 1785 |
SPIRVBasicBlock *BB); |
| 1786 |
SPIRVFunctionPointerCallINTEL() : CalledValueId(SPIRVID_INVALID) {} |
| 1787 |
SPIRVValue *getCalledValue() const { return get<SPIRVValue>(CalledValueId); } |
| 1788 |
_SPIRV_DEF_ENCDEC4(Type, Id, CalledValueId, Args) |
| 1789 |
void validate() const override; |
| 1790 |
bool isOperandLiteral(unsigned Index) const override { return false; } |
| 1791 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 1792 |
return ExtensionID::SPV_INTEL_function_pointers; |
| 1793 |
} |
| 1794 |
SPIRVCapVec getRequiredCapability() const override { |
| 1795 |
return getVec(CapabilityFunctionPointersINTEL); |
| 1796 |
} |
| 1797 |
|
| 1798 |
protected: |
| 1799 |
SPIRVId CalledValueId; |
| 1800 |
}; |
| 1801 |
|
| 1802 |
class SPIRVExtInst : public SPIRVFunctionCallGeneric<OpExtInst, 5> { |
| 1803 |
public: |
| 1804 |
SPIRVExtInst(SPIRVType *TheType, SPIRVId TheId, SPIRVId TheBuiltinSet, |
| 1805 |
SPIRVWord TheEntryPoint, const std::vector<SPIRVWord> &TheArgs, |
| 1806 |
SPIRVBasicBlock *BB) |
| 1807 |
: SPIRVFunctionCallGeneric(TheType, TheId, TheArgs, BB), |
| 1808 |
ExtSetId(TheBuiltinSet), ExtOp(TheEntryPoint) { |
| 1809 |
setExtSetKindById(); |
| 1810 |
SPIRVExtInst::validate(); |
| 1811 |
} |
| 1812 |
SPIRVExtInst(SPIRVType *TheType, SPIRVId TheId, SPIRVId TheBuiltinSet, |
| 1813 |
SPIRVWord TheEntryPoint, |
| 1814 |
const std::vector<SPIRVValue *> &TheArgs, SPIRVBasicBlock *BB) |
| 1815 |
: SPIRVFunctionCallGeneric(TheType, TheId, TheArgs, BB), |
| 1816 |
ExtSetId(TheBuiltinSet), ExtOp(TheEntryPoint) { |
| 1817 |
setExtSetKindById(); |
| 1818 |
SPIRVExtInst::validate(); |
| 1819 |
} |
| 1820 |
|
| 1821 |
SPIRVExtInst(SPIRVModule *BM, SPIRVId ResId, SPIRVType *TheType, |
| 1822 |
SPIRVExtInstSetKind SetKind, SPIRVWord SetId, SPIRVWord InstId, |
| 1823 |
const std::vector<SPIRVWord> &Args) |
| 1824 |
: SPIRVFunctionCallGeneric(BM, ResId, TheType, Args), ExtSetKind(SetKind), |
| 1825 |
ExtSetId(SetId), ExtOp(InstId) {} |
| 1826 |
|
| 1827 |
SPIRVExtInst(SPIRVExtInstSetKind SetKind = SPIRVEIS_Count, |
| 1828 |
unsigned ExtOC = SPIRVWORD_MAX) |
| 1829 |
: ExtSetKind(SetKind), ExtSetId(SPIRVWORD_MAX), ExtOp(ExtOC) {} |
| 1830 |
void setExtSetId(unsigned Set) { ExtSetId = Set; } |
| 1831 |
void setExtOp(unsigned ExtOC) { ExtOp = ExtOC; } |
| 1832 |
SPIRVId getExtSetId() const { return ExtSetId; } |
| 1833 |
SPIRVWord getExtOp() const { return ExtOp; } |
| 1834 |
|
| 1835 |
SPIRVExtInstSetKind getExtSetKind() const { return ExtSetKind; } |
| 1836 |
|
| 1837 |
void addContinuedInstruction(SPIRVExtInst *Inst) { |
| 1838 |
ContinuedInstructions.push_back(Inst); |
| 1839 |
} |
| 1840 |
|
| 1841 |
std::vector<SPIRVExtInst *> getContinuedInstructions() { |
| 1842 |
return ContinuedInstructions; |
| 1843 |
} |
| 1844 |
|
| 1845 |
void setExtSetKindById() { |
| 1846 |
assert(Module && "Invalid module"); |
| 1847 |
ExtSetKind = Module->getBuiltinSet(ExtSetId); |
| 1848 |
assert((ExtSetKind == SPIRVEIS_OpenCL || ExtSetKind == SPIRVEIS_Debug || |
| 1849 |
ExtSetKind == SPIRVEIS_OpenCL_DebugInfo_100 || |
| 1850 |
ExtSetKind == SPIRVEIS_NonSemantic_Shader_DebugInfo_100 || |
| 1851 |
ExtSetKind == SPIRVEIS_NonSemantic_Shader_DebugInfo_200 || |
| 1852 |
ExtSetKind == SPIRVEIS_NonSemantic_AuxData) && |
| 1853 |
"not supported"); |
| 1854 |
} |
| 1855 |
void encode(spv_ostream &O) const override { |
| 1856 |
getEncoder(O) << Type << Id << ExtSetId; |
| 1857 |
switch (ExtSetKind) { |
| 1858 |
case SPIRVEIS_OpenCL: |
| 1859 |
getEncoder(O) << ExtOpOCL; |
| 1860 |
break; |
| 1861 |
case SPIRVEIS_Debug: |
| 1862 |
case SPIRVEIS_OpenCL_DebugInfo_100: |
| 1863 |
case SPIRVEIS_NonSemantic_Shader_DebugInfo_100: |
| 1864 |
case SPIRVEIS_NonSemantic_Shader_DebugInfo_200: |
| 1865 |
getEncoder(O) << ExtOpDebug; |
| 1866 |
break; |
| 1867 |
case SPIRVEIS_NonSemantic_AuxData: |
| 1868 |
getEncoder(O) << ExtOpNonSemanticAuxData; |
| 1869 |
break; |
| 1870 |
default: |
| 1871 |
assert(0 && "not supported"); |
| 1872 |
getEncoder(O) << ExtOp; |
| 1873 |
} |
| 1874 |
getEncoder(O) << Args; |
| 1875 |
} |
| 1876 |
void decode(std::istream &I) override { |
| 1877 |
getDecoder(I) >> Type >> Id >> ExtSetId; |
| 1878 |
setExtSetKindById(); |
| 1879 |
switch (ExtSetKind) { |
| 1880 |
case SPIRVEIS_OpenCL: |
| 1881 |
getDecoder(I) >> ExtOpOCL; |
| 1882 |
break; |
| 1883 |
case SPIRVEIS_Debug: |
| 1884 |
case SPIRVEIS_OpenCL_DebugInfo_100: |
| 1885 |
case SPIRVEIS_NonSemantic_Shader_DebugInfo_100: |
| 1886 |
case SPIRVEIS_NonSemantic_Shader_DebugInfo_200: |
| 1887 |
getDecoder(I) >> ExtOpDebug; |
| 1888 |
break; |
| 1889 |
case SPIRVEIS_NonSemantic_AuxData: |
| 1890 |
getDecoder(I) >> ExtOpNonSemanticAuxData; |
| 1891 |
break; |
| 1892 |
default: |
| 1893 |
assert(0 && "not supported"); |
| 1894 |
getDecoder(I) >> ExtOp; |
| 1895 |
} |
| 1896 |
SPIRVDecoder Decoder = getDecoder(I); |
| 1897 |
Decoder >> Args; |
| 1898 |
|
| 1899 |
if (ExtSetKind == SPIRVEIS_NonSemantic_Shader_DebugInfo_100 || |
| 1900 |
ExtSetKind == SPIRVEIS_NonSemantic_Shader_DebugInfo_200) { |
| 1901 |
if (getExtOp() == SPIRVDebug::Instruction::Source) { |
| 1902 |
for (SPIRVEntry *E : Decoder.getSourceContinuedInstructions()) { |
| 1903 |
addContinuedInstruction(static_cast<SPIRVExtInst *>(E)); |
| 1904 |
} |
| 1905 |
} |
| 1906 |
} |
| 1907 |
} |
| 1908 |
void validate() const override { |
| 1909 |
SPIRVFunctionCallGeneric::validate(); |
| 1910 |
validateBuiltin(ExtSetId, ExtOp); |
| 1911 |
} |
| 1912 |
bool isOperandLiteral(unsigned Index) const override { |
| 1913 |
assert(ExtSetKind == SPIRVEIS_OpenCL && |
| 1914 |
"Unsupported extended instruction set"); |
| 1915 |
auto EOC = static_cast<OCLExtOpKind>(ExtOp); |
| 1916 |
switch (EOC) { |
| 1917 |
default: |
| 1918 |
return false; |
| 1919 |
case OpenCLLIB::Vloadn: |
| 1920 |
case OpenCLLIB::Vload_halfn: |
| 1921 |
case OpenCLLIB::Vloada_halfn: |
| 1922 |
return Index == 2; |
| 1923 |
case OpenCLLIB::Vstore_half_r: |
| 1924 |
case OpenCLLIB::Vstore_halfn_r: |
| 1925 |
case OpenCLLIB::Vstorea_halfn_r: |
| 1926 |
return Index == 3; |
| 1927 |
} |
| 1928 |
} |
| 1929 |
std::vector<SPIRVValue *> getArgValues() { |
| 1930 |
std::vector<SPIRVValue *> VArgs; |
| 1931 |
for (size_t I = 0; I < Args.size(); ++I) { |
| 1932 |
if (isOperandLiteral(I)) |
| 1933 |
VArgs.push_back(Module->getLiteralAsConstant(Args[I])); |
| 1934 |
else |
| 1935 |
VArgs.push_back(getValue(Args[I])); |
| 1936 |
} |
| 1937 |
return VArgs; |
| 1938 |
} |
| 1939 |
std::vector<SPIRVType *> getArgTypes() { |
| 1940 |
std::vector<SPIRVType *> ArgTypes; |
| 1941 |
auto VArgs = getArgValues(); |
| 1942 |
for (auto VArg : VArgs) |
| 1943 |
ArgTypes.push_back(VArg->getType()); |
| 1944 |
return ArgTypes; |
| 1945 |
} |
| 1946 |
|
| 1947 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 1948 |
if (SPIRVBuiltinSetNameMap::map(ExtSetKind).find("NonSemantic.") == 0 && |
| 1949 |
!Module->isAllowedToUseVersion(VersionNumber::SPIRV_1_6)) |
| 1950 |
return ExtensionID::SPV_KHR_non_semantic_info; |
| 1951 |
return {}; |
| 1952 |
} |
| 1953 |
|
| 1954 |
protected: |
| 1955 |
SPIRVExtInstSetKind ExtSetKind; |
| 1956 |
SPIRVId ExtSetId; |
| 1957 |
union { |
| 1958 |
SPIRVWord ExtOp; |
| 1959 |
OCLExtOpKind ExtOpOCL; |
| 1960 |
SPIRVDebugExtOpKind ExtOpDebug; |
| 1961 |
NonSemanticAuxDataOpKind ExtOpNonSemanticAuxData; |
| 1962 |
}; |
| 1963 |
std::vector<SPIRVExtInst *> ContinuedInstructions; |
| 1964 |
}; |
| 1965 |
|
| 1966 |
class SPIRVCompositeConstruct : public SPIRVInstruction { |
| 1967 |
public: |
| 1968 |
const static Op OC = OpCompositeConstruct; |
| 1969 |
const static SPIRVWord FixedWordCount = 3; |
| 1970 |
// Complete constructor |
| 1971 |
SPIRVCompositeConstruct(SPIRVType *TheType, SPIRVId TheId, |
| 1972 |
const std::vector<SPIRVId> &TheConstituents, |
| 1973 |
SPIRVBasicBlock *TheBB) |
| 1974 |
: SPIRVInstruction(TheConstituents.size() + FixedWordCount, OC, TheType, |
| 1975 |
TheId, TheBB), |
| 1976 |
Constituents(TheConstituents) { |
| 1977 |
validate(); |
| 1978 |
assert(TheBB && "Invalid BB"); |
| 1979 |
} |
| 1980 |
// Incomplete constructor |
| 1981 |
SPIRVCompositeConstruct() : SPIRVInstruction(OC) {} |
| 1982 |
|
| 1983 |
std::vector<SPIRVValue *> getOperands() override { |
| 1984 |
return getValues(Constituents); |
| 1985 |
} |
| 1986 |
|
| 1987 |
protected: |
| 1988 |
void setWordCount(SPIRVWord TheWordCount) override { |
| 1989 |
SPIRVEntry::setWordCount(TheWordCount); |
| 1990 |
Constituents.resize(TheWordCount - FixedWordCount); |
| 1991 |
} |
| 1992 |
_SPIRV_DEF_ENCDEC3(Type, Id, Constituents) |
| 1993 |
void validate() const override { |
| 1994 |
SPIRVInstruction::validate(); |
| 1995 |
size_t TypeOpCode = this->getType()->getOpCode(); |
| 1996 |
switch (TypeOpCode) { |
| 1997 |
case OpTypeVector: |
| 1998 |
assert(Constituents.size() > 1 && |
| 1999 |
"There must be at least two Constituent operands in vector"); |
| 2000 |
break; |
| 2001 |
case OpTypeArray: |
| 2002 |
case OpTypeStruct: |
| 2003 |
case internal::OpTypeJointMatrixINTEL: |
| 2004 |
case OpTypeCooperativeMatrixKHR: |
| 2005 |
break; |
| 2006 |
default: |
| 2007 |
assert(false && "Invalid type"); |
| 2008 |
} |
| 2009 |
} |
| 2010 |
std::vector<SPIRVId> Constituents; |
| 2011 |
}; |
| 2012 |
|
| 2013 |
class SPIRVCompositeExtractBase : public SPIRVInstTemplateBase { |
| 2014 |
public: |
| 2015 |
SPIRVValue *getComposite() { return getValue(Ops[0]); } |
| 2016 |
const std::vector<SPIRVWord> getIndices() const { |
| 2017 |
return std::vector<SPIRVWord>(Ops.begin() + 1, Ops.end()); |
| 2018 |
} |
| 2019 |
|
| 2020 |
protected: |
| 2021 |
// ToDo: validate the result type is consistent with the base type and indices |
| 2022 |
// need to trace through the base type for struct types |
| 2023 |
void validate() const override { |
| 2024 |
SPIRVInstruction::validate(); |
| 2025 |
assert(OpCode == OpCompositeExtract); |
| 2026 |
SPIRVId Composite = Ops[0]; |
| 2027 |
(void)Composite; |
| 2028 |
assert(getValueType(Composite)->isTypeArray() || |
| 2029 |
getValueType(Composite)->isTypeStruct() || |
| 2030 |
getValueType(Composite)->isTypeVector()); |
| 2031 |
} |
| 2032 |
}; |
| 2033 |
|
| 2034 |
typedef SPIRVInstTemplate<SPIRVCompositeExtractBase, OpCompositeExtract, true, |
| 2035 |
4, true> |
| 2036 |
SPIRVCompositeExtract; |
| 2037 |
|
| 2038 |
class SPIRVCompositeInsertBase : public SPIRVInstTemplateBase { |
| 2039 |
public: |
| 2040 |
SPIRVValue *getObject() { return getValue(Ops[0]); } |
| 2041 |
SPIRVValue *getComposite() { return getValue(Ops[1]); } |
| 2042 |
const std::vector<SPIRVWord> getIndices() const { |
| 2043 |
return std::vector<SPIRVWord>(Ops.begin() + 2, Ops.end()); |
| 2044 |
} |
| 2045 |
|
| 2046 |
protected: |
| 2047 |
// ToDo: validate the object type is consistent with the base type and indices |
| 2048 |
// need to trace through the base type for struct types |
| 2049 |
void validate() const override { |
| 2050 |
SPIRVInstruction::validate(); |
| 2051 |
assert(OpCode == OpCompositeInsert); |
| 2052 |
SPIRVId Composite = Ops[1]; |
| 2053 |
(void)Composite; |
| 2054 |
assert(getValueType(Composite)->isTypeArray() || |
| 2055 |
getValueType(Composite)->isTypeStruct() || |
| 2056 |
getValueType(Composite)->isTypeVector()); |
| 2057 |
assert(Type == getValueType(Composite)); |
| 2058 |
} |
| 2059 |
}; |
| 2060 |
|
| 2061 |
typedef SPIRVInstTemplate<SPIRVCompositeInsertBase, OpCompositeInsert, true, 5, |
| 2062 |
true> |
| 2063 |
SPIRVCompositeInsert; |
| 2064 |
|
| 2065 |
class SPIRVCopyObject : public SPIRVInstruction { |
| 2066 |
public: |
| 2067 |
const static Op OC = OpCopyObject; |
| 2068 |
|
| 2069 |
// Complete constructor |
| 2070 |
SPIRVCopyObject(SPIRVType *TheType, SPIRVId TheId, SPIRVValue *TheOperand, |
| 2071 |
SPIRVBasicBlock *TheBB) |
| 2072 |
: SPIRVInstruction(4, OC, TheType, TheId, TheBB), |
| 2073 |
Operand(TheOperand->getId()) { |
| 2074 |
validate(); |
| 2075 |
assert(TheBB && "Invalid BB"); |
| 2076 |
} |
| 2077 |
// Incomplete constructor |
| 2078 |
SPIRVCopyObject() : SPIRVInstruction(OC), Operand(SPIRVID_INVALID) {} |
| 2079 |
|
| 2080 |
SPIRVValue *getOperand() { return getValue(Operand); } |
| 2081 |
|
| 2082 |
protected: |
| 2083 |
_SPIRV_DEF_ENCDEC3(Type, Id, Operand) |
| 2084 |
|
| 2085 |
void validate() const override { SPIRVInstruction::validate(); } |
| 2086 |
SPIRVId Operand; |
| 2087 |
}; |
| 2088 |
|
| 2089 |
class SPIRVCopyLogical : public SPIRVInstruction { |
| 2090 |
public: |
| 2091 |
const static Op OC = OpCopyLogical; |
| 2092 |
|
| 2093 |
// Complete constructor |
| 2094 |
SPIRVCopyLogical(SPIRVType *TheType, SPIRVId TheId, SPIRVValue *TheOperand, |
| 2095 |
SPIRVBasicBlock *TheBB) |
| 2096 |
: SPIRVInstruction(4, OC, TheType, TheId, TheBB), |
| 2097 |
Operand(TheOperand->getId()) { |
| 2098 |
validate(); |
| 2099 |
assert(TheBB && "Invalid BB"); |
| 2100 |
} |
| 2101 |
// Incomplete constructor |
| 2102 |
SPIRVCopyLogical() : SPIRVInstruction(OC), Operand(SPIRVID_INVALID) {} |
| 2103 |
|
| 2104 |
SPIRVValue *getOperand() { return getValue(Operand); } |
| 2105 |
std::vector<SPIRVValue *> getOperands() override { return {getOperand()}; } |
| 2106 |
|
| 2107 |
protected: |
| 2108 |
_SPIRV_DEF_ENCDEC3(Type, Id, Operand) |
| 2109 |
|
| 2110 |
void validate() const override { SPIRVInstruction::validate(); } |
| 2111 |
SPIRVId Operand; |
| 2112 |
}; |
| 2113 |
|
| 2114 |
class SPIRVCopyMemory : public SPIRVInstruction, public SPIRVMemoryAccess { |
| 2115 |
public: |
| 2116 |
const static Op OC = OpCopyMemory; |
| 2117 |
const static SPIRVWord FixedWords = 3; |
| 2118 |
// Complete constructor |
| 2119 |
SPIRVCopyMemory(SPIRVValue *TheTarget, SPIRVValue *TheSource, |
| 2120 |
const std::vector<SPIRVWord> &TheMemoryAccess, |
| 2121 |
SPIRVBasicBlock *TheBB) |
| 2122 |
: SPIRVInstruction(FixedWords + TheMemoryAccess.size(), OC, TheBB), |
| 2123 |
SPIRVMemoryAccess(TheMemoryAccess), MemoryAccess(TheMemoryAccess), |
| 2124 |
Target(TheTarget->getId()), Source(TheSource->getId()) { |
| 2125 |
validate(); |
| 2126 |
assert(TheBB && "Invalid BB"); |
| 2127 |
} |
| 2128 |
|
| 2129 |
// Incomplete constructor |
| 2130 |
SPIRVCopyMemory() |
| 2131 |
: SPIRVInstruction(OC), SPIRVMemoryAccess(), Target(SPIRVID_INVALID), |
| 2132 |
Source(SPIRVID_INVALID) { |
| 2133 |
setHasNoId(); |
| 2134 |
setHasNoType(); |
| 2135 |
} |
| 2136 |
|
| 2137 |
SPIRVValue *getSource() { return getValue(Source); } |
| 2138 |
SPIRVValue *getTarget() { return getValue(Target); } |
| 2139 |
|
| 2140 |
protected: |
| 2141 |
void setWordCount(SPIRVWord TheWordCount) override { |
| 2142 |
SPIRVEntry::setWordCount(TheWordCount); |
| 2143 |
MemoryAccess.resize(TheWordCount - FixedWords); |
| 2144 |
} |
| 2145 |
|
| 2146 |
void encode(spv_ostream &O) const override { |
| 2147 |
getEncoder(O) << Target << Source << MemoryAccess; |
| 2148 |
} |
| 2149 |
|
| 2150 |
void decode(std::istream &I) override { |
| 2151 |
getDecoder(I) >> Target >> Source >> MemoryAccess; |
| 2152 |
memoryAccessUpdate(MemoryAccess); |
| 2153 |
} |
| 2154 |
|
| 2155 |
void validate() const override { |
| 2156 |
assert(getValueType(Target)->isTypePointer() && "Invalid Target type"); |
| 2157 |
assert(getValueType(Source)->isTypePointer() && "Invalid Source type"); |
| 2158 |
assert(!(getValueType(Target)->getPointerElementType()->isTypeVoid()) && |
| 2159 |
"Invalid Target element type"); |
| 2160 |
assert(!(getValueType(Source)->getPointerElementType()->isTypeVoid()) && |
| 2161 |
"Invalid Source element type"); |
| 2162 |
assert(getValueType(Target)->getPointerElementType() == |
| 2163 |
getValueType(Source)->getPointerElementType() && |
| 2164 |
"Mismatching Target and Source element types"); |
| 2165 |
SPIRVInstruction::validate(); |
| 2166 |
} |
| 2167 |
|
| 2168 |
std::vector<SPIRVWord> MemoryAccess; |
| 2169 |
SPIRVId Target; |
| 2170 |
SPIRVId Source; |
| 2171 |
}; |
| 2172 |
|
| 2173 |
class SPIRVCopyMemorySized : public SPIRVInstruction, public SPIRVMemoryAccess { |
| 2174 |
public: |
| 2175 |
const static Op OC = OpCopyMemorySized; |
| 2176 |
const static SPIRVWord FixedWords = 4; |
| 2177 |
// Complete constructor |
| 2178 |
SPIRVCopyMemorySized(SPIRVValue *TheTarget, SPIRVValue *TheSource, |
| 2179 |
SPIRVValue *TheSize, |
| 2180 |
const std::vector<SPIRVWord> &TheMemoryAccess, |
| 2181 |
SPIRVBasicBlock *TheBB) |
| 2182 |
: SPIRVInstruction(FixedWords + TheMemoryAccess.size(), OC, TheBB), |
| 2183 |
SPIRVMemoryAccess(TheMemoryAccess), MemoryAccess(TheMemoryAccess), |
| 2184 |
Target(TheTarget->getId()), Source(TheSource->getId()), |
| 2185 |
Size(TheSize->getId()) { |
| 2186 |
validate(); |
| 2187 |
assert(TheBB && "Invalid BB"); |
| 2188 |
updateModuleVersion(); |
| 2189 |
} |
| 2190 |
// Incomplete constructor |
| 2191 |
SPIRVCopyMemorySized() |
| 2192 |
: SPIRVInstruction(OC), SPIRVMemoryAccess(), Target(SPIRVID_INVALID), |
| 2193 |
Source(SPIRVID_INVALID), Size(0) { |
| 2194 |
setHasNoId(); |
| 2195 |
setHasNoType(); |
| 2196 |
updateModuleVersion(); |
| 2197 |
} |
| 2198 |
|
| 2199 |
SPIRVWord getRequiredSPIRVVersion() const override { |
| 2200 |
if (getSrcAlignment()) |
| 2201 |
return static_cast<SPIRVWord>(VersionNumber::SPIRV_1_4); |
| 2202 |
return static_cast<SPIRVWord>(VersionNumber::SPIRV_1_0); |
| 2203 |
} |
| 2204 |
|
| 2205 |
SPIRVValue *getSource() { return getValue(Source); } |
| 2206 |
SPIRVValue *getTarget() { return getValue(Target); } |
| 2207 |
SPIRVValue *getSize() { return getValue(Size); } |
| 2208 |
|
| 2209 |
protected: |
| 2210 |
void setWordCount(SPIRVWord TheWordCount) override { |
| 2211 |
SPIRVEntry::setWordCount(TheWordCount); |
| 2212 |
MemoryAccess.resize(TheWordCount - FixedWords); |
| 2213 |
} |
| 2214 |
|
| 2215 |
void encode(spv_ostream &O) const override { |
| 2216 |
getEncoder(O) << Target << Source << Size << MemoryAccess; |
| 2217 |
} |
| 2218 |
|
| 2219 |
void decode(std::istream &I) override { |
| 2220 |
getDecoder(I) >> Target >> Source >> Size >> MemoryAccess; |
| 2221 |
memoryAccessUpdate(MemoryAccess); |
| 2222 |
} |
| 2223 |
|
| 2224 |
void validate() const override { SPIRVInstruction::validate(); } |
| 2225 |
|
| 2226 |
std::vector<SPIRVWord> MemoryAccess; |
| 2227 |
SPIRVId Target; |
| 2228 |
SPIRVId Source; |
| 2229 |
SPIRVId Size; |
| 2230 |
}; |
| 2231 |
|
| 2232 |
class SPIRVVectorExtractDynamic : public SPIRVInstruction { |
| 2233 |
public: |
| 2234 |
const static Op OC = OpVectorExtractDynamic; |
| 2235 |
// Complete constructor |
| 2236 |
SPIRVVectorExtractDynamic(SPIRVId TheId, SPIRVValue *TheVector, |
| 2237 |
SPIRVValue *TheIndex, SPIRVBasicBlock *TheBB) |
| 2238 |
: SPIRVInstruction(5, OC, TheVector->getType()->getVectorComponentType(), |
| 2239 |
TheId, TheBB), |
| 2240 |
VectorId(TheVector->getId()), IndexId(TheIndex->getId()) { |
| 2241 |
validate(); |
| 2242 |
assert(TheBB && "Invalid BB"); |
| 2243 |
} |
| 2244 |
// Incomplete constructor |
| 2245 |
SPIRVVectorExtractDynamic() |
| 2246 |
: SPIRVInstruction(OC), VectorId(SPIRVID_INVALID), |
| 2247 |
IndexId(SPIRVID_INVALID) {} |
| 2248 |
|
| 2249 |
SPIRVValue *getVector() { return getValue(VectorId); } |
| 2250 |
SPIRVValue *getIndex() const { return getValue(IndexId); } |
| 2251 |
std::vector<SPIRVValue *> getOperands() override { |
| 2252 |
return {getVector(), getIndex()}; |
| 2253 |
} |
| 2254 |
|
| 2255 |
protected: |
| 2256 |
_SPIRV_DEF_ENCDEC4(Type, Id, VectorId, IndexId) |
| 2257 |
void validate() const override { |
| 2258 |
SPIRVInstruction::validate(); |
| 2259 |
if (getValue(VectorId)->isForward()) |
| 2260 |
return; |
| 2261 |
assert(getValueType(VectorId)->isTypeVector() || |
| 2262 |
getValueType(VectorId)->isTypeJointMatrixINTEL()); |
| 2263 |
} |
| 2264 |
SPIRVId VectorId; |
| 2265 |
SPIRVId IndexId; |
| 2266 |
}; |
| 2267 |
|
| 2268 |
class SPIRVVectorInsertDynamic : public SPIRVInstruction { |
| 2269 |
public: |
| 2270 |
const static Op OC = OpVectorInsertDynamic; |
| 2271 |
// Complete constructor |
| 2272 |
SPIRVVectorInsertDynamic(SPIRVId TheId, SPIRVValue *TheVector, |
| 2273 |
SPIRVValue *TheComponent, SPIRVValue *TheIndex, |
| 2274 |
SPIRVBasicBlock *TheBB) |
| 2275 |
: SPIRVInstruction(6, OC, TheVector->getType(), TheId, TheBB), |
| 2276 |
VectorId(TheVector->getId()), IndexId(TheIndex->getId()), |
| 2277 |
ComponentId(TheComponent->getId()) { |
| 2278 |
validate(); |
| 2279 |
assert(TheBB && "Invalid BB"); |
| 2280 |
} |
| 2281 |
// Incomplete constructor |
| 2282 |
SPIRVVectorInsertDynamic() |
| 2283 |
: SPIRVInstruction(OC), VectorId(SPIRVID_INVALID), |
| 2284 |
IndexId(SPIRVID_INVALID), ComponentId(SPIRVID_INVALID) {} |
| 2285 |
|
| 2286 |
SPIRVValue *getVector() { return getValue(VectorId); } |
| 2287 |
SPIRVValue *getComponent() { return getValue(ComponentId); } |
| 2288 |
SPIRVValue *getIndex() const { return getValue(IndexId); } |
| 2289 |
std::vector<SPIRVValue *> getOperands() override { |
| 2290 |
return {getVector(), getComponent(), getIndex()}; |
| 2291 |
} |
| 2292 |
|
| 2293 |
protected: |
| 2294 |
_SPIRV_DEF_ENCDEC5(Type, Id, VectorId, ComponentId, IndexId) |
| 2295 |
void validate() const override { |
| 2296 |
SPIRVInstruction::validate(); |
| 2297 |
if (getValue(VectorId)->isForward()) |
| 2298 |
return; |
| 2299 |
assert(getValueType(VectorId)->isTypeVector() || |
| 2300 |
getValueType(VectorId)->isTypeJointMatrixINTEL()); |
| 2301 |
} |
| 2302 |
SPIRVId VectorId; |
| 2303 |
SPIRVId IndexId; |
| 2304 |
SPIRVId ComponentId; |
| 2305 |
}; |
| 2306 |
|
| 2307 |
class SPIRVVectorShuffleBase : public SPIRVInstTemplateBase { |
| 2308 |
public: |
| 2309 |
SPIRVValue *getVector1() { return getValue(Ops[0]); } |
| 2310 |
SPIRVValue *getVector2() { return getValue(Ops[1]); } |
| 2311 |
const std::vector<SPIRVWord> getComponents() const { |
| 2312 |
return std::vector<SPIRVWord>(Ops.begin() + 2, Ops.end()); |
| 2313 |
} |
| 2314 |
|
| 2315 |
protected: |
| 2316 |
void validate() const override { |
| 2317 |
SPIRVInstruction::validate(); |
| 2318 |
[[maybe_unused]] SPIRVId Vector1 = Ops[0]; |
| 2319 |
assert(OpCode == OpVectorShuffle); |
| 2320 |
assert(Type->isTypeVector()); |
| 2321 |
assert(Type->getVectorComponentType() == |
| 2322 |
getValueType(Vector1)->getVectorComponentType()); |
| 2323 |
assert(Ops.size() - 2 == Type->getVectorComponentCount()); |
| 2324 |
} |
| 2325 |
}; |
| 2326 |
|
| 2327 |
typedef SPIRVInstTemplate<SPIRVVectorShuffleBase, OpVectorShuffle, true, 5, |
| 2328 |
true> |
| 2329 |
SPIRVVectorShuffle; |
| 2330 |
|
| 2331 |
class SPIRVControlBarrier : public SPIRVInstruction { |
| 2332 |
public: |
| 2333 |
static const Op OC = OpControlBarrier; |
| 2334 |
// Complete constructor |
| 2335 |
SPIRVControlBarrier(SPIRVValue *TheScope, SPIRVValue *TheMemScope, |
| 2336 |
SPIRVValue *TheMemSema, SPIRVBasicBlock *TheBB) |
| 2337 |
: SPIRVInstruction(4, OC, TheBB), ExecScope(TheScope->getId()), |
| 2338 |
MemScope(TheMemScope->getId()), MemSema(TheMemSema->getId()) { |
| 2339 |
validate(); |
| 2340 |
assert(TheBB && "Invalid BB"); |
| 2341 |
} |
| 2342 |
// Incomplete constructor |
| 2343 |
SPIRVControlBarrier() : SPIRVInstruction(OC), ExecScope(ScopeInvocation) { |
| 2344 |
setHasNoId(); |
| 2345 |
setHasNoType(); |
| 2346 |
} |
| 2347 |
void setWordCount(SPIRVWord TheWordCount) override { |
| 2348 |
SPIRVEntry::setWordCount(TheWordCount); |
| 2349 |
} |
| 2350 |
SPIRVValue *getExecScope() const { return getValue(ExecScope); } |
| 2351 |
SPIRVValue *getMemScope() const { return getValue(MemScope); } |
| 2352 |
SPIRVValue *getMemSemantic() const { return getValue(MemSema); } |
| 2353 |
std::vector<SPIRVValue *> getOperands() override { |
| 2354 |
std::vector<SPIRVId> Operands; |
| 2355 |
Operands.push_back(ExecScope); |
| 2356 |
Operands.push_back(MemScope); |
| 2357 |
Operands.push_back(MemSema); |
| 2358 |
return getValues(Operands); |
| 2359 |
} |
| 2360 |
|
| 2361 |
SPIRVCapVec getRequiredCapability() const override { |
| 2362 |
if (isDeviceBarrier()) { |
| 2363 |
return getVec(internal::CapabilityDeviceBarrierINTEL); |
| 2364 |
} |
| 2365 |
return SPIRVInstruction::getRequiredCapability(); |
| 2366 |
} |
| 2367 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 2368 |
if (isDeviceBarrier()) { |
| 2369 |
return ExtensionID::SPV_INTEL_device_barrier; |
| 2370 |
} |
| 2371 |
return std::nullopt; |
| 2372 |
} |
| 2373 |
|
| 2374 |
protected: |
| 2375 |
_SPIRV_DEF_ENCDEC3(ExecScope, MemScope, MemSema) |
| 2376 |
void validate() const override { |
| 2377 |
assert(OpCode == OC); |
| 2378 |
assert(WordCount == 4); |
| 2379 |
SPIRVInstruction::validate(); |
| 2380 |
} |
| 2381 |
|
| 2382 |
bool isDeviceBarrier() const { |
| 2383 |
if (!getModule()->isAllowedToUseExtension( |
| 2384 |
ExtensionID::SPV_INTEL_device_barrier)) |
| 2385 |
return false; |
| 2386 |
SPIRVValue *ESV = getValue(ExecScope); |
| 2387 |
if (ESV && ESV->getOpCode() == OpConstant) { |
| 2388 |
if (static_cast<SPIRVConstant *>(ESV)->getZExtIntValue() != ScopeDevice) { |
| 2389 |
return false; |
| 2390 |
} |
| 2391 |
} |
| 2392 |
return true; |
| 2393 |
} |
| 2394 |
|
| 2395 |
SPIRVId ExecScope; |
| 2396 |
SPIRVId MemScope = SPIRVID_INVALID; |
| 2397 |
SPIRVId MemSema = SPIRVID_INVALID; |
| 2398 |
}; |
| 2399 |
|
| 2400 |
template <Op OC> class SPIRVLifetime : public SPIRVInstruction { |
| 2401 |
public: |
| 2402 |
// Complete constructor |
| 2403 |
SPIRVLifetime(SPIRVId TheObject, SPIRVWord TheSize, SPIRVBasicBlock *TheBB) |
| 2404 |
: SPIRVInstruction(3, OC, TheBB), Object(TheObject), Size(TheSize) { |
| 2405 |
validate(); |
| 2406 |
assert(TheBB && "Invalid BB"); |
| 2407 |
}; |
| 2408 |
// Incomplete constructor |
| 2409 |
SPIRVLifetime() |
| 2410 |
: SPIRVInstruction(OC), Object(SPIRVID_INVALID), Size(SPIRVWORD_MAX) { |
| 2411 |
setHasNoId(); |
| 2412 |
setHasNoType(); |
| 2413 |
} |
| 2414 |
SPIRVCapVec getRequiredCapability() const override { |
| 2415 |
return getVec(CapabilityKernel); |
| 2416 |
} |
| 2417 |
SPIRVValue *getObject() { return getValue(Object); }; |
| 2418 |
SPIRVWord getSize() { return Size; }; |
| 2419 |
|
| 2420 |
protected: |
| 2421 |
void validate() const override { |
| 2422 |
auto ObjType = getValue(Object)->getType(); |
| 2423 |
// Type must be an OpTypePointer with Storage Class Function. |
| 2424 |
assert(ObjType->isTypePointer() && "Objects type must be a pointer"); |
| 2425 |
assert(static_cast<SPIRVTypePointer *>(ObjType)->getStorageClass() == |
| 2426 |
StorageClassFunction && |
| 2427 |
"Invalid storage class"); |
| 2428 |
// Size must be 0 if Pointer is a pointer to a non-void type or the |
| 2429 |
// Addresses capability is not being used. If Size is non-zero, it is the |
| 2430 |
// number of bytes of memory whose lifetime is starting. Its type must be an |
| 2431 |
// integer type scalar. It is treated as unsigned; if its type has |
| 2432 |
// Signedness of 1, its sign bit cannot be set. |
| 2433 |
if (!(ObjType->getPointerElementType()->isTypeVoid() || |
| 2434 |
// (void *) is i8* in LLVM IR |
| 2435 |
ObjType->getPointerElementType()->isTypeInt(8)) || |
| 2436 |
!Module->hasCapability(CapabilityAddresses)) |
| 2437 |
assert(Size == 0 && "Size must be 0"); |
| 2438 |
} |
| 2439 |
_SPIRV_DEF_ENCDEC2(Object, Size) |
| 2440 |
SPIRVId Object; |
| 2441 |
SPIRVWord Size; |
| 2442 |
}; |
| 2443 |
|
| 2444 |
typedef SPIRVLifetime<OpLifetimeStart> SPIRVLifetimeStart; |
| 2445 |
typedef SPIRVLifetime<OpLifetimeStop> SPIRVLifetimeStop; |
| 2446 |
|
| 2447 |
class SPIRVGroupAsyncCopy : public SPIRVInstruction { |
| 2448 |
public: |
| 2449 |
static const Op OC = OpGroupAsyncCopy; |
| 2450 |
static const SPIRVWord WC = 9; |
| 2451 |
// Complete constructor |
| 2452 |
SPIRVGroupAsyncCopy(SPIRVValue *TheScope, SPIRVId TheId, SPIRVValue *TheDest, |
| 2453 |
SPIRVValue *TheSrc, SPIRVValue *TheNumElems, |
| 2454 |
SPIRVValue *TheStride, SPIRVValue *TheEvent, |
| 2455 |
SPIRVBasicBlock *TheBB) |
| 2456 |
: SPIRVInstruction(WC, OC, TheEvent->getType(), TheId, TheBB), |
| 2457 |
ExecScope(TheScope->getId()), Destination(TheDest->getId()), |
| 2458 |
Source(TheSrc->getId()), NumElements(TheNumElems->getId()), |
| 2459 |
Stride(TheStride->getId()), Event(TheEvent->getId()) { |
| 2460 |
validate(); |
| 2461 |
assert(TheBB && "Invalid BB"); |
| 2462 |
} |
| 2463 |
// Incomplete constructor |
| 2464 |
SPIRVGroupAsyncCopy() |
| 2465 |
: SPIRVInstruction(OC), ExecScope(SPIRVID_INVALID), |
| 2466 |
Destination(SPIRVID_INVALID), Source(SPIRVID_INVALID), |
| 2467 |
NumElements(SPIRVID_INVALID), Stride(SPIRVID_INVALID), |
| 2468 |
Event(SPIRVID_INVALID) {} |
| 2469 |
SPIRVValue *getExecScope() const { return getValue(ExecScope); } |
| 2470 |
SPIRVValue *getDestination() const { return getValue(Destination); } |
| 2471 |
SPIRVValue *getSource() const { return getValue(Source); } |
| 2472 |
SPIRVValue *getNumElements() const { return getValue(NumElements); } |
| 2473 |
SPIRVValue *getStride() const { return getValue(Stride); } |
| 2474 |
SPIRVValue *getEvent() const { return getValue(Event); } |
| 2475 |
std::vector<SPIRVValue *> getOperands() override { |
| 2476 |
std::vector<SPIRVId> Operands; |
| 2477 |
Operands.push_back(ExecScope); |
| 2478 |
Operands.push_back(Destination); |
| 2479 |
Operands.push_back(Source); |
| 2480 |
Operands.push_back(NumElements); |
| 2481 |
Operands.push_back(Stride); |
| 2482 |
Operands.push_back(Event); |
| 2483 |
return getValues(Operands); |
| 2484 |
} |
| 2485 |
|
| 2486 |
protected: |
| 2487 |
_SPIRV_DEF_ENCDEC8(Type, Id, ExecScope, Destination, Source, NumElements, |
| 2488 |
Stride, Event) |
| 2489 |
void validate() const override { |
| 2490 |
assert(OpCode == OC); |
| 2491 |
assert(WordCount == WC); |
| 2492 |
SPIRVInstruction::validate(); |
| 2493 |
} |
| 2494 |
SPIRVId ExecScope; |
| 2495 |
SPIRVId Destination; |
| 2496 |
SPIRVId Source; |
| 2497 |
SPIRVId NumElements; |
| 2498 |
SPIRVId Stride; |
| 2499 |
SPIRVId Event; |
| 2500 |
}; |
| 2501 |
|
| 2502 |
enum SPIRVOpKind { SPIRVOPK_Id, SPIRVOPK_Literal, SPIRVOPK_Count }; |
| 2503 |
|
| 2504 |
class SPIRVDevEnqInstBase : public SPIRVInstTemplateBase { |
| 2505 |
public: |
| 2506 |
SPIRVCapVec getRequiredCapability() const override { |
| 2507 |
return getVec(CapabilityDeviceEnqueue); |
| 2508 |
} |
| 2509 |
}; |
| 2510 |
|
| 2511 |
#define _SPIRV_OP(x, ...) \ |
| 2512 |
typedef SPIRVInstTemplate<SPIRVDevEnqInstBase, Op##x, __VA_ARGS__> SPIRV##x; |
| 2513 |
// CL 2.0 enqueue kernel builtins |
| 2514 |
_SPIRV_OP(EnqueueMarker, true, 7) |
| 2515 |
_SPIRV_OP(EnqueueKernel, true, 13, true) |
| 2516 |
_SPIRV_OP(GetKernelNDrangeSubGroupCount, true, 8) |
| 2517 |
_SPIRV_OP(GetKernelNDrangeMaxSubGroupSize, true, 8) |
| 2518 |
_SPIRV_OP(GetKernelWorkGroupSize, true, 7) |
| 2519 |
_SPIRV_OP(GetKernelPreferredWorkGroupSizeMultiple, true, 7) |
| 2520 |
_SPIRV_OP(RetainEvent, false, 2) |
| 2521 |
_SPIRV_OP(ReleaseEvent, false, 2) |
| 2522 |
_SPIRV_OP(CreateUserEvent, true, 3) |
| 2523 |
_SPIRV_OP(IsValidEvent, true, 4) |
| 2524 |
_SPIRV_OP(SetUserEventStatus, false, 3) |
| 2525 |
_SPIRV_OP(CaptureEventProfilingInfo, false, 4) |
| 2526 |
_SPIRV_OP(GetDefaultQueue, true, 3) |
| 2527 |
_SPIRV_OP(BuildNDRange, true, 6) |
| 2528 |
#undef _SPIRV_OP |
| 2529 |
|
| 2530 |
class SPIRVPipeInstBase : public SPIRVInstTemplateBase { |
| 2531 |
public: |
| 2532 |
SPIRVCapVec getRequiredCapability() const override { |
| 2533 |
return getVec(CapabilityPipes); |
| 2534 |
} |
| 2535 |
}; |
| 2536 |
|
| 2537 |
#define _SPIRV_OP(x, ...) \ |
| 2538 |
typedef SPIRVInstTemplate<SPIRVPipeInstBase, Op##x, __VA_ARGS__> SPIRV##x; |
| 2539 |
// CL 2.0 pipe builtins |
| 2540 |
_SPIRV_OP(ReadPipe, true, 7) |
| 2541 |
_SPIRV_OP(WritePipe, true, 7) |
| 2542 |
_SPIRV_OP(ReservedReadPipe, true, 9) |
| 2543 |
_SPIRV_OP(ReservedWritePipe, true, 9) |
| 2544 |
_SPIRV_OP(ReserveReadPipePackets, true, 7) |
| 2545 |
_SPIRV_OP(ReserveWritePipePackets, true, 7) |
| 2546 |
_SPIRV_OP(CommitReadPipe, false, 5) |
| 2547 |
_SPIRV_OP(CommitWritePipe, false, 5) |
| 2548 |
_SPIRV_OP(IsValidReserveId, true, 4) |
| 2549 |
_SPIRV_OP(GetNumPipePackets, true, 6) |
| 2550 |
_SPIRV_OP(GetMaxPipePackets, true, 6) |
| 2551 |
#undef _SPIRV_OP |
| 2552 |
|
| 2553 |
class SPIRVPipeStorageInstBase : public SPIRVInstTemplateBase { |
| 2554 |
public: |
| 2555 |
SPIRVCapVec getRequiredCapability() const override { |
| 2556 |
return getVec(CapabilityPipeStorage, CapabilityPipes); |
| 2557 |
} |
| 2558 |
}; |
| 2559 |
|
| 2560 |
#define _SPIRV_OP(x, ...) \ |
| 2561 |
typedef SPIRVInstTemplate<SPIRVPipeStorageInstBase, Op##x, __VA_ARGS__> \ |
| 2562 |
SPIRV##x; |
| 2563 |
|
| 2564 |
_SPIRV_OP(CreatePipeFromPipeStorage, true, 4) |
| 2565 |
#undef _SPIRV_OP |
| 2566 |
|
| 2567 |
class SPIRVGroupInstBase : public SPIRVInstTemplateBase { |
| 2568 |
public: |
| 2569 |
SPIRVCapVec getRequiredCapability() const override { |
| 2570 |
return getVec(CapabilityGroups); |
| 2571 |
} |
| 2572 |
}; |
| 2573 |
|
| 2574 |
#define _SPIRV_OP(x, ...) \ |
| 2575 |
typedef SPIRVInstTemplate<SPIRVGroupInstBase, Op##x, __VA_ARGS__> SPIRV##x; |
| 2576 |
// Group instructions. |
| 2577 |
// Even though GroupWaitEvents has Group in its name, it doesn't require the |
| 2578 |
// Group capability |
| 2579 |
typedef SPIRVInstTemplate<SPIRVInstTemplateBase, OpGroupWaitEvents, false, 4> |
| 2580 |
SPIRVGroupWaitEvents; |
| 2581 |
_SPIRV_OP(GroupAll, true, 5) |
| 2582 |
_SPIRV_OP(GroupAny, true, 5) |
| 2583 |
_SPIRV_OP(GroupBroadcast, true, 6) |
| 2584 |
_SPIRV_OP(GroupIAdd, true, 6, false, 1) |
| 2585 |
_SPIRV_OP(GroupFAdd, true, 6, false, 1) |
| 2586 |
_SPIRV_OP(GroupFMin, true, 6, false, 1) |
| 2587 |
_SPIRV_OP(GroupUMin, true, 6, false, 1) |
| 2588 |
_SPIRV_OP(GroupSMin, true, 6, false, 1) |
| 2589 |
_SPIRV_OP(GroupFMax, true, 6, false, 1) |
| 2590 |
_SPIRV_OP(GroupUMax, true, 6, false, 1) |
| 2591 |
_SPIRV_OP(GroupSMax, true, 6, false, 1) |
| 2592 |
_SPIRV_OP(GroupReserveReadPipePackets, true, 8) |
| 2593 |
_SPIRV_OP(GroupReserveWritePipePackets, true, 8) |
| 2594 |
_SPIRV_OP(GroupCommitReadPipe, false, 6) |
| 2595 |
_SPIRV_OP(GroupCommitWritePipe, false, 6) |
| 2596 |
#undef _SPIRV_OP |
| 2597 |
|
| 2598 |
class SPIRVGroupNonUniformElectInst : public SPIRVInstTemplateBase { |
| 2599 |
public: |
| 2600 |
SPIRVCapVec getRequiredCapability() const override { |
| 2601 |
return getVec(CapabilityGroupNonUniform); |
| 2602 |
} |
| 2603 |
}; |
| 2604 |
|
| 2605 |
#define _SPIRV_OP(x, ...) \ |
| 2606 |
typedef SPIRVInstTemplate<SPIRVGroupNonUniformElectInst, Op##x, __VA_ARGS__> \ |
| 2607 |
SPIRV##x; |
| 2608 |
_SPIRV_OP(GroupNonUniformElect, true, 4) |
| 2609 |
#undef _SPIRV_OP |
| 2610 |
|
| 2611 |
class SPIRVGroupNonUniformVoteInst : public SPIRVInstTemplateBase { |
| 2612 |
public: |
| 2613 |
SPIRVCapVec getRequiredCapability() const override { |
| 2614 |
return getVec(CapabilityGroupNonUniformVote); |
| 2615 |
} |
| 2616 |
}; |
| 2617 |
|
| 2618 |
#define _SPIRV_OP(x, ...) \ |
| 2619 |
typedef SPIRVInstTemplate<SPIRVGroupNonUniformVoteInst, Op##x, __VA_ARGS__> \ |
| 2620 |
SPIRV##x; |
| 2621 |
_SPIRV_OP(GroupNonUniformAll, true, 5) |
| 2622 |
_SPIRV_OP(GroupNonUniformAny, true, 5) |
| 2623 |
_SPIRV_OP(GroupNonUniformAllEqual, true, 5) |
| 2624 |
#undef _SPIRV_OP |
| 2625 |
|
| 2626 |
class SPIRVGroupNonUniformBallotInst : public SPIRVInstTemplateBase { |
| 2627 |
public: |
| 2628 |
SPIRVCapVec getRequiredCapability() const override { |
| 2629 |
return getVec(CapabilityGroupNonUniformBallot); |
| 2630 |
} |
| 2631 |
|
| 2632 |
SPIRVWord getRequiredSPIRVVersion() const override { |
| 2633 |
switch (OpCode) { |
| 2634 |
case OpGroupNonUniformBroadcast: { |
| 2635 |
assert(Ops.size() == 3 && "Expecting (Execution, Value, Id) operands"); |
| 2636 |
if (!isConstantOpCode(getOperand(2)->getOpCode())) { |
| 2637 |
// Before version 1.5, Id must come from a constant instruction. |
| 2638 |
return static_cast<SPIRVWord>(VersionNumber::SPIRV_1_5); |
| 2639 |
} |
| 2640 |
break; |
| 2641 |
} |
| 2642 |
default: |
| 2643 |
break; |
| 2644 |
} |
| 2645 |
return static_cast<SPIRVWord>(VersionNumber::SPIRV_1_3); |
| 2646 |
} |
| 2647 |
}; |
| 2648 |
|
| 2649 |
#define _SPIRV_OP(x, ...) \ |
| 2650 |
typedef SPIRVInstTemplate<SPIRVGroupNonUniformBallotInst, Op##x, \ |
| 2651 |
__VA_ARGS__> \ |
| 2652 |
SPIRV##x; |
| 2653 |
_SPIRV_OP(GroupNonUniformBroadcast, true, 6) |
| 2654 |
_SPIRV_OP(GroupNonUniformBroadcastFirst, true, 5) |
| 2655 |
_SPIRV_OP(GroupNonUniformBallot, true, 5) |
| 2656 |
_SPIRV_OP(GroupNonUniformInverseBallot, true, 5) |
| 2657 |
_SPIRV_OP(GroupNonUniformBallotBitExtract, true, 6) |
| 2658 |
_SPIRV_OP(GroupNonUniformBallotBitCount, true, 6, false, 1) |
| 2659 |
_SPIRV_OP(GroupNonUniformBallotFindLSB, true, 5) |
| 2660 |
_SPIRV_OP(GroupNonUniformBallotFindMSB, true, 5) |
| 2661 |
#undef _SPIRV_OP |
| 2662 |
|
| 2663 |
class SPIRVGroupNonUniformArithmeticInst : public SPIRVInstTemplateBase { |
| 2664 |
public: |
| 2665 |
void setOpWords(const std::vector<SPIRVWord> &Ops) override { |
| 2666 |
SPIRVInstTemplateBase::setOpWords(Ops); |
| 2667 |
SPIRVGroupOperationKind GroupOp; |
| 2668 |
if (getSPIRVGroupOperation(GroupOp)) { |
| 2669 |
if (GroupOp == GroupOperationClusteredReduce) |
| 2670 |
Module->addCapability(CapabilityGroupNonUniformClustered); |
| 2671 |
else |
| 2672 |
Module->addCapability(CapabilityGroupNonUniformArithmetic); |
| 2673 |
} else |
| 2674 |
llvm_unreachable( |
| 2675 |
"GroupNonUniformArithmeticInst has no group operation operand!"); |
| 2676 |
} |
| 2677 |
}; |
| 2678 |
|
| 2679 |
#define _SPIRV_OP(x, ...) \ |
| 2680 |
typedef SPIRVInstTemplate<SPIRVGroupNonUniformArithmeticInst, Op##x, \ |
| 2681 |
__VA_ARGS__> \ |
| 2682 |
SPIRV##x; |
| 2683 |
_SPIRV_OP(GroupNonUniformIAdd, true, 6, true, 1) |
| 2684 |
_SPIRV_OP(GroupNonUniformFAdd, true, 6, true, 1) |
| 2685 |
_SPIRV_OP(GroupNonUniformIMul, true, 6, true, 1) |
| 2686 |
_SPIRV_OP(GroupNonUniformFMul, true, 6, true, 1) |
| 2687 |
_SPIRV_OP(GroupNonUniformSMin, true, 6, true, 1) |
| 2688 |
_SPIRV_OP(GroupNonUniformUMin, true, 6, true, 1) |
| 2689 |
_SPIRV_OP(GroupNonUniformFMin, true, 6, true, 1) |
| 2690 |
_SPIRV_OP(GroupNonUniformSMax, true, 6, true, 1) |
| 2691 |
_SPIRV_OP(GroupNonUniformUMax, true, 6, true, 1) |
| 2692 |
_SPIRV_OP(GroupNonUniformFMax, true, 6, true, 1) |
| 2693 |
_SPIRV_OP(GroupNonUniformBitwiseAnd, true, 6, true, 1) |
| 2694 |
_SPIRV_OP(GroupNonUniformBitwiseOr, true, 6, true, 1) |
| 2695 |
_SPIRV_OP(GroupNonUniformBitwiseXor, true, 6, true, 1) |
| 2696 |
_SPIRV_OP(GroupNonUniformLogicalAnd, true, 6, true, 1) |
| 2697 |
_SPIRV_OP(GroupNonUniformLogicalOr, true, 6, true, 1) |
| 2698 |
_SPIRV_OP(GroupNonUniformLogicalXor, true, 6, true, 1) |
| 2699 |
#undef _SPIRV_OP |
| 2700 |
|
| 2701 |
class SPIRVGroupNonUniformShuffleInst : public SPIRVInstTemplateBase { |
| 2702 |
public: |
| 2703 |
SPIRVCapVec getRequiredCapability() const override { |
| 2704 |
return getVec(CapabilityGroupNonUniformShuffle); |
| 2705 |
} |
| 2706 |
}; |
| 2707 |
|
| 2708 |
#define _SPIRV_OP(x, ...) \ |
| 2709 |
typedef SPIRVInstTemplate<SPIRVGroupNonUniformShuffleInst, Op##x, \ |
| 2710 |
__VA_ARGS__> \ |
| 2711 |
SPIRV##x; |
| 2712 |
_SPIRV_OP(GroupNonUniformShuffle, true, 6) |
| 2713 |
_SPIRV_OP(GroupNonUniformShuffleXor, true, 6) |
| 2714 |
#undef _SPIRV_OP |
| 2715 |
|
| 2716 |
class SPIRVGroupNonUniformShuffleRelativeInst : public SPIRVInstTemplateBase { |
| 2717 |
public: |
| 2718 |
SPIRVCapVec getRequiredCapability() const override { |
| 2719 |
return getVec(CapabilityGroupNonUniformShuffleRelative); |
| 2720 |
} |
| 2721 |
}; |
| 2722 |
|
| 2723 |
#define _SPIRV_OP(x, ...) \ |
| 2724 |
typedef SPIRVInstTemplate<SPIRVGroupNonUniformShuffleRelativeInst, Op##x, \ |
| 2725 |
__VA_ARGS__> \ |
| 2726 |
SPIRV##x; |
| 2727 |
_SPIRV_OP(GroupNonUniformShuffleUp, true, 6) |
| 2728 |
_SPIRV_OP(GroupNonUniformShuffleDown, true, 6) |
| 2729 |
#undef _SPIRV_OP |
| 2730 |
|
| 2731 |
class SPIRVGroupNonUniformRotateKHRInst : public SPIRVInstTemplateBase { |
| 2732 |
public: |
| 2733 |
SPIRVCapVec getRequiredCapability() const override { |
| 2734 |
return getVec(CapabilityGroupNonUniformRotateKHR); |
| 2735 |
} |
| 2736 |
|
| 2737 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 2738 |
return ExtensionID::SPV_KHR_subgroup_rotate; |
| 2739 |
} |
| 2740 |
}; |
| 2741 |
|
| 2742 |
#define _SPIRV_OP(x, ...) \ |
| 2743 |
typedef SPIRVInstTemplate<SPIRVGroupNonUniformRotateKHRInst, Op##x, \ |
| 2744 |
__VA_ARGS__> \ |
| 2745 |
SPIRV##x; |
| 2746 |
_SPIRV_OP(GroupNonUniformRotateKHR, true, 6, true) |
| 2747 |
#undef _SPIRV_OP |
| 2748 |
|
| 2749 |
class SPIRVBlockingPipesIntelInst : public SPIRVInstTemplateBase { |
| 2750 |
protected: |
| 2751 |
SPIRVCapVec getRequiredCapability() const override { |
| 2752 |
return getVec(CapabilityBlockingPipesINTEL); |
| 2753 |
} |
| 2754 |
|
| 2755 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 2756 |
return ExtensionID::SPV_INTEL_blocking_pipes; |
| 2757 |
} |
| 2758 |
}; |
| 2759 |
|
| 2760 |
#define _SPIRV_OP(x, ...) \ |
| 2761 |
typedef SPIRVInstTemplate<SPIRVBlockingPipesIntelInst, Op##x, __VA_ARGS__> \ |
| 2762 |
SPIRV##x; |
| 2763 |
_SPIRV_OP(ReadPipeBlockingINTEL, false, 5) |
| 2764 |
_SPIRV_OP(WritePipeBlockingINTEL, false, 5) |
| 2765 |
#undef _SPIRV_OP |
| 2766 |
|
| 2767 |
class SPIRVFixedPointIntelInst : public SPIRVInstTemplateBase { |
| 2768 |
protected: |
| 2769 |
SPIRVCapVec getRequiredCapability() const override { |
| 2770 |
return getVec(CapabilityArbitraryPrecisionFixedPointINTEL); |
| 2771 |
} |
| 2772 |
|
| 2773 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 2774 |
return ExtensionID::SPV_INTEL_arbitrary_precision_fixed_point; |
| 2775 |
} |
| 2776 |
}; |
| 2777 |
|
| 2778 |
#define _SPIRV_OP(x, ...) \ |
| 2779 |
typedef SPIRVInstTemplate<SPIRVFixedPointIntelInst, Op##x, __VA_ARGS__> \ |
| 2780 |
SPIRV##x; |
| 2781 |
_SPIRV_OP(FixedSqrtINTEL, true, 9) |
| 2782 |
_SPIRV_OP(FixedRecipINTEL, true, 9) |
| 2783 |
_SPIRV_OP(FixedRsqrtINTEL, true, 9) |
| 2784 |
_SPIRV_OP(FixedSinINTEL, true, 9) |
| 2785 |
_SPIRV_OP(FixedCosINTEL, true, 9) |
| 2786 |
_SPIRV_OP(FixedSinCosINTEL, true, 9) |
| 2787 |
_SPIRV_OP(FixedSinPiINTEL, true, 9) |
| 2788 |
_SPIRV_OP(FixedCosPiINTEL, true, 9) |
| 2789 |
_SPIRV_OP(FixedSinCosPiINTEL, true, 9) |
| 2790 |
_SPIRV_OP(FixedLogINTEL, true, 9) |
| 2791 |
_SPIRV_OP(FixedExpINTEL, true, 9) |
| 2792 |
#undef _SPIRV_OP |
| 2793 |
|
| 2794 |
class SPIRVArbFloatIntelInst : public SPIRVInstTemplateBase { |
| 2795 |
protected: |
| 2796 |
SPIRVCapVec getRequiredCapability() const override { |
| 2797 |
return getVec(CapabilityArbitraryPrecisionFloatingPointINTEL); |
| 2798 |
} |
| 2799 |
|
| 2800 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 2801 |
return ExtensionID::SPV_INTEL_arbitrary_precision_floating_point; |
| 2802 |
} |
| 2803 |
}; |
| 2804 |
|
| 2805 |
#define _SPIRV_OP(x, ...) \ |
| 2806 |
typedef SPIRVInstTemplate<SPIRVArbFloatIntelInst, \ |
| 2807 |
OpArbitraryFloat##x##INTEL, __VA_ARGS__> \ |
| 2808 |
SPIRVArbitraryFloat##x##INTEL; |
| 2809 |
_SPIRV_OP(Cast, true, 9) |
| 2810 |
_SPIRV_OP(CastFromInt, true, 9) |
| 2811 |
_SPIRV_OP(CastToInt, true, 9) |
| 2812 |
_SPIRV_OP(Add, true, 11) |
| 2813 |
_SPIRV_OP(Sub, true, 11) |
| 2814 |
_SPIRV_OP(Mul, true, 11) |
| 2815 |
_SPIRV_OP(Div, true, 11) |
| 2816 |
_SPIRV_OP(GT, true, 7) |
| 2817 |
_SPIRV_OP(GE, true, 7) |
| 2818 |
_SPIRV_OP(LT, true, 7) |
| 2819 |
_SPIRV_OP(LE, true, 7) |
| 2820 |
_SPIRV_OP(EQ, true, 7) |
| 2821 |
_SPIRV_OP(Recip, true, 9) |
| 2822 |
_SPIRV_OP(RSqrt, true, 9) |
| 2823 |
_SPIRV_OP(Cbrt, true, 9) |
| 2824 |
_SPIRV_OP(Hypot, true, 11) |
| 2825 |
_SPIRV_OP(Sqrt, true, 9) |
| 2826 |
_SPIRV_OP(Log, true, 9) |
| 2827 |
_SPIRV_OP(Log2, true, 9) |
| 2828 |
_SPIRV_OP(Log10, true, 9) |
| 2829 |
_SPIRV_OP(Log1p, true, 9) |
| 2830 |
_SPIRV_OP(Exp, true, 9) |
| 2831 |
_SPIRV_OP(Exp2, true, 9) |
| 2832 |
_SPIRV_OP(Exp10, true, 9) |
| 2833 |
_SPIRV_OP(Expm1, true, 9) |
| 2834 |
_SPIRV_OP(Sin, true, 9) |
| 2835 |
_SPIRV_OP(Cos, true, 9) |
| 2836 |
_SPIRV_OP(SinCos, true, 9) |
| 2837 |
_SPIRV_OP(SinPi, true, 9) |
| 2838 |
_SPIRV_OP(CosPi, true, 9) |
| 2839 |
_SPIRV_OP(SinCosPi, true, 9) |
| 2840 |
_SPIRV_OP(ASin, true, 9) |
| 2841 |
_SPIRV_OP(ASinPi, true, 9) |
| 2842 |
_SPIRV_OP(ACos, true, 9) |
| 2843 |
_SPIRV_OP(ACosPi, true, 9) |
| 2844 |
_SPIRV_OP(ATan, true, 9) |
| 2845 |
_SPIRV_OP(ATanPi, true, 9) |
| 2846 |
_SPIRV_OP(ATan2, true, 11) |
| 2847 |
_SPIRV_OP(Pow, true, 11) |
| 2848 |
_SPIRV_OP(PowR, true, 11) |
| 2849 |
_SPIRV_OP(PowN, true, 11) |
| 2850 |
#undef _SPIRV_OP |
| 2851 |
|
| 2852 |
class SPIRVAtomicInstBase : public SPIRVInstTemplateBase { |
| 2853 |
public: |
| 2854 |
SPIRVCapVec getRequiredCapability() const override { |
| 2855 |
// Most of the atomic instructions require a specific capability when |
| 2856 |
// operating on 64-bit integers. |
| 2857 |
// In SPIRV 1.2 spec, only 2 atomic instructions have no result type: |
| 2858 |
// 1. OpAtomicStore - need to check type of the Value operand |
| 2859 |
// 2. OpAtomicFlagClear - doesn't require Int64Atomics capability. |
| 2860 |
// Besides, OpAtomicCompareExchangeWeak, OpAtomicFlagTestAndSet and |
| 2861 |
// OpAtomicFlagClear instructions require the "kernel" capability. But this |
| 2862 |
// capability should be added by setting the OpenCL memory model. |
| 2863 |
if (hasType()) { |
| 2864 |
if (getType()->isTypeInt(64)) |
| 2865 |
return {CapabilityInt64Atomics}; |
| 2866 |
if (getType()->isTypeInt(16) && |
| 2867 |
Module->isAllowedToUseExtension( |
| 2868 |
ExtensionID::SPV_INTEL_16bit_atomics)) { |
| 2869 |
Module->addExtension(ExtensionID::SPV_INTEL_16bit_atomics); |
| 2870 |
return {internal::CapabilityInt16AtomicsINTEL}; |
| 2871 |
} |
| 2872 |
} |
| 2873 |
return {}; |
| 2874 |
} |
| 2875 |
|
| 2876 |
// Overriding the following method because of particular OpAtomic* |
| 2877 |
// instructions that declare additional capabilities, e.g. based on operand |
| 2878 |
// types. |
| 2879 |
void setOpWords(const std::vector<SPIRVWord> &TheOps) override { |
| 2880 |
SPIRVInstTemplateBase::setOpWords(TheOps); |
| 2881 |
for (auto RC : getRequiredCapability()) |
| 2882 |
Module->addCapability(RC); |
| 2883 |
} |
| 2884 |
}; |
| 2885 |
|
| 2886 |
// This specialization will handle smaller set of compare-and-swap instructions |
| 2887 |
// that require only one capability. The instructions are: OpAtomicLoad, |
| 2888 |
// OpAtomicStore, OpAtomicExchange, OpAtomicCompareExchange and |
| 2889 |
// OpAtomicCompareExchangeWeak. |
| 2890 |
class SPIRVAtomicCompareExchangeInstructions : public SPIRVAtomicInstBase { |
| 2891 |
public: |
| 2892 |
SPIRVCapVec getRequiredCapability() const override { |
| 2893 |
if (hasType() && getType()->isTypeInt(16) && |
| 2894 |
this->getModule()->isAllowedToUseExtension( |
| 2895 |
ExtensionID::SPV_INTEL_16bit_atomics)) { |
| 2896 |
Module->addExtension(ExtensionID::SPV_INTEL_16bit_atomics); |
| 2897 |
return {internal::CapabilityAtomicInt16CompareExchangeINTEL}; |
| 2898 |
} |
| 2899 |
return SPIRVAtomicInstBase::getRequiredCapability(); |
| 2900 |
} |
| 2901 |
}; |
| 2902 |
|
| 2903 |
class SPIRVAtomicStoreInst : public SPIRVAtomicCompareExchangeInstructions { |
| 2904 |
public: |
| 2905 |
// Overriding the following method because of 'const'-related |
| 2906 |
// issues with overriding getRequiredCapability(). TODO: Resolve. |
| 2907 |
void setOpWords(const std::vector<SPIRVWord> &TheOps) override { |
| 2908 |
SPIRVInstTemplateBase::setOpWords(TheOps); |
| 2909 |
static const unsigned ValueOperandIndex = 3; |
| 2910 |
if (getOperand(ValueOperandIndex)->getType()->isTypeInt(64)) |
| 2911 |
Module->addCapability(CapabilityInt64Atomics); |
| 2912 |
} |
| 2913 |
}; |
| 2914 |
|
| 2915 |
class SPIRVAtomicFAddEXTInst : public SPIRVAtomicInstBase { |
| 2916 |
public: |
| 2917 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 2918 |
assert(hasType()); |
| 2919 |
if (getType()->isTypeFloat(16, FPEncodingBFloat16KHR)) |
| 2920 |
Module->addExtension(ExtensionID::SPV_INTEL_16bit_atomics); |
| 2921 |
if (getType()->isTypeFloat(16)) |
| 2922 |
return ExtensionID::SPV_EXT_shader_atomic_float16_add; |
| 2923 |
return ExtensionID::SPV_EXT_shader_atomic_float_add; |
| 2924 |
} |
| 2925 |
|
| 2926 |
SPIRVCapVec getRequiredCapability() const override { |
| 2927 |
assert(hasType()); |
| 2928 |
if (getType()->isTypeFloat(16, FPEncodingBFloat16KHR)) |
| 2929 |
return {internal::CapabilityAtomicBFloat16AddINTEL}; |
| 2930 |
if (getType()->isTypeFloat(16)) |
| 2931 |
return {CapabilityAtomicFloat16AddEXT}; |
| 2932 |
if (getType()->isTypeFloat(32)) |
| 2933 |
return {CapabilityAtomicFloat32AddEXT}; |
| 2934 |
if (getType()->isTypeFloat(64)) |
| 2935 |
return {CapabilityAtomicFloat64AddEXT}; |
| 2936 |
llvm_unreachable( |
| 2937 |
"AtomicFAddEXT can only be generated for bf16, f16, f32, f64 types"); |
| 2938 |
} |
| 2939 |
}; |
| 2940 |
|
| 2941 |
class SPIRVAtomicFMinMaxEXTBase : public SPIRVAtomicInstBase { |
| 2942 |
public: |
| 2943 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 2944 |
if (getType()->isTypeFloat(16, FPEncodingBFloat16KHR)) |
| 2945 |
Module->addExtension(ExtensionID::SPV_INTEL_16bit_atomics); |
| 2946 |
return ExtensionID::SPV_EXT_shader_atomic_float_min_max; |
| 2947 |
} |
| 2948 |
|
| 2949 |
SPIRVCapVec getRequiredCapability() const override { |
| 2950 |
assert(hasType()); |
| 2951 |
if (getType()->isTypeFloat(16, FPEncodingBFloat16KHR)) |
| 2952 |
return {internal::CapabilityAtomicBFloat16MinMaxINTEL}; |
| 2953 |
if (getType()->isTypeFloat(16)) |
| 2954 |
return {CapabilityAtomicFloat16MinMaxEXT}; |
| 2955 |
if (getType()->isTypeFloat(32)) |
| 2956 |
return {CapabilityAtomicFloat32MinMaxEXT}; |
| 2957 |
if (getType()->isTypeFloat(64)) |
| 2958 |
return {CapabilityAtomicFloat64MinMaxEXT}; |
| 2959 |
llvm_unreachable("AtomicF(Min|Max)EXT can only be generated for bf16, f16, " |
| 2960 |
"f32, f64 types"); |
| 2961 |
} |
| 2962 |
}; |
| 2963 |
|
| 2964 |
#define _SPIRV_OP(x, ...) \ |
| 2965 |
typedef SPIRVInstTemplate<SPIRVAtomicInstBase, Op##x, __VA_ARGS__> SPIRV##x; |
| 2966 |
// Atomic builtins |
| 2967 |
_SPIRV_OP(AtomicFlagTestAndSet, true, 6) |
| 2968 |
_SPIRV_OP(AtomicFlagClear, false, 4) |
| 2969 |
_SPIRV_OP(AtomicIIncrement, true, 6) |
| 2970 |
_SPIRV_OP(AtomicIDecrement, true, 6) |
| 2971 |
_SPIRV_OP(AtomicIAdd, true, 7) |
| 2972 |
_SPIRV_OP(AtomicISub, true, 7) |
| 2973 |
_SPIRV_OP(AtomicUMin, true, 7) |
| 2974 |
_SPIRV_OP(AtomicUMax, true, 7) |
| 2975 |
_SPIRV_OP(AtomicSMin, true, 7) |
| 2976 |
_SPIRV_OP(AtomicSMax, true, 7) |
| 2977 |
_SPIRV_OP(AtomicAnd, true, 7) |
| 2978 |
_SPIRV_OP(AtomicOr, true, 7) |
| 2979 |
_SPIRV_OP(AtomicXor, true, 7) |
| 2980 |
_SPIRV_OP(MemoryBarrier, false, 3) |
| 2981 |
#undef _SPIRV_OP |
| 2982 |
#define _SPIRV_OP(x, BaseClass, ...) \ |
| 2983 |
typedef SPIRVInstTemplate<SPIRV##BaseClass, Op##x, __VA_ARGS__> SPIRV##x; |
| 2984 |
// Specialized atomic builtins |
| 2985 |
_SPIRV_OP(AtomicLoad, AtomicCompareExchangeInstructions, true, 6) |
| 2986 |
_SPIRV_OP(AtomicStore, AtomicStoreInst, false, 5) |
| 2987 |
_SPIRV_OP(AtomicExchange, AtomicCompareExchangeInstructions, true, 7) |
| 2988 |
_SPIRV_OP(AtomicCompareExchange, AtomicCompareExchangeInstructions, true, 9) |
| 2989 |
_SPIRV_OP(AtomicCompareExchangeWeak, AtomicCompareExchangeInstructions, true, 9) |
| 2990 |
_SPIRV_OP(AtomicFAddEXT, AtomicFAddEXTInst, true, 7) |
| 2991 |
_SPIRV_OP(AtomicFMinEXT, AtomicFMinMaxEXTBase, true, 7) |
| 2992 |
_SPIRV_OP(AtomicFMaxEXT, AtomicFMinMaxEXTBase, true, 7) |
| 2993 |
#undef _SPIRV_OP |
| 2994 |
|
| 2995 |
class SPIRVImageInstBase : public SPIRVInstTemplateBase { |
| 2996 |
public: |
| 2997 |
SPIRVCapVec getRequiredCapability() const override { |
| 2998 |
return getVec(CapabilityImageBasic); |
| 2999 |
} |
| 3000 |
|
| 3001 |
protected: |
| 3002 |
void setOpWords(const std::vector<SPIRVWord> &OpsArg) override; |
| 3003 |
}; |
| 3004 |
|
| 3005 |
#define _SPIRV_OP(x, ...) \ |
| 3006 |
typedef SPIRVInstTemplate<SPIRVImageInstBase, Op##x, __VA_ARGS__> SPIRV##x; |
| 3007 |
// Image instructions |
| 3008 |
_SPIRV_OP(SampledImage, true, 5) |
| 3009 |
_SPIRV_OP(ImageSampleImplicitLod, true, 5, true) |
| 3010 |
_SPIRV_OP(ImageSampleExplicitLod, true, 7, true, 2) |
| 3011 |
_SPIRV_OP(ImageRead, true, 5, true, 2) |
| 3012 |
_SPIRV_OP(ImageWrite, false, 4, true, 3) |
| 3013 |
_SPIRV_OP(ImageQueryFormat, true, 4) |
| 3014 |
_SPIRV_OP(ImageQueryOrder, true, 4) |
| 3015 |
_SPIRV_OP(ImageQuerySizeLod, true, 5) |
| 3016 |
_SPIRV_OP(ImageQuerySize, true, 4) |
| 3017 |
_SPIRV_OP(ImageQueryLod, true, 5) |
| 3018 |
_SPIRV_OP(ImageQueryLevels, true, 4) |
| 3019 |
_SPIRV_OP(ImageQuerySamples, true, 4) |
| 3020 |
#undef _SPIRV_OP |
| 3021 |
|
| 3022 |
#define _SPIRV_OP(x, ...) \ |
| 3023 |
typedef SPIRVInstTemplate<SPIRVInstTemplateBase, Op##x, __VA_ARGS__> SPIRV##x; |
| 3024 |
// Other instructions |
| 3025 |
_SPIRV_OP(GenericPtrMemSemantics, true, 4, false) |
| 3026 |
_SPIRV_OP(GenericCastToPtrExplicit, true, 5, false, 1) |
| 3027 |
#undef _SPIRV_OP |
| 3028 |
|
| 3029 |
class SPIRVSpecConstantOpBase : public SPIRVInstTemplateBase { |
| 3030 |
public: |
| 3031 |
bool isOperandLiteral(unsigned I) const override { |
| 3032 |
// If SpecConstant results from CompositeExtract/Insert operation, then all |
| 3033 |
// operands are expected to be literals. |
| 3034 |
switch (Ops[0]) { // Opcode of underlying SpecConstant operation |
| 3035 |
case OpCompositeExtract: |
| 3036 |
case OpCompositeInsert: |
| 3037 |
return true; |
| 3038 |
default: |
| 3039 |
return SPIRVInstTemplateBase::isOperandLiteral(I); |
| 3040 |
} |
| 3041 |
} |
| 3042 |
}; |
| 3043 |
|
| 3044 |
typedef SPIRVInstTemplate<SPIRVSpecConstantOpBase, OpSpecConstantOp, true, 4, |
| 3045 |
true, 0> |
| 3046 |
SPIRVSpecConstantOp; |
| 3047 |
|
| 3048 |
class SPIRVAssumeTrueKHR : public SPIRVInstruction { |
| 3049 |
public: |
| 3050 |
static const Op OC = OpAssumeTrueKHR; |
| 3051 |
static const SPIRVWord FixedWordCount = 2; |
| 3052 |
|
| 3053 |
SPIRVAssumeTrueKHR(SPIRVId TheCondition, SPIRVBasicBlock *BB) |
| 3054 |
: SPIRVInstruction(FixedWordCount, OC, BB), ConditionId(TheCondition) { |
| 3055 |
validate(); |
| 3056 |
setHasNoId(); |
| 3057 |
setHasNoType(); |
| 3058 |
assert(BB && "Invalid BB"); |
| 3059 |
} |
| 3060 |
|
| 3061 |
SPIRVAssumeTrueKHR() : SPIRVInstruction(OC), ConditionId(SPIRVID_MAX) { |
| 3062 |
setHasNoId(); |
| 3063 |
setHasNoType(); |
| 3064 |
} |
| 3065 |
|
| 3066 |
SPIRVCapVec getRequiredCapability() const override { |
| 3067 |
return getVec(CapabilityExpectAssumeKHR); |
| 3068 |
} |
| 3069 |
|
| 3070 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3071 |
return ExtensionID::SPV_KHR_expect_assume; |
| 3072 |
} |
| 3073 |
|
| 3074 |
SPIRVValue *getCondition() const { return getValue(ConditionId); } |
| 3075 |
|
| 3076 |
void setWordCount(SPIRVWord TheWordCount) override { |
| 3077 |
SPIRVEntry::setWordCount(TheWordCount); |
| 3078 |
} |
| 3079 |
_SPIRV_DEF_ENCDEC1(ConditionId) |
| 3080 |
|
| 3081 |
protected: |
| 3082 |
SPIRVId ConditionId; |
| 3083 |
}; |
| 3084 |
|
| 3085 |
class SPIRVExpectKHRInstBase : public SPIRVInstTemplateBase { |
| 3086 |
protected: |
| 3087 |
SPIRVCapVec getRequiredCapability() const override { |
| 3088 |
return getVec(CapabilityExpectAssumeKHR); |
| 3089 |
} |
| 3090 |
|
| 3091 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3092 |
return ExtensionID::SPV_KHR_expect_assume; |
| 3093 |
} |
| 3094 |
}; |
| 3095 |
|
| 3096 |
#define _SPIRV_OP(x, ...) \ |
| 3097 |
typedef SPIRVInstTemplate<SPIRVExpectKHRInstBase, Op##x, __VA_ARGS__> \ |
| 3098 |
SPIRV##x; |
| 3099 |
_SPIRV_OP(ExpectKHR, true, 5) |
| 3100 |
#undef _SPIRV_OP |
| 3101 |
|
| 3102 |
class SPIRVDotKHRBase : public SPIRVInstTemplateBase { |
| 3103 |
protected: |
| 3104 |
SPIRVCapVec getRequiredCapability() const override { |
| 3105 |
// Both vector operands must have the same type, so analyzing the |
| 3106 |
// first operand will suffice. |
| 3107 |
SPIRVCapabilityKind ArgCap = getRequiredCapabilityForOperand(Ops[0]); |
| 3108 |
return getVec(ArgCap, CapabilityDotProductKHR); |
| 3109 |
} |
| 3110 |
|
| 3111 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3112 |
if (!Module->isAllowedToUseVersion(VersionNumber::SPIRV_1_6)) |
| 3113 |
return ExtensionID::SPV_KHR_integer_dot_product; |
| 3114 |
return {}; |
| 3115 |
} |
| 3116 |
|
| 3117 |
void validate() const override { |
| 3118 |
SPIRVInstruction::validate(); |
| 3119 |
SPIRVId Vec1 = Ops[0]; |
| 3120 |
SPIRVId Vec2 = Ops[1]; |
| 3121 |
(void)Vec1; |
| 3122 |
(void)Vec2; |
| 3123 |
|
| 3124 |
assert(getValueType(Vec1) == getValueType(Vec2) && |
| 3125 |
"Input vectors must have the same type"); |
| 3126 |
assert(getType()->isTypeInt() && "Result type must be an integer type"); |
| 3127 |
assert(!getType()->isTypeVector() && "Result type must be scalar"); |
| 3128 |
} |
| 3129 |
|
| 3130 |
private: |
| 3131 |
bool isAccSat() const { |
| 3132 |
return (OpCode == OpSDotAccSatKHR || OpCode == OpUDotAccSatKHR || |
| 3133 |
OpCode == OpSUDotAccSatKHR); |
| 3134 |
} |
| 3135 |
|
| 3136 |
std::optional<PackedVectorFormat> getPackedVectorFormat() const { |
| 3137 |
size_t PackFmtIdx = 2; |
| 3138 |
if (isAccSat()) { |
| 3139 |
// AccSat instructions have an additional Accumulator operand. |
| 3140 |
PackFmtIdx++; |
| 3141 |
} |
| 3142 |
|
| 3143 |
if (PackFmtIdx == Ops.size() - 1) |
| 3144 |
return static_cast<PackedVectorFormat>(Ops[PackFmtIdx]); |
| 3145 |
|
| 3146 |
return std::nullopt; |
| 3147 |
} |
| 3148 |
|
| 3149 |
SPIRVCapabilityKind getRequiredCapabilityForOperand(SPIRVId ArgId) const { |
| 3150 |
const SPIRVType *T = getValueType(ArgId); |
| 3151 |
if (auto PackFmt = getPackedVectorFormat()) { |
| 3152 |
switch (*PackFmt) { |
| 3153 |
case PackedVectorFormatPackedVectorFormat4x8BitKHR: |
| 3154 |
assert(!T->isTypeVector() && T->isTypeInt() && T->getBitWidth() == 32 && |
| 3155 |
"Type does not match pack format"); |
| 3156 |
return CapabilityDotProductInput4x8BitPackedKHR; |
| 3157 |
case PackedVectorFormatMax: |
| 3158 |
break; |
| 3159 |
} |
| 3160 |
llvm_unreachable("Unknown Packed Vector Format"); |
| 3161 |
} |
| 3162 |
|
| 3163 |
if (T->isTypeVector()) { |
| 3164 |
const SPIRVType *EltT = T->getVectorComponentType(); |
| 3165 |
if (T->getVectorComponentCount() == 4 && EltT->isTypeInt() && |
| 3166 |
EltT->getBitWidth() == 8) |
| 3167 |
return CapabilityDotProductInput4x8BitKHR; |
| 3168 |
if (EltT->isTypeInt()) |
| 3169 |
return CapabilityDotProductInputAllKHR; |
| 3170 |
} |
| 3171 |
|
| 3172 |
llvm_unreachable("No mapping for argument type to capability."); |
| 3173 |
} |
| 3174 |
|
| 3175 |
SPIRVWord getRequiredSPIRVVersion() const override { |
| 3176 |
if (Module->isAllowedToUseVersion(VersionNumber::SPIRV_1_6)) |
| 3177 |
return static_cast<SPIRVWord>(VersionNumber::SPIRV_1_6); |
| 3178 |
return static_cast<SPIRVWord>(VersionNumber::SPIRV_1_0); |
| 3179 |
} |
| 3180 |
}; |
| 3181 |
|
| 3182 |
#define _SPIRV_OP(x, ...) \ |
| 3183 |
typedef SPIRVInstTemplate<SPIRVDotKHRBase, Op##x, __VA_ARGS__> SPIRV##x; |
| 3184 |
_SPIRV_OP(SDotKHR, true, 5, true, 2) |
| 3185 |
_SPIRV_OP(UDotKHR, true, 5, true, 2) |
| 3186 |
_SPIRV_OP(SUDotKHR, true, 5, true, 2) |
| 3187 |
_SPIRV_OP(SDotAccSatKHR, true, 6, true, 3) |
| 3188 |
_SPIRV_OP(UDotAccSatKHR, true, 6, true, 3) |
| 3189 |
_SPIRV_OP(SUDotAccSatKHR, true, 6, true, 3) |
| 3190 |
#undef _SPIRV_OP |
| 3191 |
|
| 3192 |
class SPIRVBitOp : public SPIRVInstTemplateBase { |
| 3193 |
public: |
| 3194 |
SPIRVCapVec getRequiredCapability() const override { |
| 3195 |
if (Module->isAllowedToUseExtension(ExtensionID::SPV_KHR_bit_instructions)) |
| 3196 |
return getVec(CapabilityBitInstructions); |
| 3197 |
|
| 3198 |
return getVec(CapabilityShader); |
| 3199 |
} |
| 3200 |
|
| 3201 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3202 |
for (auto Cap : getRequiredCapability()) { |
| 3203 |
if (Cap == CapabilityBitInstructions) |
| 3204 |
return ExtensionID::SPV_KHR_bit_instructions; |
| 3205 |
} |
| 3206 |
return std::nullopt; |
| 3207 |
} |
| 3208 |
}; |
| 3209 |
|
| 3210 |
#define _SPIRV_OP(x, ...) \ |
| 3211 |
typedef SPIRVInstTemplate<SPIRVBitOp, Op##x, __VA_ARGS__> SPIRV##x; |
| 3212 |
_SPIRV_OP(BitFieldInsert, true, 7) |
| 3213 |
_SPIRV_OP(BitFieldSExtract, true, 6) |
| 3214 |
_SPIRV_OP(BitFieldUExtract, true, 6) |
| 3215 |
_SPIRV_OP(BitReverse, true, 4) |
| 3216 |
#undef _SPIRV_OP |
| 3217 |
|
| 3218 |
class SPIRVSubgroupShuffleINTELInstBase : public SPIRVInstTemplateBase { |
| 3219 |
protected: |
| 3220 |
SPIRVCapVec getRequiredCapability() const override { |
| 3221 |
return getVec(CapabilitySubgroupShuffleINTEL); |
| 3222 |
} |
| 3223 |
|
| 3224 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3225 |
return ExtensionID::SPV_INTEL_subgroups; |
| 3226 |
} |
| 3227 |
}; |
| 3228 |
|
| 3229 |
#define _SPIRV_OP(x, ...) \ |
| 3230 |
typedef SPIRVInstTemplate<SPIRVSubgroupShuffleINTELInstBase, Op##x, \ |
| 3231 |
__VA_ARGS__> \ |
| 3232 |
SPIRV##x; |
| 3233 |
// Intel Subgroup Shuffle Instructions |
| 3234 |
_SPIRV_OP(SubgroupShuffleINTEL, true, 5) |
| 3235 |
_SPIRV_OP(SubgroupShuffleDownINTEL, true, 6) |
| 3236 |
_SPIRV_OP(SubgroupShuffleUpINTEL, true, 6) |
| 3237 |
_SPIRV_OP(SubgroupShuffleXorINTEL, true, 5) |
| 3238 |
#undef _SPIRV_OP |
| 3239 |
|
| 3240 |
class SPIRVSubgroupBufferBlockIOINTELInstBase : public SPIRVInstTemplateBase { |
| 3241 |
protected: |
| 3242 |
SPIRVCapVec getRequiredCapability() const override { |
| 3243 |
return getVec(CapabilitySubgroupBufferBlockIOINTEL); |
| 3244 |
} |
| 3245 |
|
| 3246 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3247 |
return ExtensionID::SPV_INTEL_subgroups; |
| 3248 |
} |
| 3249 |
}; |
| 3250 |
|
| 3251 |
#define _SPIRV_OP(x, ...) \ |
| 3252 |
typedef SPIRVInstTemplate<SPIRVSubgroupBufferBlockIOINTELInstBase, Op##x, \ |
| 3253 |
__VA_ARGS__> \ |
| 3254 |
SPIRV##x; |
| 3255 |
// Intel Subgroup Buffer Block Read and Write Instructions |
| 3256 |
_SPIRV_OP(SubgroupBlockReadINTEL, true, 4) |
| 3257 |
_SPIRV_OP(SubgroupBlockWriteINTEL, false, 3) |
| 3258 |
#undef _SPIRV_OP |
| 3259 |
|
| 3260 |
class SPIRVSubgroupImageBlockIOINTELInstBase : public SPIRVInstTemplateBase { |
| 3261 |
protected: |
| 3262 |
SPIRVCapVec getRequiredCapability() const override { |
| 3263 |
return getVec(CapabilitySubgroupImageBlockIOINTEL); |
| 3264 |
} |
| 3265 |
|
| 3266 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3267 |
return ExtensionID::SPV_INTEL_subgroups; |
| 3268 |
} |
| 3269 |
}; |
| 3270 |
|
| 3271 |
#define _SPIRV_OP(x, ...) \ |
| 3272 |
typedef SPIRVInstTemplate<SPIRVSubgroupImageBlockIOINTELInstBase, Op##x, \ |
| 3273 |
__VA_ARGS__> \ |
| 3274 |
SPIRV##x; |
| 3275 |
// Intel Subgroup Image Block Read and Write Instructions |
| 3276 |
_SPIRV_OP(SubgroupImageBlockReadINTEL, true, 5) |
| 3277 |
_SPIRV_OP(SubgroupImageBlockWriteINTEL, false, 4) |
| 3278 |
#undef _SPIRV_OP |
| 3279 |
|
| 3280 |
class SPIRVSubgroupImageMediaBlockIOINTELInstBase |
| 3281 |
: public SPIRVInstTemplateBase { |
| 3282 |
protected: |
| 3283 |
SPIRVCapVec getRequiredCapability() const override { |
| 3284 |
return getVec(CapabilitySubgroupImageMediaBlockIOINTEL); |
| 3285 |
} |
| 3286 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3287 |
return ExtensionID::SPV_INTEL_media_block_io; |
| 3288 |
} |
| 3289 |
}; |
| 3290 |
|
| 3291 |
#define _SPIRV_OP(x, ...) \ |
| 3292 |
typedef SPIRVInstTemplate<SPIRVSubgroupImageMediaBlockIOINTELInstBase, \ |
| 3293 |
Op##x, __VA_ARGS__> \ |
| 3294 |
SPIRV##x; |
| 3295 |
// Intel Subgroup Image Media Block Read and Write Instructions |
| 3296 |
_SPIRV_OP(SubgroupImageMediaBlockReadINTEL, true, 7) |
| 3297 |
_SPIRV_OP(SubgroupImageMediaBlockWriteINTEL, false, 6) |
| 3298 |
#undef _SPIRV_OP |
| 3299 |
|
| 3300 |
class SPIRVSubgroupAVCIntelInstBase : public SPIRVInstTemplateBase { |
| 3301 |
protected: |
| 3302 |
SPIRVCapVec getRequiredCapability() const override { |
| 3303 |
return getVec(CapabilitySubgroupAvcMotionEstimationINTEL); |
| 3304 |
} |
| 3305 |
|
| 3306 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3307 |
return ExtensionID::SPV_INTEL_device_side_avc_motion_estimation; |
| 3308 |
} |
| 3309 |
}; |
| 3310 |
|
| 3311 |
// Intel Subgroup AVC Motion Estimation Instructions |
| 3312 |
typedef SPIRVInstTemplate<SPIRVSubgroupAVCIntelInstBase, OpVmeImageINTEL, true, |
| 3313 |
5> |
| 3314 |
SPIRVVmeImageINTEL; |
| 3315 |
|
| 3316 |
#define _SPIRV_OP(x, ...) \ |
| 3317 |
typedef SPIRVInstTemplate<SPIRVSubgroupAVCIntelInstBase, \ |
| 3318 |
OpSubgroupAvc##x##INTEL, __VA_ARGS__> \ |
| 3319 |
SPIRVSubgroupAvc##x##INTEL; |
| 3320 |
_SPIRV_OP(MceGetDefaultInterBaseMultiReferencePenalty, true, 5) |
| 3321 |
_SPIRV_OP(MceSetInterBaseMultiReferencePenalty, true, 5) |
| 3322 |
_SPIRV_OP(MceGetDefaultInterShapePenalty, true, 5) |
| 3323 |
_SPIRV_OP(MceSetInterShapePenalty, true, 5) |
| 3324 |
_SPIRV_OP(MceGetDefaultInterDirectionPenalty, true, 5) |
| 3325 |
_SPIRV_OP(MceSetInterDirectionPenalty, true, 5) |
| 3326 |
_SPIRV_OP(MceGetDefaultInterMotionVectorCostTable, true, 5) |
| 3327 |
_SPIRV_OP(MceGetDefaultHighPenaltyCostTable, true, 3) |
| 3328 |
_SPIRV_OP(MceGetDefaultMediumPenaltyCostTable, true, 3) |
| 3329 |
_SPIRV_OP(MceGetDefaultLowPenaltyCostTable, true, 3) |
| 3330 |
_SPIRV_OP(MceSetMotionVectorCostFunction, true, 7) |
| 3331 |
_SPIRV_OP(MceSetAcOnlyHaar, true, 4) |
| 3332 |
_SPIRV_OP(MceSetSourceInterlacedFieldPolarity, true, 5) |
| 3333 |
_SPIRV_OP(MceSetSingleReferenceInterlacedFieldPolarity, true, 5) |
| 3334 |
_SPIRV_OP(MceSetDualReferenceInterlacedFieldPolarities, true, 6) |
| 3335 |
_SPIRV_OP(MceConvertToImePayload, true, 4) |
| 3336 |
_SPIRV_OP(MceConvertToImeResult, true, 4) |
| 3337 |
_SPIRV_OP(MceConvertToRefPayload, true, 4) |
| 3338 |
_SPIRV_OP(MceConvertToRefResult, true, 4) |
| 3339 |
_SPIRV_OP(MceConvertToSicPayload, true, 4) |
| 3340 |
_SPIRV_OP(MceConvertToSicResult, true, 4) |
| 3341 |
_SPIRV_OP(MceGetMotionVectors, true, 4) |
| 3342 |
_SPIRV_OP(MceGetInterDistortions, true, 4) |
| 3343 |
_SPIRV_OP(MceGetBestInterDistortions, true, 4) |
| 3344 |
_SPIRV_OP(MceGetInterMajorShape, true, 4) |
| 3345 |
_SPIRV_OP(MceGetInterMinorShape, true, 4) |
| 3346 |
_SPIRV_OP(MceGetInterDirections, true, 4) |
| 3347 |
_SPIRV_OP(MceGetInterMotionVectorCount, true, 4) |
| 3348 |
_SPIRV_OP(MceGetInterReferenceIds, true, 4) |
| 3349 |
_SPIRV_OP(MceGetInterReferenceInterlacedFieldPolarities, true, 6) |
| 3350 |
_SPIRV_OP(ImeInitialize, true, 6) |
| 3351 |
_SPIRV_OP(ImeSetSingleReference, true, 6) |
| 3352 |
_SPIRV_OP(ImeSetDualReference, true, 7) |
| 3353 |
_SPIRV_OP(ImeRefWindowSize, true, 5) |
| 3354 |
_SPIRV_OP(ImeAdjustRefOffset, true, 7) |
| 3355 |
_SPIRV_OP(ImeConvertToMcePayload, true, 4) |
| 3356 |
_SPIRV_OP(ImeSetMaxMotionVectorCount, true, 5) |
| 3357 |
_SPIRV_OP(ImeSetUnidirectionalMixDisable, true, 4) |
| 3358 |
_SPIRV_OP(ImeSetEarlySearchTerminationThreshold, true, 5) |
| 3359 |
_SPIRV_OP(ImeSetWeightedSad, true, 5) |
| 3360 |
_SPIRV_OP(ImeEvaluateWithSingleReference, true, 6) |
| 3361 |
_SPIRV_OP(ImeEvaluateWithDualReference, true, 7) |
| 3362 |
_SPIRV_OP(ImeEvaluateWithSingleReferenceStreamin, true, 7) |
| 3363 |
_SPIRV_OP(ImeEvaluateWithDualReferenceStreamin, true, 8) |
| 3364 |
_SPIRV_OP(ImeEvaluateWithSingleReferenceStreamout, true, 6) |
| 3365 |
_SPIRV_OP(ImeEvaluateWithDualReferenceStreamout, true, 7) |
| 3366 |
_SPIRV_OP(ImeEvaluateWithSingleReferenceStreaminout, true, 7) |
| 3367 |
_SPIRV_OP(ImeEvaluateWithDualReferenceStreaminout, true, 8) |
| 3368 |
_SPIRV_OP(ImeConvertToMceResult, true, 4) |
| 3369 |
_SPIRV_OP(ImeGetSingleReferenceStreamin, true, 4) |
| 3370 |
_SPIRV_OP(ImeGetDualReferenceStreamin, true, 4) |
| 3371 |
_SPIRV_OP(ImeStripSingleReferenceStreamout, true, 4) |
| 3372 |
_SPIRV_OP(ImeStripDualReferenceStreamout, true, 4) |
| 3373 |
_SPIRV_OP(ImeGetStreamoutSingleReferenceMajorShapeMotionVectors, true, 5) |
| 3374 |
_SPIRV_OP(ImeGetStreamoutSingleReferenceMajorShapeDistortions, true, 5) |
| 3375 |
_SPIRV_OP(ImeGetStreamoutSingleReferenceMajorShapeReferenceIds, true, 5) |
| 3376 |
_SPIRV_OP(ImeGetStreamoutDualReferenceMajorShapeMotionVectors, true, 6) |
| 3377 |
_SPIRV_OP(ImeGetStreamoutDualReferenceMajorShapeDistortions, true, 6) |
| 3378 |
_SPIRV_OP(ImeGetStreamoutDualReferenceMajorShapeReferenceIds, true, 6) |
| 3379 |
_SPIRV_OP(ImeGetBorderReached, true, 5) |
| 3380 |
_SPIRV_OP(ImeGetTruncatedSearchIndication, true, 4) |
| 3381 |
_SPIRV_OP(ImeGetUnidirectionalEarlySearchTermination, true, 4) |
| 3382 |
_SPIRV_OP(ImeGetWeightingPatternMinimumMotionVector, true, 4) |
| 3383 |
_SPIRV_OP(ImeGetWeightingPatternMinimumDistortion, true, 4) |
| 3384 |
_SPIRV_OP(FmeInitialize, true, 10) |
| 3385 |
_SPIRV_OP(BmeInitialize, true, 11) |
| 3386 |
_SPIRV_OP(RefConvertToMcePayload, true, 4) |
| 3387 |
_SPIRV_OP(RefSetBidirectionalMixDisable, true, 4) |
| 3388 |
_SPIRV_OP(RefSetBilinearFilterEnable, true, 4) |
| 3389 |
_SPIRV_OP(RefEvaluateWithSingleReference, true, 6) |
| 3390 |
_SPIRV_OP(RefEvaluateWithDualReference, true, 7) |
| 3391 |
_SPIRV_OP(RefEvaluateWithMultiReference, true, 6) |
| 3392 |
_SPIRV_OP(RefEvaluateWithMultiReferenceInterlaced, true, 7) |
| 3393 |
_SPIRV_OP(RefConvertToMceResult, true, 4) |
| 3394 |
_SPIRV_OP(SicInitialize, true, 4) |
| 3395 |
_SPIRV_OP(SicConfigureSkc, true, 9) |
| 3396 |
_SPIRV_OP(SicGetMotionVectorMask, true, 5) |
| 3397 |
_SPIRV_OP(SicConvertToMcePayload, true, 4) |
| 3398 |
_SPIRV_OP(SicSetIntraLumaShapePenalty, true, 5) |
| 3399 |
_SPIRV_OP(SicSetBilinearFilterEnable, true, 4) |
| 3400 |
_SPIRV_OP(SicSetSkcForwardTransformEnable, true, 5) |
| 3401 |
_SPIRV_OP(SicSetBlockBasedRawSkipSad, true, 5) |
| 3402 |
_SPIRV_OP(SicEvaluateWithSingleReference, true, 6) |
| 3403 |
_SPIRV_OP(SicEvaluateWithDualReference, true, 7) |
| 3404 |
_SPIRV_OP(SicEvaluateWithMultiReference, true, 6) |
| 3405 |
_SPIRV_OP(SicEvaluateWithMultiReferenceInterlaced, true, 7) |
| 3406 |
_SPIRV_OP(SicConvertToMceResult, true, 4) |
| 3407 |
_SPIRV_OP(SicGetInterRawSads, true, 4) |
| 3408 |
#undef _SPIRV_OP |
| 3409 |
|
| 3410 |
class SPIRVSubgroupAVCIntelInstBaseIntra : public SPIRVInstTemplateBase { |
| 3411 |
protected: |
| 3412 |
SPIRVCapVec getRequiredCapability() const override { |
| 3413 |
return getVec(CapabilitySubgroupAvcMotionEstimationIntraINTEL); |
| 3414 |
} |
| 3415 |
}; |
| 3416 |
|
| 3417 |
// Intel Subgroup AVC Motion Estimation Intra Instructions |
| 3418 |
#define _SPIRV_OP(x, ...) \ |
| 3419 |
typedef SPIRVInstTemplate<SPIRVSubgroupAVCIntelInstBaseIntra, \ |
| 3420 |
OpSubgroupAvc##x##INTEL, __VA_ARGS__> \ |
| 3421 |
SPIRVSubgroupAvc##x##INTEL; |
| 3422 |
_SPIRV_OP(MceGetDefaultIntraLumaShapePenalty, true, 5) |
| 3423 |
_SPIRV_OP(MceGetDefaultIntraLumaModePenalty, true, 5) |
| 3424 |
_SPIRV_OP(MceGetDefaultNonDcLumaIntraPenalty, true, 3) |
| 3425 |
_SPIRV_OP(SicConfigureIpeLuma, true, 11) |
| 3426 |
_SPIRV_OP(SicSetIntraLumaModeCostFunction, true, 7) |
| 3427 |
_SPIRV_OP(SicEvaluateIpe, true, 5) |
| 3428 |
_SPIRV_OP(SicGetIpeLumaShape, true, 4) |
| 3429 |
_SPIRV_OP(SicGetBestIpeLumaDistortion, true, 4) |
| 3430 |
_SPIRV_OP(SicGetPackedIpeLumaModes, true, 4) |
| 3431 |
_SPIRV_OP(SicGetPackedSkcLumaCountThreshold, true, 4) |
| 3432 |
_SPIRV_OP(SicGetPackedSkcLumaSumThreshold, true, 4) |
| 3433 |
#undef _SPIRV_OP |
| 3434 |
|
| 3435 |
class SPIRVSubgroupAVCIntelInstBaseChroma : public SPIRVInstTemplateBase { |
| 3436 |
protected: |
| 3437 |
SPIRVCapVec getRequiredCapability() const override { |
| 3438 |
return getVec(CapabilitySubgroupAvcMotionEstimationChromaINTEL); |
| 3439 |
} |
| 3440 |
}; |
| 3441 |
|
| 3442 |
// Intel Subgroup AVC Motion Estimation Chroma Instructions |
| 3443 |
#define _SPIRV_OP(x, ...) \ |
| 3444 |
typedef SPIRVInstTemplate<SPIRVSubgroupAVCIntelInstBaseChroma, \ |
| 3445 |
OpSubgroupAvc##x##INTEL, __VA_ARGS__> \ |
| 3446 |
SPIRVSubgroupAvc##x##INTEL; |
| 3447 |
_SPIRV_OP(MceGetDefaultIntraChromaModeBasePenalty, true, 3) |
| 3448 |
_SPIRV_OP(SicConfigureIpeLumaChroma, true, 14) |
| 3449 |
_SPIRV_OP(SicSetIntraChromaModeCostFunction, true, 5) |
| 3450 |
_SPIRV_OP(SicGetBestIpeChromaDistortion, true, 4) |
| 3451 |
_SPIRV_OP(SicGetIpeChromaMode, true, 4) |
| 3452 |
#undef _SPIRV_OP |
| 3453 |
|
| 3454 |
SPIRVSpecConstantOp *createSpecConstantOpInst(SPIRVInstruction *Inst); |
| 3455 |
SPIRVInstruction *createInstFromSpecConstantOp(SPIRVSpecConstantOp *C); |
| 3456 |
|
| 3457 |
class SPIRVVariableLengthArrayINTELInstBase : public SPIRVInstTemplateBase { |
| 3458 |
protected: |
| 3459 |
SPIRVCapVec getRequiredCapability() const override { |
| 3460 |
return getVec(CapabilityVariableLengthArrayINTEL); |
| 3461 |
} |
| 3462 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3463 |
return ExtensionID::SPV_INTEL_variable_length_array; |
| 3464 |
} |
| 3465 |
}; |
| 3466 |
#define _SPIRV_OP(x, ...) \ |
| 3467 |
typedef SPIRVInstTemplate<SPIRVVariableLengthArrayINTELInstBase, \ |
| 3468 |
Op##x##INTEL, __VA_ARGS__> \ |
| 3469 |
SPIRV##x##INTEL; |
| 3470 |
_SPIRV_OP(VariableLengthArray, true, 4) |
| 3471 |
_SPIRV_OP(SaveMemory, true, 3) |
| 3472 |
_SPIRV_OP(RestoreMemory, false, 2) |
| 3473 |
#undef _SPIRV_OP |
| 3474 |
|
| 3475 |
template <Op OC> |
| 3476 |
class SPIRVBfloat16ConversionINTELInstBase : public SPIRVUnaryInst<OC> { |
| 3477 |
protected: |
| 3478 |
SPIRVCapVec getRequiredCapability() const override { |
| 3479 |
return getVec(internal::CapabilityBfloat16ConversionINTEL); |
| 3480 |
} |
| 3481 |
|
| 3482 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3483 |
return ExtensionID::SPV_INTEL_bfloat16_conversion; |
| 3484 |
} |
| 3485 |
|
| 3486 |
void validate() const override { |
| 3487 |
SPIRVUnaryInst<OC>::validate(); |
| 3488 |
|
| 3489 |
SPIRVType *ResCompTy = this->getType(); |
| 3490 |
SPIRVWord ResCompCount = 1; |
| 3491 |
if (ResCompTy->isTypeVector()) { |
| 3492 |
ResCompCount = ResCompTy->getVectorComponentCount(); |
| 3493 |
ResCompTy = ResCompTy->getVectorComponentType(); |
| 3494 |
} |
| 3495 |
|
| 3496 |
// validate is a const method, whilst getOperand is non-const method |
| 3497 |
// because it may call a method of class Module that may modify LiteralMap |
| 3498 |
// of Module field. That modification is not impacting validate method for |
| 3499 |
// these instructions, so const_cast is safe here. |
| 3500 |
using SPVBf16ConvTy = SPIRVBfloat16ConversionINTELInstBase<OC>; |
| 3501 |
SPIRVValue *Input = const_cast<SPVBf16ConvTy *>(this)->getOperand(0); |
| 3502 |
|
| 3503 |
SPIRVType *InCompTy = Input->getType(); |
| 3504 |
SPIRVWord InCompCount = 1; |
| 3505 |
if (InCompTy->isTypeVector()) { |
| 3506 |
InCompCount = InCompTy->getVectorComponentCount(); |
| 3507 |
InCompTy = InCompTy->getVectorComponentType(); |
| 3508 |
} |
| 3509 |
|
| 3510 |
auto InstName = OpCodeNameMap::map(OC); |
| 3511 |
SPIRVErrorLog &SPVErrLog = this->getModule()->getErrorLog(); |
| 3512 |
|
| 3513 |
if (OC == internal::OpConvertFToBF16INTEL) { |
| 3514 |
SPVErrLog.checkError( |
| 3515 |
ResCompTy->isTypeInt(16), SPIRVEC_InvalidInstruction, |
| 3516 |
InstName + "\nResult value must be a scalar or vector of integer " |
| 3517 |
"16-bit type\n"); |
| 3518 |
SPVErrLog.checkError( |
| 3519 |
InCompTy->isTypeFloat(32), SPIRVEC_InvalidInstruction, |
| 3520 |
InstName + "\nInput value must be a scalar or vector of " |
| 3521 |
"floating-point 32-bit type\n"); |
| 3522 |
} else { |
| 3523 |
SPVErrLog.checkError( |
| 3524 |
ResCompTy->isTypeFloat(32), SPIRVEC_InvalidInstruction, |
| 3525 |
InstName + "\nResult value must be a scalar or vector of " |
| 3526 |
"floating-point 32-bit type\n"); |
| 3527 |
SPVErrLog.checkError( |
| 3528 |
InCompTy->isTypeInt(16), SPIRVEC_InvalidInstruction, |
| 3529 |
InstName + "\nInput value must be a scalar or vector of integer " |
| 3530 |
"16-bit type\n"); |
| 3531 |
} |
| 3532 |
|
| 3533 |
SPVErrLog.checkError( |
| 3534 |
ResCompCount == InCompCount, SPIRVEC_InvalidInstruction, |
| 3535 |
InstName + "\nInput type must have the same number of components as " |
| 3536 |
"result type\n"); |
| 3537 |
} |
| 3538 |
}; |
| 3539 |
|
| 3540 |
#define _SPIRV_OP(x) \ |
| 3541 |
typedef SPIRVBfloat16ConversionINTELInstBase<internal::Op##x> SPIRV##x; |
| 3542 |
_SPIRV_OP(ConvertFToBF16INTEL) |
| 3543 |
_SPIRV_OP(ConvertBF16ToFINTEL) |
| 3544 |
#undef _SPIRV_OP |
| 3545 |
|
| 3546 |
class SPIRVJointMatrixINTELInstBase : public SPIRVInstTemplateBase { |
| 3547 |
protected: |
| 3548 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3549 |
return ExtensionID::SPV_INTEL_joint_matrix; |
| 3550 |
} |
| 3551 |
}; |
| 3552 |
|
| 3553 |
class SPIRVJointMatrixINTELInst : public SPIRVJointMatrixINTELInstBase { |
| 3554 |
SPIRVCapVec getRequiredCapability() const override { |
| 3555 |
return getVec(internal::CapabilityJointMatrixINTEL); |
| 3556 |
} |
| 3557 |
}; |
| 3558 |
|
| 3559 |
#define _SPIRV_OP(x, ...) \ |
| 3560 |
typedef SPIRVInstTemplate<SPIRVJointMatrixINTELInst, internal::Op##x##INTEL, \ |
| 3561 |
__VA_ARGS__> \ |
| 3562 |
SPIRV##x##INTEL; |
| 3563 |
_SPIRV_OP(JointMatrixLoad, true, 6, true) |
| 3564 |
_SPIRV_OP(JointMatrixStore, false, 5, true) |
| 3565 |
_SPIRV_OP(JointMatrixMad, true, 7) |
| 3566 |
_SPIRV_OP(JointMatrixSUMad, true, 7) |
| 3567 |
_SPIRV_OP(JointMatrixUSMad, true, 7) |
| 3568 |
_SPIRV_OP(JointMatrixUUMad, true, 7) |
| 3569 |
// TODO: move to SPIRVJointMatrixINTELWorkItemInst |
| 3570 |
_SPIRV_OP(JointMatrixWorkItemLength, true, 4) |
| 3571 |
#undef _SPIRV_OP |
| 3572 |
|
| 3573 |
class SPIRVJointMatrixINTELWorkItemInst : public SPIRVJointMatrixINTELInstBase { |
| 3574 |
protected: |
| 3575 |
SPIRVCapVec getRequiredCapability() const override { |
| 3576 |
return getVec(internal::CapabilityJointMatrixWIInstructionsINTEL); |
| 3577 |
} |
| 3578 |
}; |
| 3579 |
|
| 3580 |
#define _SPIRV_OP(x, ...) \ |
| 3581 |
typedef SPIRVInstTemplate<SPIRVJointMatrixINTELWorkItemInst, \ |
| 3582 |
internal::Op##x##INTEL, __VA_ARGS__> \ |
| 3583 |
SPIRV##x##INTEL; |
| 3584 |
_SPIRV_OP(JointMatrixGetElementCoord, true, 5) |
| 3585 |
#undef _SPIRV_OP |
| 3586 |
|
| 3587 |
class SPIRVCooperativeMatrixPrefetchINTELInstBase |
| 3588 |
: public SPIRVInstTemplateBase { |
| 3589 |
protected: |
| 3590 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3591 |
return ExtensionID::SPV_INTEL_joint_matrix; |
| 3592 |
} |
| 3593 |
SPIRVCapVec getRequiredCapability() const override { |
| 3594 |
return getVec(internal::CapabilityCooperativeMatrixPrefetchINTEL); |
| 3595 |
} |
| 3596 |
}; |
| 3597 |
|
| 3598 |
#define _SPIRV_OP(x, ...) \ |
| 3599 |
typedef SPIRVInstTemplate<SPIRVCooperativeMatrixPrefetchINTELInstBase, \ |
| 3600 |
internal::Op##x##INTEL, __VA_ARGS__> \ |
| 3601 |
SPIRV##x##INTEL; |
| 3602 |
_SPIRV_OP(CooperativeMatrixPrefetch, false, 6, true, 3) |
| 3603 |
#undef _SPIRV_OP |
| 3604 |
|
| 3605 |
class SPIRVCooperativeMatrixKHRInstBase : public SPIRVInstTemplateBase { |
| 3606 |
protected: |
| 3607 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3608 |
return ExtensionID::SPV_KHR_cooperative_matrix; |
| 3609 |
} |
| 3610 |
SPIRVCapVec getRequiredCapability() const override { |
| 3611 |
return getVec(CapabilityCooperativeMatrixKHR); |
| 3612 |
} |
| 3613 |
}; |
| 3614 |
|
| 3615 |
#define _SPIRV_OP(x, ...) \ |
| 3616 |
typedef SPIRVInstTemplate<SPIRVCooperativeMatrixKHRInstBase, Op##x, \ |
| 3617 |
__VA_ARGS__> \ |
| 3618 |
SPIRV##x; |
| 3619 |
_SPIRV_OP(CooperativeMatrixLoadKHR, true, 5, true, 3) |
| 3620 |
_SPIRV_OP(CooperativeMatrixStoreKHR, false, 4, true, 4) |
| 3621 |
_SPIRV_OP(CooperativeMatrixLengthKHR, true, 4, false) |
| 3622 |
_SPIRV_OP(CooperativeMatrixMulAddKHR, true, 6, true, 3) |
| 3623 |
#undef _SPIRV_OP |
| 3624 |
|
| 3625 |
class SPIRVCooperativeMatrixCheckedInstructionsINTELInstBase |
| 3626 |
: public SPIRVInstTemplateBase { |
| 3627 |
protected: |
| 3628 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3629 |
return ExtensionID::SPV_INTEL_joint_matrix; |
| 3630 |
} |
| 3631 |
SPIRVCapVec getRequiredCapability() const override { |
| 3632 |
return getVec( |
| 3633 |
internal::CapabilityCooperativeMatrixCheckedInstructionsINTEL); |
| 3634 |
} |
| 3635 |
}; |
| 3636 |
|
| 3637 |
#define _SPIRV_OP(x, ...) \ |
| 3638 |
typedef SPIRVInstTemplate< \ |
| 3639 |
SPIRVCooperativeMatrixCheckedInstructionsINTELInstBase, \ |
| 3640 |
internal::Op##x##INTEL, __VA_ARGS__> \ |
| 3641 |
SPIRV##x##INTEL; |
| 3642 |
_SPIRV_OP(CooperativeMatrixLoadChecked, true, 9, true, 7) |
| 3643 |
_SPIRV_OP(CooperativeMatrixStoreChecked, false, 8, true, 8) |
| 3644 |
_SPIRV_OP(CooperativeMatrixConstructChecked, true, 8) |
| 3645 |
#undef _SPIRV_OP |
| 3646 |
|
| 3647 |
class SPIRVSplitBarrierINTELBase : public SPIRVInstTemplateBase { |
| 3648 |
protected: |
| 3649 |
SPIRVCapVec getRequiredCapability() const override { |
| 3650 |
return getVec(CapabilitySplitBarrierINTEL); |
| 3651 |
} |
| 3652 |
|
| 3653 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3654 |
return ExtensionID::SPV_INTEL_split_barrier; |
| 3655 |
} |
| 3656 |
}; |
| 3657 |
|
| 3658 |
#define _SPIRV_OP(x, ...) \ |
| 3659 |
typedef SPIRVInstTemplate<SPIRVSplitBarrierINTELBase, Op##x, __VA_ARGS__> \ |
| 3660 |
SPIRV##x; |
| 3661 |
_SPIRV_OP(ControlBarrierArriveINTEL, false, 4) |
| 3662 |
_SPIRV_OP(ControlBarrierWaitINTEL, false, 4) |
| 3663 |
#undef _SPIRV_OP |
| 3664 |
|
| 3665 |
class SPIRVGroupUniformArithmeticKHRInstBase : public SPIRVInstTemplateBase { |
| 3666 |
public: |
| 3667 |
SPIRVCapVec getRequiredCapability() const override { |
| 3668 |
return getVec(CapabilityGroupUniformArithmeticKHR); |
| 3669 |
} |
| 3670 |
|
| 3671 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3672 |
return ExtensionID::SPV_KHR_uniform_group_instructions; |
| 3673 |
} |
| 3674 |
}; |
| 3675 |
|
| 3676 |
#define _SPIRV_OP(x, ...) \ |
| 3677 |
typedef SPIRVInstTemplate<SPIRVGroupUniformArithmeticKHRInstBase, \ |
| 3678 |
Op##x##KHR, __VA_ARGS__> \ |
| 3679 |
SPIRV##x##KHR; |
| 3680 |
_SPIRV_OP(GroupIMul, true, 6, false, 1) |
| 3681 |
_SPIRV_OP(GroupFMul, true, 6, false, 1) |
| 3682 |
_SPIRV_OP(GroupBitwiseAnd, true, 6, false, 1) |
| 3683 |
_SPIRV_OP(GroupBitwiseOr, true, 6, false, 1) |
| 3684 |
_SPIRV_OP(GroupBitwiseXor, true, 6, false, 1) |
| 3685 |
_SPIRV_OP(GroupLogicalAnd, true, 6, false, 1) |
| 3686 |
_SPIRV_OP(GroupLogicalOr, true, 6, false, 1) |
| 3687 |
_SPIRV_OP(GroupLogicalXor, true, 6, false, 1) |
| 3688 |
#undef _SPIRV_OP |
| 3689 |
|
| 3690 |
class SPIRVComplexFloat : public SPIRVInstTemplateBase { |
| 3691 |
protected: |
| 3692 |
void validate() const override { |
| 3693 |
SPIRVId Op1 = Ops[0]; |
| 3694 |
SPIRVId Op2 = Ops[1]; |
| 3695 |
SPIRVType *Op1Ty, *Op2Ty; |
| 3696 |
SPIRVInstruction::validate(); |
| 3697 |
if (getValue(Op1)->isForward() || getValue(Op2)->isForward()) |
| 3698 |
return; |
| 3699 |
if (getValueType(Op1)->isTypeVector()) { |
| 3700 |
Op1Ty = getValueType(Op1)->getVectorComponentType(); |
| 3701 |
Op2Ty = getValueType(Op2)->getVectorComponentType(); |
| 3702 |
assert(getValueType(Op1)->getVectorComponentCount() == |
| 3703 |
getValueType(Op2)->getVectorComponentCount() && |
| 3704 |
"Inconsistent Vector component width"); |
| 3705 |
} else { |
| 3706 |
Op1Ty = getValueType(Op1); |
| 3707 |
Op2Ty = getValueType(Op2); |
| 3708 |
} |
| 3709 |
(void)Op1Ty; |
| 3710 |
(void)Op2Ty; |
| 3711 |
assert(Op1Ty->isTypeFloat() && "Invalid type for complex instruction"); |
| 3712 |
assert(Op1Ty == Op2Ty && "Invalid type for complex instruction"); |
| 3713 |
} |
| 3714 |
|
| 3715 |
public: |
| 3716 |
SPIRVCapVec getRequiredCapability() const override { |
| 3717 |
return getVec(internal::CapabilityComplexFloatMulDivINTEL); |
| 3718 |
} |
| 3719 |
|
| 3720 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3721 |
return ExtensionID::SPV_INTEL_complex_float_mul_div; |
| 3722 |
} |
| 3723 |
}; |
| 3724 |
|
| 3725 |
template <Op OC> |
| 3726 |
class SPIRVComplexFloatInst |
| 3727 |
: public SPIRVInstTemplate<SPIRVComplexFloat, OC, true, 5, false> {}; |
| 3728 |
|
| 3729 |
#define _SPIRV_OP(x) typedef SPIRVComplexFloatInst<internal::Op##x> SPIRV##x; |
| 3730 |
_SPIRV_OP(ComplexFMulINTEL) |
| 3731 |
_SPIRV_OP(ComplexFDivINTEL) |
| 3732 |
#undef _SPIRV_OP |
| 3733 |
|
| 3734 |
class SPIRVMaskedGatherScatterINTELInstBase : public SPIRVInstTemplateBase { |
| 3735 |
protected: |
| 3736 |
SPIRVCapVec getRequiredCapability() const override { |
| 3737 |
return getVec(internal::CapabilityMaskedGatherScatterINTEL); |
| 3738 |
} |
| 3739 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3740 |
return ExtensionID::SPV_INTEL_masked_gather_scatter; |
| 3741 |
} |
| 3742 |
}; |
| 3743 |
|
| 3744 |
class SPIRVMaskedGatherINTELInst |
| 3745 |
: public SPIRVMaskedGatherScatterINTELInstBase { |
| 3746 |
void validate() const override { |
| 3747 |
SPIRVInstruction::validate(); |
| 3748 |
SPIRVErrorLog &SPVErrLog = this->getModule()->getErrorLog(); |
| 3749 |
std::string InstName = "MaskedGatherINTEL"; |
| 3750 |
|
| 3751 |
SPIRVType *ResTy = this->getType(); |
| 3752 |
SPVErrLog.checkError(ResTy->isTypeVector(), SPIRVEC_InvalidInstruction, |
| 3753 |
InstName + "\nResult must be a vector type\n"); |
| 3754 |
SPIRVWord ResCompCount = ResTy->getVectorComponentCount(); |
| 3755 |
SPIRVType *ResCompTy = ResTy->getVectorComponentType(); |
| 3756 |
|
| 3757 |
SPIRVValue *PtrVec = |
| 3758 |
const_cast<SPIRVMaskedGatherINTELInst *>(this)->getOperand(0); |
| 3759 |
SPIRVType *PtrVecTy = PtrVec->getType(); |
| 3760 |
SPVErrLog.checkError( |
| 3761 |
PtrVecTy->isTypeVectorPointer(), SPIRVEC_InvalidInstruction, |
| 3762 |
InstName + "\nPtrVector must be a vector of pointers type\n"); |
| 3763 |
SPIRVWord PtrVecCompCount = PtrVecTy->getVectorComponentCount(); |
| 3764 |
SPIRVType *PtrVecCompTy = PtrVecTy->getVectorComponentType(); |
| 3765 |
SPIRVType *PtrElemTy = PtrVecCompTy->getPointerElementType(); |
| 3766 |
|
| 3767 |
SPVErrLog.checkError( |
| 3768 |
this->isOperandLiteral(1), SPIRVEC_InvalidInstruction, |
| 3769 |
InstName + "\nAlignment must be a constant expression integer\n"); |
| 3770 |
const uint32_t Align = |
| 3771 |
static_cast<SPIRVConstant *>( |
| 3772 |
const_cast<SPIRVMaskedGatherINTELInst *>(this)->getOperand(2)) |
| 3773 |
->getZExtIntValue(); |
| 3774 |
SPVErrLog.checkError( |
| 3775 |
((Align & (Align - 1)) == 0), SPIRVEC_InvalidInstruction, |
| 3776 |
InstName + "\nAlignment must be 0 or power-of-two integer\n"); |
| 3777 |
|
| 3778 |
SPIRVValue *Mask = |
| 3779 |
const_cast<SPIRVMaskedGatherINTELInst *>(this)->getOperand(2); |
| 3780 |
SPIRVType *MaskTy = Mask->getType(); |
| 3781 |
SPVErrLog.checkError(MaskTy->isTypeVector(), SPIRVEC_InvalidInstruction, |
| 3782 |
InstName + "\nMask must be a vector type\n"); |
| 3783 |
SPIRVType *MaskCompTy = MaskTy->getVectorComponentType(); |
| 3784 |
SPVErrLog.checkError(MaskCompTy->isTypeBool(), SPIRVEC_InvalidInstruction, |
| 3785 |
InstName + "\nMask must be a boolean vector type\n"); |
| 3786 |
SPIRVWord MaskCompCount = MaskTy->getVectorComponentCount(); |
| 3787 |
|
| 3788 |
SPIRVValue *FillEmpty = |
| 3789 |
const_cast<SPIRVMaskedGatherINTELInst *>(this)->getOperand(3); |
| 3790 |
SPIRVType *FillEmptyTy = FillEmpty->getType(); |
| 3791 |
SPVErrLog.checkError(FillEmptyTy->isTypeVector(), |
| 3792 |
SPIRVEC_InvalidInstruction, |
| 3793 |
InstName + "\nFillEmpty must be a vector type\n"); |
| 3794 |
SPIRVWord FillEmptyCompCount = FillEmptyTy->getVectorComponentCount(); |
| 3795 |
SPIRVType *FillEmptyCompTy = FillEmptyTy->getVectorComponentType(); |
| 3796 |
|
| 3797 |
SPVErrLog.checkError( |
| 3798 |
ResCompCount == PtrVecCompCount && |
| 3799 |
PtrVecCompCount == FillEmptyCompCount && |
| 3800 |
FillEmptyCompCount == MaskCompCount, |
| 3801 |
SPIRVEC_InvalidInstruction, |
| 3802 |
InstName + "\nResult, PtrVector, Mask and FillEmpty vectors must have " |
| 3803 |
"the same size\n"); |
| 3804 |
|
| 3805 |
SPVErrLog.checkError( |
| 3806 |
ResCompTy == PtrElemTy && PtrElemTy == FillEmptyCompTy, |
| 3807 |
SPIRVEC_InvalidInstruction, |
| 3808 |
InstName + "\nComponent Type of Result and FillEmpty vector must be " |
| 3809 |
"same as base type of PtrVector the same base type\n"); |
| 3810 |
} |
| 3811 |
}; |
| 3812 |
|
| 3813 |
class SPIRVMaskedScatterINTELInst |
| 3814 |
: public SPIRVMaskedGatherScatterINTELInstBase { |
| 3815 |
void validate() const override { |
| 3816 |
SPIRVInstruction::validate(); |
| 3817 |
SPIRVErrorLog &SPVErrLog = this->getModule()->getErrorLog(); |
| 3818 |
std::string InstName = "MaskedScatterINTEL"; |
| 3819 |
|
| 3820 |
SPIRVValue *InputVec = |
| 3821 |
const_cast<SPIRVMaskedScatterINTELInst *>(this)->getOperand(0); |
| 3822 |
SPIRVType *InputVecTy = InputVec->getType(); |
| 3823 |
SPVErrLog.checkError( |
| 3824 |
InputVecTy->isTypeVector(), SPIRVEC_InvalidInstruction, |
| 3825 |
InstName + "\nInputVector must be a vector of pointers type\n"); |
| 3826 |
SPIRVWord InputVecCompCount = InputVecTy->getVectorComponentCount(); |
| 3827 |
SPIRVType *InputVecCompTy = InputVecTy->getVectorComponentType(); |
| 3828 |
|
| 3829 |
SPIRVValue *PtrVec = |
| 3830 |
const_cast<SPIRVMaskedScatterINTELInst *>(this)->getOperand(1); |
| 3831 |
SPIRVType *PtrVecTy = PtrVec->getType(); |
| 3832 |
SPVErrLog.checkError( |
| 3833 |
PtrVecTy->isTypeVectorPointer(), SPIRVEC_InvalidInstruction, |
| 3834 |
InstName + "\nPtrVector must be a vector of pointers type\n"); |
| 3835 |
SPIRVWord PtrVecCompCount = PtrVecTy->getVectorComponentCount(); |
| 3836 |
SPIRVType *PtrVecCompTy = PtrVecTy->getVectorComponentType(); |
| 3837 |
SPIRVType *PtrElemTy = PtrVecCompTy->getPointerElementType(); |
| 3838 |
|
| 3839 |
SPVErrLog.checkError( |
| 3840 |
this->isOperandLiteral(2), SPIRVEC_InvalidInstruction, |
| 3841 |
InstName + "\nAlignment must be a constant expression integer\n"); |
| 3842 |
const uint32_t Align = |
| 3843 |
static_cast<SPIRVConstant *>( |
| 3844 |
const_cast<SPIRVMaskedScatterINTELInst *>(this)->getOperand(2)) |
| 3845 |
->getZExtIntValue(); |
| 3846 |
SPVErrLog.checkError( |
| 3847 |
((Align & (Align - 1)) == 0), SPIRVEC_InvalidInstruction, |
| 3848 |
InstName + "\nAlignment must be 0 or power-of-two integer\n"); |
| 3849 |
|
| 3850 |
SPIRVValue *Mask = |
| 3851 |
const_cast<SPIRVMaskedScatterINTELInst *>(this)->getOperand(2); |
| 3852 |
SPIRVType *MaskTy = Mask->getType(); |
| 3853 |
SPVErrLog.checkError(MaskTy->isTypeVector(), SPIRVEC_InvalidInstruction, |
| 3854 |
InstName + "\nMask must be a vector type\n"); |
| 3855 |
SPIRVType *MaskCompTy = MaskTy->getVectorComponentType(); |
| 3856 |
SPVErrLog.checkError(MaskCompTy->isTypeBool(), SPIRVEC_InvalidInstruction, |
| 3857 |
InstName + "\nMask must be a boolean vector type\n"); |
| 3858 |
SPIRVWord MaskCompCount = MaskTy->getVectorComponentCount(); |
| 3859 |
|
| 3860 |
SPVErrLog.checkError( |
| 3861 |
InputVecCompCount == PtrVecCompCount && |
| 3862 |
PtrVecCompCount == MaskCompCount, |
| 3863 |
SPIRVEC_InvalidInstruction, |
| 3864 |
InstName + "\nInputVector, PtrVector and Mask vectors must have " |
| 3865 |
"the same size\n"); |
| 3866 |
|
| 3867 |
SPVErrLog.checkError( |
| 3868 |
InputVecCompTy == PtrElemTy, SPIRVEC_InvalidInstruction, |
| 3869 |
InstName + "\nComponent Type of InputVector must be " |
| 3870 |
"same as base type of PtrVector the same base type\n"); |
| 3871 |
} |
| 3872 |
}; |
| 3873 |
|
| 3874 |
#define _SPIRV_OP(x, ...) \ |
| 3875 |
typedef SPIRVInstTemplate<SPIRVMaskedGatherScatterINTELInstBase, \ |
| 3876 |
internal::Op##x##INTEL, __VA_ARGS__> \ |
| 3877 |
SPIRV##x##INTEL; |
| 3878 |
_SPIRV_OP(MaskedGather, true, 7) |
| 3879 |
_SPIRV_OP(MaskedScatter, false, 5) |
| 3880 |
#undef _SPIRV_OP |
| 3881 |
|
| 3882 |
template <Op OC> |
| 3883 |
class SPIRVTensorFloat32RoundingINTELInstBase : public SPIRVUnaryInst<OC> { |
| 3884 |
protected: |
| 3885 |
SPIRVCapVec getRequiredCapability() const override { |
| 3886 |
return getVec(internal::CapabilityTensorFloat32RoundingINTEL); |
| 3887 |
} |
| 3888 |
|
| 3889 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3890 |
return ExtensionID::SPV_INTEL_tensor_float32_conversion; |
| 3891 |
} |
| 3892 |
|
| 3893 |
void validate() const override { |
| 3894 |
SPIRVUnaryInst<OC>::validate(); |
| 3895 |
|
| 3896 |
SPIRVType *ResCompTy = this->getType(); |
| 3897 |
SPIRVWord ResCompCount = 1; |
| 3898 |
if (ResCompTy->isTypeVector()) { |
| 3899 |
ResCompCount = ResCompTy->getVectorComponentCount(); |
| 3900 |
ResCompTy = ResCompTy->getVectorComponentType(); |
| 3901 |
} |
| 3902 |
|
| 3903 |
// validate is a const method, whilst getOperand is non-const method |
| 3904 |
// because it may call a method of class Module that may modify LiteralMap |
| 3905 |
// of Module field. That modification is not impacting validate method for |
| 3906 |
// these instructions, so const_cast is safe here. |
| 3907 |
using SPVTF32RoundTy = SPIRVTensorFloat32RoundingINTELInstBase<OC>; |
| 3908 |
SPIRVValue *Input = const_cast<SPVTF32RoundTy *>(this)->getOperand(0); |
| 3909 |
|
| 3910 |
SPIRVType *InCompTy = Input->getType(); |
| 3911 |
SPIRVWord InCompCount = 1; |
| 3912 |
if (InCompTy->isTypeVector()) { |
| 3913 |
InCompCount = InCompTy->getVectorComponentCount(); |
| 3914 |
InCompTy = InCompTy->getVectorComponentType(); |
| 3915 |
} |
| 3916 |
|
| 3917 |
auto InstName = OpCodeNameMap::map(OC); |
| 3918 |
SPIRVErrorLog &SPVErrLog = this->getModule()->getErrorLog(); |
| 3919 |
|
| 3920 |
SPVErrLog.checkError( |
| 3921 |
ResCompTy->isTypeFloat(32), SPIRVEC_InvalidInstruction, |
| 3922 |
InstName + "\nResult value must be a scalar or vector of floating-point" |
| 3923 |
" 32-bit type\n"); |
| 3924 |
SPVErrLog.checkError(InCompTy->isTypeFloat(32), SPIRVEC_InvalidInstruction, |
| 3925 |
InstName + |
| 3926 |
"\nInput value must be a scalar or vector of " |
| 3927 |
"floating-point 32-bit type\n"); |
| 3928 |
SPVErrLog.checkError( |
| 3929 |
ResCompCount == InCompCount, SPIRVEC_InvalidInstruction, |
| 3930 |
InstName + "\nInput type must have the same number of components as " |
| 3931 |
"result type\n"); |
| 3932 |
} |
| 3933 |
}; |
| 3934 |
|
| 3935 |
#define _SPIRV_OP(x) \ |
| 3936 |
typedef SPIRVTensorFloat32RoundingINTELInstBase<internal::Op##x> SPIRV##x; |
| 3937 |
_SPIRV_OP(RoundFToTF32INTEL) |
| 3938 |
#undef _SPIRV_OP |
| 3939 |
|
| 3940 |
template <Op OC> class SPIRVReadClockKHRInstBase : public SPIRVUnaryInst<OC> { |
| 3941 |
protected: |
| 3942 |
SPIRVCapVec getRequiredCapability() const override { |
| 3943 |
return getVec(CapabilityShaderClockKHR); |
| 3944 |
} |
| 3945 |
|
| 3946 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3947 |
return ExtensionID::SPV_KHR_shader_clock; |
| 3948 |
} |
| 3949 |
|
| 3950 |
void validate() const override { |
| 3951 |
SPIRVUnaryInst<OC>::validate(); |
| 3952 |
|
| 3953 |
SPIRVType *ResCompTy = this->getType(); |
| 3954 |
SPIRVWord ResCompCount = 1; |
| 3955 |
if (ResCompTy->isTypeVector()) { |
| 3956 |
ResCompCount = ResCompTy->getVectorComponentCount(); |
| 3957 |
ResCompTy = ResCompTy->getVectorComponentType(); |
| 3958 |
} |
| 3959 |
auto InstName = OpCodeNameMap::map(OC); |
| 3960 |
SPIRVErrorLog &SPVErrLog = this->getModule()->getErrorLog(); |
| 3961 |
|
| 3962 |
// check for either 64 bit int type or two element vector of 32 bit int |
| 3963 |
// types. |
| 3964 |
SPVErrLog.checkError( |
| 3965 |
ResCompTy->isTypeInt(64) || |
| 3966 |
(ResCompCount == 2 && ResCompTy->isTypeInt(32)), |
| 3967 |
SPIRVEC_InvalidInstruction, |
| 3968 |
InstName + "\nResult value must be a scalar of integer" |
| 3969 |
" 64-bit type or two element vector of 32-bit type\n"); |
| 3970 |
} |
| 3971 |
}; |
| 3972 |
#define _SPIRV_OP(x, ...) typedef SPIRVReadClockKHRInstBase<Op##x> SPIRV##x; |
| 3973 |
_SPIRV_OP(ReadClockKHR) |
| 3974 |
#undef _SPIRV_OP |
| 3975 |
|
| 3976 |
template <Op OC> class SPIRVBindlessImagesInstBase : public SPIRVUnaryInst<OC> { |
| 3977 |
protected: |
| 3978 |
SPIRVCapVec getRequiredCapability() const override { |
| 3979 |
return getVec(internal::CapabilityBindlessImagesINTEL); |
| 3980 |
} |
| 3981 |
|
| 3982 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 3983 |
return ExtensionID::SPV_INTEL_bindless_images; |
| 3984 |
} |
| 3985 |
|
| 3986 |
void validate() const override { |
| 3987 |
SPIRVUnary::validate(); |
| 3988 |
|
| 3989 |
// validate is a const method, whilst getOperand is non-const method |
| 3990 |
// because it may call a method of class Module that may modify LiteralMap |
| 3991 |
// of Module field. That modification is not impacting validate method for |
| 3992 |
// these instructions, so const_cast is safe here. |
| 3993 |
using SPVBindlessImagesInst = SPIRVBindlessImagesInstBase<OC>; |
| 3994 |
SPIRVValue *Input = |
| 3995 |
const_cast<SPVBindlessImagesInst *>(this)->getOperand(0); |
| 3996 |
SPIRVType *InCompTy = Input->getType(); |
| 3997 |
|
| 3998 |
auto StringAddrMod = [](SPIRVAddressingModelKind Kind) -> std::string { |
| 3999 |
if (Kind == AddressingModelPhysical32) |
| 4000 |
return std::string("Physical32"); |
| 4001 |
if (Kind == AddressingModelPhysical64) |
| 4002 |
return std::string("Physical64"); |
| 4003 |
return std::string("AddressingModel: ") + std::to_string(Kind); |
| 4004 |
}; |
| 4005 |
|
| 4006 |
auto InstName = OpCodeNameMap::map(OC); |
| 4007 |
auto AddrMod = this->getModule()->getAddressingModel(); |
| 4008 |
SPIRVErrorLog &SPVErrLog = this->getModule()->getErrorLog(); |
| 4009 |
SPVErrLog.checkError( |
| 4010 |
(InCompTy->isTypeInt(32) && AddrMod == AddressingModelPhysical32) || |
| 4011 |
(InCompTy->isTypeInt(64) && AddrMod == AddressingModelPhysical64), |
| 4012 |
SPIRVEC_InvalidInstruction, |
| 4013 |
InstName + |
| 4014 |
"\nParameter value must be a 32-bit scalar in case of " |
| 4015 |
"Physical32 addressing model or a 64-bit scalar in case of " |
| 4016 |
"Physical64 addressing model\n" |
| 4017 |
"Type size: " + |
| 4018 |
std::to_string(InCompTy->getBitWidth()) + |
| 4019 |
"\nAddressing model: " + StringAddrMod(AddrMod) + "\n"); |
| 4020 |
|
| 4021 |
SPIRVType *ResTy = this->getType(); |
| 4022 |
SPVErrLog.checkError( |
| 4023 |
(ResTy->isTypeImage() && OC == internal::OpConvertHandleToImageINTEL) || |
| 4024 |
(ResTy->isTypeSampler() && |
| 4025 |
OC == internal::OpConvertHandleToSamplerINTEL) || |
| 4026 |
(ResTy->isTypeSampledImage() && |
| 4027 |
OC == internal::OpConvertHandleToSampledImageINTEL), |
| 4028 |
SPIRVEC_InvalidInstruction, |
| 4029 |
InstName + "\nIncorrect return type of the instruction must be " |
| 4030 |
"image/sampler\n"); |
| 4031 |
} |
| 4032 |
}; |
| 4033 |
#define _SPIRV_OP(x) \ |
| 4034 |
typedef SPIRVBindlessImagesInstBase<internal::Op##x> SPIRV##x; |
| 4035 |
_SPIRV_OP(ConvertHandleToImageINTEL) |
| 4036 |
_SPIRV_OP(ConvertHandleToSamplerINTEL) |
| 4037 |
_SPIRV_OP(ConvertHandleToSampledImageINTEL) |
| 4038 |
#undef _SPIRV_OP |
| 4039 |
|
| 4040 |
class SPIRVSubgroup2DBlockIOINTELInst : public SPIRVInstTemplateBase { |
| 4041 |
public: |
| 4042 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 4043 |
return ExtensionID::SPV_INTEL_2d_block_io; |
| 4044 |
} |
| 4045 |
SPIRVCapVec getRequiredCapability() const override { |
| 4046 |
return getVec(CapabilitySubgroup2DBlockIOINTEL); |
| 4047 |
} |
| 4048 |
}; |
| 4049 |
|
| 4050 |
class SPIRVSubgroup2DBlockLoadTransposeINTELInst |
| 4051 |
: public SPIRVSubgroup2DBlockIOINTELInst { |
| 4052 |
SPIRVCapVec getRequiredCapability() const override { |
| 4053 |
return getVec(CapabilitySubgroup2DBlockTransposeINTEL); |
| 4054 |
} |
| 4055 |
}; |
| 4056 |
|
| 4057 |
class SPIRVSubgroup2DBlockLoadTransformINTELInst |
| 4058 |
: public SPIRVSubgroup2DBlockIOINTELInst { |
| 4059 |
SPIRVCapVec getRequiredCapability() const override { |
| 4060 |
return getVec(CapabilitySubgroup2DBlockTransformINTEL); |
| 4061 |
} |
| 4062 |
}; |
| 4063 |
|
| 4064 |
#define _SPIRV_OP(x, ...) \ |
| 4065 |
typedef SPIRVInstTemplate<SPIRVSubgroup2DBlockIOINTELInst, Op##x##INTEL, \ |
| 4066 |
__VA_ARGS__> \ |
| 4067 |
SPIRV##x##INTEL; |
| 4068 |
_SPIRV_OP(Subgroup2DBlockLoad, false, 11) |
| 4069 |
_SPIRV_OP(Subgroup2DBlockPrefetch, false, 10) |
| 4070 |
_SPIRV_OP(Subgroup2DBlockStore, false, 11) |
| 4071 |
#undef _SPIRV_OP |
| 4072 |
#define _SPIRV_OP(x, ...) \ |
| 4073 |
typedef SPIRVInstTemplate<SPIRVSubgroup2DBlockLoadTransposeINTELInst, \ |
| 4074 |
Op##x##INTEL, __VA_ARGS__> \ |
| 4075 |
SPIRV##x##INTEL; |
| 4076 |
_SPIRV_OP(Subgroup2DBlockLoadTranspose, false, 11) |
| 4077 |
#undef _SPIRV_OP |
| 4078 |
#define _SPIRV_OP(x, ...) \ |
| 4079 |
typedef SPIRVInstTemplate<SPIRVSubgroup2DBlockLoadTransformINTELInst, \ |
| 4080 |
Op##x##INTEL, __VA_ARGS__> \ |
| 4081 |
SPIRV##x##INTEL; |
| 4082 |
_SPIRV_OP(Subgroup2DBlockLoadTransform, false, 11) |
| 4083 |
#undef _SPIRV_OP |
| 4084 |
|
| 4085 |
class SPIRVSubgroupMatrixMultiplyAccumulateINTELInst |
| 4086 |
: public SPIRVInstTemplateBase { |
| 4087 |
public: |
| 4088 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 4089 |
return ExtensionID::SPV_INTEL_subgroup_matrix_multiply_accumulate; |
| 4090 |
} |
| 4091 |
|
| 4092 |
protected: |
| 4093 |
void validate() const override { |
| 4094 |
SPIRVInstTemplateBase::validate(); |
| 4095 |
|
| 4096 |
// Check if FP4 or FP8 matrix operands are used |
| 4097 |
// Operands parameter is the last operand (index 4) |
| 4098 |
auto *NonConstThis = |
| 4099 |
const_cast<SPIRVSubgroupMatrixMultiplyAccumulateINTELInst *>(this); |
| 4100 |
if (NonConstThis->getOperands().size() > 4) { |
| 4101 |
const SPIRVConstant *OperandsConst = |
| 4102 |
static_cast<const SPIRVConstant *>(NonConstThis->getOperand(4)); |
| 4103 |
uint64_t OperandsMask = OperandsConst->getZExtIntValue(); |
| 4104 |
|
| 4105 |
// FP4 operand bits |
| 4106 |
constexpr uint64_t FP4Mask = |
| 4107 |
spv::internal:: |
| 4108 |
IMatrixMultiplyAccumulateOperandsMatrixAPackedFloat4E2M1INTELMask | |
| 4109 |
spv::internal:: |
| 4110 |
IMatrixMultiplyAccumulateOperandsMatrixBPackedFloat4E2M1INTELMask; |
| 4111 |
|
| 4112 |
// FP8 operand bits |
| 4113 |
constexpr uint64_t FP8Mask = |
| 4114 |
spv::internal:: |
| 4115 |
IMatrixMultiplyAccumulateOperandsMatrixAPackedFloat8E4M3INTELMask | |
| 4116 |
spv::internal:: |
| 4117 |
IMatrixMultiplyAccumulateOperandsMatrixBPackedFloat8E4M3INTELMask | |
| 4118 |
spv::internal:: |
| 4119 |
IMatrixMultiplyAccumulateOperandsMatrixAPackedFloat8E5M2INTELMask | |
| 4120 |
spv::internal:: |
| 4121 |
IMatrixMultiplyAccumulateOperandsMatrixBPackedFloat8E5M2INTELMask; |
| 4122 |
|
| 4123 |
if ((OperandsMask & FP4Mask) != 0) { |
| 4124 |
getModule()->getErrorLog().checkError( |
| 4125 |
getModule()->isAllowedToUseExtension( |
| 4126 |
ExtensionID:: |
| 4127 |
SPV_INTEL_subgroup_matrix_multiply_accumulate_float4), |
| 4128 |
SPIRVEC_RequiresExtension, |
| 4129 |
"SPV_INTEL_subgroup_matrix_multiply_accumulate_float4\n" |
| 4130 |
"SubgroupMatrixMultiplyAccumulateINTEL with FP4 operand flags " |
| 4131 |
"requires this extension"); |
| 4132 |
getModule()->addExtension( |
| 4133 |
ExtensionID::SPV_INTEL_subgroup_matrix_multiply_accumulate_float4); |
| 4134 |
} |
| 4135 |
|
| 4136 |
if ((OperandsMask & FP8Mask) != 0) { |
| 4137 |
getModule()->getErrorLog().checkError( |
| 4138 |
getModule()->isAllowedToUseExtension( |
| 4139 |
ExtensionID:: |
| 4140 |
SPV_INTEL_subgroup_matrix_multiply_accumulate_float8), |
| 4141 |
SPIRVEC_RequiresExtension, |
| 4142 |
"SPV_INTEL_subgroup_matrix_multiply_accumulate_float8\n" |
| 4143 |
"SubgroupMatrixMultiplyAccumulateINTEL with FP8 operand flags " |
| 4144 |
"requires this extension"); |
| 4145 |
getModule()->addExtension( |
| 4146 |
ExtensionID::SPV_INTEL_subgroup_matrix_multiply_accumulate_float8); |
| 4147 |
} |
| 4148 |
} |
| 4149 |
} |
| 4150 |
|
| 4151 |
SPIRVCapVec getRequiredCapability() const override { |
| 4152 |
return getVec(CapabilitySubgroupMatrixMultiplyAccumulateINTEL); |
| 4153 |
} |
| 4154 |
}; |
| 4155 |
|
| 4156 |
#define _SPIRV_OP(x, ...) \ |
| 4157 |
typedef SPIRVInstTemplate<SPIRVSubgroupMatrixMultiplyAccumulateINTELInst, \ |
| 4158 |
Op##x##INTEL, __VA_ARGS__> \ |
| 4159 |
SPIRV##x##INTEL; |
| 4160 |
_SPIRV_OP(SubgroupMatrixMultiplyAccumulate, true, 7, true, 4) |
| 4161 |
#undef _SPIRV_OP |
| 4162 |
|
| 4163 |
class SPIRVTernaryBitwiseFunctionINTELInst : public SPIRVInstTemplateBase { |
| 4164 |
public: |
| 4165 |
void validate() const override { |
| 4166 |
SPIRVInstruction::validate(); |
| 4167 |
SPIRVErrorLog &SPVErrLog = this->getModule()->getErrorLog(); |
| 4168 |
std::string InstName = "BitwiseFunctionINTEL"; |
| 4169 |
|
| 4170 |
const SPIRVType *ResTy = this->getType(); |
| 4171 |
SPVErrLog.checkError( |
| 4172 |
ResTy->isTypeInt() || (ResTy->isTypeVector() && |
| 4173 |
ResTy->getVectorComponentType()->isTypeInt()), |
| 4174 |
SPIRVEC_InvalidInstruction, |
| 4175 |
InstName + "\nResult type must be an integer scalar or vector.\n"); |
| 4176 |
|
| 4177 |
auto CommonArgCheck = [this, ResTy, &InstName, |
| 4178 |
&SPVErrLog](size_t ArgI, const char *ArgPlacement) { |
| 4179 |
SPIRVValue *Arg = |
| 4180 |
const_cast<SPIRVTernaryBitwiseFunctionINTELInst *>(this)->getOperand( |
| 4181 |
ArgI); |
| 4182 |
SPVErrLog.checkError( |
| 4183 |
Arg->getType() == ResTy, SPIRVEC_InvalidInstruction, |
| 4184 |
InstName + "\n" + ArgPlacement + |
| 4185 |
" argument must be the same as the result type.\n"); |
| 4186 |
}; |
| 4187 |
|
| 4188 |
CommonArgCheck(0, "First"); |
| 4189 |
CommonArgCheck(1, "Second"); |
| 4190 |
CommonArgCheck(2, "Third"); |
| 4191 |
|
| 4192 |
SPIRVValue *LUTIndexArg = |
| 4193 |
const_cast<SPIRVTernaryBitwiseFunctionINTELInst *>(this)->getOperand(3); |
| 4194 |
const SPIRVType *LUTIndexArgTy = LUTIndexArg->getType(); |
| 4195 |
SPVErrLog.checkError( |
| 4196 |
LUTIndexArgTy->isTypeInt(32), SPIRVEC_InvalidInstruction, |
| 4197 |
InstName + "\nFourth argument must be a 32-bit integer scalar.\n"); |
| 4198 |
SPVErrLog.checkError( |
| 4199 |
isConstantOpCode(LUTIndexArg->getOpCode()), SPIRVEC_InvalidInstruction, |
| 4200 |
InstName + "\nFourth argument must be constant instruction.\n"); |
| 4201 |
} |
| 4202 |
|
| 4203 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 4204 |
return ExtensionID::SPV_INTEL_ternary_bitwise_function; |
| 4205 |
} |
| 4206 |
SPIRVCapVec getRequiredCapability() const override { |
| 4207 |
return getVec(CapabilityTernaryBitwiseFunctionINTEL); |
| 4208 |
} |
| 4209 |
}; |
| 4210 |
|
| 4211 |
#define _SPIRV_OP(x, ...) \ |
| 4212 |
typedef SPIRVInstTemplate<SPIRVTernaryBitwiseFunctionINTELInst, \ |
| 4213 |
Op##x##INTEL, __VA_ARGS__> \ |
| 4214 |
SPIRV##x##INTEL; |
| 4215 |
_SPIRV_OP(BitwiseFunction, true, 7) |
| 4216 |
#undef _SPIRV_OP |
| 4217 |
|
| 4218 |
class SPIRVPredicatedIOINTELInst : public SPIRVInstTemplateBase { |
| 4219 |
public: |
| 4220 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 4221 |
return ExtensionID::SPV_INTEL_predicated_io; |
| 4222 |
} |
| 4223 |
SPIRVCapVec getRequiredCapability() const override { |
| 4224 |
return getVec(internal::CapabilityPredicatedIOINTEL); |
| 4225 |
} |
| 4226 |
}; |
| 4227 |
|
| 4228 |
#define _SPIRV_OP(x, ...) \ |
| 4229 |
typedef SPIRVInstTemplate<SPIRVPredicatedIOINTELInst, \ |
| 4230 |
internal::Op##x##INTEL, __VA_ARGS__> \ |
| 4231 |
SPIRV##x##INTEL; |
| 4232 |
_SPIRV_OP(PredicatedLoad, true, 6, true) |
| 4233 |
_SPIRV_OP(PredicatedStore, false, 4, true) |
| 4234 |
#undef _SPIRV_OP |
| 4235 |
|
| 4236 |
template <Op OC> class SPIRVFSigmoidINTELInstBase : public SPIRVUnaryInst<OC> { |
| 4237 |
public: |
| 4238 |
SPIRVCapVec getRequiredCapability() const override { |
| 4239 |
return getVec(internal::CapabilitySigmoidINTEL); |
| 4240 |
} |
| 4241 |
|
| 4242 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 4243 |
return ExtensionID::SPV_INTEL_sigmoid; |
| 4244 |
} |
| 4245 |
|
| 4246 |
void validate() const override { |
| 4247 |
SPIRVUnaryInst<OC>::validate(); |
| 4248 |
|
| 4249 |
SPIRVType *ResCompTy = this->getType(); |
| 4250 |
SPIRVWord ResCompCount = 1; |
| 4251 |
if (ResCompTy->isTypeVector()) { |
| 4252 |
ResCompCount = ResCompTy->getVectorComponentCount(); |
| 4253 |
ResCompTy = ResCompTy->getVectorComponentType(); |
| 4254 |
} |
| 4255 |
|
| 4256 |
// validate is a const method, whilst getOperand is non-const method |
| 4257 |
// because it may call a method of class Module that may modify LiteralMap |
| 4258 |
// of Module field. That modification is not impacting validate method for |
| 4259 |
// these instructions, so const_cast is safe here. |
| 4260 |
using SPVFSigmoidTy = SPIRVFSigmoidINTELInstBase<OC>; |
| 4261 |
const SPIRVValue *Input = const_cast<SPVFSigmoidTy *>(this)->getOperand(0); |
| 4262 |
|
| 4263 |
SPIRVType *InCompTy = Input->getType(); |
| 4264 |
SPIRVWord InCompCount = 1; |
| 4265 |
if (InCompTy->isTypeVector()) { |
| 4266 |
InCompCount = InCompTy->getVectorComponentCount(); |
| 4267 |
InCompTy = InCompTy->getVectorComponentType(); |
| 4268 |
} |
| 4269 |
|
| 4270 |
auto InstName = OpCodeNameMap::map(OC); |
| 4271 |
SPIRVErrorLog &SPVErrLog = this->getModule()->getErrorLog(); |
| 4272 |
|
| 4273 |
SPVErrLog.checkError( |
| 4274 |
ResCompTy->isTypeFloat(16) || ResCompTy->isTypeFloat(32) || |
| 4275 |
ResCompTy->isTypeFloat(16, FPEncodingBFloat16KHR), |
| 4276 |
SPIRVEC_InvalidInstruction, |
| 4277 |
InstName + "\nResult value must be a scalar or vector of floating-point" |
| 4278 |
" 16-bit or 32-bit type\n"); |
| 4279 |
SPVErrLog.checkError( |
| 4280 |
ResCompTy == InCompTy, SPIRVEC_InvalidInstruction, |
| 4281 |
InstName + |
| 4282 |
"\nInput type must have the same component type as result type\n"); |
| 4283 |
SPVErrLog.checkError( |
| 4284 |
ResCompCount == InCompCount, SPIRVEC_InvalidInstruction, |
| 4285 |
InstName + "\nInput type must have the same number of components as " |
| 4286 |
"result type\n"); |
| 4287 |
} |
| 4288 |
}; |
| 4289 |
|
| 4290 |
#define _SPIRV_OP(x, ...) \ |
| 4291 |
typedef SPIRVFSigmoidINTELInstBase<internal::Op##x> SPIRV##x; |
| 4292 |
_SPIRV_OP(FSigmoidINTEL) |
| 4293 |
#undef _SPIRV_OP |
| 4294 |
|
| 4295 |
class SPIRVFPConversionINTELInstBase : public SPIRVInstTemplateBase { |
| 4296 |
public: |
| 4297 |
SPIRVCapVec getRequiredCapability() const override { |
| 4298 |
return getVec(internal::CapabilityFloatConversionsINTEL); |
| 4299 |
} |
| 4300 |
|
| 4301 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 4302 |
return ExtensionID::SPV_INTEL_fp_conversions; |
| 4303 |
} |
| 4304 |
}; |
| 4305 |
#define _SPIRV_OP(x, ...) \ |
| 4306 |
typedef SPIRVInstTemplate<SPIRVFPConversionINTELInstBase, \ |
| 4307 |
internal::Op##x##INTEL, __VA_ARGS__> \ |
| 4308 |
SPIRV##x##INTEL; |
| 4309 |
_SPIRV_OP(ClampConvertFToF, true, 4, false) |
| 4310 |
_SPIRV_OP(ClampConvertFToS, true, 4, false) |
| 4311 |
_SPIRV_OP(StochasticRoundFToF, true, 5, true) |
| 4312 |
_SPIRV_OP(ClampStochasticRoundFToF, true, 5, true) |
| 4313 |
_SPIRV_OP(ClampStochasticRoundFToS, true, 5, true) |
| 4314 |
#undef _SPIRV_OP |
| 4315 |
|
| 4316 |
class SPIRVFmaKHRInstBase : public SPIRVInstTemplateBase { |
| 4317 |
public: |
| 4318 |
SPIRVCapVec getRequiredCapability() const override { |
| 4319 |
return getVec(CapabilityFMAKHR); |
| 4320 |
} |
| 4321 |
|
| 4322 |
std::optional<ExtensionID> getRequiredExtension() const override { |
| 4323 |
return ExtensionID::SPV_KHR_fma; |
| 4324 |
} |
| 4325 |
}; |
| 4326 |
|
| 4327 |
typedef SPIRVInstTemplate<SPIRVFmaKHRInstBase, OpFmaKHR, true, 6, false> |
| 4328 |
SPIRVFmaKHR; |
| 4329 |
|
| 4330 |
} // namespace SPIRV |
| 4331 |
#endif // SPIRV_LIBSPIRV_SPIRVINSTRUCTION_H |