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