brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.9 KiB · ea41716 Raw
315 lines · c
1//===-- SPIRVBaseInfo.h - Top level SPIRV definitions -----------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8//9// This file contains TableGen generated enum definitions, mnemonic lookup10// functions, versioning/capabilities/extensions getters for symbolic/named11// operands for various SPIR-V instructions.12//13//===----------------------------------------------------------------------===//14 15#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVSYMBOLICOPERANDS_H16#define LLVM_LIB_TARGET_SPIRV_SPIRVSYMBOLICOPERANDS_H17 18#include "llvm/ADT/SmallVector.h"19#include "llvm/ADT/StringRef.h"20#include "llvm/Support/VersionTuple.h"21#include <string>22 23namespace llvm {24namespace SPIRV {25namespace OperandCategory {26#define GET_OperandCategory_DECL27#include "SPIRVGenTables.inc"28} // namespace OperandCategory29 30namespace Extension {31#define GET_Extension_DECL32#include "SPIRVGenTables.inc"33} // namespace Extension34 35namespace Capability {36#define GET_Capability_DECL37#include "SPIRVGenTables.inc"38} // namespace Capability39 40namespace Environment {41#define GET_Environment_DECL42#include "SPIRVGenTables.inc"43} // namespace Environment44 45namespace SourceLanguage {46#define GET_SourceLanguage_DECL47#include "SPIRVGenTables.inc"48} // namespace SourceLanguage49 50namespace AddressingModel {51#define GET_AddressingModel_DECL52#include "SPIRVGenTables.inc"53} // namespace AddressingModel54 55namespace ExecutionModel {56#define GET_ExecutionModel_DECL57#include "SPIRVGenTables.inc"58} // namespace ExecutionModel59 60namespace MemoryModel {61#define GET_MemoryModel_DECL62#include "SPIRVGenTables.inc"63} // namespace MemoryModel64 65namespace MatrixMultiplyAccumulateOperands {66#define GET_MatrixMultiplyAccumulateOperands_DECL67#include "SPIRVGenTables.inc"68} // namespace MatrixMultiplyAccumulateOperands69 70namespace ExecutionMode {71#define GET_ExecutionMode_DECL72#include "SPIRVGenTables.inc"73} // namespace ExecutionMode74 75namespace StorageClass {76#define GET_StorageClass_DECL77#include "SPIRVGenTables.inc"78} // namespace StorageClass79 80namespace Dim {81#define GET_Dim_DECL82#include "SPIRVGenTables.inc"83} // namespace Dim84 85namespace SamplerAddressingMode {86#define GET_SamplerAddressingMode_DECL87#include "SPIRVGenTables.inc"88} // namespace SamplerAddressingMode89 90namespace SamplerFilterMode {91#define GET_SamplerFilterMode_DECL92#include "SPIRVGenTables.inc"93} // namespace SamplerFilterMode94 95namespace ImageFormat {96#define GET_ImageFormat_DECL97#include "SPIRVGenTables.inc"98} // namespace ImageFormat99 100namespace ImageChannelOrder {101#define GET_ImageChannelOrder_DECL102#include "SPIRVGenTables.inc"103} // namespace ImageChannelOrder104 105namespace ImageChannelDataType {106#define GET_ImageChannelDataType_DECL107#include "SPIRVGenTables.inc"108} // namespace ImageChannelDataType109 110namespace ImageOperand {111#define GET_ImageOperand_DECL112#include "SPIRVGenTables.inc"113} // namespace ImageOperand114 115namespace FPFastMathMode {116#define GET_FPFastMathMode_DECL117#include "SPIRVGenTables.inc"118} // namespace FPFastMathMode119 120namespace FPRoundingMode {121#define GET_FPRoundingMode_DECL122#include "SPIRVGenTables.inc"123} // namespace FPRoundingMode124 125namespace LinkageType {126#define GET_LinkageType_DECL127#include "SPIRVGenTables.inc"128} // namespace LinkageType129 130namespace AccessQualifier {131#define GET_AccessQualifier_DECL132#include "SPIRVGenTables.inc"133} // namespace AccessQualifier134 135namespace FunctionParameterAttribute {136#define GET_FunctionParameterAttribute_DECL137#include "SPIRVGenTables.inc"138} // namespace FunctionParameterAttribute139 140namespace Decoration {141#define GET_Decoration_DECL142#include "SPIRVGenTables.inc"143} // namespace Decoration144 145namespace BuiltIn {146#define GET_BuiltIn_DECL147#include "SPIRVGenTables.inc"148} // namespace BuiltIn149 150namespace SelectionControl {151#define GET_SelectionControl_DECL152#include "SPIRVGenTables.inc"153} // namespace SelectionControl154 155namespace LoopControl {156#define GET_LoopControl_DECL157#include "SPIRVGenTables.inc"158} // namespace LoopControl159 160namespace FunctionControl {161#define GET_FunctionControl_DECL162#include "SPIRVGenTables.inc"163} // namespace FunctionControl164 165namespace MemorySemantics {166#define GET_MemorySemantics_DECL167#include "SPIRVGenTables.inc"168} // namespace MemorySemantics169 170namespace MemoryOperand {171#define GET_MemoryOperand_DECL172#include "SPIRVGenTables.inc"173} // namespace MemoryOperand174 175namespace Scope {176#define GET_Scope_DECL177#include "SPIRVGenTables.inc"178} // namespace Scope179 180namespace GroupOperation {181#define GET_GroupOperation_DECL182#include "SPIRVGenTables.inc"183} // namespace GroupOperation184 185namespace KernelEnqueueFlags {186#define GET_KernelEnqueueFlags_DECL187#include "SPIRVGenTables.inc"188} // namespace KernelEnqueueFlags189 190namespace KernelProfilingInfo {191#define GET_KernelProfilingInfo_DECL192#include "SPIRVGenTables.inc"193} // namespace KernelProfilingInfo194 195namespace InstructionSet {196#define GET_InstructionSet_DECL197#include "SPIRVGenTables.inc"198} // namespace InstructionSet199 200namespace OpenCLExtInst {201#define GET_OpenCLExtInst_DECL202#include "SPIRVGenTables.inc"203} // namespace OpenCLExtInst204 205namespace GLSLExtInst {206#define GET_GLSLExtInst_DECL207#include "SPIRVGenTables.inc"208} // namespace GLSLExtInst209 210namespace NonSemanticExtInst {211#define GET_NonSemanticExtInst_DECL212#include "SPIRVGenTables.inc"213} // namespace NonSemanticExtInst214 215namespace Opcode {216#define GET_Opcode_DECL217#include "SPIRVGenTables.inc"218} // namespace Opcode219 220namespace CooperativeMatrixLayout {221#define GET_CooperativeMatrixLayout_DECL222#include "SPIRVGenTables.inc"223} // namespace CooperativeMatrixLayout224 225namespace CooperativeMatrixOperands {226#define GET_CooperativeMatrixOperands_DECL227#include "SPIRVGenTables.inc"228} // namespace CooperativeMatrixOperands229 230namespace SpecConstantOpOperands {231#define GET_SpecConstantOpOperands_DECL232#include "SPIRVGenTables.inc"233} // namespace SpecConstantOpOperands234 235namespace FPEncoding {236#define GET_FPEncoding_DECL237#include "SPIRVGenTables.inc"238} // namespace FPEncoding239 240struct ExtendedBuiltin {241  StringRef Name;242  InstructionSet::InstructionSet Set;243  uint32_t Number;244};245 246enum InstFlags {247  // It is a half type248  INST_PRINTER_WIDTH16 = 1,249  // It is a 64-bit type250  INST_PRINTER_WIDTH64 = INST_PRINTER_WIDTH16 << 1,251 252};253} // namespace SPIRV254 255using CapabilityList = SmallVector<SPIRV::Capability::Capability, 8>;256using ExtensionList = SmallVector<SPIRV::Extension::Extension, 8>;257using EnvironmentList = SmallVector<SPIRV::Environment::Environment, 8>;258 259std::string260getSymbolicOperandMnemonic(SPIRV::OperandCategory::OperandCategory Category,261                           int32_t Value);262VersionTuple263getSymbolicOperandMinVersion(SPIRV::OperandCategory::OperandCategory Category,264                             uint32_t Value);265VersionTuple266getSymbolicOperandMaxVersion(SPIRV::OperandCategory::OperandCategory Category,267                             uint32_t Value);268CapabilityList269getSymbolicOperandCapabilities(SPIRV::OperandCategory::OperandCategory Category,270                               uint32_t Value);271EnvironmentList getSymbolicOperandAllowedEnvironments(272    SPIRV::OperandCategory::OperandCategory Category, uint32_t Value);273CapabilityList274getCapabilitiesEnabledByExtension(SPIRV::Extension::Extension Extension);275ExtensionList276getSymbolicOperandExtensions(SPIRV::OperandCategory::OperandCategory Category,277                             uint32_t Value);278std::string getLinkStringForBuiltIn(SPIRV::BuiltIn::BuiltIn BuiltInValue);279 280bool getSpirvBuiltInIdByName(StringRef Name, SPIRV::BuiltIn::BuiltIn &BI);281 282std::string getExtInstSetName(SPIRV::InstructionSet::InstructionSet Set);283SPIRV::InstructionSet::InstructionSet284getExtInstSetFromString(std::string SetName);285std::string getExtInstName(SPIRV::InstructionSet::InstructionSet Set,286                           uint32_t InstructionNumber);287 288// Return a string representation of the operands from startIndex onwards.289// Templated to allow both MachineInstr and MCInst to use the same logic.290template <class InstType>291std::string getSPIRVStringOperand(const InstType &MI, unsigned StartIndex) {292  std::string s; // Iteratively append to this string.293 294  const unsigned NumOps = MI.getNumOperands();295  bool IsFinished = false;296  for (unsigned i = StartIndex; i < NumOps && !IsFinished; ++i) {297    const auto &Op = MI.getOperand(i);298    if (!Op.isImm()) // Stop if we hit a register operand.299      break;300    assert((Op.getImm() >> 32) == 0 && "Imm operand should be i32 word");301    const uint32_t Imm = Op.getImm(); // Each i32 word is up to 4 characters.302    for (unsigned ShiftAmount = 0; ShiftAmount < 32; ShiftAmount += 8) {303      char c = (Imm >> ShiftAmount) & 0xff;304      if (c == 0) { // Stop if we hit a null-terminator character.305        IsFinished = true;306        break;307      }308      s += c; // Otherwise, append the character to the result string.309    }310  }311  return s;312}313} // namespace llvm314#endif // LLVM_LIB_TARGET_SPIRV_SPIRVSYMBOLICOPERANDS_H315