Path: blob/main/contrib/llvm-project/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.h
35294 views
//===-- SPIRVBaseInfo.h - Top level SPIRV definitions -----------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file contains TableGen generated enum definitions, mnemonic lookup9// functions, versioning/capabilities/extensions getters for symbolic/named10// operands for various SPIR-V instructions.11//12//===----------------------------------------------------------------------===//1314#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVSYMBOLICOPERANDS_H15#define LLVM_LIB_TARGET_SPIRV_SPIRVSYMBOLICOPERANDS_H1617#include "llvm/ADT/SmallVector.h"18#include "llvm/ADT/StringRef.h"19#include "llvm/Support/VersionTuple.h"20#include <string>2122namespace llvm {23namespace SPIRV {24namespace OperandCategory {25#define GET_OperandCategory_DECL26#include "SPIRVGenTables.inc"27} // namespace OperandCategory2829namespace Extension {30#define GET_Extension_DECL31#include "SPIRVGenTables.inc"32} // namespace Extension3334namespace Capability {35#define GET_Capability_DECL36#include "SPIRVGenTables.inc"37} // namespace Capability3839namespace SourceLanguage {40#define GET_SourceLanguage_DECL41#include "SPIRVGenTables.inc"42} // namespace SourceLanguage4344namespace AddressingModel {45#define GET_AddressingModel_DECL46#include "SPIRVGenTables.inc"47} // namespace AddressingModel4849namespace ExecutionModel {50#define GET_ExecutionModel_DECL51#include "SPIRVGenTables.inc"52} // namespace ExecutionModel5354namespace MemoryModel {55#define GET_MemoryModel_DECL56#include "SPIRVGenTables.inc"57} // namespace MemoryModel5859namespace ExecutionMode {60#define GET_ExecutionMode_DECL61#include "SPIRVGenTables.inc"62} // namespace ExecutionMode6364namespace StorageClass {65#define GET_StorageClass_DECL66#include "SPIRVGenTables.inc"67} // namespace StorageClass6869namespace Dim {70#define GET_Dim_DECL71#include "SPIRVGenTables.inc"72} // namespace Dim7374namespace SamplerAddressingMode {75#define GET_SamplerAddressingMode_DECL76#include "SPIRVGenTables.inc"77} // namespace SamplerAddressingMode7879namespace SamplerFilterMode {80#define GET_SamplerFilterMode_DECL81#include "SPIRVGenTables.inc"82} // namespace SamplerFilterMode8384namespace ImageFormat {85#define GET_ImageFormat_DECL86#include "SPIRVGenTables.inc"87} // namespace ImageFormat8889namespace ImageChannelOrder {90#define GET_ImageChannelOrder_DECL91#include "SPIRVGenTables.inc"92} // namespace ImageChannelOrder9394namespace ImageChannelDataType {95#define GET_ImageChannelDataType_DECL96#include "SPIRVGenTables.inc"97} // namespace ImageChannelDataType9899namespace ImageOperand {100#define GET_ImageOperand_DECL101#include "SPIRVGenTables.inc"102} // namespace ImageOperand103104namespace FPFastMathMode {105#define GET_FPFastMathMode_DECL106#include "SPIRVGenTables.inc"107} // namespace FPFastMathMode108109namespace FPRoundingMode {110#define GET_FPRoundingMode_DECL111#include "SPIRVGenTables.inc"112} // namespace FPRoundingMode113114namespace LinkageType {115#define GET_LinkageType_DECL116#include "SPIRVGenTables.inc"117} // namespace LinkageType118119namespace AccessQualifier {120#define GET_AccessQualifier_DECL121#include "SPIRVGenTables.inc"122} // namespace AccessQualifier123124namespace FunctionParameterAttribute {125#define GET_FunctionParameterAttribute_DECL126#include "SPIRVGenTables.inc"127} // namespace FunctionParameterAttribute128129namespace Decoration {130#define GET_Decoration_DECL131#include "SPIRVGenTables.inc"132} // namespace Decoration133134namespace BuiltIn {135#define GET_BuiltIn_DECL136#include "SPIRVGenTables.inc"137} // namespace BuiltIn138139namespace SelectionControl {140#define GET_SelectionControl_DECL141#include "SPIRVGenTables.inc"142} // namespace SelectionControl143144namespace LoopControl {145#define GET_LoopControl_DECL146#include "SPIRVGenTables.inc"147} // namespace LoopControl148149namespace FunctionControl {150#define GET_FunctionControl_DECL151#include "SPIRVGenTables.inc"152} // namespace FunctionControl153154namespace MemorySemantics {155#define GET_MemorySemantics_DECL156#include "SPIRVGenTables.inc"157} // namespace MemorySemantics158159namespace MemoryOperand {160#define GET_MemoryOperand_DECL161#include "SPIRVGenTables.inc"162} // namespace MemoryOperand163164namespace Scope {165#define GET_Scope_DECL166#include "SPIRVGenTables.inc"167} // namespace Scope168169namespace GroupOperation {170#define GET_GroupOperation_DECL171#include "SPIRVGenTables.inc"172} // namespace GroupOperation173174namespace KernelEnqueueFlags {175#define GET_KernelEnqueueFlags_DECL176#include "SPIRVGenTables.inc"177} // namespace KernelEnqueueFlags178179namespace KernelProfilingInfo {180#define GET_KernelProfilingInfo_DECL181#include "SPIRVGenTables.inc"182} // namespace KernelProfilingInfo183184namespace InstructionSet {185#define GET_InstructionSet_DECL186#include "SPIRVGenTables.inc"187} // namespace InstructionSet188189namespace OpenCLExtInst {190#define GET_OpenCLExtInst_DECL191#include "SPIRVGenTables.inc"192} // namespace OpenCLExtInst193194namespace GLSLExtInst {195#define GET_GLSLExtInst_DECL196#include "SPIRVGenTables.inc"197} // namespace GLSLExtInst198199namespace NonSemanticExtInst {200#define GET_NonSemanticExtInst_DECL201#include "SPIRVGenTables.inc"202} // namespace NonSemanticExtInst203204namespace Opcode {205#define GET_Opcode_DECL206#include "SPIRVGenTables.inc"207} // namespace Opcode208209struct ExtendedBuiltin {210StringRef Name;211InstructionSet::InstructionSet Set;212uint32_t Number;213};214} // namespace SPIRV215216using CapabilityList = SmallVector<SPIRV::Capability::Capability, 8>;217using ExtensionList = SmallVector<SPIRV::Extension::Extension, 8>;218219std::string220getSymbolicOperandMnemonic(SPIRV::OperandCategory::OperandCategory Category,221int32_t Value);222VersionTuple223getSymbolicOperandMinVersion(SPIRV::OperandCategory::OperandCategory Category,224uint32_t Value);225VersionTuple226getSymbolicOperandMaxVersion(SPIRV::OperandCategory::OperandCategory Category,227uint32_t Value);228CapabilityList229getSymbolicOperandCapabilities(SPIRV::OperandCategory::OperandCategory Category,230uint32_t Value);231CapabilityList232getCapabilitiesEnabledByExtension(SPIRV::Extension::Extension Extension);233ExtensionList234getSymbolicOperandExtensions(SPIRV::OperandCategory::OperandCategory Category,235uint32_t Value);236std::string getLinkStringForBuiltIn(SPIRV::BuiltIn::BuiltIn BuiltInValue);237238bool getSpirvBuiltInIdByName(StringRef Name, SPIRV::BuiltIn::BuiltIn &BI);239240std::string getExtInstSetName(SPIRV::InstructionSet::InstructionSet Set);241SPIRV::InstructionSet::InstructionSet242getExtInstSetFromString(std::string SetName);243std::string getExtInstName(SPIRV::InstructionSet::InstructionSet Set,244uint32_t InstructionNumber);245246// Return a string representation of the operands from startIndex onwards.247// Templated to allow both MachineInstr and MCInst to use the same logic.248template <class InstType>249std::string getSPIRVStringOperand(const InstType &MI, unsigned StartIndex) {250std::string s; // Iteratively append to this string.251252const unsigned NumOps = MI.getNumOperands();253bool IsFinished = false;254for (unsigned i = StartIndex; i < NumOps && !IsFinished; ++i) {255const auto &Op = MI.getOperand(i);256if (!Op.isImm()) // Stop if we hit a register operand.257break;258assert((Op.getImm() >> 32) == 0 && "Imm operand should be i32 word");259const uint32_t Imm = Op.getImm(); // Each i32 word is up to 4 characters.260for (unsigned ShiftAmount = 0; ShiftAmount < 32; ShiftAmount += 8) {261char c = (Imm >> ShiftAmount) & 0xff;262if (c == 0) { // Stop if we hit a null-terminator character.263IsFinished = true;264break;265}266s += c; // Otherwise, append the character to the result string.267}268}269return s;270}271} // namespace llvm272#endif // LLVM_LIB_TARGET_SPIRV_SPIRVSYMBOLICOPERANDS_H273274275