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