26#include "llvm/IR/IntrinsicsSPIRV.h" 
   41    if (LI->getType()->isAggregateType())
 
 
   48    return PType->getAddressSpace();
 
   50    return PType->getAddressSpace();
 
   53    return ExtTy->getIntParameter(0);
 
 
   60  case SPIRV::StorageClass::Uniform:
 
   61  case SPIRV::StorageClass::PushConstant:
 
   62  case SPIRV::StorageClass::StorageBuffer:
 
   63  case SPIRV::StorageClass::PhysicalStorageBufferEXT:
 
   65  case SPIRV::StorageClass::UniformConstant:
 
   66  case SPIRV::StorageClass::Input:
 
   67  case SPIRV::StorageClass::Output:
 
   68  case SPIRV::StorageClass::Workgroup:
 
   69  case SPIRV::StorageClass::CrossWorkgroup:
 
   70  case SPIRV::StorageClass::Private:
 
   71  case SPIRV::StorageClass::Function:
 
   72  case SPIRV::StorageClass::Generic:
 
   73  case SPIRV::StorageClass::AtomicCounter:
 
   74  case SPIRV::StorageClass::Image:
 
   75  case SPIRV::StorageClass::CallableDataNV:
 
   76  case SPIRV::StorageClass::IncomingCallableDataNV:
 
   77  case SPIRV::StorageClass::RayPayloadNV:
 
   78  case SPIRV::StorageClass::HitAttributeNV:
 
   79  case SPIRV::StorageClass::IncomingRayPayloadNV:
 
   80  case SPIRV::StorageClass::ShaderRecordBufferNV:
 
   81  case SPIRV::StorageClass::CodeSectionINTEL:
 
   82  case SPIRV::StorageClass::DeviceOnlyINTEL:
 
   83  case SPIRV::StorageClass::HostOnlyINTEL:
 
 
   90    : PointerSize(PointerSize), Bound(0), 
CurMF(nullptr) {}
 
 
  121    SPIRV::AccessQualifier::AccessQualifier AccessQual, 
bool EmitIR) {
 
 
  131  VRegToTypeMap[&MF][VReg] = SpirvType;
 
 
  136  MRI.setRegClass(Res, &SPIRV::TYPERegClass);
 
 
  145  return createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
 
  146    return MIRBuilder.
buildInstr(SPIRV::OpTypeBool)
 
  151unsigned SPIRVGlobalRegistry::adjustOpTypeIntWidth(
unsigned Width)
 const {
 
  155  if (
ST.canUseExtension(
 
  156          SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers) ||
 
  157      ST.canUseExtension(SPIRV::Extension::SPV_INTEL_int4))
 
  161  else if (Width <= 16)
 
  163  else if (Width <= 32)
 
  170SPIRVType *SPIRVGlobalRegistry::getOpTypeInt(
unsigned Width,
 
  173  Width = adjustOpTypeIntWidth(Width);
 
  174  const SPIRVSubtarget &
ST =
 
  176  return createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
 
  177    if (Width == 4 && 
ST.canUseExtension(SPIRV::Extension::SPV_INTEL_int4)) {
 
  179          .
addImm(SPIRV::Extension::SPV_INTEL_int4);
 
  181          .
addImm(SPIRV::Capability::Int4TypeINTEL);
 
  184                   SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers)) {
 
  186          .
addImm(SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers);
 
  188          .
addImm(SPIRV::Capability::ArbitraryPrecisionIntegersINTEL);
 
  190    return MIRBuilder.
buildInstr(SPIRV::OpTypeInt)
 
  193        .
addImm(IsSigned ? 1 : 0);
 
  197SPIRVType *SPIRVGlobalRegistry::getOpTypeFloat(uint32_t Width,
 
  199  return createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
 
  200    return MIRBuilder.
buildInstr(SPIRV::OpTypeFloat)
 
  207SPIRVGlobalRegistry::getOpTypeFloat(uint32_t Width,
 
  209                                    SPIRV::FPEncoding::FPEncoding FPEncode) {
 
  210  return createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
 
  211    return MIRBuilder.
buildInstr(SPIRV::OpTypeFloat)
 
  219  return createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
 
  220    return MIRBuilder.
buildInstr(SPIRV::OpTypeVoid)
 
  230  auto It = LastInsertedTypeMap.find(MF);
 
  231  if (It == LastInsertedTypeMap.end())
 
  233  if (It->second == 
MI)
 
  234    LastInsertedTypeMap.erase(MF);
 
 
  239SPIRVType *SPIRVGlobalRegistry::createOpType(
 
  246  auto LastInsertedType = LastInsertedTypeMap.find(
CurMF);
 
  247  if (LastInsertedType != LastInsertedTypeMap.end()) {
 
  248    auto It = LastInsertedType->second->getIterator();
 
  252    if (It->getParent() != NewMBB)
 
  253      InsertAt = oldInsertPoint->getParent() == NewMBB
 
  256    else if (It->getNextNode())
 
  257      InsertAt = It->getNextNode()->getIterator();
 
  263    auto Result = LastInsertedTypeMap.try_emplace(
CurMF, 
nullptr);
 
  265    LastInsertedType = Result.first;
 
  268  MachineInstr *
Type = 
Op(MIRBuilder);
 
  272  LastInsertedType->second = 
Type;
 
  278SPIRVType *SPIRVGlobalRegistry::getOpTypeVector(uint32_t NumElems,
 
  283  assert((EleOpc == SPIRV::OpTypeInt || EleOpc == SPIRV::OpTypeFloat ||
 
  284          EleOpc == SPIRV::OpTypeBool) &&
 
  285         "Invalid vector element type");
 
  287  return createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
 
  288    return MIRBuilder.
buildInstr(SPIRV::OpTypeVector)
 
  300  auto *
const CF = ConstantFP::get(Ctx, Val);
 
  302  if (
MI && (
MI->getOpcode() == SPIRV::OpConstantNull ||
 
  303             MI->getOpcode() == SPIRV::OpConstantF))
 
  304    return MI->getOperand(0).getReg();
 
 
  314  Register Res = 
CurMF->getRegInfo().createGenericVirtualRegister(LLTy);
 
  315  CurMF->getRegInfo().setRegClass(Res, &SPIRV::fIDRegClass);
 
  325          MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
 
  329          MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantF)
 
  336        const auto &ST = 
CurMF->getSubtarget();
 
  338                                         *ST.getRegisterInfo(),
 
  339                                         *ST.getRegBankInfo());
 
 
  351  auto *
const CI = ConstantInt::get(
const_cast<IntegerType *
>(Ty), Val);
 
  353  if (
MI && (
MI->getOpcode() == SPIRV::OpConstantNull ||
 
  354             MI->getOpcode() == SPIRV::OpConstantI))
 
  355    return MI->getOperand(0).getReg();
 
 
  366  Register Res = 
CurMF->getRegInfo().createGenericVirtualRegister(LLTy);
 
  367  CurMF->getRegInfo().setRegClass(Res, &SPIRV::iIDRegClass);
 
  378                                             : SPIRV::OpConstantTrue)
 
  381        } 
else if (!CI->
isZero() || !ZeroAsNull) {
 
  382          MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantI)
 
  387          MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
 
  391        const auto &ST = 
CurMF->getSubtarget();
 
  393                                         *ST.getRegisterInfo(),
 
  394                                         *ST.getRegBankInfo());
 
 
  406  auto &MF = MIRBuilder.
getMF();
 
  408  auto *
const CI = ConstantInt::get(
const_cast<IntegerType *
>(Ty), Val);
 
  416  Res = 
MRI.createGenericVirtualRegister(LLTy);
 
  417  MRI.setRegClass(Res, &SPIRV::iIDRegClass);
 
  427        if (Val || !ZeroAsNull) {
 
  428          MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantI)
 
  433          MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
 
  437        const auto &Subtarget = 
CurMF->getSubtarget();
 
  439                                         *Subtarget.getRegisterInfo(),
 
  440                                         *Subtarget.getRegBankInfo());
 
 
  450  auto &MF = MIRBuilder.
getMF();
 
  454                                   SPIRV::AccessQualifier::ReadWrite, 
true);
 
  455  auto *
const CF = ConstantFP::get(Ctx, Val);
 
  461  Res = MF.getRegInfo().createGenericVirtualRegister(LLTy);
 
  462  MF.getRegInfo().setRegClass(Res, &SPIRV::fIDRegClass);
 
  468        MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantF)
 
  471        addNumImm(CF->getValueAPF().bitcastToAPInt(), MIB);
 
 
  478Register SPIRVGlobalRegistry::getOrCreateBaseRegister(
 
  482  if (SpvType->
getOpcode() == SPIRV::OpTypeVector ||
 
  483      SpvType->
getOpcode() == SPIRV::OpTypeArray) {
 
  487  if (
Type->getOpcode() == SPIRV::OpTypeFloat) {
 
  492  assert(
Type->getOpcode() == SPIRV::OpTypeInt);
 
  495                             SpvBaseType, 
TII, ZeroAsNull);
 
  498Register SPIRVGlobalRegistry::getOrCreateCompositeOrNull(
 
  501    unsigned ElemCnt, 
bool ZeroAsNull) {
 
  509        getOrCreateBaseRegister(Val, 
I, SpvType, 
TII, 
BitWidth, ZeroAsNull);
 
  512  Register Res = 
CurMF->getRegInfo().createGenericVirtualRegister(LLTy);
 
  516  MachineInstr *DepMI = 
const_cast<MachineInstr *
>(SpvType);
 
  518  const MachineInstr *NewMI =
 
  519      createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
 
  520        MachineInstrBuilder MIB;
 
  522          MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantComposite)
 
  525          for (
unsigned i = 0; i < ElemCnt; ++i)
 
  528          MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
 
  532        const auto &Subtarget = 
CurMF->getSubtarget();
 
  534                                         *Subtarget.getRegisterInfo(),
 
  535                                         *Subtarget.getRegBankInfo());
 
  552  auto *ConstVal = ConstantInt::get(LLVMBaseTy, Val);
 
  556  return getOrCreateCompositeOrNull(ConstVal, 
I, SpvType, 
TII, ConstVec, BW,
 
 
  571  auto *ConstVal = ConstantFP::get(LLVMBaseTy, Val);
 
  575  return getOrCreateCompositeOrNull(ConstVal, 
I, SpvType, 
TII, ConstVec, BW,
 
 
  587  Constant *CI = ConstantInt::get(LLVMBaseTy, Val);
 
  600       ConstantInt::get(LLVMBaseTy, Val), ConstantInt::get(LLVMBaseTy, Num)});
 
  601  return getOrCreateCompositeOrNull(CI, 
I, SpvType, 
TII, UniqueKey, BW,
 
 
  605Register SPIRVGlobalRegistry::getOrCreateIntCompositeOrNull(
 
  627          auto MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantComposite)
 
  630          for (
unsigned i = 0; i < ElemCnt; ++i)
 
  635        return MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
 
  651  const auto ConstInt = ConstantInt::get(LLVMBaseTy, Val);
 
  655  return getOrCreateIntCompositeOrNull(Val, MIRBuilder, SpvType, EmitIR,
 
 
  674  Res = 
CurMF->getRegInfo().createGenericVirtualRegister(LLTy);
 
  675  CurMF->getRegInfo().setRegClass(Res, &SPIRV::pIDRegClass);
 
  680        return MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
 
 
  690                                          unsigned Param, 
unsigned FilerMode,
 
  703  MIRBuilder.
buildInstr(SPIRV::OpConstantSampler)
 
 
  714    const GlobalValue *GV, SPIRV::StorageClass::StorageClass Storage,
 
  716    const std::optional<SPIRV::LinkageType::LinkageType> &LinkageType,
 
  725    GVar = M->getGlobalVariable(Name);
 
  726    if (GVar == 
nullptr) {
 
  744  auto MIB = MIRBuilder.
buildInstr(SPIRV::OpVariable)
 
  752  if (IsInstSelector) {
 
  753    const auto &Subtarget = 
CurMF->getSubtarget();
 
  755                                     *Subtarget.getRegisterInfo(),
 
  756                                     *Subtarget.getRegBankInfo());
 
  765  if (Reg != ResVReg) {
 
  768    MRI->setType(Reg, RegLLTy);
 
  775    if (!DefType || DefType != 
BaseType)
 
  787  if (IsConst && !ST.isShader())
 
  792    buildOpDecorate(Reg, MIRBuilder, SPIRV::Decoration::Alignment, {Alignment});
 
  797                    {
static_cast<uint32_t>(*LinkageType)}, Name);
 
  799  SPIRV::BuiltIn::BuiltIn BuiltInId;
 
  802                    {
static_cast<uint32_t>(BuiltInId)});
 
  808  if (GVar && (GVarMD = GVar->
getMetadata(
"spirv.Decorations")) != 
nullptr)
 
 
  825                      std::nullopt, MIRBuilder, 
false);
 
  827  buildOpDecorate(VarReg, MIRBuilder, SPIRV::Decoration::DescriptorSet, {Set});
 
  828  buildOpDecorate(VarReg, MIRBuilder, SPIRV::Decoration::Binding, {Binding});
 
 
  837                                               bool ExplicitLayoutRequired,
 
  840         "Invalid array element type");
 
  849      return MIRBuilder.
buildInstr(SPIRV::OpTypeArray)
 
  855    assert(
ST.isShader() && 
"Runtime arrays are not allowed in non-shader " 
  859    ArrayType = createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
 
  860      return MIRBuilder.
buildInstr(SPIRV::OpTypeRuntimeArray)
 
  868    addArrayStrideDecorations(
ArrayType->defs().begin()->getReg(), ET,
 
  880  return createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
 
  888SPIRVType *SPIRVGlobalRegistry::getOpTypeStruct(
 
  890    SPIRV::AccessQualifier::AccessQualifier AccQual,
 
  892  const SPIRVSubtarget &
ST =
 
  895  constexpr unsigned MaxWordCount = UINT16_MAX;
 
  898  size_t MaxNumElements = MaxWordCount - 2;
 
  899  size_t SPIRVStructNumElements = NumElements;
 
  900  if (NumElements > MaxNumElements) {
 
  902    SPIRVStructNumElements = MaxNumElements;
 
  903    MaxNumElements = MaxWordCount - 1;
 
  906  for (
const auto &Elem : Ty->
elements()) {
 
  909         Decorator != 
nullptr, EmitIR);
 
  911           "Invalid struct element type");
 
  921      createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
 
  924        for (
size_t I = 0; 
I < SPIRVStructNumElements; ++
I)
 
  925          MIBStruct.
addUse(FieldTypes[
I]);
 
  926        for (
size_t I = SPIRVStructNumElements; 
I < NumElements;
 
  927             I += MaxNumElements) {
 
  929              MIRBuilder.
buildInstr(SPIRV::OpTypeStructContinuedINTEL);
 
  930          for (
size_t J = 
I; J < std::min(
I + MaxNumElements, NumElements); ++J)
 
  937    Decorator(SPVType->defs().begin()->getReg());
 
  942SPIRVType *SPIRVGlobalRegistry::getOrCreateSpecialType(
 
  944    SPIRV::AccessQualifier::AccessQualifier AccQual) {
 
  949SPIRVType *SPIRVGlobalRegistry::getOpTypePointer(
 
  950    SPIRV::StorageClass::StorageClass SC, 
SPIRVType *ElemType,
 
  955  return createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
 
  956    return MIRBuilder.
buildInstr(SPIRV::OpTypePointer)
 
  958        .
addImm(
static_cast<uint32_t
>(SC))
 
  963SPIRVType *SPIRVGlobalRegistry::getOpTypeForwardPointer(
 
  965  return createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
 
  966    return MIRBuilder.
buildInstr(SPIRV::OpTypeForwardPointer)
 
  968        .
addImm(
static_cast<uint32_t
>(SC));
 
  972SPIRVType *SPIRVGlobalRegistry::getOpTypeFunction(
 
  975  return createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
 
  976    auto MIB = MIRBuilder.
buildInstr(SPIRV::OpTypeFunction)
 
  979    for (
const SPIRVType *ArgType : ArgTypes)
 
  991  const MachineInstr *NewMI = getOpTypeFunction(RetType, ArgTypes, MIRBuilder);
 
  992  add(Ty, 
false, NewMI);
 
  993  return finishCreatingSPIRVType(Ty, NewMI);
 
 
  996SPIRVType *SPIRVGlobalRegistry::findSPIRVType(
 
  998    SPIRV::AccessQualifier::AccessQualifier AccQual,
 
  999    bool ExplicitLayoutRequired, 
bool EmitIR) {
 
 1000  Ty = adjustIntTypeByWidth(Ty);
 
 1003          findMI(Ty, ExplicitLayoutRequired, &MIRBuilder.
getMF()))
 
 1005  if (
auto It = ForwardPointerTypes.find(Ty); It != ForwardPointerTypes.end())
 
 1007  return restOfCreateSPIRVType(Ty, MIRBuilder, AccQual, ExplicitLayoutRequired,
 
 1012  assert(SpirvType && 
"Attempting to get type id for nullptr type.");
 
 1013  if (SpirvType->
getOpcode() == SPIRV::OpTypeForwardPointer ||
 
 1014      SpirvType->
getOpcode() == SPIRV::OpTypeStructContinuedINTEL)
 
 1015    return SpirvType->
uses().
begin()->getReg();
 
 1016  return SpirvType->
defs().
begin()->getReg();
 
 
 1027const Type *SPIRVGlobalRegistry::adjustIntTypeByWidth(
const Type *Ty)
 const {
 
 1029    unsigned SrcBitWidth = IType->getBitWidth();
 
 1030    if (SrcBitWidth > 1) {
 
 1031      unsigned BitWidth = adjustOpTypeIntWidth(SrcBitWidth);
 
 1040SPIRVType *SPIRVGlobalRegistry::createSPIRVType(
 
 1042    SPIRV::AccessQualifier::AccessQualifier AccQual,
 
 1043    bool ExplicitLayoutRequired, 
bool EmitIR) {
 
 1045    return getOrCreateSpecialType(Ty, MIRBuilder, AccQual);
 
 1047  if (
const MachineInstr *
MI =
 
 1048          findMI(Ty, ExplicitLayoutRequired, &MIRBuilder.
getMF()))
 
 1052    const unsigned Width = IType->getBitWidth();
 
 1053    return Width == 1 ? getOpTypeBool(MIRBuilder)
 
 1054                      : getOpTypeInt(Width, MIRBuilder, 
false);
 
 1059                            SPIRV::FPEncoding::BFloat16KHR);
 
 1065    return getOpTypeVoid(MIRBuilder);
 
 1069                      AccQual, ExplicitLayoutRequired, EmitIR);
 
 1075                                  AccQual, ExplicitLayoutRequired, EmitIR);
 
 1077                          ExplicitLayoutRequired, EmitIR);
 
 1080    if (SType->isOpaque())
 
 1081      return getOpTypeOpaque(SType, MIRBuilder);
 
 1084    if (ExplicitLayoutRequired) {
 
 1085      Decorator = [&MIRBuilder, SType, 
this](
Register Reg) {
 
 1086        addStructOffsetDecorations(
Reg, 
const_cast<StructType *
>(SType),
 
 1090    return getOpTypeStruct(SType, MIRBuilder, AccQual, std::move(Decorator),
 
 1094    SPIRVType *RetTy = findSPIRVType(FType->getReturnType(), MIRBuilder,
 
 1095                                     AccQual, ExplicitLayoutRequired, EmitIR);
 
 1097    for (
const auto &ParamTy : FType->params())
 
 1098      ParamTypes.
push_back(findSPIRVType(ParamTy, MIRBuilder, AccQual,
 
 1099                                         ExplicitLayoutRequired, EmitIR));
 
 1100    return getOpTypeFunction(RetTy, ParamTypes, MIRBuilder);
 
 1111  const SPIRVSubtarget *
ST =
 
 1112      static_cast<const SPIRVSubtarget *
>(&MIRBuilder.
getMF().getSubtarget());
 
 1122  if (
auto It = ForwardPointerTypes.find(Ty); It != ForwardPointerTypes.end()) {
 
 1125    return getOpTypePointer(SC, SpvElementType, MIRBuilder, 
Reg);
 
 1131SPIRVType *SPIRVGlobalRegistry::restOfCreateSPIRVType(
 
 1133    SPIRV::AccessQualifier::AccessQualifier AccessQual,
 
 1134    bool ExplicitLayoutRequired, 
bool EmitIR) {
 
 1139  TypesInProcessing.insert(Ty);
 
 1140  SPIRVType *SpirvType = createSPIRVType(Ty, MIRBuilder, AccessQual,
 
 1141                                         ExplicitLayoutRequired, EmitIR);
 
 1142  TypesInProcessing.erase(Ty);
 
 1149  if (SpirvType->
getOpcode() == SPIRV::OpTypeForwardPointer ||
 
 1155    add(ExtTy->getTypeParameter(0), ExtTy->getIntParameter(0), SpirvType);
 
 1157    add(Ty, ExplicitLayoutRequired, SpirvType);
 
 1170  auto t = VRegToTypeMap.find(MF ? MF : 
CurMF);
 
 1171  if (t != VRegToTypeMap.end()) {
 
 1172    auto tt = t->second.find(VReg);
 
 1173    if (tt != t->second.end())
 
 
 1189    SPIRV::AccessQualifier::AccessQualifier AccessQual,
 
 1190    bool ExplicitLayoutRequired, 
bool EmitIR) {
 
 1195    Reg = 
find(ExtTy->getTypeParameter(0), ExtTy->getIntParameter(0), MF);
 
 1197    Reg = 
find(Ty = adjustIntTypeByWidth(Ty), ExplicitLayoutRequired, MF);
 
 1207  TypesInProcessing.clear();
 
 1208  SPIRVType *STy = restOfCreateSPIRVType(Ty, MIRBuilder, AccessQual,
 
 1209                                         ExplicitLayoutRequired, EmitIR);
 
 1211  for (
auto &
CU : ForwardPointerTypes) {
 
 1214    bool PtrNeedsLayout = 
false;
 
 1215    const Type *Ty2 = 
CU.first;
 
 1217    if ((Reg = 
find(Ty2, PtrNeedsLayout, MF)).
isValid())
 
 1220      STy2 = restOfCreateSPIRVType(Ty2, MIRBuilder, AccessQual, PtrNeedsLayout,
 
 1225  ForwardPointerTypes.clear();
 
 1230                                         unsigned TypeOpcode)
 const {
 
 1232  assert(
Type && 
"isScalarOfType VReg has no type assigned");
 
 1233  return Type->getOpcode() == TypeOpcode;
 
 
 1237                                                 unsigned TypeOpcode)
 const {
 
 1239  assert(
Type && 
"isScalarOrVectorOfType VReg has no type assigned");
 
 1240  if (
Type->getOpcode() == TypeOpcode)
 
 1242  if (
Type->getOpcode() == SPIRV::OpTypeVector) {
 
 1243    Register ScalarTypeVReg = 
Type->getOperand(1).getReg();
 
 1245    return ScalarType->
getOpcode() == TypeOpcode;
 
 
 1251  switch (
Type->getOpcode()) {
 
 1252  case SPIRV::OpTypeImage:
 
 1253  case SPIRV::OpTypeSampler:
 
 1254  case SPIRV::OpTypeSampledImage:
 
 1256  case SPIRV::OpTypeStruct:
 
 1257    return hasBlockDecoration(
Type);
 
 
 1272  return Type->getOpcode() == SPIRV::OpTypeVector
 
 1273             ? 
static_cast<unsigned>(
Type->getOperand(2).
getImm())
 
 
 1286  Register ScalarReg = 
Type->getOpcode() == SPIRV::OpTypeVector
 
 1287                           ? 
Type->getOperand(1).getReg()
 
 1288                           : 
Type->getOperand(0).getReg();
 
 
 1298  if (
Type->getOpcode() == SPIRV::OpTypeVector) {
 
 1299    auto EleTypeReg = 
Type->getOperand(1).getReg();
 
 1302  if (
Type->getOpcode() == SPIRV::OpTypeInt ||
 
 1303      Type->getOpcode() == SPIRV::OpTypeFloat)
 
 1304    return Type->getOperand(1).getImm();
 
 1305  if (
Type->getOpcode() == SPIRV::OpTypeBool)
 
 1307  llvm_unreachable(
"Attempting to get bit width of non-integer/float type.");
 
 
 1313  unsigned NumElements = 1;
 
 1314  if (
Type->getOpcode() == SPIRV::OpTypeVector) {
 
 1315    NumElements = 
static_cast<unsigned>(
Type->getOperand(2).
getImm());
 
 1318  return Type->getOpcode() == SPIRV::OpTypeInt ||
 
 1319                 Type->getOpcode() == SPIRV::OpTypeFloat
 
 1320             ? NumElements * 
Type->getOperand(1).getImm()
 
 
 1326  if (
Type && 
Type->getOpcode() == SPIRV::OpTypeVector)
 
 1328  return Type && 
Type->getOpcode() == SPIRV::OpTypeInt ? 
Type : 
nullptr;
 
 
 1337  return PtrType && PtrType->
getOpcode() == SPIRV::OpTypePointer
 
 
 1344  return ElemType ? ElemType->
getOpcode() : 0;
 
 
 1349  if (!Type1 || !Type2)
 
 1355  if (Op1 == SPIRV::OpTypePointer &&
 
 1358  if (Op2 == SPIRV::OpTypePointer &&
 
 1363  return Bits1 > 0 && Bits1 == Bits2;
 
 
 1366SPIRV::StorageClass::StorageClass
 
 1370         Type->getOperand(1).isImm() && 
"Pointer type is expected");
 
 
 1374SPIRV::StorageClass::StorageClass
 
 1376  return static_cast<SPIRV::StorageClass::StorageClass
>(
 
 
 1382    SPIRV::StorageClass::StorageClass SC, 
bool IsWritable, 
bool EmitIr) {
 
 1393                           ExplicitLayoutRequired, EmitIr);
 
 1396                  SPIRV::Decoration::Block, {});
 
 1400                          SPIRV::Decoration::NonWritable, 0, {});
 
 1403  SPIRVType *R = getOrCreateSPIRVPointerTypeInternal(BlockType, MIRBuilder, SC);
 
 
 1416  assert(ST->getNumElements() == Offsets.size());
 
 1429      getOpTypeStruct(ST, MIRBuilder, SPIRV::AccessQualifier::None,
 
 1430                      std::move(Decorator), EmitIr);
 
 1431  add(
Key, SPIRVStructType);
 
 1432  return SPIRVStructType;
 
 
 1437    const SPIRV::AccessQualifier::AccessQualifier Qualifier,
 
 1440         "SPIR-V image builtin type must have sampled type parameter!");
 
 1443                           SPIRV::AccessQualifier::ReadWrite, 
true);
 
 1446         "Invalid number of parameters for SPIR-V image builtin!");
 
 1448  SPIRV::AccessQualifier::AccessQualifier accessQualifier =
 
 1449      SPIRV::AccessQualifier::None;
 
 1451    accessQualifier = Qualifier == SPIRV::AccessQualifier::WriteOnly
 
 1452                          ? SPIRV::AccessQualifier::WriteOnly
 
 1453                          : SPIRV::AccessQualifier::AccessQualifier(
 
 1459      MIRBuilder, SampledType,
 
 1465  SPIRVToLLVMType[R] = ExtensionType;
 
 
 1469SPIRVType *SPIRVGlobalRegistry::getOrCreateOpTypeImage(
 
 1472    SPIRV::ImageFormat::ImageFormat ImageFormat,
 
 1473    SPIRV::AccessQualifier::AccessQualifier AccessQual) {
 
 1475                                   Depth, Arrayed, Multisampled, Sampled,
 
 1476                                   ImageFormat, AccessQual);
 
 1491        if (AccessQual != SPIRV::AccessQualifier::None)
 
 1507        return MIRBuilder.
buildInstr(SPIRV::OpTypeSampler)
 
 
 1516    SPIRV::AccessQualifier::AccessQualifier AccessQual) {
 
 1522        return MIRBuilder.
buildInstr(SPIRV::OpTypePipe)
 
 
 1537        return MIRBuilder.
buildInstr(SPIRV::OpTypeDeviceEvent)
 
 
 1554        return MIRBuilder.
buildInstr(SPIRV::OpTypeSampledImage)
 
 
 1567          findMI(ExtensionType, 
false, &MIRBuilder.
getMF()))
 
 1575                .canUseExtension(SPIRV::Extension::SPV_INTEL_int4)) {
 
 1577              .
addImm(SPIRV::Capability::Int4CooperativeMatrixINTEL);
 
 1579        return MIRBuilder.
buildInstr(SPIRV::OpTypeCooperativeMatrixKHR)
 
 1587  add(ExtensionType, 
false, NewMI);
 
 
 1599  add(Ty, 
false, NewMI);
 
 
 1615          if (Operand.isReg()) {
 
 1616            MIB.
addUse(Operand.getReg());
 
 1617          } 
else if (Operand.isImm()) {
 
 1618            MIB.
addImm(Operand.getImm());
 
 1623  add(Ty, 
false, NewMI);
 
 
 1630    SPIRV::StorageClass::StorageClass SC,
 
 1631    SPIRV::AccessQualifier::AccessQualifier AQ) {
 
 1632  unsigned VecElts = 0;
 
 1639                                MIRBuilder, AQ, 
false, 
true);
 
 1661    TypeStr = TypeStr.
substr(0, TypeStr.
find(
']'));
 
 
 1678      MIRBuilder, SPIRV::AccessQualifier::ReadWrite, 
false, 
true);
 
 
 1681SPIRVType *SPIRVGlobalRegistry::finishCreatingSPIRVType(
const Type *LLVMTy,
 
 1692                                                     unsigned SPIRVOPcode,
 
 1701                       MIRBuilder.
getDL(), 
TII.get(SPIRVOPcode))
 
 1706  add(Ty, 
false, NewMI);
 
 1707  return finishCreatingSPIRVType(Ty, NewMI);
 
 
 1747      MIRBuilder, SPIRV::AccessQualifier::ReadWrite, 
false, EmitIR);
 
 
 1761                       MIRBuilder.
getDL(), 
TII.get(SPIRV::OpTypeBool))
 
 1764  add(Ty, 
false, NewMI);
 
 1765  return finishCreatingSPIRVType(Ty, NewMI);
 
 
 1774      MIRBuilder, SPIRV::AccessQualifier::ReadWrite, 
false, EmitIR);
 
 
 1789                       MIRBuilder.
getDL(), 
TII.get(SPIRV::OpTypeVector))
 
 1794  add(Ty, 
false, NewMI);
 
 1795  return finishCreatingSPIRVType(Ty, NewMI);
 
 
 1800    SPIRV::StorageClass::StorageClass SC) {
 
 
 1807    SPIRV::StorageClass::StorageClass SC) {
 
 1810      BaseType, MIRBuilder, SPIRV::AccessQualifier::ReadWrite,
 
 1813  return getOrCreateSPIRVPointerTypeInternal(SpirvBaseType, MIRBuilder, SC);
 
 
 1818  [[maybe_unused]] SPIRV::StorageClass::StorageClass OldSC =
 
 1825  return getOrCreateSPIRVPointerTypeInternal(PointeeType, MIRBuilder, SC);
 
 
 1830    SPIRV::StorageClass::StorageClass SC) {
 
 1836      "The base type was not correctly laid out for the given storage class.");
 
 
 1840SPIRVType *SPIRVGlobalRegistry::getOrCreateSPIRVPointerTypeInternal(
 
 1842    SPIRV::StorageClass::StorageClass SC) {
 
 1853                       MIRBuilder.
getTII().
get(SPIRV::OpTypePointer))
 
 1859  return finishCreatingSPIRVType(Ty, NewMI);
 
 1872  Res = 
CurMF->getRegInfo().createGenericVirtualRegister(LLTy);
 
 1873  CurMF->getRegInfo().setRegClass(Res, &SPIRV::iIDRegClass);
 
 1881                           MIRBuilder.
getDL(), 
TII.get(SPIRV::OpUndef))
 
 1884        const auto &ST = 
CurMF->getSubtarget();
 
 1886                                         *ST.getRegisterInfo(),
 
 1887                                         *ST.getRegBankInfo());
 
 
 1898  case SPIRV::OpTypeFloat:
 
 1899    return &SPIRV::fIDRegClass;
 
 1900  case SPIRV::OpTypePointer:
 
 1901    return &SPIRV::pIDRegClass;
 
 1902  case SPIRV::OpTypeVector: {
 
 1904    unsigned ElemOpcode = ElemType ? ElemType->
getOpcode() : 0;
 
 1905    if (ElemOpcode == SPIRV::OpTypeFloat)
 
 1906      return &SPIRV::vfIDRegClass;
 
 1907    if (ElemOpcode == SPIRV::OpTypePointer)
 
 1908      return &SPIRV::vpIDRegClass;
 
 1909    return &SPIRV::vIDRegClass;
 
 1912  return &SPIRV::iIDRegClass;
 
 
 1917      static_cast<SPIRV::StorageClass::StorageClass
>(
 
 
 1922  unsigned Opcode = SpvType ? SpvType->
getOpcode() : 0;
 
 1924  case SPIRV::OpTypeInt:
 
 1925  case SPIRV::OpTypeFloat:
 
 1926  case SPIRV::OpTypeBool:
 
 1928  case SPIRV::OpTypePointer:
 
 1930  case SPIRV::OpTypeVector: {
 
 1933    switch (ElemType ? ElemType->
getOpcode() : 0) {
 
 1934    case SPIRV::OpTypePointer:
 
 1937    case SPIRV::OpTypeInt:
 
 1938    case SPIRV::OpTypeFloat:
 
 1939    case SPIRV::OpTypeBool:
 
 
 1962  if (
auto L = AliasInstMDMap.find(AliasingListMD); L != AliasInstMDMap.end())
 
 1969      if (ScopeMD->getNumOperands() < 2)
 
 1975        auto D = AliasInstMDMap.find(DomainMD);
 
 1976        if (
D != AliasInstMDMap.end())
 
 1978        const Register Ret = 
MRI->createVirtualRegister(&SPIRV::IDRegClass);
 
 1983      AliasInstMDMap.insert(std::make_pair(DomainMD, 
Domain));
 
 1985        auto S = AliasInstMDMap.find(ScopeMD);
 
 1986        if (S != AliasInstMDMap.end())
 
 1988        const Register Ret = 
MRI->createVirtualRegister(&SPIRV::IDRegClass);
 
 1989        auto MIB = MIRBuilder.
buildInstr(SPIRV::OpAliasScopeDeclINTEL)
 
 1994      AliasInstMDMap.insert(std::make_pair(ScopeMD, Scope));
 
 1999  const Register Ret = 
MRI->createVirtualRegister(&SPIRV::IDRegClass);
 
 2002  for (
auto *Scope : ScopeList)
 
 2003    MIB.
addUse(Scope->getOperand(0).getReg());
 
 2005  AliasInstMDMap.
insert(std::make_pair(AliasingListMD, 
List));
 
 
 2011    const MDNode *AliasingListMD) {
 
 
 2038    B.CreateIntrinsic(Intrinsic::spv_value_md,
 
 2040    AssignCI = 
B.CreateIntrinsic(Intrinsic::fake_use, {Arg});
 
 2043                               OfType, Arg, {}, 
B);
 
 
 2053      B.GetInsertBlock() ? 
B.GetInsertBlock()->getParent() : 
nullptr;
 
 2054  if (AssignPtrTyCI == 
nullptr ||
 
 2055      AssignPtrTyCI->
getParent()->getParent() != CurrF) {
 
 2057        Intrinsic::spv_assign_ptr_type, {Arg->
getType()}, OfType, Arg,
 
 
 2071      Intrinsic::spv_assign_ptr_type)
 
 
 2080void SPIRVGlobalRegistry::addStructOffsetDecorations(
 
 2084  for (
uint32_t I = 0; 
I < Ty->getNumElements(); ++
I) {
 
 2090void SPIRVGlobalRegistry::addArrayStrideDecorations(
 
 2092  uint32_t SizeInBytes = DataLayout().getTypeSizeInBits(ElementType) / 8;
 
 2097bool SPIRVGlobalRegistry::hasBlockDecoration(
SPIRVType *
Type)
 const {
 
 2099  for (
const MachineInstr &Use :
 
 2100       Type->getMF()->getRegInfo().use_instructions(Def)) {
 
 2101    if (
Use.getOpcode() != SPIRV::OpDecorate)
 
 2104    if (
Use.getOperand(1).getImm() == SPIRV::Decoration::Block)
 
unsigned const MachineRegisterInfo * MRI
 
static unsigned getIntrinsicID(const SDNode *N)
 
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
 
This file implements a class to represent arbitrary precision integral constant values and operations...
 
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
 
Function Alias Analysis false
 
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
 
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
 
This file contains the declarations for the subclasses of Constant, which represent the different fla...
 
const HexagonInstrInfo * TII
 
Promote Memory to Register
 
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
 
static unsigned getNumElements(Type *Ty)
 
static bool storageClassRequiresExplictLayout(SPIRV::StorageClass::StorageClass SC)
 
static Register createTypeVReg(MachineRegisterInfo &MRI)
 
unsigned getAS(SPIRVType *SpvType)
 
static bool allowEmitFakeUse(const Value *Arg)
 
static unsigned typeToAddressSpace(const Type *Ty)
 
APInt bitcastToAPInt() const
 
Class for arbitrary precision integers.
 
uint64_t getZExtValue() const
Get zero extended value.
 
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
 
Class to represent array types.
 
uint64_t getNumElements() const
 
Type * getElementType() const
 
void setArgOperand(unsigned i, Value *v)
 
This class represents a function call, abstracting a target machine's calling convention.
 
ConstantFP - Floating Point Values [float, double].
 
const APFloat & getValue() const
 
const APFloat & getValueAPF() const
 
This is the shared class of boolean and integer constants.
 
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
 
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
 
static Constant * getAnon(ArrayRef< Constant * > V, bool Packed=false)
Return an anonymous struct that has the specified elements.
 
static LLVM_ABI ConstantTargetNone * get(TargetExtType *T)
Static factory methods - Return objects of the specified value.
 
static LLVM_ABI Constant * getSplat(ElementCount EC, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
 
This is an important base class in LLVM.
 
LLVM_ABI const APInt & getUniqueInteger() const
If C is a constant integer then return its value, otherwise C must be a vector of constant integers,...
 
LLVM_ABI bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
 
A parsed version of the target data layout string in and methods for querying it.
 
Class to represent fixed width SIMD vectors.
 
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
 
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
 
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
 
Module * getParent()
Get the module that this global value is contained inside of...
 
@ ExternalLinkage
Externally visible function.
 
MaybeAlign getAlign() const
Returns the alignment of the given variable.
 
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
 
Class to represent integer types.
 
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
 
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
 
static constexpr LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
 
static constexpr LLT fixed_vector(unsigned NumElements, unsigned ScalarSizeInBits)
Get a low-level fixed-width vector of some number of elements and element width.
 
This is an important class for using LLVM in a threaded context.
 
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
 
Instances of this class represent operands of the MCInst class.
 
ArrayRef< MDOperand > operands() const
 
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
 
unsigned getNumOperands() const
Return number of MDNode operands.
 
Tracking metadata reference owned by Metadata.
 
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
 
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
 
LLVM_ABI iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
 
MachineInstrBundleIterator< MachineInstr > iterator
 
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
 
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
 
Function & getFunction()
Return the LLVM function that this machine code represents.
 
Helper class to build MachineInstr.
 
void setInsertPt(MachineBasicBlock &MBB, MachineBasicBlock::iterator II)
Set the insertion point before the specified position.
 
LLVMContext & getContext() const
 
const TargetInstrInfo & getTII()
 
MachineBasicBlock::iterator getInsertPt()
Current insertion point for new instructions.
 
MachineInstrBuilder buildSplatBuildVector(const DstOp &Res, const SrcOp &Src)
Build and insert Res = G_BUILD_VECTOR with Src replicated to fill the number of elements.
 
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
 
const DebugLoc & getDL()
Getter for DebugLoc.
 
MachineFunction & getMF()
Getter for the function we currently build.
 
const MachineBasicBlock & getMBB() const
Getter for the basic block we currently build.
 
const DebugLoc & getDebugLoc()
Get the current instruction's debug location.
 
MachineRegisterInfo * getMRI()
Getter for MRI.
 
MachineInstrBuilder buildCopy(const DstOp &Res, const SrcOp &Op)
Build and insert Res = COPY Op.
 
virtual MachineInstrBuilder buildConstant(const DstOp &Res, const ConstantInt &Val)
Build and insert Res = G_CONSTANT Val.
 
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
 
const MachineInstrBuilder & addUse(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
 
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly.
 
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
 
Representation of each machine instruction.
 
mop_range defs()
Returns all explicit operands that are register definitions.
 
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
 
const MachineBasicBlock * getParent() const
 
LLVM_ABI void insert(mop_iterator InsertBefore, ArrayRef< MachineOperand > Ops)
Inserts Ops BEFORE It. Can untie/retie tied operands.
 
mop_range uses()
Returns all operands which may be register uses.
 
LLVM_ABI const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
 
const MachineOperand & getOperand(unsigned i) const
 
Register getReg() const
getReg - Returns the register number.
 
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
 
LLVM_ABI MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
 
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
 
A Module instance is used to store all the information related to an LLVM module.
 
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
 
Wrapper class representing virtual and physical registers.
 
constexpr bool isValid() const
 
SPIRVType * getOrCreateOpTypePipe(MachineIRBuilder &MIRBuilder, SPIRV::AccessQualifier::AccessQualifier AccQual)
 
unsigned getNumScalarOrVectorTotalBitWidth(const SPIRVType *Type) const
 
SPIRVType * getSPIRVTypeForVReg(Register VReg, const MachineFunction *MF=nullptr) const
 
Register getOrCreateConstInt(uint64_t Val, MachineInstr &I, SPIRVType *SpvType, const SPIRVInstrInfo &TII, bool ZeroAsNull=true)
 
SPIRVType * getResultType(Register VReg, MachineFunction *MF=nullptr)
 
void addAssignPtrTypeInstr(Value *Val, CallInst *AssignPtrTyCI)
 
SPIRVType * getOrCreateSPIRVBoolType(MachineIRBuilder &MIRBuilder, bool EmitIR)
 
void buildAssignPtr(IRBuilder<> &B, Type *ElemTy, Value *Arg)
 
SPIRVType * assignFloatTypeToVReg(unsigned BitWidth, Register VReg, MachineInstr &I, const SPIRVInstrInfo &TII)
 
MachineInstr * getOrAddMemAliasingINTELInst(MachineIRBuilder &MIRBuilder, const MDNode *AliasingListMD)
 
void assignSPIRVTypeToVReg(SPIRVType *Type, Register VReg, const MachineFunction &MF)
 
SPIRVType * assignVectTypeToVReg(SPIRVType *BaseType, unsigned NumElements, Register VReg, MachineInstr &I, const SPIRVInstrInfo &TII)
 
Register getOrCreateUndef(MachineInstr &I, SPIRVType *SpvType, const SPIRVInstrInfo &TII)
 
Register buildGlobalVariable(Register Reg, SPIRVType *BaseType, StringRef Name, const GlobalValue *GV, SPIRV::StorageClass::StorageClass Storage, const MachineInstr *Init, bool IsConst, const std::optional< SPIRV::LinkageType::LinkageType > &LinkageType, MachineIRBuilder &MIRBuilder, bool IsInstSelector)
 
void replaceAllUsesWith(Value *Old, Value *New, bool DeleteOld=true)
 
SPIRVType * changePointerStorageClass(SPIRVType *PtrType, SPIRV::StorageClass::StorageClass SC, MachineInstr &I)
 
const Type * getTypeForSPIRVType(const SPIRVType *Ty) const
 
SPIRVType * getOrCreateUnknownType(const Type *Ty, MachineIRBuilder &MIRBuilder, unsigned Opcode, const ArrayRef< MCOperand > Operands)
 
bool isBitcastCompatible(const SPIRVType *Type1, const SPIRVType *Type2) const
 
unsigned getScalarOrVectorComponentCount(Register VReg) const
 
Register createConstInt(const ConstantInt *CI, MachineInstr &I, SPIRVType *SpvType, const SPIRVInstrInfo &TII, bool ZeroAsNull)
 
SPIRVType * getOrCreateSPIRVFloatType(unsigned BitWidth, MachineInstr &I, const SPIRVInstrInfo &TII)
 
bool isScalarOrVectorSigned(const SPIRVType *Type) const
 
void addDeducedElementType(Value *Val, Type *Ty)
 
SPIRVGlobalRegistry(unsigned PointerSize)
 
Register getOrCreateGlobalVariableWithBinding(const SPIRVType *VarType, uint32_t Set, uint32_t Binding, StringRef Name, MachineIRBuilder &MIRBuilder)
 
SPIRVType * getOrCreateSPIRVType(const Type *Type, MachineInstr &I, SPIRV::AccessQualifier::AccessQualifier AQ, bool EmitIR)
 
unsigned getPointerSize() const
 
SPIRVType * getOrCreateSPIRVPointerType(const Type *BaseType, MachineIRBuilder &MIRBuilder, SPIRV::StorageClass::StorageClass SC)
 
SPIRVType * getOrCreateOpTypeByOpcode(const Type *Ty, MachineIRBuilder &MIRBuilder, unsigned Opcode)
 
Register buildConstantFP(APFloat Val, MachineIRBuilder &MIRBuilder, SPIRVType *SpvType=nullptr)
 
SPIRVType * getPointeeType(SPIRVType *PtrType)
 
void invalidateMachineInstr(MachineInstr *MI)
 
Register getSPIRVTypeID(const SPIRVType *SpirvType) const
 
Register createConstFP(const ConstantFP *CF, MachineInstr &I, SPIRVType *SpvType, const SPIRVInstrInfo &TII, bool ZeroAsNull)
 
void updateIfExistDeducedElementType(Value *OldVal, Value *NewVal, bool DeleteOld)
 
bool isScalarOfType(Register VReg, unsigned TypeOpcode) const
 
SPIRVType * assignIntTypeToVReg(unsigned BitWidth, Register VReg, MachineInstr &I, const SPIRVInstrInfo &TII)
 
unsigned getPointeeTypeOp(Register PtrReg)
 
SPIRVType * getOrCreateOpTypeSampledImage(SPIRVType *ImageType, MachineIRBuilder &MIRBuilder)
 
SPIRVType * getOrCreateVulkanBufferType(MachineIRBuilder &MIRBuilder, Type *ElemType, SPIRV::StorageClass::StorageClass SC, bool IsWritable, bool EmitIr=false)
 
SPIRVType * getOrCreateSPIRVTypeByName(StringRef TypeStr, MachineIRBuilder &MIRBuilder, bool EmitIR, SPIRV::StorageClass::StorageClass SC=SPIRV::StorageClass::Function, SPIRV::AccessQualifier::AccessQualifier AQ=SPIRV::AccessQualifier::ReadWrite)
 
SPIRVType * getOrCreateLayoutType(MachineIRBuilder &MIRBuilder, const TargetExtType *T, bool EmitIr=false)
 
void addGlobalObject(const Value *V, const MachineFunction *MF, Register R)
 
SPIRVType * getScalarOrVectorComponentType(Register VReg) const
 
SPIRVType * getOrCreateOpTypeFunctionWithArgs(const Type *Ty, SPIRVType *RetType, const SmallVectorImpl< SPIRVType * > &ArgTypes, MachineIRBuilder &MIRBuilder)
 
void buildAssignType(IRBuilder<> &B, Type *Ty, Value *Arg)
 
Register getOrCreateConsIntVector(uint64_t Val, MachineIRBuilder &MIRBuilder, SPIRVType *SpvType, bool EmitIR)
 
const TargetRegisterClass * getRegClass(SPIRVType *SpvType) const
 
void updateIfExistAssignPtrTypeInstr(Value *OldVal, Value *NewVal, bool DeleteOld)
 
SPIRVType * getOrCreateSPIRVVectorType(SPIRVType *BaseType, unsigned NumElements, MachineIRBuilder &MIRBuilder, bool EmitIR)
 
SPIRVType * getOrCreateOpTypeCoopMatr(MachineIRBuilder &MIRBuilder, const TargetExtType *ExtensionType, const SPIRVType *ElemType, uint32_t Scope, uint32_t Rows, uint32_t Columns, uint32_t Use, bool EmitIR)
 
bool isScalarOrVectorOfType(Register VReg, unsigned TypeOpcode) const
 
Register getOrCreateConstIntArray(uint64_t Val, size_t Num, MachineInstr &I, SPIRVType *SpvType, const SPIRVInstrInfo &TII)
 
Register getOrCreateConstVector(uint64_t Val, MachineInstr &I, SPIRVType *SpvType, const SPIRVInstrInfo &TII, bool ZeroAsNull=true)
 
SPIRVType * getOrCreateOpTypeDeviceEvent(MachineIRBuilder &MIRBuilder)
 
SPIRVType * getImageType(const TargetExtType *ExtensionType, const SPIRV::AccessQualifier::AccessQualifier Qualifier, MachineIRBuilder &MIRBuilder)
 
bool isResourceType(SPIRVType *Type) const
 
SPIRVType * getOrCreateSPIRVIntegerType(unsigned BitWidth, MachineIRBuilder &MIRBuilder)
 
Register buildConstantInt(uint64_t Val, MachineIRBuilder &MIRBuilder, SPIRVType *SpvType, bool EmitIR, bool ZeroAsNull=true)
 
SPIRVType * assignTypeToVReg(const Type *Type, Register VReg, MachineIRBuilder &MIRBuilder, SPIRV::AccessQualifier::AccessQualifier AQ, bool EmitIR)
 
LLT getRegType(SPIRVType *SpvType) const
 
void buildMemAliasingOpDecorate(Register Reg, MachineIRBuilder &MIRBuilder, uint32_t Dec, const MDNode *GVarMD)
 
SPIRV::StorageClass::StorageClass getPointerStorageClass(Register VReg) const
 
SPIRVType * getOrCreateOpTypeSampler(MachineIRBuilder &MIRBuilder)
 
Register buildConstantSampler(Register Res, unsigned AddrMode, unsigned Param, unsigned FilerMode, MachineIRBuilder &MIRBuilder)
 
void updateAssignType(CallInst *AssignCI, Value *Arg, Value *OfType)
 
Register getOrCreateConstFP(APFloat Val, MachineInstr &I, SPIRVType *SpvType, const SPIRVInstrInfo &TII, bool ZeroAsNull=true)
 
CallInst * findAssignPtrTypeInstr(const Value *Val)
 
Register getOrCreateConstNullPtr(MachineIRBuilder &MIRBuilder, SPIRVType *SpvType)
 
unsigned getScalarOrVectorBitWidth(const SPIRVType *Type) const
 
const SPIRVType * retrieveScalarOrVectorIntType(const SPIRVType *Type) const
 
const MachineInstr * findMI(SPIRV::IRHandle Handle, const MachineFunction *MF)
 
bool erase(const MachineInstr *MI)
 
bool add(SPIRV::IRHandle Handle, const MachineInstr *MI)
 
Register find(SPIRV::IRHandle Handle, const MachineFunction *MF)
 
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
 
void push_back(const T &Elt)
 
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
 
StringRef - Represent a constant reference to a string, i.e.
 
bool consume_back(StringRef Suffix)
Returns true if this StringRef has the given suffix and removes that suffix.
 
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
 
std::string str() const
str - Get the contents as an std::string.
 
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
 
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
 
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
 
Class to represent struct types.
 
ArrayRef< Type * > elements() const
 
static LLVM_ABI StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
 
unsigned getNumElements() const
Random access to the elements.
 
bool hasName() const
Return true if this is a named struct that has a non-empty name.
 
LLVM_ABI StringRef getName() const
Return the name for this struct type if it has an identity.
 
Class to represent target extensions types, which are generally unintrospectable from target-independ...
 
unsigned getNumIntParameters() const
 
Type * getTypeParameter(unsigned i) const
 
unsigned getNumTypeParameters() const
 
unsigned getIntParameter(unsigned i) const
 
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
 
The instances of the Type class are immutable: once they are created, they are never changed.
 
LLVM_ABI unsigned getIntegerBitWidth() const
 
bool isVectorTy() const
True if this is an instance of VectorType.
 
bool isArrayTy() const
True if this is an instance of ArrayType.
 
Type * getArrayElementType() const
 
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
 
LLVM_ABI uint64_t getArrayNumElements() const
 
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
 
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
 
bool isAggregateType() const
Return true if the type is an aggregate type.
 
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
 
bool isIntegerTy() const
True if this is an instance of IntegerType.
 
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
 
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
 
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
 
bool isVoidTy() const
Return true if this is 'void'.
 
static LLVM_ABI TypedPointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
 
'undef' values are things that do not have specified contents.
 
static LLVM_ABI UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
 
A Use represents the edge between a Value definition and its users.
 
LLVM Value Representation.
 
Type * getType() const
All values are typed, get the type of this value.
 
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
 
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
 
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
 
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
 
Type * getElementType() const
 
const ParentTy * getParent() const
 
self_iterator getIterator()
 
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
 
IRHandle handle(const Type *Ty)
 
IRHandle irhandle_sampled_image(const Type *SampledTy, const MachineInstr *ImageTy)
 
IRHandle irhandle_vkbuffer(const Type *ElementType, StorageClass::StorageClass SC, bool IsWriteable)
 
IRHandle irhandle_sampler()
 
TargetExtType * parseBuiltinTypeNameToTargetExtType(std::string TypeName, LLVMContext &Context)
Translates a string representing a SPIR-V or OpenCL builtin type to a TargetExtType that can be furth...
 
SPIRVType * lowerBuiltinType(const Type *OpaqueType, SPIRV::AccessQualifier::AccessQualifier AccessQual, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
 
IRHandle irhandle_event()
 
IRHandle irhandle_pipe(uint8_t AQ)
 
IRHandle irhandle_image(const Type *SampledTy, unsigned Dim, unsigned Depth, unsigned Arrayed, unsigned MS, unsigned Sampled, unsigned ImageFormat, unsigned AQ=0)
 
NodeAddr< DefNode * > Def
 
NodeAddr< UseNode * > Use
 
This is an optimization pass for GlobalISel generic memory operations.
 
void buildOpName(Register Target, const StringRef &Name, MachineIRBuilder &MIRBuilder)
 
bool isTypedPointerWrapper(const TargetExtType *ExtTy)
 
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
 
unsigned getPointerAddressSpace(const Type *T)
 
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
 
void addNumImm(const APInt &Imm, MachineInstrBuilder &MIB)
 
LLVM_ABI bool constrainSelectedInstRegOperands(MachineInstr &I, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
Mutate the newly-selected instruction I to constrain its (possibly generic) virtual register operands...
 
CallInst * buildIntrWithMD(Intrinsic::ID IntrID, ArrayRef< Type * > Types, Value *Arg, Value *Arg2, ArrayRef< Constant * > Imms, IRBuilder<> &B)
 
LLVM_ABI void reportFatalInternalError(Error Err)
Report a fatal error that indicates a bug in LLVM.
 
constexpr unsigned storageClassToAddressSpace(SPIRV::StorageClass::StorageClass SC)
 
bool getSpirvBuiltInIdByName(llvm::StringRef Name, SPIRV::BuiltIn::BuiltIn &BI)
 
MetadataAsValue * buildMD(Value *Arg)
 
bool isTypedPointerTy(const Type *T)
 
void buildOpDecorate(Register Reg, MachineIRBuilder &MIRBuilder, SPIRV::Decoration::Decoration Dec, const std::vector< uint32_t > &DecArgs, StringRef StrImm)
 
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
 
Type * getTypedPointerWrapper(Type *ElemTy, unsigned AS)
 
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
 
void buildOpMemberDecorate(Register Reg, MachineIRBuilder &MIRBuilder, SPIRV::Decoration::Decoration Dec, uint32_t Member, const std::vector< uint32_t > &DecArgs, StringRef StrImm)
 
Type * toTypedPointer(Type *Ty)
 
bool isSpecialOpaqueType(const Type *Ty)
 
bool isPointerTy(const Type *T)
 
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
 
MachineBasicBlock::iterator getInsertPtValidEnd(MachineBasicBlock *MBB)
 
const Type * unifyPtrType(const Type *Ty)
 
const MachineInstr SPIRVType
 
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
 
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
 
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
 
std::function< void(Register)> StructOffsetDecorator
 
SPIRV::StorageClass::StorageClass addressSpaceToStorageClass(unsigned AddrSpace, const SPIRVSubtarget &STI)
 
void buildOpSpirvDecorations(Register Reg, MachineIRBuilder &MIRBuilder, const MDNode *GVarMD, const SPIRVSubtarget &ST)
 
Type * parseBasicTypeName(StringRef &TypeName, LLVMContext &Ctx)
 
DWARFExpression::Operation Op
 
constexpr unsigned BitWidth
 
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
 
bool hasBuiltinTypePrefix(StringRef Name)
 
bool isPointerTyOrWrapper(const Type *Ty)
 
bool isSpvIntrinsic(const MachineInstr &MI, Intrinsic::ID IntrinsicID)
 
PoisonValue * getNormalizedPoisonValue(Type *Ty)
 
void addStringImm(const StringRef &Str, MCInst &Inst)
 
MachineInstr * getVRegDef(MachineRegisterInfo &MRI, Register Reg)
 
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
 
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.