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;
32class MachineInstrBuilder;
33class MachineIRBuilder;
34class MachineRegisterInfo;
35class Register;
36class StringRef;
37class SPIRVInstrInfo;
38class SPIRVSubtarget;
39class SPIRVGlobalRegistry;
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
116// Add the given string as a series of integer operand, inserting null
117// terminators and padding to make sure the operands all have 32-bit
118// little-endian words.
119void addStringImm(const StringRef &Str, MCInst &Inst);
120void addStringImm(const StringRef &Str, MachineInstrBuilder &MIB);
121void addStringImm(const StringRef &Str, IRBuilder<> &B,
122 std::vector<Value *> &Args);
123
124// Read the series of integer operands back as a null-terminated string using
125// the reverse of the logic in addStringImm.
126std::string getStringImm(const MachineInstr &MI, unsigned StartIndex);
127
128// Returns the string constant that the register refers to. It is assumed that
129// Reg is a global value that contains a string.
131
132// Add the given numerical immediate to MIB.
133void addNumImm(const APInt &Imm, MachineInstrBuilder &MIB);
134
135// Add an OpName instruction for the given target register.
137 MachineIRBuilder &MIRBuilder);
139 const SPIRVInstrInfo &TII);
140
141// Add an OpDecorate instruction for the given Reg.
143 SPIRV::Decoration::Decoration Dec,
144 const std::vector<uint32_t> &DecArgs,
145 StringRef StrImm = "");
147 SPIRV::Decoration::Decoration Dec,
148 const std::vector<uint32_t> &DecArgs,
149 StringRef StrImm = "");
150
151// Add an OpDecorate instruction for the given Reg.
153 SPIRV::Decoration::Decoration Dec, uint32_t Member,
154 const std::vector<uint32_t> &DecArgs,
155 StringRef StrImm = "");
157 const SPIRVInstrInfo &TII,
158 SPIRV::Decoration::Decoration Dec, uint32_t Member,
159 const std::vector<uint32_t> &DecArgs,
160 StringRef StrImm = "");
161
162// Add an OpDecorate instruction by "spirv.Decorations" metadata node.
164 const MDNode *GVarMD);
165
166// Return a valid position for the OpVariable instruction inside a function,
167// i.e., at the beginning of the first block of the function.
169
170// Return a valid position for the instruction at the end of the block before
171// terminators and debug instructions.
173
174// Returns true if a pointer to the storage class can be casted to/from a
175// pointer to the Generic storage class.
176constexpr bool isGenericCastablePtr(SPIRV::StorageClass::StorageClass SC) {
177 switch (SC) {
178 case SPIRV::StorageClass::Workgroup:
179 case SPIRV::StorageClass::CrossWorkgroup:
180 case SPIRV::StorageClass::Function:
181 return true;
182 default:
183 return false;
184 }
185}
186
187// Convert a SPIR-V storage class to the corresponding LLVM IR address space.
188// TODO: maybe the following two functions should be handled in the subtarget
189// to allow for different OpenCL vs Vulkan handling.
190constexpr unsigned
191storageClassToAddressSpace(SPIRV::StorageClass::StorageClass SC) {
192 switch (SC) {
193 case SPIRV::StorageClass::Function:
194 return 0;
195 case SPIRV::StorageClass::CrossWorkgroup:
196 return 1;
197 case SPIRV::StorageClass::UniformConstant:
198 return 2;
199 case SPIRV::StorageClass::Workgroup:
200 return 3;
201 case SPIRV::StorageClass::Generic:
202 return 4;
203 case SPIRV::StorageClass::DeviceOnlyINTEL:
204 return 5;
205 case SPIRV::StorageClass::HostOnlyINTEL:
206 return 6;
207 case SPIRV::StorageClass::Input:
208 return 7;
209 case SPIRV::StorageClass::Output:
210 return 8;
211 case SPIRV::StorageClass::CodeSectionINTEL:
212 return 9;
213 case SPIRV::StorageClass::Private:
214 return 10;
215 case SPIRV::StorageClass::StorageBuffer:
216 return 11;
217 case SPIRV::StorageClass::Uniform:
218 return 12;
219 default:
220 report_fatal_error("Unable to get address space id");
221 }
222}
223
224// Convert an LLVM IR address space to a SPIR-V storage class.
225SPIRV::StorageClass::StorageClass
226addressSpaceToStorageClass(unsigned AddrSpace, const SPIRVSubtarget &STI);
227
228SPIRV::MemorySemantics::MemorySemantics
229getMemSemanticsForStorageClass(SPIRV::StorageClass::StorageClass SC);
230
231SPIRV::MemorySemantics::MemorySemantics getMemSemantics(AtomicOrdering Ord);
232
233SPIRV::Scope::Scope getMemScope(LLVMContext &Ctx, SyncScope::ID Id);
234
235// Find def instruction for the given ConstReg, walking through
236// spv_track_constant and ASSIGN_TYPE instructions. Updates ConstReg by def
237// of OpConstant instruction.
238MachineInstr *getDefInstrMaybeConstant(Register &ConstReg,
239 const MachineRegisterInfo *MRI);
240
241// Get constant integer value of the given ConstReg.
242uint64_t getIConstVal(Register ConstReg, const MachineRegisterInfo *MRI);
243
244// Check if MI is a SPIR-V specific intrinsic call.
245bool isSpvIntrinsic(const MachineInstr &MI, Intrinsic::ID IntrinsicID);
246// Check if it's a SPIR-V specific intrinsic call.
247bool isSpvIntrinsic(const Value *Arg);
248
249// Get type of i-th operand of the metadata node.
250Type *getMDOperandAsType(const MDNode *N, unsigned I);
251
252// If OpenCL or SPIR-V builtin function name is recognized, return a demangled
253// name, otherwise return an empty string.
254std::string getOclOrSpirvBuiltinDemangledName(StringRef Name);
255
256// Check if a string contains a builtin prefix.
257bool hasBuiltinTypePrefix(StringRef Name);
258
259// Check if given LLVM type is a special opaque builtin type.
260bool isSpecialOpaqueType(const Type *Ty);
261
262// Check if the function is an SPIR-V entry point
263bool isEntryPoint(const Function &F);
264
265// Parse basic scalar type name, substring TypeName, and return LLVM type.
266Type *parseBasicTypeName(StringRef &TypeName, LLVMContext &Ctx);
267
268// Sort blocks in a partial ordering, so each block is after all its
269// dominators. This should match both the SPIR-V and the MIR requirements.
270// Returns true if the function was changed.
271bool sortBlocks(Function &F);
272
273inline bool hasInitializer(const GlobalVariable *GV) {
274 return GV->hasInitializer() && !isa<UndefValue>(GV->getInitializer());
275}
276
277// True if this is an instance of TypedPointerType.
278inline bool isTypedPointerTy(const Type *T) {
279 return T && T->getTypeID() == Type::TypedPointerTyID;
280}
281
282// True if this is an instance of PointerType.
283inline bool isUntypedPointerTy(const Type *T) {
284 return T && T->getTypeID() == Type::PointerTyID;
285}
286
287// True if this is an instance of PointerType or TypedPointerType.
288inline bool isPointerTy(const Type *T) {
290}
291
292// Get the address space of this pointer or pointer vector type for instances of
293// PointerType or TypedPointerType.
294inline unsigned getPointerAddressSpace(const Type *T) {
295 Type *SubT = T->getScalarType();
296 return SubT->getTypeID() == Type::PointerTyID
297 ? cast<PointerType>(SubT)->getAddressSpace()
298 : cast<TypedPointerType>(SubT)->getAddressSpace();
299}
300
301// Return true if the Argument is decorated with a pointee type
302inline bool hasPointeeTypeAttr(Argument *Arg) {
303 return Arg->hasByValAttr() || Arg->hasByRefAttr() || Arg->hasStructRetAttr();
304}
305
306// Return the pointee type of the argument or nullptr otherwise
308 if (Arg->hasByValAttr())
309 return Arg->getParamByValType();
310 if (Arg->hasStructRetAttr())
311 return Arg->getParamStructRetType();
312 if (Arg->hasByRefAttr())
313 return Arg->getParamByRefType();
314 return nullptr;
315}
316
318 SmallVector<Type *> ArgTys;
319 for (unsigned i = 0; i < F->arg_size(); ++i)
320 ArgTys.push_back(F->getArg(i)->getType());
321 return FunctionType::get(F->getReturnType(), ArgTys, F->isVarArg());
322}
323
324#define TYPED_PTR_TARGET_EXT_NAME "spirv.$TypedPointerType"
325inline Type *getTypedPointerWrapper(Type *ElemTy, unsigned AS) {
327 {ElemTy}, {AS});
328}
329
330inline bool isTypedPointerWrapper(const TargetExtType *ExtTy) {
331 return ExtTy->getName() == TYPED_PTR_TARGET_EXT_NAME &&
332 ExtTy->getNumIntParameters() == 1 &&
333 ExtTy->getNumTypeParameters() == 1;
334}
335
336// True if this is an instance of PointerType or TypedPointerType.
337inline bool isPointerTyOrWrapper(const Type *Ty) {
338 if (auto *ExtTy = dyn_cast<TargetExtType>(Ty))
339 return isTypedPointerWrapper(ExtTy);
340 return isPointerTy(Ty);
341}
342
343inline Type *applyWrappers(Type *Ty) {
344 if (auto *ExtTy = dyn_cast<TargetExtType>(Ty)) {
345 if (isTypedPointerWrapper(ExtTy))
346 return TypedPointerType::get(applyWrappers(ExtTy->getTypeParameter(0)),
347 ExtTy->getIntParameter(0));
348 } else if (auto *VecTy = dyn_cast<VectorType>(Ty)) {
349 Type *ElemTy = VecTy->getElementType();
350 Type *NewElemTy = ElemTy->isTargetExtTy() ? applyWrappers(ElemTy) : ElemTy;
351 if (NewElemTy != ElemTy)
352 return VectorType::get(NewElemTy, VecTy->getElementCount());
353 }
354 return Ty;
355}
356
357inline Type *getPointeeType(const Type *Ty) {
358 if (Ty) {
359 if (auto PType = dyn_cast<TypedPointerType>(Ty))
360 return PType->getElementType();
361 else if (auto *ExtTy = dyn_cast<TargetExtType>(Ty))
362 if (isTypedPointerWrapper(ExtTy))
363 return ExtTy->getTypeParameter(0);
364 }
365 return nullptr;
366}
367
368inline bool isUntypedEquivalentToTyExt(Type *Ty1, Type *Ty2) {
369 if (!isUntypedPointerTy(Ty1) || !Ty2)
370 return false;
371 if (auto *ExtTy = dyn_cast<TargetExtType>(Ty2))
372 if (isTypedPointerWrapper(ExtTy) &&
373 ExtTy->getTypeParameter(0) ==
375 ExtTy->getIntParameter(0) == cast<PointerType>(Ty1)->getAddressSpace())
376 return true;
377 return false;
378}
379
380inline bool isEquivalentTypes(Type *Ty1, Type *Ty2) {
381 return isUntypedEquivalentToTyExt(Ty1, Ty2) ||
383}
384
386 if (Type *NewTy = applyWrappers(Ty); NewTy != Ty)
387 return NewTy;
388 return isUntypedPointerTy(Ty)
391 : Ty;
392}
393
395 Type *OrigRetTy = FTy->getReturnType();
396 Type *RetTy = toTypedPointer(OrigRetTy);
397 bool IsUntypedPtr = false;
398 for (Type *PTy : FTy->params()) {
399 if (isUntypedPointerTy(PTy)) {
400 IsUntypedPtr = true;
401 break;
402 }
403 }
404 if (!IsUntypedPtr && RetTy == OrigRetTy)
405 return FTy;
406 SmallVector<Type *> ParamTys;
407 for (Type *PTy : FTy->params())
408 ParamTys.push_back(toTypedPointer(PTy));
409 return FunctionType::get(RetTy, ParamTys, FTy->isVarArg());
410}
411
412inline const Type *unifyPtrType(const Type *Ty) {
413 if (auto FTy = dyn_cast<FunctionType>(Ty))
414 return toTypedFunPointer(const_cast<FunctionType *>(FTy));
415 return toTypedPointer(const_cast<Type *>(Ty));
416}
417
418inline bool isVector1(Type *Ty) {
419 auto *FVTy = dyn_cast<FixedVectorType>(Ty);
420 return FVTy && FVTy->getNumElements() == 1;
421}
422
423// Modify an LLVM type to conform with future transformations in IRTranslator.
424// At the moment use cases comprise only a <1 x Type> vector. To extend when/if
425// needed.
426inline Type *normalizeType(Type *Ty) {
427 auto *FVTy = dyn_cast<FixedVectorType>(Ty);
428 if (!FVTy || FVTy->getNumElements() != 1)
429 return Ty;
430 // If it's a <1 x Type> vector type, replace it by the element type, because
431 // it's not a legal vector type in LLT and IRTranslator will represent it as
432 // the scalar eventually.
433 return normalizeType(FVTy->getElementType());
434}
435
438}
439
441 LLVMContext &Ctx = Arg->getContext();
444}
445
446CallInst *buildIntrWithMD(Intrinsic::ID IntrID, ArrayRef<Type *> Types,
447 Value *Arg, Value *Arg2, ArrayRef<Constant *> Imms,
448 IRBuilder<> &B);
449
450MachineInstr *getVRegDef(MachineRegisterInfo &MRI, Register Reg);
451
452#define SPIRV_BACKEND_SERVICE_FUN_NAME "__spirv_backend_service_fun"
453bool getVacantFunctionName(Module &M, std::string &Name);
454
455void setRegClassType(Register Reg, const Type *Ty, SPIRVGlobalRegistry *GR,
456 MachineIRBuilder &MIRBuilder,
457 SPIRV::AccessQualifier::AccessQualifier AccessQual,
458 bool EmitIR, bool Force = false);
461 const MachineFunction &MF, bool Force = false);
465 const MachineFunction &MF);
468 MachineIRBuilder &MIRBuilder);
470 const Type *Ty, SPIRVGlobalRegistry *GR, MachineIRBuilder &MIRBuilder,
471 SPIRV::AccessQualifier::AccessQualifier AccessQual, bool EmitIR);
472
473// Return true if there is an opaque pointer type nested in the argument.
474bool isNestedPointer(const Type *Ty);
475
477
478inline FPDecorationId demangledPostfixToDecorationId(const std::string &S) {
479 static std::unordered_map<std::string, FPDecorationId> Mapping = {
480 {"rte", FPDecorationId::RTE},
481 {"rtz", FPDecorationId::RTZ},
482 {"rtp", FPDecorationId::RTP},
483 {"rtn", FPDecorationId::RTN},
484 {"sat", FPDecorationId::SAT}};
485 auto It = Mapping.find(S);
486 return It == Mapping.end() ? FPDecorationId::NONE : It->second;
487}
488
489SmallVector<MachineInstr *, 4>
490createContinuedInstructions(MachineIRBuilder &MIRBuilder, unsigned Opcode,
491 unsigned MinWC, unsigned ContinuedOpcode,
492 ArrayRef<Register> Args, Register ReturnRegister,
493 Register TypeID);
494
495// Instruction selection directed by type folding.
496const std::set<unsigned> &getTypeFoldingSupportedOpcodes();
497bool isTypeFoldingSupported(unsigned Opcode);
498
499// Get loop controls from llvm.loop. metadata.
500SmallVector<unsigned, 1> getSpirvLoopControlOperandsFromLoopMetadata(Loop *L);
501
502// Traversing [g]MIR accounting for pseudo-instructions.
503MachineInstr *passCopy(MachineInstr *Def, const MachineRegisterInfo *MRI);
504MachineInstr *getDef(const MachineOperand &MO, const MachineRegisterInfo *MRI);
505MachineInstr *getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI);
506int64_t foldImm(const MachineOperand &MO, const MachineRegisterInfo *MRI);
507unsigned getArrayComponentCount(const MachineRegisterInfo *MRI,
508 const MachineInstr *ResType);
510getFirstValidInstructionInsertPoint(MachineBasicBlock &BB);
511
512} // namespace llvm
513#endif // LLVM_LIB_TARGET_SPIRV_SPIRVUTILS_H
unsigned const MachineRegisterInfo * MRI
MachineBasicBlock & MBB
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
return RetTy
std::string Name
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
Register Reg
Promote Memory to Register
Definition: Mem2Reg.cpp:110
Type::TypeID TypeID
#define TYPED_PTR_TARGET_EXT_NAME
Definition: SPIRVUtils.h:324
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition: APInt.h:78
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
This class represents an Operation in the Expression.
Core dominator tree base class.
Class to represent function types.
Definition: DerivedTypes.h:105
ArrayRef< Type * > params() const
Definition: DerivedTypes.h:132
bool isVarArg() const
Definition: DerivedTypes.h:125
Type * getReturnType() const
Definition: DerivedTypes.h:126
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 provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2780
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
Metadata node.
Definition: Metadata.h:1077
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1565
MachineInstrBundleIterator< MachineInstr > iterator
Helper class to build MachineInstr.
Representation of each machine instruction.
Definition: MachineInstr.h:72
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Metadata wrapper in the Value hierarchy.
Definition: Metadata.h:182
static LLVM_ABI MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:103
size_t GetNodeRank(BasicBlock *BB) const
Definition: SPIRVUtils.cpp:602
void partialOrderVisit(BasicBlock &Start, std::function< bool(BasicBlock *)> Op)
Definition: SPIRVUtils.cpp:693
bool compare(const BasicBlock *LHS, const BasicBlock *RHS) const
Definition: SPIRVUtils.cpp:684
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.
Definition: Constants.cpp:1885
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
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...
Definition: DerivedTypes.h:781
unsigned getNumIntParameters() const
Definition: DerivedTypes.h:838
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
Definition: DerivedTypes.h:829
StringRef getName() const
Return the name for this target extension type.
Definition: DerivedTypes.h:814
Target - Wrapper for Target specific information.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
@ TypedPointerTyID
Typed pointer used by some GPU targets.
Definition: Type.h:77
@ PointerTyID
Pointers.
Definition: Type.h:72
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:479
LLVM Value Representation.
Definition: Value.h:75
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:1098
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void buildOpName(Register Target, const StringRef &Name, MachineIRBuilder &MIRBuilder)
Definition: SPIRVUtils.cpp:113
bool getVacantFunctionName(Module &M, std::string &Name)
Definition: SPIRVUtils.cpp:754
std::string getStringImm(const MachineInstr &MI, unsigned StartIndex)
Definition: SPIRVUtils.cpp:79
bool isTypedPointerWrapper(const TargetExtType *ExtTy)
Definition: SPIRVUtils.h:330
bool isTypeFoldingSupported(unsigned Opcode)
Definition: SPIRVUtils.cpp:958
unsigned getPointerAddressSpace(const Type *T)
Definition: SPIRVUtils.h:294
MachineInstr * getDef(const MachineOperand &MO, const MachineRegisterInfo *MRI)
Definition: SPIRVUtils.cpp:970
void addNumImm(const APInt &Imm, MachineInstrBuilder &MIB)
Definition: SPIRVUtils.cpp:93
FPDecorationId demangledPostfixToDecorationId(const std::string &S)
Definition: SPIRVUtils.h:478
CallInst * buildIntrWithMD(Intrinsic::ID IntrID, ArrayRef< Type * > Types, Value *Arg, Value *Arg2, ArrayRef< Constant * > Imms, IRBuilder<> &B)
Definition: SPIRVUtils.cpp:821
unsigned getArrayComponentCount(const MachineRegisterInfo *MRI, const MachineInstr *ResType)
Definition: SPIRVUtils.cpp:995
bool sortBlocks(Function &F)
Definition: SPIRVUtils.cpp:723
Type * toTypedFunPointer(FunctionType *FTy)
Definition: SPIRVUtils.h:394
FPDecorationId
Definition: SPIRVUtils.h:476
@ RTP
Definition: SPIRVUtils.h:476
@ RTE
Definition: SPIRVUtils.h:476
@ RTN
Definition: SPIRVUtils.h:476
@ NONE
Definition: Attributor.h:6612
@ SAT
Definition: SPIRVUtils.h:476
@ RTZ
Definition: SPIRVUtils.h:476
SmallVector< unsigned, 1 > getSpirvLoopControlOperandsFromLoopMetadata(Loop *L)
Definition: SPIRVUtils.cpp:895
uint64_t getIConstVal(Register ConstReg, const MachineRegisterInfo *MRI)
Definition: SPIRVUtils.cpp:368
SmallVector< MachineInstr *, 4 > createContinuedInstructions(MachineIRBuilder &MIRBuilder, unsigned Opcode, unsigned MinWC, unsigned ContinuedOpcode, ArrayRef< Register > Args, Register ReturnRegister, Register TypeID)
Definition: SPIRVUtils.cpp:859
SPIRV::MemorySemantics::MemorySemantics getMemSemanticsForStorageClass(SPIRV::StorageClass::StorageClass SC)
Definition: SPIRVUtils.cpp:283
constexpr unsigned storageClassToAddressSpace(SPIRV::StorageClass::StorageClass SC)
Definition: SPIRVUtils.h:191
MachineBasicBlock::iterator getFirstValidInstructionInsertPoint(MachineBasicBlock &BB)
bool isNestedPointer(const Type *Ty)
Definition: SPIRVUtils.cpp:832
MetadataAsValue * buildMD(Value *Arg)
Definition: SPIRVUtils.h:440
std::string getOclOrSpirvBuiltinDemangledName(StringRef Name)
Definition: SPIRVUtils.cpp:434
bool isTypedPointerTy(const Type *T)
Definition: SPIRVUtils.h:278
bool isUntypedEquivalentToTyExt(Type *Ty1, Type *Ty2)
Definition: SPIRVUtils.h:368
void buildOpDecorate(Register Reg, MachineIRBuilder &MIRBuilder, SPIRV::Decoration::Decoration Dec, const std::vector< uint32_t > &DecArgs, StringRef StrImm)
Definition: SPIRVUtils.cpp:140
MachineBasicBlock::iterator getOpVariableMBBIt(MachineInstr &I)
Definition: SPIRVUtils.cpp:211
Register createVirtualRegister(SPIRVType *SpvType, SPIRVGlobalRegistry *GR, MachineRegisterInfo *MRI, const MachineFunction &MF)
Definition: SPIRVUtils.cpp:794
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
Definition: SPIRVUtils.cpp:976
Type * getTypedPointerWrapper(Type *ElemTy, unsigned AS)
Definition: SPIRVUtils.h:325
Type * reconstructFunctionType(Function *F)
Definition: SPIRVUtils.h:317
void buildOpMemberDecorate(Register Reg, MachineIRBuilder &MIRBuilder, SPIRV::Decoration::Decoration Dec, uint32_t Member, const std::vector< uint32_t > &DecArgs, StringRef StrImm)
Definition: SPIRVUtils.cpp:159
Type * toTypedPointer(Type *Ty)
Definition: SPIRVUtils.h:385
bool isVector1(Type *Ty)
Definition: SPIRVUtils.h:418
bool isSpecialOpaqueType(const Type *Ty)
Definition: SPIRVUtils.cpp:480
void setRegClassType(Register Reg, SPIRVType *SpvType, SPIRVGlobalRegistry *GR, MachineRegisterInfo *MRI, const MachineFunction &MF, bool Force)
Definition: SPIRVUtils.cpp:770
bool isPointerTy(const Type *T)
Definition: SPIRVUtils.h:288
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition: Error.cpp:167
MachineBasicBlock::iterator getInsertPtValidEnd(MachineBasicBlock *MBB)
Definition: SPIRVUtils.cpp:231
const Type * unifyPtrType(const Type *Ty)
Definition: SPIRVUtils.h:412
constexpr bool isGenericCastablePtr(SPIRV::StorageClass::StorageClass SC)
Definition: SPIRVUtils.h:176
MachineInstr * passCopy(MachineInstr *Def, const MachineRegisterInfo *MRI)
Definition: SPIRVUtils.cpp:963
bool isEntryPoint(const Function &F)
Definition: SPIRVUtils.cpp:489
const std::set< unsigned > & getTypeFoldingSupportedOpcodes()
Definition: SPIRVUtils.cpp:922
SPIRV::StorageClass::StorageClass addressSpaceToStorageClass(unsigned AddrSpace, const SPIRVSubtarget &STI)
Definition: SPIRVUtils.cpp:245
AtomicOrdering
Atomic ordering for LLVM's memory model.
SPIRV::Scope::Scope getMemScope(LLVMContext &Ctx, SyncScope::ID Id)
Definition: SPIRVUtils.cpp:319
std::string getStringValueFromReg(Register Reg, MachineRegisterInfo &MRI)
Definition: SPIRVUtils.cpp:83
int64_t foldImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
Definition: SPIRVUtils.cpp:985
Type * parseBasicTypeName(StringRef &TypeName, LLVMContext &Ctx)
Definition: SPIRVUtils.cpp:503
Type * getPointeeTypeByAttr(Argument *Arg)
Definition: SPIRVUtils.h:307
bool hasPointeeTypeAttr(Argument *Arg)
Definition: SPIRVUtils.h:302
MachineInstr * getDefInstrMaybeConstant(Register &ConstReg, const MachineRegisterInfo *MRI)
Definition: SPIRVUtils.cpp:345
bool isEquivalentTypes(Type *Ty1, Type *Ty2)
Definition: SPIRVUtils.h:380
bool hasBuiltinTypePrefix(StringRef Name)
Definition: SPIRVUtils.cpp:473
Type * getMDOperandAsType(const MDNode *N, unsigned I)
Definition: SPIRVUtils.cpp:380
bool hasInitializer(const GlobalVariable *GV)
Definition: SPIRVUtils.h:273
Type * applyWrappers(Type *Ty)
Definition: SPIRVUtils.h:343
Type * normalizeType(Type *Ty)
Definition: SPIRVUtils.h:426
bool isPointerTyOrWrapper(const Type *Ty)
Definition: SPIRVUtils.h:337
bool isSpvIntrinsic(const MachineInstr &MI, Intrinsic::ID IntrinsicID)
Definition: SPIRVUtils.cpp:374
Type * getPointeeType(const Type *Ty)
Definition: SPIRVUtils.h:357
PoisonValue * getNormalizedPoisonValue(Type *Ty)
Definition: SPIRVUtils.h:436
void addStringImm(const StringRef &Str, MCInst &Inst)
Definition: SPIRVUtils.cpp:54
MachineInstr * getVRegDef(MachineRegisterInfo &MRI, Register Reg)
Definition: SPIRVUtils.cpp:747
void buildOpSpirvDecorations(Register Reg, MachineIRBuilder &MIRBuilder, const MDNode *GVarMD)
Definition: SPIRVUtils.cpp:183
bool isUntypedPointerTy(const Type *T)
Definition: SPIRVUtils.h:283
SPIRV::MemorySemantics::MemorySemantics getMemSemantics(AtomicOrdering Ord)
Definition: SPIRVUtils.cpp:301
#define N