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