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