LLVM 24.0.0git
SPIRVUtils.h
Go to the documentation of this file.
1//===--- SPIRVUtils.h ---- SPIR-V Utility Functions -------------*- 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-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains miscellaneous utility functions.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVUTILS_H
14#define LLVM_LIB_TARGET_SPIRV_SPIRVUTILS_H
15
17#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/StringMap.h"
22#include "llvm/IR/Dominators.h"
24#include "llvm/IR/IRBuilder.h"
27#include <queue>
28#include <set>
29#include <string>
30
31#include "SPIRVTypeInst.h"
32
33namespace llvm {
34class MCInst;
35class MachineFunction;
39class Register;
40class StringRef;
41class Triple;
42class SPIRVInstrInfo;
43class SPIRVSubtarget;
45
46// This class implements a partial ordering visitor, which visits a cyclic graph
47// in natural topological-like ordering. Topological ordering is not defined for
48// directed graphs with cycles, so this assumes cycles are a single node, and
49// ignores back-edges. The cycle is visited from the entry in the same
50// topological-like ordering.
51//
52// Note: this visitor REQUIRES a reducible graph.
53//
54// This means once we visit a node, we know all the possible ancestors have been
55// visited.
56//
57// clang-format off
58//
59// Given this graph:
60//
61// ,-> B -\
62// A -+ +---> D ----> E -> F -> G -> H
63// `-> C -/ ^ |
64// +-----------------+
65//
66// Visit order is:
67// A, [B, C in any order], D, E, F, G, H
68//
69// clang-format on
70//
71// Changing the function CFG between the construction of the visitor and
72// visiting is undefined. The visitor can be reused, but if the CFG is updated,
73// the visitor must be rebuilt.
76 LoopInfo LI;
77
79 std::queue<BasicBlock *> ToVisit;
80
81 struct OrderInfo {
82 size_t Rank;
83 size_t TraversalIndex;
84 };
85
86 using BlockToOrderInfoMap = DenseMap<BasicBlock *, OrderInfo>;
87 BlockToOrderInfoMap BlockToOrder;
88 std::vector<BasicBlock *> Order;
89
90 // Get all basic-blocks reachable from Start.
91 SmallPtrSet<BasicBlock *, 0> getReachableFrom(BasicBlock *Start);
92
93 // Internal function used to determine the partial ordering.
94 // Visits |BB| with the current rank being |Rank|.
95 size_t visit(BasicBlock *BB, size_t Rank);
96
97 bool CanBeVisited(BasicBlock *BB) const;
98
99public:
100 size_t GetNodeRank(BasicBlock *BB) const;
101
102 // Build the visitor to operate on the function F.
104
105 // Returns the dominator tree computed for the function this visitor
106 // operates on.
107 const DomTreeBuilder::BBDomTree &getDominatorTree() const { return DT; }
108
109 // Returns true is |LHS| comes before |RHS| in the partial ordering.
110 // If |LHS| and |RHS| have the same rank, the traversal order determines the
111 // order (order is stable).
112 bool compare(const BasicBlock *LHS, const BasicBlock *RHS) const;
113
114 // Visit the function starting from the basic block |Start|, and calling |Op|
115 // on each visited BB. This traversal ignores back-edges, meaning this won't
116 // visit a node to which |Start| is not an ancestor.
117 // If Op returns |true|, the visitor continues. If |Op| returns false, the
118 // visitor will stop at that rank. This means if 2 nodes share the same rank,
119 // and Op returns false when visiting the first, the second will be visited
120 // afterwards. But none of their successors will.
121 void partialOrderVisit(BasicBlock &Start,
122 std::function<bool(BasicBlock *)> Op);
123};
124
125namespace SPIRV {
127 const Type *Ty = nullptr;
128 unsigned FastMathFlags = 0;
129 // When SPV_KHR_float_controls2 ContractionOff and SignzeroInfNanPreserve are
130 // deprecated, and we replace them with FPFastMathDefault appropriate flags
131 // instead. However, we have no guarantee about the order in which we will
132 // process execution modes. Therefore it could happen that we first process
133 // ContractionOff, setting AllowContraction bit to 0, and then we process
134 // FPFastMathDefault enabling AllowContraction bit, effectively invalidating
135 // ContractionOff. Because of that, it's best to keep separate bits for the
136 // different execution modes, and we will try and combine them later when we
137 // emit OpExecutionMode instructions.
138 bool ContractionOff = false;
140 bool FPFastMathDefault = false;
141
145};
146
148 : public SmallVector<SPIRV::FPFastMathDefaultInfo, 3> {
150 switch (BitWidth) {
151 case 16: // half
152 return 0;
153 case 32: // float
154 return 1;
155 case 64: // double
156 return 2;
157 default:
158 report_fatal_error("Expected BitWidth to be 16, 32, 64", false);
159 }
161 "Unreachable code in computeFPFastMathDefaultInfoVecIndex");
162 }
163};
164
165// This code restores function args/retvalue types for composite cases
166// because the final types should still be aggregate whereas they're i32
167// during the translation to cope with aggregate flattening etc.
170// This handles retrieving the original ASM constraints, which we had to spoof
171// into having a single output.
173} // namespace SPIRV
174
175// Add the given string as a series of integer operand, inserting null
176// terminators and padding to make sure the operands all have 32-bit
177// little-endian words.
178void addStringImm(StringRef Str, MCInst &Inst);
179void addStringImm(StringRef Str, MachineInstrBuilder &MIB);
180
181// Read the series of integer operands back as a null-terminated string using
182// the reverse of the logic in addStringImm.
183std::string getStringImm(const MachineInstr &MI, unsigned StartIndex);
184
185// Add the given numerical immediate to MIB.
186void addNumImm(const APInt &Imm, MachineInstrBuilder &MIB);
187
188// Add an OpName instruction for the given target register.
189void buildOpName(Register Target, StringRef Name, MachineIRBuilder &MIRBuilder);
190
191// Add an OpDecorate instruction for the given Reg.
192void buildOpDecorate(Register Reg, MachineIRBuilder &MIRBuilder,
193 SPIRV::Decoration::Decoration Dec,
194 ArrayRef<uint32_t> DecArgs, StringRef StrImm = "");
195void buildOpDecorate(Register Reg, MachineInstr &I, const SPIRVInstrInfo &TII,
196 SPIRV::Decoration::Decoration Dec,
197 ArrayRef<uint32_t> DecArgs, StringRef StrImm = "");
198
199// Add an OpDecorate instruction for the given Reg.
200void buildOpMemberDecorate(Register Reg, MachineIRBuilder &MIRBuilder,
201 SPIRV::Decoration::Decoration Dec, uint32_t Member,
202 ArrayRef<uint32_t> DecArgs, StringRef StrImm = "");
203
204// Add an OpDecorate instruction by "spirv.Decorations" metadata node.
205void buildOpSpirvDecorations(Register Reg, MachineIRBuilder &MIRBuilder,
206 const MDNode *GVarMD, const SPIRVSubtarget &ST);
207
208// Return a valid position for the OpVariable instruction inside a function,
209// i.e., at the beginning of the first block of the function.
211
212// Return a valid position for the instruction at the end of the block before
213// terminators and debug instructions.
215
216// Returns true if a pointer to the storage class can be casted to/from a
217// pointer to the Generic storage class.
218constexpr bool isGenericCastablePtr(SPIRV::StorageClass::StorageClass SC) {
219 switch (SC) {
220 case SPIRV::StorageClass::Workgroup:
221 case SPIRV::StorageClass::CrossWorkgroup:
222 case SPIRV::StorageClass::Function:
223 case SPIRV::StorageClass::CodeSectionINTEL:
224 return true;
225 default:
226 return false;
227 }
228}
229
230// Convert a SPIR-V storage class to the corresponding LLVM IR address space.
231// TODO: maybe the following two functions should be handled in the subtarget
232// to allow for different OpenCL vs Vulkan handling.
233constexpr unsigned
234storageClassToAddressSpace(SPIRV::StorageClass::StorageClass SC) {
235 switch (SC) {
236 case SPIRV::StorageClass::Function:
237 return SPIRVAS::Function;
238 case SPIRV::StorageClass::CrossWorkgroup:
240 case SPIRV::StorageClass::UniformConstant:
242 case SPIRV::StorageClass::Workgroup:
243 return SPIRVAS::Workgroup;
244 case SPIRV::StorageClass::Generic:
245 return SPIRVAS::Generic;
246 case SPIRV::StorageClass::DeviceOnlyINTEL:
248 case SPIRV::StorageClass::HostOnlyINTEL:
250 case SPIRV::StorageClass::Input:
251 return SPIRVAS::Input;
252 case SPIRV::StorageClass::Output:
253 return SPIRVAS::Output;
254 case SPIRV::StorageClass::CodeSectionINTEL:
256 case SPIRV::StorageClass::Private:
257 return SPIRVAS::Private;
258 case SPIRV::StorageClass::StorageBuffer:
260 case SPIRV::StorageClass::Uniform:
261 return SPIRVAS::Uniform;
262 case SPIRV::StorageClass::PushConstant:
264 default:
265 report_fatal_error("Unable to get address space id");
266 }
267}
268
269// Convert an LLVM IR address space to a SPIR-V storage class.
270SPIRV::StorageClass::StorageClass
271addressSpaceToStorageClass(unsigned AddrSpace, const SPIRVSubtarget &STI);
272
273SPIRV::MemorySemantics::MemorySemantics
274getMemSemanticsForStorageClass(SPIRV::StorageClass::StorageClass SC);
275
276SPIRV::MemorySemantics::MemorySemantics getMemSemantics(AtomicOrdering Ord);
277
278uint32_t getMemSemanticsWithStorageClass(const Triple &TT, uint32_t OrderSem,
279 uint32_t StorageClassSem);
280
281SPIRV::Scope::Scope getMemScope(const Triple &TT, LLVMContext &Ctx,
282 SyncScope::ID Id);
283
284// Find def instruction for the given ConstReg, walking through
285// spv_track_constant and ASSIGN_TYPE instructions. Updates ConstReg by def
286// of OpConstant instruction.
287MachineInstr *getDefInstrMaybeConstant(Register &ConstReg,
288 const MachineRegisterInfo *MRI);
289
290// Get constant integer value of the given ConstReg.
291uint64_t getIConstVal(Register ConstReg, const MachineRegisterInfo *MRI);
292
293// Check if MI is a SPIR-V specific intrinsic call.
294bool isSpvIntrinsic(const MachineInstr &MI, Intrinsic::ID IntrinsicID);
295// Check if it's a SPIR-V specific intrinsic call.
296bool isSpvIntrinsic(const Value *Arg);
297
298// Get type of i-th operand of the metadata node.
299Type *getMDOperandAsType(const MDNode *N, unsigned I);
300
301// Get the i-th operand of the metadata node as a ConstantInt, or nullptr if it
302// is out of range or not a ConstantInt.
303ConstantInt *getMDOperandAsConstInt(const MDNode *N, unsigned I);
304
305// If OpenCL or SPIR-V builtin function name is recognized, return a demangled
306// name, otherwise return an empty string.
307std::string getOclOrSpirvBuiltinDemangledName(StringRef Name);
308
309// Check if a string contains a builtin prefix.
310bool hasBuiltinTypePrefix(StringRef Name);
311
312// Check if given LLVM type is a special opaque builtin type.
313bool isSpecialOpaqueType(const Type *Ty);
314
315// Check if the function is an SPIR-V entry point
316bool isEntryPoint(const Function &F);
317
318// Parse basic scalar type name, substring TypeName, and return LLVM type.
319Type *parseBasicTypeName(StringRef &TypeName, LLVMContext &Ctx);
320
321// Sort blocks in a partial ordering, so each block is after all its
322// dominators. This should match both the SPIR-V and the MIR requirements.
323// Returns true if the function was changed.
324bool sortBlocks(Function &F);
325
326// Create a stack slot in the entry block of F for a value of the given type.
327AllocaInst *createVariable(Function &F, Type *Type);
328
329// Create a value in BB set to the value associated with the branch the block
330// terminator will take.
331Value *
332createExitVariable(BasicBlock *BB,
333 const DenseMap<BasicBlock *, ConstantInt *> &TargetToValue);
334
335// Check for peeled array structs and recursively reconstitute them. In HLSL
336// CBuffers, arrays may have padding between the elements, but not after the
337// last element. To represent this in LLVM IR an array [N x T] will be
338// represented as {[N-1 x {T, spirv.Padding}], T}. The function
339// matchPeeledArrayPattern recognizes this pattern retrieving the type {T,
340// spirv.Padding}, and the size N.
341bool matchPeeledArrayPattern(const StructType *Ty, Type *&OriginalElementType,
342 uint64_t &TotalSize);
343
344// This function will turn the type {[N-1 x {T, spirv.Padding}], T} back into
345// [N x {T, spirv.Padding}]. So it can be translated into SPIR-V. The offset
346// decorations will be such that there will be no padding after the array when
347// relevant.
348Type *reconstitutePeeledArrayType(Type *Ty);
349
350inline bool hasInitializer(const GlobalVariable *GV) {
351 if (!GV->hasInitializer())
352 return false;
353 if (const auto *Init = GV->getInitializer(); isa<UndefValue>(Init))
354 return GV->isConstant() && Init->getType()->isAggregateType();
355 return true;
356}
357
358// True if this is an instance of TypedPointerType.
359inline bool isTypedPointerTy(const Type *T) {
360 return T && T->getTypeID() == Type::TypedPointerTyID;
361}
362
363// True if this is an instance of PointerType.
364inline bool isUntypedPointerTy(const Type *T) {
365 return T && T->getTypeID() == Type::PointerTyID;
366}
367
368// True if this is an instance of PointerType or TypedPointerType.
369inline bool isPointerTy(const Type *T) {
371}
372
373// True if this is a vector whose element type is an (untyped) PointerType.
374inline bool isUntypedPointerVectorTy(const Type *T) {
376 isUntypedPointerTy(T->getScalarType());
377}
378
379// Get the address space of this pointer or pointer vector type for instances of
380// PointerType or TypedPointerType.
381inline unsigned getPointerAddressSpace(const Type *T) {
382 Type *SubT = T->getScalarType();
383 return SubT->getTypeID() == Type::PointerTyID
384 ? cast<PointerType>(SubT)->getAddressSpace()
385 : cast<TypedPointerType>(SubT)->getAddressSpace();
386}
387
388// Return true if the Argument is decorated with a pointee type
389inline bool hasPointeeTypeAttr(Argument *Arg) {
390 return Arg->hasByValAttr() || Arg->hasByRefAttr() || Arg->hasStructRetAttr();
391}
392
393// Return the pointee type of the argument or nullptr otherwise
395 if (Arg->hasByValAttr())
396 return Arg->getParamByValType();
397 if (Arg->hasStructRetAttr())
398 return Arg->getParamStructRetType();
399 if (Arg->hasByRefAttr())
400 return Arg->getParamByRefType();
401 return nullptr;
402}
403
404#define TYPED_PTR_TARGET_EXT_NAME "spirv.$TypedPointerType"
405inline Type *getTypedPointerWrapper(Type *ElemTy, unsigned AS) {
407 {ElemTy}, {AS});
408}
409
410inline bool isTypedPointerWrapper(const TargetExtType *ExtTy) {
411 return ExtTy->getName() == TYPED_PTR_TARGET_EXT_NAME &&
412 ExtTy->getNumIntParameters() == 1 &&
413 ExtTy->getNumTypeParameters() == 1;
414}
415
416// True if this is an instance of PointerType or TypedPointerType.
417inline bool isPointerTyOrWrapper(const Type *Ty) {
418 if (auto *ExtTy = dyn_cast<TargetExtType>(Ty))
419 return isTypedPointerWrapper(ExtTy);
420 return isPointerTy(Ty);
421}
422
423inline Type *applyWrappers(Type *Ty) {
424 if (auto *ExtTy = dyn_cast<TargetExtType>(Ty)) {
425 if (isTypedPointerWrapper(ExtTy))
426 return TypedPointerType::get(applyWrappers(ExtTy->getTypeParameter(0)),
427 ExtTy->getIntParameter(0));
428 } else if (auto *VecTy = dyn_cast<VectorType>(Ty)) {
429 Type *ElemTy = VecTy->getElementType();
430 Type *NewElemTy = ElemTy->isTargetExtTy() ? applyWrappers(ElemTy) : ElemTy;
431 if (NewElemTy != ElemTy)
432 return VectorType::get(NewElemTy, VecTy->getElementCount());
433 }
434 return Ty;
435}
436
437inline Type *getPointeeType(const Type *Ty) {
438 if (Ty) {
439 if (auto PType = dyn_cast<TypedPointerType>(Ty))
440 return PType->getElementType();
441 else if (auto *ExtTy = dyn_cast<TargetExtType>(Ty))
442 if (isTypedPointerWrapper(ExtTy))
443 return ExtTy->getTypeParameter(0);
444 }
445 return nullptr;
446}
447
448inline bool isUntypedEquivalentToTyExt(Type *Ty1, Type *Ty2) {
449 if (!isUntypedPointerTy(Ty1) || !Ty2)
450 return false;
451 if (auto *ExtTy = dyn_cast<TargetExtType>(Ty2))
452 if (isTypedPointerWrapper(ExtTy) &&
453 ExtTy->getTypeParameter(0) ==
455 ExtTy->getIntParameter(0) == cast<PointerType>(Ty1)->getAddressSpace())
456 return true;
457 return false;
458}
459
460inline bool isEquivalentTypes(Type *Ty1, Type *Ty2) {
461 return isUntypedEquivalentToTyExt(Ty1, Ty2) ||
463}
464
466 if (Type *NewTy = applyWrappers(Ty); NewTy != Ty)
467 return NewTy;
468 return isUntypedPointerTy(Ty)
471 : Ty;
472}
473
475 Type *OrigRetTy = FTy->getReturnType();
476 Type *RetTy = toTypedPointer(OrigRetTy);
477 bool IsUntypedPtr = false;
478 for (Type *PTy : FTy->params()) {
479 if (isUntypedPointerTy(PTy)) {
480 IsUntypedPtr = true;
481 break;
482 }
483 }
484 if (!IsUntypedPtr && RetTy == OrigRetTy)
485 return FTy;
486 SmallVector<Type *> ParamTys;
487 for (Type *PTy : FTy->params())
488 ParamTys.push_back(toTypedPointer(PTy));
489 return FunctionType::get(RetTy, ParamTys, FTy->isVarArg());
490}
491
492inline const Type *unifyPtrType(const Type *Ty) {
493 if (auto FTy = dyn_cast<FunctionType>(Ty))
494 return toTypedFunPointer(const_cast<FunctionType *>(FTy));
495 return toTypedPointer(const_cast<Type *>(Ty));
496}
497
498inline bool isVector1(Type *Ty) {
499 auto *FVTy = dyn_cast<FixedVectorType>(Ty);
500 return FVTy && FVTy->getNumElements() == 1;
501}
502
503// We define this predicate out of line to avoid having to include all OpTypes.
504bool isVectorType(SPIRVTypeInst SPVTy);
505
506// Per spec: "Vector types must be parameterized only with 2, 3, or
507// 4 components, plus any additional sizes enabled by capabilities.", and
508// we enable the Vector16 capability where available.
509inline bool requiresLongVectorEXT(unsigned NumComponents,
510 bool CanUseVector16 = true) {
511 return NumComponents != 2 && NumComponents != 3 && NumComponents != 4 &&
512 (!CanUseVector16 || (NumComponents != 8 && NumComponents != 16));
513}
514
515inline bool isLongVectorEXT(const Type *Ty, bool CanUseVector16 = true) {
516 if (auto *FVTy = dyn_cast<FixedVectorType>(Ty))
517 return requiresLongVectorEXT(FVTy->getNumElements(), CanUseVector16);
518 return false;
519}
520
521// Modify an LLVM type to conform with future transformations in IRTranslator.
522// At the moment use cases comprise only a <1 x Type> vector. To extend when/if
523// needed.
524inline Type *normalizeType(Type *Ty, bool CanUseAnyVectorRank) {
525 if (CanUseAnyVectorRank)
526 return Ty;
527
528 auto *FVTy = dyn_cast<FixedVectorType>(Ty);
529 if (!FVTy || FVTy->getNumElements() != 1)
530 return Ty;
531 // If it's a <1 x Type> vector type, replace it by the element type, because
532 // it's not a legal vector type in LLT and IRTranslator will represent it as
533 // the scalar eventually.
534 return normalizeType(FVTy->getElementType(), CanUseAnyVectorRank);
535}
536
538 bool CanUseAnyVectorRank) {
539 return PoisonValue::get(normalizeType(Ty, CanUseAnyVectorRank));
540}
541
543 LLVMContext &Ctx = Arg->getContext();
546}
547
548CallInst *buildIntrWithMD(Intrinsic::ID IntrID, ArrayRef<Type *> Types,
549 Value *Arg, Value *Arg2, ArrayRef<Constant *> Imms,
550 IRBuilder<> &B);
551
552MachineInstr *getVRegDef(MachineRegisterInfo &MRI, Register Reg);
553
554#define SPIRV_BACKEND_SERVICE_FUN_NAME "__spirv_backend_service_fun"
555#define SPIRV_WAS_AVAILABLE_EXTERNALLY_ATTR "spv.was-available-externally"
556
557void setRegClassType(Register Reg, const Type *Ty, SPIRVGlobalRegistry *GR,
558 MachineIRBuilder &MIRBuilder,
559 SPIRV::AccessQualifier::AccessQualifier AccessQual,
560 bool EmitIR, bool Force = false);
561void setRegClassType(Register Reg, SPIRVTypeInst SpvType,
562 SPIRVGlobalRegistry *GR, MachineRegisterInfo *MRI,
563 const MachineFunction &MF, bool Force = false);
564Register createVirtualRegister(SPIRVTypeInst SpvType, SPIRVGlobalRegistry *GR,
565 MachineRegisterInfo *MRI,
566 const MachineFunction &MF);
567Register createVirtualRegister(SPIRVTypeInst SpvType, SPIRVGlobalRegistry *GR,
568 MachineIRBuilder &MIRBuilder);
570 const Type *Ty, SPIRVGlobalRegistry *GR, MachineIRBuilder &MIRBuilder,
571 SPIRV::AccessQualifier::AccessQualifier AccessQual, bool EmitIR);
572
573// Return true if there is an opaque pointer type nested in the argument.
574bool isNestedPointer(const Type *Ty);
575
577
578inline FPDecorationId demangledPostfixToDecorationId(const std::string &S) {
579 static const StringMap<FPDecorationId> Mapping = {
580 {"rte", FPDecorationId::RTE},
581 {"rtz", FPDecorationId::RTZ},
582 {"rtp", FPDecorationId::RTP},
583 {"rtn", FPDecorationId::RTN},
584 {"sat", FPDecorationId::SAT}};
585 auto It = Mapping.find(S);
586 return It == Mapping.end() ? FPDecorationId::NONE : It->second;
587}
588
589SmallVector<MachineInstr *, 4>
590createContinuedInstructions(MachineIRBuilder &MIRBuilder, unsigned Opcode,
591 unsigned MinWC, unsigned ContinuedOpcode,
592 ArrayRef<Register> Args, Register ReturnRegister,
594
595// Instruction selection directed by type folding.
596const std::set<unsigned> &getTypeFoldingSupportedOpcodes();
597bool isTypeFoldingSupported(unsigned Opcode);
598
599// Get loop controls from llvm.loop. metadata.
600SmallVector<unsigned, 1> getSpirvLoopControlOperandsFromLoopMetadata(Loop *L);
601SmallVector<unsigned, 1>
603
604// Traversing [g]MIR accounting for pseudo-instructions.
605MachineInstr *passCopy(MachineInstr *Def, const MachineRegisterInfo *MRI);
606MachineInstr *getDef(const MachineOperand &MO, const MachineRegisterInfo *MRI);
607MachineInstr *getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI);
608int64_t foldImm(const MachineOperand &MO, const MachineRegisterInfo *MRI);
609unsigned getArrayComponentCount(const MachineRegisterInfo *MRI,
610 const MachineInstr *ResType);
611
612std::optional<SPIRV::LinkageType::LinkageType>
613getSpirvLinkageTypeFor(const SPIRVSubtarget &ST, const GlobalValue &GV);
615} // namespace llvm
616#endif // LLVM_LIB_TARGET_SPIRV_SPIRVUTILS_H
const AArch64InstrInfo & TII
This file defines the StringMap class.
uint64_t uint64_t
uint64_t Imm
MachineBasicBlock & MBB
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file defines the DenseMap class.
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Machine Check Debug Module
Register Reg
Promote Memory to Register
Definition Mem2Reg.cpp:110
Type::TypeID TypeID
#define T
MachineRegisterInfo & MRI
SPIR-V address space definition.
#define TYPED_PTR_TARGET_EXT_NAME
Definition SPIRVUtils.h:404
This file defines the SmallPtrSet class.
Value * RHS
Value * LHS
This class represents an incoming formal argument to a Function.
Definition Argument.h:32
LLVM_ABI Type * getParamByRefType() const
If this is a byref argument, return its type.
Definition Function.cpp:228
LLVM_ABI bool hasByRefAttr() const
Return true if this argument has the byref attribute.
Definition Function.cpp:136
LLVM_ABI Type * getParamStructRetType() const
If this is an sret argument, return its type.
Definition Function.cpp:223
LLVM_ABI bool hasByValAttr() const
Return true if this argument has the byval attribute.
Definition Function.cpp:126
LLVM_ABI Type * getParamByValType() const
If this is a byval argument, return its type.
Definition Function.cpp:218
LLVM_ABI bool hasStructRetAttr() const
Return true if this argument has the sret attribute.
Definition Function.cpp:281
LLVM Basic Block Representation.
Definition BasicBlock.h:62
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Class to represent function types.
ArrayRef< Type * > params() const
bool isVarArg() const
Type * getReturnType() const
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool hasInitializer() const
Definitions have initializers, declarations don't.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1588
MachineInstrBundleIterator< MachineInstr > iterator
Helper class to build MachineInstr.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Metadata wrapper in the Value hierarchy.
Definition Metadata.h:185
static LLVM_ABI MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition Metadata.cpp:105
size_t GetNodeRank(BasicBlock *BB) const
void partialOrderVisit(BasicBlock &Start, std::function< bool(BasicBlock *)> Op)
bool compare(const BasicBlock *LHS, const BasicBlock *RHS) const
const DomTreeBuilder::BBDomTree & getDominatorTree() const
Definition SPIRVUtils.h:107
In order to facilitate speculative execution, many instructions do not invoke immediate undefined beh...
Definition Constants.h:1705
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.
Definition Register.h:20
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:129
iterator end()
Definition StringMap.h:214
iterator find(StringRef Key)
Definition StringMap.h:227
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Class to represent target extensions types, which are generally unintrospectable from target-independ...
unsigned getNumIntParameters() const
static LLVM_ABI TargetExtType * get(LLVMContext &Context, StringRef Name, ArrayRef< Type * > Types={}, ArrayRef< unsigned > Ints={})
Return a target extension type having the specified name and optional type and integer parameters.
Definition Type.cpp:931
unsigned getNumTypeParameters() const
StringRef getName() const
Return the name for this target extension type.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
@ TypedPointerTyID
Typed pointer used by some GPU targets.
Definition Type.h:79
@ PointerTyID
Pointers.
Definition Type.h:74
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Definition Type.cpp:292
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition Type.h:130
TypeID getTypeID() const
Return the type id for the type.
Definition Type.h:138
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.
static ConstantAsMetadata * getConstant(Value *C)
Definition Metadata.h:493
LLVM Value Representation.
Definition Value.h:75
LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.h:260
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
DomTreeBase< BasicBlock > BBDomTree
Definition Dominators.h:55
FunctionType * getOriginalFunctionType(const Function &F)
StringRef getOriginalAsmConstraints(const CallBase &CB)
This is an optimization pass for GlobalISel generic memory operations.
std::string getStringImm(const MachineInstr &MI, unsigned StartIndex)
void addStringImm(StringRef Str, MCInst &Inst)
MachineBasicBlock::iterator getOpVariableMBBIt(MachineFunction &MF)
bool isTypedPointerWrapper(const TargetExtType *ExtTy)
Definition SPIRVUtils.h:410
bool isTypeFoldingSupported(unsigned Opcode)
uint32_t getMemSemanticsWithStorageClass(const Triple &TT, uint32_t OrderSem, uint32_t StorageClassSem)
unsigned getPointerAddressSpace(const Type *T)
Definition SPIRVUtils.h:381
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
MachineInstr * getDef(const MachineOperand &MO, const MachineRegisterInfo *MRI)
void addNumImm(const APInt &Imm, MachineInstrBuilder &MIB)
FPDecorationId demangledPostfixToDecorationId(const std::string &S)
Definition SPIRVUtils.h:578
CallInst * buildIntrWithMD(Intrinsic::ID IntrID, ArrayRef< Type * > Types, Value *Arg, Value *Arg2, ArrayRef< Constant * > Imms, IRBuilder<> &B)
bool isUntypedPointerVectorTy(const Type *T)
Definition SPIRVUtils.h:374
bool matchPeeledArrayPattern(const StructType *Ty, Type *&OriginalElementType, uint64_t &TotalSize)
Register createVirtualRegister(SPIRVTypeInst SpvType, SPIRVGlobalRegistry *GR, MachineRegisterInfo *MRI, const MachineFunction &MF)
unsigned getArrayComponentCount(const MachineRegisterInfo *MRI, const MachineInstr *ResType)
bool sortBlocks(Function &F)
Type * toTypedFunPointer(FunctionType *FTy)
Definition SPIRVUtils.h:474
FPDecorationId
Definition SPIRVUtils.h:576
AllocaInst * createVariable(Function &F, Type *Type)
void buildOpDecorate(Register Reg, MachineIRBuilder &MIRBuilder, SPIRV::Decoration::Decoration Dec, ArrayRef< uint32_t > DecArgs, StringRef StrImm)
bool isa_and_nonnull(const Y &Val)
Definition Casting.h:676
SPIRV::Scope::Scope getMemScope(const Triple &TT, LLVMContext &Ctx, SyncScope::ID Id)
uint64_t getIConstVal(Register ConstReg, const MachineRegisterInfo *MRI)
SmallVector< MachineInstr *, 4 > createContinuedInstructions(MachineIRBuilder &MIRBuilder, unsigned Opcode, unsigned MinWC, unsigned ContinuedOpcode, ArrayRef< Register > Args, Register ReturnRegister, Register TypeID)
SPIRV::MemorySemantics::MemorySemantics getMemSemanticsForStorageClass(SPIRV::StorageClass::StorageClass SC)
constexpr unsigned storageClassToAddressSpace(SPIRV::StorageClass::StorageClass SC)
Definition SPIRVUtils.h:234
bool isVectorType(SPIRVTypeInst SPVTy)
bool isNestedPointer(const Type *Ty)
Function * getOrCreateBackendServiceFunction(Module &M)
MetadataAsValue * buildMD(Value *Arg)
Definition SPIRVUtils.h:542
std::string getOclOrSpirvBuiltinDemangledName(StringRef Name)
bool isTypedPointerTy(const Type *T)
Definition SPIRVUtils.h:359
void buildOpName(Register Target, StringRef Name, MachineIRBuilder &MIRBuilder)
bool isUntypedEquivalentToTyExt(Type *Ty1, Type *Ty2)
Definition SPIRVUtils.h:448
SmallVector< unsigned, 1 > getSpirvLoopControlOperandsFromLoopMetadata(MDNode *LoopMD)
Type * normalizeType(Type *Ty, bool CanUseAnyVectorRank)
Definition SPIRVUtils.h:524
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
Type * getTypedPointerWrapper(Type *ElemTy, unsigned AS)
Definition SPIRVUtils.h:405
Type * toTypedPointer(Type *Ty)
Definition SPIRVUtils.h:465
ConstantInt * getMDOperandAsConstInt(const MDNode *N, unsigned I)
bool isVector1(Type *Ty)
Definition SPIRVUtils.h:498
bool isSpecialOpaqueType(const Type *Ty)
bool isPointerTy(const Type *T)
Definition SPIRVUtils.h:369
IRBuilder(LLVMContext &, FolderTy, InserterTy) -> IRBuilder< FolderTy, InserterTy >
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
void setRegClassType(Register Reg, SPIRVTypeInst SpvType, SPIRVGlobalRegistry *GR, MachineRegisterInfo *MRI, const MachineFunction &MF, bool Force)
MachineBasicBlock::iterator getInsertPtValidEnd(MachineBasicBlock *MBB)
const Type * unifyPtrType(const Type *Ty)
Definition SPIRVUtils.h:492
constexpr bool isGenericCastablePtr(SPIRV::StorageClass::StorageClass SC)
Definition SPIRVUtils.h:218
MachineInstr * passCopy(MachineInstr *Def, const MachineRegisterInfo *MRI)
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...
Definition Casting.h:547
std::optional< SPIRV::LinkageType::LinkageType > getSpirvLinkageTypeFor(const SPIRVSubtarget &ST, const GlobalValue &GV)
bool isEntryPoint(const Function &F)
const std::set< unsigned > & getTypeFoldingSupportedOpcodes()
SPIRV::StorageClass::StorageClass addressSpaceToStorageClass(unsigned AddrSpace, const SPIRVSubtarget &STI)
void buildOpSpirvDecorations(Register Reg, MachineIRBuilder &MIRBuilder, const MDNode *GVarMD, const SPIRVSubtarget &ST)
int64_t foldImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
bool isLongVectorEXT(const Type *Ty, bool CanUseVector16=true)
Definition SPIRVUtils.h:515
Type * parseBasicTypeName(StringRef &TypeName, LLVMContext &Ctx)
bool requiresLongVectorEXT(unsigned NumComponents, bool CanUseVector16=true)
Definition SPIRVUtils.h:509
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
Type * getPointeeTypeByAttr(Argument *Arg)
Definition SPIRVUtils.h:394
bool hasPointeeTypeAttr(Argument *Arg)
Definition SPIRVUtils.h:389
MachineInstr * getDefInstrMaybeConstant(Register &ConstReg, const MachineRegisterInfo *MRI)
constexpr unsigned BitWidth
Value * createExitVariable(BasicBlock *BB, const DenseMap< BasicBlock *, ConstantInt * > &TargetToValue)
bool isEquivalentTypes(Type *Ty1, Type *Ty2)
Definition SPIRVUtils.h:460
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
bool hasBuiltinTypePrefix(StringRef Name)
Type * getMDOperandAsType(const MDNode *N, unsigned I)
void buildOpMemberDecorate(Register Reg, MachineIRBuilder &MIRBuilder, SPIRV::Decoration::Decoration Dec, uint32_t Member, ArrayRef< uint32_t > DecArgs, StringRef StrImm)
bool hasInitializer(const GlobalVariable *GV)
Definition SPIRVUtils.h:350
Type * applyWrappers(Type *Ty)
Definition SPIRVUtils.h:423
bool isPointerTyOrWrapper(const Type *Ty)
Definition SPIRVUtils.h:417
bool isSpvIntrinsic(const MachineInstr &MI, Intrinsic::ID IntrinsicID)
Type * getPointeeType(const Type *Ty)
Definition SPIRVUtils.h:437
PoisonValue * getNormalizedPoisonValue(Type *Ty, bool CanUseAnyVectorRank)
Definition SPIRVUtils.h:537
MachineInstr * getVRegDef(MachineRegisterInfo &MRI, Register Reg)
bool isUntypedPointerTy(const Type *T)
Definition SPIRVUtils.h:364
Type * reconstitutePeeledArrayType(Type *Ty)
SPIRV::MemorySemantics::MemorySemantics getMemSemantics(AtomicOrdering Ord)
#define N
static size_t computeFPFastMathDefaultInfoVecIndex(size_t BitWidth)
Definition SPIRVUtils.h:149
FPFastMathDefaultInfo(const Type *Ty, unsigned FastMathFlags)
Definition SPIRVUtils.h:143