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