// Copyright (c) 2020 The Khronos Group Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and/or associated documentation files (the "Materials"),
// to deal in the Materials without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Materials, and to permit persons to whom the
// Materials are furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Materials.
//
// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
// IN THE MATERIALS.

// The header is for SPIR-V to LLVM IR internal definitions, that are not a part
// of Khronos SPIR-V specification.

#include "spirv/unified1/spirv.hpp"

#ifndef spirv_internal_HPP
#define spirv_internal_HPP

namespace spv {
namespace internal {

enum InternalSourceLanguageNonSemanticDI {
  ISourceLanguagePython = 200,
  ISourceLanguageJulia = 201,
  ISourceLanguageRust = 202,
  ISourceLanguageD = 203,
  ISourceLanguageFortran77 = 204,
  ISourceLanguageFortran90 = 205,
  ISourceLanguageFortran95 = 206,
  ISourceLanguageFortran2003 = 207,
  ISourceLanguageFortran2008 = 208,
  ISourceLanguageFortran2018 = 209,
  ISourceLanguageC = 210,
  ISourceLanguageC99 = 211,
  ISourceLanguageC11 = 212,
  ISourceLanguageC17 = 213,
  ISourceLanguageCPP = 214,
  ISourceLanguageCPP03 = 215,
  ISourceLanguageCPP11 = 216,
  ISourceLanguageCPP14 = 217,
  ISourceLanguageCPP17 = 218,
  ISourceLanguageCPP20 = 219,
};

enum InternalLinkageType {
    ILTPrev = LinkageTypeMax - 2,
    ILTInternal
};

enum InternalOp {
  IOpTypeTokenINTEL = 6113,
  IOpTaskSequenceCreateINTEL = 6163,
  IOpTaskSequenceAsyncINTEL = 6164,
  IOpTaskSequenceGetINTEL = 6165,
  IOpTaskSequenceReleaseINTEL = 6166,
  IOpCooperativeMatrixLoadCheckedINTEL = 6193,
  IOpCooperativeMatrixStoreCheckedINTEL = 6194,
  IOpCooperativeMatrixConstructCheckedINTEL = 6195,
  IOpTypeTaskSequenceINTEL = 6199,
  IOpClampConvertFToFINTEL = 6216, // old op, for backward compatibility
  IOpStochasticRoundFToFINTEL = 6217,
  IOpClampStochasticRoundFToFINTEL = 6218, // old op, for backward compatibility
  IOpClampStochasticRoundFToSINTEL = 6219,
  IOpCooperativeMatrixLoadOffsetINTEL = 6239,
  IOpCooperativeMatrixStoreOffsetINTEL = 6240,
  IOpSubgroupScaledMatrixMultiplyAccumulateINTEL = 6264,
  IOpClampConvertFToSINTEL = 6424,
  IOpMaskedGatherINTEL = 6428,
  IOpMaskedScatterINTEL = 6429,
  IOpJointMatrixGetElementCoordINTEL = 6440,
  IOpCooperativeMatrixApplyFunctionINTEL = 6448,
  IOpCooperativeMatrixPrefetchINTEL = 6449,
  IOpConvertHandleToImageINTEL = 6529,
  IOpConvertHandleToSamplerINTEL = 6530,
  IOpConvertHandleToSampledImageINTEL = 6531,
  IOpFSigmoidINTEL = 6168,
  IOpPrev = OpMax - 2,
  IOpForward
};

enum InternalDecoration {
  IDecRuntimeAlignedINTEL = 5940,
  IDecCallableFunctionINTEL = 6087,
  IDecHostAccessINTEL = 6147,
  IDecInitModeINTEL = 6148,
  IDecImplementInCSRINTEL = 6149,
  IDecArgumentAttributeINTEL = 6409,
};

enum InternalCapability {
  ICapTokenTypeINTEL = 6112,
  ICapabilityHWThreadQueryINTEL = 6134,
  ICapGlobalVariableDecorationsINTEL = 6146,
  ICapabilityTaskSequenceINTEL = 6162,
  ICapabilitySigmoidINTEL = 6167,
  ICapabilityDeviceBarrierINTEL = 6185,
  ICapabilityCooperativeMatrixCheckedInstructionsINTEL = 6192,
  ICapabilityFloat4E2M1INTEL = 6212,
  ICapabilityFloat4E2M1CooperativeMatrixINTEL = 6213,
  ICapabilityFloatConversionsFtoFINTEL = 6215,
  ICapabilityFloatConversionsFtoSINTEL = 6216,
  ICapabilityBFloat16ArithmeticINTEL = 6226,
  ICapabilityCooperativeMatrixOffsetInstructionsINTEL = 6238,
  ICapabilityAtomicBFloat16AddINTEL = 6255,
  ICapabilityAtomicBFloat16MinMaxINTEL = 6256,
  ICapabilityAtomicInt16CompareExchangeINTEL = 6260,
  ICapabilityInt16AtomicsINTEL = 6261,
  ICapabilityAtomicBFloat16LoadStoreINTEL = 6262,
  ICapabilitySubgroupScaledMatrixMultiplyAccumulateINTEL = 6263,
  ICapabilityCooperativeMatrixPrefetchINTEL = 6411,
  ICapabilityMaskedGatherScatterINTEL = 6427,
  ICapabilityJointMatrixWIInstructionsINTEL = 6435,
  ICapabilityCooperativeMatrixInvocationInstructionsINTEL = 6435,
  ICapabilityCooperativeMatrixTF32ComponentTypeINTEL = 6436,
  ICapabilityCooperativeMatrixBFloat16ComponentTypeINTEL = 6437,
  ICapabilitySubgroupRequirementsINTEL = 6445,
  ICapabilityBindlessImagesINTEL = 6528
};

enum InternalExecutionMode {
  IExecModeNamedSubgroupSizeINTEL = 6446,
};

constexpr LinkageType LinkageTypeInternal =
    static_cast<LinkageType>(ILTInternal);

enum InternalJointMatrixLayout {
  RowMajor = 0,
  ColumnMajor = 1,
  PackedA = 2,
  PackedB = 3
};

enum InternalFPEncoding {
  FPEncodingFloat4E2M1INTEL = 6214,
  FPEncodingMax = 0x7fffffff,
};

enum InternalBuiltIn {
  IBuiltInSubDeviceIDINTEL = 6135,
  IBuiltInGlobalHWThreadIDINTEL = 6136,
  IBuiltInDeviceBarrierValidINTEL = 6186,
};

enum InternalMatrixMultiplyAccumulateOperandsMask {
  // FP8 matrix operands
  IMatrixMultiplyAccumulateOperandsMatrixAPackedFloat8E4M3INTELMask = 0x4000,
  IMatrixMultiplyAccumulateOperandsMatrixBPackedFloat8E4M3INTELMask = 0x8000,
  IMatrixMultiplyAccumulateOperandsMatrixAPackedFloat8E5M2INTELMask = 0x10000,
  IMatrixMultiplyAccumulateOperandsMatrixBPackedFloat8E5M2INTELMask = 0x20000,
  // FP4 matrix operands
  IMatrixMultiplyAccumulateOperandsMatrixAPackedFloat4E2M1INTELMask = 0x40000,
  IMatrixMultiplyAccumulateOperandsMatrixBPackedFloat4E2M1INTELMask = 0x80000,
  // Scale factors for SPV_INTEL_subgroup_scaled_matrix_multiply_accumulate.
  IMatrixMultiplyAccumulateOperandsScaleAFloat8E8M0INTELMask = 0x100000,
  IMatrixMultiplyAccumulateOperandsScaleBFloat8E8M0INTELMask = 0x200000,
};

#define _SPIRV_OP(x, y) constexpr x x##y = static_cast<x>(I##x##y);
_SPIRV_OP(Capability, JointMatrixWIInstructionsINTEL)
_SPIRV_OP(Capability, CooperativeMatrixTF32ComponentTypeINTEL)
_SPIRV_OP(Capability, CooperativeMatrixBFloat16ComponentTypeINTEL)
_SPIRV_OP(Op, JointMatrixGetElementCoordINTEL)

_SPIRV_OP(Capability, CooperativeMatrixPrefetchINTEL)
_SPIRV_OP(Op, CooperativeMatrixPrefetchINTEL)

_SPIRV_OP(Capability, CooperativeMatrixCheckedInstructionsINTEL)
_SPIRV_OP(Op, CooperativeMatrixLoadCheckedINTEL)
_SPIRV_OP(Op, CooperativeMatrixStoreCheckedINTEL)
_SPIRV_OP(Op, CooperativeMatrixConstructCheckedINTEL)

_SPIRV_OP(Capability, CooperativeMatrixOffsetInstructionsINTEL)
_SPIRV_OP(Op, CooperativeMatrixLoadOffsetINTEL)
_SPIRV_OP(Op, CooperativeMatrixStoreOffsetINTEL)

_SPIRV_OP(Capability, CooperativeMatrixInvocationInstructionsINTEL)
_SPIRV_OP(Op, CooperativeMatrixApplyFunctionINTEL)

_SPIRV_OP(Capability, DeviceBarrierINTEL)
_SPIRV_OP(BuiltIn, DeviceBarrierValidINTEL)

_SPIRV_OP(Capability, HWThreadQueryINTEL)
_SPIRV_OP(BuiltIn, SubDeviceIDINTEL)
_SPIRV_OP(BuiltIn, GlobalHWThreadIDINTEL)

_SPIRV_OP(Capability, MaskedGatherScatterINTEL)
_SPIRV_OP(Op, MaskedGatherINTEL)
_SPIRV_OP(Op, MaskedScatterINTEL)

_SPIRV_OP(Capability, SubgroupRequirementsINTEL)

_SPIRV_OP(Capability, TaskSequenceINTEL)
_SPIRV_OP(Op, TaskSequenceCreateINTEL)
_SPIRV_OP(Op, TaskSequenceAsyncINTEL)
_SPIRV_OP(Op, TaskSequenceGetINTEL)
_SPIRV_OP(Op, TaskSequenceReleaseINTEL)
_SPIRV_OP(Op, TypeTaskSequenceINTEL)

_SPIRV_OP(Capability, BindlessImagesINTEL)
_SPIRV_OP(Op, ConvertHandleToImageINTEL)
_SPIRV_OP(Op, ConvertHandleToSamplerINTEL)
_SPIRV_OP(Op, ConvertHandleToSampledImageINTEL)

_SPIRV_OP(Capability, AtomicBFloat16AddINTEL)
_SPIRV_OP(Capability, AtomicBFloat16MinMaxINTEL)

_SPIRV_OP(Capability, SigmoidINTEL)
_SPIRV_OP(Op, FSigmoidINTEL)
_SPIRV_OP(Capability, Float4E2M1INTEL)
_SPIRV_OP(Capability, Float4E2M1CooperativeMatrixINTEL)

_SPIRV_OP(Capability, FloatConversionsFtoFINTEL)
_SPIRV_OP(Op, ClampConvertFToFINTEL)
_SPIRV_OP(Op, StochasticRoundFToFINTEL)
_SPIRV_OP(Op, ClampStochasticRoundFToFINTEL)
_SPIRV_OP(Capability, FloatConversionsFtoSINTEL)
_SPIRV_OP(Op, ClampConvertFToSINTEL)
_SPIRV_OP(Op, ClampStochasticRoundFToSINTEL)

_SPIRV_OP(Capability, SubgroupScaledMatrixMultiplyAccumulateINTEL)
_SPIRV_OP(Op, SubgroupScaledMatrixMultiplyAccumulateINTEL)
#undef _SPIRV_OP

constexpr SourceLanguage SourceLanguagePython =
    static_cast<SourceLanguage>(ISourceLanguagePython);
constexpr SourceLanguage SourceLanguageJulia =
    static_cast<SourceLanguage>(ISourceLanguageJulia);
constexpr SourceLanguage SourceLanguageRust =
    static_cast<SourceLanguage>(ISourceLanguageRust);
constexpr SourceLanguage SourceLanguageD =
    static_cast<SourceLanguage>(ISourceLanguageD);
constexpr SourceLanguage SourceLanguageFortran77 =
    static_cast<SourceLanguage>(ISourceLanguageFortran77);
constexpr SourceLanguage SourceLanguageFortran90 =
    static_cast<SourceLanguage>(ISourceLanguageFortran90);
constexpr SourceLanguage SourceLanguageFortran95 =
    static_cast<SourceLanguage>(ISourceLanguageFortran95);
constexpr SourceLanguage SourceLanguageFortran2003 =
    static_cast<SourceLanguage>(ISourceLanguageFortran2003);
constexpr SourceLanguage SourceLanguageFortran2008 =
    static_cast<SourceLanguage>(ISourceLanguageFortran2008);
constexpr SourceLanguage SourceLanguageFortran2018 =
    static_cast<SourceLanguage>(ISourceLanguageFortran2018);
constexpr SourceLanguage SourceLanguageC =
    static_cast<SourceLanguage>(ISourceLanguageC);
constexpr SourceLanguage SourceLanguageC99 =
    static_cast<SourceLanguage>(ISourceLanguageC99);
constexpr SourceLanguage SourceLanguageC11 =
    static_cast<SourceLanguage>(ISourceLanguageC11);
constexpr SourceLanguage SourceLanguageC17 =
    static_cast<SourceLanguage>(ISourceLanguageC17);
constexpr SourceLanguage SourceLanguageCPP =
    static_cast<SourceLanguage>(ISourceLanguageCPP);
constexpr SourceLanguage SourceLanguageCPP03 =
    static_cast<SourceLanguage>(ISourceLanguageCPP03);
constexpr SourceLanguage SourceLanguageCPP11 =
    static_cast<SourceLanguage>(ISourceLanguageCPP11);
constexpr SourceLanguage SourceLanguageCPP14 =
    static_cast<SourceLanguage>(ISourceLanguageCPP14);
constexpr SourceLanguage SourceLanguageCPP17 =
    static_cast<SourceLanguage>(ISourceLanguageCPP17);
constexpr SourceLanguage SourceLanguageCPP20 =
    static_cast<SourceLanguage>(ISourceLanguageCPP20);

constexpr Op OpForward = static_cast<Op>(IOpForward);
constexpr Op OpTypeTokenINTEL = static_cast<Op>(IOpTypeTokenINTEL);

constexpr Decoration DecorationRuntimeAlignedINTEL =
    static_cast<Decoration>(IDecRuntimeAlignedINTEL);
constexpr Decoration DecorationHostAccessINTEL =
    static_cast<Decoration>(IDecHostAccessINTEL);
constexpr Decoration DecorationInitModeINTEL =
    static_cast<Decoration>(IDecInitModeINTEL);
constexpr Decoration DecorationImplementInCSRINTEL =
    static_cast<Decoration>(IDecImplementInCSRINTEL);
constexpr Decoration DecorationArgumentAttributeINTEL =
    static_cast<Decoration>(IDecArgumentAttributeINTEL);

constexpr Capability CapabilityTokenTypeINTEL =
    static_cast<Capability>(ICapTokenTypeINTEL);
constexpr Capability CapabilityGlobalVariableDecorationsINTEL =
    static_cast<Capability>(ICapGlobalVariableDecorationsINTEL);
constexpr Capability CapabilityBFloat16ArithmeticINTEL =
    static_cast<Capability>(ICapabilityBFloat16ArithmeticINTEL);

constexpr ExecutionMode ExecutionModeNamedSubgroupSizeINTEL =
    static_cast<ExecutionMode>(IExecModeNamedSubgroupSizeINTEL);

constexpr Capability CapabilityAtomicInt16CompareExchangeINTEL =
    static_cast<Capability>(ICapabilityAtomicInt16CompareExchangeINTEL);
constexpr Capability CapabilityInt16AtomicsINTEL =
    static_cast<Capability>(ICapabilityInt16AtomicsINTEL);
constexpr Capability CapabilityAtomicBFloat16LoadStoreINTEL =
    static_cast<Capability>(ICapabilityAtomicBFloat16LoadStoreINTEL);

} // namespace internal
} // namespace spv

#endif // #ifndef spirv_internal_HPP
