Thanks to visit codestin.com
Credit goes to llvm.org

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} // namespace SPIRV
163
164// Add the given string as a series of integer operand, inserting null
165// terminators and padding to make sure the operands all have 32-bit
166// little-endian words.
167void addStringImm(const StringRef &Str, MCInst &Inst);
168void addStringImm(const StringRef &Str, MachineInstrBuilder &MIB);
169void addStringImm(const StringRef &Str, IRBuilder<> &B,
170 std::vector<Value *> &Args);
171
172// Read the series of integer operands back as a null-terminated string using
173// the reverse of the logic in addStringImm.
174std::string getStringImm(const MachineInstr &MI, unsigned StartIndex);
175
176// Returns the string constant that the register refers to. It is assumed that
177// Reg is a global value that contains a string.
178std::string getStringValueFromReg(Register Reg, MachineRegisterInfo &MRI);
179
180// Add the given numerical immediate to MIB.
181void addNumImm(const APInt &Imm, MachineInstrBuilder &MIB);
182
183// Add an OpName instruction for the given target register.
184void buildOpName(Register Target, const StringRef &Name,
185 MachineIRBuilder &MIRBuilder);
186void buildOpName(Register Target, const StringRef &Name, MachineInstr &I,
187 const SPIRVInstrInfo &TII);
188
189// Add an OpDecorate instruction for the given Reg.
190void buildOpDecorate(Register Reg, MachineIRBuilder &MIRBuilder,
191 SPIRV::Decoration::Decoration Dec,
192 const std::vector<uint32_t> &DecArgs,
193 StringRef StrImm = "");
194void buildOpDecorate(Register Reg, MachineInstr &I, const SPIRVInstrInfo &TII,
195 SPIRV::Decoration::Decoration Dec,
196 const std::vector<uint32_t> &DecArgs,
197 StringRef StrImm = "");
198
199// Add an OpDecorate instruction for the given Reg.
200void buildOpMemberDecorate(Register Reg, MachineIRBuilder &MIRBuilder,
201 SPIRV::Decoration::Decoration Dec, uint32_t Member,
202 const std::vector<uint32_t> &DecArgs,
203 StringRef StrImm = "");
204void buildOpMemberDecorate(Register Reg, MachineInstr &I,
205 const SPIRVInstrInfo &TII,
206 SPIRV::Decoration::Decoration Dec, uint32_t Member,
207 const std::vector<uint32_t> &DecArgs,
208 StringRef StrImm = "");
209
210// Add an OpDecorate instruction by "spirv.Decorations" metadata node.
211void buildOpSpirvDecorations(Register Reg, MachineIRBuilder &MIRBuilder,
212 const MDNode *GVarMD, const SPIRVSubtarget &ST);
213
214// Return a valid position for the OpVariable instruction inside a function,
215// i.e., at the beginning of the first block of the function.
217
218// Return a valid position for the instruction at the end of the block before
219// terminators and debug instructions.
221
222// Returns true if a pointer to the storage class can be casted to/from a
223// pointer to the Generic storage class.
224constexpr bool isGenericCastablePtr(SPIRV::StorageClass::StorageClass SC) {
225 switch (SC) {
226 case SPIRV::StorageClass::Workgroup:
227 case SPIRV::StorageClass::CrossWorkgroup:
228 case SPIRV::StorageClass::Function:
229 return true;
230 default:
231 return false;
232 }
233}
234
235// Convert a SPIR-V storage class to the corresponding LLVM IR address space.
236// TODO: maybe the following two functions should be handled in the subtarget
237// to allow for different OpenCL vs Vulkan handling.
238constexpr unsigned
239storageClassToAddressSpace(SPIRV::StorageClass::StorageClass SC) {
240 switch (SC) {
241 case SPIRV::StorageClass::Function:
242 return 0;
243 case SPIRV::StorageClass::CrossWorkgroup:
244 return 1;
245 case SPIRV::StorageClass::UniformConstant:
246 return 2;
247 case SPIRV::StorageClass::Workgroup:
248 return 3;
249 case SPIRV::StorageClass::Generic:
250 return 4;
251 case SPIRV::StorageClass::DeviceOnlyINTEL:
252 return 5;
253 case SPIRV::StorageClass::HostOnlyINTEL:
254 return 6;
255 case SPIRV::StorageClass::Input:
256 return 7;
257 case SPIRV::StorageClass::Output:
258 return 8;
259 case SPIRV::StorageClass::CodeSectionINTEL:
260 return 9;
261 case SPIRV::StorageClass::Private:
262 return 10;
263 case SPIRV::StorageClass::StorageBuffer:
264 return 11;
265 case SPIRV::StorageClass::Uniform:
266 return 12;
267 default:
268 report_fatal_error("Unable to get address space id");
269 }
270}
271
272// Convert an LLVM IR address space to a SPIR-V storage class.
273SPIRV::StorageClass::StorageClass
274addressSpaceToStorageClass(unsigned AddrSpace, const SPIRVSubtarget &STI);
275
276SPIRV::MemorySemantics::MemorySemantics
277getMemSemanticsForStorageClass(SPIRV::StorageClass::StorageClass SC);
278
279SPIRV::MemorySemantics::MemorySemantics getMemSemantics(AtomicOrdering Ord);
280
281SPIRV::Scope::Scope getMemScope(LLVMContext &Ctx, SyncScope::ID Id);
282
283// Find def instruction for the given ConstReg, walking through
284// spv_track_constant and ASSIGN_TYPE instructions. Updates ConstReg by def
285// of OpConstant instruction.
286MachineInstr *getDefInstrMaybeConstant(Register &ConstReg,
287 const MachineRegisterInfo *MRI);
288
289// Get constant integer value of the given ConstReg.
290uint64_t getIConstVal(Register ConstReg, const MachineRegisterInfo *MRI);
291
292// Check if MI is a SPIR-V specific intrinsic call.
293bool isSpvIntrinsic(const MachineInstr &MI, Intrinsic::ID IntrinsicID);
294// Check if it's a SPIR-V specific intrinsic call.
295bool isSpvIntrinsic(const Value *Arg);
296
297// Get type of i-th operand of the metadata node.
298Type *getMDOperandAsType(const MDNode *N, unsigned I);
299
300// If OpenCL or SPIR-V builtin function name is recognized, return a demangled
301// name, otherwise return an empty string.
302std::string getOclOrSpirvBuiltinDemangledName(StringRef Name);
303
304// Check if a string contains a builtin prefix.
305bool hasBuiltinTypePrefix(StringRef Name);
306
307// Check if given LLVM type is a special opaque builtin type.
308bool isSpecialOpaqueType(const Type *Ty);
309
310// Check if the function is an SPIR-V entry point
311bool isEntryPoint(const Function &F);
312
313// Parse basic scalar type name, substring TypeName, and return LLVM type.
314Type *parseBasicTypeName(StringRef &TypeName, LLVMContext &Ctx);
315
316// Sort blocks in a partial ordering, so each block is after all its
317// dominators. This should match both the SPIR-V and the MIR requirements.
318// Returns true if the function was changed.
319bool sortBlocks(Function &F);
320
321inline bool hasInitializer(const GlobalVariable *GV) {
322 return GV->hasInitializer() && !isa<UndefValue>(GV->getInitializer());
323}
324
325// True if this is an instance of TypedPointerType.
326inline bool isTypedPointerTy(const Type *T) {
327 return T && T->getTypeID() == Type::TypedPointerTyID;
328}
329
330// True if this is an instance of PointerType.
331inline bool isUntypedPointerTy(const Type *T) {
332 return T && T->getTypeID() == Type::PointerTyID;
333}
334
335// True if this is an instance of PointerType or TypedPointerType.
336inline bool isPointerTy(const Type *T) {
338}
339
340// Get the address space of this pointer or pointer vector type for instances of
341// PointerType or TypedPointerType.
342inline unsigned getPointerAddressSpace(const Type *T) {
343 Type *SubT = T->getScalarType();
344 return SubT->getTypeID() == Type::PointerTyID
345 ? cast<PointerType>(SubT)->getAddressSpace()
346 : cast<TypedPointerType>(SubT)->getAddressSpace();
347}
348
349// Return true if the Argument is decorated with a pointee type
350inline bool hasPointeeTypeAttr(Argument *Arg) {
351 return Arg->hasByValAttr() || Arg->hasByRefAttr() || Arg->hasStructRetAttr();
352}
353
354// Return the pointee type of the argument or nullptr otherwise
356 if (Arg->hasByValAttr())
357 return Arg->getParamByValType();
358 if (Arg->hasStructRetAttr())
359 return Arg->getParamStructRetType();
360 if (Arg->hasByRefAttr())
361 return Arg->getParamByRefType();
362 return nullptr;
363}
364
366 SmallVector<Type *> ArgTys;
367 for (unsigned i = 0; i < F->arg_size(); ++i)
368 ArgTys.push_back(F->getArg(i)->getType());
369 return FunctionType::get(F->getReturnType(), ArgTys, F->isVarArg());
370}
371
372#define TYPED_PTR_TARGET_EXT_NAME "spirv.$TypedPointerType"
373inline Type *getTypedPointerWrapper(Type *ElemTy, unsigned AS) {
374 return TargetExtType::get(ElemTy->getContext(), TYPED_PTR_TARGET_EXT_NAME,
375 {ElemTy}, {AS});
376}
377
378inline bool isTypedPointerWrapper(const TargetExtType *ExtTy) {
379 return ExtTy->getName() == TYPED_PTR_TARGET_EXT_NAME &&
380 ExtTy->getNumIntParameters() == 1 &&
381 ExtTy->getNumTypeParameters() == 1;
382}
383
384// True if this is an instance of PointerType or TypedPointerType.
385inline bool isPointerTyOrWrapper(const Type *Ty) {
386 if (auto *ExtTy = dyn_cast<TargetExtType>(Ty))
387 return isTypedPointerWrapper(ExtTy);
388 return isPointerTy(Ty);
389}
390
391inline Type *applyWrappers(Type *Ty) {
392 if (auto *ExtTy = dyn_cast<TargetExtType>(Ty)) {
393 if (isTypedPointerWrapper(ExtTy))
394 return TypedPointerType::get(applyWrappers(ExtTy->getTypeParameter(0)),
395 ExtTy->getIntParameter(0));
396 } else if (auto *VecTy = dyn_cast<VectorType>(Ty)) {
397 Type *ElemTy = VecTy->getElementType();
398 Type *NewElemTy = ElemTy->isTargetExtTy() ? applyWrappers(ElemTy) : ElemTy;
399 if (NewElemTy != ElemTy)
400 return VectorType::get(NewElemTy, VecTy->getElementCount());
401 }
402 return Ty;
403}
404
405inline Type *getPointeeType(const Type *Ty) {
406 if (Ty) {
407 if (auto PType = dyn_cast<TypedPointerType>(Ty))
408 return PType->getElementType();
409 else if (auto *ExtTy = dyn_cast<TargetExtType>(Ty))
410 if (isTypedPointerWrapper(ExtTy))
411 return ExtTy->getTypeParameter(0);
412 }
413 return nullptr;
414}
415
416inline bool isUntypedEquivalentToTyExt(Type *Ty1, Type *Ty2) {
417 if (!isUntypedPointerTy(Ty1) || !Ty2)
418 return false;
419 if (auto *ExtTy = dyn_cast<TargetExtType>(Ty2))
420 if (isTypedPointerWrapper(ExtTy) &&
421 ExtTy->getTypeParameter(0) ==
423 ExtTy->getIntParameter(0) == cast<PointerType>(Ty1)->getAddressSpace())
424 return true;
425 return false;
426}
427
428inline bool isEquivalentTypes(Type *Ty1, Type *Ty2) {
429 return isUntypedEquivalentToTyExt(Ty1, Ty2) ||
431}
432
434 if (Type *NewTy = applyWrappers(Ty); NewTy != Ty)
435 return NewTy;
436 return isUntypedPointerTy(Ty)
439 : Ty;
440}
441
443 Type *OrigRetTy = FTy->getReturnType();
444 Type *RetTy = toTypedPointer(OrigRetTy);
445 bool IsUntypedPtr = false;
446 for (Type *PTy : FTy->params()) {
447 if (isUntypedPointerTy(PTy)) {
448 IsUntypedPtr = true;
449 break;
450 }
451 }
452 if (!IsUntypedPtr && RetTy == OrigRetTy)
453 return FTy;
454 SmallVector<Type *> ParamTys;
455 for (Type *PTy : FTy->params())
456 ParamTys.push_back(toTypedPointer(PTy));
457 return FunctionType::get(RetTy, ParamTys, FTy->isVarArg());
458}
459
460inline const Type *unifyPtrType(const Type *Ty) {
461 if (auto FTy = dyn_cast<FunctionType>(Ty))
462 return toTypedFunPointer(const_cast<FunctionType *>(FTy));
463 return toTypedPointer(const_cast<Type *>(Ty));
464}
465
466inline bool isVector1(Type *Ty) {
467 auto *FVTy = dyn_cast<FixedVectorType>(Ty);
468 return FVTy && FVTy->getNumElements() == 1;
469}
470
471// Modify an LLVM type to conform with future transformations in IRTranslator.
472// At the moment use cases comprise only a <1 x Type> vector. To extend when/if
473// needed.
474inline Type *normalizeType(Type *Ty) {
475 auto *FVTy = dyn_cast<FixedVectorType>(Ty);
476 if (!FVTy || FVTy->getNumElements() != 1)
477 return Ty;
478 // If it's a <1 x Type> vector type, replace it by the element type, because
479 // it's not a legal vector type in LLT and IRTranslator will represent it as
480 // the scalar eventually.
481 return normalizeType(FVTy->getElementType());
482}
483
487
489 LLVMContext &Ctx = Arg->getContext();
492}
493
494CallInst *buildIntrWithMD(Intrinsic::ID IntrID, ArrayRef<Type *> Types,
495 Value *Arg, Value *Arg2, ArrayRef<Constant *> Imms,
496 IRBuilder<> &B);
497
498MachineInstr *getVRegDef(MachineRegisterInfo &MRI, Register Reg);
499
500#define SPIRV_BACKEND_SERVICE_FUN_NAME "__spirv_backend_service_fun"
501bool getVacantFunctionName(Module &M, std::string &Name);
502
503void setRegClassType(Register Reg, const Type *Ty, SPIRVGlobalRegistry *GR,
504 MachineIRBuilder &MIRBuilder,
505 SPIRV::AccessQualifier::AccessQualifier AccessQual,
506 bool EmitIR, bool Force = false);
509 const MachineFunction &MF, bool Force = false);
513 const MachineFunction &MF);
516 MachineIRBuilder &MIRBuilder);
518 const Type *Ty, SPIRVGlobalRegistry *GR, MachineIRBuilder &MIRBuilder,
519 SPIRV::AccessQualifier::AccessQualifier AccessQual, bool EmitIR);
520
521// Return true if there is an opaque pointer type nested in the argument.
522bool isNestedPointer(const Type *Ty);
523
525
526inline FPDecorationId demangledPostfixToDecorationId(const std::string &S) {
527 static std::unordered_map<std::string, FPDecorationId> Mapping = {
528 {"rte", FPDecorationId::RTE},
529 {"rtz", FPDecorationId::RTZ},
530 {"rtp", FPDecorationId::RTP},
531 {"rtn", FPDecorationId::RTN},
532 {"sat", FPDecorationId::SAT}};
533 auto It = Mapping.find(S);
534 return It == Mapping.end() ? FPDecorationId::NONE : It->second;
535}
536
537SmallVector<MachineInstr *, 4>
538createContinuedInstructions(MachineIRBuilder &MIRBuilder, unsigned Opcode,
539 unsigned MinWC, unsigned ContinuedOpcode,
540 ArrayRef<Register> Args, Register ReturnRegister,
542
543// Instruction selection directed by type folding.
544const std::set<unsigned> &getTypeFoldingSupportedOpcodes();
545bool isTypeFoldingSupported(unsigned Opcode);
546
547// Get loop controls from llvm.loop. metadata.
549
550// Traversing [g]MIR accounting for pseudo-instructions.
551MachineInstr *passCopy(MachineInstr *Def, const MachineRegisterInfo *MRI);
552MachineInstr *getDef(const MachineOperand &MO, const MachineRegisterInfo *MRI);
553MachineInstr *getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI);
554int64_t foldImm(const MachineOperand &MO, const MachineRegisterInfo *MRI);
555unsigned getArrayComponentCount(const MachineRegisterInfo *MRI,
556 const MachineInstr *ResType);
558getFirstValidInstructionInsertPoint(MachineBasicBlock &BB);
559} // namespace llvm
560#endif // LLVM_LIB_TARGET_SPIRV_SPIRVUTILS_H
unsigned const MachineRegisterInfo * MRI
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:55
#define I(x, y, z)
Definition MD5.cpp:58
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:372
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
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:1468
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:19
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:908
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:295
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:56
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)
bool isTypedPointerWrapper(const TargetExtType *ExtTy)
Definition SPIRVUtils.h:378
bool isTypeFoldingSupported(unsigned Opcode)
unsigned getPointerAddressSpace(const Type *T)
Definition SPIRVUtils.h:342
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:644
MachineInstr * getDef(const MachineOperand &MO, const MachineRegisterInfo *MRI)
void addNumImm(const APInt &Imm, MachineInstrBuilder &MIB)
FPDecorationId demangledPostfixToDecorationId(const std::string &S)
Definition SPIRVUtils.h:526
CallInst * buildIntrWithMD(Intrinsic::ID IntrID, ArrayRef< Type * > Types, Value *Arg, Value *Arg2, ArrayRef< Constant * > Imms, IRBuilder<> &B)
unsigned getArrayComponentCount(const MachineRegisterInfo *MRI, const MachineInstr *ResType)
bool sortBlocks(Function &F)
Type * toTypedFunPointer(FunctionType *FTy)
Definition SPIRVUtils.h:442
FPDecorationId
Definition SPIRVUtils.h:524
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:239
MachineBasicBlock::iterator getFirstValidInstructionInsertPoint(MachineBasicBlock &BB)
bool isNestedPointer(const Type *Ty)
MetadataAsValue * buildMD(Value *Arg)
Definition SPIRVUtils.h:488
std::string getOclOrSpirvBuiltinDemangledName(StringRef Name)
bool isTypedPointerTy(const Type *T)
Definition SPIRVUtils.h:326
bool isUntypedEquivalentToTyExt(Type *Ty1, Type *Ty2)
Definition SPIRVUtils.h:416
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:373
Type * reconstructFunctionType(Function *F)
Definition SPIRVUtils.h:365
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:433
bool isVector1(Type *Ty)
Definition SPIRVUtils.h:466
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:336
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:460
constexpr bool isGenericCastablePtr(SPIRV::StorageClass::StorageClass SC)
Definition SPIRVUtils.h:224
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:548
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:355
bool hasPointeeTypeAttr(Argument *Arg)
Definition SPIRVUtils.h:350
MachineInstr * getDefInstrMaybeConstant(Register &ConstReg, const MachineRegisterInfo *MRI)
constexpr unsigned BitWidth
bool isEquivalentTypes(Type *Ty1, Type *Ty2)
Definition SPIRVUtils.h:428
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:560
bool hasBuiltinTypePrefix(StringRef Name)
Type * getMDOperandAsType(const MDNode *N, unsigned I)
bool hasInitializer(const GlobalVariable *GV)
Definition SPIRVUtils.h:321
Type * applyWrappers(Type *Ty)
Definition SPIRVUtils.h:391
Type * normalizeType(Type *Ty)
Definition SPIRVUtils.h:474
bool isPointerTyOrWrapper(const Type *Ty)
Definition SPIRVUtils.h:385
bool isSpvIntrinsic(const MachineInstr &MI, Intrinsic::ID IntrinsicID)
Type * getPointeeType(const Type *Ty)
Definition SPIRVUtils.h:405
PoisonValue * getNormalizedPoisonValue(Type *Ty)
Definition SPIRVUtils.h:484
void addStringImm(const StringRef &Str, MCInst &Inst)
MachineInstr * getVRegDef(MachineRegisterInfo &MRI, Register Reg)
bool isUntypedPointerTy(const Type *T)
Definition SPIRVUtils.h:331
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